> 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

Notas sobre Lógica rota de 2FA 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.

### Lógica rota de 2FA

La aplicación introduce autenticación de dos factores: / Después de usuario/contraseña, un **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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-39d8162c29a0f670cd135b7caaa8e257d0564568%2F%7BEADD372C-6B83-488A-A6BF-33E63F7E8275%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b7096d751d9122f8a5a76bfa0f921e20bdccce7d%2Fimage%20(247).png?alt=media" 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álido el 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 para `carlos` para que la comprobación de 2FA se realice en la cuenta de la víctima.

#### Ataque de fuerza bruta al código 2FA

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

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-320e6c232a2b39126c4ae2ae10d5361beec9e936%2F%7B9AC3C534-94B3-419B-9333-3E1B1CDBE72D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* El **carga útil** 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-85ae02b3d9733ac0cc034488646cd927c7fe9897%2F%7B74BA9A5C-1D63-4A53-933F-98E8280A06FF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a33181992fde2f30e4b1ed6b81e78e26a9ed2f4d%2F%7B8FB4058E-CA1B-4381-919C-D636554A5B71%7D.png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a5c81b03c3b04a6501d692246922aab5cf19fe5c%2F%7BE0F88A65-57C7-47C7-B14C-78FEB9C9801C%7D.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/authentication/broken-2fa-logic.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.
