# Proxy / WAF Koruma Bypass {{#include ../banners/hacktricks-training.md}} ## Nginx ACL kurallarını Pathname Manipulation ile Bypass Etme Teknikler [from this research](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies). Nginx kural örneği: ```plaintext location = /admin { deny all; } location = /admin/ { deny all; } ``` Bypass'ları önlemek için Nginx, yolu kontrol etmeden önce normalizasyon yapar. Ancak backend sunucu farklı bir normalizasyon (nginx'in kaldırmadığı karakterleri kaldırmak gibi) uyguluyorsa, bu savunma atlanabilir. ### **NodeJS - Express** | Nginx Sürümü | **Node.js Bypass Characters** | | ------------- | ----------------------------- | | 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 Sürümü | **Flask Bypass Characters** | | ------------- | -------------------------------------------------------------- | | 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 Sürümü | **Spring Boot Bypass Characters** | | ------------- | --------------------------------- | | 1.22.0 | `;` | | 1.21.6 | `;` | | 1.20.2 | `\x09`, `;` | | 1.18.0 | `\x09`, `;` | | 1.16.1 | `\x09`, `;` | ### **PHP-FPM** Nginx FPM yapılandırması: ```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` erişimini engelleyecek şekilde yapılandırılmıştır ancak `/admin.php/index.php` yoluna erişilerek bu engel atlatılabilir. ### Nasıl önlenir ```plaintext location ~* ^/admin { deny all; } ``` ## Mod Security Kurallarını Aşma ### Yol Karışıklığı [**Bu yazıda**](https://blog.sicuranext.com/modsecurity-path-confusion-bugs-bypass/) ModSecurity v3 (3.0.12'ye kadar) sürümünde, erişilen yolu (parametrelerin başlangıcına kadar) içermesi gereken `REQUEST_FILENAME` değişkeninin **uygunsuz şekilde uygulandığı** açıklanıyor. Bu, yolu elde etmek için bir URL decode işlemi gerçekleştirdiği içindir.\ Bu yüzden, mod security'de `http://example.com/foo%3f';alert(1);foo=` gibi bir istek, `%3f` `?`'ye dönüştüğü için yolun sadece `/foo` olduğunu varsayar (bu URL yolunu sonlandırır), oysa sunucunun alacağı gerçek yol `/foo%3f';alert(1);foo=` olacaktır. `REQUEST_BASENAME` ve `PATH_INFO` değişkenleri de bu hatadan etkilendi. Benzer bir durum Mod Security'nin 2. sürümünde de meydana geldi; bu, kullanıcıların yedek dosyalarla ilişkili belirli uzantılara sahip dosyalara (ör. `.bak`) erişmesini engelleyen bir korumayı, noktanın URL encode edilmiş hali `%2e` gönderilerek atlamaya izin veriyordu; örneğin: `https://example.com/backup%2ebak`. ## AWS WAF ACL'yi Aşma ### Hatalı Header [Bu araştırma](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies) AWS tarafından doğru şekilde parse edilmeyen ancak backend sunucu tarafından parse edilen "malformed" bir header göndererek HTTP header'ları üzerinde uygulanan AWS WAF kurallarını atlamanın mümkün olduğunu belirtiyor. Örneğin, X-Query header'ında bir SQL injection bulunan aşağıdaki isteği göndermek: ```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). ## Genel WAF bypass'ları ### İstek Boyutu Limitleri Genellikle WAF'lerin kontrol ettikleri isteklerde belirli bir uzunluk limiti vardır ve bir POST/PUT/PATCH isteği bu limiti aşarsa, WAF isteği kontrol etmez. - For AWS WAF, you can [**check the documentation**](https://docs.aws.amazon.com/waf/latest/developerguide/limits.html)**:**
Maximum size of a web request body that can be inspected for Application Load Balancer and AWS AppSync protections8 KB
Maximum size of a web request body that can be inspected for CloudFront, API Gateway, Amazon Cognito, App Runner, and Verified Access protections**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**: Logs and blocks the request.\ If **detection mode**: Inspects up to the limit, ignores the rest, and logs if the `Content-Length` exceeds the 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) Bazı CDN/WAF katmanları, `.js` ile biten yollar gibi statik varlıklar için yapılan GET isteklerinde zayıf veya hiç content inspection uygulamayabilir; buna karşın rate limiting ve IP reputation gibi global kuralları uygulamaya devam edebilir. Statik uzantıların auto-caching ile birleştiğinde, bu durum sonraki HTML cevaplarını etkileyen kötü amaçlı varyantların teslim edilmesi veya tohumlanması için kötüye kullanılabilir. Pratik kullanım örnekleri: - İçerik denetiminden kaçınmak için `.js` yoluna yapılan bir GET'de güvensiz header'lara (ör. `User-Agent`) payload gönderin, ardından cachelenmiş varyantı etkilemek için hemen ana HTML'i isteyin. - Temiz/yeni bir IP kullanın; bir IP işaretlendikten sonra yönlendirme değişiklikleri tekniği güvenilmez hale getirebilir. - Burp Repeater'da, aynı front-end yolundan iki isteği (`.js` sonra HTML) yarıştırmak için "Send group in parallel" (single-packet style) kullanın. Bu, header-reflection cache poisoning ile iyi eşleşir. Bakınız: {{#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