コード例 #1
0
ファイル: UseModuleMenu.py プロジェクト: moloch--/Empire
    def execute(self):
        """
        Execute the selected module

        Usage: execute
        """
        post_body = {}
        for key, value in self.record_options.items():
            post_body[key] = self.record_options[key]['Value']

        response = state.execute_module(self.selected, post_body)
        if 'success' in response.keys():
            if 'Agent' in post_body.keys():
                print(
                    print_util.color('[*] Tasked ' +
                                     self.record_options['Agent']['Value'] +
                                     ' to run Task ' +
                                     str(response['taskID'])))
                menu_state.pop()
            else:
                print(print_util.color('[*] ' + str(response['msg'])))

        elif 'error' in response.keys():
            if response['error'].startswith('[!]'):
                msg = response['error']
            else:
                msg = f"[!] Error: {response['error']}"
            print(print_util.color(msg))
コード例 #2
0
ファイル: UseModuleMenu.py プロジェクト: vinnybod/Empire
    def execute(self):
        """
        Execute the selected module

        Usage: execute
        """
        # Find file then upload to server
        if "File" in self.record_options:
            # if a full path upload to server, else use file from download directory
            if pathlib.Path(self.record_options["File"]["Value"]).is_file():
                file_directory = self.record_options["File"]["Value"]
                filename = file_directory.split("/")[-1]
                self.record_options["File"]["Value"] = filename

                data = get_data_from_file(file_directory)
                response = state.upload_file(filename, data)
                if "success" in response.keys():
                    print(
                        print_util.color(
                            "[+] File uploaded to server successfully"))

                elif "error" in response.keys():
                    if response["error"].startswith("[!]"):
                        msg = response["error"]
                    else:
                        msg = f"[!] Error: {response['error']}"
                    print(print_util.color(msg))

                # Save copy off to downloads folder so last value points to the correct file
                data = base64.b64decode(data.encode("UTF-8"))
                with open(f"{state.directory['downloads']}{filename}",
                          "wb+") as f:
                    f.write(data)

        post_body = {}
        for key, value in self.record_options.items():
            post_body[key] = self.record_options[key]["Value"]

        response = state.execute_module(self.selected, post_body)
        if "success" in response.keys():
            if "Agent" in post_body.keys():
                print(
                    print_util.color("[*] Tasked " +
                                     self.record_options["Agent"]["Value"] +
                                     " to run Task " +
                                     str(response["taskID"])))
                menu_state.pop()
            else:
                print(print_util.color("[*] " + str(response["msg"])))

        elif "error" in response.keys():
            if response["error"].startswith("[!]"):
                msg = response["error"]
            else:
                msg = f"[!] Error: {response['error']}"
            print(print_util.color(msg))
