Python多处理密码破解程序 [英] Python Multiprocessing password cracker

查看:397
本文介绍了Python多处理密码破解程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在业余时间学习Python了很短的时间,我为构建非常具体的任务创建密码破解程序面临挑战,这是测试我的ADSL Router的安全性如何(不太好)-使用Wireshark,我可以很清楚地看到它是如何通过http对密码进行哈希处理的,并开发了一些代码来执行单词列表攻击. (如果您认为我的代码写得不好,我深感抱歉-您可能是正确的!).

I have been learning Python in my spare time for a small amount of time now and I set myself a challenge to build a password cracker for a very specific task, it was to test how effective the security on my ADSL Router was (not very) - using Wireshark I could quite clearly see how it was hashing the password over http and I developed some code to perform a wordlist attack. (I apologise if you think my code is badly written - you would probably be correct!).

#!/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()

这很好用,但是让我想要更多,所以我想我可以在其中添加一些多处理功能以加快处理速度-使用各种不同的指令和指南,我未能以成功的结果告终! (尽管感觉我很亲近)

This works well enough but has left me wanting more, so I thought I could add some Multiprocessing power to it to speed things up - using various different instructions and guides I have failed to end up with a successful result! (although feeling like i was very close)

请有人将我指向多核python密码破解的白痴指南",或帮助我修改代码以适合自己.

Please could someone either point me towards "An idiots guide to multicore python password cracking" or help my modify my code to suit.

P.S.我最初的计划是使用opencl或cuda ...但是我很快就了解了自己的深度!

P.S. my original plan was to use opencl or cuda...but I quickly learned how out of my depth I was!

推荐答案

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

I have made an example for you that should be relatively easy to add into your code. Here is how it works; First, we need to brake up the wordlist into manageable chunks that we can throw into the multiprocessor module. I do this by making a list with a dictionary of 'starting' and 'stopping' points. Next, I pass those arguments into apply_async which will in turn run the pwd_find function. This is the function you want to add your for word in wordlist: loop, but with a starting and stopping point (see code below).

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以终止处理器.

If your code finds a match, add p.terminate followed by p.join to kill the processors.

如果您想进一步了解多处理器模块,请

If you would like to lean more about the multiprocessor module, go here to learn more.

我希望这可以帮助您,或者至少可以使您对多处理有更好的了解!

I hope this helps you out, or at the very least, gives you a better insight into multiprocessing!

这篇关于Python多处理密码破解程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