This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit d129a22a2d8df344d9585e2e79348afd7553e9ad Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Jan 29 15:44:22 2015 +0100 websocket en place pour la premiere detection --- app/app.py | 19 ++++++++++--------- app/detection_modules/nmap_detection.py | 17 ++++++++--------- res.xml | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/app.py b/app/app.py index 01b77e4..566a6d7 100755 --- a/app/app.py +++ b/app/app.py @@ -1,24 +1,24 @@ __author__ = 'aguilbaud' from bottle import * -from detection_modules.nmap_detection import check_ip_range, get_current_ip, get_scanned_ip +from detection_modules.nmap_detection import check_ip_range from bottle_websocket import GeventWebSocketServer from bottle_websocket import websocket import json import threading -state = "" - class ThreadDetect(threading.Thread): - def __init__(self, ip_range): + def __init__(self, ip_range, ws): threading.Thread.__init__(self) self.ip_range = ip_range + self.ws = ws def run(self): - global state - check_ip_range(self.ip_range) - state = "Scan termine" + req = {} + check_ip_range(self.ip_range, self.ws) + req["state"] = "Scan termine" + self.ws.send(json.dumps(req)) @route('/') def index(section='home'): @@ -35,7 +35,7 @@ def start_first_detection(ip_range, ws): req = {} if re.search('^\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?[.]\d{1,3}(-\d{1,3})?$', ip_range): #state = "Scan de l'adresse : " - t = ThreadDetect(ip_range) + t = ThreadDetect(ip_range, ws) t.start() else: req["error"] = "La plage d'IP est mal formatee" @@ -55,6 +55,7 @@ def static(filepath): def bower_files(filepath): return static_file(filepath, root='bower_components') +""" @get('/getstate') def getstate(): global state @@ -65,7 +66,7 @@ def getstate(): for ip in scanned_ip: res += ip + ' : ' + scanned_ip[ip] return res - +""" @get('/websocket', apply=[websocket]) def echo(ws): diff --git a/app/detection_modules/nmap_detection.py b/app/detection_modules/nmap_detection.py index 87fa9e7..45e8f26 100644 --- a/app/detection_modules/nmap_detection.py +++ b/app/detection_modules/nmap_detection.py @@ -2,13 +2,11 @@ from xml.dom import minidom import pexpect import json -current_ip = "" - scanned_ip = {} # fonction qui permet de decomposer les differentes plages d'ip # lance la detection nmap pour chacune des ip comprises dans cette plage -def check_ip_range(ip_range): +def check_ip_range(ip_range, ws): # separation des 4 octets byte1 = ip_range.split('.')[0] byte2 = ip_range.split('.')[1] @@ -51,7 +49,7 @@ def check_ip_range(ip_range): for j in range(int(split_byte2[0]), int(split_byte2[1]) + 1): for k in range(int(split_byte3[0]), int(split_byte3[1]) + 1): for l in range(int(split_byte4[0]), int(split_byte4[1]) + 1): - launch_detection(i, j, k, l) + launch_detection(i, j, k, l, ws) # verifie que la plage de donnee entree est dans l'ordre croissant @@ -70,10 +68,11 @@ def check_order_and_under_255(tab_val): # lance la detection a l'aide de nmap sur l'ip representee par les 4 octets passes en parametres -def launch_detection(b1, b2, b3, b4): - global current_ip +def launch_detection(b1, b2, b3, b4, ws): + req = {} ip = str(b1) + '.' + str(b2) + '.' + str(b3) + '.' + str(b4) - current_ip = ip + req["state"] = "Scan de l'IP " + ip + " en cours..." + ws.send(json.dumps(req)) child = pexpect.spawn('nmap', ['-A', ip, '-oX', 'res.xml']) res = '' # ici : possibilite de verifier l'avancement du scan, si option verbose (-v3) activee dans la commande nmap @@ -86,10 +85,9 @@ def launch_detection(b1, b2, b3, b4): parse_res(ip) except pexpect.TIMEOUT: res += ' TIMEOUT' - current_ip = "" return res - +''' def get_current_ip(): global current_ip return current_ip @@ -98,6 +96,7 @@ def get_current_ip(): def get_scanned_ip(): global scanned_ip return scanned_ip +''' # parse le resultat xml de nmap pour ne conserver que les valeurs interssantes # envoie directement le resultat sur le service ElasticSearch diff --git a/res.xml b/res.xml index d4a0732..ef6f0d4 100644 --- a/res.xml +++ b/res.xml @@ -1,10 +1,10 @@ <?xml version="1.0"?> <?xml-stylesheet href="file:///usr/bin/../share/nmap/nmap.xsl" type="text/xsl"?> -<!-- Nmap 6.40 scan initiated Thu Jan 29 12:45:57 2015 as: /usr/bin/nmap -A -oX res.xml 198.116.0.10 --> -<nmaprun scanner="nmap" args="/usr/bin/nmap -A -oX res.xml 198.116.0.10" start="1422531957" startstr="Thu Jan 29 12:45:57 2015" version="6.40" xmloutputversion="1.04"> +<!-- Nmap 6.40 scan initiated Thu Jan 29 15:43:56 2015 as: /usr/bin/nmap -A -oX res.xml 198.116.0.10 --> +<nmaprun scanner="nmap" args="/usr/bin/nmap -A -oX res.xml 198.116.0.10" start="1422542636" startstr="Thu Jan 29 15:43:56 2015" version="6.40" xmloutputversion="1.04"> <scaninfo type="connect" protocol="tcp" numservices="1000" services="1,3-4,6-7,9,13,17,19-26,30,32-33,37,42-43,49,53,70,79-85,88-90,99-100,106,109-111,113,119,125,135,139,143-144,146,161,163,179,199,211-212,222,254-256,259,264,280,301,306,311,340,366,389,406-407,416-417,425,427,443-445,458,464-465,481,497,500,512-515,524,541,543-545,548,554-555,563,587,593,616-617,625,631,636,646,648,666-668,683,687,691,700,705,711,714,720,722,726,749,765,777,783,787,800-801,808,843,873,880,888,898,900-9 [...] <verbose level="0"/> <debugging level="0"/> -<runstats><finished time="1422531961" timestr="Thu Jan 29 12:46:01 2015" elapsed="3.15" summary="Nmap done at Thu Jan 29 12:46:01 2015; 1 IP address (0 hosts up) scanned in 3.15 seconds" exit="success"/><hosts up="0" down="1" total="1"/> +<runstats><finished time="1422542639" timestr="Thu Jan 29 15:43:59 2015" elapsed="3.15" summary="Nmap done at Thu Jan 29 15:43:59 2015; 1 IP address (0 hosts up) scanned in 3.15 seconds" exit="success"/><hosts up="0" down="1" total="1"/> </runstats> </nmaprun> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.