Jku X5u
Jku X5u
Louis Nyffenegger
@PentesterLab
louis@pentesterlab.com
About me
Security Engineer
PentesterLab:
Platform to learn web security/penetration testing
100% Hands-on
PentesterLab.com / @PentesterLab
Who uses JWT?
PentesterLab.com / @PentesterLab
Crypto 101
Signature vs Encryption
PentesterLab.com / @PentesterLab
Multiple ways of signing
PentesterLab.com / @PentesterLab
Signing with a secret
Sign! Verify!
Secret
PentesterLab.com / @PentesterLab
Signing: asymmetric
Sign! Verify!
Public Private
PentesterLab.com / @PentesterLab
THE JWT FORMAT
JavaScript Object Notation (JSON)
PentesterLab.com / @PentesterLab
The Compact JWS Format
PentesterLab.com / @PentesterLab
The Compact JWS Format
Separated by a dot
Header
. Payload
. Signature
PentesterLab.com / @PentesterLab
The Compact JWS Format
Separated by a dot
eyJ = Base64('{"')
PentesterLab.com / @PentesterLab
The Compact JWS Format
Base64({…})
. Base64({…})
. Base64(…)
PentesterLab.com / @PentesterLab
The Compact JWS Format: Encoding
* https://tools.ietf.org/html/rfc7515#appendix-C
PentesterLab.com / @PentesterLab
The JWT Format: header
Base64({"alg": "HS256",
"typ": "JWS"}) . …
. …
PentesterLab.com / @PentesterLab
The JWT Format: Algorithms
PentesterLab.com / @PentesterLab
The JWT Format: payload
…
. Base64({"user":"admin",
"roles": ["adm","users"]}) . …
PentesterLab.com / @PentesterLab
The JWT Format: payload
…
. Base64({"user":"admin",
"exp":12…, "iat":1234.. }) . …
PentesterLab.com / @PentesterLab
The JWT Format: creating a token
PentesterLab.com / @PentesterLab
Classic JWT attacks
• None algorithm
• Trivial secret
• Algorithm confusion
• Injection in the kid parameter
• CVE-2018-0114
•
PentesterLab.com / @PentesterLab
jku & x5u
jku and x5u
PentesterLab.com / @PentesterLab
The JWT Format: jku&x5u
Base64({"jku": "https://...",
...}) . …
. …
Base64({"x5u": "https://...",
...}) . …
. …
PentesterLab.com / @PentesterLab
The JWT Format: jwk
{
"keys": [
{
"kty": "RSA",
"use": "sig",
"kid": "pentesterlab",
"n": "oTtAXRgdJ6Pu0jr3hK3opCF5uqKWKbm4Kkq...vTF0FGw",
"e": "AQAB",
"alg": "RS256"
}
]
}
PentesterLab.com / @PentesterLab
The JWT Format: x5c
{
"keys": [
{
"kty": "RSA",
"use": "sig",
"kid": "pentesterlab",
"x5c": "MIIDWDCCAkACCQCnE....fpye27SQbC2fBxebsek=",
"alg": "RS256"
}
]
}
PentesterLab.com / @PentesterLab
jku and x5u
User Application
Trusted
Server
PentesterLab.com / @PentesterLab
jku and x5u
User Application
Trusted
Server
PentesterLab.com / @PentesterLab
jku and x5u
1 HTTP Request with JWT 2 Parsing of the JWT to extract the “jku” header
User Application
Trusted
Server
PentesterLab.com / @PentesterLab
jku and x5u
1 HTTP Request with JWT 2 Parsing of the JWT to extract the “jku” header
User Application
Trusted
Server
PentesterLab.com / @PentesterLab
jku and x5u
1 HTTP Request with JWT 2 Parsing of the JWT to extract the “jku” header
Trusted
Server
PentesterLab.com / @PentesterLab
jku and x5u
1 HTTP Request with JWT 2 Parsing of the JWT to extract the “jku” header
Trusted
Server
PentesterLab.com / @PentesterLab
jku and x5u
1 HTTP Request with JWT 2 Parsing of the JWT to extract the “jku” header
Trusted
Server
PentesterLab.com / @PentesterLab
jku and x5u
1 HTTP Request with malicious JWT 2 Parsing of the JWT to extract the “jku” header
Malicious
Server
PentesterLab.com / @PentesterLab
jku and x5u
1 HTTP Request with malicious JWT 2 Parsing of the JWT to extract the “jku” header
Attacker
Application
Malicious
Server
PentesterLab.com / @PentesterLab
jku and x5u
PentesterLab.com / @PentesterLab
jku and x5u : regular expression
PentesterLab.com / @PentesterLab
jku and x5u : starts with
PentesterLab.com / @PentesterLab
jku and Open Redirect
Trusted
Malicious
Server
Server
PentesterLab.com / @PentesterLab
jku and Open Redirect
Trusted
Malicious
Server
Server
Open Redirect
PentesterLab.com / @PentesterLab
jku and Open Redirect
Trusted
Malicious
Server
Server
Open Redirect
PentesterLab.com / @PentesterLab
jku and Open Redirect
PentesterLab.com / @PentesterLab
jku and Open Redirect
PentesterLab.com / @PentesterLab
jku and Open Redirect
PentesterLab.com / @PentesterLab
jku and Header Injection
Trusted
Server
PentesterLab.com / @PentesterLab
jku and Header Injection
Trusted
Server
Header Injection
PentesterLab.com / @PentesterLab
jku and Header Injection
PentesterLab.com / @PentesterLab
jku and Header Injection
PentesterLab.com / @PentesterLab
jku and Header Injection
PentesterLab.com / @PentesterLab
Libraries: jku header injection - Exploitation
Exploitation:
• Find a Header Injection
• Use the Header Injection to return
your JWK
• Add the Header Injection as jku
• Sign the token with your RSA key
PentesterLab.com / @PentesterLab
jku and x5u: downgrade
PentesterLab.com / @PentesterLab
Conclusion
Recommendations
PentesterLab.com / @PentesterLab
Recommendations
✓ Read RFC
PentesterLab.com / @PentesterLab
THANKS
FOR YOUR TIME !
Any questions?