暴力字典密码破解之crypt

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HIVAN1/article/details/82596181

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

猜你喜欢

转载自blog.csdn.net/HIVAN1/article/details/82596181