forked from p34709852/monkey
Agent: Use error to propagate failure
This commit is contained in:
parent
a2534391a6
commit
0a1901b9a1
|
@ -188,7 +188,20 @@ class SSHExploiter(HostExploiter):
|
|||
self._set_interrupted()
|
||||
return self.exploit_result
|
||||
|
||||
return self._propagate(ssh)
|
||||
try:
|
||||
self._propagate(ssh)
|
||||
except FailedExploitationError as err:
|
||||
ssh.close()
|
||||
self.exploit_result.error_message = str(err)
|
||||
logger.error(self.exploit_result.error_message)
|
||||
|
||||
self._publish_propagation_event(
|
||||
target=self.host.ip_addr,
|
||||
propagation_success=False,
|
||||
error_message=self.exploit_result.error_message,
|
||||
tags=PROPAGATION_TAGS,
|
||||
)
|
||||
return self.exploit_result
|
||||
|
||||
def _exploit(self) -> paramiko.SSHClient:
|
||||
port = SSH_PORT
|
||||
|
@ -222,33 +235,24 @@ class SSHExploiter(HostExploiter):
|
|||
|
||||
def _propagate(self, ssh: paramiko.SSHClient):
|
||||
if not self.host.os.get("type") and not self._get_victim_os(ssh):
|
||||
return self.exploit_result
|
||||
raise FailedExploitationError(
|
||||
f"Can't find suitable monkey executable for host {self.host}"
|
||||
)
|
||||
|
||||
agent_binary_file_object = self.agent_binary_repository.get_agent_binary(
|
||||
self.exploit_result.os
|
||||
)
|
||||
|
||||
if not agent_binary_file_object:
|
||||
self.exploit_result.error_message = (
|
||||
raise FailedExploitationError(
|
||||
f"Can't find suitable monkey executable for host {self.host}"
|
||||
)
|
||||
|
||||
self._publish_propagation_event(
|
||||
target=self.host.ip_addr,
|
||||
propagation_success=False,
|
||||
error_message=self.exploit_result.error_message,
|
||||
tags=(SSH_EXPLOITER_TAG,),
|
||||
)
|
||||
|
||||
logger.error(self.exploit_result.error_message)
|
||||
return self.exploit_result
|
||||
|
||||
if self._is_interrupted():
|
||||
self._set_interrupted()
|
||||
return self.exploit_result
|
||||
raise FailedExploitationError(f"Propagation was interrupted")
|
||||
|
||||
monkey_path_on_victim = get_agent_dst_path(self.host)
|
||||
|
||||
status = self._upload_agent_binary(ssh, agent_binary_file_object, monkey_path_on_victim)
|
||||
|
||||
self.telemetry_messenger.send_telemetry(
|
||||
|
@ -261,13 +265,7 @@ class SSHExploiter(HostExploiter):
|
|||
)
|
||||
|
||||
if status == ScanStatus.SCANNED:
|
||||
self._publish_propagation_event(
|
||||
target=self.host.ip_addr,
|
||||
propagation_success=False,
|
||||
error_message=self.exploit_result.error_message,
|
||||
tags=PROPAGATION_TAGS,
|
||||
)
|
||||
return self.exploit_result
|
||||
raise FailedExploitationError(self.exploit_result.error_message)
|
||||
|
||||
try:
|
||||
cmdline = f"{monkey_path_on_victim} {MONKEY_ARG}"
|
||||
|
@ -292,22 +290,9 @@ class SSHExploiter(HostExploiter):
|
|||
|
||||
ssh.close()
|
||||
self.add_executed_cmd(cmdline)
|
||||
return self.exploit_result
|
||||
|
||||
except Exception as exc:
|
||||
self.exploit_result.error_message = (
|
||||
f"Error running monkey on victim {self.host}: ({exc})"
|
||||
)
|
||||
|
||||
self._publish_propagation_event(
|
||||
target=self.host.ip_addr,
|
||||
propagation_success=False,
|
||||
error_message=self.exploit_result.error_message,
|
||||
tags=PROPAGATION_TAGS,
|
||||
)
|
||||
|
||||
logger.error(self.exploit_result.error_message)
|
||||
return self.exploit_result
|
||||
raise FailedExploitationError(f"Error running monkey on victim {self.host}: ({exc})")
|
||||
|
||||
def _get_victim_os(self, ssh: paramiko.SSHClient) -> bool:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue