def launch(self): sem = Semaphore(0) try: scanner = VulnscanManager(config.omp_ip, config.omp_user, config.omp_password) task_id, target_id = scanner.launch_scan(target='https://log.cmbchina.com', profile="Full and fast", callback_end=partial(lambda x: x.release(), sem) ) print task_id, target_id sem.acquire() print("finished") report_id = scanner.get_report_id(task_id) self.result_name = task_id + '.csv' cmd = 'omp --get-report ' + report_id + ' --format ' + data.format_csv + ' > ' + self.result_name Utils.cmd_block(self.client, cmd) Utils.sftp_get(config.server_ip, config.port, config.server_user, config.server_password, self.result_name, './temp/server/'+self.result_name) except VulnscanException as e: print("Error:") print(e)
def my_launch_scanner(): sem = Semaphore(0) # Configure try: manager = VulnscanManager("127.0.0.1", "nishan", "e6cded22-43a3-4ca5-967f-5b3bf7eff4ce", 9390, 5) print "Connection successful" except: print "Connection failed" sys.exit(-1) # Launch try: scan_id, task_id = manager.launch_scan( target="127.0.0.1", profile="Full and fast", callback_end=partial(lambda x: x.release(), sem), callback_progress=my_print_status) print "Scan ID is : {}\n".format(t) print "Task Created Successfull" except: print "Task Creation Unsuccessfull" # Wait sem.acquire() # Finished scan print("finished") id = manager.get_report_id(scan_id) command = "omp -u nishan -w e6cded22-43a3-4ca5-967f-5b3bf7eff4ce -R {} > /home/nishan/logs/log.xml".format( id) system(command) sleep(2) now = datetime.now() index = "openvas-{}.{}.{}".format(now.year, now.month, now.day) np = OpenVasES('/home/nishan/logs/log.xml', '10.10.66.66', '9200', index) np.toES()
def main(): try: TARGET_IP = "127.0.0.1" OPENVAS_HOST = "127.0.0.1" USER = "******" PASSWORD = "******" PORT = 9390 TIMEOUT = None #profile = "empty" profile = "Full and fast" manager = VulnscanManager(OPENVAS_HOST, USER, PASSWORD) sem = Semaphore(0) # Launch scan_id, target_id = manager.launch_scan( target=TARGET_IP, profile=profile, callback_end=partial(lambda x: x.release(), sem), callback_progress=my_print_status) print "scan_id=%s , target_id=%s " % (scan_id, target_id) # Wait sem.acquire() # Finished scan print("finished") report_id = manager.get_report_id(scan_id) write_report(manager, report_id, TARGET_IP) manager.delete_scan(scan_id) manager.delete_target(target_id) except VulnscanException, e: print "Error:" print e
def launch_scanner(server, username, password, target, profile, args): global pbar try: sem = Semaphore(0) # configure the scan print_loading("Connecting to openVAS\r") manager = VulnscanManager(server, username, password) stdout.write("\033[K") print_ok("Connected to openVAS\n") # print_loading("Launching Scan\r") stdout.flush() pbar = ChargingBar("Scanning", max=100, suffix='%(percent)d%%') pbar.next(n=0) # pbar.next() scan_id, target_id = manager.launch_scan( target, profile=profile, callback_end=partial(lambda x: x.release(), sem), callback_progress=print_status) # wait sem.acquire() sleep(2) pbar.finish() stdout.write("\033[A") stdout.write("\033[K") stdout.flush() # print() # stdout.write("\033[K") # stdout.flush() print_ok("Finished Scan\n") # print_loading("Getting Report ID") report_id = manager.get_report_id(scan_id) # check if it has been specified to save the file as an xml if args.save_xml or args.save_all: print_loading("Getting XML Report ") report = manager.get_report_xml(report_id) # print(report) stdout.write("\r\033[K") stdout.flush() print_ok("Loaded XML Report\n") name = args.save_xml if not name.lower().endswith(".xml"): name += ".xml" print_loading("Attempting to save XML Report ") with open(name, "wb") as f: f.write( ElementTree.tostring(report, encoding="utf-8", method="xml")) stdout.write("\r\033[K") stdout.flush() print_ok("Saved XML Report as : {}\n".format(name)) # check if it has been specified to save the file as an html if args.save_html or args.save_all: print_loading("Getting HTML Report ") report = manager.get_report_html(report_id) html_text = report.find("report").text if not html_text: html_text = report.find("report").find("report_format").tail stdout.write("\r\033[K") stdout.flush() print_ok("Loaded HTML Report\n") name = args.save_html if not name.lower().endswith(".html"): name += ".html" print_loading("Attempting to save HTML Report ") with open(name, "wb") as f: f.write(base64.b64decode(html_text)) stdout.write("\r\033[K") stdout.flush() print_ok("Saved HTML Report as : {}\n".format(name)) print_ok("Scan ID : {}\n".format(scan_id)) print_ok("Target ID : {}\n".format(target_id)) print_ok("Report ID : {}\n".format(report_id)) # finished scan print_ok("Finished\n") except Exception as e: print_error(e) os._exit(-1)
def populate_openvas_data(data): """ Fetch OpenVAS data """ try: data['ovs'] = {} data['ovs']['host'] = {} data['ovs']['project'] = {} data['ovs']['data'] = {} ovc = data['config']['openvas'] ovs_report = None if DEBUG and os.path.isfile(DEBUG_OPENVAS_DATA): print("Warning: DEBUG is enabled, reading opemvas data from %s" % DEBUG_OPENVAS_DATA) ovs_report = ET.ElementTree().parse(DEBUG_OPENVAS_DATA) else: scanner = VulnscanManager(ovc['host'], ovc['user'], ovc['password'], int(ovc['port']), 30) finished_scans = scanner.get_finished_scans for entry in finished_scans: if ovc['scan'] is None or entry == ovc['scan']: report_id = scanner.get_report_id(finished_scans[entry]) ovs_report = ET.ElementTree( scanner.get_report_xml(report_id)) if DEBUG: ovs_report.write(DEBUG_OPENVAS_DATA) except VulnscanException as e: print(e) if ovs_report: for results in ovs_report.iter('results'): for result in results: ret = {} host = result.find('host').text details = result.findall('./detection/result/details/detail') for detail in details: # typically product, location, source_oid and source_name label = detail.find('name').text value = detail.find('value').text ret[label] = value if host not in data['os']['hosts']: print("IP '%s' is unknown" % host) else: project_id = data['os']['hosts'][host] project = data['os']['projects'][project_id]['name'] projects = data['ovs']['project'] if project not in projects: projects[project] = {} projects[project].update({'host': {}, 'emails': {}}) projects[project]['emails'].update( data['os']['projects'][project_id]['emails']) hosts = projects[project]['host'] if host not in hosts: hosts[host] = {} hosts[host]['ports'] = {} hosts[host]['threat'] = '' hosts[host]['severity'] = '' if ret['location'] not in hosts[host]['ports']: hosts[host]['ports'].update({ret['location']: []}) ret['severity'] = result.find('severity').text ret['threat'] = result.find('threat').text ret['description'] = result.find('description').text hosts[host]['ports'][ret['location']].append(ret)