SlideShare a Scribd company logo
1 of 55
Download to read offline
JWT == insecurity?
A journey in the insecurity of 

JSON web tokensโ€ฆ
by Louis Ny๏ฌ€enegger
@PentesterLab
louis@pentesterlab.com
Introduction01
Agenda
The JWT format (simpli๏ฌed)02
By Design03
Libraries04
Using Libraries05
Conclusion06
PentesterLab.com / @PentesterLab
About Me
PentesterLab.com / @PentesterLab
Security Engineer:
PentesterLab:
Pentester/Code Reviewer/Security consultant/Security architect
Platform to learn web security/penetration testing
100% Hands-on
Available for individuals (free and PRO) and enterprises
Run a website to help people learn security
JOSE/JWE/JWS/JWT
PentesterLab.com / @PentesterLab
โ€ข JOSE:
โ€ข Javascript Object Signing and Encryption
โ€ข Also the name of the working group
โ€ข JWT: JSON Web Token == โ€œjotโ€ Token
โ€ข JWE: JSON Web Encryption
โ€ข JWS: JSON Web Signature
โ€ข JWK: JSON Web Key
โ€ข JWA: JSON Web Algorithm
Who uses JWT
PentesterLab.com / @PentesterLab
โ€ข A lot of people for OAuth
โ€ข A lot of people for sessions
โ€ข A lot of people to manage trust
โ€ข A lot of people for password reset
โ€ข A lot of people who care about being stateless
and multi-datacenter architecture
THE JWT FORMAT
JavaScript Object Notation (JSON)
PentesterLab.com / @PentesterLab
Human readable format to store or transmit objects
The Compact JWS Format
PentesterLab.com / @PentesterLab
Header Payload Signature
3 parts in a JSON Web Token:
The Compact JWS Format
PentesterLab.com / @PentesterLab
Header Payload Signature
Separated by a dot
. .
The Compact JWS Format
PentesterLab.com / @PentesterLab
eyJ0eXAiOiJK
V1QiLCJhbGci
OiJIUzI1NiJ9
eyJsb2dpbi
I6ImFkb
WluIn0
FSfvCBAwypJ4abF6
jFLmR7JgZhkW674
Z8dIdAIRyt1E
Separated by a dot
. .
eyJ = Base64('{"')
The Compact JWS Format
PentesterLab.com / @PentesterLab
Base64({โ€ฆ}) Base64({โ€ฆ}) Base64(โ€ฆ)
Header and Payload are base64* encoded JSON
. .
* urlsafe base64 encoding without padding
The signature is also base64 encoded
The Compact JWS Format: Encoding
PentesterLab.com / @PentesterLab
Urlsafe base64 encoding without padding:
*https://tools.ietf.org/html/rfc7515#appendix-C
The JWT Format: header
PentesterLab.com / @PentesterLab
Base64({"alg": "HS256",
"typ": "JWS"})
The header contains an algorithm โ€œalgโ€ attribute:
In this example HMAC with SHA256 was used
To tell how the token was signed.
โ€ฆ
. . โ€ฆ
The JWT Format: Algorithms
PentesterLab.com / @PentesterLab
A lot of different algorithms are supported*:
None
* https://jwt.io/ covers most
HS256
HS384
HS512
RS256
RS384
RS512
ES256
ES384
ES512
PS256
PS384
PS512
The JWT Format: Algorithms
PentesterLab.com / @PentesterLab
Scenario: one client talking to multiple services
The JWT Format: Algorithms
PentesterLab.com / @PentesterLab
HS256
HS384
HS512
HMAC: All services need to know the secret
The JWT Format: Algorithms
PentesterLab.com / @PentesterLab
HS256
HS384
HS512
HMAC: if one service gets compromised
The JWT Format: Algorithms
PentesterLab.com / @PentesterLab
HS256
HS384
HS512
HMAC: the secret is compromised for all services
The JWT Format: Asymmetric
PentesterLab.com / @PentesterLab
RS256
RS384
RS512
ES256
ES384
ES512
PS256
PS384
PS512
Asymmetric: sharing the key
Private
Public
The JWT Format: Asymmetric
PentesterLab.com / @PentesterLab
RS256
RS384
RS512
ES256
ES384
ES512
PS256
PS384
PS512
Asymmetric: Only trusted services get the
private key
Private
Public
The JWT Format: Asymmetric
PentesterLab.com / @PentesterLab
RS256
RS384
RS512
ES256
ES384
ES512
PS256
PS384
PS512
Asymmetric: If one service gets compromisedโ€ฆ
Private
Public
The JWT Format: Asymmetric
PentesterLab.com / @PentesterLab
RS256
RS384
RS512
ES256
ES384
ES512
PS256
PS384
PS512
Asymmetric: Even in the browser!
Private
Public
The JWT Format: payload
PentesterLab.com / @PentesterLab
โ€ฆ
The payload may contain literally anything:
Base64({"user":"admin",
"roles": ["adm","users"]}). . โ€ฆ
The JWT Format: payload
PentesterLab.com / @PentesterLab
The payload may contain registered claims:
Base64({"user":"admin",
"exp":12โ€ฆ, "iat":1234.. }). .โ€ฆ โ€ฆ
The JWT Format: payload
PentesterLab.com / @PentesterLab
The payload may contain registered claims:
โ€ข โ€œissโ€: issuer
โ€ข โ€œsubโ€: subject
โ€ข โ€œaudโ€: audience
โ€ข โ€œjtiโ€: claim id
โ€ข โ€œexpโ€: expiration time
โ€ข โ€œnbfโ€: not before
โ€ข โ€œiatโ€: issued at*
* useful for async processing
The JWT Format: creating a token
PentesterLab.com / @PentesterLab
โ€ข Create the JSON header and base64 encode it
โ€ข Create the JSON payload and base64 encode it
โ€ข Concatenate with a dot the (encoded) header
and payload
โ€ข Sign the result (header+.+payload)
โ€ข Base64 encode the signature
โ€ข Append a dot then the signature
The JWT Format: verifying a token
PentesterLab.com / @PentesterLab
โ€ข Split the token in three parts based on the dots
โ€ข Base64 decode each part
โ€ข Parse the JSON for the header and payload
โ€ข Retrieve the algorithm from the header
โ€ข Verify the signature based on the algorithm
โ€ข Verify the claims
Keep in mind
PentesterLab.com / @PentesterLab
โ€ข Multiple systems can issue tokens
โ€ข A token can be used by multiple systems
โ€ข All these systems can use different libraries
By Design
By design: verifying signature
PentesterLab.com / @PentesterLab
Base64({ "alg": "HS256",
"typ": "JWS"})
You need to base64 decode and parse
JSON to verify the signature:
Larger attack surface
JSON.load vs JSON.parse, Base64 decoding
โ€ฆ
. . โ€ฆ
By design: verifying signature
PentesterLab.com / @PentesterLab
The attacker controls the algorithm used:
Downgrade attacks, confusion attack
Base64({ "alg": "HS256",
"typ": "JWS"})
โ€ฆ
. . โ€ฆ
By design: Confusion attack
PentesterLab.com / @PentesterLab
Exploitation:
โ€ข Get a token signed with RSA (you only have
access to the public key)
โ€ข Decode the header and change the algorithm
from RSA โ€œRS256โ€ to HMAC โ€œHS256โ€
โ€ข Tamper with the payload
โ€ข Sign the token with the public RSA key
โ€ข Pro๏ฌt
By design: verifying signature
PentesterLab.com / @PentesterLab
โ€ฆ
Claims are optionals and not always supported*:
Always-valid tokens?
Base64({"user":"admin",
"exp":12โ€ฆ, "iat":1234.. }). . โ€ฆ
* Check https://jwt.io/
By design: verifying signature
PentesterLab.com / @PentesterLab
Claims are optionals
and not always
supported*
Always-valid tokens?
* Check https://jwt.io/
By design: verifying signature
PentesterLab.com / @PentesterLab
Signed data: you cannot (easily) manage quick-
revocation*:
The claim โ€œjtiโ€ and a cache can be used to limit
the impact of this
No quick-revocation! Replay
* Unless you rotate the key or manage a server-side cache
By design: The None algorithm
PentesterLab.com / @PentesterLab
JWT RFC contains a None algorithm
No integrity!
Basically an unsigned tokenโ€ฆ
By design: The None algorithm
PentesterLab.com / @PentesterLab
Exploitation:
โ€ข Get a token
โ€ข Decode the header and change the algorithm to
โ€œNoneโ€ or โ€œnoneโ€
โ€ข Decode and tamper with the payload
โ€ข Keep or remove the signature
โ€ข Pro๏ฌt
Libraries
Libraries: CVE-2018-0114
PentesterLab.com / @PentesterLab
JWS allows you to add a โ€œjwkโ€ attribute (JSON Web
Key) to the header to tell the receiver what key was
used to sign the token:
Libraries: CVE-2018-0114
PentesterLab.com / @PentesterLab
โ€ข Vulnerability in Cisco Node Jose
โ€ข Node-Jose uses the embedded โ€œjwkโ€ key to check
the signature
Integrity bypass!
Libraries: CVE-2018-0114 - Exploitation
PentesterLab.com / @PentesterLab
Exploitation:
โ€ข Get a token
โ€ข Decode and tamper with the payload
โ€ข Generate a RSA key
โ€ข Add โ€œn" & โ€œeโ€ to the header and use
RS256
โ€ข Sign the token with your RSA key
Libraries: Go-JOSE version <= 1.0.5
PentesterLab.com / @PentesterLab
Non-compact/full format for JWS:
Libraries: Go-JOSE version <= 1.0.5
PentesterLab.com / @PentesterLab
From: https://rwc.iacr.org/2017/Slides/nguyen.quan.pdf
The issue:
Libraries: Go-JOSE version <= 1.0.5
PentesterLab.com / @PentesterLab
From: https://rwc.iacr.org/2017/Slides/nguyen.quan.pdf
The issue:
Integrity of the protected bypass!
Libraries: Go-JOSE version <= 1.0.5
PentesterLab.com / @PentesterLab
If the application trusts the protected*:
* you cannot change the payload
Libraries: Go-JOSE version <= 1.0.5 - Exploitation
PentesterLab.com / @PentesterLab
Exploitation:
โ€ข Get a token (compact or full)
โ€ข Modify it to use the full format
โ€ข Add your malicious protected
โ€ข Pro๏ฌt
Using libraries
Using Libraries: weak secret
PentesterLab.com / @PentesterLab
Some developers use weak secrets.
Reminder: you only need one token to brute force
the secret (completely of๏ฌ‚ine)
Integrity bypass!
Using Libraries: decode vs verify
PentesterLab.com / @PentesterLab
A lot of libraries have two functions/methods:
โ€ข decode <- donโ€™t use this one
โ€ข verify
Integrity bypass!
Using Libraries: decode vs verify
PentesterLab.com / @PentesterLab
Exploitation:
โ€ข Get a token
โ€ข Decode and tamper with the header or payload
โ€ข Pro๏ฌt
Using Libraries: not using exp or iat
PentesterLab.com / @PentesterLab
In many libraries you need to opt-in to use โ€œexpโ€ or
โ€œiatโ€
Always-valid tokens?
Conclusion
Recommendations
PentesterLab.com / @PentesterLab
โœ“ Use strong keys and secrets
โœ“ Review the libraries you pick (KISS library)
โœ“ Make sure you check the signature
โœ“ Make sure your tokens expire
โœ“ Enforce the algorithm
Conclusion
PentesterLab.com / @PentesterLab
โ€ข JWT are complex and kind of insecure by design
โ€ข JWT libraries introduce very interesting bugs
โ€ข Make sure you test for those if you pentest or do
bug bounties
Any questions?
FOR YOUR TIME
THANKS!
louis@pentesterlab.com / PentesterLab.com / @PentesterLab

