2022-07-19 02:27:08 +08:00
|
|
|
from dataclasses import replace
|
2022-07-19 02:52:05 +08:00
|
|
|
from typing import Sequence, Tuple
|
2022-07-19 02:27:08 +08:00
|
|
|
|
2022-07-26 14:32:05 +08:00
|
|
|
from common.agent_configuration import (
|
2022-07-19 02:27:08 +08:00
|
|
|
AgentConfiguration,
|
|
|
|
ExploitationConfiguration,
|
2022-07-19 20:12:46 +08:00
|
|
|
ExploitationOptionsConfiguration,
|
2022-07-19 02:27:08 +08:00
|
|
|
NetworkScanConfiguration,
|
2022-07-19 02:49:25 +08:00
|
|
|
PluginConfiguration,
|
2022-07-19 02:27:08 +08:00
|
|
|
PropagationConfiguration,
|
|
|
|
ScanTargetConfiguration,
|
|
|
|
)
|
2022-07-19 02:52:05 +08:00
|
|
|
from common.credentials import Credentials
|
2022-07-19 02:27:08 +08:00
|
|
|
|
|
|
|
from . import TestConfiguration
|
|
|
|
|
|
|
|
|
|
|
|
def add_exploiters(
|
2022-07-19 02:49:25 +08:00
|
|
|
agent_configuration: AgentConfiguration,
|
|
|
|
brute_force: Sequence[PluginConfiguration] = [],
|
|
|
|
vulnerability: Sequence[PluginConfiguration] = [],
|
2022-07-19 02:27:08 +08:00
|
|
|
) -> AgentConfiguration:
|
|
|
|
exploitation_configuration = replace(
|
|
|
|
agent_configuration.propagation.exploitation,
|
|
|
|
brute_force=brute_force,
|
|
|
|
vulnerability=vulnerability,
|
|
|
|
)
|
|
|
|
return replace_exploitation_configuration(agent_configuration, exploitation_configuration)
|
|
|
|
|
|
|
|
|
2022-07-27 22:59:58 +08:00
|
|
|
def add_fingerprinters(
|
2022-07-28 18:10:24 +08:00
|
|
|
agent_configuration: AgentConfiguration, fingerprinters: Sequence[PluginConfiguration]
|
2022-07-27 22:59:58 +08:00
|
|
|
) -> AgentConfiguration:
|
|
|
|
network_scan_configuration = replace(
|
|
|
|
agent_configuration.propagation.network_scan, fingerprinters=fingerprinters
|
|
|
|
)
|
|
|
|
|
|
|
|
return replace_network_scan_configuration(agent_configuration, network_scan_configuration)
|
|
|
|
|
|
|
|
|
2022-07-19 02:27:08 +08:00
|
|
|
def add_tcp_ports(
|
|
|
|
agent_configuration: AgentConfiguration, tcp_ports: Sequence[int]
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
tcp_scan_configuration = replace(
|
|
|
|
agent_configuration.propagation.network_scan.tcp, ports=tuple(tcp_ports)
|
|
|
|
)
|
|
|
|
network_scan_configuration = replace(
|
|
|
|
agent_configuration.propagation.network_scan, tcp=tcp_scan_configuration
|
|
|
|
)
|
|
|
|
|
|
|
|
return replace_network_scan_configuration(agent_configuration, network_scan_configuration)
|
|
|
|
|
|
|
|
|
|
|
|
def add_subnets(
|
|
|
|
agent_configuration: AgentConfiguration, subnets: Sequence[str]
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
scan_target_configuration = replace(
|
|
|
|
agent_configuration.propagation.network_scan.targets, subnets=subnets
|
|
|
|
)
|
|
|
|
return replace_scan_target_configuration(agent_configuration, scan_target_configuration)
|
|
|
|
|
|
|
|
|
2022-07-19 02:52:31 +08:00
|
|
|
def add_credential_collectors(
|
|
|
|
agent_configuration: AgentConfiguration, credential_collectors: Sequence[PluginConfiguration]
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
return replace(agent_configuration, credential_collectors=tuple(credential_collectors))
|
|
|
|
|
|
|
|
|
2022-07-19 20:12:46 +08:00
|
|
|
def add_http_ports(
|
|
|
|
agent_configuration: AgentConfiguration, http_ports: Sequence[int]
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
exploitation_options_configuration = agent_configuration.propagation.exploitation.options
|
|
|
|
exploitation_options_configuration = replace(
|
|
|
|
exploitation_options_configuration, http_ports=http_ports
|
|
|
|
)
|
|
|
|
|
|
|
|
return replace_exploitation_options_configuration(
|
|
|
|
agent_configuration, exploitation_options_configuration
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-20 01:24:00 +08:00
|
|
|
def set_keep_tunnel_open_time(
|
|
|
|
agent_configuration: AgentConfiguration, keep_tunnel_open_time: int
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
return replace(agent_configuration, keep_tunnel_open_time=keep_tunnel_open_time)
|
|
|
|
|
|
|
|
|
2022-07-19 03:03:52 +08:00
|
|
|
def set_maximum_depth(
|
|
|
|
agent_configuration: AgentConfiguration, maximum_depth: int
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
propagation_configuration = replace(
|
|
|
|
agent_configuration.propagation, maximum_depth=maximum_depth
|
|
|
|
)
|
|
|
|
return replace_propagation_configuration(agent_configuration, propagation_configuration)
|
|
|
|
|
|
|
|
|
2022-07-19 02:27:08 +08:00
|
|
|
def replace_exploitation_configuration(
|
|
|
|
agent_configuration: AgentConfiguration, exploitation_configuration: ExploitationConfiguration
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
propagation_configuration = replace(
|
|
|
|
agent_configuration.propagation, exploitation=exploitation_configuration
|
|
|
|
)
|
|
|
|
|
|
|
|
return replace_propagation_configuration(agent_configuration, propagation_configuration)
|
|
|
|
|
|
|
|
|
|
|
|
def replace_scan_target_configuration(
|
|
|
|
agent_configuration: AgentConfiguration, scan_target_configuration: ScanTargetConfiguration
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
network_scan_configuration = replace(
|
|
|
|
agent_configuration.propagation.network_scan, targets=scan_target_configuration
|
|
|
|
)
|
|
|
|
|
|
|
|
return replace_network_scan_configuration(agent_configuration, network_scan_configuration)
|
|
|
|
|
|
|
|
|
|
|
|
def replace_network_scan_configuration(
|
|
|
|
agent_configuration: AgentConfiguration, network_scan_configuration: NetworkScanConfiguration
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
propagation_configuration = replace(
|
|
|
|
agent_configuration.propagation, network_scan=network_scan_configuration
|
|
|
|
)
|
|
|
|
return replace_propagation_configuration(agent_configuration, propagation_configuration)
|
|
|
|
|
|
|
|
|
|
|
|
def replace_propagation_configuration(
|
|
|
|
agent_configuration: AgentConfiguration, propagation_configuration: PropagationConfiguration
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
return replace(agent_configuration, propagation=propagation_configuration)
|
|
|
|
|
|
|
|
|
2022-07-19 20:12:46 +08:00
|
|
|
def replace_exploitation_options_configuration(
|
|
|
|
agent_configuration: AgentConfiguration,
|
|
|
|
exploitation_options_configuration: ExploitationOptionsConfiguration,
|
|
|
|
) -> AgentConfiguration:
|
|
|
|
exploitation_configuration = agent_configuration.propagation.exploitation
|
|
|
|
exploitation_configuration = replace(
|
|
|
|
exploitation_configuration, options=exploitation_options_configuration
|
|
|
|
)
|
|
|
|
return replace_exploitation_configuration(agent_configuration, exploitation_configuration)
|
|
|
|
|
|
|
|
|
2022-07-19 02:27:08 +08:00
|
|
|
def replace_agent_configuration(
|
|
|
|
test_configuration: TestConfiguration, agent_configuration: AgentConfiguration
|
|
|
|
) -> TestConfiguration:
|
|
|
|
return replace(test_configuration, agent_configuration=agent_configuration)
|
2022-07-19 02:52:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
def replace_propagation_credentials(
|
|
|
|
test_configuration: TestConfiguration, propagation_credentials: Tuple[Credentials, ...]
|
|
|
|
):
|
|
|
|
return replace(test_configuration, propagation_credentials=propagation_credentials)
|