From ddcc689d0f3cb240126040ec6f9b69c41b8a21af Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 27 Jul 2022 09:19:38 -0400 Subject: [PATCH] Agent: Pass only ExploitationConfiguration to _exploit_hosts() --- monkey/infection_monkey/master/exploiter.py | 12 +++++++----- monkey/infection_monkey/master/propagator.py | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/monkey/infection_monkey/master/exploiter.py b/monkey/infection_monkey/master/exploiter.py index 9152f34a1..b74a542e7 100644 --- a/monkey/infection_monkey/master/exploiter.py +++ b/monkey/infection_monkey/master/exploiter.py @@ -50,14 +50,14 @@ class Exploiter: def exploit_hosts( self, - exploiter_config: ExploitationConfiguration, + exploitation_config: ExploitationConfiguration, hosts_to_exploit: Queue, current_depth: int, results_callback: Callback, scan_completed: Event, stop: Event, ): - exploiters_to_run = self._process_exploiter_config(exploiter_config) + exploiters_to_run = self._process_exploiter_config(exploitation_config) logger.debug( "Agent is configured to run the following exploiters in order: " f"{', '.join([e.name for e in exploiters_to_run])}" @@ -80,18 +80,20 @@ class Exploiter: @staticmethod def _process_exploiter_config( - exploiter_config: ExploitationConfiguration, + exploitation_config: ExploitationConfiguration, ) -> Sequence[PluginConfiguration]: # Run vulnerability exploiters before brute force exploiters to minimize the effect of # account lockout due to invalid credentials - ordered_exploiters = chain(exploiter_config.vulnerability, exploiter_config.brute_force) + ordered_exploiters = chain( + exploitation_config.vulnerability, exploitation_config.brute_force + ) exploiters_to_run = list(deepcopy(ordered_exploiters)) extended_exploiters = [] for exploiter in exploiters_to_run: # This order allows exploiter-specific options to # override general options for all exploiters. - options = {**exploiter_config.options.__dict__, **exploiter.options} + options = {**exploitation_config.options.__dict__, **exploiter.options} extended_exploiters.append(PluginConfiguration(exploiter.name, options)) return extended_exploiters diff --git a/monkey/infection_monkey/master/propagator.py b/monkey/infection_monkey/master/propagator.py index 16cd30f7f..c185c6153 100644 --- a/monkey/infection_monkey/master/propagator.py +++ b/monkey/infection_monkey/master/propagator.py @@ -4,6 +4,7 @@ from threading import Event from typing import List from common.agent_configuration import ( + ExploitationConfiguration, NetworkScanConfiguration, PropagationConfiguration, ScanTargetConfiguration, @@ -60,7 +61,7 @@ class Propagator: exploit_thread = create_daemon_thread( target=self._exploit_hosts, name="PropagatorExploitThread", - args=(propagation_config, current_depth, network_scan_completed, stop), + args=(propagation_config.exploitation, current_depth, network_scan_completed, stop), ) scan_thread.start() @@ -142,16 +143,15 @@ class Propagator: def _exploit_hosts( self, - propagation_config: PropagationConfiguration, + exploitation_config: ExploitationConfiguration, current_depth: int, network_scan_completed: Event, stop: Event, ): logger.info("Exploiting victims") - exploiter_config = propagation_config.exploitation self._exploiter.exploit_hosts( - exploiter_config, + exploitation_config, self._hosts_to_exploit, current_depth, self._process_exploit_attempts,