From 2ea3a272633d2bfec6a9c179914e00f89d67127e Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:08:30 +0530 Subject: [PATCH 1/8] Common: Add docstring to PropagationConfiguration dataclass --- .../agent_configuration/agent_sub_configurations.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/monkey/common/agent_configuration/agent_sub_configurations.py b/monkey/common/agent_configuration/agent_sub_configurations.py index ab05a55cc..6fd9e5afd 100644 --- a/monkey/common/agent_configuration/agent_sub_configurations.py +++ b/monkey/common/agent_configuration/agent_sub_configurations.py @@ -118,6 +118,15 @@ class ExploitationConfiguration: @dataclass(frozen=True) class PropagationConfiguration: + """ + A configuration for propagation + + Attributes: + :param maximum_depth: Maximum number of hops to take from the Island server + :param network_scan: Configuration for network scanning + :param exploitation: Configuration for exploitation + """ + maximum_depth: int network_scan: NetworkScanConfiguration exploitation: ExploitationConfiguration From c53d41645cdfeccd442d6f2b7a6331459b3f6506 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:15:33 +0530 Subject: [PATCH 2/8] Common: Add maximum depth validation to PropagationConfigurationSchema --- .../agent_configuration/agent_sub_configuration_schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/common/agent_configuration/agent_sub_configuration_schemas.py b/monkey/common/agent_configuration/agent_sub_configuration_schemas.py index 15fdd6ba9..e666407ac 100644 --- a/monkey/common/agent_configuration/agent_sub_configuration_schemas.py +++ b/monkey/common/agent_configuration/agent_sub_configuration_schemas.py @@ -135,7 +135,7 @@ class ExploitationConfigurationSchema(Schema): class PropagationConfigurationSchema(Schema): - maximum_depth = fields.Int() + maximum_depth = fields.Int(validate=validate.Range(min=1)) network_scan = fields.Nested(NetworkScanConfigurationSchema) exploitation = fields.Nested(ExploitationConfigurationSchema) From afc2021470ee78e794933412e6a0860044fe1aa1 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:16:04 +0530 Subject: [PATCH 3/8] UT: Add test for PropagationConfigurationSchema maximum depth validation --- .../common/configuration/test_agent_configuration.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 95539b9c7..7a93fbe96 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -225,6 +225,17 @@ def test_propagation_configuration(): assert config_dict == PROPAGATION_CONFIGURATION +@pytest.mark.parametrize("depth", [-1, 0]) +def test_propagation_configuration__invalid_maximum_depth(depth): + schema = PropagationConfigurationSchema() + + invalid_maximum_depth_configuration = PROPAGATION_CONFIGURATION.copy() + invalid_maximum_depth_configuration["maximum_depth"] = depth + + with pytest.raises(ValidationError): + schema.load(invalid_maximum_depth_configuration) + + def test_agent_configuration(): config = AgentConfiguration.from_mapping(AGENT_CONFIGURATION) config_json = AgentConfiguration.to_json(config) From 6da238fe1d423b78527db0ab532dc168d9703860 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:43:28 +0530 Subject: [PATCH 4/8] Common: Reword PropagationConfiguration docstring --- monkey/common/agent_configuration/agent_sub_configurations.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/monkey/common/agent_configuration/agent_sub_configurations.py b/monkey/common/agent_configuration/agent_sub_configurations.py index 6fd9e5afd..6811d12d1 100644 --- a/monkey/common/agent_configuration/agent_sub_configurations.py +++ b/monkey/common/agent_configuration/agent_sub_configurations.py @@ -122,7 +122,9 @@ class PropagationConfiguration: A configuration for propagation Attributes: - :param maximum_depth: Maximum number of hops to take from the Island server + :param maximum_depth: Maximum number of hops allowed to spread from the machine where + the attack started i.e. how far to propagate in the network from the + first machine :param network_scan: Configuration for network scanning :param exploitation: Configuration for exploitation """ From a89741190ff34c19668ec3ad4f6ec189ca0609bc Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:44:57 +0530 Subject: [PATCH 5/8] UI: Change minimum value of maximum_depth to 0 in the propagation schema --- .../cc/ui/src/services/configuration/propagation/propagation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js b/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js index 6df67ff3e..919b1ae8b 100644 --- a/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js +++ b/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js @@ -11,7 +11,7 @@ const PROPAGATION_CONFIGURATION_SCHEMA = { 'maximum_depth': { 'title': 'Maximum scan depth', 'type': 'integer', - 'minimum': 1, + 'minimum': 0, 'default': 2, 'description': 'Amount of hops allowed for the monkey to spread from the ' + 'Island server. \n' + From b4243216a32080e00f566a144d2a820d24586deb Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:47:30 +0530 Subject: [PATCH 6/8] UI: Modify description of maximum_depth in the propagation schema --- .../ui/src/services/configuration/propagation/propagation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js b/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js index 919b1ae8b..e479de369 100644 --- a/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js +++ b/monkey/monkey_island/cc/ui/src/services/configuration/propagation/propagation.js @@ -18,7 +18,8 @@ const PROPAGATION_CONFIGURATION_SCHEMA = { ' \u26A0' + ' Note that setting this value too high may result in the ' + 'Monkey propagating too far, '+ - 'if the "Local network scan" is enabled' + 'if "Local network scan" is enabled.\n' + + 'Setting this to 0 will disable all scanning and exploitation.' }, 'network_scan': NETWORK_SCAN_CONFIGURATION_SCHEMA } From a9fa7427f375f3b7c12400a4297cfb1c4ca7ad1c Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:48:56 +0530 Subject: [PATCH 7/8] Common: Change minimum value of maximum_depth in PropagationConfigurationSchema to 0 --- .../agent_configuration/agent_sub_configuration_schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/common/agent_configuration/agent_sub_configuration_schemas.py b/monkey/common/agent_configuration/agent_sub_configuration_schemas.py index e666407ac..88c12ddee 100644 --- a/monkey/common/agent_configuration/agent_sub_configuration_schemas.py +++ b/monkey/common/agent_configuration/agent_sub_configuration_schemas.py @@ -135,7 +135,7 @@ class ExploitationConfigurationSchema(Schema): class PropagationConfigurationSchema(Schema): - maximum_depth = fields.Int(validate=validate.Range(min=1)) + maximum_depth = fields.Int(validate=validate.Range(min=0)) network_scan = fields.Nested(NetworkScanConfigurationSchema) exploitation = fields.Nested(ExploitationConfigurationSchema) From c2052a57a839739043954241b4d0d5a601779f8f Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 27 Jul 2022 18:50:50 +0530 Subject: [PATCH 8/8] UT: Modify PropagationConfigurationSchema maximum depth validation test cases --- .../common/configuration/test_agent_configuration.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 7a93fbe96..78f612384 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -225,15 +225,14 @@ def test_propagation_configuration(): assert config_dict == PROPAGATION_CONFIGURATION -@pytest.mark.parametrize("depth", [-1, 0]) -def test_propagation_configuration__invalid_maximum_depth(depth): +def test_propagation_configuration__invalid_maximum_depth(): schema = PropagationConfigurationSchema() - invalid_maximum_depth_configuration = PROPAGATION_CONFIGURATION.copy() - invalid_maximum_depth_configuration["maximum_depth"] = depth + negative_maximum_depth_configuration = PROPAGATION_CONFIGURATION.copy() + negative_maximum_depth_configuration["maximum_depth"] = -1 with pytest.raises(ValidationError): - schema.load(invalid_maximum_depth_configuration) + schema.load(negative_maximum_depth_configuration) def test_agent_configuration():