Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unknown NTSTATUS in SessionError #1311

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions impacket/krb5/kerberosv5.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def getErrorPacket( self ):
return self.packet

def getErrorString( self ):
return constants.ERROR_MESSAGES[self.error]
return str(self)

def __str__( self ):
retString = 'Kerberos SessionError: %s(%s)' % (constants.ERROR_MESSAGES[self.error])
Expand All @@ -708,7 +708,13 @@ def __str__( self ):
if self.error == constants.ErrorCodes.KRB_ERR_GENERIC.value:
eData = decoder.decode(self.packet['e-data'], asn1Spec = KERB_ERROR_DATA())[0]
nt_error = struct.unpack('<L', eData['data-value'].asOctets()[:4])[0]
retString += '\nNT ERROR: %s(%s)' % (nt_errors.ERROR_MESSAGES[nt_error])

if nt_error in nt_errors.ERROR_MESSAGES:
error_msg_short = nt_errors.ERROR_MESSAGES[nt_error][0]
error_msg_verbose = nt_errors.ERROR_MESSAGES[nt_error][1]
retString += '\nNT ERROR: code: 0x%x - %s - %s' % (nt_error, error_msg_short, error_msg_verbose)
else:
retString += '\nNT ERROR: unknown error code: 0x%x' % nt_error
except:
pass

Expand Down
8 changes: 7 additions & 1 deletion impacket/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,13 @@ def __str__( self ):
error_code_str = '%s(%s)' % error_code

if self.nt_status:
return 'SMB SessionError: %s(%s)' % nt_errors.ERROR_MESSAGES[self.error_code]
key = self.error_code
if key in nt_errors.ERROR_MESSAGES:
error_msg_short = nt_errors.ERROR_MESSAGES[key][0]
error_msg_verbose = nt_errors.ERROR_MESSAGES[key][1]
return 'SMB SessionError: code: 0x%x - %s - %s' % (self.error_code, error_msg_short, error_msg_verbose)
else:
return 'SMB SessionError: unknown error code: 0x%x' % self.error_code
else:
# Fall back to the old format
return 'SMB SessionError: class: %s, code: %s' % (error_class_str, error_code_str)
Expand Down
11 changes: 7 additions & 4 deletions impacket/smbconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,13 @@ def getErrorPacket( self ):
return self.packet

def getErrorString( self ):
return nt_errors.ERROR_MESSAGES[self.error]
return str(self)

def __str__( self ):
if self.error in nt_errors.ERROR_MESSAGES:
return 'SMB SessionError: %s(%s)' % (nt_errors.ERROR_MESSAGES[self.error])
key = self.error
if key in nt_errors.ERROR_MESSAGES:
error_msg_short = nt_errors.ERROR_MESSAGES[key][0]
error_msg_verbose = nt_errors.ERROR_MESSAGES[key][1]
return 'SMB SessionError: code: 0x%x - %s - %s' % (self.error, error_msg_short, error_msg_verbose)
else:
return 'SMB SessionError: 0x%x' % self.error
return 'SMB SessionError: unknown error code: 0x%x' % self.error