Agent: Ensure temp file is removed by PowerShellExploiter

This commit is contained in:
Mike Salvatore 2021-09-02 11:52:35 -04:00
parent 8144a3334e
commit 936074605f
1 changed files with 11 additions and 7 deletions

View File

@ -144,14 +144,18 @@ class PowerShellExploiter(HostExploiter):
return True
def _copy_monkey_binary_to_victim(self, monkey_path_on_victim) -> bool:
self._write_virtual_file_to_local_path()
try:
self._write_virtual_file_to_local_path()
logger.info(f"Attempting to copy the monkey agent binary to {self.host.ip_addr}")
is_monkey_copy_successful = self._client.copy_file(
TEMP_MONKEY_BINARY_FILEPATH, monkey_path_on_victim
)
os.remove(TEMP_MONKEY_BINARY_FILEPATH)
logger.info(f"Attempting to copy the monkey agent binary to {self.host.ip_addr}")
is_monkey_copy_successful = self._client.copy_file(
TEMP_MONKEY_BINARY_FILEPATH, monkey_path_on_victim
)
except Exception as ex:
raise ex
finally:
if os.path.isfile(TEMP_MONKEY_BINARY_FILEPATH):
os.remove(TEMP_MONKEY_BINARY_FILEPATH)
return is_monkey_copy_successful