Guest User

HashCrack.py | Manual Dictionary Attack Using Python

a guest
Mar 14th, 2014
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. #! /usr/bin/env python
  2. # HashCrack.py
  3. # Author: Abdul Fatir
  4.  
  5. import hashlib
  6. import optparse
  7.  
  8. def crackMD5Hash(_file,_hash):
  9.     _wordlistfile = open(_file,"r")
  10.     cracked = False
  11.     for word in _wordlistfile:
  12.         _purgedword = word.strip()
  13.         md5 = hashlib.md5()
  14.         md5.update(_purgedword)
  15.         _wordhash = md5.hexdigest()
  16.         if _wordhash == _hash:
  17.            
  18.             print "[+] Hash ("+_hash+ ") cracked: "+_purgedword
  19.             cracked = True
  20.             break
  21.     if(not cracked):
  22.         print "[-] Unable to crack the hash."
  23.        
  24. def crackSHA1Hash(_file,_hash):
  25.     _wordlistfile = open(_file,"r")
  26.     cracked = False
  27.     for word in _wordlistfile:
  28.         _purgedword = word.strip()
  29.         sha1 = hashlib.sha1()
  30.         sha1.update(_purgedword)
  31.         _wordhash = sha1.hexdigest()
  32.         if _wordhash == _hash:
  33.             print "[+] Hash ("+_hash+ ") cracked: "+_purgedword
  34.             cracked = True
  35.             break
  36.     if(not cracked):
  37.         print "[-] Unable to crack the hash."
  38.  
  39.        
  40.        
  41. def Main():
  42.     argparser = optparse.OptionParser("usage %prog -f <wordlist file> -p <hash to be cracked> -a <hash algorithm>")
  43.     argparser.add_option('-f', dest='filename',type='string',help='Please specify a word list')
  44.     argparser.add_option('-p', dest='passhash',type='string',help='Please specify a password hash to be cracked')
  45.     argparser.add_option('-a', dest='hashalgo',type='string',help='Please specify a hash algorithm')
  46.     (options, arg) = argparser.parse_args()
  47.     if (options.filename == None) | (options.passhash == None) | (options.hashalgo == None):
  48.         print argparser.usage
  49.         exit(0)
  50.     else:
  51.         filename = options.filename
  52.         passhash = options.passhash
  53.         hashalgo = options.hashalgo
  54.     print "[*] Cracking hash ..."
  55.     if (hashalgo == 'MD5')|(hashalgo == 'md5'):
  56.         crackMD5Hash(filename,passhash)
  57.     elif (hashalgo == 'SHA1')|(hashalgo == 'sha1'):
  58.         crackSHA1Hash(filename,passhash)
  59.    
  60. if __name__ == '__main__':
  61.     Main()
Add Comment
Please, Sign In to add comment