> 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/authentication/broken-2fa-logic.md).

# Lógica rota de 2FA

### Lógica defectuosa de 2FA

La aplicación introduce autenticación de dos factores: / Después de iniciar sesión/contraseña, una **código 2FA** se envía por **correo electrónico**. / Tenemos:

* Nuestras credenciales: `wiener:peter`
* El nombre de usuario de la víctima: `carlos`

<figure><img src="/files/afd3e8ed5bf2d2204bfed981a24d6718cba81fef" alt=""><figcaption></figcaption></figure>

Acceso a **servidor de correo** para recibir códigos 2FA

<figure><img src="/files/39861d36bce884b97c383b7c84b5ac1fb6d58a92" alt=""><figcaption></figcaption></figure>

#### Operación observada

1. Después del primer paso de inicio de sesión, la aplicación envía un código 2FA por correo electrónico.
2. El segundo paso (`/login2`) comprueba este código.
3. El usuario para el que es válida la 2FA se determina mediante el **`verify`** cookie.

Ejemplo de una solicitud al segundo paso:

```http
GET /login2 HTTP/2
Host: 0a7500ab0376700f81a18e2c00f200a8.web-security-academy.net
Cookie: session=cNFHPofUz1wxXQpsZZN7yIiKQklG1Ygd; verify=carlos
```

Aquí, forzamos la `verify` cookie a `carlos` para que la verificación de 2FA se realice en la cuenta de la víctima.

#### Fuerza bruta del código 2FA

1. La solicitud de validación de 2FA se envía a **Intruder** (o equivalente) dirigiéndose a la solicitud que contiene:

```bash
mfa-code=XXXXX
```

<figure><img src="/files/3112c5ee4957170dd1004f0e5a29665cdb42873f" alt=""><figcaption></figcaption></figure>

* El **payload** está configurado para probar todas las combinaciones posibles del código, desde `0000` a `9999` (es decir, 10.000 valores).

Usamos la cookie:

```bash
verify=carlos
```

* para que todas las pruebas de código se realicen en la cuenta de **carlos**.

<figure><img src="/files/0171fc44bf7aad0c79c21ae2f38f06bc62d3c8e4" alt=""><figcaption></figcaption></figure>

* En la configuración, se añade una \*\*condición de filtro\*\* a la respuesta para ignorar aquellas que contengan el mensaje:
* `Código de seguridad incorrecto`

<figure><img src="/files/ccd597a542fb5cb50c4d5a6487ba6d9f3e2ff9ef" alt=""><figcaption></figcaption></figure>

1. Estamos lanzando el ataque de fuerza bruta.
2. Entre las respuestas, encontramos la que ya no contiene el mensaje de error y devuelve un \*\*código HTTP 302\*\* (redirección). / → Esta respuesta corresponde a **código 2FA correcto** en nombre de **carlos**.

<figure><img src="/files/101e3dd783b152219b5ee93a2606ebd8912fc0be" 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 dynamically by asking a question.

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

```
GET https://hacking-notes.jord4n.pro/es/web/authentication/broken-2fa-logic.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
