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

# Lógica de 2FA Quebrada

### Lógica Quebrada de 2FA

A aplicação introduz autenticação de dois fatores: / Após login/senha, um **código 2FA** é enviado por **email**. / Temos:

* Nossas credenciais: `wiener:peter`
* O nome de usuário da vítima: `carlos`

<figure><img src="/files/3fbc50efb613720d30f1ed8886c5b0b1b8d64bac" alt=""><figcaption></figcaption></figure>

Acesso ao **servidor de e-mail** para receber códigos 2FA

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

#### Operação Observada

1. Após a primeira etapa de login, a aplicação envia um código 2FA por e-mail.
2. A segunda etapa (`/login2`) verifica esse código.
3. O usuário para o qual o 2FA é válido é determinado por meio do **`verify`** cookie.

Exemplo de uma requisição para a segunda etapa:

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

Aqui, forçamos o `verify` cookie para `carlos` para que a verificação de 2FA seja feita na conta da vítima.

#### Força bruta do código 2FA

1. A requisição de validação do 2FA é enviada para **Intruder** (ou equivalente) ao direcionar a requisição que contém:

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

<figure><img src="/files/04a36f94352be35a263cd705aeb228f9cbd4f657" alt=""><figcaption></figcaption></figure>

* O **payload** está configurado para testar todas as combinações possíveis do código, de `0000` para `9999` (isto é, 10.000 valores).

Usamos o cookie:

```bash
verify=carlos
```

* para que todos os testes de código sejam realizados na conta de **carlos**.

<figure><img src="/files/8446b1260a24f937581d47ad59d3a7e35bfa9b46" alt=""><figcaption></figcaption></figure>

* Nas configurações, uma \*\*condição de filtro\*\* é adicionada à resposta para ignorar as que contenham a mensagem:
* `Código de segurança incorreto`

<figure><img src="/files/515ccf93f92542e52b4c5ba234e8c6cc3692232f" alt=""><figcaption></figcaption></figure>

1. Estamos iniciando o ataque de força bruta.
2. Entre as respostas, encontramos a que não contém mais a mensagem de erro e retorna um \*\*código HTTP 302\*\* (redirecionamento). / → Esta resposta corresponde a **código 2FA correto** em nome de **carlos**.

<figure><img src="/files/0b0885008e8530224caa08a0636c17f8cb92fdc1" 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/pt-br/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.
