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

# 通过暴力破解绕过 2FA

### 使用暴力破解攻击绕过 2FA

这个实验有两个可被暴力破解攻击利用的因素。/ 用户 ID 已经已知，但 2FA 验证码无法获取。/ 目标是强制获取 MFA 代码，以便访问以下账户 **Carlos**.

* **受害者**: `carlos`
* **密码**: `montoya`

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

**2FA 身份验证上下文**

在使用用户名和密码成功连接后，应用程序会要求输入 MFA 代码。

服务器端请求如下：

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

**遇到的问题**

* 在测试多个 MFA 代码时，服务器表示 **CSRF 令牌已不再有效**.

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

* 然后应用程序会自动重定向到登录页面。

每次重新访问登录页面时，都会生成 **新的 CSRF 令牌** 。

这会阻止对 `mfa-code` 参数进行利用。

<figure><img src="/files/6645e7ab7392e39e7b0c630ebf01e82eccec9208" alt=""><figcaption></figcaption></figure>

**设置解决方案（Burp Suite）**

为绕过此保护，使用了一个 **宏** 以在每次尝试时自动重新生成有效的 CSRF 令牌。

<figure><img src="/files/92bf9e2861ec125d1c270a8a91bd7a82e5cf83ae" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/854f4e05a9b9b1b515a7c726cac02b6c1e453d4a" alt="" width="461"><figcaption></figcaption></figure>

**步骤：**

1. 创建一个新的 **宏** 在 Burp Suite 中。

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

* 将以下请求包含到宏中：
* `GET /login`
* `POST /login`
* `GET /login2`

<figure><img src="/files/8c0319187dd76cc80ae588db6336915404118272" alt=""><figcaption></figcaption></figure>

1. 验证该宏是否允许提取一个 **新的 CSRF 令牌** 在每次执行时。

<figure><img src="/files/1c5e3c30dcb1379925b731bbfd725d17a3a6b8ab" alt=""><figcaption></figcaption></figure>

宏现在已准备就绪并可正常使用。

**MFA 代码暴力破解攻击**

1. 拦截 `POST` 包含 `mfa-code` 参数进行利用。

<figure><img src="/files/64631d4d5c07aed5e541578ee3c17554c8ece5b1" alt=""><figcaption></figcaption></figure>

* 将此请求发送到 **Intruder**.
* 在字段上设置有效载荷。 `mfa-code` 字段。
* 将值范围设置为 **0000 到 9999**，格式为 **4 位必需数字**.

<figure><img src="/files/9215208b9258304da85d439dd7db49505b40c22c" alt="" width="394"><figcaption></figcaption></figure>

关联宏，以便 **CSRF 会自动更新** 到每个请求。

<figure><img src="/files/099ca8ef4420a38ab52d0372ada06c6528f33930" alt=""><figcaption></figcaption></figure>

**结果**

* CSRF 令牌会随着每次尝试正确变化。
* 当测试到有效的 MFA 代码时，服务器响应会有所不同。
* 正确的代码可以通过一个 **`302 Found`** 响应来识别，表示已成功重定向到用户账户。

<figure><img src="/files/6b9d887ff86c30bf76cce90e67f84cbad91771db" 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/zh/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.
