Closed xqxq closed 10 years ago
could you please gist your script and paste the link?
1) this nse script seems to require root privs and you are running NmapProcess.run() 2) your code is not check NmapProcess.rc ==0 3) you should also check if key exists in scripts_results (although, i must admit, a clear API should be implemented here 4) scripts_results is accessible from NmapService object, not NmapHost 5) as documented, NmapService.scripts_results returns an array of dict (again I should implement proper API, but still, documentation is there)
... i think the issue is related to the way you use the lib. I'll make you a quick sample.
this works for me. good luck.
I am quite new to object oriented programming so I apologize in advance if I seem dense.
I looked at your example and I am wondering if you pasted the wrong script as the output shows the script name ntp-monlist and the script posted is ntpmon.py.
Your example is reading the results from a file.
I was trying to get the result directly from NMAP output without writing to a file first, is that possible or do I have to write the results out and then go back and read the file?
Thanx in advance for your assistance!
Here is the GIST Link: https://gist.github.com/xqxq/8ddae3bb9a82be5089ec
https://gist.github.com/savon-noir/63969d0a4001cba60fcf
try this kind of things... should work but i haven't tested...no time. Your problems are not related to this lib. If you need python guidance, I would suggest you to go on #python on irc.freenode.net there is an awesome community of ppl there willing to help.
Also, I suggest you to read the doc: https://libnmap.readthedocs.org/en/latest/ and understand how to use the lib (and check other code examples).
The issue I had was with referencing the objects - your example clarified the correct syntax.
Thanx so much for your time - I am on the road now.
Have a working script now - thanks so much for your time!! Still getting the hang of object oriented referencing.
Have a great week!
Hi
I am trying to scan for and retrieve the NTP-MONLIST Results.
I end with with a KEYERROR when trying to reference the NTP-MONLIST results.
Please see below my scripts and testing.
Any guidance will be much appreciated!
-John
When I run the nmap command manually I get the results as part of the XML results:
[root@localhost python]# /usr/bin/nmap -oX - -vvv --stats-every 2s -sU -pU:123 -n -Pn --script=ntp-monlist 127.0.0.1 <?xml version="1.0"?> <?xml-stylesheet href="file:///usr/share/nmap/nmap.xsl" type="text/xsl"?>
This is my script:
!/usr/bin/python
from libnmap.process import NmapProcess from libnmap.parser import NmapParser, NmapParserException from libnmap.objects import NmapReport, NmapHost, NmapService
start a new nmap scan on localhost with some specific options
def do_scan(targets, options): nm = NmapProcess(targets, options, safe_mode=False) rc = nm.run() if rc != 0: print "nmap scan failed: %s" % (nm.stderr)
print scan results from a nmap report
def print_scan(nmap_report): print "Starting Nmap {0} ( http://nmap.org ) at {1}".format( nmap_report._nmaprun['version'], nmap_report._nmaprun['startstr'])
if name == "main": global DEBUG DEBUG = 0
TGTHOST = "127.0.0.1" TGTPROTO = "udp" NMAP_PROTO = " -sU -pU:" TGTPORT = 123
report = do_scan(TGTHOST, NMAP_PROTO + str(TGTPORT) + " -n -Pn --script=ntp-monlist ")
print_scan(report)
This is the output I get from the command_line:
[root@localhost python]# ./libnmap_testing.py Starting Nmap 5.51 ( http://nmap.org ) at Fri May 16 13:10:26 2014 Nmap scan report for 127.0.0.1 (127.0.0.1) Host is up. PORT STATE SERVICE 123/udp open ntp Nmap done at Fri May 16 13:10:26 2014; 1 IP address (1 host up) scanned in 0.08 seconds ++++++++++++++++++++++ nmap_report.commandline: /usr/bin/nmap -oX - -vvv --stats-every 2s -sU -pU:123 -n -Pn --script=ntp-monlist 127.0.0.1
++++++++++++++++++++++
HOST.address: 127.0.0.1 HOST.mac:
print_scan(report)
File "./libnmap_testing.py", line 57, in print_scan
print "HOST.scripts_results: ", (host.scripts_results['ntp-monlist'])
HOST.scripts_results: Traceback (most recent call last): File "./libnmap_testing.py", line 76, in
KeyError: 'ntp-monlist'