2023-12-31 04:43:12 +00:00
# 代理 / WAF 保护绕过
2023-10-26 14:38:55 +00:00
< details >
2023-12-31 04:43:12 +00:00
< summary > < strong > 从零开始学习 AWS 黑客技术,成为< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS 红队专家)< / strong > < / a > < strong > ! < / strong > < / summary >
2023-10-26 14:38:55 +00:00
2023-12-31 04:43:12 +00:00
支持 HackTricks 的其他方式:
* 如果您希望在 **HackTricks 中看到您的公司广告** 或 **下载 HackTricks 的 PDF** ,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取 [**官方 PEASS & HackTricks 商品** ](https://peass.creator-spring.com )
* 发现 [**PEASS 家族** ](https://opensea.io/collection/the-peass-family ),我们独家的 [**NFT 集合** ](https://opensea.io/collection/the-peass-family )
* **加入** 💬 [**Discord 群组** ](https://discord.gg/hRep4RUj7f ) 或 [**telegram 群组** ](https://t.me/peass ) 或在 **Twitter** 🐦 上**关注**我 [**@carlospolopm** ](https://twitter.com/carlospolopm )**。**
* **通过向** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) 和 [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github 仓库提交 PR 来**分享您的黑客技巧**。
2023-10-26 14:38:55 +00:00
< / details >
2023-12-31 04:43:12 +00:00
## 绕过 Nginx ACL 规则 <a href="#heading-bypassing-nginx-acl-rules-with-nodejs" id="heading-bypassing-nginx-acl-rules-with-nodejs"></a>
2023-10-26 14:38:55 +00:00
2023-12-31 04:43:12 +00:00
Nginx 限制示例:
2023-10-26 14:38:55 +00:00
```plaintext
location = /admin {
deny all;
}
location = /admin/ {
deny all;
}
```
### NodeJS
< figure > < img src = "../.gitbook/assets/image (713).png" alt = "" > < figcaption > < / figcaption > < / figure >
2023-12-31 04:43:12 +00:00
* 由于Nginx将字符`\xa0`包含在路径名中,因此不会触发对`/admin` URI的ACL规则。结果, Nginx将HTTP消息转发到后端;
* 当Node.js服务器收到URI `/admin\x0a` 时,将删除字符`\xa0`,允许成功检索`/admin`端点。
2023-10-26 14:38:55 +00:00
| 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
2023-12-31 04:43:12 +00:00
Flask会从URL路径中移除字符`\x85`, `\xA0` , `\x1F` , `\x1E` , `\x1D` , `\x1C` , `\x0C` , `\x0B` 和`\x09`, 但NGINX不会。
2023-10-26 14:38:55 +00:00
< figure > < img src = "../.gitbook/assets/image (714).png" alt = "" > < figcaption > < / figcaption > < / figure >
| 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 <a href="#heading-bypassing-nginx-acl-rules-with-spring-boot" id="heading-bypassing-nginx-acl-rules-with-spring-boot"></a>
2023-12-31 04:43:12 +00:00
以下是通过在路径名末尾添加字符`\x09`或的ACL保护绕过演示:
2023-10-26 14:38:55 +00:00
< figure > < img src = "../.gitbook/assets/image (715).png" alt = "" > < figcaption > < / figcaption > < / figure >
| Nginx版本 | **Spring Boot绕过字符** |
| ------------- | --------------------------------- |
| 1.22.0 | `;` |
| 1.21.6 | `;` |
| 1.20.2 | `\x09` , `;` |
| 1.18.0 | `\x09` , `;` |
| 1.16.1 | `\x09` , `;` |
### PHP-FPM <a href="#heading-bypassing-nginx-acl-rules-with-php-fpm-integration" id="heading-bypassing-nginx-acl-rules-with-php-fpm-integration"></a>
2023-12-31 04:43:12 +00:00
考虑以下Nginx FPM配置:
2023-10-26 14:38:55 +00:00
```plaintext
location = /admin.php {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
```
2023-12-31 04:43:12 +00:00
可以通过访问 `/admin.php/index.php` 来绕过它:
2023-10-26 14:38:55 +00:00
< figure > < img src = "../.gitbook/assets/image (716).png" alt = "" > < figcaption > < / figcaption > < / figure >
2023-12-31 04:43:12 +00:00
### 如何防止 <a href="#heading-how-to-prevent" id="heading-how-to-prevent"></a>
为了防止这些问题,你必须在 Nginx ACL 规则中使用 `~` 表达式而不是 `=` 表达式,例如:
2023-10-26 14:38:55 +00:00
2023-12-31 04:43:12 +00:00
COPYCOPY
2023-10-26 14:38:55 +00:00
```plaintext
location ~* ^/admin {
deny all;
}
```
2023-12-31 04:43:12 +00:00
## 绕过 AWS WAF ACL 的行折叠技术 <a href="#heading-bypassing-aws-waf-acl-with-line-folding" id="heading-bypassing-aws-waf-acl-with-line-folding"></a>
2023-10-26 14:38:55 +00:00
2023-12-31 04:43:12 +00:00
通过使用以下语法, 可以在HTTP头中绕过AWS WAF保护, AWS WAF将无法理解X-Query头包含的是sql注入负载, 而后面的node服务器却能理解:
2023-10-26 14:38:55 +00:00
```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
```
## 参考资料
* [https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies ](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies )
< details >
2023-12-31 04:43:12 +00:00
< summary > < strong > 通过< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > 从零开始学习AWS黑客攻击! < / strong > < / summary >
支持HackTricks的其他方式:
2023-10-26 14:38:55 +00:00
2023-12-31 04:43:12 +00:00
* 如果您希望在**HackTricks中看到您的公司广告**或**下载HackTricks的PDF**,请查看[**订阅计划**](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 ) 或 [**telegram群组** ](https://t.me/peass ) 或在 **Twitter** 🐦 上**关注**我 [**@carlospolopm** ](https://twitter.com/carlospolopm )**。**
* **通过向** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) 和 [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github仓库提交PR来分享您的黑客技巧。
2023-10-26 14:38:55 +00:00
< / details >