コード例 #3
0
    def parse_command_line(self,
                           text: str,
                           cmd_line: List[str],
                           resource_file=False):
        if len(cmd_line) == 0:
            return
        if not state.connected and not cmd_line[0] == "connect":
            if cmd_line[0] == "exit":
                choice = input(print_util.color("[>] Exit? [y/N] ", "red"))
                if choice.lower() == "y":
                    raise CliExitException
                else:
                    return
            else:
                return

        # Switch Menus
        if text.strip() == "main":
            state.get_modules()
            state.get_listeners()
            print_util.title(
                state.empire_version,
                len(state.modules),
                len(state.listeners),
                len(state.get_active_agents()),
            )
            menu_state.push(self.menus["MainMenu"])
        elif text.strip() == "listeners":
            menu_state.push(self.menus["ListenerMenu"])
        elif text.strip() == "chat":
            menu_state.push(self.menus["ChatMenu"])
        elif menu_state.current_menu_name == "ChatMenu":
            menu_state.current_menu.send_chat(text)
        elif text.strip() == "agents":
            menu_state.push(self.menus["AgentMenu"])
        elif text.strip() == "sponsors":
            menu_state.push(self.menus["SponsorsMenu"])
        elif text.strip() == "credentials":
            menu_state.push(self.menus["CredentialMenu"])
        elif text.strip() == "plugins":
            menu_state.push(self.menus["PluginMenu"])
        elif text.strip() == "admin":
            menu_state.push(self.menus["AdminMenu"])
        elif cmd_line[0] == "uselistener" and len(cmd_line) > 1:
            if cmd_line[1] in state.listener_types:
                menu_state.push(self.menus["UseListenerMenu"],
                                selected=cmd_line[1])
            else:
                print(f"No listener {cmd_line[1]}")
        elif cmd_line[0] == "usestager" and len(cmd_line) > 1:
            if cmd_line[1] in state.stagers:
                menu_state.push(self.menus["UseStagerMenu"],
                                selected=cmd_line[1])
            else:
                print(f"No stager {cmd_line[1]}")
        elif cmd_line[0] == "interact" and len(cmd_line) > 1:
            if cmd_line[1] in state.agents:
                menu_state.push(self.menus["InteractMenu"],
                                selected=cmd_line[1])
            else:
                print(f"No agent {cmd_line[1]}")
        elif cmd_line[0] == "useplugin" and len(cmd_line) > 1:
            if cmd_line[1] in state.plugins:
                menu_state.push(self.menus["UsePluginMenu"],
                                selected=cmd_line[1])
            else:
                print(f"No plugin {cmd_line[1]}")
        elif cmd_line[0] == "usecredential" and len(cmd_line) > 1:
            if cmd_line[1] in state.credentials or cmd_line[1] == "add":
                menu_state.push(self.menus["UseCredentialMenu"],
                                selected=cmd_line[1])
            else:
                print(f"[!] No credential {cmd_line[1]}")
        elif cmd_line[0] == "usemodule" and len(cmd_line) > 1:
            if cmd_line[1] in state.modules:
                if menu_state.current_menu_name == "InteractMenu":
                    menu_state.push(
                        self.menus["UseModuleMenu"],
                        selected=cmd_line[1],
                        agent=menu_state.current_menu.selected,
                    )
                else:
                    menu_state.push(self.menus["UseModuleMenu"],
                                    selected=cmd_line[1])
            else:
                print(f"No module {cmd_line[1]}")
        elif cmd_line[0] == "editlistener" and len(cmd_line) > 1:
            if menu_state.current_menu_name == "ListenerMenu":
                if cmd_line[1] in state.listeners:
                    menu_state.push(self.menus["EditListenerMenu"],
                                    selected=cmd_line[1])
            else:
                print(f"No listener {cmd_line[1]}")
        elif text.strip() == "shell":
            if menu_state.current_menu_name == "InteractMenu":
                menu_state.push(self.menus["ShellMenu"],
                                selected=menu_state.current_menu.selected)
            else:
                pass
        elif menu_state.current_menu_name == "ShellMenu":
            if text == "exit":
                menu_state.push(
                    self.menus["InteractMenu"],
                    selected=menu_state.current_menu.selected,
                )
            else:
                menu_state.current_menu.shell(menu_state.current_menu.selected,
                                              text)
        elif text.strip() == "proxy":
            if menu_state.current_menu_name == "InteractMenu":
                if menu_state.current_menu.agent_options["language"] not in [
                        "python",
                        "ironpython",
                ]:
                    print(
                        print_util.color(
                            f'[!] Agent proxies are not available in {menu_state.current_menu.agent_options["language"]} agents'
                        ))
                    pass
                elif state.listeners[menu_state.current_menu.agent_options[
                        "listener"]]["module"] not in [
                            "http", "http_hop", "redirector"
                        ]:
                    print(
                        print_util.color(
                            f"[!] Agent proxies are not available in {state.listeners[menu_state.current_menu.agent_options['listener']]['module']} listeners"
                        ))
                else:
                    menu_state.push(
                        self.menus["ProxyMenu"],
                        selected=menu_state.current_menu.selected,
                    )
            else:
                pass
        elif text.strip() == "back":
            menu_state.pop()
        elif text.strip() == "exit":
            if resource_file:
                raise CliExitException
            choice = input(print_util.color("[>] Exit? [y/N] ", "red"))
            if choice.lower() == "y":
                raise CliExitException
            else:
                pass
        else:
            func = None
            try:
                func = getattr(
                    menu_state.current_menu
                    if hasattr(menu_state.current_menu, cmd_line[0]) else self,
                    cmd_line[0],
                )
            except:
                pass

            if func:
                try:
                    # If the command is set, wrap the value in quotes so docopt
                    # doesn't interpret it as a parameter. Also concatenate all the words
                    # after the 3rd word for easier autofilling with suggested values that have spaces
                    # There may be a better way to do this.
                    if cmd_line[0] == "set":
                        cmd_line[2] = f'"{" ".join(cmd_line[2:])}"'
                        del cmd_line[3:]
                    args = self.strip(docopt(func.__doc__, argv=cmd_line[1:]))
                    new_args = {}
                    # todo casting for type hinted values?
                    for key, hint in get_type_hints(func).items():
                        # if args.get(key) is not None:
                        if key != "return":
                            new_args[key] = args[key]
                    # print(new_args)
                    func(**new_args)
                except Exception as e:
                    print(e)
                    pass
                except SystemExit as e:
                    pass
            elif not func and menu_state.current_menu_name == "InteractMenu":
                if cmd_line[0] in shortcut_handler.get_names(
                        self.menus["InteractMenu"].agent_language):
                    menu_state.current_menu.execute_shortcut(
                        cmd_line[0], cmd_line[1:])
