From 43c85284093a3c96b00678a85fd7308e42364e49 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Tue, 15 Mar 2022 14:10:35 +0200 Subject: [PATCH] Agent: Handle unexpected errors in mssqlexec.py --- monkey/infection_monkey/exploit/mssqlexec.py | 27 ++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/monkey/infection_monkey/exploit/mssqlexec.py b/monkey/infection_monkey/exploit/mssqlexec.py index ab9cfc8dd..0b18e824c 100644 --- a/monkey/infection_monkey/exploit/mssqlexec.py +++ b/monkey/infection_monkey/exploit/mssqlexec.py @@ -73,20 +73,27 @@ class MSSQLExploiter(HostExploiter): ) return self.exploit_result - # Create dir for payload - self.create_temp_dir() - self.create_empty_payload_file() + try: + # Create dir for payload + self.create_temp_dir() + self.create_empty_payload_file() - http_thread = self.start_monkey_server() - self.upload_monkey() - MSSQLExploiter._stop_monkey_server(http_thread) + http_thread = self.start_monkey_server() + self.upload_monkey() + MSSQLExploiter._stop_monkey_server(http_thread) - # Clear payload to pass in another command - self.create_empty_payload_file() + # Clear payload to pass in another command + self.create_empty_payload_file() - self.run_monkey() + self.run_monkey() - self.remove_temp_dir() + self.remove_temp_dir() + except Exception as e: + logger.error( + f"Unhandled exception occurred when trying " + f"to exploit MSSQL on host {self.host}: {e}" + ) + return self.exploit_result self.exploit_result.propagation_success = True return self.exploit_result