|
11 | 11 | # dependencies to get rid of or internalize
|
12 | 12 | from infection_monkey.exploit import IAgentBinaryRepository, IAgentOTPProvider
|
13 | 13 | from infection_monkey.exploit.tools import all_udp_ports_are_closed
|
14 |
| -from infection_monkey.exploit.tools.http_agent_binary_server import start_agent_binary_server |
| 14 | +from infection_monkey.exploit.tools.helpers import get_agent_dst_path |
| 15 | +from infection_monkey.exploit.tools.http_agent_binary_server import start_dropper_script_server |
15 | 16 | from infection_monkey.i_puppet import ExploiterResultData, TargetHost
|
| 17 | +from infection_monkey.model import MONKEY_ARG |
16 | 18 | from infection_monkey.network import TCPPortSelector
|
17 | 19 | from infection_monkey.propagation_credentials_repository import IPropagationCredentialsRepository
|
| 20 | +from infection_monkey.utils.commands import build_monkey_commandline_parameters |
18 | 21 |
|
19 | 22 | from .community_string_generator import generate_community_strings
|
20 | 23 | from .snmp_client import SNMPClient
|
@@ -97,29 +100,41 @@ def run(
|
97 | 100 | self._propagation_credentials_repository.get_credentials()
|
98 | 101 | )
|
99 | 102 |
|
100 |
| - snmp_exploiter = self._create_snmp_exploiter(snmp_client) |
101 |
| - return snmp_exploiter.exploit_host( |
102 |
| - host, servers, current_depth, snmp_options, community_strings, interrupt |
103 |
| - ) |
| 103 | + snmp_exploiter = self._create_snmp_exploiter(snmp_client, host, servers, current_depth) |
| 104 | + return snmp_exploiter.exploit_host(host, snmp_options, community_strings, interrupt) |
104 | 105 | except Exception as err:
|
105 | 106 | msg = f"An unexpected exception occurred while attempting to exploit host: {err}"
|
106 | 107 | logger.exception(msg)
|
107 | 108 | return ExploiterResultData(
|
108 | 109 | exploitation_success=False, propagation_success=False, error_message=msg
|
109 | 110 | )
|
110 | 111 |
|
111 |
| - def _create_snmp_exploiter(self, snmp_client: SNMPClient) -> SNMPExploiter: |
| 112 | + def _create_snmp_exploiter( |
| 113 | + self, |
| 114 | + snmp_client: SNMPClient, |
| 115 | + target_host: TargetHost, |
| 116 | + servers: Sequence[str], |
| 117 | + current_depth: int, |
| 118 | + ) -> SNMPExploiter: |
112 | 119 | exploit_client = SNMPExploitClient(
|
113 | 120 | self._agent_id, self._agent_event_publisher, self._plugin_name, snmp_client
|
114 | 121 | )
|
115 |
| - agent_binary_server_factory = partial( |
116 |
| - start_agent_binary_server, |
| 122 | + args = [MONKEY_ARG] |
| 123 | + args.extend( |
| 124 | + build_monkey_commandline_parameters( |
| 125 | + parent=self._agent_id, servers=servers, depth=current_depth + 1 |
| 126 | + ) |
| 127 | + ) |
| 128 | + dropper_script_server_factory = partial( |
| 129 | + start_dropper_script_server, |
| 130 | + target_host=target_host, |
117 | 131 | agent_binary_repository=self._agent_binary_repository,
|
118 | 132 | tcp_port_selector=self._tcp_port_selector,
|
| 133 | + destination_path=get_agent_dst_path(target_host), |
| 134 | + args=args, |
119 | 135 | )
|
120 | 136 | return SNMPExploiter(
|
121 |
| - self._agent_id, |
122 | 137 | exploit_client,
|
123 |
| - agent_binary_server_factory, |
| 138 | + dropper_script_server_factory, |
124 | 139 | self._otp_provider,
|
125 | 140 | )
|
0 commit comments