Common: Add ScanTargetConfigurationSchema

This commit is contained in:
Mike Salvatore 2022-06-17 08:30:42 -04:00
parent 7e9c481992
commit 3c879f444d
4 changed files with 36 additions and 0 deletions

View File

@ -13,4 +13,6 @@ from .agent_configuration import (
ICMPScanConfigurationSchema,
TCPScanConfiguration,
TCPScanConfigurationSchema,
ScanTargetConfiguration,
ScanTargetConfigurationSchema,
)

View File

@ -96,6 +96,17 @@ class ScanTargetConfiguration:
subnets: List[str]
class ScanTargetConfigurationSchema(Schema):
blocked_ips = fields.List(fields.Str())
inaccessible_subnets = fields.List(fields.Str())
local_network_scan = fields.Bool()
subnets = fields.List(fields.Str())
@post_load
def _make_scan_target_configuration(self, data, **kwargs):
return ScanTargetConfiguration(**data)
@dataclass(frozen=True)
class ICMPScanConfiguration:
timeout_ms: int

View File

@ -7,6 +7,7 @@ from common.configuration import (
ExploiterConfigurationSchema,
ICMPScanConfigurationSchema,
PluginConfigurationSchema,
ScanTargetConfigurationSchema,
TCPScanConfigurationSchema,
)
@ -99,6 +100,27 @@ def test_exploitation_configuration():
assert config_dict == exploitation_config
def test_scan_target_configuration():
blocked_ips = ["10.0.0.1", "192.168.1.1"]
inaccessible_subnets = ["172.0.0.0/24", "172.2.2.0/24", "192.168.56.0/24"]
local_network_scan = True
subnets = ["10.0.0.2", "10.0.0.2/16"]
scan_target_config = {
"blocked_ips": blocked_ips,
"inaccessible_subnets": inaccessible_subnets,
"local_network_scan": local_network_scan,
"subnets": subnets,
}
schema = ScanTargetConfigurationSchema()
config = schema.load(scan_target_config)
assert config.blocked_ips == blocked_ips
assert config.inaccessible_subnets == inaccessible_subnets
assert config.local_network_scan == local_network_scan
assert config.subnets == subnets
def test_icmp_scan_configuration_schema():
timeout_ms = 2525
schema = ICMPScanConfigurationSchema()

View File

@ -190,6 +190,7 @@ _make_plugin_configuration # unused method (monkey/common/configuration/agent_c
_make_custom_pba_configuration # unused method (monkey/common/configuration/agent_configuration.py:24)
_make_exploiter_configuration # unused method (monkey/common/configuration/agent_configuration.py:69)
_make_exploitation_options_configuration # unused method (monkey/common/configuration/agent_configuration.py:86)
_make_scan_target_configuration # unused method (monkey/common/configuration/agent_configuration.py:105)
_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)
LINUX # unused variable (monkey/common/operating_systems.py:5)