Beispiel #1
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] in ['malleable_profile',
                        'delete_malleable_profile'] and position_util(
                            cmd_line, 2, word_before_cursor):
         for profile in filtered_search_list(word_before_cursor,
                                             state.profiles.keys()):
             yield Completion(profile,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] == 'load_malleable_profile' and position_util(
             cmd_line, 2, word_before_cursor):
         for profile in filtered_search_list(word_before_cursor,
                                             complete_path('.profile')):
             yield Completion(profile,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] == 'download' and position_util(
             cmd_line, 2, word_before_cursor):
         for files in filtered_search_list(word_before_cursor,
                                           state.server_files):
             yield Completion(files,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] in ['upload'] and position_util(
             cmd_line, 2, word_before_cursor):
         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()):
                 yield Completion(files,
                                  display=files.split('/')[-1],
                                  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)
Beispiel #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)
Beispiel #3
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
         )
Beispiel #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))
Beispiel #5
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] in ['kill', 'options', 'enable',
                        'disable'] and position_util(
                            cmd_line, 2, word_before_cursor):
         for listener in filtered_search_list(word_before_cursor,
                                              state.listeners.keys()):
             yield Completion(listener,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] == 'editlistener' and position_util(
             cmd_line, 2, word_before_cursor):
         for listener in filtered_search_list(
                 word_before_cursor, sorted(state.listeners.keys())):
             yield Completion(listener,
                              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)
 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)
Beispiel #7
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] in ["kill"] and position_util(cmd_line, 2,
                                                  word_before_cursor):
         for agent in filtered_search_list(word_before_cursor,
                                           state.agents.keys()):
             yield Completion(agent,
                              start_position=-len(word_before_cursor))
         yield Completion("all", start_position=-len(word_before_cursor))
         yield Completion("stale", start_position=-len(word_before_cursor))
     elif cmd_line[0] in ["clear", "rename"] and position_util(
             cmd_line, 2, word_before_cursor):
         for agent in filtered_search_list(word_before_cursor,
                                           state.agents.keys()):
             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)
Beispiel #8
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] == "useplugin" and position_util(
             cmd_line, 2, word_before_cursor):
         for plugin in filtered_search_list(word_before_cursor,
                                            state.plugins.keys()):
             yield Completion(plugin,
                              start_position=-len(word_before_cursor))
     else:
         yield from super().get_completions(document, complete_event,
                                            cmd_line, word_before_cursor)
Beispiel #9
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if not state.connected:
         if cmd_line[0] == 'connect' and position_util(
                 cmd_line, 2, word_before_cursor):
             yield Completion('-c', start_position=-len(word_before_cursor))
         elif cmd_line[0] == 'connect' and len(cmd_line) > 1 and cmd_line[1] in ['-c', '--config'] \
                 and position_util(cmd_line, 3, word_before_cursor):
             for server in filtered_search_list(
                     word_before_cursor,
                     empire_config.yaml.get('servers', [])):
                 yield Completion(server,
                                  start_position=-len(word_before_cursor))
         elif position_util(cmd_line, 1, word_before_cursor):
             if 'connect'.startswith(word_before_cursor):
                 yield Completion('connect',
                                  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)
Beispiel #10
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] == 'usestager' and position_util(
             cmd_line, 2, word_before_cursor):
         for stager in filtered_search_list(word_before_cursor,
                                            state.stagers.keys()):
             yield Completion(stager,
                              start_position=-len(word_before_cursor))
     else:
         yield from super().get_completions(document, complete_event,
                                            cmd_line, word_before_cursor)
Beispiel #11
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     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 position_util(cmd_line, 3,
                                                 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))
     else:
         yield from super().get_completions(document, complete_event,
                                            cmd_line, word_before_cursor)
Beispiel #12
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] == "uselistener" and position_util(
             cmd_line, 2, word_before_cursor):
         for listener in filtered_search_list(word_before_cursor,
                                              sorted(state.listener_types)):
             yield Completion(listener,
                              start_position=-len(word_before_cursor))
     else:
         yield from super().get_completions(document, complete_event,
                                            cmd_line, word_before_cursor)
Beispiel #13
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if not state.connected:
         if cmd_line[0] == "connect" and position_util(
                 cmd_line, 2, word_before_cursor):
             yield Completion("-c", start_position=-len(word_before_cursor))
         elif (cmd_line[0] == "connect" and len(cmd_line) > 1
               and cmd_line[1] in ["-c", "--config"]
               and position_util(cmd_line, 3, word_before_cursor)):
             for server in filtered_search_list(
                     word_before_cursor,
                     empire_config.yaml.get("servers", [])):
                 yield Completion(server,
                                  start_position=-len(word_before_cursor))
         elif position_util(cmd_line, 1, word_before_cursor):
             if "connect".startswith(word_before_cursor):
                 yield Completion("connect",
                                  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)
Beispiel #14
0
 def get_completions(self, document, complete_event, cmd_line,
                     word_before_cursor):
     if cmd_line[0] in [
             "malleable_profile",
             "delete_malleable_profile",
     ] and position_util(cmd_line, 2, word_before_cursor):
         for profile in filtered_search_list(word_before_cursor,
                                             state.profiles.keys()):
             yield Completion(profile,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] == "load_malleable_profile" and position_util(
             cmd_line, 2, word_before_cursor):
         for profile in filtered_search_list(word_before_cursor,
                                             complete_path(".profile")):
             yield Completion(profile,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] == "download" and position_util(
             cmd_line, 2, word_before_cursor):
         for files in filtered_search_list(word_before_cursor,
                                           state.server_files):
             yield Completion(files,
                              start_position=-len(word_before_cursor))
     elif cmd_line[0] in ["upload"] and position_util(
             cmd_line, 2, word_before_cursor):
         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),
                 )
     elif position_util(cmd_line, 1, word_before_cursor):
         yield from super().get_completions(document, complete_event,
                                            cmd_line, word_before_cursor)
Beispiel #15
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))
Beispiel #16
0
 def get_completions(self, document, complete_event, cmd_line,
                     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)
Beispiel #17
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),
                    )