Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_noportscan does not parse mac address #30

Closed
egabrum opened this issue Oct 8, 2020 · 16 comments
Closed

parse_noportscan does not parse mac address #30

egabrum opened this issue Oct 8, 2020 · 16 comments

Comments

@egabrum
Copy link

egabrum commented Oct 8, 2020

I'm trying to use this package to find the IP, knowing the MAC address, but...
This data:

<host><status state="up" reason="arp-response" reason_ttl="0"/>
<address addr="10.11.12.13" addrtype="ipv4"/>
<address addr="00:01:02:03:04:05" addrtype="mac" vendor="Vendor Inc."/>
<hostnames>
<hostname name="00-01-02-03-04-05-dns-inc.com" type="PTR"/>
</hostnames>
<times srtt="1000" rttvar="5000" to="100000"/>
</host>

Is only parsed as:

{'state': 'up', 'reason': 'arp-response', 'reason_ttl': '0', 'addr': '10.11.12.13', 'addrtype': 'ipv4'}

@nmmapper
Copy link
Owner

nmmapper commented Oct 9, 2020

That's a flaw then, will work on that, if possible you can fix it and create a pull request.

nmmapper added a commit that referenced this issue Oct 11, 2020
@nmmapper
Copy link
Owner

This issue has been fixed, try again and you will get all addresses.

@egabrum
Copy link
Author

egabrum commented Oct 12, 2020

for hostname in host.find("hostnames"): TypeError: 'NoneType' object is not iterable

Not all entries have a hostname.

Why not use something like xmljson to directly convert the xml from nmap to json ?

@nmmapper
Copy link
Owner

We'll fix that, but you can always open a pull request with those changes you are recommendint

@nmmapper
Copy link
Owner

nmmapper commented Oct 15, 2020

You can try again and let us know before we close the issue.

@egabrum
Copy link
Author

egabrum commented Oct 16, 2020

Looks good to me now. Thanks.
I find a bit off that, to get the mac, I have to iterate through the list of 'addresses', but not big deal.

@chodyo
Copy link

chodyo commented Oct 16, 2020

I'm having a bit of trouble getting the mac at all from this library so I'd like to piggy back off this issue. Running this library's nmap_no_portscan gives me an object with the nmap output parsed, but no mac address, while running sudo nmap -sn <ip> does output the mac address. Feels like I missed something here and I haven't been able to figure out what it is.

Examples

Example nmap output (censored):

