>>> hashRecognition("179ad45c6ce2cb97cf1029e212046e81") == HASH.MD5_GENERIC True >>> hashRecognition("S:2BFCFDF5895014EE9BB2B9BA067B01E0389BB5711B7B5F82B7235E9E182C") == HASH.ORACLE True >>> hashRecognition("foobar") == None True
(value)
| 787 | |
| 788 | @cachedmethod |
| 789 | def hashRecognition(value): |
| 790 | """ |
| 791 | >>> hashRecognition("179ad45c6ce2cb97cf1029e212046e81") == HASH.MD5_GENERIC |
| 792 | True |
| 793 | >>> hashRecognition("S:2BFCFDF5895014EE9BB2B9BA067B01E0389BB5711B7B5F82B7235E9E182C") == HASH.ORACLE |
| 794 | True |
| 795 | >>> hashRecognition("foobar") == None |
| 796 | True |
| 797 | """ |
| 798 | |
| 799 | retVal = None |
| 800 | |
| 801 | if value and len(value) >= 8 and ' ' not in value: # Note: pre-filter condition (for optimization purposes) |
| 802 | isOracle, isMySQL = Backend.isDbms(DBMS.ORACLE), Backend.isDbms(DBMS.MYSQL) |
| 803 | |
| 804 | if kb.cache.hashRegex is None: |
| 805 | parts = [] |
| 806 | |
| 807 | for name, regex in getPublicTypeMembers(HASH): |
| 808 | # Hashes for Oracle and old MySQL look the same hence these checks |
| 809 | if isOracle and regex == HASH.MYSQL_OLD or isMySQL and regex == HASH.ORACLE_OLD: |
| 810 | continue |
| 811 | elif regex == HASH.CRYPT_GENERIC: |
| 812 | if any((value.lower() == value, value.upper() == value)): |
| 813 | continue |
| 814 | else: |
| 815 | parts.append("(?P<%s>%s)" % (name, regex)) |
| 816 | |
| 817 | kb.cache.hashRegex = ('|'.join(parts)).replace("(?i)", "") |
| 818 | |
| 819 | if isinstance(value, six.string_types): |
| 820 | match = re.search(kb.cache.hashRegex, value, re.I) |
| 821 | if match: |
| 822 | algorithm, _ = [_ for _ in match.groupdict().items() if _[1] is not None][0] |
| 823 | retVal = getattr(HASH, algorithm) |
| 824 | |
| 825 | return retVal |
| 826 | |
| 827 | def _bruteProcessVariantA(attack_info, hash_regex, suffix, retVal, proc_id, proc_count, wordlists, custom_wordlist, api): |
| 828 | if IS_WIN: |
no test coverage detected
searching dependent graphs…