@@ -727,21 +727,31 @@ def attackDumpedTable():
727727 table [column ]['length' ] = max (table [column ]['length' ], len (table [column ]['values' ][i ]))
728728
729729def hashRecognition (value ):
730+ """
731+ >>> hashRecognition("179ad45c6ce2cb97cf1029e212046e81") == HASH.MD5_GENERIC
732+ True
733+ >>> hashRecognition("S:2BFCFDF5895014EE9BB2B9BA067B01E0389BB5711B7B5F82B7235E9E182C") == HASH.ORACLE
734+ True
735+ >>> hashRecognition("foobar") == None
736+ True
737+ """
738+
730739 retVal = None
731740
732- isOracle , isMySQL = Backend .isDbms (DBMS .ORACLE ), Backend .isDbms (DBMS .MYSQL )
741+ if value and len (value ) >= 8 and ' ' not in value : # Note: pre-filter condition (for optimization purposes)
742+ isOracle , isMySQL = Backend .isDbms (DBMS .ORACLE ), Backend .isDbms (DBMS .MYSQL )
733743
734- if isinstance (value , six .string_types ):
735- for name , regex in getPublicTypeMembers (HASH ):
736- # Hashes for Oracle and old MySQL look the same hence these checks
737- if isOracle and regex == HASH .MYSQL_OLD or isMySQL and regex == HASH .ORACLE_OLD :
738- continue
739- elif regex == HASH .CRYPT_GENERIC :
740- if any ((value .lower () == value , value .upper () == value )):
744+ if isinstance (value , six .string_types ):
745+ for name , regex in getPublicTypeMembers (HASH ):
746+ # Hashes for Oracle and old MySQL look the same hence these checks
747+ if isOracle and regex == HASH .MYSQL_OLD or isMySQL and regex == HASH .ORACLE_OLD :
741748 continue
742- elif re .match (regex , value ):
743- retVal = regex
744- break
749+ elif regex == HASH .CRYPT_GENERIC :
750+ if any ((value .lower () == value , value .upper () == value )):
751+ continue
752+ elif re .match (regex , value ):
753+ retVal = regex
754+ break
745755
746756 return retVal
747757
0 commit comments