From 3a18f608aa216105c30e7b2ac0ea9a72447caf4b Mon Sep 17 00:00:00 2001 From: rain Date: Thu, 25 May 2023 11:41:08 -0500 Subject: [PATCH] Added support for multiple clients, and a filter count display at the bottom-right of the page --- app/models.py | 6 ++++-- app/static/css/style.css | 14 +++++++++++++- app/templates/home.html | 2 ++ app/views.py | 8 +++++++- parser.py | 29 +++++++++++++++-------------- query.py | 7 ++++--- 6 files changed, 45 insertions(+), 21 deletions(-) diff --git a/app/models.py b/app/models.py index 8d860e5..2611ee5 100644 --- a/app/models.py +++ b/app/models.py @@ -1,18 +1,20 @@ from app import db class target(db.Model): - __tablename__ = 'targets' + __tablename__ = "targets" id = db.Column(db.Integer, primary_key = True) os = db.Column(db.String()) hostname = db.Column(db.String()) address = 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.hostname = hostname self.address = address self.ports = ports + self.clientId = clientId def __repr__(self): return '
' % self.address diff --git a/app/static/css/style.css b/app/static/css/style.css index 7f939f6..d56cb0f 100755 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -92,8 +92,9 @@ a:hover, a:link, a:visited, a:active{ input[type=text]{ background: transparent; - color: var(--header-text); border: 0; + border-bottom: 2px solid var(--accent-color); + color: var(--header-text); width: 100%; height: 100%; text-align: center; @@ -108,4 +109,15 @@ input[type=text]{ } ::-ms-input-placeholder { /* Microsoft Edge */ 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); } \ No newline at end of file diff --git a/app/templates/home.html b/app/templates/home.html index 15fb396..a5141f9 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -8,6 +8,7 @@
+ @@ -29,4 +30,5 @@ +
{{targets|count}}
{% endblock %} diff --git a/app/views.py b/app/views.py index cb195c6..3469f97 100644 --- a/app/views.py +++ b/app/views.py @@ -15,6 +15,12 @@ def post_home(): """Render website's home page with applied filters.""" 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") if os: targets = targets.where(target.os == os) @@ -33,7 +39,7 @@ def post_home(): 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 diff --git a/parser.py b/parser.py index 3d62caf..6ba4081 100755 --- a/parser.py +++ b/parser.py @@ -7,27 +7,28 @@ 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',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('-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() 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): + def __init__(self, os,hostname,address,ports,clientId): self.os = os self.hostname = hostname self.address = address self.ports = ports + self.clientId = clientId 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): - 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): @@ -48,11 +49,11 @@ def create_table(conn, create_table_sql): except Error as 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 """ - values = (os,hostname,address,ports) - query = """ INSERT into targets (os,hostname,address,ports) - VALUES(?,?,?,?); """ + values = (os,hostname,address,ports,clientId) + query = """ INSERT into targets (os,hostname,address,ports,clientId) + VALUES(?,?,?,?,?); """ try: c = conn.cursor() c.execute(query, values) @@ -75,7 +76,8 @@ def main(): os text, hostname text, address text, - ports text + ports text, + clientId text ); """ create_table(conn, targetTableCreate) @@ -90,6 +92,7 @@ def main(): hostname = None address = None ports = [] + clientId = args.i for o in host.iter('osclass'): os = str(o.attrib['osfamily']) @@ -104,14 +107,12 @@ def main(): for port in host.iter('port'): ports.append(str(port.attrib['portid'])) - - - targets.append(target(os, hostname, address, '|'+'|'.join(ports)+'|')) + targets.append(target(os, hostname, address, '|'+'|'.join(ports)+'|',clientId)) # Write the targets to the database for tar in targets: tar.add(conn) #print(tar.ptarg()) - print(f"[*] Added {len(targets)} targets") + print(f"[*] Added {len(targets)} targets to {args.i}") # Close the database connection conn.commit() diff --git a/query.py b/query.py index d0132e7..10998eb 100755 --- a/query.py +++ b/query.py @@ -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('-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('-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('-t', type=str, help='The database table',default="targets") args = parser.parse_args() @@ -35,10 +36,10 @@ def get_db_cols(conn, table): exit(1) -def query_db(conn, columns, table, ports): +def query_db(conn, columns, table, ports, clientId): """ Create a table in the database """ 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: c = conn.cursor() c.execute(query) @@ -56,7 +57,7 @@ def main(): print(f'{args.s}'.join([row[1] for row in rows])) 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: print(f'{args.s}'.join([str(item) for item in row]))