forked from p15670423/monkey
BB: Correctly pass and import test configuration and agent configuration
This commit is contained in:
parent
1f4167f44c
commit
2764069aec
|
@ -1,9 +1,9 @@
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
from common.configuration.agent_configuration import AgentConfiguration
|
from envs.monkey_zoo.blackbox.test_configurations.test_configuration import TestConfiguration
|
||||||
|
|
||||||
|
|
||||||
class IslandConfigParser:
|
class IslandConfigParser:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_target_ips_from_configuration(agent_configuration: AgentConfiguration) -> Iterable[str]:
|
def get_target_ips(test_configuration: TestConfiguration) -> Iterable[str]:
|
||||||
return agent_configuration.propagation.network_scan.targets.subnets
|
return test_configuration.agent_configuration.propagation.network_scan.targets.subnets
|
||||||
|
|
|
@ -6,6 +6,7 @@ from typing import Union
|
||||||
from bson import json_util
|
from bson import json_util
|
||||||
|
|
||||||
from envs.monkey_zoo.blackbox.island_client.monkey_island_requests import MonkeyIslandRequests
|
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
|
SLEEP_BETWEEN_REQUESTS_SECONDS = 0.5
|
||||||
MONKEY_TEST_ENDPOINT = "api/test/monkey"
|
MONKEY_TEST_ENDPOINT = "api/test/monkey"
|
||||||
|
@ -30,8 +31,10 @@ class MonkeyIslandClient(object):
|
||||||
return json.loads(self.requests.get("api/agent-configuration").content)
|
return json.loads(self.requests.get("api/agent-configuration").content)
|
||||||
|
|
||||||
@avoid_race_condition
|
@avoid_race_condition
|
||||||
def import_config(self, config_contents):
|
def import_config(self, test_configuration: TestConfiguration):
|
||||||
_ = self.requests.post("api/agent-configuration", data=config_contents)
|
_ = self.requests.post(
|
||||||
|
"api/agent-configuration", data=test_configuration.agent_configuration.to_json()
|
||||||
|
)
|
||||||
|
|
||||||
@avoid_race_condition
|
@avoid_race_condition
|
||||||
def run_monkey_local(self):
|
def run_monkey_local(self):
|
||||||
|
|
|
@ -4,7 +4,6 @@ from time import sleep
|
||||||
|
|
||||||
import pytest
|
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.communication_analyzer import CommunicationAnalyzer
|
||||||
from envs.monkey_zoo.blackbox.analyzers.zerologon_analyzer import ZerologonAnalyzer
|
from envs.monkey_zoo.blackbox.analyzers.zerologon_analyzer import ZerologonAnalyzer
|
||||||
from envs.monkey_zoo.blackbox.gcp_test_machine_list import GCP_TEST_MACHINE_LIST
|
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,
|
wmi_mimikatz_test_configuration,
|
||||||
zerologon_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.tests.exploitation import ExploitationTest
|
||||||
from envs.monkey_zoo.blackbox.utils.gcp_machine_handlers import (
|
from envs.monkey_zoo.blackbox.utils.gcp_machine_handlers import (
|
||||||
initialize_gcp_client,
|
initialize_gcp_client,
|
||||||
|
@ -85,13 +85,13 @@ class TestMonkeyBlackbox:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run_exploitation_test(
|
def run_exploitation_test(
|
||||||
island_client: MonkeyIslandClient,
|
island_client: MonkeyIslandClient,
|
||||||
agent_configuration: AgentConfiguration,
|
test_configuration: TestConfiguration,
|
||||||
test_name: str,
|
test_name: str,
|
||||||
timeout_in_seconds=DEFAULT_TIMEOUT_SECONDS,
|
timeout_in_seconds=DEFAULT_TIMEOUT_SECONDS,
|
||||||
):
|
):
|
||||||
analyzer = CommunicationAnalyzer(
|
analyzer = CommunicationAnalyzer(
|
||||||
island_client,
|
island_client,
|
||||||
IslandConfigParser.get_target_ips_from_configuration(agent_configuration),
|
IslandConfigParser.get_target_ips(test_configuration),
|
||||||
)
|
)
|
||||||
log_handler = TestLogsHandler(
|
log_handler = TestLogsHandler(
|
||||||
test_name, island_client, TestMonkeyBlackbox.get_log_dir_path()
|
test_name, island_client, TestMonkeyBlackbox.get_log_dir_path()
|
||||||
|
@ -99,7 +99,7 @@ class TestMonkeyBlackbox:
|
||||||
ExploitationTest(
|
ExploitationTest(
|
||||||
name=test_name,
|
name=test_name,
|
||||||
island_client=island_client,
|
island_client=island_client,
|
||||||
agent_configuration=agent_configuration,
|
test_configuration=test_configuration,
|
||||||
analyzers=[analyzer],
|
analyzers=[analyzer],
|
||||||
timeout=timeout_in_seconds,
|
timeout=timeout_in_seconds,
|
||||||
log_handler=log_handler,
|
log_handler=log_handler,
|
||||||
|
@ -146,7 +146,7 @@ class TestMonkeyBlackbox:
|
||||||
zero_logon_analyzer = ZerologonAnalyzer(island_client, expected_creds)
|
zero_logon_analyzer = ZerologonAnalyzer(island_client, expected_creds)
|
||||||
communication_analyzer = CommunicationAnalyzer(
|
communication_analyzer = CommunicationAnalyzer(
|
||||||
island_client,
|
island_client,
|
||||||
IslandConfigParser.get_target_ips_from_configuration(zerologon_test_configuration),
|
IslandConfigParser.get_target_ips(zerologon_test_configuration),
|
||||||
)
|
)
|
||||||
log_handler = TestLogsHandler(
|
log_handler = TestLogsHandler(
|
||||||
test_name, island_client, TestMonkeyBlackbox.get_log_dir_path()
|
test_name, island_client, TestMonkeyBlackbox.get_log_dir_path()
|
||||||
|
@ -154,7 +154,7 @@ class TestMonkeyBlackbox:
|
||||||
ExploitationTest(
|
ExploitationTest(
|
||||||
name=test_name,
|
name=test_name,
|
||||||
island_client=island_client,
|
island_client=island_client,
|
||||||
agent_configuration=zerologon_test_configuration,
|
test_configuration=zerologon_test_configuration,
|
||||||
analyzers=[zero_logon_analyzer, communication_analyzer],
|
analyzers=[zero_logon_analyzer, communication_analyzer],
|
||||||
timeout=DEFAULT_TIMEOUT_SECONDS + 30,
|
timeout=DEFAULT_TIMEOUT_SECONDS + 30,
|
||||||
log_handler=log_handler,
|
log_handler=log_handler,
|
||||||
|
|
|
@ -13,16 +13,16 @@ LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ExploitationTest(BasicTest):
|
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.name = name
|
||||||
self.island_client = island_client
|
self.island_client = island_client
|
||||||
self.agent_configuration = agent_configuration
|
self.test_configuration = test_configuration
|
||||||
self.analyzers = analyzers
|
self.analyzers = analyzers
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.log_handler = log_handler
|
self.log_handler = log_handler
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.island_client.import_config(self.serialized_config)
|
self.island_client.import_config(self.test_configuration)
|
||||||
self.print_test_starting_info()
|
self.print_test_starting_info()
|
||||||
try:
|
try:
|
||||||
self.island_client.run_monkey_local()
|
self.island_client.run_monkey_local()
|
||||||
|
@ -36,9 +36,7 @@ class ExploitationTest(BasicTest):
|
||||||
|
|
||||||
def print_test_starting_info(self):
|
def print_test_starting_info(self):
|
||||||
LOGGER.info("Started {} test".format(self.name))
|
LOGGER.info("Started {} test".format(self.name))
|
||||||
machine_list = ", ".join(
|
machine_list = ", ".join(IslandConfigParser.get_target_ips(self.test_configuration))
|
||||||
IslandConfigParser.get_target_ips_from_configuration(self.agent_configuration)
|
|
||||||
)
|
|
||||||
LOGGER.info(f"Machines participating in test: {machine_list}")
|
LOGGER.info(f"Machines participating in test: {machine_list}")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue