From 2d130a04425b8677984b555fe62bfae3105bbdb5 Mon Sep 17 00:00:00 2001 From: Kekoa Kaaikala Date: Thu, 6 Oct 2022 14:15:52 +0000 Subject: [PATCH] Agent: Extract method _get_agent_command --- monkey/infection_monkey/exploit/smbexec.py | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/monkey/infection_monkey/exploit/smbexec.py b/monkey/infection_monkey/exploit/smbexec.py index d4b7078af..5108c85b3 100644 --- a/monkey/infection_monkey/exploit/smbexec.py +++ b/monkey/infection_monkey/exploit/smbexec.py @@ -56,18 +56,7 @@ class SMBExploiter(HostExploiter): return self.exploit_result # execute the remote dropper in case the path isn't final - if remote_full_path.lower() != str(dest_path).lower(): - cmdline = DROPPER_CMDLINE_DETACHED_WINDOWS % { - "dropper_path": remote_full_path - } + build_monkey_commandline( - self.servers, - self.current_depth + 1, - str(dest_path), - ) - else: - cmdline = MONKEY_CMDLINE_DETACHED_WINDOWS % { - "monkey_path": remote_full_path - } + build_monkey_commandline(self.servers, self.current_depth + 1) + cmdline = self._get_agent_command(remote_full_path, dest_path) smb_conn = None for str_bind_format, port in SMBExploiter.KNOWN_PROTOCOLS.values(): @@ -206,3 +195,19 @@ class SMBExploiter(HostExploiter): continue return remote_full_path, SelectedCredentials(user, password, lm_hash, ntlm_hash) + + def _get_agent_command(self, remote_full_path: str, dest_path: PurePath) -> str: + if remote_full_path.lower() != str(dest_path).lower(): + cmdline = DROPPER_CMDLINE_DETACHED_WINDOWS % { + "dropper_path": remote_full_path + } + build_monkey_commandline( + self.servers, + self.current_depth + 1, + str(dest_path), + ) + else: + cmdline = MONKEY_CMDLINE_DETACHED_WINDOWS % { + "monkey_path": remote_full_path + } + build_monkey_commandline(self.servers, self.current_depth + 1) + + return cmdline