Island: Reformat "propagation" config options before sending to Agent

This commit is contained in:
Mike Salvatore 2021-12-10 09:31:07 -05:00
parent 81d4afab52
commit 80707dac8e
2 changed files with 46 additions and 19 deletions

View File

@ -419,7 +419,7 @@ class ConfigService:
ConfigService._remove_credentials_from_flat_config(config)
ConfigService._format_payloads_from_flat_config(config)
ConfigService._format_pbas_from_flat_config(config)
ConfigService._format_network_scan_from_flat_config(config)
ConfigService._format_propagation_from_flat_config(config)
@staticmethod
def _remove_credentials_from_flat_config(config: Dict):
@ -464,9 +464,23 @@ class ConfigService:
config.pop(flat_windows_command_field, None)
config.pop(flat_windows_filename_field, None)
@staticmethod
def _format_propagation_from_flat_config(config: Dict):
formatted_propagation_config = {"network_scan": {}, "targets": {}}
formatted_propagation_config[
"network_scan"
] = ConfigService._format_network_scan_from_flat_config(config)
formatted_propagation_config["targets"] = ConfigService._format_targets_from_flat_config(
config
)
config["propagation"] = formatted_propagation_config
@staticmethod
def _format_network_scan_from_flat_config(config: Dict):
formatted_network_scan_config = {"tcp": {}, "icmp": {}, "targets": {}}
formatted_network_scan_config = {"tcp": {}, "icmp": {}}
formatted_network_scan_config["tcp"] = ConfigService._format_tcp_scan_from_flat_config(
config
@ -474,11 +488,8 @@ class ConfigService:
formatted_network_scan_config["icmp"] = ConfigService._format_icmp_scan_from_flat_config(
config
)
formatted_network_scan_config[
"targets"
] = ConfigService._format_scan_targets_from_flat_config(config)
config["network_scan"] = formatted_network_scan_config
return formatted_network_scan_config
@staticmethod
def _format_tcp_scan_from_flat_config(config: Dict):
@ -519,7 +530,7 @@ class ConfigService:
return formatted_icmp_scan_config
@staticmethod
def _format_scan_targets_from_flat_config(config: Dict):
def _format_targets_from_flat_config(config: Dict):
flat_blocked_ips_field = "blocked_ips"
flat_inaccessible_subnets_field = "inaccessible_subnets"
flat_local_network_scan_field = "local_network_scan"

View File

@ -95,6 +95,31 @@ def test_get_config_propagation_credentials_from_flat_config(flat_monkey_config)
assert creds == expected_creds
def test_format_config_for_agent__propagation(flat_monkey_config):
ConfigService.format_flat_config_for_agent(flat_monkey_config)
assert "propagation" in flat_monkey_config
assert "network_scan" in flat_monkey_config["propagation"]
assert "targets" in flat_monkey_config["propagation"]
def test_format_config_for_agent__propagation_targets(flat_monkey_config):
expected_targets = {
"blocked_ips": ["192.168.1.1", "192.168.1.100"],
"inaccessible_subnets": ["10.0.0.0/24", "10.0.10.0/24"],
"local_network_scan": True,
"subnet_scan_list": ["192.168.1.50", "192.168.56.0/24", "10.0.33.0/30"],
}
ConfigService.format_flat_config_for_agent(flat_monkey_config)
assert flat_monkey_config["propagation"]["targets"] == expected_targets
assert "blocked_ips" not in flat_monkey_config
assert "inaccessible_subnets" not in flat_monkey_config
assert "local_network_scan" not in flat_monkey_config
assert "subnet_scan_list" not in flat_monkey_config
def test_format_config_for_agent__network_scan(flat_monkey_config):
expected_network_scan_config = {
"tcp": {
@ -118,22 +143,13 @@ def test_format_config_for_agent__network_scan(flat_monkey_config):
"icmp": {
"timeout_ms": 1000,
},
"targets": {
"blocked_ips": ["192.168.1.1", "192.168.1.100"],
"inaccessible_subnets": ["10.0.0.0/24", "10.0.10.0/24"],
"local_network_scan": True,
"subnet_scan_list": ["192.168.1.50", "192.168.56.0/24", "10.0.33.0/30"],
},
}
ConfigService.format_flat_config_for_agent(flat_monkey_config)
assert "network_scan" in flat_monkey_config
assert flat_monkey_config["network_scan"] == expected_network_scan_config
assert "propagation" in flat_monkey_config
assert "network_scan" in flat_monkey_config["propagation"]
assert flat_monkey_config["propagation"]["network_scan"] == expected_network_scan_config
assert "tcp_scan_timeout" not in flat_monkey_config
assert "tcp_target_ports" not in flat_monkey_config
assert "ping_scan_timeout" not in flat_monkey_config
assert "blocked_ips" not in flat_monkey_config
assert "inaccessible_subnets" not in flat_monkey_config
assert "local_network_scan" not in flat_monkey_config
assert "subnet_scan_list" not in flat_monkey_config