forked from p15670423/monkey
UT: Extract agent configuration from test_agent_configuration.py
This commit is contained in:
parent
ace3eb8718
commit
7cb7f7ab5a
|
@ -0,0 +1,75 @@
|
|||
PLUGIN_NAME = "bond"
|
||||
PLUGIN_OPTIONS = {"gun": "Walther PPK", "car": "Aston Martin DB5"}
|
||||
PLUGIN_CONFIGURATION = {"name": PLUGIN_NAME, "options": PLUGIN_OPTIONS}
|
||||
|
||||
LINUX_COMMAND = "a"
|
||||
LINUX_FILENAME = "b"
|
||||
WINDOWS_COMMAND = "c"
|
||||
WINDOWS_FILENAME = "d"
|
||||
CUSTOM_PBA_CONFIGURATION = {
|
||||
"linux_command": LINUX_COMMAND,
|
||||
"linux_filename": LINUX_FILENAME,
|
||||
"windows_command": WINDOWS_COMMAND,
|
||||
"windows_filename": WINDOWS_FILENAME,
|
||||
}
|
||||
|
||||
BLOCKED_IPS = ["10.0.0.1", "192.168.1.1"]
|
||||
INACCESSIBLE_SUBNETS = ["172.0.0.0/24", "172.2.2.0/24", "192.168.56.0/24"]
|
||||
LOCAL_NETWORK_SCAN = True
|
||||
SUBNETS = ["10.0.0.2", "10.0.0.2/16"]
|
||||
SCAN_TARGET_CONFIGURATION = {
|
||||
"blocked_ips": BLOCKED_IPS,
|
||||
"inaccessible_subnets": INACCESSIBLE_SUBNETS,
|
||||
"local_network_scan": LOCAL_NETWORK_SCAN,
|
||||
"subnets": SUBNETS,
|
||||
}
|
||||
|
||||
TIMEOUT = 2.525
|
||||
ICMP_CONFIGURATION = {"timeout": TIMEOUT}
|
||||
|
||||
PORTS = [8080, 443]
|
||||
TCP_SCAN_CONFIGURATION = {"timeout": TIMEOUT, "ports": PORTS}
|
||||
|
||||
FINGERPRINTERS = [{"name": "mssql", "options": {}}]
|
||||
NETWORK_SCAN_CONFIGURATION = {
|
||||
"tcp": TCP_SCAN_CONFIGURATION,
|
||||
"icmp": ICMP_CONFIGURATION,
|
||||
"fingerprinters": FINGERPRINTERS,
|
||||
"targets": SCAN_TARGET_CONFIGURATION,
|
||||
}
|
||||
|
||||
BRUTE_FORCE = [
|
||||
{"name": "ex1", "options": {}, "supported_os": ["LINUX"]},
|
||||
{
|
||||
"name": "ex2",
|
||||
"options": {"smb_download_timeout": 10},
|
||||
"supported_os": ["LINUX", "WINDOWS"],
|
||||
},
|
||||
]
|
||||
VULNERABILITY = [
|
||||
{
|
||||
"name": "ex3",
|
||||
"options": {"smb_download_timeout": 10},
|
||||
"supported_os": ["WINDOWS"],
|
||||
},
|
||||
]
|
||||
EXPLOITATION_CONFIGURATION = {
|
||||
"options": {"http_ports": PORTS},
|
||||
"brute_force": BRUTE_FORCE,
|
||||
"vulnerability": VULNERABILITY,
|
||||
}
|
||||
|
||||
PROPAGATION_CONFIGURATION = {
|
||||
"maximum_depth": 5,
|
||||
"network_scan": NETWORK_SCAN_CONFIGURATION,
|
||||
"exploitation": EXPLOITATION_CONFIGURATION,
|
||||
}
|
||||
|
||||
AGENT_CONFIGURATION = {
|
||||
"keep_tunnel_open_time": 30,
|
||||
"custom_pbas": CUSTOM_PBA_CONFIGURATION,
|
||||
"post_breach_actions": [PLUGIN_CONFIGURATION],
|
||||
"credential_collectors": [PLUGIN_CONFIGURATION],
|
||||
"payloads": [PLUGIN_CONFIGURATION],
|
||||
"propagation": PROPAGATION_CONFIGURATION,
|
||||
}
|
|
@ -1,3 +1,28 @@
|
|||
from tests.common.example_agent_configuration import (
|
||||
AGENT_CONFIGURATION,
|
||||
BLOCKED_IPS,
|
||||
CUSTOM_PBA_CONFIGURATION,
|
||||
EXPLOITATION_CONFIGURATION,
|
||||
FINGERPRINTERS,
|
||||
ICMP_CONFIGURATION,
|
||||
INACCESSIBLE_SUBNETS,
|
||||
LINUX_COMMAND,
|
||||
LINUX_FILENAME,
|
||||
LOCAL_NETWORK_SCAN,
|
||||
NETWORK_SCAN_CONFIGURATION,
|
||||
PLUGIN_CONFIGURATION,
|
||||
PLUGIN_NAME,
|
||||
PLUGIN_OPTIONS,
|
||||
PORTS,
|
||||
PROPAGATION_CONFIGURATION,
|
||||
SCAN_TARGET_CONFIGURATION,
|
||||
SUBNETS,
|
||||
TCP_SCAN_CONFIGURATION,
|
||||
TIMEOUT,
|
||||
WINDOWS_COMMAND,
|
||||
WINDOWS_FILENAME,
|
||||
)
|
||||
|
||||
from common import OperatingSystems
|
||||
from common.configuration import AgentConfiguration, AgentConfigurationSchema
|
||||
from common.configuration.agent_sub_configuration_schemas import (
|
||||
|
@ -20,30 +45,14 @@ from common.configuration.agent_sub_configurations import (
|
|||
PropagationConfiguration,
|
||||
)
|
||||
|
||||
NAME = "bond"
|
||||
OPTIONS = {"gun": "Walther PPK", "car": "Aston Martin DB5"}
|
||||
PLUGIN_CONFIGURATION = {"name": NAME, "options": OPTIONS}
|
||||
|
||||
|
||||
def test_build_plugin_configuration():
|
||||
schema = PluginConfigurationSchema()
|
||||
|
||||
config = schema.load(PLUGIN_CONFIGURATION)
|
||||
|
||||
assert config.name == NAME
|
||||
assert config.options == OPTIONS
|
||||
|
||||
|
||||
LINUX_COMMAND = "a"
|
||||
LINUX_FILENAME = "b"
|
||||
WINDOWS_COMMAND = "c"
|
||||
WINDOWS_FILENAME = "d"
|
||||
CUSTOM_PBA_CONFIGURATION = {
|
||||
"linux_command": LINUX_COMMAND,
|
||||
"linux_filename": LINUX_FILENAME,
|
||||
"windows_command": WINDOWS_COMMAND,
|
||||
"windows_filename": WINDOWS_FILENAME,
|
||||
}
|
||||
assert config.name == PLUGIN_NAME
|
||||
assert config.options == PLUGIN_OPTIONS
|
||||
|
||||
|
||||
def test_custom_pba_configuration_schema():
|
||||
|
@ -57,18 +66,6 @@ def test_custom_pba_configuration_schema():
|
|||
assert config.windows_filename == WINDOWS_FILENAME
|
||||
|
||||
|
||||
BLOCKED_IPS = ["10.0.0.1", "192.168.1.1"]
|
||||
INACCESSIBLE_SUBNETS = ["172.0.0.0/24", "172.2.2.0/24", "192.168.56.0/24"]
|
||||
LOCAL_NETWORK_SCAN = True
|
||||
SUBNETS = ["10.0.0.2", "10.0.0.2/16"]
|
||||
SCAN_TARGET_CONFIGURATION = {
|
||||
"blocked_ips": BLOCKED_IPS,
|
||||
"inaccessible_subnets": INACCESSIBLE_SUBNETS,
|
||||
"local_network_scan": LOCAL_NETWORK_SCAN,
|
||||
"subnets": SUBNETS,
|
||||
}
|
||||
|
||||
|
||||
def test_scan_target_configuration():
|
||||
schema = ScanTargetConfigurationSchema()
|
||||
|
||||
|
@ -80,10 +77,6 @@ def test_scan_target_configuration():
|
|||
assert config.subnets == SUBNETS
|
||||
|
||||
|
||||
TIMEOUT = 2.525
|
||||
ICMP_CONFIGURATION = {"timeout": TIMEOUT}
|
||||
|
||||
|
||||
def test_icmp_scan_configuration_schema():
|
||||
schema = ICMPScanConfigurationSchema()
|
||||
|
||||
|
@ -92,11 +85,6 @@ def test_icmp_scan_configuration_schema():
|
|||
assert config.timeout == TIMEOUT
|
||||
|
||||
|
||||
PORTS = [8080, 443]
|
||||
|
||||
TCP_SCAN_CONFIGURATION = {"timeout": TIMEOUT, "ports": PORTS}
|
||||
|
||||
|
||||
def test_tcp_scan_configuration_schema():
|
||||
schema = TCPScanConfigurationSchema()
|
||||
|
||||
|
@ -106,15 +94,6 @@ def test_tcp_scan_configuration_schema():
|
|||
assert config.ports == PORTS
|
||||
|
||||
|
||||
FINGERPRINTERS = [{"name": "mssql", "options": {}}]
|
||||
NETWORK_SCAN_CONFIGURATION = {
|
||||
"tcp": TCP_SCAN_CONFIGURATION,
|
||||
"icmp": ICMP_CONFIGURATION,
|
||||
"fingerprinters": FINGERPRINTERS,
|
||||
"targets": SCAN_TARGET_CONFIGURATION,
|
||||
}
|
||||
|
||||
|
||||
def test_network_scan_configuration():
|
||||
schema = NetworkScanConfigurationSchema()
|
||||
|
||||
|
@ -155,28 +134,6 @@ def test_exploiter_configuration_schema():
|
|||
assert config.supported_os == supported_os
|
||||
|
||||
|
||||
BRUTE_FORCE = [
|
||||
{"name": "ex1", "options": {}, "supported_os": ["LINUX"]},
|
||||
{
|
||||
"name": "ex2",
|
||||
"options": {"smb_download_timeout": 10},
|
||||
"supported_os": ["LINUX", "WINDOWS"],
|
||||
},
|
||||
]
|
||||
VULNERABILITY = [
|
||||
{
|
||||
"name": "ex3",
|
||||
"options": {"smb_download_timeout": 10},
|
||||
"supported_os": ["WINDOWS"],
|
||||
},
|
||||
]
|
||||
EXPLOITATION_CONFIGURATION = {
|
||||
"options": {"http_ports": PORTS},
|
||||
"brute_force": BRUTE_FORCE,
|
||||
"vulnerability": VULNERABILITY,
|
||||
}
|
||||
|
||||
|
||||
def test_exploitation_configuration():
|
||||
schema = ExploitationConfigurationSchema()
|
||||
|
||||
|
@ -187,13 +144,6 @@ def test_exploitation_configuration():
|
|||
assert config_dict == EXPLOITATION_CONFIGURATION
|
||||
|
||||
|
||||
PROPAGATION_CONFIGURATION = {
|
||||
"maximum_depth": 5,
|
||||
"network_scan": NETWORK_SCAN_CONFIGURATION,
|
||||
"exploitation": EXPLOITATION_CONFIGURATION,
|
||||
}
|
||||
|
||||
|
||||
def test_propagation_configuration():
|
||||
schema = PropagationConfigurationSchema()
|
||||
|
||||
|
@ -208,17 +158,9 @@ def test_propagation_configuration():
|
|||
|
||||
|
||||
def test_agent_configuration():
|
||||
agent_configuration = {
|
||||
"keep_tunnel_open_time": 30,
|
||||
"custom_pbas": CUSTOM_PBA_CONFIGURATION,
|
||||
"post_breach_actions": [PLUGIN_CONFIGURATION],
|
||||
"credential_collectors": [PLUGIN_CONFIGURATION],
|
||||
"payloads": [PLUGIN_CONFIGURATION],
|
||||
"propagation": PROPAGATION_CONFIGURATION,
|
||||
}
|
||||
schema = AgentConfigurationSchema()
|
||||
|
||||
config = schema.load(agent_configuration)
|
||||
config = schema.load(AGENT_CONFIGURATION)
|
||||
config_dict = schema.dump(config)
|
||||
|
||||
assert isinstance(config, AgentConfiguration)
|
||||
|
@ -228,4 +170,4 @@ def test_agent_configuration():
|
|||
assert isinstance(config.credential_collectors[0], PluginConfiguration)
|
||||
assert isinstance(config.payloads[0], PluginConfiguration)
|
||||
assert isinstance(config.propagation, PropagationConfiguration)
|
||||
assert config_dict == agent_configuration
|
||||
assert config_dict == AGENT_CONFIGURATION
|
||||
|
|
Loading…
Reference in New Issue