This script allows you to crack an MD5 hash. The script asks you for both the file where the hash resides (a .txt file normally, although a .dat will work just as well), as well as the wordlist (also a .txt or .dat) to be used. The program functions by hashing each line from the wordlist, and then comparing it to the hash specified. Very quick runtime!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#Begin Hash Cracker.py import hashlib, sys m = hashlib.md5() hash = "" hash_file = raw_input("What is the file name in which the hash resides? ") wordlist = raw_input("What is your wordlist? (Enter the file name) ") try: hashdocument = open(hash_file,"r") except IOError: print "Invalid file." raw_input() sys.exit() else: hash = hashdocument.readline() hash = hash.replace("\n","") try: wordlistfile = open(wordlist,"r") except IOError: print "Invalid file." raw_input() sys.exit() else: pass for line in wordlistfile: m = hashlib.md5() #flush the buffer (this caused a massive problem when placed at the beginning of the script, because the buffer kept getting overwritten, thus comparing incorrect hashes) line = line.replace("\n","") m.update(line) word_hash = m.hexdigest() if word_hash==hash: print "Collision! The word corresponding to the given hash is", line, raw_input() sys.exit() print "The hash given does not correspond to any supplied word in the wordlist." raw_input() sys.exit() #EoF #Written by Neil Shah, 9th grade
This is an alternative to hash cracking online. It allows the user to modify the wordlist being used, and is extremely quick (much faster alternative to Rainbow Tables and other tools such as John the Ripper or Cain and Abel). The reason I wrote this program is for others to be able to benefit from this utility, while also improving my programming skills in Python. The replace function is used so that the string to be hashed does not include the '\n' or newline character while hashing (therefore generating incorrect hashes, and rendering the program useless). Enjoy!