PHP2Shell session memory exhaustion with session decode failure or upstream crash on nginx

This rule is part of a beta feature. To learn more, contact Support.

Goal

Detects PHP2Shell (CVE-2026-109618/109619) exploitation stages on an nginx host running PHP-FPM. A pre-script PHP memory exhaustion accompanied by a session subsystem error, a session decode failure, or an upstream worker crash on the same host and service signals an exploit attempt.

Strategy

This rule monitors nginx error logs for PHP messages relayed from PHP-FPM workers. PHP2Shell is a memory-safety vulnerability in PHP’s multipart and session upload-progress handling that leads to remote code execution.

  • In the arm stage, a large multipart POST exhausts memory_limit before any script runs, so PHP logs Allowed memory size of ... exhausted with the location in Unknown on line 0 instead of a script path. A Failed to decode session object warning often follows.
  • In the fire stage, a second request crashes the PHP-FPM worker, and nginx logs upstream prematurely closed connection. Ordinary out-of-memory errors name the script and line that ran out of memory, so a pre-script memory failure is rare on its own.

The rule raises signals with different levels of severity, depending on the situation:

  • Critical: The memory failure occurs on the same host and service, within five minutes, as a PHP session subsystem error that was raised before any script ran. This error can be a failure to read or write session data, or a rejected session ID, each ending in Unknown on line 0. This pairing matches crash-free exploit chains that keep the worker alive and never corrupt cross-request session state, so they produce neither a worker crash nor a session decode failure.
  • High: The memory failure and the session decode failure occur together.
  • Medium: The memory failure and an upstream worker crash occur together.

Triage & Response

  • Examine the raw nginx error lines for the memory failure and the crash on {{host}}, and extract the client: address and request: line embedded in the FastCGI sent in stderr message.
  • Review nginx access logs on {{host}} around the signal for large multipart POST requests from that client, especially requests that returned 500 or 502.
  • Determine whether the memory failure came from a legitimate oversized upload by checking the request path, the client, and whether {{service}} normally accepts large file uploads.
  • Review any PHP session subsystem errors (Failed to read session data, Failed to write session data, or Session ID is too long or contains illegal characters) on {{host}}, and distinguish a misconfigured session.save_path, which raises these warnings on their own, from warnings that appear only in the same request as the memory failure.
  • Check whether the PHP-FPM workers on {{host}} were restarted or crashed repeatedly, and compare the timing with the requests from the same client.
  • Identify the PHP version running on {{host}} and verify whether it includes the fix (8.5.12, 8.4.27, 8.3.36 or 8.2.35).
  • Inspect the host for signs of successful exploitation, such as child processes spawned by PHP-FPM workers, in-memory executables, new files owned by the web server user, or unexpected outbound connections.