Advertisement
Guest User

CameToLearn's Python Hashcracker

a guest
Sep 16th, 2015
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.00 KB | None | 0 0
  1. import hashlib, sys, getopt
  2.  
  3. #Coded by CameToLearn from https://cybrary.it
  4.  
  5. #TODO: Add input of multiple hashes
  6.  
  7.  
  8. def usage():
  9.     print "-v              |    Print attempts"
  10.     print "-h              |    This menu"
  11.     print "-H, --hash      |    Hash to crack"
  12.     print "-t --type       |    Supports: md5, sha1, sha224, sha256, sha384, sha512"
  13.     print "-d --dict       |    Dictionary file to crack with"
  14.     #print "-i, --inputfile |    Input file of hashes"
  15.     sys.exit()
  16.    
  17. def main():
  18.     counter = 0
  19.     input_hash = ""
  20.     input_hash_type = ""
  21.     #input_hash_file = ""
  22.     wordlist = ""
  23.     verbose = 0
  24.  
  25.     try:
  26.         options, arguments = getopt.getopt(sys.argv[1:], "vhi:H:t:d:", ["hash=", "type=", "help", "inputfile=", "dict="])
  27.     except getopt.GetoptError as err:
  28.         print str(err)
  29.         usage()
  30.  
  31.     for option, argument in options:
  32.         if option in ("-h", "--help"):
  33.             usage()  
  34.         elif option == "-v":
  35.             verbose = 1
  36.         elif option in ("-H", "--hash"):
  37.             input_hash = argument
  38.         elif option in ("-t", "--type"):
  39.             input_hash_type = argument.lower()
  40.         elif option in ("-d", "--dict"):
  41.             wordlist = argument
  42.  
  43.         """elif option in ("-i", "--inputfile"):
  44.            input_hash_file = argument"""
  45.        
  46.     if input_hash == "" or input_hash_type == "" or wordlist == "":
  47.         usage()
  48.  
  49.     if input_hash_type == "md5":
  50.         htype = hashlib.md5
  51.     elif input_hash_type == "sha1":
  52.         htype = hashlib.sha1
  53.     elif input_hash_type == "sha224":
  54.         htype = hashlib.sha224
  55.     elif input_hash_type == "sha256":
  56.         htype = hashlib.sha256
  57.     elif input_hash_type == "sha384":
  58.         htype = hashlib.sha384
  59.     elif input_hash_type == "sha512":
  60.         htype = hashlib.sha512
  61.  
  62.    
  63.     try:
  64.         dictfile = open(wordlist,'r')
  65.     except Exception as e:
  66.         print "Unable to open file, make sure you typed the correct filename.", e
  67.         sys.exit()
  68.  
  69.        
  70.     try:
  71.         if verbose:
  72.             for word in dictfile:
  73.                 counter += 1
  74.                 word = word.strip()
  75.                 hashed = htype(word).hexdigest()
  76.                 if hashed == input_hash:
  77.                     print "Hash cracked, at attempt {0}. hashed word is: '{1}' ".format(counter, word)
  78.                     dictfile.close()
  79.                     sys.exit()
  80.                 else:
  81.                     print "Attempting password '{0}', Attemp No. {1}".format(word, counter)
  82.         else:
  83.             for word in dictfile:
  84.                 counter += 1
  85.                 word = word.strip()
  86.                 hashed = htype(word.strip()).hexdigest()
  87.                 if hashed == input_hash:
  88.                     print "Hash cracked, at attempt {0}. hashed word is: '{1}' ".format(counter, word)
  89.                     dictfile.close()
  90.                     sys.exit()
  91.     except KeyboardInterrupt:
  92.         print "User Exit"
  93.         sys.exit()
  94.    
  95.  
  96.  
  97. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement