From 00626fe579a9ee7517a92920e9d1e7a008fd7c1b Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Thu, 21 Jul 2022 18:50:14 +0530 Subject: [PATCH] BB: Use agent configuration object to get target IPs in IslandConfigParser --- .../blackbox/island_client/island_config_parser.py | 6 ++---- envs/monkey_zoo/blackbox/test_blackbox.py | 8 ++++---- envs/monkey_zoo/blackbox/tests/exploitation.py | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/envs/monkey_zoo/blackbox/island_client/island_config_parser.py b/envs/monkey_zoo/blackbox/island_client/island_config_parser.py index bb4cd7b41..5f6dcf8e5 100644 --- a/envs/monkey_zoo/blackbox/island_client/island_config_parser.py +++ b/envs/monkey_zoo/blackbox/island_client/island_config_parser.py @@ -11,7 +11,5 @@ class IslandConfigParser: return agent_configuration.to_json() @staticmethod - def get_target_ips_from_serialized_config(serialized_config: Mapping) -> Iterable: - return dpath.util.get( - serialized_config, "agent_configuration.propagation.network_scan.targets.subnets", "." - ) + def get_target_ips_from_configuration(agent_configuration: AgentConfiguration) -> Iterable: + return agent_configuration.propagation.network_scan.targets.subnets diff --git a/envs/monkey_zoo/blackbox/test_blackbox.py b/envs/monkey_zoo/blackbox/test_blackbox.py index fe9263bd1..9ee6cab18 100644 --- a/envs/monkey_zoo/blackbox/test_blackbox.py +++ b/envs/monkey_zoo/blackbox/test_blackbox.py @@ -92,7 +92,7 @@ class TestMonkeyBlackbox: serialized_config = IslandConfigParser.get_serialized_config(agent_configuration) analyzer = CommunicationAnalyzer( island_client, - IslandConfigParser.get_target_ips_from_serialized_config(serialized_config), + IslandConfigParser.get_target_ips_from_configuration(agent_configuration), ) log_handler = TestLogsHandler( test_name, island_client, TestMonkeyBlackbox.get_log_dir_path() @@ -100,7 +100,7 @@ class TestMonkeyBlackbox: ExploitationTest( name=test_name, island_client=island_client, - serialized_config=serialized_config, + agent_configuration=agent_configuration, analyzers=[analyzer], timeout=timeout_in_seconds, log_handler=log_handler, @@ -148,7 +148,7 @@ class TestMonkeyBlackbox: zero_logon_analyzer = ZerologonAnalyzer(island_client, expected_creds) communication_analyzer = CommunicationAnalyzer( island_client, - IslandConfigParser.get_target_ips_from_serialized_config(serialized_config), + IslandConfigParser.get_target_ips_from_configuration(zerologon_test_configuration), ) log_handler = TestLogsHandler( test_name, island_client, TestMonkeyBlackbox.get_log_dir_path() @@ -156,7 +156,7 @@ class TestMonkeyBlackbox: ExploitationTest( name=test_name, island_client=island_client, - serialized_config=serialized_config, + agent_configuration=zerologon_test_configuration, analyzers=[zero_logon_analyzer, communication_analyzer], timeout=DEFAULT_TIMEOUT_SECONDS + 30, log_handler=log_handler, diff --git a/envs/monkey_zoo/blackbox/tests/exploitation.py b/envs/monkey_zoo/blackbox/tests/exploitation.py index 2a6522698..0dd5c817d 100644 --- a/envs/monkey_zoo/blackbox/tests/exploitation.py +++ b/envs/monkey_zoo/blackbox/tests/exploitation.py @@ -13,10 +13,10 @@ LOGGER = logging.getLogger(__name__) class ExploitationTest(BasicTest): - def __init__(self, name, island_client, serialized_config, analyzers, timeout, log_handler): + def __init__(self, name, island_client, agent_configuration, analyzers, timeout, log_handler): self.name = name self.island_client = island_client - self.serialized_config = serialized_config + self.agent_configuration = agent_configuration self.analyzers = analyzers self.timeout = timeout self.log_handler = log_handler @@ -37,7 +37,7 @@ class ExploitationTest(BasicTest): def print_test_starting_info(self): LOGGER.info("Started {} test".format(self.name)) machine_list = ", ".join( - IslandConfigParser.get_target_ips_from_serialized_config(self.serialized_config) + IslandConfigParser.get_target_ips_from_configuration(self.agent_configuration) ) LOGGER.info(f"Machines participating in test: {machine_list}") print("")