Agent: Upload binary with random string when using powershell

This commit is contained in:
vakaris_zilius 2022-03-23 13:11:54 +00:00
parent 06f33e0fa1
commit 7c504d220d
1 changed files with 5 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import logging
import os
from pathlib import Path
from typing import List, Optional
from infection_monkey.exploit.HostExploiter import HostExploiter
@ -19,7 +20,7 @@ from infection_monkey.exploit.powershell_utils.powershell_client import (
IPowerShellClient,
PowerShellClient,
)
from infection_monkey.exploit.tools.helpers import get_random_file_suffix
from infection_monkey.exploit.tools.helpers import get_agent_dest_path, get_random_file_suffix
from infection_monkey.model import DROPPER_ARG, RUN_MONKEY, VictimHost
from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.environment import is_windows_os
@ -170,7 +171,7 @@ class PowerShellExploiter(HostExploiter):
raise ValueError(f"Unknown secret type {credentials.secret_type}")
def _execute_monkey_agent_on_victim(self):
monkey_path_on_victim = self.options["dropper_target_path_win_64"]
monkey_path_on_victim = get_agent_dest_path(self.host, self.options)
self._copy_monkey_binary_to_victim(monkey_path_on_victim)
logger.info("Successfully copied the monkey binary to the victim.")
@ -182,7 +183,7 @@ class PowerShellExploiter(HostExploiter):
f"Failed to execute the agent binary on the victim: {ex}"
)
def _copy_monkey_binary_to_victim(self, monkey_path_on_victim):
def _copy_monkey_binary_to_victim(self, monkey_path_on_victim: Path):
temp_monkey_binary_filepath = f"monkey_temp_bin_{get_random_file_suffix()}"
@ -190,7 +191,7 @@ class PowerShellExploiter(HostExploiter):
try:
logger.info(f"Attempting to copy the monkey agent binary to {self.host.ip_addr}")
self._client.copy_file(temp_monkey_binary_filepath, monkey_path_on_victim)
self._client.copy_file(temp_monkey_binary_filepath, str(monkey_path_on_victim))
except Exception as ex:
raise RemoteAgentCopyError(f"Failed to copy the agent binary to the victim: {ex}")
finally: