Exemple #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))
Exemple #2
0
    def execute_shortcut(self, command_name: str, params: List[str]):
        shortcut: Shortcut = shortcut_handler.get(self.agent_language,
                                                  command_name)

        if not shortcut:
            return None

        if shortcut.shell:
            self.shell(shortcut.shell)
            return

        if not len(params) == len(shortcut.get_dynamic_param_names()):
            return None  # todo log message

        if shortcut.module not in state.modules:
            print(
                print_util.color(
                    f'No module named {shortcut.name} found on the server.'))
            return None

        module_options = dict.copy(state.modules[shortcut.module]['options'])
        post_body = {}

        for i, shortcut_param in enumerate(shortcut.get_dynamic_params()):
            if shortcut_param.name in module_options:
                post_body[shortcut_param.name] = params[i]

        # TODO Still haven't figured out other data types. Right now everything is a string.
        #  Which I think is how it is in the old cli
        for key, value in module_options.items():
            if key in shortcut.get_dynamic_param_names():
                continue
            elif key in shortcut.get_static_param_names():
                post_body[key] = str(shortcut.get_param(key).value)
            else:
                post_body[key] = str(module_options[key]['Value'])
        post_body['Agent'] = self.session_id
        response = state.execute_module(shortcut.module, post_body)
        if 'success' in response.keys():
            print(
                print_util.color('[*] Tasked ' + self.selected +
                                 ' to run Task ' + str(response['taskID'])))
        elif 'error' in response.keys():
            print(print_util.color('[!] Error: ' + response['error']))
Exemple #3
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))
Exemple #4
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),
                    )