def run_cmd(command_name, populated_command, celery_path, task_id, path=None, process_domain_tuple=None): """ :param command_name: :param populated_command: :param celery_path: :param task_id: :param path: :param process_domain_tuple: :return: """ #task_id = run_cmd.request.id #task_id = run_cmd.request.id # Without the sleep, some jobs were showing as submitted even though # they were started. Not sure why. #time.sleep(3) audit_log = celery_path + "/log/cmdExecutionAudit.log" f = open(audit_log, 'a') start_time = time.time() start_time_int = int(start_time) start_ctime = time.ctime(start_time) start = timer() #f.write("[+] CMD EXECUTED: " + str(start_ctime) + " - " + populated_command + "\n") #f.write(task_id) print(populated_command) #The except isnt working yet if I kill the process from linux cli. i guess that is not enough to trigger an exception. try: p = Popen(populated_command, shell=True, stdout=PIPE, stdin=PIPE) pid = p.pid + 1 db.update_task_status_started("STARTED", task_id, pid, start_time_int) out, err = p.communicate() end = timer() end_ctime = time.ctime(end) run_time = end - start db.update_task_status_completed("COMPLETED", task_id, run_time) #f.write("\n[-] CMD COMPLETED in " + str(run_time) + " - " + populated_command + "\n") f.write("\n" + str(start_ctime) + "\t" + str(end_ctime) + "\t" + str("{:.2f}".format(run_time)) + "\t" + command_name + "\t" + populated_command) except: end = timer() run_time = end - start db.update_task_status_error("FAILED", task_id, run_time) f.close() if process_domain_tuple: lib.scan.determine_if_domains_are_in_scope(out, process_domain_tuple) return out
def cel_nmap_scan(cmd_name, populated_command, host, config_nmap_options, celery_path, task_id, workspace): """ :param cmd_name: :param populated_command: :param host: :param config_nmap_options: :param celery_path: :param task_id: :param workspace: :return: """ # Without the sleep, some jobs were showing as submitted even though # they were started. Not sure why. #time.sleep(3) path = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(lib.scan.__file__)), "..")) audit_log = path + "/log/cmdExecutionAudit.log" f = open(audit_log, 'a') start_time = time.time() start_time_int = int(start_time) start_ctime = time.ctime(start_time) start = timer() #f.write(str(start_ctime)+ "," + "CMD EXECUTED" + "," + populated_command + "\n") #f.write(task_id) print(populated_command) #The except isnt working yet if I kill the process from linux cli. i guess that is not enough to trigger an exception. # try: print("[+] Kicking off nmap scan for " + host) db.update_task_status_started("STARTED", task_id, 0, start_time_int) nm = NmapProcess(host, options=config_nmap_options) rc = nm.run() nmap_report = NmapParser.parse(nm.stdout) end = timer() end_ctime = time.ctime(end) run_time = end - start db.update_task_status_completed("COMPLETED", task_id, run_time) #f.write("\n" + str(end_ctime) + "," + "CMD COMPLETED" + ","" + str(run_time) + " - " + populated_command + "\n") f.write( str(start_ctime) + "," + str(end_ctime) + "," + str(run_time) + cmd_name + "\n") # except: # end = timer() # run_time = end - start # db.update_task_status_error("FAILED", task_id, run_time) f.close() lib.csimport.process_nmap_data2(nmap_report, workspace) return nmap_report
def run_cmd(command_name, populated_command,celery_path,task_id,path=None,process_domain_tuple=None): """ :param populated_command: the command celery worker will run :param output_base_dir: passed so we can record the job in the cmdExecutionAudit.log :param workspace: the user specified workspace name. Default: default :param ip: The IP is passed so that we can write it to the database :return: """ #task_id = run_cmd.request.id #task_id = run_cmd.request.id # Without the sleep, some jobs were showing as submitted even though # they were started. Not sure why. #time.sleep(3) audit_log = celery_path + "/log/cmdExecutionAudit.log" f = open(audit_log, 'a') start_time = time.time() start_time_int = int(start_time) start_ctime = time.ctime(start_time) start = timer() #f.write("[+] CMD EXECUTED: " + str(start_ctime) + " - " + populated_command + "\n") #f.write(task_id) print(populated_command) #The except isnt working yet if I kill the process from linux cli. i guess that is not enough to trigger an exception. try: p = Popen(populated_command, shell=True, stdout=PIPE, stdin=PIPE) pid = p.pid + 1 db.update_task_status_started("STARTED", task_id, pid, start_time_int) out,err = p.communicate() end = timer() end_ctime = time.ctime(end) run_time = end - start db.update_task_status_completed("COMPLETED", task_id, run_time) #f.write("\n[-] CMD COMPLETED in " + str(run_time) + " - " + populated_command + "\n") f.write("\n" + str(start_ctime) + "\t" + str(end_ctime) + "\t" + str("{:.2f}".format(run_time)) + "\t" + command_name + "\t" + populated_command) except: end = timer() run_time = end - start db.update_task_status_error("FAILED", task_id, run_time) f.close() if process_domain_tuple: lib.scan.post_process_domains(out,process_domain_tuple) return out
def take_screenshot(urls_to_screenshot, task_id, ip, scan_output_base_file_dir, workspace, command_name, populated_command): path = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(lib.scan.__file__)), "..")) audit_log = path + "/log/cmdExecutionAudit.log" f = open(audit_log, 'a') start_time = time.time() start_time_int = int(start_time) start_ctime = time.ctime(start_time) start = timer() display = Display(visible=0, size=(800, 600)) display.start() options = Options() options.add_argument("--headless") driver = webdriver.Firefox(firefox_options=options) pid = driver.service.process.pid print(pid) db.update_task_status_started("STARTED", task_id, pid, start_time_int) for url, output in urls_to_screenshot: try: #driver = webdriver.Firefox(firefox_options=options) # capture the screen driver.get(url) print("Taking screenshot of [{0}]".format(url)) screenshot = driver.save_screenshot(output) except WebDriverException as e: #print('exception: {0}'.format(e)) print("Error taking screenshot of [{0}]".format(url)) except Exception as e: print('exception: {0}'.format(e)) #print(type(e).__name__) # finally: # driver.quit() driver.quit() display.stop() end = timer() end_ctime = time.ctime(end) run_time = end - start db.update_task_status_completed("COMPLETED", task_id, run_time) # f.write("\n[-] CMD COMPLETED in " + str(run_time) + " - " + populated_command + "\n") f.write("\n" + str(start_ctime) + "\t" + str(end_ctime) + "\t" + str("{:.2f}".format(run_time)) + "\t" + command_name + "\t" + populated_command) f.close()
def run_cmd(command_name, populated_command, celery_path, task_id, path=None, process_domain_tuple=None, process_nmap=None, output_file=None): """ :param command_name: :param populated_command: :param celery_path: :param task_id: :param path: :param process_domain_tuple: :return: """ #task_id = run_cmd.request.id #task_id = run_cmd.request.id # Without the sleep, some jobs were showing as submitted even though # they were started. Not sure why. #time.sleep(3) audit_log = celery_path + "/log/cmdExecutionAudit.log" f = open(audit_log, 'a') start_time = time.time() start_time_int = int(start_time) start_ctime = time.ctime(start_time) start = timer() #f.write("[+] CMD EXECUTED: " + str(start_ctime) + " - " + populated_command + "\n") #f.write(task_id) print(populated_command) #The except isnt working yet if I kill the process from linux cli. i guess that is not enough to trigger an exception. try: p = Popen(populated_command, shell=True, stdout=PIPE, stdin=PIPE) pid = p.pid + 1 db.update_task_status_started("STARTED", task_id, pid, start_time_int) out, err = p.communicate() end = timer() end_ctime = time.ctime(end) run_time = end - start db.update_task_status_completed("COMPLETED", task_id, run_time) #f.write("\n[-] CMD COMPLETED in " + str(run_time) + " - " + populated_command + "\n") f.write("\n" + str(start_ctime) + "\t" + str(end_ctime) + "\t" + str("{:.2f}".format(run_time)) + "\t" + command_name + "\t" + populated_command) except: end = timer() run_time = end - start db.update_task_status_error("FAILED", task_id, run_time) f.close() if process_domain_tuple: lib.scan.determine_if_domains_are_in_scope(out, process_domain_tuple) else: #putting this here because i want to parse scan tool output for urls, not subdomain tools output parsers.generic_urlextract.extract_in_scope_urls_from_task_output(out) if process_nmap: nmap_xml = output_file + ".xml" nmap_report = NmapParser.parse_fromfile(nmap_xml) workspace = lib.db.get_current_workspace()[0][0] lib.csimport.process_nmap_data(nmap_report, workspace) return out