Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/utils/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def crackHMAC(token, secrets, limit=None):
's3cr3t'
>>> crackHMAC(token, ["admin", "letmein"]) is None
True
>>> crackHMAC("eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiYWRtaW4ifQ.x", ["secret"]) is None
True
"""

data = parseJWT(token)
Expand All @@ -97,7 +99,13 @@ def crackHMAC(token, secrets, limit=None):

fn = HMAC_ALGORITHMS[data["header"]["alg"].upper()]
signingInput = getBytes(data["signingInput"])
target = decodeBase64(data["signature"], binary=True)

try:
target = decodeBase64(data["signature"], binary=True)
except Exception:
# a signature segment that is not valid base64url (e.g. a truncated/malformed token that still
# matches the JWT pattern) cannot be an HMAC we could verify, so it is simply not crackable
return None

for index, secret in enumerate(secrets):
if limit is not None and index >= limit:
Expand Down