是否有可能发现一个网站的所有 url 路由? [除了暴力破解]
如果没有暴力破解(或 URL 模糊测试)是不可能的,但您的用户可以共享链接,所以...
我看到了两种方法:
1.如果用户通过身份验证
如果用户通过了身份验证,那么解决方案就很简单了。将已解决的谜题 ID 保存在数据库中。如果用户想查看解决方案,请检查数据库以查看用户是否已解决难题并提供响应。
2。如果用户未通过身份验证
您可以使用某种加密签名的令牌。当用户解决难题时,您将向他们发送一个签名令牌,这意味着 “此用户已解决此难题”。稍后,当用户想要查看解决方案时,他们需要发送令牌才能查看。
见Django's Cryptographic signing docs。
import time
from django.core.signing import Signer
signer = Signer()
token = signer.sign_object({
'solution_id': <solution-id>, # could be the name of the html file
'expire_at': time.time() + 900 # token expiry time (15 minutes from now)
})
print(token) # -> 'eyJtZXNzYWdlIjoiSGVsbG8hIn0:Xdc-mOFDjs22KsQAqfVfi8PQSPdo3ckWJxPWwQOFhR4'
# Send the token to the client
稍后如果用户想要查看/solution.html,他们需要在 url 中发送令牌。
/solution.html?token=<token value>
在您看来,您可以像这样检查令牌:
token = request.GET.get('token')
if not token:
# return HTTP 403 Permission Denied
try:
data = signer.unsign(token)
except signing.BadSignature:
# invalid signature
# return HTTP 403 Permission Denied
# check if token expired
if data['expire_at'] > time.time():
# return HTTP 403
# check if token's solution_id matches the requested solution
# ...
# return the response
这种方法的缺点是即使用户解决了一个难题,他们也只能在令牌过期之前查看解决方案。