BB: Correctly pass and import test configuration and agent configuration

This commit is contained in:
Shreya Malviya 2022-07-21 19:13:56 +05:30 committed by Mike Salvatore
parent 1f4167f44c
commit 2764069aec
4 changed files with 18 additions and 17 deletions

View File

@ -1,9 +1,9 @@
from typing import Iterable
from common.configuration.agent_configuration import AgentConfiguration
from envs.monkey_zoo.blackbox.test_configurations.test_configuration import TestConfiguration
class IslandConfigParser:
@staticmethod
def get_target_ips_from_configuration(agent_configuration: AgentConfiguration) -> Iterable[str]:
return agent_configuration.propagation.network_scan.targets.subnets
def get_target_ips(test_configuration: TestConfiguration) -> Iterable[str]:
return test_configuration.agent_configuration.propagation.network_scan.targets.subnets

View File

@ -6,6 +6,7 @@ from typing import Union
from bson import json_util
from envs.monkey_zoo.blackbox.island_client.monkey_island_requests import MonkeyIslandRequests
from envs.monkey_zoo.blackbox.test_configurations.test_configuration import TestConfiguration
SLEEP_BETWEEN_REQUESTS_SECONDS = 0.5
MONKEY_TEST_ENDPOINT = "api/test/monkey"
@ -30,8 +31,10 @@ class MonkeyIslandClient(object):
return json.loads(self.requests.get("api/agent-configuration").content)
@avoid_race_condition
def import_config(self, config_contents):
_ = self.requests.post("api/agent-configuration", data=config_contents)
def import_config(self, test_configuration: TestConfiguration):
_ = self.requests.post(
"api/agent-configuration", data=test_configuration.agent_configuration.to_json()
)
@avoid_race_condition
def run_monkey_local(self):

View File

@ -4,7 +4,6 @@ from time import sleep
import pytest
from common.configuration.agent_configuration import AgentConfiguration
from envs.monkey_zoo.blackbox.analyzers.communication_analyzer import CommunicationAnalyzer
from envs.monkey_zoo.blackbox.analyzers.zerologon_analyzer import ZerologonAnalyzer
from envs.monkey_zoo.blackbox.gcp_test_machine_list import GCP_TEST_MACHINE_LIST
@ -20,6 +19,7 @@ from envs.monkey_zoo.blackbox.test_configurations import (
wmi_mimikatz_test_configuration,
zerologon_test_configuration,
)
from envs.monkey_zoo.blackbox.test_configurations.test_configuration import TestConfiguration
from envs.monkey_zoo.blackbox.tests.exploitation import ExploitationTest
from envs.monkey_zoo.blackbox.utils.gcp_machine_handlers import (
initialize_gcp_client,
@ -85,13 +85,13 @@ class TestMonkeyBlackbox:
@staticmethod
def run_exploitation_test(
island_client: MonkeyIslandClient,
agent_configuration: AgentConfiguration,
test_configuration: TestConfiguration,
test_name: str,
timeout_in_seconds=DEFAULT_TIMEOUT_SECONDS,
):
analyzer = CommunicationAnalyzer(
island_client,
IslandConfigParser.get_target_ips_from_configuration(agent_configuration),
IslandConfigParser.get_target_ips(test_configuration),
)
log_handler = TestLogsHandler(
test_name, island_client, TestMonkeyBlackbox.get_log_dir_path()
@ -99,7 +99,7 @@ class TestMonkeyBlackbox:
ExploitationTest(
name=test_name,
island_client=island_client,
agent_configuration=agent_configuration,
test_configuration=test_configuration,
analyzers=[analyzer],
timeout=timeout_in_seconds,
log_handler=log_handler,
@ -146,7 +146,7 @@ class TestMonkeyBlackbox:
zero_logon_analyzer = ZerologonAnalyzer(island_client, expected_creds)
communication_analyzer = CommunicationAnalyzer(
island_client,
IslandConfigParser.get_target_ips_from_configuration(zerologon_test_configuration),
IslandConfigParser.get_target_ips(zerologon_test_configuration),
)
log_handler = TestLogsHandler(
test_name, island_client, TestMonkeyBlackbox.get_log_dir_path()
@ -154,7 +154,7 @@ class TestMonkeyBlackbox:
ExploitationTest(
name=test_name,
island_client=island_client,
agent_configuration=zerologon_test_configuration,
test_configuration=zerologon_test_configuration,
analyzers=[zero_logon_analyzer, communication_analyzer],
timeout=DEFAULT_TIMEOUT_SECONDS + 30,
log_handler=log_handler,

View File

@ -13,16 +13,16 @@ LOGGER = logging.getLogger(__name__)
class ExploitationTest(BasicTest):
def __init__(self, name, island_client, agent_configuration, analyzers, timeout, log_handler):
def __init__(self, name, island_client, test_configuration, analyzers, timeout, log_handler):
self.name = name
self.island_client = island_client
self.agent_configuration = agent_configuration
self.test_configuration = test_configuration
self.analyzers = analyzers
self.timeout = timeout
self.log_handler = log_handler
def run(self):
self.island_client.import_config(self.serialized_config)
self.island_client.import_config(self.test_configuration)
self.print_test_starting_info()
try:
self.island_client.run_monkey_local()
@ -36,9 +36,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_configuration(self.agent_configuration)
)
machine_list = ", ".join(IslandConfigParser.get_target_ips(self.test_configuration))
LOGGER.info(f"Machines participating in test: {machine_list}")
print("")