From afd3160c2f37cc76f30a0c1927d84a06ac19dfa0 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 16 Jun 2022 20:00:23 -0400 Subject: [PATCH] Common: Add ExploitationOptionsConfiguration --- monkey/common/configuration/__init__.py | 2 ++ monkey/common/configuration/agent_configuration.py | 13 +++++++++++++ .../unit_tests/common/test_agent_configuration.py | 10 ++++++++++ vulture_allowlist.py | 1 + 4 files changed, 26 insertions(+) diff --git a/monkey/common/configuration/__init__.py b/monkey/common/configuration/__init__.py index ed2b3cbc9..f9b876cdf 100644 --- a/monkey/common/configuration/__init__.py +++ b/monkey/common/configuration/__init__.py @@ -3,6 +3,8 @@ from .agent_configuration import ( PluginConfigurationSchema, CustomPBAConfiguration, CustomPBAConfigurationSchema, + ExploitationOptionsConfiguration, + ExploitationOptionsConfigurationSchema, ExploiterConfiguration, ExploiterConfigurationSchema, ) diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py index 6ac8f9a2a..5bb1feba4 100644 --- a/monkey/common/configuration/agent_configuration.py +++ b/monkey/common/configuration/agent_configuration.py @@ -47,6 +47,19 @@ class PluginConfigurationSchema(Schema): return PluginConfiguration(**data) +@dataclass(frozen=True) +class ExploitationOptionsConfiguration: + http_ports: List[int] + + +class ExploitationOptionsConfigurationSchema(Schema): + http_ports = fields.List(fields.Int()) + + @post_load + def make_exploitation_options_configuration(self, data, **kwargs): + return ExploitationOptionsConfiguration(**data) + + @dataclass(frozen=True) class ExploiterConfiguration: name: str diff --git a/monkey/tests/unit_tests/common/test_agent_configuration.py b/monkey/tests/unit_tests/common/test_agent_configuration.py index 6fd5ac290..21c0c8575 100644 --- a/monkey/tests/unit_tests/common/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/test_agent_configuration.py @@ -1,6 +1,7 @@ from common import OperatingSystems from common.configuration import ( CustomPBAConfigurationSchema, + ExploitationOptionsConfigurationSchema, ExploiterConfigurationSchema, PluginConfigurationSchema, ) @@ -39,6 +40,15 @@ def test_custom_pba_configuration_schema(): assert config.windows_filename == windows_filename +def test_exploitation_options_configuration_schema(): + ports = [1, 2, 3] + schema = ExploitationOptionsConfigurationSchema() + + config = schema.load({"http_ports": ports}) + + assert config.http_ports == ports + + def test_exploiter_configuration_schema(): name = "bond" options = {"gun": "Walther PPK", "car": "Aston Martin DB5"} diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 7e1c4056a..bff9d7991 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -188,6 +188,7 @@ Meta # unused class (monkey/common/configuration/agent_configuration.py:13) unknown # unused variable (monkey/common/configuration/agent_configuration.py:14) make_plugin_configuration # unused method (monkey/common/configuration/agent_configuration.py:19) make_custom_pba_configuration # unused method (monkey/common/configuration/agent_configuration.py:34) +make_exploitation_options_configuration # unused method (monkey/common/configuration/agent_configuration.py:58) make_exploiter_configuration # unused method (monkey/common/configuration/agent_configuration.py:62) LINUX # unused variable (monkey/common/operating_systems.py:5) WINDOWS # unused variable (monkey/common/operating_systems.py:6)