diff --git a/monkey/common/configuration/__init__.py b/monkey/common/configuration/__init__.py index c7fefc11b..fc1f3c84d 100644 --- a/monkey/common/configuration/__init__.py +++ b/monkey/common/configuration/__init__.py @@ -7,7 +7,6 @@ from .agent_sub_configurations import ( TCPScanConfiguration, NetworkScanConfiguration, ExploitationOptionsConfiguration, - ExploiterConfiguration, ExploitationConfiguration, PropagationConfiguration, ) diff --git a/monkey/common/configuration/agent_sub_configuration_schemas.py b/monkey/common/configuration/agent_sub_configuration_schemas.py index 4d2ee2d8e..bf4d3b8c7 100644 --- a/monkey/common/configuration/agent_sub_configuration_schemas.py +++ b/monkey/common/configuration/agent_sub_configuration_schemas.py @@ -4,7 +4,6 @@ from .agent_sub_configurations import ( CustomPBAConfiguration, ExploitationConfiguration, ExploitationOptionsConfiguration, - ExploiterConfiguration, ICMPScanConfiguration, NetworkScanConfiguration, PluginConfiguration, @@ -81,19 +80,10 @@ class ExploitationOptionsConfigurationSchema(Schema): return ExploitationOptionsConfiguration(**data) -class ExploiterConfigurationSchema(Schema): - name = fields.Str() - options = fields.Mapping() - - @post_load - def _make_exploiter_configuration(self, data, **kwargs): - return ExploiterConfiguration(**data) - - class ExploitationConfigurationSchema(Schema): options = fields.Nested(ExploitationOptionsConfigurationSchema) - brute_force = fields.List(fields.Nested(ExploiterConfigurationSchema)) - vulnerability = fields.List(fields.Nested(ExploiterConfigurationSchema)) + brute_force = fields.List(fields.Nested(PluginConfigurationSchema)) + vulnerability = fields.List(fields.Nested(PluginConfigurationSchema)) @post_load def _make_exploitation_options_configuration(self, data, **kwargs): diff --git a/monkey/common/configuration/agent_sub_configurations.py b/monkey/common/configuration/agent_sub_configurations.py index c4a0c704c..d93b4d774 100644 --- a/monkey/common/configuration/agent_sub_configurations.py +++ b/monkey/common/configuration/agent_sub_configurations.py @@ -48,17 +48,11 @@ class ExploitationOptionsConfiguration: http_ports: List[int] -@dataclass(frozen=True) -class ExploiterConfiguration: - name: str - options: Dict - - @dataclass(frozen=True) class ExploitationConfiguration: options: ExploitationOptionsConfiguration - brute_force: List[ExploiterConfiguration] - vulnerability: List[ExploiterConfiguration] + brute_force: List[PluginConfiguration] + vulnerability: List[PluginConfiguration] @dataclass(frozen=True) diff --git a/monkey/common/configuration/default_agent_configuration.py b/monkey/common/configuration/default_agent_configuration.py index 4eb8496a2..251676017 100644 --- a/monkey/common/configuration/default_agent_configuration.py +++ b/monkey/common/configuration/default_agent_configuration.py @@ -3,7 +3,6 @@ from .agent_sub_configurations import ( CustomPBAConfiguration, ExploitationConfiguration, ExploitationOptionsConfiguration, - ExploiterConfiguration, ICMPScanConfiguration, NetworkScanConfiguration, PluginConfiguration, @@ -83,16 +82,16 @@ NETWORK_SCAN_CONFIGURATION = NetworkScanConfiguration( EXPLOITATION_OPTIONS_CONFIGURATION = ExploitationOptionsConfiguration(HTTP_PORTS) BRUTE_FORCE_EXPLOITERS = [ - ExploiterConfiguration("MSSQLExploiter", {}), - ExploiterConfiguration("PowerShellExploiter", {}), - ExploiterConfiguration("SSHExploiter", {}), - ExploiterConfiguration("SmbExploiter", {"smb_download_timeout": 30}), - ExploiterConfiguration("WmiExploiter", {"smb_download_timeout": 30}), + PluginConfiguration("MSSQLExploiter", {}), + PluginConfiguration("PowerShellExploiter", {}), + PluginConfiguration("SSHExploiter", {}), + PluginConfiguration("SmbExploiter", {"smb_download_timeout": 30}), + PluginConfiguration("WmiExploiter", {"smb_download_timeout": 30}), ] VULNERABILITY_EXPLOITERS = [ - ExploiterConfiguration("Log4ShellExploiter", {}), - ExploiterConfiguration("HadoopExploiter", {}), + PluginConfiguration("Log4ShellExploiter", {}), + PluginConfiguration("HadoopExploiter", {}), ] EXPLOITATION_CONFIGURATION = ExploitationConfiguration( diff --git a/monkey/infection_monkey/master/exploiter.py b/monkey/infection_monkey/master/exploiter.py index 53665da38..6171576f2 100644 --- a/monkey/infection_monkey/master/exploiter.py +++ b/monkey/infection_monkey/master/exploiter.py @@ -10,7 +10,7 @@ from typing import Callable, Dict, Sequence from common import OperatingSystems from common.configuration.agent_sub_configurations import ( ExploitationConfiguration, - ExploiterConfiguration, + PluginConfiguration, ) from infection_monkey.custom_types import PropagationCredentials from infection_monkey.i_puppet import ExploiterResultData, IPuppet @@ -81,7 +81,7 @@ class Exploiter: @staticmethod def _process_exploiter_config( exploiter_config: ExploitationConfiguration, - ) -> Sequence[ExploiterConfiguration]: + ) -> Sequence[PluginConfiguration]: # Run vulnerability exploiters before brute force exploiters to minimize the effect of # account lockout due to invalid credentials ordered_exploiters = chain(exploiter_config.vulnerability, exploiter_config.brute_force) @@ -92,13 +92,13 @@ class Exploiter: # This order allows exploiter-specific options to # override general options for all exploiters. options = {**exploiter_config.options.__dict__, **exploiter.options} - extended_exploiters.append(ExploiterConfiguration(exploiter.name, options)) + extended_exploiters.append(PluginConfiguration(exploiter.name, options)) return extended_exploiters def _exploit_hosts_on_queue( self, - exploiters_to_run: Sequence[ExploiterConfiguration], + exploiters_to_run: Sequence[PluginConfiguration], hosts_to_exploit: Queue, current_depth: int, results_callback: Callback, @@ -125,7 +125,7 @@ class Exploiter: def _run_all_exploiters( self, - exploiters_to_run: Sequence[ExploiterConfiguration], + exploiters_to_run: Sequence[PluginConfiguration], victim_host: VictimHost, current_depth: int, results_callback: Callback, diff --git a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py index e06a4cf3e..fecb6a6f6 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -33,7 +33,6 @@ from common.configuration.agent_sub_configuration_schemas import ( CustomPBAConfigurationSchema, ExploitationConfigurationSchema, ExploitationOptionsConfigurationSchema, - ExploiterConfigurationSchema, ICMPScanConfigurationSchema, NetworkScanConfigurationSchema, PluginConfigurationSchema, @@ -126,7 +125,7 @@ def test_exploitation_options_configuration_schema(): def test_exploiter_configuration_schema(): name = "bond" options = {"gun": "Walther PPK", "car": "Aston Martin DB5"} - schema = ExploiterConfigurationSchema() + schema = PluginConfigurationSchema() config = schema.load({"name": name, "options": options}) diff --git a/monkey/tests/unit_tests/infection_monkey/master/test_exploiter.py b/monkey/tests/unit_tests/infection_monkey/master/test_exploiter.py index cc7e497b6..4a44cca95 100644 --- a/monkey/tests/unit_tests/infection_monkey/master/test_exploiter.py +++ b/monkey/tests/unit_tests/infection_monkey/master/test_exploiter.py @@ -10,7 +10,7 @@ from tests.unit_tests.infection_monkey.master.mock_puppet import MockPuppet from common import OperatingSystems from common.configuration.agent_sub_configurations import ( ExploitationConfiguration, - ExploiterConfiguration, + PluginConfiguration, ) from infection_monkey.master import Exploiter from infection_monkey.model import VictimHost @@ -41,11 +41,11 @@ def callback(): @pytest.fixture def exploiter_config(default_agent_configuration): brute_force = [ - ExploiterConfiguration(name="MSSQLExploiter", options={"timeout": 10}), - ExploiterConfiguration(name="SSHExploiter", options={}), - ExploiterConfiguration(name="WmiExploiter", options={"timeout": 10}), + PluginConfiguration(name="MSSQLExploiter", options={"timeout": 10}), + PluginConfiguration(name="SSHExploiter", options={}), + PluginConfiguration(name="WmiExploiter", options={"timeout": 10}), ] - vulnerability = [ExploiterConfiguration(name="ZerologonExploiter", options={})] + vulnerability = [PluginConfiguration(name="ZerologonExploiter", options={})] return ExploitationConfiguration( options=default_agent_configuration.propagation.exploitation.options, brute_force=brute_force,