Agent: Remove unnecessary interrupts from log4shell

This commit is contained in:
vakaris_zilius 2022-03-21 16:09:43 +00:00
parent 0f77d4ca37
commit 325c4368de
1 changed files with 5 additions and 15 deletions

View File

@ -18,6 +18,7 @@ from infection_monkey.network.info import get_free_tcp_port
from infection_monkey.network.tools import get_interface_to_target from infection_monkey.network.tools import get_interface_to_target
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.monkey_dir import get_monkey_dir_path from infection_monkey.utils.monkey_dir import get_monkey_dir_path
from infection_monkey.utils.threading import interruptable_iter
from infection_monkey.utils.timer import Timer from infection_monkey.utils.timer import Timer
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -42,6 +43,8 @@ class Log4ShellExploiter(WebRCE):
self._start_servers() self._start_servers()
try: try:
self.exploit(None, None) self.exploit(None, None)
if self._is_interrupted():
self._set_interrupted()
return self.exploit_result return self.exploit_result
finally: finally:
self._stop_servers() self._stop_servers()
@ -133,11 +136,8 @@ class Log4ShellExploiter(WebRCE):
# Try to exploit all services, # Try to exploit all services,
# because we don't know which services are running and on which ports # because we don't know which services are running and on which ports
for exploit in get_log4shell_service_exploiters(): for exploit in get_log4shell_service_exploiters():
for port in self._open_ports: intr_ports = interruptable_iter(self._open_ports, self.interrupt)
for port in intr_ports:
if self._is_interrupted():
self._set_interrupted()
return self.exploit_result
logger.debug( logger.debug(
f'Attempting Log4Shell exploit on for service "{exploit.service_name}"' f'Attempting Log4Shell exploit on for service "{exploit.service_name}"'
@ -151,10 +151,6 @@ class Log4ShellExploiter(WebRCE):
f"potential {exploit.service_name} service: {ex}" f"potential {exploit.service_name} service: {ex}"
) )
if self._is_interrupted():
self._set_interrupted()
return self.exploit_result
if self._wait_for_victim(): if self._wait_for_victim():
self.exploit_info["vulnerable_service"] = { self.exploit_info["vulnerable_service"] = {
"service_name": exploit.service_name, "service_name": exploit.service_name,
@ -168,9 +164,6 @@ class Log4ShellExploiter(WebRCE):
if victim_called_back: if victim_called_back:
self._wait_for_victim_to_download_agent() self._wait_for_victim_to_download_agent()
if self._is_interrupted():
return False
return victim_called_back return victim_called_back
def _wait_for_victim_to_download_java_bytecode(self) -> bool: def _wait_for_victim_to_download_java_bytecode(self) -> bool:
@ -196,8 +189,5 @@ class Log4ShellExploiter(WebRCE):
if self._agent_http_server_thread.downloads > 0: if self._agent_http_server_thread.downloads > 0:
break break
if self._is_interrupted():
return
# TODO: if the http server got an error we're waiting for nothing here # TODO: if the http server got an error we're waiting for nothing here
time.sleep(1) time.sleep(1)