Not much for practical use. I am learning python from book 'Violent Python'. This is exercise 1 a little bit more flexible solution then asked. Maybe someone will find it usefull.
#/etc/shadow
#hash dictionary attack
import crypt
def testPass(hashType, salt, hash, saltedHash):
print "With salt: $",salt
dictFile = open('dictionary.txt','r')
for word in dictFile.readlines():
word = word.strip('\n')
saltFor = '$' + hashType + '$' + salt
cryptWord = crypt.crypt(word,saltFor)
if (cryptWord == saltedHash):
print "[+]Found Password: "+word+"\n"
return
print "[-] Password Not Found.\n"
return
def main():
shadowFile = open('shadow')
for line in shadowFile.readlines():
if ":" in line:
user = line.split(':')[0]
saltedHash = line.split(':')[1]
hashType = saltedHash.split('$')[1]
salt = saltedHash.split('$')[2]
hash = saltedHash.split('$')[3]
print 'dict attack on user: ', user
testPass(hashType, salt, hash, saltedHash)
if __name__ == "__main__":
main()