Example #1
0
 def get_completions(self, document, complete_event, cmd_line, word_before_cursor):
     if cmd_line[0] in ["usecredential"] and position_util(
         cmd_line, 2, word_before_cursor
     ):
         for cred in filtered_search_list(
             word_before_cursor, state.credentials.keys()
         ):
             full = state.credentials[cred]
             help_text = print_util.truncate(
                 f"{full.get('username', '')}, {full.get('domain', '')}, {full.get('password', '')}",
                 width=75,
             )
             yield Completion(
                 cred,
                 display=HTML(f"{full['ID']} <purple>({help_text})</purple>"),
                 start_position=-len(word_before_cursor),
             )
         yield Completion("add", start_position=-len(word_before_cursor))
     elif cmd_line[0] in ["set", "unset"] and position_util(
         cmd_line, 2, word_before_cursor
     ):
         for option in filtered_search_list(word_before_cursor, self.record_options):
             if option != "id":
                 yield Completion(option, start_position=-len(word_before_cursor))
     elif cmd_line[0] == "set" and position_util(cmd_line, 3, word_before_cursor):
         if len(cmd_line) > 1 and cmd_line[1] == "credtype":
             for option in filtered_search_list(
                 word_before_cursor, ["plaintext", "hash"]
             ):
                 yield Completion(option, start_position=-len(word_before_cursor))
     else:
         yield from super().get_completions(
             document, complete_event, cmd_line, word_before_cursor
         )
Example #2
0
    def get_completions(self, document, complete_event, cmd_line,
                        word_before_cursor):
        """
        Adds autocomplete for the set and unset methods and defers to the base Menu when trying to invoke
        global commands (position 1 commands).
        """
        if cmd_line[0] in ['set', 'unset'] and position_util(
                cmd_line, 2, word_before_cursor):
            for option in filtered_search_list(word_before_cursor,
                                               self.record_options):
                yield Completion(option,
                                 start_position=-len(word_before_cursor))
        elif cmd_line[0] == 'set' and len(cmd_line) > 1 and cmd_line[1] == 'bypasses' \
                and 'bypasses' in map(lambda x: x.lower(), self.record_options.keys())\
                and position_util(cmd_line, where_am_i(cmd_line, word_before_cursor), word_before_cursor):
            for suggested_value in filtered_search_list(
                    word_before_cursor, state.bypasses):
                if suggested_value not in cmd_line:
                    yield Completion(suggested_value,
                                     start_position=-len(word_before_cursor))
        elif cmd_line[0] == 'set' and position_util(cmd_line, 3,
                                                    word_before_cursor):
            if len(cmd_line) > 1 and cmd_line[1] == 'listener':
                for listener in filtered_search_list(word_before_cursor,
                                                     state.listeners.keys()):
                    yield Completion(listener,
                                     start_position=-len(word_before_cursor))
            if len(cmd_line) > 1 and cmd_line[1] == 'profile':
                for profile in filtered_search_list(word_before_cursor,
                                                    state.profiles.keys()):
                    yield Completion(profile,
                                     start_position=-len(word_before_cursor))
            if len(cmd_line) > 1 and cmd_line[1] == 'agent':
                for agent in filtered_search_list(word_before_cursor,
                                                  state.agents.keys()):
                    yield Completion(agent,
                                     start_position=-len(word_before_cursor))
            if len(cmd_line) > 1 and cmd_line[1] == 'credid':
                for cred in filtered_search_list(word_before_cursor,
                                                 state.credentials.keys()):
                    full = state.credentials[cred]
                    help_text = print_util.truncate(
                        f"{full.get('username', '')}, {full.get('domain', '')}, {full.get('password', '')}",
                        width=75)
                    yield Completion(
                        cred,
                        display=HTML(
                            f"{full['ID']} <purple>({help_text})</purple>"),
                        start_position=-len(word_before_cursor))

            if len(cmd_line) > 1 and len(
                    self.suggested_values_for_option(cmd_line[1])) > 0:
                for suggested_value in filtered_search_list(
                        word_before_cursor,
                        self.suggested_values_for_option(cmd_line[1])):
                    yield Completion(suggested_value,
                                     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)
Example #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))
        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))
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] in ['remove'] and position_util(cmd_line, 2,
                                                    word_before_cursor):
         for cred in filtered_search_list(word_before_cursor,
                                          state.credentials.keys()):
             full = state.credentials[cred]
             help_text = print_util.truncate(
                 f"{full.get('username', '')}, {full.get('domain', '')}, {full.get('password', '')}",
                 width=75)
             yield Completion(
                 cred,
                 display=HTML(
                     f"{full['ID']} <purple>({help_text})</purple>"),
                 start_position=-len(word_before_cursor))
         yield Completion('all', start_position=-len(word_before_cursor))
     if position_util(cmd_line, 1, word_before_cursor):
         yield from super().get_completions(document, complete_event,
                                            cmd_line, word_before_cursor)
Example #5
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),
                    )