Agent: Simplify and improve logging in RansomwarePayload

This commit is contained in:
Mike Salvatore 2021-06-30 07:43:18 -04:00
parent 946641f9a2
commit 169bb34106
1 changed files with 7 additions and 13 deletions

View File

@ -1,6 +1,7 @@
import logging import logging
import shutil import shutil
from pathlib import Path from pathlib import Path
from pprint import pformat
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
from infection_monkey.ransomware.bitflip_encryptor import BitflipEncryptor from infection_monkey.ransomware.bitflip_encryptor import BitflipEncryptor
@ -21,28 +22,18 @@ README_DEST = "README.txt"
class RansomwarePayload: class RansomwarePayload:
def __init__(self, config: dict, telemetry_messenger: ITelemetryMessenger): def __init__(self, config: dict, telemetry_messenger: ITelemetryMessenger):
LOG.debug(f"Ransomware payload configuration:\n{pformat(config)}")
self._encryption_enabled = config["encryption"]["enabled"] self._encryption_enabled = config["encryption"]["enabled"]
LOG.info( self._readme_enabled = config["other_behaviors"]["readme"]
f"Encryption routine for ransomware simulation enabled: {self._encryption_enabled}"
)
target_directories = config["encryption"]["directories"] target_directories = config["encryption"]["directories"]
LOG.info(
"Windows dir configured for encryption is " + target_directories["windows_target_dir"]
)
LOG.info(
f"Linux dir configured for encryption is \"{target_directories['linux_target_dir']}\""
)
self._target_dir = ( self._target_dir = (
target_directories["windows_target_dir"] target_directories["windows_target_dir"]
if is_windows_os() if is_windows_os()
else target_directories["linux_target_dir"] else target_directories["linux_target_dir"]
) )
self._readme_enabled = config["other_behaviors"]["readme"]
LOG.info(f"README enabled: {self._readme_enabled}")
self._new_file_extension = EXTENSION self._new_file_extension = EXTENSION
self._valid_file_extensions_for_encryption = VALID_FILE_EXTENSIONS_FOR_ENCRYPTION.copy() self._valid_file_extensions_for_encryption = VALID_FILE_EXTENSIONS_FOR_ENCRYPTION.copy()
self._valid_file_extensions_for_encryption.discard(self._new_file_extension) self._valid_file_extensions_for_encryption.discard(self._new_file_extension)
@ -59,6 +50,7 @@ class RansomwarePayload:
self._leave_readme() self._leave_readme()
def _find_files(self) -> List[Path]: def _find_files(self) -> List[Path]:
LOG.info(f"Collecting files in {self._target_dir}")
if not self._target_dir: if not self._target_dir:
return [] return []
@ -67,6 +59,8 @@ class RansomwarePayload:
) )
def _encrypt_files(self, file_list: List[Path]) -> List[Tuple[Path, Optional[Exception]]]: def _encrypt_files(self, file_list: List[Path]) -> List[Tuple[Path, Optional[Exception]]]:
LOG.info(f"Encrypting files in {self._target_dir}")
results = [] results = []
for filepath in file_list: for filepath in file_list:
try: try: