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 f6c5213f788e75b93ebfb6ab6f3cb4115b9edd5b Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed May 27 15:44:50 2015 +0200 scan options can be specified on configuration file + scan page redone --- app/module_loader.py | 33 +++++++++++-------- app/websocket_func.py | 32 +++++++----------- mum.conf | 3 +- static/js/controllers/headCtrl.js | 3 ++ static/js/controllers/scanCtrl.js | 36 ++++++++------------- views/scan.html | 68 +++++++++++++++++++++++---------------- 6 files changed, 89 insertions(+), 86 deletions(-) diff --git a/app/module_loader.py b/app/module_loader.py index 6ca0034..03f5fbc 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -53,6 +53,10 @@ class ModuleLoader: def get_websocket_container(self): return self.wsc + + def get_scan_options(self): + return json.loads(self.conf['scan']) + """ def get_all_known_ports(self): res = [] @@ -112,24 +116,27 @@ class ModuleLoader: ws.send(json.dumps({"ERROR": hnfe.__str__()})) return None - def create_empty_host(self, addr_host): + def create_empty_host(self, addr_host, ws): """ If for some reason the nmap scan is impossible, it is possible to add a host without preliminary nmap scan. Therefore, a fake empty nmap result is generated and the host is added this way on the database. :param addr_host: a string containing the IP address of the host. """ - fake_nmap_res = {} - fake_nmap_res['os'] = 'unknown' - fake_nmap_res['addr'] = addr_host - fake_nmap_res['hostname'] = '' - fake_nmap_res['openports'] = [] - self.db.add_host(addr_host, - json.dumps(fake_nmap_res), - self.get_conection_modules_list(), - self.get_monitoring_modules_list()) - monitoring_intructions = self.db.get_monitoring_instructions(addr_host) - for instr in monitoring_intructions: - self.add_to_waiting_list(instr) + if re.search('^\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}$', addr_host): + fake_nmap_res = {} + fake_nmap_res['os'] = 'unknown' + fake_nmap_res['addr'] = addr_host + fake_nmap_res['hostname'] = '' + fake_nmap_res['openports'] = [] + self.db.add_host(addr_host, + json.dumps(fake_nmap_res), + self.get_conection_modules_list(), + self.get_monitoring_modules_list()) + monitoring_intructions = self.db.get_monitoring_instructions(addr_host) + for instr in monitoring_intructions: + self.add_to_waiting_list(instr) + else: + ws.send(json.dumps({"ERROR": "You must specify a valid IP address to add a host without scan"})) def create_connection(self, addr_host, conf_conn): """ diff --git a/app/websocket_func.py b/app/websocket_func.py index 83552eb..1eaafff 100644 --- a/app/websocket_func.py +++ b/app/websocket_func.py @@ -32,17 +32,6 @@ class ThreadDetect(threading.Thread): for instr in monitoring_intructions: self.ml.add_to_waiting_list(instr) self.ml.remove_task(task_name) - """ - # now launching full detection - for ip in json.loads(scanned_ip): - conn = module_loader.load_conn("ssh", ip, "aguilbaud", "/home/aguilbaud/.ssh/id_rsa") - module_loader.run_all_detection_modules(db.get_host_os(ip), conn, db, self.ws) - monitoring_intructions = db.get_monitoring_instructions(ip) - for instr in monitoring_intructions: - process_monitoring.add_to_waiting_list(instr) - #module_loader.run_all_monitoring_modules("unix", conn, db, self.ws) - # adding entries on process monitoring - """ # Launching of the detection after getting a ip range. @@ -55,17 +44,14 @@ def start_first_detection(args, ml, ws): # asked from scan page def NMAP_SCAN_DEMAND(msg, ws, ml): - if os.getegid() != 0: - print "Error: Cannot run nmap without root privileges." - ws.send(json.dumps({"ERROR": "Cannot run nmap without root privileges."})) + if msg["NMAP_SCAN_DEMAND"]["nmap_options"] == '': + ml.create_empty_host(msg["NMAP_SCAN_DEMAND"]["ip_range"], ws) else: - start_first_detection(msg["NMAP_SCAN_DEMAND"], ml, ws) - - -# asked from scan page -def CREATE_EMPTY_HOST(msg, ws, ml): - ml.create_empty_host(msg["CREATE_EMPTY_HOST"]) - ws.send(json.dumps({"SUCCESS_MODULE": "Creation of new host"})) + if os.getegid() != 0: + print "Error: Cannot run nmap without root privileges." + ws.send(json.dumps({"ERROR": "Cannot run nmap without root privileges."})) + else: + start_first_detection(msg["NMAP_SCAN_DEMAND"], ml, ws) # asked from hostpage @@ -166,3 +152,7 @@ def GET_KEYS_LIST(msg, ws, ml): # asked from the header controller def TASK_LIST(msg, ws, ml): ws.send(json.dumps({"RES_TASK_LIST": ml.get_db().get_task_list()})) + + +def GET_SCAN_OPTIONS(msg, ws, ml): + ws.send(json.dumps({"RES_GET_SCAN_OPTIONS": ml.get_scan_options()})) \ No newline at end of file diff --git a/mum.conf b/mum.conf index 1524f55..df375cf 100644 --- a/mum.conf +++ b/mum.conf @@ -5,4 +5,5 @@ external_modules_location= keys_location= smtp_server= smtp_port= -smtp_address= \ No newline at end of file +smtp_address= +scan={"Scan and detect": "-sU -sS -p U:161,T:1-65535 -A -Pn", "Scan only": "-sU -sS -p U:161,T:1-65535", "No scan": ""} \ No newline at end of file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index 993e171..65415f8 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -71,6 +71,9 @@ mumApp.controller('headCtrl', function ($scope, $rootScope, toastr, $interval, $ case "RES_GET_ALL_SUBSCRIPTIONS": $rootScope.$broadcast("resGetAllSubscriptions", obj[key]); break; + case "RES_GET_SCAN_OPTIONS": + $rootScope.$broadcast("resGetScanOptions", obj[key]); + break; case "RES_CALL_FUNC_DB": // Get a result after calling a funcion on the db $rootScope.$broadcast("resCall", obj[key]); break; diff --git a/static/js/controllers/scanCtrl.js b/static/js/controllers/scanCtrl.js index 711f48a..49e259e 100644 --- a/static/js/controllers/scanCtrl.js +++ b/static/js/controllers/scanCtrl.js @@ -1,6 +1,8 @@ -mumApp.controller('scanCtrl', function ($scope, $rootScope, $routeParams) { +mumApp.controller('scanCtrl', function ($scope, $rootScope, $routeParams, $timeout) { // Concerning the scan form + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_SCAN_OPTIONS": null})); + if ($routeParams.param == null) { $scope.ip_range = ""; // la plage d'ip entree dans le champ } @@ -8,35 +10,23 @@ mumApp.controller('scanCtrl', function ($scope, $rootScope, $routeParams) { $scope.ip_range = $routeParams.param; } - $scope.state = ""; // l'etat general du scan en cours - $scope.ip_scanned = {}; - - $scope.ip_manual_field = ""; + $scope.nmap_options = {}; - $scope.show_opt = false; + $scope.selected_option = 'No scan'; - $scope.nmap_options = "-sU -sS -p U:161,T:1-65535 -A -Pn"; - - $scope.$on("success", function (event, args) { - $scope.state = "Success!"; - $scope.ip_scanned = args; - }); + $scope.nmap_options_input = ''; - $scope.$on("stateUpdate", function (event, args) { - $scope.state = args; + $scope.$on("resGetScanOptions", function (event, args) { + $timeout(function () { + $scope.nmap_options = args; + }, 0); }); - $scope.validated = false; // pour afficher ou non certaines parties de la page - $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page - - $scope.post_val = function (){ //lace la detection apres remplissage du champ et validation du formulaire + $scope.run_detection = function (){ + $scope.ip_range = ""; var args = {}; args.ip_range = $scope.ip_range; - args.nmap_options = $scope.nmap_options; + args.nmap_options = $scope.nmap_options_input; $rootScope.$broadcast("sendViaWs", JSON.stringify({"NMAP_SCAN_DEMAND": args})); }; - - $scope.create_empty_host = function (){ - $rootScope.$broadcast("sendViaWs", JSON.stringify({"CREATE_EMPTY_HOST": $scope.ip_manual_field})); - } }); \ No newline at end of file diff --git a/views/scan.html b/views/scan.html index 6beb234..d10206a 100644 --- a/views/scan.html +++ b/views/scan.html @@ -1,29 +1,41 @@ <div class="col-md-offset-2 main"> - <h1 class="page-header">Scan for new machines</h1> - <div ng-show="!validated" class="ng-hide"> - <form class="form-inline" ng_submit="post_val()"> - <label for="input_ip_range">Enter a hostname, a single IP or an IP range to scan (example : 198.116.0.1-10)</label> - <input type="text" class="form-control" id="input_ip_range" ng-model="ip_range"/><br/> - <button type="button" - class="btn btn-danger" - ng-click="show_opt = !show_opt">Show nmap options (careful)</button> - <input type="text" class="form-control" ng-show="show_opt" ng-model="nmap_options"/> - <button type="submit" - class="btn btn-primary" - ng-click="validated = true" - ng-disabled="ip_range == ''">Scan now</button> - <p>If you have trouble scanning with nmap on your server, you can add here a host manually, by - indicating its IP address :</p> - <input type="text" class="form-control" ng-model="ip_manual_field"/> - <button type="button" - class="btn btn-primary" - ng-click="create_empty_host()" - ng-disabled="ip_manual_field == ''">Add a host without scan</button> - </form> - - </div> - <div ng-show="validated"> - <p>{{state}}</p> - <p>Scanned IP : {{ip_scanned}}</p> - </div> -</div> + + <h1 class="page-header">Scan for new machines</h1> + + <p>Enter a hostname, a single IP or an IP range to scan:</p> + + <div class="row"> + <div class="col-xs-3"> + <input type="text" class="form-control" ng-model="ip_range"/><br/> + </div> + </div> + + <p>Select or type the nmap options to use for the scan:</p> + + <div class="row"> + <div class="col-xs-2" + ng-repeat="(optname, opt) in nmap_options"> + <input type="radio" name="selected_option" value="{{optname}}" + ng-model="$parent.selected_option" + ng-change="$parent.nmap_options_input = opt"> + {{optname}} + </div> + </div> + + <div class="row"> + <div class="col-md-6"> + <input type="text" class="form-control" + ng-model="nmap_options_input" + ng-change="selected_option = 'custom'"/> + </div> + </div> + + + <div class="row"> + <div class="col-xs-3"> + <button class="btn btn-primary" + ng-click="run_detection()" + ng-disabled="ip_range == ''">Scan now!</button> + </div> + </div> +</div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.