From 59efaabd505b458ffe377fdc2eaa80be46810b97 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 28 Jun 2021 09:28:43 -0400 Subject: [PATCH 1/2] agent: Catch and log exceptions thrown by the ransomware payload --- monkey/infection_monkey/monkey.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index a70781333..bf3ae80a6 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -469,5 +469,8 @@ class InfectionMonkey(object): @staticmethod def run_ransomware(): - telemetry_messenger = TelemetryMessengerWrapper() - RansomewarePayload(WormConfiguration.ransomware, telemetry_messenger).run_payload() + try: + telemetry_messenger = TelemetryMessengerWrapper() + RansomewarePayload(WormConfiguration.ransomware, telemetry_messenger).run_payload() + except Exception as ex: + LOG.error(f"An unexpected error occurred while running the ransomware payload: {ex}") From 2ec020f2764cfe23bf34ac132cdcfd44fa419ac5 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 28 Jun 2021 09:29:48 -0400 Subject: [PATCH 2/2] agent: Add logging to ransomware payload --- monkey/infection_monkey/ransomware/ransomware_payload.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monkey/infection_monkey/ransomware/ransomware_payload.py b/monkey/infection_monkey/ransomware/ransomware_payload.py index f46c5ae72..da300a175 100644 --- a/monkey/infection_monkey/ransomware/ransomware_payload.py +++ b/monkey/infection_monkey/ransomware/ransomware_payload.py @@ -37,6 +37,7 @@ class RansomewarePayload: self._telemetry_messenger = telemetry_messenger def run_payload(self): + LOG.info("Running ransomware payload") file_list = self._find_files() self._encrypt_files(file_list) @@ -52,10 +53,12 @@ class RansomewarePayload: results = [] for filepath in file_list: try: + LOG.debug(f"Encrypting {filepath}") self._encryptor.encrypt_file_in_place(filepath) self._add_extension(filepath) self._send_telemetry(filepath, "") except Exception as ex: + LOG.warning(f"Error encrypting {filepath}: {ex}") self._send_telemetry(filepath, str(ex)) return results