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

# Bypass de 2FA via força bruta

Notas sobre bypass de 2FA via força bruta para os laboratórios do PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payload, validação no Burp Suite e contexto de remediação.

### Contornando a 2FA Usando um Ataque de Força Bruta

Este laboratório tem dois fatores que são vulneráveis a ataque de força bruta. / Os IDs de usuário já são conhecidos, mas o código de verificação da 2FA não está acessível. / O objetivo é forçar o código MFA para acessar a conta de **Carlos**.

* **Vítima**: `carlos`
* **Senha**: `montoya`

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3834412bbcf44d707207510096f72ba0b0eccada%2F%7B4DED2AEE-EA63-4072-9E04-BAF3CFC206DC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Contexto de Autenticação 2FA**

Após uma conexão bem-sucedida com o nome de usuário e a senha, o aplicativo exige um código MFA.

A consulta no lado do servidor é assim:

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

**Problema encontrado**

* Ao testar vários códigos MFA, o servidor indica que o **token CSRF não é mais válido**.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-964d0e1a2d6d3bd6103dc107200e6915e9773250%2F%7BC01D1654-0FBB-418B-9281-E7AE950854A1%7D.png?alt=media" alt="" width="464"><figcaption></figcaption></figure>

* O aplicativo então redireciona automaticamente para a página de login.

A cada novo acesso à página de login, um **novo token CSRF** é gerado.

Isso impede um ataque de força bruta direto ao `mfa-code` parâmetro.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7201e3354f2bd7840af1ba91304b8ddd869057b6%2F%7BAA71B106-2316-4CD6-ADDA-6F8FA67512DD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Configurando a solução (Burp Suite)**

Para contornar essa proteção, um **macro** é usado para regenerar automaticamente um token CSRF válido a cada tentativa.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-89547f86ba355f76c71e4433af94aa50d6ea96e1%2F%7BCC2731F5-E07D-487D-8B38-81D8336FEA6B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1e764a2d92dac7dde3dd174cf8b5dcdc87e39fab%2F%7B3EF5EB33-F316-4FF5-AFDA-E9FEFFC38E36%7D.png?alt=media" alt="" width="461"><figcaption></figcaption></figure>

**Etapas:**

1. Criar uma nova **macro** no Burp Suite.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f3b8e88622c250b5d11f0576c296d378414bf96d%2F%7B595C3E70-CED1-4912-A6E8-C88D680E9903%7D.png?alt=media" alt="" width="459"><figcaption></figcaption></figure>

* Inclua as seguintes requisições na macro:
* `GET /login`
* `POST /login`
* `GET /login2`

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c3f201c93c6c856f7f18662c8ea82fa2c003e8de%2F%7B3863FEBE-6FF4-468F-B4D3-A7747BA24BD0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

1. Verifique se a macro permite extrair um **novo token CSRF** a cada execução.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-525be5a3d11a9b8834309c181841d449d13c765d%2F%7BC488BB59-A9A6-4DFB-B938-5A3750FFBD80%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

A macro agora está pronta e funcional.

**Ataque de Força Bruta ao Código MFA**

1. Intercepte a `POST` consulta contendo o `mfa-code` parâmetro.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3672181bbd5df883883eae782d5a77203cd591b5%2F%7BE49939DA-088C-4E64-96CC-34CD2A46A4F4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Envie esta requisição para **Intruder**.
* Defina o payload no campo `mfa-code` campo.
* Defina um intervalo de valores de **0000 a 9999**, com um formato de **4 dígitos obrigatórios**.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78278bbb025425207b01cc78dbea415d4ea11e67%2F%7BC0CE4BB8-36E4-47F9-BC97-82B1FFB7FB68%7D.png?alt=media" alt="" width="394"><figcaption></figcaption></figure>

Associe a macro para que **o CSRF seja atualizado automaticamente** em cada consulta.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c9e9c533009cc059e9deb568e51cd7b30d58893d%2F%7BC167ABD2-994F-4D27-B3BE-B95DFB48A301%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Resultado**

* O token CSRF muda corretamente a cada tentativa.
* Quando um código MFA válido é testado, a resposta do servidor é diferente.
* O código correto é identificável por uma **`302 Encontrado`** resposta, indicando um redirecionamento bem-sucedido para a conta do usuário.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-229a1a4f28b1aea19f7b3b757caf5ec08da82557%2F%7BD4634311-3A29-461E-9A0E-79F7D5407B5F%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/pt-br/web/authentication/2fa-bypass-via-brute-force.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.
