From 30c41592fbe644b46e6d615e49fc955ffc72b558 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 10 Jan 2022 08:50:09 -0500 Subject: [PATCH] Agent: Remove dependency on threading from LDAPExploitServer --- monkey/infection_monkey/exploit/log4shell.py | 8 ++++++-- .../exploit/log4shell_utils/ldap_server.py | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/exploit/log4shell.py b/monkey/infection_monkey/exploit/log4shell.py index 51fb46de1..4ad252204 100644 --- a/monkey/infection_monkey/exploit/log4shell.py +++ b/monkey/infection_monkey/exploit/log4shell.py @@ -95,8 +95,12 @@ class Log4ShellExploiter(WebRCE): http_server_port=self.class_http_server_port, storage_dir=get_monkey_dir_path(), ) - ldap_thread = self.ldap_server.get_run_thread() - self.ldap_server_thread = ldap_thread + + # Setting `daemon=True` to save ourselves some trouble when this is merged to the + # agent-refactor branch. + # TODO: Make a call to `create_daemon_thread()` instead of calling the `Thread()` + # constructor directly after merging to the agent-refactor branch. + self.ldap_server_thread = Thread(target=self.ldap_server.run, daemon=True) self.ldap_server_thread.start() def stop_servers(self): diff --git a/monkey/infection_monkey/exploit/log4shell_utils/ldap_server.py b/monkey/infection_monkey/exploit/log4shell_utils/ldap_server.py index 8cad3fba3..f575f20cc 100644 --- a/monkey/infection_monkey/exploit/log4shell_utils/ldap_server.py +++ b/monkey/infection_monkey/exploit/log4shell_utils/ldap_server.py @@ -1,6 +1,5 @@ import tempfile from pathlib import Path -from threading import Thread from ldaptor.interfaces import IConnectedLDAPEntry from ldaptor.ldiftree import LDIFTreeEntry @@ -84,8 +83,8 @@ class LDAPExploitServer: log_observer = log.PythonLoggingObserver() log_observer.start() - def get_run_thread(self) -> Thread: - return Thread(target=reactor.run, args=[None]) + def run(self): + reactor.run() def stop(self): reactor.stop()