From e576136a63b52efb44c3c08f5525407b4ff05f13 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 20 Jan 2022 08:52:09 -0500 Subject: [PATCH] Agent: Skip Log4Shell exploiter if there are no open ports --- monkey/infection_monkey/exploit/log4shell.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/monkey/infection_monkey/exploit/log4shell.py b/monkey/infection_monkey/exploit/log4shell.py index 48d331aaa..ed2290279 100644 --- a/monkey/infection_monkey/exploit/log4shell.py +++ b/monkey/infection_monkey/exploit/log4shell.py @@ -45,8 +45,15 @@ class Log4ShellExploiter(WebRCE): self._ldap_server = None self._exploit_class_http_server = None self._agent_http_server_thread = None + self._open_ports = [ + int(port[0]) for port in WebRCE.get_open_service_ports(self.host, self.HTTP, ["http"]) + ] def _exploit_host(self): + if not self._open_ports: + logger.info("Could not find any open web ports to exploit") + return False + self._start_servers() try: return self.exploit(None, None) @@ -130,11 +137,8 @@ class Log4ShellExploiter(WebRCE): def exploit(self, url, command) -> bool: # Try to exploit all services, # because we don't know which services are running and on which ports - open_ports = [ - int(port[0]) for port in WebRCE.get_open_service_ports(self.host, self.HTTP, ["http"]) - ] for exploit in get_log4shell_service_exploiters(): - for port in open_ports: + for port in self._open_ports: try: exploit.trigger_exploit(self._build_ldap_payload(), self.host, port) except Exception as ex: