【问题标题】:Python Multiprocessing password crackerPython多处理密码破解器
【发布时间】:2016-02-01 02:10:14
【问题描述】:

我已经在业余时间学习 Python 了一小段时间,我给自己设定了一个挑战,为一项非常具体的任务构建密码破解程序,它是测试我的 ADSL 路由器的安全性有多有效(不是很) - 使用 Wireshark 我可以很清楚地看到它是如何通过 http 散列密码的,我开发了一些代码来执行 wordlist 攻击。 (如果您认为我的代码写得不好,我深表歉意——您可能是对的!)。

#!/usr/bin/env python

import hashlib, os, time, math
from hashlib import md5

def screen_clear():
    if os.name == 'nt':
        return os.system('cls')
    else:
        return os.system('clear')

screen_clear()

print ""
print "Welcome to the Technicolor md5 cracker"
print ""

user = raw_input("Username: ")
print ""
nonce = raw_input("Nonce: ")
print ""
hash = raw_input("Hash: ")
print ""
file = raw_input("Wordlist: ")
print ""

realm = "Technicolor Gateway"
qop = "auth"
uri = "/login.lp"

HA2 = md5("GET" + ":" + uri).hexdigest()

wordlist = open(file, 'r')

time1 = time.time()

for word in wordlist:
    pwd = word.replace("\n","") 
    HA1 = md5(user + ":" + realm + ":" + pwd).hexdigest()
    hidepw = md5(HA1 + ":" + nonce +":" + "00000001" + ":" + "xyz" + ":" + qop + ":" + HA2).hexdigest()
    if hidepw == hash:
        screen_clear()
        time2 = time.time()
        timetotal = math.ceil(time2 - time1)
        print pwd + " = " + hidepw + " (in " + str(timetotal) + " seconds)"
        print ""
        end = raw_input("hit enter to exit")
        exit()

wordlist.close()

screen_clear()
time2 = time.time()
totaltime = math.ceil(time2 - time1)
print "Sorry, out of " + str(tested) + " passwords tested, your password was not found (in " + str(totaltime) + " seconds)"
print ""
end = raw_input("hit enter to exit")
screen_clear()
exit()

这很好用,但让我想要更多,所以我想我可以为其添加一些多处理功能以加快速度 - 使用各种不同的说明和指南,我未能最终获得成功的结果! (虽然感觉我很亲近)

请有人将我指向“多核 python 密码破解的白痴指南”或帮助我修改我的代码以适应。

附:我最初的计划是使用 opencl 或 cuda ......但我很快就知道我是多么的超出我的深度!

【问题讨论】:

    标签: python multithreading passwords multicore cracking


    【解决方案1】:

    我为您制作了一个示例,应该相对容易添加到您的代码中。下面是它的工作原理;首先,我们需要将wordlist 分解为可管理的块,我们可以将它们放入多处理器模块中。我通过列出一个包含“开始”和“结束”点的字典来做到这一点。接下来,我将这些参数传递给apply_async,后者将依次运行pwd_find 函数。这是您要添加 for word in wordlist: 循环的函数,但有一个起点和终点(参见下面的代码)。

    from multiprocessing import Pool
    import math
    import time
    
    cores = 4  # Number of cores to use
    wordlist = []
    
    for i in range(127):  # Remove this for your own word list.
        wordlist.append(str(i))  # Creates a large 'word' list for testing.
    
    def pwd_find(start, stop):
    
        for word in range(start, stop):
            print(wordlist[word])
            time.sleep(0.1)  # Slows things down so it's easier to see that your system is using more than one core.
            ### Add your code here... ###
    
    
    break_points = []  # List that will have start and stopping points
    for i in range(cores):  # Creates start and stopping points based on length of word list
        break_points.append({"start":math.ceil(len(wordlist)/cores * i), "stop":math.ceil(len(wordlist)/cores * (i + 1))})
    
    if __name__ == '__main__':  # Added this because the multiprocessor module acts funny without it.
    
        p = Pool(cores)  # Number of processors to utilize.
        for i in break_points:  # Cycles though the breakpoints list created above.
            print(i)  # shows the start and stop points.
            a = p.apply_async(pwd_find, kwds=i, args=tuple())  # This will start the separate processes.
        print("Done!")
        p.close()
        p.join()
    

    如果您的代码找到匹配项,请添加 p.terminate 后跟 p.join 以终止处理器。

    如果您想进一步了解多处理器模块,请go here 了解更多信息。

    我希望这可以帮助您,或者至少可以让您更好地了解多处理!

    【讨论】:

    • 非常感谢您的详细解答,由于工作原因我没有时间回家尝试这个,我一定会在我回来时告诉您我的成功!
    • 花了一个晚上让我的代码工作,现在它给了我一个正确的答案(现在将比较看看它有多快)!感谢您的帮助-您的解释足以让我仍然进行一些思考!一个问题是字典包含一个整数的浮点数(很容易解决),但我花了一段时间才弄清楚如何从 apply_async 进程( print (a.get()) )中输出任何错误 - 这一切都非常有趣,我当然学到了很多
    • 只是为了跟进这一点,在我的超线程双核笔记本电脑上运行整个“rockyou.txt”单词表所需的时间大约减少了一半!太棒了。
    • 嗨@Andy,你能发布整个代码吗?对学习很有用。或者一个github链接:)
    猜你喜欢
    • 1970-01-01
    • 2019-07-31
    • 2015-10-18
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多