Python-暴力破解UNIX密码脚本

# coding=UTF-8
"""
暴力破解UNIX的密码,需要输入字典文件和UNIX的密码文件
遍历整个字典,试图用常用的盐值来匹配破解哈希密码
"""
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 cryptPass == cryptWord:
            print('Found passed:', word)
            return
        print('Password not found!')
        return


def main():
    passfile = open('passwor', 'r')
    for line in passfile.readlines():
        user = line.split(':')[0]
        cryptPass = line.split(':')[1].strip(")
        print("Cracking password For:", user)
        testPass(cryptPass)

if __name__ == '__main__':
    main()

你可能感兴趣的:(web)