我一直在闲暇时间学习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密码破解"或者帮助我修改我的代码以适应。
P.S。我最初的计划是使用opencl或cuda ...但我很快就知道了我的深度!
答案 0 :(得分: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了解更多信息。
我希望这可以帮助您,或者至少可以让您更好地了解多处理过程!