> 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/2fa-bypass-via-brute-force.md).

# Elusión de 2FA mediante fuerza bruta

### Bypass de 2FA usando un ataque de fuerza bruta

Este laboratorio tiene dos factores vulnerables a un ataque de fuerza bruta. / Los ID de usuario ya se conocen, pero el código de verificación 2FA no es accesible. / El objetivo es forzar el código MFA para acceder a la cuenta de **Carlos**.

* **Víctima**: `carlos`
* **Contraseña**: `montoya`

<figure><img src="/files/49d23d7694f646cfeb32f79b92225731a608527f" alt=""><figcaption></figcaption></figure>

**Contexto de autenticación 2FA**

Después de una conexión exitosa con el nombre de usuario y la contraseña, la aplicación requiere un código MFA.

La consulta del lado del servidor se ve así:

```bash
csrf=pqkmb1Cny2T3wbbgKEdqZPweWFpyCv0A&mfa-code=1234
```

**Problema encontrado**

* Al probar varios códigos MFA, el servidor indica que el **token CSRF ya no es válido**.

<figure><img src="/files/36f7fd955c03edb423431b4be9b929834c756051" alt="" width="464"><figcaption></figcaption></figure>

* La aplicación luego redirige automáticamente a la página de inicio de sesión.

Con cada nuevo acceso a la página de inicio de sesión, se **genera un nuevo token CSRF** se genera.

Esto impide un ataque directo de fuerza bruta sobre el `mfa-code` parámetro.

<figure><img src="/files/56dcb9319179ea95ece675c99b00e7697d31654d" alt=""><figcaption></figcaption></figure>

**Configuración de la solución (Burp Suite)**

Para sortear esta protección, se utiliza una **macro** se utiliza para regenerar automáticamente un token CSRF válido en cada intento.

<figure><img src="/files/4cbb6e387a1794ba3b78453ab9f71abbdf820a08" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/1eeb1e3fbcd61daa19e409fc6c3322b07466625c" alt="" width="461"><figcaption></figcaption></figure>

**Pasos:**

1. Crear una nueva **macro** en Burp Suite.

<figure><img src="/files/ba9b9fd426756b5544af1a1276834383840b97b8" alt="" width="459"><figcaption></figcaption></figure>

* Incluye las siguientes solicitudes en la macro:
* `GET /login`
* `POST /login`
* `GET /login2`

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

1. Verifica que la macro permita extraer un **genera un nuevo token CSRF** en cada ejecución.

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

La macro ya está lista y funcional.

**Ataque de fuerza bruta al código MFA**

1. Intercepta la `POST` solicitud que contiene el `mfa-code` parámetro.

<figure><img src="/files/39ea8d3edaa5bcb009ef6ff82976df9046707c3d" alt=""><figcaption></figcaption></figure>

* Envía esta solicitud a **Intruder**.
* Configura la carga útil en el `mfa-code` campo.
* Establece un rango de valores desde **0000 a 9999**, con un formato de **4 dígitos obligatorios**.

<figure><img src="/files/27265e68827ac61a82e8489ec9cddc0d25795c86" alt="" width="394"><figcaption></figcaption></figure>

Asocia la macro para que **CSRF se actualice automáticamente** en cada solicitud.

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

**Resultado**

* El token CSRF cambia correctamente con cada intento.
* Cuando se prueba un código MFA válido, la respuesta del servidor cambia.
* El código correcto se puede identificar por una **`302 Found`** respuesta, lo que indica una redirección exitosa a la cuenta del usuario.

<figure><img src="/files/587c3204b20094cad1c7ab3d72d8072130915889" 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/2fa-bypass-via-brute-force.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.