$ sudo nmap -sn 192.168.1.10
Starting Nmap 7.70 ( https://nmap.org ) at 2020-10-16 17:29 BST
Nmap scan report for 192.168.1.10
Host is up (0.055s latency).
MAC Address: XX:XX:XX:XX:XX:XX (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.44 seconds

Example script:

# test.py
import nmap3
nmap = nmap3.NmapHostDiscovery()
results = nmap.nmap_no_portscan("192.168.1.10")
print(results)

Example output (python3 test.py and sudo python3 test.py both give the same output):

{
    "runtime": {
        "time": "1602865359",
        "timestr": "Fri Oct 16 17:22:39 2020",
        "elapsed": "0.58",
        "summary": "Nmap done at Fri Oct 16 17:22:39 2020; 1 IP address (1 host up) scanned in 0.58 seconds",
        "exit": "success"
    },
    "status": {
        "up": "1",
        "down": "0",
        "total": "1"
    },
    "hosts": [
        {
            "state": "up",
            "reason": "arp-response",
            "reason_ttl": "0",
            "addr": "192.168.1.10",
            "addrtype": "ipv4"
        }
    ]
}

@nmmapper
Copy link
Owner

Looks good to me now. Thanks.
I find a bit off that, to get the mac, I have to iterate through the list of 'addresses', but not big deal.

Mac addresses are shown as IP addresses that's why there is that iteration

@nmmapper
Copy link
Owner

I'm having a bit of trouble getting the mac at all from this library so I'd like to piggy back off this issue. Running this library's nmap_no_portscan gives me an object with the nmap output parsed, but no mac address, while running sudo nmap -sn <ip> does output the mac address. Feels like I missed something here and I haven't been able to figure out what it is.
Examples

Example nmap output (censored):

$ sudo nmap -sn 192.168.1.10
Starting Nmap 7.70 ( https://nmap.org ) at 2020-10-16 17:29 BST
Nmap scan report for 192.168.1.10
Host is up (0.055s latency).
MAC Address: XX:XX:XX:XX:XX:XX (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.44 seconds

Example script:

# test.py
import nmap3
nmap = nmap3.NmapHostDiscovery()
results = nmap.nmap_no_portscan("192.168.1.10")
print(results)

Example output (python3 test.py and sudo python3 test.py both give the same output):

{
    "runtime": {
        "time": "1602865359",
        "timestr": "Fri Oct 16 17:22:39 2020",
        "elapsed": "0.58",
        "summary": "Nmap done at Fri Oct 16 17:22:39 2020; 1 IP address (1 host up) scanned in 0.58 seconds",
        "exit": "success"
    },
    "status": {
        "up": "1",
        "down": "0",
        "total": "1"
    },
    "hosts": [
        {
            "state": "up",
            "reason": "arp-response",
            "reason_ttl": "0",
            "addr": "192.168.1.10",
            "addrtype": "ipv4"
        }
    ]
}

Seems we need to look into it again, i will still polish that out. and i will update this issue.

@nmmapper
Copy link
Owner

Mac addresses are detected when the script runs as root, but when the script does not run as root mac addresses will not be shown.

(www.python3-nmap.com) $nmap -sn 192.168.178.1
Starting Nmap 7.70 ( https://nmap.org ) at 2020-10-18 16:15 EAT
Nmap scan report for homerouter.cpe (192.168.178.1)
Host is up (0.0033s latency).
MAC Address: 80:13:82:AB:D2:34 (Huawei Technologies)
Nmap done: 1 IP address (1 host up) scanned in 0.28 seconds
(www.python3-nmap.com) $

Without root

(www.python3-nmap.com) $nmap -sn 192.168.178.1
Starting Nmap 7.70 ( https://nmap.org ) at 2020-10-18 16:16 EAT
Nmap scan report for homerouter.cpe (192.168.178.1)
Host is up (0.0011s latency).
Nmap done: 1 IP address (1 host up) scanned in 0.00 seconds
(www.python3-nmap.com) $

@chodyo
Copy link

chodyo commented Oct 18, 2020

Mac addresses are detected when the script runs as root, but when the script does not run as root mac addresses will not be shown.

I have observed the same behavior with nmap but I am unable to get the mac address with python3-nmap. My expectation is that when I run the example python script with sudo that it will be able to obtain mac addresses, but that doesn't seem to be the case.

Is there some other function I need to use, am I somehow using sudo wrong? I get the impression it's just a usability issue since I seem to be the only one having this problem :D

@nmmapper
Copy link
Owner

Mac addresses are detected when the script runs as root, but when the script does not run as root mac addresses will not be shown.

I have observed the same behavior with nmap but I am unable to get the mac address with python3-nmap. My expectation is that when I run the example python script with sudo that it will be able to obtain mac addresses, but that doesn't seem to be the case.

Is there some other function I need to use, am I somehow using sudo wrong? I get the impression it's just a usability issue since I seem to be the only one having this problem :D

Addtionally there is not guarantee that the MAC Address will be returned, I scanned two IP, but only one returned the Mac address the other never returned the MAC Address. The one that returned the MAC address was the router IP(Gate way IP). The one that didn't return the MAC address was a physical linux computer.

@chodyo
Copy link

chodyo commented Oct 18, 2020

Hmm, that's odd. I have been able to consistently get mac addresses with sudo nmap -sn but I haven't ever been able to get it from NmapHostDiscovery. Is there any way I can turn on debug logs?

@nmmapper
Copy link
Owner

Hmm, that's odd. I have been able to consistently get mac addresses with sudo nmap -sn but I haven't ever been able to get it from NmapHostDiscovery. Is there any way I can turn on debug logs?

You can not turn on debug, but you can get raw xml and see if it's returned and it's a parsing issue with

self.raw_ouput

@chodyo
Copy link

chodyo commented Oct 19, 2020

Great, I was able to see the mac in the XML, so it's the same problem that egabrum reported in this ticket originally. Thank you for your help!

@nmmapper
Copy link
Owner

Great, I was able to see the mac in the XML, so it's the same problem that egabrum reported in this ticket originally. Thank you for your help!

That's great, if you can fix that so it works and open a pull requests, so all can benefit.

nmmapper added a commit that referenced this issue Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants