diff --git a/monkey/common/agent_configuration/agent_sub_configuration_schemas.py b/monkey/common/agent_configuration/agent_sub_configuration_schemas.py index 81dc6f53b..d47730fec 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=0)) network_scan = fields.Nested(NetworkScanConfigurationSchema) exploitation = fields.Nested(ExploitationConfigurationSchema) diff --git a/monkey/common/agent_configuration/agent_sub_configurations.py b/monkey/common/agent_configuration/agent_sub_configurations.py index e0e9a60ff..f58bcd9b0 100644 --- a/monkey/common/agent_configuration/agent_sub_configurations.py +++ b/monkey/common/agent_configuration/agent_sub_configurations.py @@ -134,6 +134,17 @@ class ExploitationConfiguration: @dataclass(frozen=True) class PropagationConfiguration: + """ + A configuration for propagation + + Attributes: + :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 + """ + maximum_depth: int network_scan: NetworkScanConfiguration exploitation: ExploitationConfiguration 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..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 @@ -11,14 +11,15 @@ 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' + ' \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 } 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 6110dbc7b..22a09b87b 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -237,6 +237,16 @@ def test_propagation_configuration(): assert config_dict == PROPAGATION_CONFIGURATION +def test_propagation_configuration__invalid_maximum_depth(): + schema = PropagationConfigurationSchema() + + negative_maximum_depth_configuration = PROPAGATION_CONFIGURATION.copy() + negative_maximum_depth_configuration["maximum_depth"] = -1 + + with pytest.raises(ValidationError): + schema.load(negative_maximum_depth_configuration) + + def test_agent_configuration(): config = AgentConfiguration.from_mapping(AGENT_CONFIGURATION) config_json = AgentConfiguration.to_json(config)