More Related Content

What's hot

What's hot (20)

OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologiesOWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
ย 
Cross Origin Resource Sharing
Cross Origin Resource SharingCross Origin Resource Sharing
Cross Origin Resource Sharing
ย 
CEHv9 : module 15 - hacking mobile platforms
CEHv9 : module 15 - hacking mobile platformsCEHv9 : module 15 - hacking mobile platforms
CEHv9 : module 15 - hacking mobile platforms
ย 
Insecure Java Deserialization
Insecure Java DeserializationInsecure Java Deserialization
Insecure Java Deserialization
ย 
Ekoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's MethodologyEkoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's Methodology
ย 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
ย 
(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage
ย 
Draft: building secure applications with keycloak (oidc/jwt)
Draft: building secure applications with keycloak (oidc/jwt)Draft: building secure applications with keycloak (oidc/jwt)
Draft: building secure applications with keycloak (oidc/jwt)
ย 
HTTP/2 for Developers
HTTP/2 for DevelopersHTTP/2 for Developers
HTTP/2 for Developers
ย 
Credential store using HashiCorp Vault
Credential store using HashiCorp VaultCredential store using HashiCorp Vault
Credential store using HashiCorp Vault
ย 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug Bounties
ย 
Implementing security requirements for banking API system using Open Source ...
 Implementing security requirements for banking API system using Open Source ... Implementing security requirements for banking API system using Open Source ...
Implementing security requirements for banking API system using Open Source ...
ย 
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 EditionGoing Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
ย 
ATT&CK Updates- ATT&CK's Open Source
ATT&CK Updates- ATT&CK's Open SourceATT&CK Updates- ATT&CK's Open Source
ATT&CK Updates- ATT&CK's Open Source
ย 
Web-App Remote Code Execution Via Scripting Engines
Web-App Remote Code Execution Via Scripting EnginesWeb-App Remote Code Execution Via Scripting Engines
Web-App Remote Code Execution Via Scripting Engines
ย 
GraphQL
GraphQLGraphQL
GraphQL
ย 
Http security response headers
Http security response headers Http security response headers
Http security response headers
ย 
Keycloak Single Sign-On
Keycloak Single Sign-OnKeycloak Single Sign-On
Keycloak Single Sign-On
ย 
Implementing WebAuthn & FAPI supports on Keycloak
Implementing WebAuthn & FAPI supports on KeycloakImplementing WebAuthn & FAPI supports on Keycloak
Implementing WebAuthn & FAPI supports on Keycloak
ย 
SACON - Deception Technology (Sahir Hidayatullah)
SACON - Deception Technology (Sahir Hidayatullah)SACON - Deception Technology (Sahir Hidayatullah)
SACON - Deception Technology (Sahir Hidayatullah)
ย 

Similar to Jwt == insecurity?

Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...
Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...
Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...
Evention
ย 
State of Crypto in Python (OSCON)
State of Crypto in Python (OSCON)State of Crypto in Python (OSCON)
State of Crypto in Python (OSCON)
jarito030506
ย 

Similar to Jwt == insecurity? (20)

Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying Techniques
ย 
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
Analysis of-quality-of-pkgs-in-packagist-univ-20171024Analysis of-quality-of-pkgs-in-packagist-univ-20171024
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
ย 
REST easy with API Platform
REST easy with API PlatformREST easy with API Platform
REST easy with API Platform
ย 
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
ย 
Secure Streaming-as-a-Service with Kafka/Spark/Flink in Hopsworks
Secure Streaming-as-a-Service with Kafka/Spark/Flink in HopsworksSecure Streaming-as-a-Service with Kafka/Spark/Flink in Hopsworks
Secure Streaming-as-a-Service with Kafka/Spark/Flink in Hopsworks
ย 
Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...
Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...
Hopsworks Secure Streaming as-a-service with Kafka Flinkspark - Theofilos Kak...
ย 
Rsyslog log normalization
Rsyslog log normalizationRsyslog log normalization
Rsyslog log normalization
ย 
Shift Left Security
Shift Left SecurityShift Left Security
Shift Left Security
ย 
The Anatomy of Java Vulnerabilities
The Anatomy of Java VulnerabilitiesThe Anatomy of Java Vulnerabilities
The Anatomy of Java Vulnerabilities
ย 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications
ย 
State of Crypto in Python (OSCON)
State of Crypto in Python (OSCON)State of Crypto in Python (OSCON)
State of Crypto in Python (OSCON)
ย 
REST API Pentester's perspective
REST API Pentester's perspectiveREST API Pentester's perspective
REST API Pentester's perspective
ย 
Configuration as Code in Jenkins. What's new? Nov 2016
Configuration as Code in Jenkins. What's new? Nov 2016Configuration as Code in Jenkins. What's new? Nov 2016
Configuration as Code in Jenkins. What's new? Nov 2016
ย 
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsBig Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
ย 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
ย 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
ย 
OWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript Applications
ย 
Mastering composer
Mastering composerMastering composer
Mastering composer
ย 
Lares from LOW to PWNED
Lares from LOW to PWNEDLares from LOW to PWNED
Lares from LOW to PWNED
ย 
To โˆž (~65K) and beyond! - Sebastiano Gottardo - Codemotion Milan 2016
To โˆž (~65K) and beyond! - Sebastiano Gottardo - Codemotion Milan 2016To โˆž (~65K) and beyond! - Sebastiano Gottardo - Codemotion Milan 2016
To โˆž (~65K) and beyond! - Sebastiano Gottardo - Codemotion Milan 2016
ย 

More from snyff (10)

Code that gets you pwn(s|'d)
Code that gets you pwn(s|'d)Code that gets you pwn(s|'d)
Code that gets you pwn(s|'d)
ย 
Entomology 101
Entomology 101Entomology 101
Entomology 101
ย 
Entrepreneurship for hackers
Entrepreneurship for hackersEntrepreneurship for hackers
Entrepreneurship for hackers
ย 
Finding Needles in Haystacks
Finding Needles in HaystacksFinding Needles in Haystacks
Finding Needles in Haystacks
ย 
Defcon CTF quals
Defcon CTF qualsDefcon CTF quals
Defcon CTF quals
ย 
Ruxmon cve 2012-2661
Ruxmon cve 2012-2661Ruxmon cve 2012-2661
Ruxmon cve 2012-2661
ย 
Ln monitoring repositories
Ln monitoring repositoriesLn monitoring repositories
Ln monitoring repositories
ย 
Owasp tds
Owasp tdsOwasp tds
Owasp tds
ย 
Ruxmon feb 2013 what happened to rails
Ruxmon feb 2013   what happened to railsRuxmon feb 2013   what happened to rails
Ruxmon feb 2013 what happened to rails
ย 
Harder Faster Stronger
Harder Faster StrongerHarder Faster Stronger
Harder Faster Stronger
ย 

Recently uploaded

Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
SUHANI PANDEY
ย 
โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men ๐Ÿ”mehsana๐Ÿ” Escorts...
โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men  ๐Ÿ”mehsana๐Ÿ”   Escorts...โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men  ๐Ÿ”mehsana๐Ÿ”   Escorts...
โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men ๐Ÿ”mehsana๐Ÿ” Escorts...
nirzagarg
ย 
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
nilamkumrai
ย 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
ย 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
SUHANI PANDEY
ย 
Call Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
SUHANI PANDEY
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
SUHANI PANDEY
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
singhpriety023
ย 

Recently uploaded (20)

Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
ย 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
ย 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
ย 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
ย 
โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men ๐Ÿ”mehsana๐Ÿ” Escorts...
โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men  ๐Ÿ”mehsana๐Ÿ”   Escorts...โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men  ๐Ÿ”mehsana๐Ÿ”   Escorts...
โžฅ๐Ÿ” 7737669865 ๐Ÿ”โ–ป mehsana Call-girls in Women Seeking Men ๐Ÿ”mehsana๐Ÿ” Escorts...
ย 
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | Girls Are Re...
ย 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
ย 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
ย 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
ย 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
ย 
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort ServiceBusty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
ย 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
ย 
Call Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Prashant Vihar, Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
ย 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
ย 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
ย 
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
ย 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
ย 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
ย 

Jwt == insecurity?

  • 1. JWT == insecurity? A journey in the insecurity of JSON web tokensโ€ฆ by Louis Ny๏ฌ€enegger @PentesterLab louis@pentesterlab.com
  • 2. Introduction01 Agenda The JWT format (simpli๏ฌed)02 By Design03 Libraries04 Using Libraries05 Conclusion06 PentesterLab.com / @PentesterLab
  • 3. About Me PentesterLab.com / @PentesterLab Security Engineer: PentesterLab: Pentester/Code Reviewer/Security consultant/Security architect Platform to learn web security/penetration testing 100% Hands-on Available for individuals (free and PRO) and enterprises Run a website to help people learn security
  • 4. JOSE/JWE/JWS/JWT PentesterLab.com / @PentesterLab โ€ข JOSE: โ€ข Javascript Object Signing and Encryption โ€ข Also the name of the working group โ€ข JWT: JSON Web Token == โ€œjotโ€ Token โ€ข JWE: JSON Web Encryption โ€ข JWS: JSON Web Signature โ€ข JWK: JSON Web Key โ€ข JWA: JSON Web Algorithm
  • 5. Who uses JWT PentesterLab.com / @PentesterLab โ€ข A lot of people for OAuth โ€ข A lot of people for sessions โ€ข A lot of people to manage trust โ€ข A lot of people for password reset โ€ข A lot of people who care about being stateless and multi-datacenter architecture
  • 7. JavaScript Object Notation (JSON) PentesterLab.com / @PentesterLab Human readable format to store or transmit objects
  • 8. The Compact JWS Format PentesterLab.com / @PentesterLab Header Payload Signature 3 parts in a JSON Web Token:
  • 9. The Compact JWS Format PentesterLab.com / @PentesterLab Header Payload Signature Separated by a dot . .
  • 10. The Compact JWS Format PentesterLab.com / @PentesterLab eyJ0eXAiOiJK V1QiLCJhbGci OiJIUzI1NiJ9 eyJsb2dpbi I6ImFkb WluIn0 FSfvCBAwypJ4abF6 jFLmR7JgZhkW674 Z8dIdAIRyt1E Separated by a dot . . eyJ = Base64('{"')
  • 11. The Compact JWS Format PentesterLab.com / @PentesterLab Base64({โ€ฆ}) Base64({โ€ฆ}) Base64(โ€ฆ) Header and Payload are base64* encoded JSON . . * urlsafe base64 encoding without padding The signature is also base64 encoded
  • 12. The Compact JWS Format: Encoding PentesterLab.com / @PentesterLab Urlsafe base64 encoding without padding: *https://tools.ietf.org/html/rfc7515#appendix-C
  • 13. The JWT Format: header PentesterLab.com / @PentesterLab Base64({"alg": "HS256", "typ": "JWS"}) The header contains an algorithm โ€œalgโ€ attribute: In this example HMAC with SHA256 was used To tell how the token was signed. โ€ฆ . . โ€ฆ
  • 14. The JWT Format: Algorithms PentesterLab.com / @PentesterLab A lot of different algorithms are supported*: None * https://jwt.io/ covers most HS256 HS384 HS512 RS256 RS384 RS512 ES256 ES384 ES512 PS256 PS384 PS512
  • 15. The JWT Format: Algorithms PentesterLab.com / @PentesterLab Scenario: one client talking to multiple services
  • 16. The JWT Format: Algorithms PentesterLab.com / @PentesterLab HS256 HS384 HS512 HMAC: All services need to know the secret
  • 17. The JWT Format: Algorithms PentesterLab.com / @PentesterLab HS256 HS384 HS512 HMAC: if one service gets compromised
  • 18. The JWT Format: Algorithms PentesterLab.com / @PentesterLab HS256 HS384 HS512 HMAC: the secret is compromised for all services
  • 19. The JWT Format: Asymmetric PentesterLab.com / @PentesterLab RS256 RS384 RS512 ES256 ES384 ES512 PS256 PS384 PS512 Asymmetric: sharing the key Private Public
  • 20. The JWT Format: Asymmetric PentesterLab.com / @PentesterLab RS256 RS384 RS512 ES256 ES384 ES512 PS256 PS384 PS512 Asymmetric: Only trusted services get the private key Private Public
  • 21. The JWT Format: Asymmetric PentesterLab.com / @PentesterLab RS256 RS384 RS512 ES256 ES384 ES512 PS256 PS384 PS512 Asymmetric: If one service gets compromisedโ€ฆ Private Public
  • 22. The JWT Format: Asymmetric PentesterLab.com / @PentesterLab RS256 RS384 RS512 ES256 ES384 ES512 PS256 PS384 PS512 Asymmetric: Even in the browser! Private Public
  • 23. The JWT Format: payload PentesterLab.com / @PentesterLab โ€ฆ The payload may contain literally anything: Base64({"user":"admin", "roles": ["adm","users"]}). . โ€ฆ
  • 24. The JWT Format: payload PentesterLab.com / @PentesterLab The payload may contain registered claims: Base64({"user":"admin", "exp":12โ€ฆ, "iat":1234.. }). .โ€ฆ โ€ฆ
  • 25. The JWT Format: payload PentesterLab.com / @PentesterLab The payload may contain registered claims: โ€ข โ€œissโ€: issuer โ€ข โ€œsubโ€: subject โ€ข โ€œaudโ€: audience โ€ข โ€œjtiโ€: claim id โ€ข โ€œexpโ€: expiration time โ€ข โ€œnbfโ€: not before โ€ข โ€œiatโ€: issued at* * useful for async processing
  • 26. The JWT Format: creating a token PentesterLab.com / @PentesterLab โ€ข Create the JSON header and base64 encode it โ€ข Create the JSON payload and base64 encode it โ€ข Concatenate with a dot the (encoded) header and payload โ€ข Sign the result (header+.+payload) โ€ข Base64 encode the signature โ€ข Append a dot then the signature
  • 27. The JWT Format: verifying a token PentesterLab.com / @PentesterLab โ€ข Split the token in three parts based on the dots โ€ข Base64 decode each part โ€ข Parse the JSON for the header and payload โ€ข Retrieve the algorithm from the header โ€ข Verify the signature based on the algorithm โ€ข Verify the claims
  • 28. Keep in mind PentesterLab.com / @PentesterLab โ€ข Multiple systems can issue tokens โ€ข A token can be used by multiple systems โ€ข All these systems can use different libraries
  • 30. By design: verifying signature PentesterLab.com / @PentesterLab Base64({ "alg": "HS256", "typ": "JWS"}) You need to base64 decode and parse JSON to verify the signature: Larger attack surface JSON.load vs JSON.parse, Base64 decoding โ€ฆ . . โ€ฆ
  • 31. By design: verifying signature PentesterLab.com / @PentesterLab The attacker controls the algorithm used: Downgrade attacks, confusion attack Base64({ "alg": "HS256", "typ": "JWS"}) โ€ฆ . . โ€ฆ
  • 32. By design: Confusion attack PentesterLab.com / @PentesterLab Exploitation: โ€ข Get a token signed with RSA (you only have access to the public key) โ€ข Decode the header and change the algorithm from RSA โ€œRS256โ€ to HMAC โ€œHS256โ€ โ€ข Tamper with the payload โ€ข Sign the token with the public RSA key โ€ข Pro๏ฌt
  • 33. By design: verifying signature PentesterLab.com / @PentesterLab โ€ฆ Claims are optionals and not always supported*: Always-valid tokens? Base64({"user":"admin", "exp":12โ€ฆ, "iat":1234.. }). . โ€ฆ * Check https://jwt.io/
  • 34. By design: verifying signature PentesterLab.com / @PentesterLab Claims are optionals and not always supported* Always-valid tokens? * Check https://jwt.io/
  • 35. By design: verifying signature PentesterLab.com / @PentesterLab Signed data: you cannot (easily) manage quick- revocation*: The claim โ€œjtiโ€ and a cache can be used to limit the impact of this No quick-revocation! Replay * Unless you rotate the key or manage a server-side cache
  • 36. By design: The None algorithm PentesterLab.com / @PentesterLab JWT RFC contains a None algorithm No integrity! Basically an unsigned tokenโ€ฆ
  • 37. By design: The None algorithm PentesterLab.com / @PentesterLab Exploitation: โ€ข Get a token โ€ข Decode the header and change the algorithm to โ€œNoneโ€ or โ€œnoneโ€ โ€ข Decode and tamper with the payload โ€ข Keep or remove the signature โ€ข Pro๏ฌt
  • 39. Libraries: CVE-2018-0114 PentesterLab.com / @PentesterLab JWS allows you to add a โ€œjwkโ€ attribute (JSON Web Key) to the header to tell the receiver what key was used to sign the token:
  • 40. Libraries: CVE-2018-0114 PentesterLab.com / @PentesterLab โ€ข Vulnerability in Cisco Node Jose โ€ข Node-Jose uses the embedded โ€œjwkโ€ key to check the signature Integrity bypass!
  • 41. Libraries: CVE-2018-0114 - Exploitation PentesterLab.com / @PentesterLab Exploitation: โ€ข Get a token โ€ข Decode and tamper with the payload โ€ข Generate a RSA key โ€ข Add โ€œn" & โ€œeโ€ to the header and use RS256 โ€ข Sign the token with your RSA key
  • 42. Libraries: Go-JOSE version <= 1.0.5 PentesterLab.com / @PentesterLab Non-compact/full format for JWS:
  • 43. Libraries: Go-JOSE version <= 1.0.5 PentesterLab.com / @PentesterLab From: https://rwc.iacr.org/2017/Slides/nguyen.quan.pdf The issue:
  • 44. Libraries: Go-JOSE version <= 1.0.5 PentesterLab.com / @PentesterLab From: https://rwc.iacr.org/2017/Slides/nguyen.quan.pdf The issue: Integrity of the protected bypass!
  • 45. Libraries: Go-JOSE version <= 1.0.5 PentesterLab.com / @PentesterLab If the application trusts the protected*: * you cannot change the payload
  • 46. Libraries: Go-JOSE version <= 1.0.5 - Exploitation PentesterLab.com / @PentesterLab Exploitation: โ€ข Get a token (compact or full) โ€ข Modify it to use the full format โ€ข Add your malicious protected โ€ข Pro๏ฌt
  • 48. Using Libraries: weak secret PentesterLab.com / @PentesterLab Some developers use weak secrets. Reminder: you only need one token to brute force the secret (completely of๏ฌ‚ine) Integrity bypass!
  • 49. Using Libraries: decode vs verify PentesterLab.com / @PentesterLab A lot of libraries have two functions/methods: โ€ข decode <- donโ€™t use this one โ€ข verify Integrity bypass!
  • 50. Using Libraries: decode vs verify PentesterLab.com / @PentesterLab Exploitation: โ€ข Get a token โ€ข Decode and tamper with the header or payload โ€ข Pro๏ฌt
  • 51. Using Libraries: not using exp or iat PentesterLab.com / @PentesterLab In many libraries you need to opt-in to use โ€œexpโ€ or โ€œiatโ€ Always-valid tokens?
  • 53. Recommendations PentesterLab.com / @PentesterLab โœ“ Use strong keys and secrets โœ“ Review the libraries you pick (KISS library) โœ“ Make sure you check the signature โœ“ Make sure your tokens expire โœ“ Enforce the algorithm
  • 54. Conclusion PentesterLab.com / @PentesterLab โ€ข JWT are complex and kind of insecure by design โ€ข JWT libraries introduce very interesting bugs โ€ข Make sure you test for those if you pentest or do bug bounties
  • 55. Any questions? FOR YOUR TIME THANKS! louis@pentesterlab.com / PentesterLab.com / @PentesterLab