def command_list(text=False): cols = [G + Bold + "Name" + end, G + Bold + "Description" + end] Columns = [] for p in modules: info = db.grab(p) Columns.append([p, info.short_description]) utils.create_table(cols, Columns)
def command_options(text=False): try: options = global_options headers = [ B + Bold + "Name", "Current value", "Required", "Description" + end ] names = list(options.keys()) values = utils.my_map(lambda x: str(options[x][2]), names) required = utils.my_map(lambda x: ["No", "Yes"][options[x][0]], names) description = utils.my_map(lambda x: options[x][1], names) cols = [] for row in range(len(names)): cols.append( [names[row], values[row], required[row], description[row]]) utils.create_table(headers, cols) except Exception as e: if Settings.debug: error("Error in finding options! ") print("Exception -> " + str(e)) print(" Module -> " + str(m)) print("Trackback -> ") traceback.print_exc() else: error("Unknown error! enable debug mode to more details")
def command_options(text=False): options = global_options headers = [ B + Bold + "Name", "Current value", "Required", "Description" + end ] names = list(options.keys()) values = utils.my_map(lambda x: str(options[x][2]), names) required = utils.my_map(lambda x: ["No", "Yes"][options[x][0]], names) description = utils.my_map(lambda x: options[x][1], names) cols = [] for row in range(len(names)): cols.append([names[row], values[row], required[row], description[row]]) utils.create_table(headers, cols)
def command_search(text=False): if not text: error("You must enter a text to search for !") else: cols = [G + Bold + "Name" + end, G + Bold + "Description" + end] Columns = [] text = text.lower() for p in modules: info = db.grab(p) full_text = " ".join([ info.author, info.short_description, info.full_description if info.full_description else "" ]).lower() if text in full_text: Columns.append([p, info.short_description]) if not Columns: error("Didn't find a module have the entered text!") else: utils.create_table(cols, Columns)
def command_options(text=False): try: options = global_options headers = [B+Bold+"Name","Current value","Required","Description"+end] names = list( options.keys() ) values = utils.my_map(lambda x:str(options[x][2]),names) required = utils.my_map(lambda x:["No","Yes"][options[x][0]],names) description = utils.my_map(lambda x:options[x][1],names) cols = [] for row in range(len(names)): cols.append([ names[row], values[row], required[row], description[row] ]) utils.create_table(headers,cols) except Exception as e: if Settings.debug: error("Error in finding options! ") print("Exception -> "+str(e) ) print(" Module -> "+str(m) ) print("Trackback -> ") traceback.print_exc() else: error("Unknown error! enable debug mode to more details")
def command_jobs(process=""): help_command = """ usage: jobs [-h] [-l] [-K] [-k] optional arguments: -h Show this help message. -l List all running jobs. -K Terminate all running jobs. -k Terminate jobs by job ID or module name""" if process == "-h": print(help_command) return else: if not Settings.headless_browser or Settings.headless_browser.browsers=={}: error("No active jobs.") return option = process.split()[:1] args = process.split()[1:] if not process or option[0] == "-l": cols = [ G + Bold + "ID" + end, G + Bold + "Module name" + end, G + Bold + "Serving on" + end ] Columns = [] for module_name in list(Settings.headless_browser.browsers.keys()): line = Settings.headless_browser.browsers[module_name] if Settings.headless_browser.browsers[module_name]["Status"]: uri = line["host"] + ":" + line["port"] Columns.append( [line["Controller"].session_id, module_name, uri]) if Columns: utils.create_table(cols, Columns) else: error("No active jobs.") elif option[0] == "-k": if not args: error("Enter a job ID/module name to terminate!") else: for module_name in list(Settings.headless_browser.browsers.keys()): if Settings.headless_browser.browsers[module_name][ "Controller"].session_id == args[0]: Settings.headless_browser.close_job(module_name) status("Job terminated successfully!") return for module_name in list(Settings.headless_browser.browsers.keys()): if module_name == args[0]: Settings.headless_browser.close_job(module_name) status("Job terminated successfully!") return error("Job not found!") elif option[0] == "-K": Settings.headless_browser.close_all() Settings.headless_browser = None status("All jobs terminated successfully!") else: error("Invalid option!")
def command_sessions(text=""): sessions_file = os.path.join("core", "sessions.json") sessions = json.load(open(sessions_file)) try: cmd = sessions_parser.parse_args(text.split()) except: cmd = sessions_parser.parse_args( "" ) # F**k you argparse, next time I will use more flexible module like getopt globally # I done this because any error argparse gives is printed and it exit the framework but now no if cmd.h: print(sessions_parser.format_help()) return elif not text or cmd.l: if not sessions: error("No captured sessions.") else: cols = [ G + Bold + "ID" + end, G + Bold + "Module name" + end, G + Bold + "Captured on" + end ] Columns = [] for session_id in list(sessions.keys()): line = sessions[session_id] date = line["session_path"].replace( os.path.join("sessions", ""), "").replace(".session", "") Columns.append([session_id, line["name"], date]) utils.create_table(cols, Columns) elif cmd.i: if not sessions: error("No captured sessions.") else: if not cmd.i: error("Enter a session ID to interact with!") elif cmd.i not in list(sessions.keys()): error("Invalid session ID!") else: if not Settings.visible_browser: Settings.visible_browser = browser.visible_browsers() status(f"Starting interaction with ({cmd.i})...") if sessions[cmd.i]["session_type"] == "localStorage": Settings.visible_browser.load_localstorage(cmd.i) else: Settings.visible_browser.load_cookie(cmd.i) elif cmd.k: if not sessions: error("No captured sessions.") else: if not cmd.k: error("Enter a session ID to interact with!") elif cmd.k not in list(sessions.keys()): error("Invalid session ID!") else: session_file = sessions[cmd.k]["session_path"] os.remove(session_file) sessions.pop(cmd.k) f = open(sessions_file, "w") json.dump(sessions, f, indent=2) f.close() status(f"Session ({cmd.k}) removed!") elif cmd.s: if not sessions: error("No captured sessions.") else: if not cmd.s: error("Enter a session type to filter with!") elif cmd.s not in [ sessions[i]["name"] for i in list(sessions.keys()) ]: error("Invalid session type!") else: cols = [G + Bold + "ID" + end, G + Bold + "Captured on" + end] Columns = [] for session_id in list(sessions.keys()): line = sessions[session_id] if cmd.s == line["name"]: date = line["session_path"].replace( os.path.join("sessions", ""), "").replace(".session", "") Columns.append([session_id, date]) utils.create_table(cols, Columns) elif cmd.K: if not sessions: error("No captured sessions.") else: for sess in list(sessions.keys()): session_file = sessions[sess]["session_path"] os.remove(session_file) f = open(sessions_file, "w") json.dump({}, f, indent=2) f.close() status(f"All captured sessions removed!")