> 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/race-conditions/exploitation-of-time-sensitive-vulnerabilities.md).

# 时间敏感漏洞的利用

### 利用时间敏感型漏洞

### 实验上下文

该网站提供了一个……功能 **密码重置** 通过电子邮件发送的链接。/ 在逻辑应用层面并不存在真正的竞态条件，但……的生成 **令牌** 是 **基于**：它取决于一个 **可预测的值** （时间），这使得可以通过\*\*同时\*\*发送请求为另一个用户伪造一个有效令牌。

<figure><img src="/files/5c4e2e368ef1ccc4b5e93c15d0c75bd33ef13bac" alt=""><figcaption></figcaption></figure>

### 初步观察

1. 我们使用 **忘记密码** 使用用户 `wiener`.

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

* 一封包含如下类型链接的电子邮件：
* `/forgot-password?user=wiener&token=<token>`

{% code overflow="wrap" %}

```bash
你好！

请点击下面的链接重置您的密码。

https://0a1300c9040343bf810b7f2a00e60085.web-security-academy.net/forgot-password?user=wiener&token=3930dc6d3d076151204ad4147326f81a5e1609a8
```

{% endcode %}

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

* 令牌看起来像一个 **SHA1** （40个十六进制字符）。

`forgot-password?user=wiener&token=3930dc6d3d076151204ad4147326f81a5e1609a8`

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

* 令牌看起来像一个 **SHA1** （40个十六进制字符）。

```bash
hashid '3930dc6d3d076151204ad4147326f81a5e1609a8'
```

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

1. 通过生成多个令牌

假设：令牌主要来源于一个 **时间戳** （或基于时间的值），而不是一个强随机的密钥。

<figure><img src="/files/f710ff92166429e68af16f3883c892d4c8bb2fb6" alt="" width="563"><figcaption></figcaption></figure>

### 关键思路：强制两个请求在同一毫秒内发出

如果我们能够触发 **两个重置** 同时进行，而且令牌只取决于时间，那么 **这两个令牌将完全相同**.

<figure><img src="/files/28552424faea3f3cb93ee50784e2231a20415ada" alt=""><figcaption></figcaption></figure>

问题：服务器（PHP）有时会避免同一会话 / CSRF 的冲突。/ 解决方案：获取 **两个独立会话**.

<figure><img src="/files/0aff02000a3d571afaf18ed8dca7734ca07a7782" alt=""><figcaption></figcaption></figure>

### 准备：获取两组会话 + CSRF 配对

向以下地址发送两个独立请求：

* `GET /forgot-password`

```http
GET /forgot-password HTTP/2
Host: 0a1300c9040343bf810b7f2a00e60085.web-security-academy.net
Cookie：
```

每次响应都会给出一组新的配对：

* `PHPSESSID=<...>`
* 一个新的 CSRF 令牌（值隐藏在表单中）

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

有 **两个已准备好的请求**，每个都包含：

* 其 `PHPSESSID` cookie
* 对应的 CSRF 字段

<figure><img src="/files/300ec3541d126027530c4a209d2ee29861cdc454" alt=""><figcaption></figcaption></figure>

### 触发：并行发送

然后我们发送 **并行地** 两个重置 POST 请求（即使是同一端点），在 Burp 中（分组 + 并行发送），使它们到达 **同一时间窗口**.

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

观察到的结果：收到的两封电子邮件包含\*\*完全相同的令牌\*\*：

```bash
933ccbd314dc37df95887cd914b07e330517f7bb
933ccbd314dc37df95887cd914b07e330517f7bb
```

<figure><img src="/files/93a0d1acd497f408d52e1120284eb874446a64d5" alt=""><figcaption></figcaption></figure>

结论：令牌本质上取决于 **时间戳**，而不是每个用户单独的某个密钥。

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

### 操作：使用 Wiener 的令牌重置 Carlos

目标：令牌对……有效 `carlos`.

方法：

1. 并行发起两个重置：

* 一个用于 `wiener`
* 一个用于 `carlos`

```bash
forgot-password?user=wiener&token=da1d6e3ed67bef3efa9fe74fcfbf7603120ea744
forgot-password?user=carlos&token=da1d6e3ed67bef3efa9fe74fcfbf7603120ea744
```

由于令牌相同，收到的令牌（例如通过 `wiener` 电子邮件）也将对……有效 `carlos`.

如果网站接受此 URL，你就可以 **设置新密码** 为 `carlos`.

<figure><img src="/files/73fdf74b975a7d47910be2c70bb126af9010eda0" alt=""><figcaption></figcaption></figure>

### 实验完成

1. 以……身份登录 `carlos` 使用新密码。
2. 访问\*\*管理员登录\*\*。
3. 删除 `carlos` 用户以验证实验。

<figure><img src="/files/aae4e86fcb698b40af718c03e11f1c0c22e99df1" 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/race-conditions/exploitation-of-time-sensitive-vulnerabilities.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.
