Agent: Change powershell client to work with Path not str

This commit is contained in:
vakaris_zilius 2022-03-23 15:24:36 +00:00
parent 7c504d220d
commit 7001977a88
2 changed files with 5 additions and 3 deletions

View File

@ -191,7 +191,7 @@ class PowerShellExploiter(HostExploiter):
try: try:
logger.info(f"Attempting to copy the monkey agent binary to {self.host.ip_addr}") 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: except Exception as ex:
raise RemoteAgentCopyError(f"Failed to copy the agent binary to the victim: {ex}") raise RemoteAgentCopyError(f"Failed to copy the agent binary to the victim: {ex}")
finally: finally:

View File

@ -1,5 +1,6 @@
import abc import abc
import logging import logging
from pathlib import Path
from typing import Optional from typing import Optional
import pypsrp import pypsrp
@ -63,7 +64,7 @@ class IPowerShellClient(Protocol, metaclass=abc.ABCMeta):
pass pass
@abc.abstractmethod @abc.abstractmethod
def copy_file(self, src: str, dest: str) -> bool: def copy_file(self, src: str, dest: Path) -> bool:
pass pass
@abc.abstractmethod @abc.abstractmethod
@ -101,7 +102,8 @@ class PowerShellClient(IPowerShellClient):
output, _, _ = self._client.execute_cmd(cmd) output, _, _ = self._client.execute_cmd(cmd)
return output return output
def copy_file(self, src: str, dest: str): def copy_file(self, src: str, dest: Path):
dest = str(dest)
try: try:
self._client.copy(src, dest) self._client.copy(src, dest)
logger.debug(f"Successfully copied {src} to {dest} on {self._ip_addr}") logger.debug(f"Successfully copied {src} to {dest} on {self._ip_addr}")