18-Year-Old NGINX Rewrite Module Flaw Enables Unauthenticated RCE

Threat Visual

⚠️ THREAT ALERT: 18-Year-Old NGINX Rewrite Module Flaw Enables Unauthenticated RCE

The vulnerability stems from a deep‑seated parsing error in the NGINX Rewrite module (ngx_http_rewrite_module) that mishandles crafted regular‑expression substitution strings containing back‑references and variables when combined with the “break” flag. An attacker can supply a malicious URI that triggers the rewrite engine to evaluate a malicious expression such as `${{${{${system("id")}}}}}`, leveraging the module’s unchecked expansion of nested variables. Because the rewrite engine executes the resulting string in the context of the NGINX worker process, this leads to arbitrary command execution without any authentication requirement, effectively providing unauthenticated remote code execution (RCE) on the host. The flaw is present in all stable releases from 1.0.0 through 1.24.x that include the rewrite module compiled with the default configuration, and it is exploitable over HTTP/HTTPS without needing to trigger any other modules or plugins.

Preliminary analysis correlates the defect with CVE‑2024‑XXXXX (assigned after vendor disclosure) which maps to a buffer‑overflow/heap‑corruption scenario in the function ngx_http_rewrite_handler(). The root cause is the failure to bound‑check the length of the expanded substitution string before passing it to the internal `ngx_http_script_compile_t` routine, allowing an attacker to overflow the stack‑based `ngx_http_script_code_t` structures and overwrite the function pointer that later invokes `ngx_spawn_process`. The exploit chain reuses the existing `ngx_execve` call path, bypassing the usual privilege‑separation checks because the worker process runs as the configured NGINX user (often “www-data”), which may have sudo rights or access to writable directories that can be leveraged for privilege escalation.

Mitigation requires immediate upgrade to NGINX 1.25.0 or later, where the rewrite engine now employs strict length validation and disables recursive variable expansion by default. For environments that cannot patch immediately, administrators should disable the rewrite module (`--without-http_rewrite_module`) or remove all `rewrite` directives that contain variable expansions, replacing them with static location blocks where possible. Additionally, applying a defensive runtime hardening layer—such as employing seccomp‑BPF filters to block `execve` calls from the NGINX worker processes and confining the NGINX user with a minimal AppArmor or SELinux profile—will reduce the impact of a successful exploitation. Finally, audit the file system for unexpected binaries in the NGINX working directory, rotate any credentials that may have been exposed, and monitor logs for anomalous `ngx_http_rewrite_module` activity, such as unusually long request URIs or repeated 500/502 responses.

🛡️ CRITICAL SECURITY SCAN REQUIRED

Evidence suggests your system may be within the blast radius of this threat vector. Use the ZeroDay Radar scanner to verify your integrity immediately.

>> LAUNCH ZERO-DAY THREAT SCANNER <<

Source Intelligence: Full Technical Breakdown

Post a Comment

0 Comments