گزارش آسیبپذیری NGINX Rift (CVE-2026-42945)
نویسنده: یاسین عابدینی · دسته: Vulnerability · تاریخ انتشار: ۱۴۰۵/۲/۲۴
گزارش تحلیلی: آسیبپذیری NGINX Rift (CVE-2026-42945)
خلاصه اجرایی
یک vulnerability بحرانی با قدمت ۱۸ سال در NGINX Rewrite Module شناسایی شده که امکان Remote Code Execution بدون احراز هویت را فراهم میکند. این آسیبپذیری با نام NGINX Rift و شناسه CVE-2026-42945 منتشر شده و با CVSS v4 score برابر 9.2 رتبهبندی شده است.
۱. مشخصات فنی Vulnerability
۱.۱ اطلاعات کلی
- CVE ID: CVE-2026-42945
- نام: NGINX Rift
- CVSS v4 Score: 9.2 (Critical)
- نوع: Heap Buffer Overflow
- Module آسیبپذیر:
ngx_http_rewrite_module - تاریخ افشا: ۱۴ می ۲۰۲۶ (۲۴ اردیبهشت ۱۴۰۵)
- Responsible Disclosure: ۲۱ آوریل ۲۰۲۶
- کاشف: depthfirst
۱.۲ ریشه مشکل (Root Cause)
آسیبپذیری در logic پردازش directives زیر در ngx_http_rewrite_module وجود دارد:
rewriteifset
سناریوی trigger:
زمانی که این directives با ترکیب زیر استفاده شوند:
- Unnamed PCRE captures مانند
$1,$2,$3 - Replacement string حاوی کاراکتر
?
مکانیزم Overflow:
Phase 1: محاسبه طول buffer
→ محاسبه اشتباه (کوچکتر از واقعیت)
Phase 2: Copy داده به buffer
→ داده واقعی بزرگتر از buffer تخصیصیافته
Result: Heap Buffer Overflow
این mismatch بین محاسبه و copy منجر به نوشتن خارج از محدوده heap allocation میشود.
۲. شرایط Exploitation
۲.۱ پیشنیازهای حمله
الزامی:
- Configuration حاوی
rewrite,ifیاsetdirective - استفاده از unnamed captures (
$1,$2, ...) - Replacement string شامل
? - دسترسی HTTP به NGINX server (بدون نیاز به authentication)
برای RCE کامل:
- ASLR غیرفعال یا ضعیف
- کنترل محتوای URI توسط attacker
- شرایط memory layout مناسب
۲.۲ مثال Configuration آسیبپذیر
location /api {
rewrite ^/api/(.*)$ /v1/$1?format=json break;
}
location /redirect {
if ($arg_path ~* "^(.+)$") {
set $target $1?redirect=true;
return 302 $target;
}
}
location /proxy {
set $backend_path $1?cache=off;
proxy_pass http://backend/$backend_path;
}
۲.۳ Attack Vector
GET /api/../../../../etc/passwd HTTP/1.1
Host: vulnerable-nginx.example.com
User-Agent: [crafted payload]
Attacker میتواند:
- URI را craft کند تا heap overflow trigger شود
- محتوای overflow را shape کند (چون از URI مشتق میشود)
- با repeated requests، worker process را در crash loop نگه دارد
- در صورت ASLR disabled، RCE کامل به دست آورد
۳. Impact و سطح خطر
۳.۱ تأثیرات فنی
حداقل Impact (همیشه):
- Denial of Service: crash و restart مکرر worker process
- Service Degradation: کاهش availability برای تمام siteهای serveشده
Maximum Impact (با شرایط مساعد):
- Remote Code Execution در worker process
- Memory Disclosure: خواندن memory محتوای worker
- Privilege Escalation: اجرای code با سطح دسترسی NGINX worker
۳.۲ Assetهای در معرض خطر
پس از compromise شدن NGINX instance:
Credential Exposure:
- SSL/TLS private keys
- Client certificates
- Upstream authentication tokens
- Session secrets
- API keys در configuration
Network Access:
- Pivot به backend network
- دسترسی به internal services
- Bypass کردن network segmentation
Data Interception:
- Man-in-the-middle روی تمام traffic
- Injection به responses
- Redirect کردن users
Persistence:
- نصب backdoor در edge layer
- Manipulation configuration
- Long-term access به infrastructure
۴. محصولات و نسخههای تحتتأثیر
۴.۱ NGINX Open Source
آسیبپذیر:
- نسخههای 0.6.27 تا 0.9.7 (بدون patch)
- نسخههای 1.0.0 تا 1.30.0
Fixed:
- 1.30.1+
- 1.31.0+
۴.۲ NGINX Plus
آسیبپذیر:
- R32 تا R36 (قبل از patch)
Fixed:
- R32 P6
- R36 P4
۴.۳ محصولات وابسته F5
| محصول | نسخههای آسیبپذیر |
|---|---|
| NGINX Instance Manager | 2.16.0 - 2.21.1 |
| F5 WAF for NGINX | 5.9.0 - 5.12.1 |
| NGINX App Protect WAF | 4.9.0 - 4.16.0, 5.1.0 - 5.8.0 |
| F5 DoS for NGINX | 4.8.0 |
| NGINX App Protect DoS | 4.3.0 - 4.7.0 |
| NGINX Gateway Fabric | 1.3.0 - 1.6.2, 2.0.0 - 2.5.1 |
| NGINX Ingress Controller | 3.5.0 - 3.7.2, 4.0.0 - 4.0.1, 5.0.0 - 5.4.1 |
۵. سناریوهای Exposure بالا
۵.۱ محیطهای پرخطر
Internet-Facing Reverse Proxies:
- CDN edge nodes
- API Gateways
- Load balancers عمومی
- WAF instances
Kubernetes Environments:
- Ingress Controllers (nginx-ingress)
- Gateway Fabric deployments
- Service mesh components
Enterprise Infrastructure:
- SaaS platforms با NGINX frontend
- Microservices architectures
- Multi-tenant environments
۵.۲ Configuration Patterns پرخطر
# Pattern 1: Dynamic routing با query parameters
rewrite ^/(.*)$ /$1?version=v2 break;
# Pattern 2: Conditional redirects
if ($http_user_agent ~* "(.+)") {
set $ua $1?tracked=yes;
}
# Pattern 3: Path manipulation
location ~ ^/old/(.*)$ {
rewrite ^ /new/$1?migrated=true permanent;
}
۶. آسیبپذیریهای همراه (Additional CVEs)
۶.۱ CVE-2026-42946 (CVSS 8.3)
- Module:
ngx_http_scgi_module,ngx_http_uwsgi_module - نوع: Excessive Memory Allocation
- شرط: AitM position +
scgi_passیاuwsgi_passconfigured - Impact: Memory disclosure یا worker restart
۶.۲ CVE-2026-40701 (CVSS 6.3)
- Module:
ngx_http_ssl_module - نوع: Use-After-Free
- شرط:
ssl_verify_client on/optional+ssl_ocsp on - Impact: محدود data modification یا worker restart
۶.۳ CVE-2026-42934 (CVSS 6.3)
- Module:
ngx_http_charset_module - نوع: Out-of-Bounds Read
- شرط:
charset+proxy_passبا buffering disabled - Impact: Memory disclosure یا worker restart
۷. راهکارهای Mitigation و Hardening
۷.۱ اقدامات فوری (P0)
۱. Patch Management:
# بررسی نسخه فعلی
nginx -v
# Upgrade به نسخه fixed
# Debian/Ubuntu:
apt update && apt install nginx
# RHEL/CentOS:
yum update nginx
# از source:
wget http://nginx.org/download/nginx-1.31.0.tar.gz
۲. Configuration Audit:
# جستجوی patterns آسیبپذیر
grep -r "rewrite.*\$[0-9].*?" /etc/nginx/
grep -r "set.*\$[0-9].*?" /etc/nginx/
grep -r "if.*\$[0-9].*?" /etc/nginx/
۳. Workaround موقت (اگر patch ممکن نیست):
تبدیل unnamed captures به named captures:
# قبل (آسیبپذیر):
rewrite ^/api/(.*)$ /v1/$1?format=json break;
# بعد (ایمن):
rewrite ^/api/(?<path>.*)$ /v1/$path?format=json break;
۷.۲ Detection و Monitoring
Log Analysis:
# جستجوی crash patterns
grep "worker process.*exited on signal" /var/log/nginx/error.log
grep "segmentation fault" /var/log/nginx/error.log
# بررسی URIs مشکوک
awk '$9 == 500 {print $7}' /var/log/nginx/access.log | sort | uniq -c
Runtime Monitoring:
# تعداد restart worker
systemctl status nginx | grep -i restart
# Memory usage anomalies
ps aux | grep nginx | awk '{print $6}'
۷.۳ Hardening برای Kubernetes
Ingress Controller Audit:
# بررسی annotations
kubectl get ingress -A -o yaml | grep -A5 "nginx.ingress.kubernetes.io/rewrite"
# بررسی ConfigMap
kubectl get configmap -n ingress-nginx ingress-nginx-controller -o yaml
Mitigation Steps:
# جایگزینی rewrite annotations
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
# قبل:
# nginx.ingress.kubernetes.io/rewrite-target: /$1?param=value
# بعد:
nginx.ingress.kubernetes.io/rewrite-target: /$path
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite ^/api/(?<path>.*)$ /v1/$path break;
۷.۴ Defense in Depth
۱. ASLR Enforcement:
# بررسی وضعیت ASLR
cat /proc/sys/kernel/randomize_va_space
# باید 2 باشد
# فعالسازی
echo 2 > /proc/sys/kernel/randomize_va_space
۲. WAF Rules:
# محدودسازی URI length
client_max_body_size 10m;
large_client_header_buffers 4 16k;
# Rate limiting
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req zone=api burst=20 nodelay;
۳. Segmentation:
# محدود کردن upstream access
upstream backend {
server 10.0.1.10:8080;
# فقط از internal network
}
# Deny direct access
location /internal {
internal;
proxy_pass http://backend;
}
۴. Secret Rotation:
پس از آپدیت Nginx حتما تمامی Secretr Key های آپدیت شوند
- SSL/TLS certificates
- Upstream credentials
- API tokens
- Session keys
۸. تست و Validation
۸.۱ بررسی Vulnerability
# تست configuration
nginx -t
# بررسی named captures
grep -E "rewrite.*\(\?<[a-z]+>" /etc/nginx/conf.d/*.conf
# Validation پس از patch
curl -I http://localhost/api/test
۸.۲ Regression Testing
# تست basic functionality
curl -v http://localhost/
curl -v http://localhost/api/endpoint
# تست rewrite rules
for path in /old/path /api/v1 /redirect; do
curl -I "http://localhost$path"
done