From 6bdd5ef1797d6c2fab67084b956c972003cdef8f Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Thu, 17 Mar 2022 13:50:02 +0000 Subject: [PATCH] Agent, UI: Improve style with small changes in interrupt code --- monkey/infection_monkey/exploit/HostExploiter.py | 1 + monkey/infection_monkey/exploit/wmiexec.py | 9 ++++++--- .../monkey_island/cc/ui/src/components/pages/MapPage.js | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/exploit/HostExploiter.py b/monkey/infection_monkey/exploit/HostExploiter.py index 54766d4b2..032a0564c 100644 --- a/monkey/infection_monkey/exploit/HostExploiter.py +++ b/monkey/infection_monkey/exploit/HostExploiter.py @@ -100,6 +100,7 @@ class HostExploiter: # Ideally the user should only do "check_for_interrupt()" if self.interrupt.is_set(): logger.info("Exploiter has been interrupted by a stop signal from the Island") + self.exploit_result["error_message"] = "Exploiter has been interrupted by a stop signal from the Island" return self.interrupt.is_set() def post_exploit(self): diff --git a/monkey/infection_monkey/exploit/wmiexec.py b/monkey/infection_monkey/exploit/wmiexec.py index 1371ae9f2..a428a4759 100644 --- a/monkey/infection_monkey/exploit/wmiexec.py +++ b/monkey/infection_monkey/exploit/wmiexec.py @@ -15,6 +15,7 @@ from infection_monkey.utils.brute_force import ( get_credential_string, ) from infection_monkey.utils.commands import build_monkey_commandline +from infection_monkey.utils.threading import interruptable_iter logger = logging.getLogger(__name__) @@ -28,10 +29,12 @@ class WmiExploiter(HostExploiter): def _exploit_host(self) -> ExploiterResultData: creds = generate_brute_force_combinations(self.options["credentials"]) + intp_creds = interruptable_iter(creds, + self.interrupt, + "WMI exploiter has been interrupted by a stop signal from the Island", + logging.INFO) - for user, password, lm_hash, ntlm_hash in creds: - if self.is_interrupted(): - return self.exploit_result + for user, password, lm_hash, ntlm_hash in intp_creds: creds_for_log = get_credential_string([user, password, lm_hash, ntlm_hash]) logger.debug(f"Attempting to connect to {self.host} using WMI with {creds_for_log}") diff --git a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js index 9b4b09f4c..fa782eac7 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/MapPage.js @@ -88,8 +88,8 @@ class MapPageComponent extends AuthComponent { { method: 'POST', headers: {'Content-Type': 'application/json'}, - // Python uses seconds, Date.now uses milliseconds, so convert - body: JSON.stringify({kill_time: Date.now() / 1000}) + // Python uses floating point seconds, Date.now uses milliseconds, so convert + body: JSON.stringify({kill_time: Date.now() / 1000.0}) }) .then(res => res.json()) .then(res => {this.setState({killPressed: true})});