Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropagationConfiguration docstring + validation #2129

Merged
merged 8 commits into from
Jul 27, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _make_exploitation_options_configuration(self, data, **kwargs):


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)

Expand Down
11 changes: 11 additions & 0 deletions monkey/common/agent_configuration/agent_sub_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,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)
Expand Down