# Proxy / WAF Zaobilaženje zaštita {{#include ../banners/hacktricks-training.md}} ## Zaobilaženje Nginx ACL pravila pomoću Pathname Manipulation Tehnike [from this research](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies). Primer Nginx pravila: ```plaintext location = /admin { deny all; } location = /admin/ { deny all; } ``` Da bi sprečio zaobilaženja Nginx izvodi normalizaciju putanje pre nego što je proveri. Međutim, ako backend server izvrši drugačiju normalizaciju (uklanjajući karaktere koje nginx ne uklanja), može biti moguće zaobići ovu zaštitu. ### **NodeJS - Express** | Nginx verzija | **Node.js karakteri za zaobilaženje** | | ------------- | ------------------------------------- | | 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 verzija | **Flask karakteri za zaobilaženje** | | ------------- | ------------------------------------------------------------------ | | 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 verzija | **Spring Boot karakteri za zaobilaženje** | | ------------- | ----------------------------------------- | | 1.22.0 | `;` | | 1.21.6 | `;` | | 1.20.2 | `\x09`, `;` | | 1.18.0 | `\x09`, `;` | | 1.16.1 | `\x09`, `;` | ### **PHP-FPM** Nginx FPM konfiguracija: ```plaintext location = /admin.php { deny all; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; } ``` Nginx je konfigurisan da blokira pristup `/admin.php`, ali je moguće bypass ovog ograničenja pristupom `/admin.php/index.php`. ### Kako sprečiti ```plaintext location ~* ^/admin { deny all; } ``` ## Bypass Mod Security Rules ### Path Confusion [**In this post**](https://blog.sicuranext.com/modsecurity-path-confusion-bugs-bypass/) je objašnjeno da ModSecurity v3 (until 3.0.12), **improperly implemented the `REQUEST_FILENAME`** varijablu koja je trebalo da sadrži pristupljenu putanju (do početka parametara). Ovo je zato što je izvršavao URL decode da dobije putanju.\ Dakle, zahtev kao `http://example.com/foo%3f';alert(1);foo=` u mod security će pretpostaviti da je putanja samo `/foo` zato što se `%3f` transformiše u `?` koji završava URL putanju, ali zapravo putanja koju će server primiti biće `/foo%3f';alert(1);foo=`. Varijable `REQUEST_BASENAME` i `PATH_INFO` su takođe bile pogođene ovim bagom. Nešto slično se desilo u verziji 2 Mod Security koja je dozvoljavala zaobilaženje zaštite koja je sprečavala korisnika da pristupi fajlovima sa određenim ekstenzijama vezanim za backup fajlove (kao što je `.bak`) jednostavno slanjem tačke URL enkodovane kao `%2e`, na primer: `https://example.com/backup%2ebak`. ## Bypass AWS WAF ACL ### Malformed Header [This research](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies) pominje da je bilo moguće zaobići AWS WAF rules primenjivane na HTTP headers slanjem "malformed" headera koji nije bio pravilno parsiran od strane AWS, ali jeste od strane backend servera. For example, sending the following request with a SQL injection in the header 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 ``` It was possible to bypass AWS WAF because it wouldn't understand that the next line is part of the value of the header while the NODEJS server did (this was fixed). ## Generički WAF bypasses ### Ograničenja veličine zahteva Commonly WAFs have a certain length limit of requests to check and if a POST/PUT/PATCH request is over it, the WAF won't check the request. - Za AWS WAF, you can [**check the documentation**](https://docs.aws.amazon.com/waf/latest/developerguide/limits.html)**:**
Maksimalna veličina tela web zahteva koja može biti pregledana za Application Load Balancer i AWS AppSync zaštite8 KB
Maksimalna veličina tela web zahteva koja može biti pregledana za CloudFront, API Gateway, Amazon Cognito, App Runner, i Verified Access zaštite**64 KB
- From [**Azure docs**](https://learn.microsoft.com/en-us/azure/web-application-firewall/ag/application-gateway-waf-request-size-limits)**:** Older Web Application Firewalls with Core Rule Set 3.1 (or lower) allow messages larger than **128 KB** by turning off request body inspection, but these messages won't be checked for vulnerabilities. For newer versions (Core Rule Set 3.2 or newer), the same can be done by disabling the maximum request body limit. When a request exceeds the size limit: If p**revention mode**: Beleži i blokira zahtev.\ If **detection mode**: Pregleda do limita, ignoriše ostatak, i loguje ako `Content-Length` prekorači limit. - From [**Akamai**](https://community.akamai.com/customers/s/article/Can-WAF-inspect-all-arguments-and-values-in-request-body?language=en_US)**:** By default, the WAF inspects only the first 8KB of a request. It can increase the limit up to 128KB by adding Advanced Metadata. - From [**Cloudflare**](https://developers.cloudflare.com/ruleset-engine/rules-language/fields/#http-request-body-fields)**:** Up to 128KB. ### Static assets inspection gaps (.js GETs) Some CDN/WAF stacks apply weak or no content inspection to GET requests for static assets (for example paths ending with `.js`), while still applying global rules like rate limiting and IP reputation. Combined with auto-caching of static extensions, this can be abused to deliver or seed malicious variants that affect subsequent HTML responses. Practical use cases: - Pošaljite payloads u untrusted headers (npr. `User-Agent`) na GET ka `.js` putanji da izbegnete inspekciju sadržaja, pa odmah zatražite glavni HTML da utičete na keširanu varijantu. - Koristite fresh/clean IP; jednom kada je IP označen, promene u routingu mogu učiniti tehniku nepouzdanom. - U Burp Repeater-u, koristite "Send group in parallel" (single-packet style) da utrčite ta dva zahteva (`.js` zatim HTML) kroz isti front-end put. This pairs well with header-reflection cache poisoning. See: {{#ref}} cache-deception/README.md {{#endref}} - [How I found a 0-Click Account takeover in a public BBP and leveraged it to access Admin-Level functionalities](https://hesar101.github.io/posts/How-I-found-a-0-Click-Account-takeover-in-a-public-BBP-and-leveraged-It-to-access-Admin-Level-functionalities/) ### Obfuscation ```bash # IIS, ASP Clasic <%s%cr%u0131pt> == #changing the case of the tag < #prepending an additional "<" #using backticks instead of parenetheses java%0ascript:alert(1) #using encoded newline characters