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

# 有缺陷的 2FA 逻辑

### 2FA 逻辑缺陷

该应用引入了双因素认证：/ 在登录名/密码之后，一个 **2FA 代码** 由……发送 **email**. / 我们有：

* 我们的凭据： `wiener:peter`
* 受害者的用户名： `carlos`

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

可访问 **邮件服务器** 以接收 2FA 代码

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

#### 观察到的操作

1. 在第一步登录之后，应用会通过电子邮件发送一个 2FA 代码。
2. 第二步（`/login2`) 会检查该代码。
3. 2FA 对其有效的用户通过 **`验证`** Cookie。

第二步请求示例：

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

在这里，我们强制将 `验证` cookie 设置为 `carlos` 以便在受害者的账户上执行 2FA 检查。

#### 暴力破解 2FA 代码

1. 2FA 验证请求发送到 **Intruder** （或等效项），方法是针对包含以下内容的请求：

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

<figure><img src="/files/0990cfe563baa5a1612ce09e2b2696911ce5132e" alt=""><figcaption></figcaption></figure>

* 该 **载荷** 被配置为测试所有可能的代码组合，从 `0000` 更改为 `9999` （即 10,000 个值）。

我们使用以下 cookie：

```bash
verify=carlos
```

* 以便所有代码测试都在 **carlos**.

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

* 在设置中，向响应添加了一个 \*\*过滤条件\*\*，以忽略包含以下消息的响应：
* `安全码错误`

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

1. 我们正在发起暴力破解攻击。
2. 在这些响应中，我们找到了不再包含错误消息并返回 \*\*HTTP 状态码 302\*\*（重定向）的那个。 / → 该响应对应于 **2FA 代码正确** 代表 **carlos**.

<figure><img src="/files/63e840a289eeec20a17f9591d1d9cc9e6d073378" 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/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.
