2

I'm trying to get the output of a Nmap NSE script to output properly to my terminal. I'm using the libnmap module, and have read a few examples as well as the documentation, so I'm not sure where I'm going wrong.

from libnmap.parser import NmapParser

p = NmapParser.parse_fromfile("test.xml")
for host in p.hosts:
    for service in host.services:
        for script_out in service.scripts_results:
            print "Output of {0}: {1}".format(script_out['id'], script_out['output']

When I ran the script above, nothing outputted. If I get the logic of the above script to work properly, then I can probably get it to work in my main script.

I ran this nmap scan in my terminal to test the script. nmap -sV --script dns-brute.nse -oX test.xml google.com

3
  • What's the output if you do for host in p.hosts: print host? Commented Apr 5, 2016 at 15:06
  • NmapHost: [216.58.216.110 (google.com ord30s22-in-f14.1e100.net) - is up] Commented Apr 5, 2016 at 16:00
  • Oh, I was hoping to see some kind of dictionary structure. But maybe the .services and/or .scripts_results are empty for some reason? Maybe the parser and the xml doesn't map 1:1? One way to figure out is to run your code inside IPython and check what's inside the object returned by parse_fromfile, either by using dir or using tab completion. Commented Apr 5, 2016 at 16:03

1 Answer 1

2

I was stuck on the same problem, after reviewing the source code and the xml file, you'll notice that while the script scan the host running a script on the xml file there is the element Hostscript which make the difference between other script lunched (ex: ftp-anon )

well try out this, it should work

from libnmap.parser import NmapParser

p = NmapParser.parse_fromfile("test.xml")
for host in p.hosts:

  for script_out in host.scripts_results:
    print "Output of {0}: {1}".format(script_out['id'],script_out['output']
       

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.