Last active
September 18, 2020 15:45
-
-
Save zenfosec/8089640e3d56ddcb6e58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # Takes an input nmap xml file and script name and outputs the ip, port, and script results | |
| # | |
| # zenfosec 4/16/2014 | |
| import xml.etree.ElementTree as ET | |
| import sys | |
| import re | |
| if len(sys.argv) != 3: | |
| print "Usage: script_miner.py <nmapresults.xml> <script_title>" | |
| sys.exit() | |
| scriptname = sys.argv[2] | |
| # opens file and imports as a tree into "root" | |
| tree = ET.parse(sys.argv[1]) | |
| root = tree.getroot() | |
| # iterates through tree and prints "ip:port script_output" | |
| for child in root: | |
| for host in child: | |
| if host.tag == 'address': | |
| ip = host.attrib['addr'] | |
| for port in host: | |
| if port.tag == 'port': | |
| portnumber = port.attrib['portid'] | |
| for status in port: | |
| try: | |
| if status.tag == "script": | |
| if status.attrib['id'] == scriptname: | |
| output = repr(status.attrib['output']) | |
| output = re.sub(r'\\n', '', output) | |
| output = re.sub("\'", '', output) | |
| output = re.sub(r'\s+', ' ', output) | |
| print "%s:%s %s: %s" % (ip,portnumber,scriptname,output) | |
| except: | |
| next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment