无法让crypt正常工作

时间:2013-02-02 18:26:36

标签: python crypt

我只是在弄乱我是否可以使用'crypt'模块而且我似乎遇到了一个我无法解决的问题。运行之后的输出是:

Password Not Found. secret HXXxJi0n6Huro HXXxJi0n6Huro

这意味着cryptWord和cryptPass是相同的,为什么程序不执行(if cryptWord == cryptPass:)和print 'Found Password:

我根本没有得到它。

dictionary.txt文件中有多次单词secret,都在不同的行上。而evil.txt文件有这一行:

test_user:HXXxJi0n6Huro

据我所知,一切正常吗?但有些东西正在从正常工作中恢复过来,我无法弄明白。任何帮助将不胜感激。

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()

1 个答案:

答案 0 :(得分:6)

您的crypPass值仍然附加了换行符。剥离它:

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