Beispiel #1
0
class HatSploitCommand(HatSploitCommand):
    plugins = plugins()
    local_storage = local_storage()
    importer = importer()

    details = {
        'Category': "plugin",
        'Name': "load",
        'Description': "Load specified plugin.",
        'Usage': "load <plugin>",
        'MinArgs': 1
    }

    def import_plugin(self, database, plugin):
        loaded_plugins = dict()
        plugins = self.local_storage.get("plugins")[database][plugin]
        try:
            loaded_plugins[plugin] = self.importer.import_plugin(plugins['Path'])
        except Exception:
            return None
        return loaded_plugins
        
    def add_plugin(self, database, plugin):
        plugins = self.local_storage.get("plugins")[database][plugin]
        not_installed = list()
        for dependence in plugins['Dependencies']:
            if not self.importer.import_check(dependence):
                not_installed.append(dependence)
        if not not_installed:
            plugin_object = self.import_plugin(database, plugin)
            if plugin_object:
                if self.local_storage.get("loaded_plugins"):
                    self.local_storage.update("loaded_plugins", plugin_object)
                else:
                    self.local_storage.set("loaded_plugins", plugin_object)
                self.local_storage.get("loaded_plugins")[plugin].run()
                self.badges.output_success("Successfully loaded " + plugin + " plugin!")
            else:
                self.badges.output_error("Failed to load plugin!")
        else:
            self.badges.output_error("Plugin depends this dependencies which is not installed:")
            for dependence in not_installed:
                self.badges.output_empty("    * " + dependence)
        
    def run(self, argc, argv):
        plugin = argv[0]
        self.badges.output_process("Loading " + plugin + " plugin...")
        
        if not self.plugins.check_loaded(plugin):
            if self.plugins.check_exist(plugin):
                database = self.plugins.get_database(plugin)
                self.add_plugin(database, plugin)
            else:
                self.badges.output_error("Invalid plugin!")
        else:
            self.badges.output_error("Already loaded!")
Beispiel #2
0
 def __init__(self):
     self.badges = badges()
     self.importer = importer()
     self.local_storage = local_storage()
Beispiel #3
0
    def __init__(self):
        self.badges = badges()
        self.importer = importer()

        self.modules_tests = modules_tests()
        self.plugins_tests = plugins_tests()
Beispiel #4
0
 def __init__(self):
     self.badges = badges()
     self.importer = importer()
     self.config = config()
Beispiel #5
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!")