Ejemplo n.º 1
0
    def __init__(self):
        self.exceptions = exceptions()
        self.tables = tables()
        self.badges = badges()
        self.local_storage = local_storage()
        self.modules = modules()

        self.job_process = None
Ejemplo n.º 2
0
    def __init__(self):
        self.db = db()
        self.badges = badges()
        self.local_storage = local_storage()
        self.config = config()
        self.modules = modules()
        self.exceptions = exceptions()

        self.tcp = tcp()
Ejemplo n.º 3
0
class HatSploitCommand(HatSploitCommand):
    local_storage = local_storage()
    modules = modules()
    jobs = jobs()

    details = {
        'Category': "module",
        'Name': "run",
        'Description': "Run current module.",
        'Usage': "run [-h|-j]",
        'MinArgs': 0
    }

    def entry_to_module(self, argc, argv, current_module):
        if argc > 0:
            if argv[0] == "-j":
                self.badges.output_process(
                    "Running module as a background job...")
                job_id = self.jobs.create_job(current_module.details['Name'],
                                              current_module.details['Module'],
                                              current_module.run)
                self.badges.output_information(
                    "Module started as a background job " + str(job_id) + ".")
                return
        current_module.run()

    def run(self, argc, argv):
        if argc > 0:
            if argv[0] == "-h":
                self.badges.output_usage(self.details['Usage'])
                return

        if self.modules.check_current_module():
            current_module = self.modules.get_current_module_object()
            count = 0
            if hasattr(current_module, "options"):
                for option in current_module.options.keys():
                    current_option = current_module.options[option]
                    if not current_option['Value'] and current_option[
                            'Value'] != 0 and current_option['Required']:
                        count += 1
                if count > 0:
                    self.badges.output_error("Missed some required options!")
                else:
                    try:
                        self.entry_to_module(argc, argv, current_module)
                    except Exception as e:
                        self.badges.output_error(
                            "An error occurred in module: " + str(e) + "!")
            else:
                try:
                    self.entry_to_module(argc, argv, current_module)
                except Exception as e:
                    self.badges.output_error("An error occurred in module: " +
                                             str(e) + "!")
        else:
            self.badges.output_warning("No module selected.")
Ejemplo n.º 4
0
    def __init__(self):
        self.io = io()
        self.tip = tip()
        self.jobs = jobs()
        self.execute = execute()
        self.loader = loader()
        self.config = config()
        self.badges = badges()
        self.banner = banner()
        self.colors = colors()
        self.local_storage = local_storage()
        self.modules = modules()
        self.exceptions = exceptions()

        self.history = self.config.path_config['base_paths']['history_path']
Ejemplo n.º 5
0
class HatSploitCommand(HatSploitCommand):
    modules = modules()

    details = {
        'Category': "module",
        'Name': "set",
        'Description': "Set an option value.",
        'Usage': "set <option> <value>",
        'MinArgs': 2
    }

    def run(self, argc, argv):
        option = argv[0].upper()
        value = argv[1]

        self.modules.set_current_module_option(option, value)
Ejemplo n.º 6
0
class HatSploitCommand(HatSploitCommand):
    modules = modules()
    local_storage = local_storage()

    details = {
        'Category': "module",
        'Name': "back",
        'Description': "Return to the previous module.",
        'Usage': "back",
        'MinArgs': 0
    }

    def run(self, argc, argv):
        if self.modules.check_current_module():
            self.local_storage.set(
                "current_module_number",
                self.local_storage.get("current_module_number") - 1)
            self.local_storage.set(
                "current_module",
                self.local_storage.get("current_module")[0:-1])
            if not self.local_storage.get("current_module"):
                self.local_storage.set("current_module_number", 0)
