Skip to content

Commit

Permalink
Fixed connection status when STATUS_LOGON_FAILURE occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
p0dalirius committed Jun 2, 2024
1 parent 8b7cace commit 7a9a033
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion smbclientng/core/InteractiveShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def command_use(self, arguments, command):
# Private functions =======================================================

def __load_modules(self):


self.modules.clear()

Expand Down
54 changes: 34 additions & 20 deletions smbclientng/core/SMBSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def init_smb_session(self):
bool: True if the connection and authentication are successful, False otherwise.
"""

self.connected = False

if self.config.debug:
print("[debug] [>] Connecting to remote SMB server '%s' ... " % self.address)
try:
Expand All @@ -94,31 +96,42 @@ def init_smb_session(self):
print("[!] %s" % err)
self.smbClient = None

self.connected = False
if self.smbClient is not None:
if self.use_kerberos:
if self.config.debug:
print("[debug] [>] Authenticating as '%s\\%s' with kerberos ... " % (self.domain, self.username))
self.connected = self.smbClient.kerberosLogin(
user=self.username,
password=self.password,
domain=self.domain,
lmhash=self.lmhash,
nthash=self.nthash,
aesKey=self.aesKey,
kdcHost=self.kdcHost
)
try:
self.connected = self.smbClient.kerberosLogin(
user=self.username,
password=self.password,
domain=self.domain,
lmhash=self.lmhash,
nthash=self.nthash,
aesKey=self.aesKey,
kdcHost=self.kdcHost
)
except impacket.smbconnection.SessionError as e:
if self.config.debug:
traceback.print_exc()
print("[!] Could not login: %s" % err)
self.connected = False

else:
if self.config.debug:
print("[debug] [>] Authenticating as '%s\\%s' with NTLM ... " % (self.domain, self.username))
self.connected = self.smbClient.login(
user=self.username,
password=self.password,
domain=self.domain,
lmhash=self.lmhash,
nthash=self.nthash
)
try:
self.connected = self.smbClient.login(
user=self.username,
password=self.password,
domain=self.domain,
lmhash=self.lmhash,
nthash=self.nthash
)
except impacket.smbconnection.SessionError as err:
if self.config.debug:
traceback.print_exc()
print("[!] Could not login: %s" % err)
self.connected = False

if self.connected:
print("[+] Successfully authenticated to '%s' as '%s\\%s'!" % (self.address, self.domain, self.username))
Expand All @@ -142,9 +155,11 @@ def close_smb_session(self):
if self.connected:
self.smbClient.close()
self.connected = False
print("[+] SMB connection closed successfully.")
if self.config.debug:
print("[+] SMB connection closed successfully.")
else:
print("[!] No active SMB connection to close.")
if self.config.debug:
print("[!] No active SMB connection to close.")
else:
raise Exception("SMB client is not initialized.")

Expand Down Expand Up @@ -616,7 +631,6 @@ def ping_smb_session(self):

try:
self.smbClient.getSMBServer().echo()
self.connected = True
except Exception as e:
self.connected = False
return self.connected
Expand Down

0 comments on commit 7a9a033

Please sign in to comment.