admin管理员组文章数量:1574959
使用crypt加密密码的暴力破解
在本文中,我们假设已经获取到用户密码的密文,从密文格式知道密码是通过crypt算法加密。下面我们尝试通过字典中的单词进行破解。
准备工作
先准备好我们获取到的密文文件。假设文件名为passwords.txt,文件内容如下:
victim: HX9LLTdc/jiDE: 503:100:Iama Victim:/home/victim:/bin/sh
root: DFNFxgW7C05fo: 504:100: Markus Hess:/root:/bin/bash
另外准备我们的字典文件。假设文件名为dictionary.txt,作为演示,假设字典中只有三个单词,如下所示:
get
apple
egg
实际可以在网上下载字典文件,包含字典中所有的单词。
总体思想
crypt算法是一种加密算法,在获取到密文到条件下,我们将字典中的单词作为明文使用crypt算法加密,将加密得到的密文和我们获取到的密文对比,如果一致,则密码得到破解。
python中已有自带到crypt库。要计算一个明文的密文,只需调用crypt.crypt(),并将明文和salt作为参数传递给它。
代码示例
使用python实现密码暴力破解的简单示例代码如下:
以下代码使用python2.*运行。
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.\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)
if __name__ == "__main__":
main()
版权声明:本文标题:暴力字典密码破解之crypt 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1727779710a1129190.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论