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

Script nmap information missing solved #16

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
# Nmap-XML-Parser
# Nmap - xml2csv
Converts Nmap XML output to csv file, and other useful functions. Ignores hosts that are down and ports that are not open.

As featured in, Advanced Nmap - Scanning Large Scale Networks:

https://www.youtube.com/watch?v=okCNbKSdmDA

## Usage

### Convert Nmap output to csv file
`python3 nmap_xml_parser.py -f nmap_scan.xml -csv nmap_scan.csv`
`python3 xml2csv.py -f nmap_scan.xml -csv nmap_scan.csv`

### Display scan information to the terminal
`python3 nmap_xml_parser.py -f nmap_scan.xml -p`
`python3 xml2csv.py -f nmap_scan.xml -p`

### Display only IP addresses
`python3 nmap_xml_parser.py -f nmap_scan.xml -ip`
`python3 xml2csv.py -f nmap_scan.xml -ip`

### Display IP addresses/ports in URL friendly format
> Displays in format http(s)://ipaddr:port if port is a possible web port

`python3 nmap_xml_parser.py -f nmap_scan.xml -pw`
`python3 xml2csv.py -f nmap_scan.xml -pw`

### Display least common open ports
> Displays the 10 least common open ports

`python3 nmap_xml_parser.py -f nmap_scan.xml -lc 10`
`python3 xml2csv.py -f nmap_scan.xml -lc 10`

### Display most common open ports
> Displays the 10 most common open ports

`python3 nmap_xml_parser.py -f nmap_scan.xml -mc 10`
`python3 xml2csv.py -f nmap_scan.xml -mc 10`

### Display only IP addresses with a specified open port
> Displays only IP addresses where port 23 is open

`python3 nmap_xml_parser.py -f nmap_scan.xml -fp 23`
`python3 xml2csv.py -f nmap_scan.xml -fp 23`
54 changes: 49 additions & 5 deletions nmap_xml_parser.py → xml2csv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python


# Credit where credit is due...
__author__ = 'Jake Miller (@LaconicWolf)'
__date__ = '20171220'
__version__ = '0.01'
Expand All @@ -17,7 +19,34 @@
from collections import Counter
from time import sleep

def saveallscript(array_script):
allscriptid = []
alltscriptout = []
size1 = len(array_script)
#print(size1)
for i in range(0,size1,1):
#print(str(i))
try:
script_id = array_script.findall('script')[i].attrib['id']
except (IndexError, KeyError):
script_id = ''
try:
script_output = array_script.findall('script')[i].attrib['output']
except (IndexError, KeyError):
script_output = ''

#print(script_id)
#print(script_output)
allscriptid.append(script_id)#mio
alltscriptout.append(script_output)#mio

return allscriptid,alltscriptout




def get_host_data(root):
#print(root.text)
"""Traverses the xml tree and build lists of scan information
and returns a list of lists.
"""
Expand Down Expand Up @@ -55,6 +84,7 @@ def get_host_data(root):
try:
port_element = host.findall('ports')
ports = port_element[0].findall('port')
#print(ports)
for port in ports:
port_data = []

Expand All @@ -78,22 +108,35 @@ def get_host_data(root):
servicefp = port.findall('service')[0].attrib['servicefp']
except (IndexError, KeyError):
servicefp = ''
"""
try:
script_id = port.findall('script')[0].attrib['id']
#print(len(port.findall('script')))
saveallscript(port)
for scriptnum in range(0,len(port.findall('script')),1):
script_id = port.findall('script')[scriptnum].attrib['id']
#scriptidfor.append(script_id)#mio
except (IndexError, KeyError):
script_id = ''
try:
script_output = port.findall('script')[0].attrib['output']
#print(script_output)
except (IndexError, KeyError):
script_output = ''
"""

# Create a list of the port data
port_data.extend((ip_address, host_name, os_name,
#print(scriptfor)
allscriptid,alltscriptout = saveallscript(port)
for i in range(0,len(alltscriptout),1):
host_data.append((ip_address, host_name, os_name,
proto, port_id, service, product,
servicefp, script_id, script_output))
servicefp, allscriptid[i], alltscriptout[i]))
#host_data.append(port_data)
#print(host_data[0])


# Add the port data to the host data
host_data.append(port_data)


# If no port information, just create a list of host information
except IndexError:
Expand All @@ -108,6 +151,7 @@ def parse_xml(filename):
containing the scan data for a host or hosts."""
try:
tree = etree.parse(filename)
#print(tree)
except Exception as error:
print("[-] A an error occurred. The XML may not be well formed. "
"Please review the error and try again: {}".format(error))
Expand Down Expand Up @@ -327,4 +371,4 @@ def main():
print("\n[-] Please choose an output option. Use -csv, -ip, or -p\n")
exit()
csv_name = args.csv
main()
main()