Skip to content

Commit

Permalink
Handle unknown NTSTATUS in SessionError (fortra#1311)
Browse files Browse the repository at this point in the history
* Handle unknown NTSTATUS in SessionError

* Handle unknown NTSTATUS in other places
  • Loading branch information
Lucas Vater authored and abbra committed Nov 27, 2023
1 parent b6b9b96 commit b6db885
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 8 additions & 2 deletions impacket/krb5/kerberosv5.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,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 @@ -721,7 +721,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 @@ -579,7 +579,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

0 comments on commit b6db885

Please sign in to comment.