BIG push, should all be working
This commit is contained in:
@@ -1,8 +1,35 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
from sqlite3 import Error
|
||||
import argparse
|
||||
import sqlite3
|
||||
import sys
|
||||
import re
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Convert your nmap scans into a sqlite database!')
|
||||
parser.add_argument('-d', type=str, help='The database file to use')
|
||||
parser.add_argument('-x', type=str, help='The xml file to read from, please use -oX with nmap')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if(args.d == None or args.x == None):
|
||||
raise("Must have a database and xml file!")
|
||||
|
||||
|
||||
class target:
|
||||
def __init__(self, os,hostname,address,ports):
|
||||
self.os = os
|
||||
self.hostname = hostname
|
||||
self.address = address
|
||||
self.ports = ports
|
||||
|
||||
def ptarg(self):
|
||||
print("{}\n{}\n{}\n{}\n".format(self.os,self.hostname,self.address,self.ports))
|
||||
|
||||
def add(self,conn):
|
||||
add_item(conn,self.os,self.hostname,self.address,self.ports)
|
||||
|
||||
|
||||
def create_connection(database):
|
||||
""" Connects to the database file """
|
||||
try:
|
||||
@@ -10,7 +37,7 @@ def create_connection(database):
|
||||
return conn
|
||||
except Error as e:
|
||||
print(e)
|
||||
|
||||
|
||||
return None
|
||||
|
||||
def create_table(conn, create_table_sql):
|
||||
@@ -34,7 +61,8 @@ def add_item(conn, os, hostname, address, ports):
|
||||
|
||||
def main():
|
||||
""" Connect to the database file """
|
||||
database = 'scanned.db'
|
||||
|
||||
database = args.d
|
||||
|
||||
conn = create_connection(database)
|
||||
if conn is None:
|
||||
@@ -50,7 +78,37 @@ def main():
|
||||
); """
|
||||
create_table(conn, targetTableCreate)
|
||||
|
||||
add_item(conn, "windows", "localhost", 1, "80,69,8080")
|
||||
|
||||
# Start parsing the xml
|
||||
tree = ET.parse(args.x)
|
||||
root = tree.getroot()
|
||||
targets = []
|
||||
|
||||
for host in root.iter('host'):
|
||||
os = None
|
||||
hostname = None
|
||||
address = None
|
||||
ports = []
|
||||
|
||||
for o in host.iter('osclass'):
|
||||
os = str(o.attrib['osfamily'])
|
||||
|
||||
for hm in host.iter('hostname'):
|
||||
hostname = str(hm.attrib['name'])
|
||||
|
||||
for addr in host.iter('address'):
|
||||
if(addr.attrib['addrtype'] == 'ipv4'):
|
||||
address = str(addr.attrib['addr']).split('.')[-1]
|
||||
|
||||
for port in host.iter('port'):
|
||||
ports.append(str(port.attrib['portid']))
|
||||
|
||||
|
||||
|
||||
targets.append(target(os, hostname, address, ', '.join(ports)))
|
||||
# Write the targets to the database
|
||||
for tar in targets:
|
||||
tar.add(conn)
|
||||
|
||||
# Close the database connection
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user