Ejemplo n.º 7
0
class HatSploitCommand(HatSploitCommand):
    modules = modules()

    details = {
        'Category': "module",
        'Name': "info",
        'Description': "Show module information.",
        'Usage': "info [<module>]",
        'MinArgs': 0
    }

    def format_module_information(self, current_module):
        authors = ""
        for author in current_module['Authors']:
            authors += author + ", "
        authors = authors[:-2]

        dependencies = ""
        for dependence in current_module['Dependencies']:
            dependencies += dependence + ", "
        dependencies = dependencies[:-2]

        comments = ""
        for line in current_module['Comments']:
            comments += line + "\n" + (" " * 14)
        comments = comments[:-15]

        self.badges.output_information("Module information:")
        self.badges.output_empty("")

        if current_module['Name']:
            self.badges.output_empty("         Name: " +
                                     current_module['Name'])
        if current_module['Module']:
            self.badges.output_empty("       Module: " +
                                     current_module['Module'])
        if authors:
            self.badges.output_empty("      Authors: " + authors)
        if current_module['Description']:
            self.badges.output_empty("  Description: " +
                                     current_module['Description'])
        if dependencies:
            self.badges.output_empty(" Dependencies: " + dependencies)
        if comments:
            self.badges.output_empty("     Comments: ")
            self.badges.output_empty("               " + comments)
        if current_module['Risk']:
            self.badges.output_empty("         Risk: " +
                                     current_module['Risk'])

        self.badges.output_empty("")

    def get_module_information(self, module):
        if self.modules.check_exist(module):
            category = self.modules.get_category(module)
            platform = self.modules.get_platform(module)
            name = self.modules.get_name(module)

            module = self.modules.get_module_object(category, platform, name)
            self.format_module_information(module)
        else:
            self.badges.output_error("Invalid module!")

    def run(self, argc, argv):
        if self.modules.check_current_module():
            if argc > 0:
                self.get_module_information(argv[0])
            else:
                self.format_module_information(
                    self.modules.get_current_module_object().details)
        else:
            if argc > 0:
                self.get_module_information(argv[0])
            else:
                self.badges.output_usage(self.details['Usage'])
Ejemplo n.º 8
0
class HatSploitCommand(HatSploitCommand):
    local_storage = local_storage()
    modules = modules()

    details = {
        'Category': "core",
        'Name': "show",
        'Description': "Show specified information.",
        'Usage': "show <information>",
        'MinArgs': 1
    }

    def show_plugins(self):
        plugins = self.local_storage.get("plugins")
        plugins_data = list()
        number = 0
        headers = ("Number", "Name", "Database", "Description")
        for database in plugins.keys():
            plugins = plugins[database]
            for plugin in sorted(plugins.keys()):
                plugins_data.append((number, plugin, database, plugins[plugin]['Description']))
                number += 1
        self.badges.output_empty("")
        self.tables.print_table("Plugins", headers, *plugins_data)
        self.badges.output_empty("")
        
    def show_modules(self, information):
        modules = self.local_storage.get("modules")
        modules_data = list()
        number = 0
        headers = ("Number", "Module", "Database", "Risk", "Description")
        for database in modules.keys():
            modules = modules[database][information]
            for platform in sorted(modules.keys()):
                for module in sorted(modules[platform].keys()):
                    full_name = self.modules.get_full_name(information, platform, module)
                    modules_data.append((number, full_name, database, modules[platform][module]['Risk'], modules[platform][module]['Description']))
                    number += 1
        self.badges.output_empty("")
        self.tables.print_table(information.title() + " Modules", headers, *modules_data)
        self.badges.output_empty("")
        
    def show_options(self):
        current_module = self.modules.get_current_module_object()
        options_data = list()
        headers = ("Option", "Value", "Required", "Description")
        options = current_module.options
        for option in sorted(options.keys()):
            value, required = options[option]['Value'], options[option]['Required']
            if required:
                required = "yes"
            else:
                required = "no"
            if not value and value != 0:
                value = ""
            options_data.append((option, value, required, options[option]['Description']))
        self.badges.output_empty("")
        self.tables.print_table("Module Options", headers, *options_data)
        self.badges.output_empty("")
        
    def print_usage(self, informations, plugins, options):
        if informations or plugins or options:
            usage = "Informations: "
            for information in informations:
                usage += information + ", "
            if plugins:
                usage += "plugins, "
            if options:
                usage += "options"
            else:
                usage = usage[:-2]
            self.badges.output_information(usage)
        else:
            self.badges.output_warning("No informations available!")

    def run(self, argc, argv):
        information = argv[0]
        
        if self.modules.check_current_module():
            current_module = self.modules.get_current_module_object()
        
            options = False
            if hasattr(current_module, "options"):
                options = True
        else:
            options = False
        
        modules = self.local_storage.get("modules")
        plugins = self.local_storage.get("plugins")
        
        informations = list()
        if modules:
            for database in sorted(modules.keys()):
                for category in sorted(modules[database].keys()):
                    informations.append(category)
        
        if plugins:
            if information == "plugins":
                self.show_plugins()
                return
        if options:
            if information == "options":
                self.show_options()
                return
        if information in informations:
            self.show_modules(information)
        else:
            self.print_usage(informations, plugins, options)
