使用linux中计算口令hash的crypt()算法
这是crypt模块的查看
#coding=utf-8
import crypt
def testPass(cryptPass):
salt= cryptPass[0:2] #用参数形式来获取加密的口令Hash
dictFile = open('dictionary',r)
for word in dictFile.readlines(): #迭代对象
word = word.strip('\n')
cryptWord = crypt.crypt(word,salt)
if (cryptWord == cryptPass):
print "[+] Found Password: "+word+"\n"
return
else:
print "[-] Password not Found.\n"
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 Password For:"+user
testPass(cryptPass) #对每个口令都hash
if __name__ == "__main__":
main()
在main函数中打开密文文件,逐行读取,用户和口令都是隔开的,对每个口令进行hash,尝试用字典中的单词破解它。如果hash值与加密口令的hash值相同,则返回找到密码,否则一直进行下去,直到最后为止。