【发布时间】:2018-11-24 08:29:53
【问题描述】:
我试图从 etc/shadow 文件中猜测密码(它有 43 个用户/密码)。我得到了一些关于密码的提示:
- 长度介于 4 到 8 个字符之间
- 只能有 2 个数字,并且只能在末尾li>
- 开头只有大写字母
所以我从一个由 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')
如何提高效率?如果它有助于任何类型的 GPU 处理,我有一个 GTX 1070。
【问题讨论】:
-
如果您的代码可以正常工作,Code Review 可能是一个更好的询问地点。 Stack Overflow 在不工作的代码中社会化。
标签: python hash coding-efficiency