From 8ef6a50180eee1dab66b34262f9c2325b0fbc45e Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 2 Jul 2021 15:11:30 +0300 Subject: [PATCH] Fix a bug in ransomware directories that caused environmental variables to not be expanded --- monkey/infection_monkey/ransomware/ransomware_payload.py | 5 +++-- monkey/infection_monkey/telemetry/file_encryption_telem.py | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/ransomware/ransomware_payload.py b/monkey/infection_monkey/ransomware/ransomware_payload.py index a3ae684ae..ac15bfa5a 100644 --- a/monkey/infection_monkey/ransomware/ransomware_payload.py +++ b/monkey/infection_monkey/ransomware/ransomware_payload.py @@ -1,4 +1,5 @@ import logging +import os import shutil from pathlib import Path from pprint import pformat @@ -55,7 +56,7 @@ class RansomwarePayload: return [] return select_production_safe_target_files( - Path(self._target_dir), self._valid_file_extensions_for_encryption + Path(os.path.expandvars(self._target_dir)), self._valid_file_extensions_for_encryption ) def _encrypt_files(self, file_list: List[Path]) -> List[Tuple[Path, Optional[Exception]]]: @@ -84,7 +85,7 @@ class RansomwarePayload: def _leave_readme(self): if self._readme_enabled: - readme_dest_path = Path(self._target_dir) / README_DEST + readme_dest_path = Path(os.path.expandvars(self._target_dir)) / README_DEST LOG.info(f"Leaving a ransomware README file at {readme_dest_path}") try: diff --git a/monkey/infection_monkey/telemetry/file_encryption_telem.py b/monkey/infection_monkey/telemetry/file_encryption_telem.py index 7f18867ab..7ecdd6ec0 100644 --- a/monkey/infection_monkey/telemetry/file_encryption_telem.py +++ b/monkey/infection_monkey/telemetry/file_encryption_telem.py @@ -1,5 +1,3 @@ -from pathlib import Path - from common.common_consts.telem_categories import TelemCategoryEnum from infection_monkey.telemetry.base_telem import BaseTelem from infection_monkey.telemetry.batchable_telem_mixin import BatchableTelemMixin @@ -7,7 +5,7 @@ from infection_monkey.telemetry.i_batchable_telem import IBatchableTelem class FileEncryptionTelem(BatchableTelemMixin, IBatchableTelem, BaseTelem): - def __init__(self, filepath: Path, success: bool, error: str): + def __init__(self, filepath: str, success: bool, error: str): """ File Encryption telemetry constructor :param filepath: The path to the file that monkey attempted to encrypt