forked from p15670423/monkey
Agent: Use interruptible_function decorator in ransomware payload
This commit is contained in:
parent
20e3b20cb5
commit
7047fa0cd0
|
@ -5,7 +5,7 @@ from typing import Callable, Iterable
|
||||||
|
|
||||||
from infection_monkey.telemetry.file_encryption_telem import FileEncryptionTelem
|
from infection_monkey.telemetry.file_encryption_telem import FileEncryptionTelem
|
||||||
from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger
|
from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger
|
||||||
from infection_monkey.utils.threading import interruptible_iter
|
from infection_monkey.utils.threading import interruptible_function, interruptible_iter
|
||||||
|
|
||||||
from .consts import README_FILE_NAME, README_SRC
|
from .consts import README_FILE_NAME, README_SRC
|
||||||
from .ransomware_options import RansomwareOptions
|
from .ransomware_options import RansomwareOptions
|
||||||
|
@ -47,7 +47,7 @@ class Ransomware:
|
||||||
self._encrypt_files(files_to_encrypt, interrupt)
|
self._encrypt_files(files_to_encrypt, interrupt)
|
||||||
|
|
||||||
if self._config.readme_enabled:
|
if self._config.readme_enabled:
|
||||||
self._leave_readme_in_target_directory(interrupt)
|
self._leave_readme_in_target_directory(interrupt=interrupt)
|
||||||
|
|
||||||
def _find_files(self) -> Iterable[Path]:
|
def _find_files(self) -> Iterable[Path]:
|
||||||
logger.info(f"Collecting files in {self._target_directory}")
|
logger.info(f"Collecting files in {self._target_directory}")
|
||||||
|
@ -72,11 +72,8 @@ class Ransomware:
|
||||||
encryption_attempt = FileEncryptionTelem(str(filepath), success, error)
|
encryption_attempt = FileEncryptionTelem(str(filepath), success, error)
|
||||||
self._telemetry_messenger.send_telemetry(encryption_attempt)
|
self._telemetry_messenger.send_telemetry(encryption_attempt)
|
||||||
|
|
||||||
def _leave_readme_in_target_directory(self, interrupt: threading.Event):
|
@interruptible_function(msg="Received a stop signal, skipping leave readme")
|
||||||
if interrupt.is_set():
|
def _leave_readme_in_target_directory(self, *, interrupt: threading.Event):
|
||||||
logger.debug("Received a stop signal, skipping leave readme")
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._leave_readme(README_SRC, self._readme_file_path) # type: ignore
|
self._leave_readme(README_SRC, self._readme_file_path) # type: ignore
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
Loading…
Reference in New Issue