From 6cf62d48cb20a39ab2c5168e17f503de381589e5 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Thu, 1 Sep 2022 17:09:53 +0530 Subject: [PATCH] BB: Use `replace_agent_configuration()` and `replace_propagation_credentials()` for all test configuration modifications --- .../blackbox/test_configurations/depth_1_a.py | 10 ++++++++-- .../blackbox/test_configurations/depth_2_a.py | 17 ++++++++++++++--- .../blackbox/test_configurations/depth_3_a.py | 10 ++++++++-- .../powershell_credentials_reuse.py | 13 +++++++++++-- .../blackbox/test_configurations/smb_pth.py | 10 ++++++++-- .../blackbox/test_configurations/utils.py | 16 +++++++++++++++- .../test_configurations/wmi_mimikatz.py | 10 ++++++++-- .../blackbox/test_configurations/zerologon.py | 12 ++++++++++-- 8 files changed, 82 insertions(+), 16 deletions(-) diff --git a/envs/monkey_zoo/blackbox/test_configurations/depth_1_a.py b/envs/monkey_zoo/blackbox/test_configurations/depth_1_a.py index f702e3149..b043456a5 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/depth_1_a.py +++ b/envs/monkey_zoo/blackbox/test_configurations/depth_1_a.py @@ -9,6 +9,8 @@ from .utils import ( add_http_ports, add_subnets, add_tcp_ports, + replace_agent_configuration, + replace_propagation_credentials, set_maximum_depth, ) @@ -89,5 +91,9 @@ CREDENTIALS = ( ) depth_1_a_test_configuration = noop_test_configuration.copy() -depth_1_a_test_configuration.agent_configuration = test_agent_configuration -depth_1_a_test_configuration.propagation_credentials = CREDENTIALS +replace_agent_configuration( + test_configuration=depth_1_a_test_configuration, agent_configuration=test_agent_configuration +) +replace_propagation_credentials( + test_configuration=depth_1_a_test_configuration, propagation_credentials=CREDENTIALS +) diff --git a/envs/monkey_zoo/blackbox/test_configurations/depth_2_a.py b/envs/monkey_zoo/blackbox/test_configurations/depth_2_a.py index 396e9ed3e..a8b9a87a5 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/depth_2_a.py +++ b/envs/monkey_zoo/blackbox/test_configurations/depth_2_a.py @@ -2,7 +2,14 @@ from common.agent_configuration import AgentConfiguration, PluginConfiguration from common.credentials import Credentials, Password, Username from .noop import noop_test_configuration -from .utils import add_exploiters, add_subnets, add_tcp_ports, set_maximum_depth +from .utils import ( + add_exploiters, + add_subnets, + add_tcp_ports, + replace_agent_configuration, + replace_propagation_credentials, + set_maximum_depth, +) # Tests: @@ -38,5 +45,9 @@ CREDENTIALS = ( ) depth_2_a_test_configuration = noop_test_configuration.copy() -depth_2_a_test_configuration.agent_configuration = test_agent_configuration -depth_2_a_test_configuration.propagation_credentials = CREDENTIALS +replace_agent_configuration( + test_configuration=depth_2_a_test_configuration, agent_configuration=test_agent_configuration +) +replace_propagation_credentials( + test_configuration=depth_2_a_test_configuration, propagation_credentials=CREDENTIALS +) diff --git a/envs/monkey_zoo/blackbox/test_configurations/depth_3_a.py b/envs/monkey_zoo/blackbox/test_configurations/depth_3_a.py index 8f9bfdc70..a1de4430c 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/depth_3_a.py +++ b/envs/monkey_zoo/blackbox/test_configurations/depth_3_a.py @@ -6,6 +6,8 @@ from .utils import ( add_exploiters, add_subnets, add_tcp_ports, + replace_agent_configuration, + replace_propagation_credentials, set_keep_tunnel_open_time, set_maximum_depth, ) @@ -65,5 +67,9 @@ CREDENTIALS = ( ) depth_3_a_test_configuration = noop_test_configuration.copy() -depth_3_a_test_configuration.agent_configuration = test_agent_configuration -depth_3_a_test_configuration.propagation_credentials = CREDENTIALS +replace_agent_configuration( + test_configuration=depth_3_a_test_configuration, agent_configuration=test_agent_configuration +) +replace_propagation_credentials( + test_configuration=depth_3_a_test_configuration, propagation_credentials=CREDENTIALS +) diff --git a/envs/monkey_zoo/blackbox/test_configurations/powershell_credentials_reuse.py b/envs/monkey_zoo/blackbox/test_configurations/powershell_credentials_reuse.py index e8dd214e5..7938b54e2 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/powershell_credentials_reuse.py +++ b/envs/monkey_zoo/blackbox/test_configurations/powershell_credentials_reuse.py @@ -1,7 +1,13 @@ from common.agent_configuration import AgentConfiguration, PluginConfiguration from .noop import noop_test_configuration -from .utils import add_exploiters, add_subnets, add_tcp_ports, set_maximum_depth +from .utils import ( + add_exploiters, + add_subnets, + add_tcp_ports, + replace_agent_configuration, + set_maximum_depth, +) def _add_exploiters(agent_configuration: AgentConfiguration) -> AgentConfiguration: @@ -30,4 +36,7 @@ test_agent_configuration = _add_subnets(test_agent_configuration) test_agent_configuration = _add_tcp_ports(test_agent_configuration) powershell_credentials_reuse_test_configuration = noop_test_configuration.copy() -powershell_credentials_reuse_test_configuration.agent_configuration = test_agent_configuration +replace_agent_configuration( + test_configuration=powershell_credentials_reuse_test_configuration, + agent_configuration=test_agent_configuration, +) diff --git a/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py b/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py index 8863013e9..b99d21ca8 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py +++ b/envs/monkey_zoo/blackbox/test_configurations/smb_pth.py @@ -6,6 +6,8 @@ from .utils import ( add_exploiters, add_subnets, add_tcp_ports, + replace_agent_configuration, + replace_propagation_credentials, set_keep_tunnel_open_time, set_maximum_depth, ) @@ -49,5 +51,9 @@ CREDENTIALS = ( ) smb_pth_test_configuration = noop_test_configuration.copy() -smb_pth_test_configuration.agent_configuration = test_agent_configuration -smb_pth_test_configuration.propagation_credentials = CREDENTIALS +replace_agent_configuration( + test_configuration=smb_pth_test_configuration, agent_configuration=test_agent_configuration +) +replace_propagation_credentials( + test_configuration=smb_pth_test_configuration, propagation_credentials=CREDENTIALS +) diff --git a/envs/monkey_zoo/blackbox/test_configurations/utils.py b/envs/monkey_zoo/blackbox/test_configurations/utils.py index c1b6b54f8..3872230c0 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/utils.py +++ b/envs/monkey_zoo/blackbox/test_configurations/utils.py @@ -1,6 +1,8 @@ -from typing import Sequence +from typing import Sequence, Tuple from common.agent_configuration import AgentConfiguration, PluginConfiguration +from common.credentials import Credentials +from envs.monkey_zoo.blackbox.test_configurations.test_configuration import TestConfiguration def add_exploiters( @@ -84,3 +86,15 @@ def set_maximum_depth( agent_configuration_copy.propagation.maximum_depth = maximum_depth return agent_configuration_copy + + +def replace_agent_configuration( + test_configuration: TestConfiguration, agent_configuration: AgentConfiguration +): + test_configuration.agent_configuration = agent_configuration + + +def replace_propagation_credentials( + test_configuration: TestConfiguration, propagation_credentials: Tuple[Credentials, ...] +): + test_configuration.propagation_credentials = propagation_credentials diff --git a/envs/monkey_zoo/blackbox/test_configurations/wmi_mimikatz.py b/envs/monkey_zoo/blackbox/test_configurations/wmi_mimikatz.py index c525f5ca5..db8b6fa1d 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/wmi_mimikatz.py +++ b/envs/monkey_zoo/blackbox/test_configurations/wmi_mimikatz.py @@ -7,6 +7,8 @@ from .utils import ( add_exploiters, add_subnets, add_tcp_ports, + replace_agent_configuration, + replace_propagation_credentials, set_maximum_depth, ) @@ -54,5 +56,9 @@ CREDENTIALS = ( ) wmi_mimikatz_test_configuration = noop_test_configuration.copy() -wmi_mimikatz_test_configuration.agent_configuration = test_agent_configuration -wmi_mimikatz_test_configuration.propagation_credentials = CREDENTIALS +replace_agent_configuration( + test_configuration=wmi_mimikatz_test_configuration, agent_configuration=test_agent_configuration +) +replace_propagation_credentials( + test_configuration=wmi_mimikatz_test_configuration, propagation_credentials=CREDENTIALS +) diff --git a/envs/monkey_zoo/blackbox/test_configurations/zerologon.py b/envs/monkey_zoo/blackbox/test_configurations/zerologon.py index 8e9a14369..87b533aed 100644 --- a/envs/monkey_zoo/blackbox/test_configurations/zerologon.py +++ b/envs/monkey_zoo/blackbox/test_configurations/zerologon.py @@ -1,7 +1,13 @@ from common.agent_configuration import AgentConfiguration, PluginConfiguration from .noop import noop_test_configuration -from .utils import add_exploiters, add_subnets, add_tcp_ports, set_maximum_depth +from .utils import ( + add_exploiters, + add_subnets, + add_tcp_ports, + replace_agent_configuration, + set_maximum_depth, +) def _add_exploiters(agent_configuration: AgentConfiguration) -> AgentConfiguration: @@ -27,4 +33,6 @@ test_agent_configuration = _add_tcp_ports(test_agent_configuration) test_agent_configuration = _add_subnets(test_agent_configuration) zerologon_test_configuration = noop_test_configuration.copy() -zerologon_test_configuration.agent_configuration = test_agent_configuration +replace_agent_configuration( + test_configuration=zerologon_test_configuration, agent_configuration=test_agent_configuration +)