From 7001977a884873c86478198d994421274e54e413 Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Wed, 23 Mar 2022 15:24:36 +0000 Subject: [PATCH] Agent: Change powershell client to work with Path not str --- monkey/infection_monkey/exploit/powershell.py | 2 +- .../exploit/powershell_utils/powershell_client.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 1c3536821..12974aae5 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -191,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, str(monkey_path_on_victim)) + self._client.copy_file(temp_monkey_binary_filepath, monkey_path_on_victim) except Exception as ex: raise RemoteAgentCopyError(f"Failed to copy the agent binary to the victim: {ex}") finally: diff --git a/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py b/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py index c0ae8b260..b1fa000c7 100644 --- a/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py +++ b/monkey/infection_monkey/exploit/powershell_utils/powershell_client.py @@ -1,5 +1,6 @@ import abc import logging +from pathlib import Path from typing import Optional import pypsrp @@ -63,7 +64,7 @@ class IPowerShellClient(Protocol, metaclass=abc.ABCMeta): pass @abc.abstractmethod - def copy_file(self, src: str, dest: str) -> bool: + def copy_file(self, src: str, dest: Path) -> bool: pass @abc.abstractmethod @@ -101,7 +102,8 @@ class PowerShellClient(IPowerShellClient): output, _, _ = self._client.execute_cmd(cmd) return output - def copy_file(self, src: str, dest: str): + def copy_file(self, src: str, dest: Path): + dest = str(dest) try: self._client.copy(src, dest) logger.debug(f"Successfully copied {src} to {dest} on {self._ip_addr}")