[英]Make password/hash verification algorithm more efficient
我試圖從etc / shadow文件(它有43個用戶/密碼)中猜測密碼。 並給了我一些有關密碼的提示:
因此,我只是從一個由4個字符和2個數字組成的小組開始。 但是要花很多時間來處理:
import crypt
import string
import itertools
import datetime
dir = "shadow3"
file = open(dir, 'r').readlines() #Read all the 43 hashes
username = []
hashed = []
c = 0
cc = 0
for x in file: #Split the hash and the username
usr, hshd, wtf, iss, this, thing, here, doing, example = x.split(':')
username.append(usr)
hashed.append(hshd)
#GRUPO1 4 caracteres 2 numeros
letters = string.ascii_lowercase
digits = string.digits
grupo1=[]
group1=itertools.product(letters,repeat=2)
group1b=itertools.product(digits,repeat=2)
for x in itertools.product(group1,group1b): #Join the possible iterations
string=''.join([''.join(k) for k in x])
grupo1.append(string)
print(len(grupo1))
for y in grupo1:#Get the one of the iterations and try it
prueba=y
for x in hashed: #Verify if that iteration is the password to any of the 43 users
rehashed = crypt.crypt(prueba, x)
if rehashed == x: #Password is found
print('La contraseña del usuario ' + username[c] + ' es ' + prueba)
cc = 1
c = c + 1
if cc == 0: #after all iterations password is not found
print('Lo sentimos "' + prueba + '" no es la contraseña de ningun usuario')
如何提高效率? 我有一個GTX 1070,它可以幫助進行任何類型的GPU處理。
我相信您的代碼有錯誤。 您的問題可以重新建模,這樣可以更快:
根據您的條件生成所有可能的密碼組合-長度在4到8個字符之間-只能有2個數字,並且只能在末尾-大寫字母只能在開頭
在每個組合上生成crypt()
比較密碼與加密值。
幸運的是,Python附帶了一個探查器,以幫助解決此類問題。 查看cProfile文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.