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

Accessing NTP-MONLIST NSE results #35

Closed
xqxq opened this issue May 16, 2014 · 1 comment
Closed

Accessing NTP-MONLIST NSE results #35

xqxq opened this issue May 16, 2014 · 1 comment

Comments

@xqxq
Copy link

xqxq commented May 16, 2014

Hi

Resend as the formatting was terrible - this is better but still not great :-(

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:
++++++++++++
/usr/bin/nmap -oX - -vvv --stats-every 2s -sU -pU:123 -n -Pn --script=ntp-monlist 127.0.0.1

<script id="ntp-monlist" output=" Target is synchronised with 206.186.121.118 Alternative Target Interfaces: 192.168.64.144 Public Servers (4) 24.87.64.125 67.215.197.149 142.137.247.109 206.186.121.118 Private Clients (1) 127.0.0.1 "/>

++++++++++++

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

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)

try:
    parsed = NmapParser.parse(nm.stdout)
except NmapParserException as e:
    print "Exception raised while parsing scan: %s" % (e.msg)

return parsed

def print_scan(nmap_report):
print "Starting Nmap {0} ( http://nmap.org ) at {1}".format(
nmap_report._nmaprun['version'],
nmap_report._nmaprun['startstr'])

for host in nmap_report.hosts:
    if len(host.hostnames):
        tmp_host = host.hostnames.pop()
    else:
        tmp_host = host.address

    print "Nmap scan report for {0} ({1})".format(
        tmp_host,
        host.address)
    print "Host is {0}.".format(host.status)
    print "  PORT     STATE         SERVICE"

    for serv in host.services:
        pserv = "{0:>5s}/{1:3s}  {2:12s}  {3}".format(
                str(serv.port),
                serv.protocol,
                serv.state,
                serv.service)
        if len(serv.banner):
            pserv += " ({0})".format(serv.banner)
        print pserv
print nmap_report.summary

print "++++++++++++++++++++++"
print "nmap_report.commandline: ", nmap_report.commandline
print "++++++++++++++++++++++"

print "HOST.address: ", host.address
print "HOST.mac: ", host.mac
print "HOST.scripts_results: ", (host.scripts_results['ntp-monlist'])
print "TGTPORT: ", TGTPORT
print "HOST.services: ", host.services

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 when I run this script 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:
HOST.scripts_results:
Traceback (most recent call last):
File "./libnmap_testing.py", line 76, in
print_scan(report)
File "./libnmap_testing.py", line 57, in print_scan
print "HOST.scripts_results: ", (host.scripts_results['ntp-monlist'])
KeyError: 'ntp-monlist'
++++++++++++++++++++++

@savon-noir
Copy link
Owner

please refer to comments in issue #34

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

2 participants