因此,問題在於,我們的安全教師創建了一個需要認證的站點,然後請求代碼(4個字符),以便您可以訪問文件。他告訴我們用Python(我們想要的任何庫)編寫一個可以找到密碼的暴力程序。所以要做到這一點,我首先要製作一個程序,可以在該代碼字段上嘗試隨機組合,以便了解每個請求的時間(我正在使用請求庫),結果是讓每個請求失去意願需要大約8秒。 通過一些計算:4^36 = 13 436 928可能的組合,將使我的節目在155.52天左右。 如果有人能幫助我更快地做到這一點,那我真的很感激。 (他告訴我們,有可能使周圍每秒1200個組合)python中的緩慢蠻力程序
這裏是我的代碼:
import requests
import time
import random
def gen():
alphabet = "abcdefghijklmnopqrstuvwxyz"
pw_length = 4
mypw = ""
for i in range(pw_length):
next_index = random.randrange(len(alphabet))
mypw = mypw + alphabet[next_index]
return mypw
t0 = time.clock()
t1 = time.time()
cookie = {'ig': 'b0b5294376ef12a219147211fc33d7bb'}
for i in range(0,5):
t2 = time.clock()
t3 = time.time()
values = {'RECALL':gen()}
r = requests.post('http://www.example.com/verif.php', stream=True, cookies=cookie, data=values)
print("##################################")
print("cpu time for req ",i,":", time.clock()-t2)
print("wall time for req ",i,":", time.time()-t3)
print("##################################")
print("##################################")
print("Total cpu time:", time.clock()-t0)
print("Total wall time:", time.time()-t1)
謝謝
當您使用['Session()'對象](http://docs.python-requests.org/en/latest/user/advanced/#session-objects)和從而讓'請求'重新使用TCP連接? –
並且不要使用隨機密碼;使用'itertools.product(alphabet,repeat = 4)'生成所有組合(使用'''.join(combo)'將4個字符重新連接成一個字符串)。 –
謝謝,我將修改該密碼生成方法。你能解釋一點嗎? –