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 09d34dd7fca6e32779a6a5f56738f00e91f078cd Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Jan 29 15:59:31 2015 +0100 nettoyage du code --- app/app.py | 67 +++++++++------------------------ app/detection_modules/nmap_detection.py | 15 +++----- res.xml | 6 +-- static/js/controllers/detectCtrl.js | 54 ++------------------------ 4 files changed, 30 insertions(+), 112 deletions(-) diff --git a/app/app.py b/app/app.py index 566a6d7..cedca86 100755 --- a/app/app.py +++ b/app/app.py @@ -1,3 +1,5 @@ +# -*- coding: utf8 -*- +from __future__ import unicode_literals __author__ = 'aguilbaud' from bottle import * @@ -5,69 +7,64 @@ from detection_modules.nmap_detection import check_ip_range from bottle_websocket import GeventWebSocketServer from bottle_websocket import websocket import json - import threading +# Pour lancer la detection nmap avec un nouveau thread class ThreadDetect(threading.Thread): def __init__(self, ip_range, ws): threading.Thread.__init__(self) self.ip_range = ip_range self.ws = ws + def run(self): req = {} check_ip_range(self.ip_range, self.ws) - req["state"] = "Scan termine" + req["state"] = "Scan terminé" self.ws.send(json.dumps(req)) + @route('/') def index(section='home'): return template('index') + @route('/angular') def angular(): return template('angular') -#@post('/detect/<ip_range>') + +# Lancement de la detection apres reception d'une plage d'ip def start_first_detection(ip_range, ws): - #ip_range = request.forms.get('ip_range') - #global state req = {} + # Verification que l'ip est bien formatee 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 : " + # Si oui on lance la detection avec le module nmap_detection t = ThreadDetect(ip_range, ws) t.start() else: - req["error"] = "La plage d'IP est mal formatee" + # Si non, on envoie un message d'erreur + req["error"] = "La plage d'IP est mal formatée" ws.send(json.dumps(req)) - #state = "La plage d'IP est mal formatee" @error(404) def error404(error): return '<h1>Cette page n\'existe pas</h1>' +# Pour recuperer les fichiers statiques via l'url @get('/static/<filepath:path>') def static(filepath): return static_file(filepath, root='static') + +# Pour recuperer les dependances bower via l'url @get('/bower_components/<filepath:path>') def bower_files(filepath): return static_file(filepath, root='bower_components') -""" -@get('/getstate') -def getstate(): - global state - scanned_ip = get_scanned_ip() - res = state + get_current_ip() - if scanned_ip != {}: - res += "\n Completed : \n" - for ip in scanned_ip: - res += ip + ' : ' + scanned_ip[ip] - return res -""" +# Creation d'une websocket pour permettre la communication avec le client @get('/websocket', apply=[websocket]) def echo(ws): while True: @@ -76,38 +73,10 @@ def echo(ws): msg = json.loads(response) for title in msg: if title == "Sending_ip_range": - #print "launching scan for" + msg["Sending_ip_range"] start_first_detection(msg["Sending_ip_range"], ws) - #if msg is not None: - # ws.send(msg) - #else: - # break - - -''' -app = Bottle() - -@app.route('/websocket') -def handle_websocket(): - wsock = request.environ.get('wsgi.websocket') - if not wsock: - abort(400, 'Expected WebSocket request.') - while True: - try: - message = wsock.receive() - print message - wsock.send("Your message was: %r" % message) - except WebSocketError: - break -from gevent.pywsgi import WSGIServer -from geventwebsocket import WebSocketError -from geventwebsocket.handler import WebSocketHandler -server = WSGIServer(("0.0.0.0", 8181), app, - handler_class=WebSocketHandler) -server.serve_forever() -''' +# Lancement du serveur a l'adresse 0.0.0.0:1337 if __name__ == '__main__': port = int(os.environ.get('PORT', 1337)) run(host='0.0.0.0', port=port, debug=True, reloader=True, server=GeventWebSocketServer) diff --git a/app/detection_modules/nmap_detection.py b/app/detection_modules/nmap_detection.py index 45e8f26..7d59fd1 100644 --- a/app/detection_modules/nmap_detection.py +++ b/app/detection_modules/nmap_detection.py @@ -1,9 +1,14 @@ +# -*- coding: utf8 -*- +from __future__ import unicode_literals +__author__ = 'aguilbaud' + from xml.dom import minidom import pexpect import json 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, ws): @@ -87,16 +92,6 @@ def launch_detection(b1, b2, b3, b4, ws): res += ' TIMEOUT' return res -''' -def get_current_ip(): - global current_ip - return 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 ef6f0d4..0337730 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 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"> +<!-- Nmap 6.40 scan initiated Thu Jan 29 15:52:38 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="1422543158" startstr="Thu Jan 29 15:52:38 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="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><finished time="1422543161" timestr="Thu Jan 29 15:52:41 2015" elapsed="3.15" summary="Nmap done at Thu Jan 29 15:52:41 2015; 1 IP address (0 hosts up) scanned in 3.15 seconds" exit="success"/><hosts up="0" down="1" total="1"/> </runstats> </nmaprun> diff --git a/static/js/controllers/detectCtrl.js b/static/js/controllers/detectCtrl.js index 6ff43a1..6bd55aa 100644 --- a/static/js/controllers/detectCtrl.js +++ b/static/js/controllers/detectCtrl.js @@ -10,6 +10,8 @@ formExample.controller('ExampleController', ['$scope', '$http', '$interval', fun /*ws.onopen = function() { ws.send("Hello, world"); };*/ + + // actions effectuees lors de la reception d'un message via la websocket ws.onmessage = function (evt) { JSON.parse(evt.data, function (key, value) { if(key == "state"){ @@ -26,57 +28,9 @@ formExample.controller('ExampleController', ['$scope', '$http', '$interval', fun }; - //lace la detection apres remplissage du champ + //lace la detection apres remplissage du champ et validation du formulaire $scope.post_val = function(){ var request = '{"Sending_ip_range" : "' + $scope.ip_range + '"}'; ws.send(request); } - - /*$scope.check_state = function(){ - $interval(function() { - $http.get('/getstate'). - success(function(data, status, headers, config) { - $scope.state = data - // when the response is available - }). - error(function(data, status, headers, config) { - alert("Impossible d'acceder à l'état") - // called asynchronously if an error occurs - // or server returns response with an error status. - }); - }, 10000); - }*/ - - }]); - - -/*formExample.service("ipService", ["stateService", "$interval", - function(stateService, $timeout) { - //Variable privée - var current_ip = { - current_ip: "a", - }; - - //Getter pour la variable current_ip - this.get_current_ip = function() { - //Cette méthode fait appel à un autre service - $http.get('/getval'). - success(function(data, status, headers, config) { - current_ip = data - }). - error(function(data, status, headers, config) { - // called asynchronously if an error occurs - // or server returns response with an error status. - }); - return current_ip; - }; - - //5 secondes après le chargement de la page, la valeur d'une propriété change dans le service. - //La view est mise à jour automatiquement - $interval(function() { - formExample.service.get_current_ip() - }, 5000); - - - } -]);*/ +}]); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.