Example #1
0
 def __init__(self):
     self.types = Types()
     self.badges = Badges()
     self.sessions = Sessions()
     self.payloads = Payloads()
     self.local_storage = LocalStorage()
     self.importer = Importer()
Example #2
0
class HatSploitCommand(Command):
    local_storage = LocalStorage()
    modules = Modules()
    payloads = Payloads()

    details = {
        'Category': "core",
        'Name': "show",
        'Authors': ['Ivan Nikolsky (enty8080)'],
        'Description': "Show specified information.",
        'Usage': "show <information>",
        'MinArgs': 1
    }

    def show_plugins(self):
        plugins = self.local_storage.get("plugins")
        headers = ("Number", "Name", "Description")
        for database in plugins.keys():
            number = 0
            plugins_data = list()
            plugins = plugins[database]
            for plugin in sorted(plugins.keys()):
                plugins_data.append(
                    (number, plugin, plugins[plugin]['Description']))
                number += 1
            self.print_table("Plugins (" + database + ")", headers,
                             *plugins_data)

    def show_modules(self, information):
        modules = self.local_storage.get("modules")
        headers = ("Number", "Module", "Risk", "Description")
        for database in modules.keys():
            number = 0
            modules_data = list()
            modules = modules[database][information]
            for platform in sorted(modules.keys()):
                for module in sorted(modules[platform].keys()):
                    modules_data.append(
                        (number, modules[platform][module]['Module'],
                         modules[platform][module]['Risk'],
                         modules[platform][module]['Description']))
                    number += 1
            self.print_table(
                information.title() + " Modules (" + database + ")", headers,
                *modules_data)

    def show_payloads(self):
        payloads = self.local_storage.get("payloads")
        headers = ("Number", "Category", "Payload", "Risk", "Description")

        for database in sorted(payloads.keys()):
            number = 0
            payloads_data = list()
            for platform in sorted(payloads[database].keys()):
                for architecture in sorted(
                        payloads[database][platform].keys()):
                    for payload in sorted(
                            payloads[database][platform][architecture].keys()):
                        current_payload = payloads[database][platform][
                            architecture][payload]
                        payloads_data.append(
                            (number, current_payload['Category'],
                             current_payload['Payload'],
                             current_payload['Risk'],
                             current_payload['Description']))
                        number += 1
            self.print_table("Payloads (" + database + ")", headers,
                             *payloads_data)

    def show_options(self):
        current_module = self.modules.get_current_module_object()

        if not hasattr(current_module, "options") and not hasattr(
                current_module, "payload"):
            self.badges.output_warning("Module has no options.")
            return

        if not hasattr(current_module, "options") and not hasattr(
                self.payloads.get_current_payload(), "options"):
            self.badges.output_warning("Module has no options.")
            return

        if hasattr(current_module, "options"):
            options_data = list()
            headers = ("Option", "Value", "Required", "Description")
            options = current_module.options.copy()

            if hasattr(current_module, "payload"):
                options['PAYLOAD'] = dict()
                options['PAYLOAD']['Description'] = current_module.payload[
                    'Description']
                options['PAYLOAD']['Value'] = current_module.payload['Value']
                options['PAYLOAD']['Type'] = None
                options['PAYLOAD']['Required'] = True

            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.print_table(
                "Module Options (" + current_module.details['Module'] + ")",
                headers, *options_data)

        if hasattr(current_module, "payload"):
            if hasattr(self.payloads.get_current_payload(), "options"):
                options_data = list()
                headers = ("Option", "Value", "Required", "Description")
                current_payload = self.payloads.get_current_payload()
                if current_payload:
                    for option in sorted(current_payload.options.keys()):
                        value, required = current_payload.options[option]['Value'], \
                                        current_payload.options[option]['Required']
                        if required:
                            required = "yes"
                        else:
                            required = "no"
                        if not value and value != 0:
                            value = ""
                        options_data.append(
                            (option, value, required,
                             current_payload.options[option]['Description']))
                    self.print_table(
                        "Payload Options (" +
                        current_payload.details['Payload'] + ")", headers,
                        *options_data)

    def print_usage(self, informations, plugins, options):
        if informations or plugins or options:
            usage = "Informations: "
            if self.local_storage.get("payloads"):
                usage += "payloads, "
            for information in informations:
                usage += information + ", "
            if plugins:
                usage += "plugins, "
            if options:
                usage += "options"
            else:
                usage = usage[:-2]
            self.output_information(usage)
        else:
            self.output_warning("No informations available!")

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

        options = self.modules.check_current_module()
        payloads = self.local_storage.get("payloads")
        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 payloads:
            if information == "payloads":
                self.show_payloads()
                return
        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)
Example #3
0
class HatSploitCommand(Command):
    payloads = Payloads()
    local_storage = LocalStorage()
    modules = Modules()
    jobs = Jobs()

    usage = ""
    usage += "run [option]\n\n"
    usage += "  -h, --help  Show this help message.\n"
    usage += "  -j, --job   Run current module as a background job.\n"

    details = {
        'Category': "module",
        'Name': "run",
        'Authors': ['Ivan Nikolsky (enty8080)'],
        'Description': "Run current module.",
        'Usage': usage,
        'MinArgs': 0
    }

    def entry_to_module(self, argc, argv, current_module):
        if argc > 0:
            if argv[0] in ['-j', '--job']:
                self.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.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] in ['-h', '--help']:
                self.output_usage(self.details['Usage'])
                return

        if self.modules.check_current_module():
            current_module = self.modules.get_current_module_object()
            current_payload = self.payloads.get_current_payload()
            missed = 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']:
                        missed += 1
            if current_payload:
                if hasattr(current_payload, "options"):
                    for option in current_payload.options.keys():
                        current_option = current_payload.options[option]
                        if not current_option['Value'] and current_option[
                                'Value'] != 0 and current_option['Required']:
                            missed += 1
            if missed > 0:
                self.output_error("Missed some required options!")
            else:
                try:
                    if current_payload:
                        payload_name = current_module.payload['Value']
                        self.output_process(
                            f"Configuring {payload_name} payload...")

                        payload_data = current_payload.run()
                        payload, args, session = None, None, None

                        if isinstance(payload_data, tuple):
                            if len(payload_data) == 2:
                                payload, args = payload_data[0], payload_data[
                                    1]
                            elif len(payload_data) == 3:
                                payload, args, session = payload_data[
                                    0], payload_data[1], payload_data[2]
                        else:
                            payload = payload_data

                        current_module.payload[
                            'Category'] = current_payload.details['Category']
                        current_module.payload[
                            'Platform'] = current_payload.details['Platform']
                        current_module.payload[
                            'Type'] = current_payload.details['Type']

                        current_module.payload['Payload'] = payload
                        current_module.payload['Args'] = args
                        current_module.payload['Session'] = session

                    self.entry_to_module(argc, argv, current_module)
                except Exception as e:
                    self.output_error("An error occurred in module: " +
                                      str(e) + "!")
        else:
            self.output_warning("No module selected.")
Example #4
0
 def __init__(self):
     self.badges = Badges()
     self.importer = Importer()
     self.local_storage = LocalStorage()
     self.payloads = Payloads()