def console(self): # commands & functions self.switcher = { "load": self.load, "set": self.set, "unset": self.unset, "global": self.setglobal, "show": self.show, "run": self.run, "back": self.back, "warrior": self.warrior, "quit": self.quit, "help": self.help, } # Configuring the commpleter self.comp = Completer([ 'load', 'set', 'unset', 'global', 'show', 'run', 'back', 'warrior', 'quit', 'help' ]) readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(self.comp.complete) print(banners.get_banner()) cprint(' [+]', 'yellow', end='') print(' Starting the console...') cprint(' [*]', 'green', end='') print(' Console ready!\n') self.session = None while True: try: if self.session is None: # /* Definitions available for use by readline clients. */ # define RL_PROMPT_START_IGNORE '\001' # define RL_PROMPT_END_IGNORE '\002' user_input = input( '\001\033[1;32m\002iBombShell> \001\033[0m\002').strip( ) else: user_input = input('iBombShell[' + '\001\033[1;32m\002' + self.session.header() + '\001\033[0m\002' + ']> ').strip() if user_input == "": continue else: self.switch(user_input) except KeyboardInterrupt: signal.signal(signal.SIGINT, self.keyboard_interrupt_handler) print("") Warrior.get_instance().kill_warriors() except Exception as e: print_error(e)
def do_GET(self): warrior_path = Config.get_instance().get_warrior_path() + "ibs-" regex = re.findall(r'^(.+)/([^/]+)$', self.path) route = '' try: route = regex[0][0].strip('/') route_id = regex[0][1] except Exception: print_error('Error creating warrior...') a = '' if route == "ibombshell": try: with open('{}{}'.format(warrior_path, route_id), 'r') as f: a = f.read() if a is not '': print("") print_ok('Warrior {} get iBombShell commands...'.format( route_id)) with open('{}{}'.format(warrior_path, route_id), 'w') as f: f.write('') else: Warrior.get_instance().review_status(route_id) except Exception: print_error('Warrior {} don\'t found'.format(route_id), start="\n") self._set_response() #self.wfile.write("GET request for {}".format(self.path).encode('utf-8')) self.wfile.write(a.encode('utf-8'))
def do_GET(self): warrior_path = Config.get_instance().get_warrior_path() + "ibs-" ipSrc = self.client_address[0] #regex = re.findall(r'^(.+)/([^/]+)$', self.path) admin = None os_version = None os_arch = None try: regex = re.findall(r'^(.+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$', self.path) admin = regex[0][2] os_version = unquote(regex[0][3]).strip("\r\n") os_arch = unquote(regex[0][4]).strip("\r\n") except: regex = re.findall(r'^(.+)/([^/]+)$', self.path) route = '' try: route = regex[0][0] routeId = regex[0][1] except Exception: cprint('\n[!] Error creating warrior...', 'red') a = '' if route == "/ibombshell": try: with open('{}{}'.format(warrior_path, routeId), 'r') as f: a = f.read() if a is not '': cprint( '\n[+] Warrior {} get iBombShell commands...'.format( routeId), 'green') with open('{}{}'.format(warrior_path, routeId), 'w') as f: f.write('') else: Warrior.get_instance().review_status(routeId) except Exception: cprint('\n[!] Warrior {} don\'t found'.format(routeId), 'red') elif route == "/newibombshell": if not Warrior.get_instance().exist_warrior(routeId): with open('{}{}'.format(warrior_path, routeId), 'w') as f: f.write('') is_admin = False if admin and admin == "admin": is_admin = True cprint("\n[+] New warrior {} from {}".format(routeId, ipSrc), 'green') Warrior.get_instance().add_warrior(routeId, ipSrc, is_admin, os_version, os_arch) else: cprint('\n[!] Warrior already exists!', 'red') self._set_response() #self.wfile.write("GET request for {}".format(self.path).encode('utf-8')) self.wfile.write(a.encode('utf-8'))
def run_module(self): warrior = self.args["warrior"] if(Warrior.get_instance().get_status(warrior) != "Dead"): print("Killing warrior {}".format(warrior)) function = """function quit{ $global:condition = $false } """ function += 'quit' super(CustomModule, self).run(function) else: cprint ('[+] Warrior is dead', 'yellow') Warrior.get_instance().remove_warrior(warrior)
def run(self, function): if not Warrior.get_instance().exist_warrior(self.args["warrior"]): raise Exception('Failed... Warrior don´t found') with open('{}ibs-{}'.format(self.warrior_path, self.args["warrior"]), 'a') as f: # TODO: Reemplazar la escritura por añadido (append) f.write(function) print_ok('Done!')
def run(self, function): if Warrior.get_instance().exist_warrior(self.args["warrior"]): with open('{}ibs-{}'.format(self.warrior_path, self.args["warrior"]), 'a') as f: # TODO: Reemplazar la escritura por añadido (append) f.write(function) cprint ('[+] Done!', 'green') else: cprint ('[!] Failed... Warrior don´t found', 'red')
def warrior(self, user_input=[]): check_len_2 = (len(user_input) >= 2) if user_input[0] == 'list': Warrior.get_instance().print_warriors() elif user_input[0] == "rename": if not check_len_2: self._raise_exception_specify("warrior") Warrior.get_instance().rename_warrior(user_input[1]) elif user_input[0] == "kill": if not check_len_2: self._raise_exception_specify("warrior") Warrior.get_instance().kill_warrior(user_input[1])
def complete_set_warrior(self, args): warriors = list(Warrior.get_instance().get_warriors().keys()) return [ warrior + ' ' for warrior in warriors if (warrior.startswith(args[1].strip(" ")) and warrior != args[1]) ]
def console(): # Configuring the commpleter comp = Completer([ 'load', 'set', 'unset', 'show', 'run', 'back', 'warrior', 'quit', 'help' ]) readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(comp.complete) print(banners.get_banner()) cprint(' [+]', 'yellow', end='') print(' Starting the console...') cprint(' [*]', 'green', end='') print(' Console ready!\n') session = None while True: try: if session is None: # With termcolor not work colors # user_input = input( # colored('iBombShell> ', 'green', attrs=['bold'])).split() # /* Definitions available for use by readline clients. */ # define RL_PROMPT_START_IGNORE '\001' # define RL_PROMPT_END_IGNORE '\002' user_input = input( '\001\033[1;32m\002iBombShell> \001\033[0m\002').split() else: # user_input = input( # "iBombShell[" # + colored(session.header(), 'green', attrs=['bold']) # + "]> ").split() user_input = input('iBombShell[' + '\001\033[1;32m\002' + session.header() + '\001\033[0m\002' + ']> ').split() if user_input == []: continue elif user_input[0] in CLEAR_COMMANDS: os.system('cls' if os.name == 'nt' else 'clear') elif user_input[0] == 'help': print_help() elif user_input[0] == 'back': session = None elif user_input[0] == 'warrior' and len(user_input) >= 2: if user_input[1] == 'list': Warrior.get_instance().print_warriors() elif user_input[1] == "rename": if len(user_input) > 2: Warrior.get_instance().rename_warrior(user_input[2]) else: raise Exception("Specify the warrior") elif user_input[1] == "kill": if len(user_input) > 2: Warrior.get_instance().kill_warrior(user_input[2]) else: raise Exception("Specify the warrior") elif user_input[0] in END_COMMANDS: Warrior.get_instance().kill_warriors() elif user_input[0] == 'load': if (len(user_input) == 1): print_load_module() continue session = Session(user_input[1]) # The module is incorrect if not (session.correct_module()): cprint('[!] Invalid module', 'red') session = None else: comp.set_commands_to_set(session.get_options_name()) elif user_input[0] == 'show': if session is None: print_load_module() continue session.show() elif user_input[0] == 'set': if session is None: print_load_module() continue else: value = ' '.join([str(x) for x in user_input[2:]]) session.set(user_input[1], value) elif user_input[0] == 'unset': if session is None: print_load_module() continue else: session.unset(user_input[1]) elif user_input[0] == 'run': if session is None: print_load_module() continue session.run() else: cprint('[!] Command not found', 'red') except KeyboardInterrupt: print("") Warrior.get_instance().kill_warriors() except Exception as e: cprint(e, "red")
def do_POST(self): warrior_path = Config.get_instance().get_warrior_path() + "ibs-" ip_src = self.client_address[0] regex = re.findall(r'^(.+)/([^/]+)$', self.path) route = '' route_id = '' try: route = regex[0][0].strip('/') route_id = regex[0][1] except Exception: print_error('Error creating warrior...') content_length = int( self.headers['Content-Length']) # <--- Gets the size of data post_data = self.rfile.read( content_length) # <--- Gets the data itself self._set_response() self.wfile.write(''.encode('utf-8')) try: post_data = post_data.decode() fields = parse_qs(post_data) if not fields: return results = "" results = fields['results'][0] try: url = str(unquote(results)) if route == "newibombshell" and route_id != '': if Warrior.get_instance().exist_warrior(route_id): print_error('Warrior already exists!') return with open('{}{}'.format(warrior_path, route_id), 'w') as f: f.write('') print("") print_ok("New warrior {} from {}".format(route_id, ip_src)) data = json.loads(url) is_admin = data['admin'] != 'no' os_version = data['os_version'].strip('\r\n') os_arch = data['os_arch'].strip('\r\n') Warrior.get_instance().add_warrior(route_id, self.client_address[0], is_admin, os_version, os_arch) Warrior.get_instance().print_warrior(route_id) else: for result in url.split("\\n"): print_info(result) except Exception: if results is not '': print_info(results) else: print_error('Error reading results!') except Exception as e: print_error('Error parsing the result!') print_error(e) enter_input()
def quit(self, user_input=[]): Warrior.get_instance().kill_warriors()