class HatSploitCommand(Command): loot = Loot() show = Show() details = { 'Category': "loot", 'Name': "loot", 'Authors': ['Ivan Nikolsky (enty8080) - command developer'], 'Description': "Manage collected loot.", 'Usage': "loot <option> [arguments]", 'MinArgs': 1, 'Options': { '-l': ['', "List all collected loot."], '-r': ['<name>', "Remove collected loot."] } } def run(self, argc, argv): choice = argv[1] if choice == '-l': self.show.show_loot() elif choice == '-r': self.loot.remove_loot(argv[2])
class HatSploitCommand(Command): db = DB() builder = Builder() show = Show() details = { 'Category': "databases", 'Name': "plugin_db", 'Authors': [ 'Ivan Nikolsky (enty8080) - command developer' ], 'Description': "Manage plugin databases.", 'Usage': "plugin_db <option> [arguments]", 'MinArgs': 1, 'Options': { '-l': ['', "List all connected plugin databases."], '-d': ['<name>', "Disconnect specified plugin database."], '-c': ['<name> <path>', "Connect new plugin database."], '-b': ['<path> <output_path>', "Build plugin database from plugins path."] } } def run(self, argc, argv): choice = argv[1] if choice == '-l': self.show.show_plugin_databases() elif choice == '-d': self.db.disconnect_plugin_database(argv[2]) elif choice == '-b': self.builder.build_plugin_database(argv[2], argv[3]) elif choice == '-c': self.db.connect_plugin_database(argv[2], argv[3])
class HatSploitCommand(Command): jobs = Jobs() show = Show() details = { 'Category': "jobs", 'Name': "jobs", 'Authors': ['Ivan Nikolsky (enty8080) - command developer'], 'Description': "Manage active jobs.", 'Usage': "jobs <option> [arguments]", 'MinArgs': 1, 'Options': { '-l': ['', 'List all active jobs.'], '-k': ['<id>', 'Kill specified job.'] } } def run(self, argc, argv): choice = argv[1] if choice == '-l': self.show.show_jobs() elif choice == '-k': self.jobs.delete_job(argv[2])
class HatSploitCommand(Command): modules = Modules() show = Show() details = { 'Category': "modules", 'Name': "info", 'Authors': ['Ivan Nikolsky (enty8080) - command developer'], 'Description': "Show module information.", 'Usage': "info [<module>]", 'MinArgs': 0 } complete = modules.modules_completer def get_module_information(self, module): if self.modules.check_exist(module): module = self.modules.get_module_object(module) self.show.show_module_information(module) else: self.print_error("Invalid module!") def run(self, argc, argv): if self.modules.check_current_module(): if argc > 1: self.get_module_information(argv[1]) else: self.show.show_module_information( self.modules.get_current_module_object().details) else: if argc > 1: self.get_module_information(argv[1]) else: self.print_usage(self.details['Usage'])
class HatSploitCommand(Command): show = Show() details = { 'Category': "modules", 'Name': "options", 'Authors': ['Ivan Nikolsky (enty8080) - command developer'], 'Description': "Show current module options.", 'Usage': "options", 'MinArgs': 0 } def run(self, argc, argv): self.show.show_options()
class HatSploitCommand(Command): payloads = Payloads() show = Show() details = { 'Category': "modules", 'Name': "payloads", 'Authors': ['Ivan Nikolsky (enty8080) - command developer'], 'Description': "Show available payloads.", 'Usage': "payloads [category]", 'MinArgs': 0 } def collect_categories(self): payloads = self.payloads.get_payloads() categories = [] if payloads: for database in sorted(payloads): for payload in sorted(payloads[database]): category = payloads[database][payload]['Category'] if category not in categories: categories.append(category) return categories def run(self, argc, argv): categories = self.collect_categories() if argc > 1: if argv[1] in categories: self.show.show_payloads(argv[1]) else: self.print_error("Invalid payload category!") self.print_information( f"Available categories: {str(categories)}") else: self.show.show_payloads()
class HatSploitCommand(Command): sessions = Sessions() show = Show() details = { 'Category': "sessions", 'Name': "sessions", 'Authors': [ 'Ivan Nikolsky (enty8080) - command developer' ], 'Description': "Manage opened sessions.", 'Usage': "sessions <option> [arguments]", 'MinArgs': 1, 'Options': { '-l': ['', "List all opened sessions."], '-i': ['<id>', "Interact with specified session."], '-d': ['<id> <remote_file> <local_path>', "Download file from session."], '-u': ['<id> <local_file> <remote_path>', "Upload file to session."], '-c': ['<id>', "Close specified session."], '--auto-interaction': ['[on|off]', "Interact with session after opening."] } } def run(self, argc, argv): if argv[1] == '-l': self.show.show_sessions() elif argv[1] == '-c': self.sessions.close_session(argv[2]) elif argv[1] == '-i': self.sessions.interact_with_session(argv[2]) elif argv[1] == '-d': self.sessions.session_download(argv[2], argv[3], argv[4]) elif argv[1] == '-u': self.sessions.session_upload(argv[2], argv[3], argv[4]) elif argv[1] == '--auto-interaction': if argv[2] == 'on': self.sessions.enable_auto_interaction() elif argv[2] == 'off': self.sessions.disable_auto_interaction()
class Commands: show = Show() importer = Importer() badges = Badges() execute = Execute() modules = Modules() local_storage = LocalStorage() def load_commands(self, path): return self.importer.import_commands(path) def execute_command(self, commands): self.execute.execute_command(commands) def execute_system_command(self, commands): self.execute.execute_system(commands) def execute_custom_command(self, commands, handler, error=True): if commands: if not self.execute.execute_builtin_method(commands): if not self.execute.execute_custom_command(commands, handler): if error: self.badges.print_error( f"Unrecognized command: {commands[0]}!") return False return True def show_commands(self, handler): self.show.show_custom_commands(handler) def commands_completer(self, text): return [ command for command in self.get_all_commands() if command.startswith(text) ] def get_commands(self): return self.local_storage.get("commands") def get_modules_commands(self): module = self.modules.get_current_module_object() if module: return module.commands if hasattr(module, "commands") else {} return {} def get_plugins_commands(self): plugins = self.local_storage.get("loaded_plugins") commands = {} if plugins: for plugin in plugins: if hasattr(plugins[plugin], "commands"): for label in plugins[plugin].commands: commands.update(plugins[plugin].commands[label]) return commands def get_all_commands(self): commands = {} module = self.modules.get_current_module_object() if module: if hasattr(module, "commands"): commands.update(module.commands) plugins = self.local_storage.get("loaded_plugins") if plugins: for plugin in plugins: if hasattr(plugins[plugin], "commands"): for label in plugins[plugin].commands: commands.update(plugins[plugin].commands[label]) commands.update(self.local_storage.get("commands")) return commands
class Execute: jobs = Jobs() fmt = FMT() badges = Badges() tables = Tables() local_storage = LocalStorage() modules = Modules() show = Show() def execute_command(self, commands): if commands: if not self.execute_builtin_method(commands): if not self.execute_core_command(commands): if not self.execute_module_command(commands): if not self.execute_plugin_command(commands): self.badges.print_error( f"Unrecognized command: {commands[0]}!") def execute_builtin_method(self, commands): if commands[0][0] == '#': return True if commands[0][0] == '?': self.show.show_all_commands() return True if commands[0][0] == '&': commands[0] = commands[0][1:] self.jobs.create_job(commands[0], None, self.execute_command, [commands], True) return True if commands[0][0] == '!': if len(commands[0]) > 1: commands[0] = commands[0].replace('!', '', 1) self.execute_system(commands) else: self.badges.print_usage("!<command>") return True return False def execute_system(self, commands): self.badges.print_process(f"Executing system command: {commands[0]}\n") try: subprocess.call(commands) except Exception: self.badges.print_error( f"Unrecognized system command: {commands[0]}!") def execute_custom_command(self, commands, handler): if handler: if commands[0] in handler: command = handler[commands[0]] if not self.check_arguments(commands, command.details): self.parse_usage(command.details) else: command.run(len(commands), commands) return True return False def check_arguments(self, commands, details): if (len(commands) - 1) < details['MinArgs']: return False if 'Options' in details: if len(commands) > 1: if commands[1] in details['Options']: if (len(commands) - 2) < len( details['Options'][commands[1]][0].split()): return False else: return False if len(commands) > 1: if commands[1] == '?': return False return True def parse_usage(self, details): self.badges.print_usage(details['Usage']) if 'Options' in details: headers = ('Option', 'Arguments', 'Description') data = [] for option in details['Options']: info = details['Options'][option] data.append((option, info[0], info[1])) self.tables.print_table('Options', headers, *data) def execute_core_command(self, commands): return self.execute_custom_command(commands, self.local_storage.get("commands")) def execute_module_command(self, commands): if self.modules.check_current_module(): if hasattr(self.modules.get_current_module_object(), "commands"): if commands[0] in self.modules.get_current_module_object( ).commands: command_object = self.modules.get_current_module_object() command = self.modules.get_current_module_object( ).commands[commands[0]] self.parse_and_execute_command(commands, command, command_object) return True return False def execute_plugin_command(self, commands): if self.local_storage.get("loaded_plugins"): for plugin in self.local_storage.get("loaded_plugins"): if hasattr( self.local_storage.get("loaded_plugins")[plugin], "commands"): for label in self.local_storage.get( "loaded_plugins")[plugin].commands: if commands[0] in self.local_storage.get( "loaded_plugins")[plugin].commands[label]: command_object = self.local_storage.get( "loaded_plugins")[plugin] command = command_object.commands[label][ commands[0]] self.parse_and_execute_command( commands, command, command_object) return True return False def parse_and_execute_command(self, commands, command, command_object): if hasattr(command_object, commands[0]): if not self.check_arguments(commands, command): self.parse_usage(command) else: getattr(command_object, commands[0])(len(commands), commands) else: self.badges.print_error("Failed to execute command!")