Search code examples
pythoncrypt

Can't get crypt to work correctly


I was just messing around seeing if I could use the 'crypt' module and I've seem to run into a problem that I can't for the life of me figure out. The output after I run this is this:

Password Not Found. secret HXXxJi0n6Huro HXXxJi0n6Huro

Which means that cryptWord and cryptPass are the same, so why isn't the program doing the (if cryptWord == cryptPass:), and print 'Found Password:

I just don't at all get it.

The dictionary.txt file just has the word secret in it multiple times, all on separate lines. And the evil.txt file has this line it:

test_user:HXXxJi0n6Huro

From what I can tell everything is working correctly? But something is holding this back from working right and I just can't figure it out. Any help would be appreciated.

import crypt

def testPass(cryptPass):

        salt = cryptPass[0:2]
        dictFile = open('dictionary.txt', 'r')
        for word in dictFile.readlines():
            word = word.strip('\n')
            cryptWord = crypt.crypt(word, salt)
            if cryptWord == cryptPass:
                print "[+] Found Password: "+word+"\n"
                return
        print "[-] Password Not Found. " +word,  cryptWord,  cryptPass+  "\n"
        return


def main():

    passFile= open('evil.txt')
    for line in passFile.readlines():
        if ":" in line:
            user = line.split(':')[0]
            cryptPass = line.split(':')[1]
            print "[*] Cracking Password For: "+user
            testPass(cryptPass)
if __name__ == '__main__':

        main()

Solution

  • Your crypPass value still has a newline attached to it. Strip it first:

    user, cryptPass = line.split(':')
    cryptPass = cryptPass.strip()