forked from p34709852/monkey
Agent: Use Paths in IPowerShellClient.copy_file()
This commit is contained in:
parent
7001977a88
commit
d3fc833813
|
@ -1,5 +1,4 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
@ -185,7 +184,7 @@ class PowerShellExploiter(HostExploiter):
|
||||||
|
|
||||||
def _copy_monkey_binary_to_victim(self, monkey_path_on_victim: Path):
|
def _copy_monkey_binary_to_victim(self, monkey_path_on_victim: Path):
|
||||||
|
|
||||||
temp_monkey_binary_filepath = f"monkey_temp_bin_{get_random_file_suffix()}"
|
temp_monkey_binary_filepath = Path(f"./monkey_temp_bin_{get_random_file_suffix()}")
|
||||||
|
|
||||||
self._create_local_agent_file(temp_monkey_binary_filepath)
|
self._create_local_agent_file(temp_monkey_binary_filepath)
|
||||||
|
|
||||||
|
@ -195,8 +194,8 @@ class PowerShellExploiter(HostExploiter):
|
||||||
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:
|
||||||
if os.path.isfile(temp_monkey_binary_filepath):
|
if temp_monkey_binary_filepath.is_file():
|
||||||
os.remove(temp_monkey_binary_filepath)
|
temp_monkey_binary_filepath.unlink()
|
||||||
|
|
||||||
def _create_local_agent_file(self, binary_path):
|
def _create_local_agent_file(self, binary_path):
|
||||||
agent_binary_bytes = self.agent_repository.get_agent_binary("windows")
|
agent_binary_bytes = self.agent_repository.get_agent_binary("windows")
|
||||||
|
|
|
@ -64,7 +64,7 @@ class IPowerShellClient(Protocol, metaclass=abc.ABCMeta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def copy_file(self, src: str, dest: Path) -> bool:
|
def copy_file(self, src: Path, dest: Path) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
@ -102,10 +102,9 @@ 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: Path):
|
def copy_file(self, src: Path, dest: Path):
|
||||||
dest = str(dest)
|
|
||||||
try:
|
try:
|
||||||
self._client.copy(src, dest)
|
self._client.copy(str(src), str(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}")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error(f"Failed to copy {src} to {dest} on {self._ip_addr}: {ex}")
|
logger.error(f"Failed to copy {src} to {dest} on {self._ip_addr}: {ex}")
|
||||||
|
|
Loading…
Reference in New Issue