From c18af3c3fb37e1101f8e0a2d9c39b9c9fcd0271f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 17 Dec 2021 08:14:53 -0500 Subject: [PATCH] Agent: Change return type of IPuppet.run_payload() to None At the moment, we don't expect payloads to return any values. This may be reevaluated as development proceeds or when telemetry is refactored. --- monkey/infection_monkey/i_puppet.py | 8 ++++---- monkey/infection_monkey/master/mock_master.py | 5 +---- monkey/infection_monkey/puppet/mock_puppet.py | 7 ++----- monkey/infection_monkey/puppet/puppet.py | 6 ++---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/monkey/infection_monkey/i_puppet.py b/monkey/infection_monkey/i_puppet.py index e25d20f53..50e050dc6 100644 --- a/monkey/infection_monkey/i_puppet.py +++ b/monkey/infection_monkey/i_puppet.py @@ -2,7 +2,7 @@ import abc import threading from collections import namedtuple from enum import Enum -from typing import Dict, Tuple +from typing import Dict from infection_monkey.puppet.plugin_type import PluginType @@ -107,13 +107,13 @@ class IPuppet(metaclass=abc.ABCMeta): """ @abc.abstractmethod - def run_payload( - self, name: str, options: Dict, interrupt: threading.Event - ) -> Tuple[None, bool, str]: + def run_payload(self, name: str, options: Dict, interrupt: threading.Event): """ Runs a payload :param str name: The name of the payload to run :param Dict options: A dictionary containing options that modify the behavior of the payload + :param threading.Event interrupt: A threading.Event object that signals the payload to stop + executing and clean itself up. """ @abc.abstractmethod diff --git a/monkey/infection_monkey/master/mock_master.py b/monkey/infection_monkey/master/mock_master.py index 0b4f9a3f6..31d4d83a7 100644 --- a/monkey/infection_monkey/master/mock_master.py +++ b/monkey/infection_monkey/master/mock_master.py @@ -4,7 +4,6 @@ from infection_monkey.i_master import IMaster from infection_monkey.i_puppet import IPuppet, PortStatus from infection_monkey.model.host import VictimHost from infection_monkey.telemetry.exploit_telem import ExploitTelem -from infection_monkey.telemetry.file_encryption_telem import FileEncryptionTelem from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger from infection_monkey.telemetry.post_breach_telem import PostBreachTelem from infection_monkey.telemetry.scan_telem import ScanTelem @@ -119,9 +118,7 @@ class MockMaster(IMaster): def _run_payload(self): logger.info("Running payloads") - # TODO: modify what FileEncryptionTelem gets - path, success, error = self._puppet.run_payload("RansomwarePayload", {}, None) - self._telemetry_messenger.send_telemetry(FileEncryptionTelem(path, success, error)) + self._puppet.run_payload("RansomwarePayload", {}, None) logger.info("Finished running payloads") def terminate(self, block: bool = False) -> None: diff --git a/monkey/infection_monkey/puppet/mock_puppet.py b/monkey/infection_monkey/puppet/mock_puppet.py index 204e44ab4..59539c58b 100644 --- a/monkey/infection_monkey/puppet/mock_puppet.py +++ b/monkey/infection_monkey/puppet/mock_puppet.py @@ -1,6 +1,6 @@ import logging import threading -from typing import Dict, Tuple +from typing import Dict from infection_monkey.i_puppet import ( ExploiterResultData, @@ -299,11 +299,8 @@ class MockPuppet(IPuppet): except KeyError: return ExploiterResultData(False, {}, [], f"{name} failed for host {host}") - def run_payload( - self, name: str, options: Dict, interrupt: threading.Event - ) -> Tuple[None, bool, str]: + def run_payload(self, name: str, options: Dict, interrupt: threading.Event): logger.debug(f"run_payload({name}, {options})") - return (None, True, "") def cleanup(self) -> None: print("Cleanup called!") diff --git a/monkey/infection_monkey/puppet/puppet.py b/monkey/infection_monkey/puppet/puppet.py index f932d84a4..5563a2dfe 100644 --- a/monkey/infection_monkey/puppet/puppet.py +++ b/monkey/infection_monkey/puppet/puppet.py @@ -1,6 +1,6 @@ import logging import threading -from typing import Dict, Tuple +from typing import Dict from infection_monkey.i_puppet import ( ExploiterResultData, @@ -45,9 +45,7 @@ class Puppet(IPuppet): ) -> ExploiterResultData: pass - def run_payload( - self, name: str, options: Dict, interrupt: threading.Event - ) -> Tuple[None, bool, str]: + def run_payload(self, name: str, options: Dict, interrupt: threading.Event): pass def cleanup(self) -> None: