BB: Simplify logic in BB tests' configurations

This commit is contained in:
Shreya Malviya 2022-08-30 18:03:45 +05:30
parent ff52fbefe4
commit a65415588f
1 changed files with 30 additions and 34 deletions

View File

@ -20,78 +20,74 @@ def add_exploiters(
brute_force: Sequence[PluginConfiguration] = [], brute_force: Sequence[PluginConfiguration] = [],
vulnerability: Sequence[PluginConfiguration] = [], vulnerability: Sequence[PluginConfiguration] = [],
) -> AgentConfiguration: ) -> AgentConfiguration:
exploitation_configuration = replace(
agent_configuration.propagation.exploitation, agent_configuration.propagation.exploitation.brute_force = brute_force
brute_force=brute_force, agent_configuration.propagation.exploitation.vulnerability = vulnerability
vulnerability=vulnerability,
) return agent_configuration
return replace_exploitation_configuration(agent_configuration, exploitation_configuration)
def add_fingerprinters( def add_fingerprinters(
agent_configuration: AgentConfiguration, fingerprinters: Sequence[PluginConfiguration] agent_configuration: AgentConfiguration, fingerprinters: Sequence[PluginConfiguration]
) -> AgentConfiguration: ) -> AgentConfiguration:
network_scan_configuration = replace(
agent_configuration.propagation.network_scan, fingerprinters=fingerprinters
)
return replace_network_scan_configuration(agent_configuration, network_scan_configuration) agent_configuration.propagation.network_scan.fingerprinters = fingerprinters
return agent_configuration
def add_tcp_ports( def add_tcp_ports(
agent_configuration: AgentConfiguration, tcp_ports: Sequence[int] agent_configuration: AgentConfiguration, tcp_ports: Sequence[int]
) -> AgentConfiguration: ) -> 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) agent_configuration.propagation.network_scan.tcp.ports = tuple(tcp_ports)
return agent_configuration
def add_subnets( def add_subnets(
agent_configuration: AgentConfiguration, subnets: Sequence[str] agent_configuration: AgentConfiguration, subnets: Sequence[str]
) -> AgentConfiguration: ) -> AgentConfiguration:
scan_target_configuration = replace(
agent_configuration.propagation.network_scan.targets, subnets=subnets agent_configuration.propagation.network_scan.targets.subnets = subnets
)
return replace_scan_target_configuration(agent_configuration, scan_target_configuration) return agent_configuration
def add_credential_collectors( def add_credential_collectors(
agent_configuration: AgentConfiguration, credential_collectors: Sequence[PluginConfiguration] agent_configuration: AgentConfiguration, credential_collectors: Sequence[PluginConfiguration]
) -> AgentConfiguration: ) -> AgentConfiguration:
return replace(agent_configuration, credential_collectors=tuple(credential_collectors))
agent_configuration.credential_collectors = tuple(credential_collectors)
return agent_configuration
def add_http_ports( def add_http_ports(
agent_configuration: AgentConfiguration, http_ports: Sequence[int] agent_configuration: AgentConfiguration, http_ports: Sequence[int]
) -> AgentConfiguration: ) -> 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.propagation.exploitation.options.http_ports = http_ports
agent_configuration, exploitation_options_configuration
) return agent_configuration
def set_keep_tunnel_open_time( def set_keep_tunnel_open_time(
agent_configuration: AgentConfiguration, keep_tunnel_open_time: int agent_configuration: AgentConfiguration, keep_tunnel_open_time: int
) -> AgentConfiguration: ) -> AgentConfiguration:
return replace(agent_configuration, keep_tunnel_open_time=keep_tunnel_open_time)
agent_configuration.keep_tunnel_open_time = keep_tunnel_open_time
return agent_configuration
def set_maximum_depth( def set_maximum_depth(
agent_configuration: AgentConfiguration, maximum_depth: int agent_configuration: AgentConfiguration, maximum_depth: int
) -> AgentConfiguration: ) -> AgentConfiguration:
propagation_configuration = replace(
agent_configuration.propagation, maximum_depth=maximum_depth agent_configuration.propagation.maximum_depth = maximum_depth
)
return replace_propagation_configuration(agent_configuration, propagation_configuration) return agent_configuration
def replace_exploitation_configuration( def replace_exploitation_configuration(