savon-noir / python-libnmap

libnmap is a python library to run nmap scans, parse and diff scan results. It supports python 2.7 up to 3.8. It's wonderful.
https://libnmap.readthedocs.org
Other
489 stars 182 forks source link

libnmap.objects.NmapService.scripts_results always returns empty dict #14

Closed trashgordon-zz closed 10 years ago

trashgordon-zz commented 10 years ago

I ran an Nmap scan (outside of python-libnmap) as follows: nmap -p139,445 --script=smb-os-discovery -oX smb-os-test.xml 192.168.31.205

In the smb-os-test.xml file, I can see that the NSE script results are included:

<?xml version="1.0"?> <?xml-stylesheet href="file:///usr/bin/../share/nmap/nmap.xsl" type="text/xsl"?>

##

However, anytime I use the following code to get the NSE script results, the dictionary returned is empty:

nmap_report = NmapParser.parse_fromfile('smb-os-test.xml') host = nmap_report.get_host_byid('192.168.31.205') svc = host.get_service(139) nse_results = svc.scripts_results() print nse_results

{}

This is what svc.get_dict() shows me: {'banner': '', 'id': 'tcp.139', 'port': '139', 'protocol': 'tcp', 'service': 'netbios-ssn', 'state': 'open'}

I also tried this for port 445, but get the same results. Am I doing something wrong? Let me know if you need any additional info.

trashgordon-zz commented 10 years ago

I see the XML did not get included. I can send that to you if you need.

savon-noir commented 10 years ago

yes you can send it over to mini.pelle@gmail.com. thanks for bug post

savon-noir commented 10 years ago

Quick fix, i need to get further with this (parsing tags) but here is the result: (see commit https://github.com/savon-noir/python-libnmap/commit/1cd054cdcdbc9450df64be9660374bc607e189a8)

In [1]: from libnmap.parser import NmapParser In [2]: p = NmapParser.parse_fromfile("/vagrant/smb-os-test.xml") In [3]: h[0].scripts_results Out[3]: [{'id': 'smb-os-discovery', 'output': '\n OS: Windows 2000 (Windows 2000 LAN Manager)\n OS CPE: cpe:/o:microsoft:windows_2000::-\n Computer name: oracle\n NetBIOS computer name: ORACLE\n Domain name: acme.local\n FQDN: oracle.acme.local\n NetBIOS domain name: ACME\n System time: 2014-03-03T16:41:35+02:00\n'}]

savon-noir commented 10 years ago

ok... way better now...

Check change log: you now have

NmapHost.scripts_results (it's a property) and will produce the below output for your specific XML. you also have NmapService.scripts_results (again a property, it was formerly a method) and will produce similar output but for service specific nse scripts output.

See example with your xml:

In [1]: from libnmap.parser import NmapParser In [2]: p = NmapParser.parse_fromfile("/vagrant/smb-os-test.xml") In [3]: h = p.hosts.pop() In [4]: h.scripts_results Out[4]: [{'elements': {'cpe': 'cpe:/o:microsoft:windows_2000::-', 'date': '2014-03-03T16:41:35+02:00', 'domain': 'ACME', 'domain_dns': 'acme.local', 'fqdn': 'oracle.acme.local', 'lanmanager': 'Windows 2000 LAN Manager', 'os': 'Windows 5.0', 'server': 'ORACLE' } ,

'id': 'smb-os-discovery','output': '\n OS: Windows 2000 (Windows 2000 LAN Manager)\n OS CPE: cpe:/o:microsoft:windows_2000::-\n Computer name: oracle\n NetBIOS computer name: ORACLE\n Domain name: acme.local\n FQDN: oracle.acme.local\n NetBIOS domain name: ACME\n System time: 2014-03-03T16:41:35+02:00\n' } ]

Any feedback and more tests cases are most welcome.

savon-noir commented 10 years ago

@trashgordon did you tested this?

trashgordon-zz commented 10 years ago

Yes, and it works great now. Thank you! And thank you for your great library!

brizzbane commented 9 years ago

I've downloaded straight from github as opposed to PIP install, and still have issue of dict showing {} when printing it out. I print out nmap_report = NmapParser.parse(nmap_proc.stdout), and see values in the XML.

What am I doing wrong :\?

[edit] got it figured out.

here is a gist of: nmap_report = NmapParser.parse(nmap_proc.stdout) that shows how to cycle through everything.

https://gist.github.com/brizzbane/637dfed0032d6f00e191