Unix口令破解器

只能用在Unix类系统上,windows上无法使用。
另外使用的是字典破解法,所以需要准备一个口令字典。
调用的是UNIX计算口令hash的crypt()算法。
当然注释中给出了SHA-512 hash算法的使用方法。

#coding=utf-8
#一个UNIX口令破解器

#crypt模块只用于UNIX
#方法是遍历字典,每一个单词加上指定的salt的计算结果与加密的口令hash做比较
#salt参数是用于增加被编码字符数目的字符串,以使编码更加安全。

#所以函数首先把加密的口令hash的前两个字符作为salt,提取出来
#然后计算字典中的每一个值的hash,与原来的hash做比较,从而破解出密码

#使用crypt模块的crypt()函数计算hash

import crypt
import hashlib

def testPass(cryptPass):
    '''验证hash是否一致'''
    #salt是前两个字符
    salt = cryptPass[0:2]
    dictFile = open("dictionary.txt",'r')
    for word in dictFile.readlines():
        word = word.strip('\n')
        cryptWord = crypt.crypt(word,salt)
        #使用hashlib的SHA-512 hash算法
        #cryptWord = hashlib.sha512(word).hexdigest()
        if (cryptWord == cryptPass):
            print "found password"+word+"\n"
            return
    print "password not found"
    return

def main():
    passFile = open("passwords.txt")
    for line in passFile.readlines():
        if ":" in line:
            user = line.split(':')[0]
            cryptPass = line.split(":")[1].strip(' ')
            print "Cracking Passwod for "+user
            testPass(cryptPass)

if __name__ == "__main__":
    main()

#Linux中在/etc/shadow中存储了口令的hash```



最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容