Greg Hewgill 的第一点值得强调。我刚刚发现——有点令我惊讶——在我的笔记本上,系统 hashlib.py 对世界开放。因此,击败上述身份验证是微不足道的:
localhost-2:coding $ cat hashcrack.py
class always_equal(object):
def __eq__(self, other):
return True
class sha512(object):
def __init__(self, password):
pass
def hexdigest(self):
return always_equal()
localhost-2:coding $ cat hashcrack.py >> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py
localhost-2:coding $ cat notsosecure.py
import hashlib
theInput = raw_input("Enter password: ")
theHashed = hashlib.sha512(theInput).hexdigest()
if theHashed == "35211b890b19afebfabc3451f04d150f1423bcb54ff7d62095677d7af7560fcvb56c112e879288836cb506853516c5dbd1d779cfaedf4a2f6f6a303600c0c589":
print "Correct!"
localhost-2:coding $ python notsosecure.py
Enter password: pwned
Correct!
想想看,我什至不需要创建一个新的 sha512 类,我可以简单地在旧的类中添加 monkeypatched hexdigest。
无论如何,+1 表示主要的安全隐患不是哈希中的位数。