Ejemplo n.º 9
0
class HatSploitCommand(HatSploitCommand):
    modules = modules()
    local_storage = local_storage()

    details = {
        'Category': "core",
        'Name': "help",
        'Description': "Show available commands.",
        'Usage': "help",
        'MinArgs': 0
    }

    def format_base_commands(self):
        commands_data = dict()
        headers = ("Command", "Description")
        commands = self.local_storage.get("commands")
        for command in sorted(commands.keys()):
            label = commands[command].details['Category']
            commands_data[label] = list()
        for command in sorted(commands.keys()):
            label = commands[command].details['Category']
            commands_data[label].append(
                (command, commands[command].details['Description']))
        self.badges.output_empty("")
        for label in sorted(commands_data.keys()):
            self.tables.print_table(label.title() + " Commands", headers,
                                    *commands_data[label])
            self.badges.output_empty("")

    def format_plugin_commands(self):
        for plugin in self.local_storage.get("loaded_plugins").keys():
            loaded_plugin = self.local_storage.get("loaded_plugins")[plugin]
            if hasattr(loaded_plugin, "commands"):
                commands_data = dict()
                headers = ("Command", "Description")
                commands = loaded_plugin.commands
                for label in sorted(commands.keys()):
                    commands_data[label] = list()
                    for command in sorted(commands[label].keys()):
                        commands_data[label].append(
                            (command, commands[label][command]['Description']))
                for label in sorted(commands_data.keys()):
                    self.tables.print_table(label.title() + " Commands",
                                            headers, *commands_data[label])
                    self.badges.output_empty("")

    def format_custom_commands(self):
        current_module = self.modules.get_current_module_object()
        if hasattr(current_module, "commands"):
            commands_data = list()
            headers = ("Command", "Description")
            commands = current_module.commands
            for command in sorted(commands.keys()):
                commands_data.append(
                    (command, commands[command]['Description']))
            self.tables.print_table("Custom Commands", headers, *commands_data)
            self.badges.output_empty("")

    def run(self, argc, argv):
        self.format_base_commands()
        if self.modules.check_current_module():
            self.format_custom_commands()
        if self.local_storage.get("loaded_plugins"):
            self.format_plugin_commands()
Ejemplo n.º 10
0
 def __init__(self):
     self.fmt = fmt()
     self.badges = badges()
     self.local_storage = local_storage()
     self.modules = modules()
Ejemplo n.º 11
0
class HatSploitCommand(HatSploitCommand):
    importer = importer()
    local_storage = local_storage()
    modules = modules()

    details = {
        'Category': "module",
        'Name': "use",
        'Description': "Use specified module.",
        'Usage': "use <module>",
        'MinArgs': 1
    }

    def import_module(self, category, platform, name):
        modules = self.modules.get_module_object(category, platform, name)
        try:
            module_object = self.importer.import_module(modules['Path'])
            if not self.local_storage.get("imported_modules"):
                self.local_storage.set("imported_modules", dict())
            self.local_storage.update(
                "imported_modules", {
                    self.modules.get_full_name(category, platform, name):
                    module_object
                })
        except Exception:
            return None
        return module_object

    def add_module(self, category, platform, name):
        modules = self.modules.get_module_object(category, platform, name)

        not_installed = list()
        for dependence in modules['Dependencies']:
            if not self.importer.import_check(dependence):
                not_installed.append(dependence)
        if not not_installed:
            imported_modules = self.local_storage.get("imported_modules")
            full_name = self.modules.get_full_name(category, platform, name)

            if self.modules.check_imported(full_name):
                module_object = imported_modules[full_name]
                self.add_to_global(module_object)
            else:
                module_object = self.import_module(category, platform, name)
                if module_object:
                    self.add_to_global(module_object)
                else:
                    self.badges.output_error(
                        "Failed to select module from database!")
        else:
            self.badges.output_error(
                "Module depends this dependencies which is not installed:")
            for dependence in not_installed:
                self.badges.output_empty("    * " + dependence)

    def add_to_global(self, module_object):
        if self.modules.check_current_module():
            self.local_storage.add_array("current_module", '')
            self.local_storage.set(
                "current_module_number",
                self.local_storage.get("current_module_number") + 1)
            self.local_storage.set_array(
                "current_module",
                self.local_storage.get("current_module_number"), module_object)
        else:
            self.local_storage.set("current_module", [])
            self.local_storage.set("current_module_number", 0)
            self.local_storage.add_array("current_module", '')
            self.local_storage.set_array(
                "current_module",
                self.local_storage.get("current_module_number"), module_object)

    def check_if_already_used(self, module):
        if self.modules.check_current_module():
            if module == self.modules.get_current_module_name():
                return True
        return False

    def run(self, argc, argv):
        module = argv[0]

        category = self.modules.get_category(module)
        platform = self.modules.get_platform(module)
        name = self.modules.get_name(module)

        if not self.check_if_already_used(module):
            if self.modules.check_exist(module):
                self.add_module(category, platform, name)
            else:
                self.badges.output_error("Invalid module!")
Ejemplo n.º 12
0
 def __init__(self):
     self.badges = badges()
     self.importer = importer()
     self.local_storage = local_storage()
     self.modules = modules()