Added support for multiple clients, and a filter count display at the bottom-right of the page
This commit is contained in:
+4
-2
@@ -1,18 +1,20 @@
|
|||||||
from app import db
|
from app import db
|
||||||
|
|
||||||
class target(db.Model):
|
class target(db.Model):
|
||||||
__tablename__ = 'targets'
|
__tablename__ = "targets"
|
||||||
id = db.Column(db.Integer, primary_key = True)
|
id = db.Column(db.Integer, primary_key = True)
|
||||||
os = db.Column(db.String())
|
os = db.Column(db.String())
|
||||||
hostname = db.Column(db.String())
|
hostname = db.Column(db.String())
|
||||||
address = db.Column(db.String())
|
address = db.Column(db.String())
|
||||||
ports = db.Column(db.String())
|
ports = db.Column(db.String())
|
||||||
|
clientId = db.Column(db.String())
|
||||||
|
|
||||||
def __init__(self, os, hostname, address, ports):
|
def __init__(self, os, hostname, address, ports, clientId):
|
||||||
self.os = os
|
self.os = os
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.address = address
|
self.address = address
|
||||||
self.ports = ports
|
self.ports = ports
|
||||||
|
self.clientId = clientId
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<address %r>' % self.address
|
return '<address %r>' % self.address
|
||||||
|
|||||||
@@ -92,8 +92,9 @@ a:hover, a:link, a:visited, a:active{
|
|||||||
|
|
||||||
input[type=text]{
|
input[type=text]{
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--header-text);
|
|
||||||
border: 0;
|
border: 0;
|
||||||
|
border-bottom: 2px solid var(--accent-color);
|
||||||
|
color: var(--header-text);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -108,4 +109,15 @@ input[type=text]{
|
|||||||
}
|
}
|
||||||
::-ms-input-placeholder { /* Microsoft Edge */
|
::-ms-input-placeholder { /* Microsoft Edge */
|
||||||
color: var(--header-text);
|
color: var(--header-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-count {
|
||||||
|
position: fixed;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
margin: 0.8vw;
|
||||||
|
font-size: 1vw;
|
||||||
|
border-radius: 15px;
|
||||||
|
padding: 1vw;
|
||||||
|
background: var(--accent-color);
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr class="table-header">
|
<tr class="table-header">
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
|
<input type="text" name="clientId" id="clientId" placeholder="Client Id" value="{{ clientId }}">
|
||||||
<input type="submit" value="Submit Query" hidden>
|
<input type="submit" value="Submit Query" hidden>
|
||||||
<th><input type="text" name="os" id="os" placeholder="OS" value="{{ os }}"></th>
|
<th><input type="text" name="os" id="os" placeholder="OS" value="{{ os }}"></th>
|
||||||
<th><input type="text" name="hostname" id="hostname" placeholder="HOSTNAME" value="{{ hostname }}"></th>
|
<th><input type="text" name="hostname" id="hostname" placeholder="HOSTNAME" value="{{ hostname }}"></th>
|
||||||
@@ -29,4 +30,5 @@
|
|||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class='result-count'>{{targets|count}}</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
+7
-1
@@ -15,6 +15,12 @@ def post_home():
|
|||||||
"""Render website's home page with applied filters."""
|
"""Render website's home page with applied filters."""
|
||||||
targets = db.session.query(target)
|
targets = db.session.query(target)
|
||||||
|
|
||||||
|
clientId = request.form.get("clientId")
|
||||||
|
if clientId:
|
||||||
|
targets = targets.where(target.clientId == clientId)
|
||||||
|
else:
|
||||||
|
clientId = "default"
|
||||||
|
|
||||||
os = request.form.get("os")
|
os = request.form.get("os")
|
||||||
if os:
|
if os:
|
||||||
targets = targets.where(target.os == os)
|
targets = targets.where(target.os == os)
|
||||||
@@ -33,7 +39,7 @@ def post_home():
|
|||||||
targets = targets.filter(target.ports.like('%|'+port+'|%'))
|
targets = targets.filter(target.ports.like('%|'+port+'|%'))
|
||||||
|
|
||||||
|
|
||||||
return render_template('home.html', targets=targets.all(), os=os,hostname=hostname,address=address,ports=ports)
|
return render_template('home.html', targets=targets.all(), os=os,hostname=hostname,address=address,ports=ports,clientId=clientId)
|
||||||
|
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
|
|||||||
@@ -7,27 +7,28 @@ import re
|
|||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Convert your nmap scans into a sqlite database!')
|
parser = argparse.ArgumentParser(description='Convert your nmap scans into a sqlite database!')
|
||||||
parser.add_argument('-d', type=str, help='The database file to use',default='app/scanned.db')
|
|
||||||
parser.add_argument('-x', type=str, help='The xml file to read from, please use -oX with nmap')
|
parser.add_argument('-x', type=str, help='The xml file to read from, please use -oX with nmap')
|
||||||
|
parser.add_argument('-d', type=str, help='The database file to use',default='app/scanned.db')
|
||||||
|
parser.add_argument('-i', type=str, help='The name to use for the client',default="default")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if(args.d == None or args.x == None):
|
if(args.d == None or args.x == None):
|
||||||
raise("Must have a database and xml file!")
|
raise("Must have a database and xml file!")
|
||||||
|
|
||||||
|
|
||||||
class target:
|
class target:
|
||||||
def __init__(self, os,hostname,address,ports):
|
def __init__(self, os,hostname,address,ports,clientId):
|
||||||
self.os = os
|
self.os = os
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.address = address
|
self.address = address
|
||||||
self.ports = ports
|
self.ports = ports
|
||||||
|
self.clientId = clientId
|
||||||
|
|
||||||
def ptarg(self):
|
def ptarg(self):
|
||||||
print("{}\n{}\n{}\n{}\n".format(self.os,self.hostname,self.address,self.ports))
|
print("{}\n{}\n{}\n{}\n{}\n".format(self.os,self.hostname,self.address,self.ports,clientId))
|
||||||
|
|
||||||
def add(self,conn):
|
def add(self,conn):
|
||||||
add_item(conn,self.os,self.hostname,self.address,self.ports)
|
add_item(conn,self.os,self.hostname,self.address,self.ports,self.clientId)
|
||||||
|
|
||||||
|
|
||||||
def create_connection(database):
|
def create_connection(database):
|
||||||
@@ -48,11 +49,11 @@ def create_table(conn, create_table_sql):
|
|||||||
except Error as e:
|
except Error as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def add_item(conn, os, hostname, address, ports):
|
def add_item(conn, os, hostname, address, ports, clientId):
|
||||||
""" Create a table in the database """
|
""" Create a table in the database """
|
||||||
values = (os,hostname,address,ports)
|
values = (os,hostname,address,ports,clientId)
|
||||||
query = """ INSERT into targets (os,hostname,address,ports)
|
query = """ INSERT into targets (os,hostname,address,ports,clientId)
|
||||||
VALUES(?,?,?,?); """
|
VALUES(?,?,?,?,?); """
|
||||||
try:
|
try:
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute(query, values)
|
c.execute(query, values)
|
||||||
@@ -75,7 +76,8 @@ def main():
|
|||||||
os text,
|
os text,
|
||||||
hostname text,
|
hostname text,
|
||||||
address text,
|
address text,
|
||||||
ports text
|
ports text,
|
||||||
|
clientId text
|
||||||
); """
|
); """
|
||||||
create_table(conn, targetTableCreate)
|
create_table(conn, targetTableCreate)
|
||||||
|
|
||||||
@@ -90,6 +92,7 @@ def main():
|
|||||||
hostname = None
|
hostname = None
|
||||||
address = None
|
address = None
|
||||||
ports = []
|
ports = []
|
||||||
|
clientId = args.i
|
||||||
|
|
||||||
for o in host.iter('osclass'):
|
for o in host.iter('osclass'):
|
||||||
os = str(o.attrib['osfamily'])
|
os = str(o.attrib['osfamily'])
|
||||||
@@ -104,14 +107,12 @@ def main():
|
|||||||
for port in host.iter('port'):
|
for port in host.iter('port'):
|
||||||
ports.append(str(port.attrib['portid']))
|
ports.append(str(port.attrib['portid']))
|
||||||
|
|
||||||
|
targets.append(target(os, hostname, address, '|'+'|'.join(ports)+'|',clientId))
|
||||||
|
|
||||||
targets.append(target(os, hostname, address, '|'+'|'.join(ports)+'|'))
|
|
||||||
# Write the targets to the database
|
# Write the targets to the database
|
||||||
for tar in targets:
|
for tar in targets:
|
||||||
tar.add(conn)
|
tar.add(conn)
|
||||||
#print(tar.ptarg())
|
#print(tar.ptarg())
|
||||||
print(f"[*] Added {len(targets)} targets")
|
print(f"[*] Added {len(targets)} targets to {args.i}")
|
||||||
|
|
||||||
# Close the database connection
|
# Close the database connection
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ parser.add_argument('-c', type=str, help='The columns to return, comma separated
|
|||||||
parser.add_argument('-d', type=str, help='The database file to use',default='app/scanned.db')
|
parser.add_argument('-d', type=str, help='The database file to use',default='app/scanned.db')
|
||||||
parser.add_argument('-p', type=str, help='The ports to return, comma separated',default="%")
|
parser.add_argument('-p', type=str, help='The ports to return, comma separated',default="%")
|
||||||
parser.add_argument('-e', help='Just print the table column headers', action='store_true')
|
parser.add_argument('-e', help='Just print the table column headers', action='store_true')
|
||||||
|
parser.add_argument('-i', type=str, help='The client name to use',default="default")
|
||||||
parser.add_argument('-s', type=str, help='Specify the ouput separator',default=",")
|
parser.add_argument('-s', type=str, help='Specify the ouput separator',default=",")
|
||||||
parser.add_argument('-t', type=str, help='The database table',default="targets")
|
parser.add_argument('-t', type=str, help='The database table',default="targets")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -35,10 +36,10 @@ def get_db_cols(conn, table):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def query_db(conn, columns, table, ports):
|
def query_db(conn, columns, table, ports, clientId):
|
||||||
""" Create a table in the database """
|
""" Create a table in the database """
|
||||||
queryPorts = ' AND ports LIKE '.join(['"%|'+str(port)+'|%"' for port in ports])
|
queryPorts = ' AND ports LIKE '.join(['"%|'+str(port)+'|%"' for port in ports])
|
||||||
query = f"SELECT {columns} from {table} WHERE ports LIKE {queryPorts}"
|
query = f"SELECT {columns} from {table} WHERE clientId LIKE {clientId} and ports LIKE {queryPorts}"
|
||||||
try:
|
try:
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute(query)
|
c.execute(query)
|
||||||
@@ -56,7 +57,7 @@ def main():
|
|||||||
print(f'{args.s}'.join([row[1] for row in rows]))
|
print(f'{args.s}'.join([row[1] for row in rows]))
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
rows = query_db(conn, args.c, args.t, args.p.split(","))
|
rows = query_db(conn, args.c, args.t, args.p.split(","), args.i)
|
||||||
for row in rows:
|
for row in rows:
|
||||||
print(f'{args.s}'.join([str(item) for item in row]))
|
print(f'{args.s}'.join([str(item) for item in row]))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user