Skip to content

Commit c17af16

Browse files
Agent: Load and run SSH exploiter in concrete puppet
1 parent 19feb24 commit c17af16

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

monkey/infection_monkey/i_puppet/i_puppet.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ def fingerprint(
103103

104104
@abc.abstractmethod
105105
def exploit_host(
106-
self, name: str, host: str, options: Dict, interrupt: threading.Event
106+
self, name: str, host: object, options: Dict, interrupt: threading.Event
107107
) -> ExploiterResultData:
108108
"""
109109
Runs an exploiter against a remote host
110110
:param str name: The name of the exploiter to run
111-
:param str host: The domain name or IP address of a host
111+
:param object host: The domain name or IP address of a host
112112
:param Dict options: A dictionary containing options that modify the behavior of the
113113
exploiter
114+
:param threading.Event interrupt: A threading.Event object that signals the exploit to stop
115+
executing and clean itself up.
114116
:return: True if exploitation was successful, False otherwise
115117
:rtype: ExploiterResultData
116118
"""

monkey/infection_monkey/master/exploiter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _run_exploiter(
115115
credentials = self._get_credentials_for_propagation()
116116
options = {"credentials": credentials, **options}
117117

118-
return self._puppet.exploit_host(exploiter_name, victim_host.ip_addr, options, stop)
118+
return self._puppet.exploit_host(exploiter_name, victim_host, options, stop)
119119

120120
def _get_credentials_for_propagation(self) -> Mapping:
121121
try:

monkey/infection_monkey/monkey.py

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
MimikatzCredentialCollector,
1717
SSHCredentialCollector,
1818
)
19+
from infection_monkey.exploit.sshexec import SSHExploiter
1920
from infection_monkey.i_puppet import IPuppet, PluginType
2021
from infection_monkey.master import AutomatedMaster
2122
from infection_monkey.master.control_channel import ControlChannel
@@ -213,6 +214,8 @@ def _build_puppet(self) -> IPuppet:
213214
puppet.load_plugin("smb", SMBFingerprinter(), PluginType.FINGERPRINTER)
214215
puppet.load_plugin("ssh", SSHFingerprinter(), PluginType.FINGERPRINTER)
215216

217+
puppet.load_plugin("SSHExploiter", SSHExploiter, PluginType.EXPLOITER)
218+
216219
puppet.load_plugin("ransomware", RansomwarePayload(), PluginType.PAYLOAD)
217220

218221
return puppet

monkey/infection_monkey/puppet/mock_puppet.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def fingerprint(
135135
return empty_fingerprint_data
136136

137137
def exploit_host(
138-
self, name: str, host: str, options: Dict, interrupt: threading.Event
138+
self, name: str, host: object, options: Dict, interrupt: threading.Event
139139
) -> ExploiterResultData:
140140
logger.debug(f"exploit_hosts({name}, {host}, {options})")
141141
attempts = [
@@ -193,9 +193,9 @@ def exploit_host(
193193
}
194194

195195
try:
196-
return successful_exploiters[host][name]
196+
return successful_exploiters[host.ip_addr][name]
197197
except KeyError:
198-
return ExploiterResultData(False, {}, [], f"{name} failed for host {host}")
198+
return ExploiterResultData(False, {}, [], f"{name} failed for host {host.ip_addr}")
199199

200200
def run_payload(self, name: str, options: Dict, interrupt: threading.Event):
201201
logger.debug(f"run_payload({name}, {options})")

monkey/infection_monkey/puppet/puppet.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
PostBreachData,
1515
)
1616

17+
from ..telemetry.messengers.legacy_telemetry_messenger_adapter import (
18+
LegacyTelemetryMessengerAdapter,
19+
)
1720
from .mock_puppet import MockPuppet
1821
from .plugin_registry import PluginRegistry
1922

@@ -57,9 +60,10 @@ def fingerprint(
5760
return fingerprinter.get_host_fingerprint(host, ping_scan_data, port_scan_data, options)
5861

5962
def exploit_host(
60-
self, name: str, host: str, options: Dict, interrupt: threading.Event
63+
self, name: str, host: object, options: Dict, interrupt: threading.Event
6164
) -> ExploiterResultData:
62-
return self._mock_puppet.exploit_host(name, host, options, interrupt)
65+
exploiter = self._plugin_registry.get_plugin(name, PluginType.EXPLOITER)
66+
return exploiter(host, LegacyTelemetryMessengerAdapter(), options).exploit_host()
6367

6468
def run_payload(self, name: str, options: Dict, interrupt: threading.Event):
6569
payload = self._plugin_registry.get_plugin(name, PluginType.PAYLOAD)

0 commit comments

Comments
 (0)