Beispiel #1
0
    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))
Beispiel #2
0
    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():
            print(
                print_util.color('[*] Tasked ' +
                                 self.record_options['Agent']['Value'] +
                                 ' to run Task ' + str(response['taskID'])))
            shell_return = threading.Thread(target=self.tasking_id_returns,
                                            args=[response['taskID']])
            shell_return.daemon = True
            shell_return.start()
        elif 'error' in response.keys():
            if response['error'].startswith('[!]'):
                msg = response['error']
            else:
                msg = f"[!] Error: {response['error']}"
            print(print_util.color(msg))
Beispiel #3
0
    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))
Beispiel #4
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']))