From 7d2f9251e796fa38a2ac20d39468d634c473337f Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 11 Mar 2022 22:04:53 +0530 Subject: [PATCH] Agent: Use agent repository in PowerShell exploiter And create a temporary local file for the agent binary so that pypsrp.Client can copy it to the victim --- monkey/infection_monkey/exploit/powershell.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 4e48df891..c4e2885e3 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -161,7 +161,7 @@ class PowerShellExploiter(HostExploiter): def _copy_monkey_binary_to_victim(self, monkey_path_on_victim) -> bool: try: - self._write_virtual_file_to_local_path() + self._create_local_agent_file() logger.info(f"Attempting to copy the monkey agent binary to {self.host.ip_addr}") is_monkey_copy_successful = self._client.copy_file( @@ -175,6 +175,11 @@ class PowerShellExploiter(HostExploiter): return is_monkey_copy_successful + def _create_local_agent_file(self): + agent_binary_bytes = self.agent_repository.get_agent_binary("windows") + with open(TEMP_MONKEY_BINARY_FILEPATH, "wb") as f: + f.write(agent_binary_bytes.getvalue()) + def _write_virtual_file_to_local_path(self) -> None: """ # TODO: monkeyfs has been removed. Fix this in issue #1740.