From 8921ed77ac142773bc3a35673e239d3e760e73a1 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Mon, 21 Mar 2022 18:05:30 +0100 Subject: [PATCH] Agent: Make Hadoop interruptable --- monkey/infection_monkey/exploit/hadoop.py | 9 +++++++++ monkey/infection_monkey/exploit/web_rce.py | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/exploit/hadoop.py b/monkey/infection_monkey/exploit/hadoop.py index 73caf065a..60ba4285d 100644 --- a/monkey/infection_monkey/exploit/hadoop.py +++ b/monkey/infection_monkey/exploit/hadoop.py @@ -65,6 +65,10 @@ class HadoopExploiter(WebRCE): return self.exploit_result def exploit(self, url, command): + if self._is_interrupted(): + self._set_interrupted() + return False + # Get the newly created application id resp = requests.post( posixpath.join(url, "ws/v1/cluster/apps/new-application"), timeout=LONG_REQUEST_TIMEOUT @@ -78,6 +82,11 @@ class HadoopExploiter(WebRCE): [random.choice(string.ascii_lowercase) for _ in range(self.RAN_STR_LEN)] # noqa: DUO102 ) payload = self._build_payload(app_id, rand_name, command) + + if self._is_interrupted(): + self._set_interrupted() + return False + resp = requests.post( posixpath.join(url, "ws/v1/cluster/apps/"), json=payload, timeout=LONG_REQUEST_TIMEOUT ) diff --git a/monkey/infection_monkey/exploit/web_rce.py b/monkey/infection_monkey/exploit/web_rce.py index 1c0bbdb88..87494af95 100644 --- a/monkey/infection_monkey/exploit/web_rce.py +++ b/monkey/infection_monkey/exploit/web_rce.py @@ -23,6 +23,7 @@ from infection_monkey.network.tools import tcp_port_to_service from infection_monkey.telemetry.attack.t1197_telem import T1197Telem from infection_monkey.telemetry.attack.t1222_telem import T1222Telem from infection_monkey.utils.commands import build_monkey_commandline +from infection_monkey.utils.threading import interruptable_iter logger = logging.getLogger(__name__) # Command used to check if monkeys already exists @@ -232,7 +233,7 @@ class WebRCE(HostExploiter): is found (bool) :return: None (we append to class variable vulnerable_urls) """ - for url in urls: + for url in interruptable_iter(urls, self.interrupt): if self.check_if_exploitable(url): self.add_vuln_url(url) self.vulnerable_urls.append(url)