def index(req): req.content_type = "text/html" content = str() #sql part conn = connexionBD() cur = conn.cursor() sql = "SELECT * FROM paquet ORDER BY heure DESC LIMIT 20;" sql_count = "SELECT COUNT(*) FROM paquet;" cur.execute(sql) conn.commit() data = cur.fetchall() cur.execute(sql_count) conn.commit() count = cur.fetchone() count = str(count[0]) conn.close() #sql part #takes every lines from the select for i in data: content += ("""<tr>""" + """<td>""" + str(i[1]) + """</td>""" + """<td>""" + str(i[2]) + """</td>""" + """<td>""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """</td>""" + """<td>""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """</td>""" + """<td>""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """</td>""" + """<td>""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """</td>""" + """</tr>""") #write the html page req.write( baseHTML( "ATS - Accueil", """ <h1>ATS</h1> <div id="tip" style="display:block;"> Afin de voir le reverse DNS d'une adresse IP, cliquez sur cette dernière dans le tableau <button id="ok" onclick="toggle_div(this,'tip');">OK</button></div> <p>Nombre total de paquets : <b>""" + count + """</b></p> <em>Pour afficher toute la table, cliquez</em> <button id="afficheTas" onclick="affiche_tas()">ICI</button><br/> <div id="tab"> <table class="data_tab"> <tr><th>Heure</th><th>Protocole</th><th>IP Source</th><th>IP Destination</th><th>Port Source</th><th>Port Destination</th></tr> """ + content + """ </table> </div> <script src="tip.js"></script> <script src="tas.js"></script> """))
def index(req): req.content_type = "text/html" content = str() #write the html page req.write( baseHTML( "ATS - Filtrage", """ <h1>Filtrage</h1> <div id="tip" style="display:block;"> Afin de voir le reverse DNS d'une adresse IP, cliquez sur cette dernière dans le tableau <button id="ok" onclick="toggle_div(this,'tip');">OK</button></div> <b>Filtre</b> <input type="text" id="condition" onkeyup="cherche()"> <div id="tab"> </div> <script src="filtre.js"></script> <script src="tip.js"></script> """))
def index(req): req.content_type="text/html" content=str() #write the html page req.write(baseHTML("ATS - Syntaxe",""" <h1>Syntaxe</h1> <p>La """+lien('syntaxe.py','syntaxe')+""" pour utiliser les filtres disponibles sur la page """+lien('filtrage.py','filtrage')+""" est la suivante :</p> <p><colonne>='<valeur>'</p><br/> <table> <tr><th>colonne</th><th>valeur</th><th>exemple</th></tr> <tr><td>heure</td><td>hh:mm:ss</td><td>heure='10:41:30'</td></tr> <tr><td>protocole</td><td>texte</td><td>protocole='TCP'</td></tr> <tr><td>ip_source</td><td>W.X.Y.Z</td><td>ip_source='10.0.2.15'</td></tr> <tr><td>ip_destination</td><td>W.X.Y.Z</td><td>ip_destination='1.1.1.1'</td></tr> <tr><td>port_source</td><td>X</td><td>port_source='35042'</td></tr> <tr><td>port_destination</td><td>X</td><td>port_destination='80'</td></tr> </table> """))
def index(req): req.content_type="text/html" #partie socket #check si ip est bien la try: ip=req.form["ip"] except KeyError: mod_python.util.redirect(req, "index.py") #check si ip a le bon format try: socket.inet_aton(ip) except socket.error: mod_python.util.redirect(req, "index.py") content=str() #reverse dns try: rdns=socket.gethostbyaddr(ip)[0] except socket.herror: rdns="<em>Non connu</em>" #partie socket #sql part conn=connexionBD() cur=conn.cursor() sql="SELECT * FROM paquet WHERE ip_source=%s ORDER BY heure DESC" sql_count="SELECT COUNT(*) FROM paquet WHERE ip_source=%s" cur.execute(sql, (ip, )) conn.commit() data=cur.fetchall() cur.execute(sql_count, (ip, )) conn.commit() count=cur.fetchone() conn.close() #sql part #takes every lines from the select for i in data : content+=("""<tr>""" + """<td>""" + str(i[1]) + """</td>""" + """<td>""" + str(i[2]) + """</td>""" + """<td>""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """</td>""" + """<td>""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """</td>""" + """<td>""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """</td>""" + """<td>""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """</td>""" + """</tr>""") #write the html page req.write(baseHTML("ATS - " + ip,""" <h1>IP source : """ + ip + """</h1> <p>Nombre de paquets venant de """+ ip + """ : <b>"""+ str(count[0])+ """</b></p> <p>Reverse DNS : <b>"""+rdns+"""</b><p> <div id="tab"> <table class="data_tab"> <tr><th>Heure</th><th>Protocole</th><th>IP Source</th><th>IP Destination</th><th>Port Source</th><th>Port Destination</th></tr> """ + content + """ </table> </div> """))
def index(req): req.content_type = "text/html" ipdst = str() portdst = str() ipsrc = str() portsrc = str() #sql part conn = connexionBD() cur = conn.cursor() ### sql = [ "SELECT COUNT(*) FROM paquet", "SELECT COUNT(DISTINCT ip_source) FROM paquet", "SELECT COUNT(DISTINCT ip_destination) FROM paquet", "SELECT COUNT(DISTINCT port_source) FROM paquet", "SELECT COUNT(DISTINCT port_destination) FROM paquet", "SELECT COUNT(*) FROM paquet WHERE (heure>=( SELECT LOCALTIME - interval '1 hour' ) AND heure<= (SELECT LOCALTIME));" ] var = [ "total", "total_ip_src", "total_ip_dst", "total_port_src", "total_port_dst", "total_uneheure" ] for x, y in zip(sql, var): cur.execute(x) conn.commit() globals()[y] = str(cur.fetchone()[0]) # sql = [ "SELECT ip_destination, COUNT(ip_destination) FROM paquet GROUP BY ip_destination ORDER BY count DESC", "SELECT port_destination, COUNT(port_destination) FROM paquet GROUP BY port_destination ORDER BY count DESC", "SELECT ip_source, COUNT(ip_source) FROM paquet GROUP BY ip_source ORDER BY count DESC", "SELECT port_source, COUNT(port_source) FROM paquet GROUP BY port_source ORDER BY count DESC" ] var = ["each_ip_dst", "each_port_dst", "each_ip_src", "each_port_src"] for x, y in zip(sql, var): cur.execute(x) conn.commit() globals()[y] = cur.fetchall() ### conn.close() #sql part champs = ["ip", "port"] suff = ["dst", "src"] global each_ip_dst global each_ip_src global each_port_dst global each_port_src global ipdst global ipsrc global portdst global portsrc for j in champs: for k in suff: nom = "each_" + j + "_" + k for i in globals()[nom]: if j == "ip" and k == "dst": globals()[j + k] += ("""<tr> <td>""" + lien('ip_destination.py?ip=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") elif j == "port" and k == "dst": globals()[j + k] += ("""<tr> <td>""" + lien('port_destination.py?port=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") elif j == "ip" and k == "src": globals()[j + k] += ("""<tr> <td>""" + lien('ip_source.py?ip=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") else: globals()[j + k] += ("""<tr> <td>""" + lien('port_source.py?port=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") #write the html page req.write( baseHTML( "ATS - Bilan", """ <h1>Bilan</h1> <div id="tip" style="display:block;"> Afin de voir le reverse DNS d'une adresse IP, cliquez sur cette dernière dans le tableau <button id="ok" onclick="toggle_div(this,'tip');">OK</button></div> <ul> <li>Nombre total de paquets : <b>""" + total + """</b></li> <li>Nombre total de paquets depuis 1h : <b>""" + total_uneheure + """</b></li> <li>Nombre total d'adresses IP source differentes : <b>""" + total_ip_src + """</b></li> <li>Nombre total d'adresses IP destination differentes : <b>""" + total_ip_dst + """</b></li> <li>Nombre total de ports source differents : <b>""" + total_port_src + """</b></li> <li>Nombre total de ports destination differents : <b>""" + total_port_dst + """</b></li> </ul> <div id="bilan_tab"> <table class="inlineTable"> <tr><th>IP destination</th><th>Récurrence</th></tr> """ + str(ipdst) + """ </table> <table class="inlineTable"> <tr><th>Port destination</th><th>Récurrence</th></tr> """ + str(portdst) + """ </table> <table class="inlineTable"> <tr><th>IP source</th><th>Récurrence</th></tr> """ + str(ipsrc) + """ </table> <table class="inlineTable"> <tr><th>Port source</th><th>Récurrence</th></tr> """ + str(portsrc) + """ </table> </div> <script src="tip.js"></script> """))
def index(req): req.content_type = "text/html" #check si ip est bien la try: port = req.form["port"] except KeyError: mod_python.util.redirect(req, "index.py") #check si port a le bon format try: float(port) except ValueError: mod_python.util.redirect(req, "index.py") content = str() #sql part conn = connexionBD() cur = conn.cursor() sql = "SELECT * FROM paquet WHERE port_destination=%s ORDER BY heure DESC" sql_count = "SELECT COUNT(*) FROM paquet WHERE port_destination=%s" cur.execute(sql, (port, )) conn.commit() data = cur.fetchall() cur.execute(sql_count, (port, )) conn.commit() count = cur.fetchone() conn.close() #sql part #takes every lines from the select for i in data: content += ("""<tr>""" + """<td>""" + str(i[1]) + """</td>""" + """<td>""" + str(i[2]) + """</td>""" + """<td>""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """</td>""" + """<td>""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """</td>""" + """<td>""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """</td>""" + """<td>""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """</td>""" + """</tr>""") #write the html page req.write( baseHTML( "ATS - " + port, """ <h1>Port destination : """ + port + """</h1> <div id="tip" style="display:block;"> Afin de voir le reverse DNS d'une adresse IP, cliquez sur cette dernière dans le tableau <button id="ok" onclick="toggle_div(this,'tip');">OK</button></div> <p>Nombre de paquets en destination de """ + port + """ : <b>""" + str(count[0]) + """</b></p> <div id="tab"> <table class="data_tab"> <tr><th>Heure</th><th>Protocole</th><th>IP Source</th><th>IP Destination</th><th>Port Source</th><th>Port Destination</th></tr> """ + content + """ </table> </div> <script src="tip.js"></script> """))