コード例 #4
0
    def parse_command_line(self, text: str, cmd_line: List[str], resource_file=False):
        if len(cmd_line) == 0:
            return
        if not state.connected and not cmd_line[0] == 'connect':
            if cmd_line[0] == 'exit':
                choice = input(print_util.color("[>] Exit? [y/N] ", "red"))
                if choice.lower() == "y":
                    raise CliExitException
                else:
                    return
            else:
                return

        # Switch Menus
        if text.strip() == 'main':
            state.get_modules()
            state.get_listeners()
            print_util.title(state.empire_version, len(state.modules), len(state.listeners),
                             len(state.get_active_agents()))
            menu_state.push(self.menus['MainMenu'])
        elif text.strip() == 'listeners':
            menu_state.push(self.menus['ListenerMenu'])
        elif text.strip() == 'chat':
            menu_state.push(self.menus['ChatMenu'])
        elif menu_state.current_menu_name == 'ChatMenu':
            menu_state.current_menu.send_chat(text)
        elif text.strip() == 'agents':
            menu_state.push(self.menus['AgentMenu'])
        elif text.strip() == 'sponsors':
            menu_state.push(self.menus['SponsorsMenu'])
        elif text.strip() == 'credentials':
            menu_state.push(self.menus['CredentialMenu'])
        elif text.strip() == 'plugins':
            menu_state.push(self.menus['PluginMenu'])
        elif text.strip() == 'admin':
            menu_state.push(self.menus['AdminMenu'])
        elif cmd_line[0] == 'uselistener' and len(cmd_line) > 1:
            if cmd_line[1] in state.listener_types:
                menu_state.push(self.menus['UseListenerMenu'], selected=cmd_line[1])
            else:
                print(f'No listener {cmd_line[1]}')
        elif cmd_line[0] == 'usestager' and len(cmd_line) > 1:
            if cmd_line[1] in state.stagers:
                menu_state.push(self.menus['UseStagerMenu'], selected=cmd_line[1])
            else:
                print(f'No stager {cmd_line[1]}')
        elif cmd_line[0] == 'interact' and len(cmd_line) > 1:
            if cmd_line[1] in state.agents:
                menu_state.push(self.menus['InteractMenu'], selected=cmd_line[1])
            else:
                print(f'No agent {cmd_line[1]}')
        elif cmd_line[0] == 'useplugin' and len(cmd_line) > 1:
            if cmd_line[1] in state.plugins:
                menu_state.push(self.menus['UsePluginMenu'], selected=cmd_line[1])
            else:
                print(f'No plugin {cmd_line[1]}')
        elif cmd_line[0] == 'usecredential' and len(cmd_line) > 1:
            if cmd_line[1] in state.credentials or cmd_line[1] == 'add':
                menu_state.push(self.menus['UseCredentialMenu'], selected=cmd_line[1])
            else:
                print(f'[!] No credential {cmd_line[1]}')
        elif cmd_line[0] == 'usemodule' and len(cmd_line) > 1:
            if cmd_line[1] in state.modules:
                if menu_state.current_menu_name == 'InteractMenu':
                    menu_state.push(self.menus['UseModuleMenu'], selected=cmd_line[1],
                                    agent=menu_state.current_menu.selected)
                else:
                    menu_state.push(self.menus['UseModuleMenu'], selected=cmd_line[1])
            else:
                print(f'No module {cmd_line[1]}')
        elif cmd_line[0] == 'editlistener' and len(cmd_line) > 1:
            if menu_state.current_menu_name == 'ListenerMenu':
                if cmd_line[1] in state.listeners:
                    menu_state.push(self.menus['EditListenerMenu'], selected=cmd_line[1])
            else:
                print(f'No listener {cmd_line[1]}')
        elif text.strip() == 'shell':
            if menu_state.current_menu_name == 'InteractMenu':
                menu_state.push(self.menus['ShellMenu'], selected=menu_state.current_menu.selected)
            else:
                pass
        elif menu_state.current_menu_name == 'ShellMenu':
            if text == 'exit':
                menu_state.push(self.menus['InteractMenu'], selected=menu_state.current_menu.selected)
            else:
                menu_state.current_menu.shell(menu_state.current_menu.selected, text)
        elif text.strip() == 'back':
            menu_state.pop()
        elif text.strip() == 'exit':
            if resource_file:
                raise CliExitException
            choice = input(print_util.color("[>] Exit? [y/N] ", "red"))
            if choice.lower() == "y":
                raise CliExitException
            else:
                pass
        else:
            func = None
            try:
                func = getattr(menu_state.current_menu if hasattr(menu_state.current_menu, cmd_line[0]) else self,
                               cmd_line[0])
            except:
                pass

            if func:
                try:
                    # If the command is set, wrap the value in quotes so docopt
                    # doesn't interpret it as a parameter. Also concatenate all the words
                    # after the 3rd word for easier autofilling with suggested values that have spaces
                    # There may be a better way to do this.
                    if cmd_line[0] == 'set':
                        cmd_line[2] = f'"{" ".join(cmd_line[2:])}"'
                        del cmd_line[3:]
                    args = self.strip(docopt(
                        func.__doc__,
                        argv=cmd_line[1:]
                    ))
                    new_args = {}
                    # todo casting for type hinted values?
                    for key, hint in get_type_hints(func).items():
                        # if args.get(key) is not None:
                        if key != 'return':
                            new_args[key] = args[key]
                    # print(new_args)
                    func(**new_args)
                except Exception as e:
                    print(e)
                    pass
                except SystemExit as e:
                    pass
            elif not func and menu_state.current_menu_name == 'InteractMenu':
                if cmd_line[0] in shortcut_handler.get_names(self.menus['InteractMenu'].agent_language):
                    menu_state.current_menu.execute_shortcut(cmd_line[0], cmd_line[1:])
コード例 #5
0
def do_ctrl_c(event):
    """
    If ctrl-c is pressed from the chat or shell menus, go back a menu.
    """
    menu_state.pop()