> For the complete documentation index, see [llms.txt](https://hacktricks.xsx.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktricks.xsx.tw/pentesting-web/proxy-waf-protections-bypass.md).

# Proxy / WAF Protections Bypass

<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>

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

{% embed url="<https://websec.nl/>" %}

## 使用路径名操纵绕过 Nginx ACL 规则 <a href="#heading-pathname-manipulation-bypassing-reverse-proxies-and-load-balancers-security-rules" id="heading-pathname-manipulation-bypassing-reverse-proxies-and-load-balancers-security-rules"></a>

来自[此研究](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies)的技术。

Nginx 规则示例：

```plaintext
location = /admin {
deny all;
}

location = /admin/ {
deny all;
}
```

为了防止绕过，Nginx在检查之前执行路径规范化。然而，如果后端服务器执行不同的规范化（删除Nginx不删除的字符），可能会绕过此防御。

### **NodeJS - Express**

| Nginx版本 | **Node.js绕过字符**        |
| ------- | ---------------------- |
| 1.22.0  | `\xA0`                 |
| 1.21.6  | `\xA0`                 |
| 1.20.2  | `\xA0`, `\x09`, `\x0C` |
| 1.18.0  | `\xA0`, `\x09`, `\x0C` |
| 1.16.1  | `\xA0`, `\x09`, `\x0C` |

### **Flask**

| Nginx版本 | **Flask绕过字符**                                                  |
| ------- | -------------------------------------------------------------- |
| 1.22.0  | `\x85`, `\xA0`                                                 |
| 1.21.6  | `\x85`, `\xA0`                                                 |
| 1.20.2  | `\x85`, `\xA0`, `\x1F`, `\x1E`, `\x1D`, `\x1C`, `\x0C`, `\x0B` |
| 1.18.0  | `\x85`, `\xA0`, `\x1F`, `\x1E`, `\x1D`, `\x1C`, `\x0C`, `\x0B` |
| 1.16.1  | `\x85`, `\xA0`, `\x1F`, `\x1E`, `\x1D`, `\x1C`, `\x0C`, `\x0B` |

### **Spring Boot**

| Nginx版本 | **Spring Boot绕过字符** |
| ------- | ------------------- |
| 1.22.0  | `;`                 |
| 1.21.6  | `;`                 |
| 1.20.2  | `\x09`, `;`         |
| 1.18.0  | `\x09`, `;`         |
| 1.16.1  | `\x09`, `;`         |

### **PHP-FPM**

Nginx FPM配置：

```plaintext
location = /admin.php {
deny all;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
```

Nginx 被配置为阻止访问 `/admin.php`，但可以通过访问 `/admin.php/index.php` 来绕过此限制。

### 如何防止

```plaintext
location ~* ^/admin {
deny all;
}
```

## 绕过 Mod 安全规则 <a href="#heading-bypassing-aws-waf-acl" id="heading-bypassing-aws-waf-acl"></a>

### 路径混淆

[**在这篇文章中**](https://blog.sicuranext.com/modsecurity-path-confusion-bugs-bypass/)解释了 ModSecurity v3（直到3.0.12版本）\*\*不正确地实现了`REQUEST_FILENAME`\*\*变量，该变量应该包含访问的路径（直到参数的开始）。这是因为它执行了URL解码以获取路径。\
因此，在 mod 安全中，像`http://example.com/foo%3f';alert(1);foo=`这样的请求将假定路径只是`/foo`，因为`%3f`被转换为`?`结束了URL路径，但实际上服务器收到的路径将是`/foo%3f';alert(1);foo=`。

变量`REQUEST_BASENAME`和`PATH_INFO`也受到了这个错误的影响。

在 Mod 安全的第2版中也发生了类似的情况，允许绕过防止用户访问与备份文件相关的特定扩展名文件（如`.bak`）的保护，只需发送点URL编码为`%2e`，例如：`https://example.com/backup%2ebak`。

## 绕过 AWS WAF ACL <a href="#heading-bypassing-aws-waf-acl" id="heading-bypassing-aws-waf-acl"></a>

### 格式错误的标头

[这项研究](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies)提到，可以通过发送一个AWS无法正确解析但后端服务器可以解析的“格式错误”标头来绕过应用于HTTP标头的AWS WAF规则。

例如，发送以下带有SQL注入的请求标头X-Query：

```http
GET / HTTP/1.1\r\n
Host: target.com\r\n
X-Query: Value\r\n
\t' or '1'='1' -- \r\n
Connection: close\r\n
\r\n
```

在过去，可以绕过AWS WAF，因为它无法理解下一行是标头值的一部分，而NODEJS服务器可以（已修复）。

## 参考资料

* <https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies>
* <https://blog.sicuranext.com/modsecurity-path-confusion-bugs-bypass/>

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

{% embed url="<https://websec.nl/>" %}

<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)
* 发现[**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>
