practical approaches for testing and breaking jwt ... commsec... · •always verify the jwt...

30
MAZIN AHMED, 2019 FULLHUNT.IO Practical Approaches for Testing and Breaking JWT Authentication https://cyberweek.ae

Upload: others

Post on 19-Aug-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

MAZIN AHMED, 2019FULLHUNT.IO

Practical Approaches forTesting and BreakingJWT Authentication

h t t p s : / / c y b e r w e e k . a e

Page 2: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

2

$> WHOAMIv Mazin Ahmed• Freelancing Penetration Tester / InfoSec Specialist

• Founder & CEO @ FullHunt, the next generation vulnerability

intelligence platform

• Ex-Security Engineer @ ProtonMail

• Occasional Bug Bounty Participant

• Top 10 researchers of Bugcrowd @ 2014

• Acknowledged by Facebook, Twitter, Oracle, LinkedIn, and many…

Page 3: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

3

{Story}

Page 4: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

4

$> AGENDA• What is JWT?• How it Works?• Web Implementations• Attacking JWT• Current Toolsets• Introducing JWT-PWN• Recommendations for Implementing Secure JWT

Page 5: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

5

$> WHAT IS JWT?• RFC-7519• Proposed @ May 2015• JSON Object + Digital Signature = JWT

Page 6: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

6

$> JWT

[ Base64(HEADER) ] . [ Base64(PAYLOAD) ] . [ Base64(SIGNATURE) ]

Page 7: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

7

$> JWTChunk 1: Header{"alg": "HS256", "typ": "JWT"}

Chunk 2: Payload{"sub": "1234567890", "name": "Mazin", "admin": true}

Page 8: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

8

$> JWT - SIGNATURE

HMACSHA256(base64UrlEncode(header)+ "." +

base64UrlEncode(payload), KEY)

Page 9: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

9

$> JWT

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

Page 10: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

10

$> WEB IMPLEMENTATION

Page 11: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

11

Attacking JSON Web TokensHack The Planet?Episode: JWT

Page 12: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

12

1. Brute-Force Secret Keys

Page 13: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

13

2. Signing a new token with the “none” algorithm

Page 14: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

14

3. Changing the Signing Algorithm of the Token

Page 15: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

15

JWT Testing Tools

Page 16: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

16

$> JWT TOOLS: JWT_TOOL• Jwt_tool (https://github.com/ticarpi/jwt_tool)

• Uses linear approach for cracking, still quite fast!• Number of attacks covered.• Custom parsing for Base64 strings, not official JWT libraries.

Page 17: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

17

$> JWT TOOLS: C-JWT-CRACKER• C-jwt-cracker (https://github.com/brendan-rius/c-jwt-cracker)

• JWT brute force cracker written in C• Unstable - Buggy libraries

From the project repository:

Page 18: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

18

$> JWT TOOLS: JWT-CRACKER• jwt-cracker (https://github.com/lmammino/jwt-cracker)

• Simple HS256 JWT token brute force cracker.• No dictionary attack support.• Only made for HS256.

Page 19: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

19

Introducing JWT-PWN

Page 20: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

20

$> JWT-PWN• Simple Scripts.• Covering all discussed attacks.• Automated approach.• Using official/main JWT libraries.• Includes a JWT secret-key cracker, with software engineering in

mind.• Beta release!

Page 21: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

21

$> JWT-PWN: JWT-DECODER.PY

Page 22: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

22

$> JWT-PWN: JWT-ANY-TO-HS256.PY

Page 23: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

23

$> JWT-PWN: JWT-MIMICKER.PY

Page 24: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

24

$> JWT-PWN: JWT-CRACKER.PY

Page 25: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

25

$> JWT-PWN: JWT-CRACKER-GO

Page 26: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

26

{Demo}https://www.youtube.com/watch?v=pIOBu-HWGT8

Page 27: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

27

JWT-PWNhttps://github.com/mazen160/jwt-pwn

Page 28: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

28

$> RECOMMENDATIONS• Always verify the JWT Header.• Always verify the JWT “alg” key in the JWT header.• Never trust the “none” algorithm for signing. • Whitelist the used algorithm, and always verify it.• Rotate your signing keys periodically.• Don’t expose important client-data in JWT; it can be decoded.• Add a claim for “Expiration” to overcome the non-expiration issue in

the stateless protocol.• Key-size matters.

Page 29: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

29

Thank you

Mazin AhmedTwitter: @mazen160Website: MazinAhmed.net

Page 30: Practical Approaches for Testing and Breaking JWT ... COMMSEC... · •Always verify the JWT Header. •Always verify the JWT “alg” key in the JWT header. •Never trust the “none”

30

Questions?

Mazin AhmedTwitter: @mazen160Website: MazinAhmed.net