コード例 #1
0
    def get_completions(self, document, complete_event, cmd_line,
                        word_before_cursor):
        if cmd_line[0] in ['interact'] and position_util(
                cmd_line, 2, word_before_cursor):
            active_agents = list(
                map(
                    lambda a: a['name'],
                    filter(lambda a: a['stale'] is not True,
                           state.agents.values())))
            for agent in filtered_search_list(word_before_cursor,
                                              active_agents):
                yield Completion(agent,
                                 start_position=-len(word_before_cursor))
        elif position_util(cmd_line, 1, word_before_cursor):
            yield from super().get_completions(document, complete_event,
                                               cmd_line, word_before_cursor)
        elif cmd_line[0] in ['display'] and position_util(
                cmd_line, 2, word_before_cursor):
            for property_name in filtered_search_list(word_before_cursor,
                                                      self.agent_options):
                yield Completion(property_name,
                                 start_position=-len(word_before_cursor))
        elif cmd_line[0] in shortcut_handler.get_names(self.agent_language):
            position = len(cmd_line)
            shortcut = shortcut_handler.get(self.agent_language, cmd_line[0])
            params = shortcut.get_dynamic_param_names()
            if position - 1 < len(params):
                if params[position - 1].lower() == 'listener':
                    for listener in filtered_search_list(
                            word_before_cursor, state.listeners.keys()):
                        yield Completion(
                            listener, start_position=-len(word_before_cursor))
                if params[position - 1].lower() == 'agent':
                    for agent in filtered_search_list(word_before_cursor,
                                                      state.agents.keys()):
                        yield Completion(
                            agent, start_position=-len(word_before_cursor))
        elif cmd_line[0] in ['view']:
            tasks = state.get_agent_tasks_slim(self.session_id)
            tasks = {str(x['taskID']): x for x in tasks['tasks']}

            for task_id in filtered_search_list(word_before_cursor,
                                                tasks.keys()):
                full = tasks[task_id]
                help_text = print_util.truncate(
                    f"{full.get('command', '')[:30]}, {full.get('username', '')}",
                    width=75)
                yield Completion(
                    task_id,
                    display=HTML(
                        f"{full['taskID']} <purple>({help_text})</purple>"),
                    start_position=-len(word_before_cursor))
コード例 #2
0
ファイル: InteractMenu.py プロジェクト: W1LDN16H7/Empire
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] in ['interact'] and position_util(
             cmd_line, 2, word_before_cursor):
         active_agents = list(
             map(
                 lambda a: a['name'],
                 filter(lambda a: a['stale'] is not True,
                        state.agents.values())))
         for agent in filtered_search_list(word_before_cursor,
                                           active_agents):
             yield Completion(agent,
                              start_position=-len(word_before_cursor))
     elif position_util(cmd_line, 1, word_before_cursor):
         yield from super().get_completions(document, complete_event,
                                            cmd_line, word_before_cursor)
     elif cmd_line[0] in ['display'] and position_util(
             cmd_line, 2, word_before_cursor):
         for property_name in filtered_search_list(word_before_cursor,
                                                   self.agent_options):
             yield Completion(property_name,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] in shortcut_handler.get_names(self.agent_language):
         position = len(cmd_line)
         shortcut = shortcut_handler.get(self.agent_language, cmd_line[0])
         params = shortcut.get_dynamic_param_names()
         if position - 1 < len(params):
             if params[position - 1].lower() == 'listener':
                 for listener in filtered_search_list(
                         word_before_cursor, state.listeners.keys()):
                     yield Completion(
                         listener, start_position=-len(word_before_cursor))
             if params[position - 1].lower() == 'agent':
                 for agent in filtered_search_list(word_before_cursor,
                                                   state.agents.keys()):
                     yield Completion(
                         agent, start_position=-len(word_before_cursor))
コード例 #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
ファイル: InteractMenu.py プロジェクト: W1LDN16H7/Empire
 def autocomplete(self):
     return self._cmd_registry + \
            super().autocomplete() + \
            shortcut_handler.get_names(self.agent_language)
コード例 #5
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:])
コード例 #6
0
    def get_completions(self, document, complete_event, cmd_line,
                        word_before_cursor):
        if cmd_line[0] in ["interact"] and position_util(
                cmd_line, 2, word_before_cursor):
            active_agents = list(
                map(
                    lambda a: a["name"],
                    filter(lambda a: a["stale"] is not True,
                           state.agents.values()),
                ))
            for agent in filtered_search_list(word_before_cursor,
                                              active_agents):
                yield Completion(agent,
                                 start_position=-len(word_before_cursor))
        elif position_util(cmd_line, 1, word_before_cursor):
            yield from super().get_completions(document, complete_event,
                                               cmd_line, word_before_cursor)
        elif cmd_line[0] in ["display"] and position_util(
                cmd_line, 2, word_before_cursor):
            for property_name in filtered_search_list(word_before_cursor,
                                                      self.agent_options):
                yield Completion(property_name,
                                 start_position=-len(word_before_cursor))
        elif cmd_line[0] in shortcut_handler.get_names(self.agent_language):
            position = len(cmd_line)
            shortcut = shortcut_handler.get(self.agent_language, cmd_line[0])
            params = shortcut.get_dynamic_param_names()
            if position - 1 < len(params):
                if params[position - 1].lower() == "listener":
                    for listener in filtered_search_list(
                            word_before_cursor, state.listeners.keys()):
                        yield Completion(
                            listener, start_position=-len(word_before_cursor))
                if params[position - 1].lower() == "agent":
                    for agent in filtered_search_list(word_before_cursor,
                                                      state.agents.keys()):
                        yield Completion(
                            agent, start_position=-len(word_before_cursor))
        elif cmd_line[0] in ["view"]:
            tasks = state.get_agent_tasks_slim(self.session_id)
            tasks = {str(x["taskID"]): x for x in tasks["tasks"]}

            for task_id in filtered_search_list(word_before_cursor,
                                                tasks.keys()):
                full = tasks[task_id]
                help_text = print_util.truncate(
                    f"{full.get('command', '')[:30]}, {full.get('username', '')}",
                    width=75,
                )
                yield Completion(
                    task_id,
                    display=HTML(
                        f"{full['taskID']} <purple>({help_text})</purple>"),
                    start_position=-len(word_before_cursor),
                )
        elif cmd_line[0] in ["upload"]:
            if len(cmd_line) > 1 and cmd_line[1] == "-p":
                yield Completion(state.search_files(),
                                 start_position=-len(word_before_cursor))
            else:
                for files in filtered_search_list(
                        word_before_cursor,
                        current_files(state.directory["downloads"])):
                    yield Completion(
                        files,
                        display=files.split("/")[-1],
                        start_position=-len(word_before_cursor),
                    )