Common: Add PropagationConfiguration

This commit is contained in:
Mike Salvatore 2022-06-17 09:04:00 -04:00
parent 9bbf5c8ae7
commit a41b2e3ea4
4 changed files with 76 additions and 33 deletions

View File

@ -17,4 +17,6 @@ from .agent_configuration import (
ExploiterConfigurationSchema, ExploiterConfigurationSchema,
ExploitationConfiguration, ExploitationConfiguration,
ExploitationConfigurationSchema, ExploitationConfigurationSchema,
PropagationConfiguration,
PropagationConfigurationSchema,
) )

View File

@ -152,3 +152,18 @@ class ExploitationConfigurationSchema(Schema):
@post_load @post_load
def _make_exploitation_options_configuration(self, data, **kwargs): def _make_exploitation_options_configuration(self, data, **kwargs):
return ExploitationConfiguration(**data) return ExploitationConfiguration(**data)
@dataclass(frozen=True)
class PropagationConfiguration:
network_scan: NetworkScanConfiguration
exploitation: ExploitationConfiguration
class PropagationConfigurationSchema(Schema):
network_scan = fields.Nested(NetworkScanConfigurationSchema)
exploitation = fields.Nested(ExploitationConfigurationSchema)
@post_load
def _make_propagation_configuration(self, data, **kwargs):
return PropagationConfiguration(**data)

View File

@ -6,8 +6,11 @@ from common.configuration import (
ExploitationOptionsConfigurationSchema, ExploitationOptionsConfigurationSchema,
ExploiterConfigurationSchema, ExploiterConfigurationSchema,
ICMPScanConfigurationSchema, ICMPScanConfigurationSchema,
NetworkScanConfiguration,
NetworkScanConfigurationSchema, NetworkScanConfigurationSchema,
PluginConfigurationSchema, PluginConfigurationSchema,
PropagationConfiguration,
PropagationConfigurationSchema,
ScanTargetConfigurationSchema, ScanTargetConfigurationSchema,
TCPScanConfigurationSchema, TCPScanConfigurationSchema,
) )
@ -96,23 +99,25 @@ def test_tcp_scan_configuration_schema():
assert config.ports == PORTS assert config.ports == PORTS
def test_network_scan_configuration(): FINGERPRINTERS = [{"name": "mssql", "options": {}}]
fingerprinters = [{"name": "mssql", "options": {}}] NETWORK_SCAN_CONFIGURATION = {
network_scan_configuration = {
"tcp": TCP_SCAN_CONFIGURATION, "tcp": TCP_SCAN_CONFIGURATION,
"icmp": ICMP_CONFIGURATION, "icmp": ICMP_CONFIGURATION,
"fingerprinters": fingerprinters, "fingerprinters": FINGERPRINTERS,
"targets": SCAN_TARGET_CONFIGURATION, "targets": SCAN_TARGET_CONFIGURATION,
} }
def test_network_scan_configuration():
schema = NetworkScanConfigurationSchema() schema = NetworkScanConfigurationSchema()
config = schema.load(network_scan_configuration) config = schema.load(NETWORK_SCAN_CONFIGURATION)
assert config.tcp.ports == TCP_SCAN_CONFIGURATION["ports"] assert config.tcp.ports == TCP_SCAN_CONFIGURATION["ports"]
assert config.tcp.timeout_ms == TCP_SCAN_CONFIGURATION["timeout_ms"] assert config.tcp.timeout_ms == TCP_SCAN_CONFIGURATION["timeout_ms"]
assert config.icmp.timeout_ms == ICMP_CONFIGURATION["timeout_ms"] assert config.icmp.timeout_ms == ICMP_CONFIGURATION["timeout_ms"]
assert config.fingerprinters[0].name == fingerprinters[0]["name"] assert config.fingerprinters[0].name == FINGERPRINTERS[0]["name"]
assert config.fingerprinters[0].options == fingerprinters[0]["options"] assert config.fingerprinters[0].options == FINGERPRINTERS[0]["options"]
assert config.targets.blocked_ips == BLOCKED_IPS assert config.targets.blocked_ips == BLOCKED_IPS
assert config.targets.inaccessible_subnets == INACCESSIBLE_SUBNETS assert config.targets.inaccessible_subnets == INACCESSIBLE_SUBNETS
assert config.targets.local_network_scan == LOCAL_NETWORK_SCAN assert config.targets.local_network_scan == LOCAL_NETWORK_SCAN
@ -143,9 +148,7 @@ def test_exploiter_configuration_schema():
assert config.supported_os == supported_os assert config.supported_os == supported_os
def test_exploitation_configuration(): BRUTE_FORCE = [
ports = [1, 2, 3]
brute_force = [
{"name": "ex1", "options": {}, "supported_os": ["LINUX"]}, {"name": "ex1", "options": {}, "supported_os": ["LINUX"]},
{ {
"name": "ex2", "name": "ex2",
@ -153,22 +156,44 @@ def test_exploitation_configuration():
"supported_os": ["LINUX", "WINDOWS"], "supported_os": ["LINUX", "WINDOWS"],
}, },
] ]
vulnerability = [ VULNERABILITY = [
{ {
"name": "ex3", "name": "ex3",
"options": {"smb_download_timeout": 10}, "options": {"smb_download_timeout": 10},
"supported_os": ["WINDOWS"], "supported_os": ["WINDOWS"],
}, },
] ]
exploitation_config = { EXPLOITATION_CONFIGURATION = {
"options": {"http_ports": ports}, "options": {"http_ports": PORTS},
"brute_force": brute_force, "brute_force": BRUTE_FORCE,
"vulnerability": vulnerability, "vulnerability": VULNERABILITY,
} }
def test_exploitation_configuration():
schema = ExploitationConfigurationSchema() schema = ExploitationConfigurationSchema()
config = schema.load(exploitation_config) config = schema.load(EXPLOITATION_CONFIGURATION)
config_dict = schema.dump(config) config_dict = schema.dump(config)
assert isinstance(config, ExploitationConfiguration) assert isinstance(config, ExploitationConfiguration)
assert config_dict == exploitation_config assert config_dict == EXPLOITATION_CONFIGURATION
PROPAGATION_CONFIGURATION = {
"network_scan": NETWORK_SCAN_CONFIGURATION,
"exploitation": EXPLOITATION_CONFIGURATION,
}
def test_propagation_configuration():
schema = PropagationConfigurationSchema()
config = schema.load(PROPAGATION_CONFIGURATION)
config_dict = schema.dump(config)
assert isinstance(config, PropagationConfiguration)
assert isinstance(config.network_scan, NetworkScanConfiguration)
assert isinstance(config.exploitation, ExploitationConfiguration)
assert config_dict == PROPAGATION_CONFIGURATION

View File

@ -192,6 +192,7 @@ _make_scan_target_configuration # unused method (monkey/common/configuration/ag
_make_icmp_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:107) _make_icmp_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:107)
_make_tcp_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:122) _make_tcp_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:122)
_make_network_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:110) _make_network_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:110)
_make_propagation_configuration # unused method (monkey/common/configuration/agent_configuration.py:167)
LINUX # unused variable (monkey/common/operating_systems.py:5) LINUX # unused variable (monkey/common/operating_systems.py:5)
WINDOWS # unused variable (monkey/common/operating_systems.py:6) WINDOWS # unused variable (monkey/common/operating_systems.py:6)