ShieldPack SHIELD PACK
From 1401 onwards.

Where would you like to start?

Services, updates, and ways to contact us, all in one place

Pricing and orders →

Use the bot or chat with us—whichever you prefer

ShieldPack posts

phpAfterShell Explained: How Hackers Could Turn a PHP Session Flaw Into Code Execution

About 4 min read

A newly disclosed vulnerability in PHP’s default file‑based session handler, dubbed phpAfterShell, allows an attacker to inject arbitrary objects into a session file and potentially achieve code execution on a vulnerable server. The flaw, identified as CVE‑2026‑126714, has been assigned a CVSS 4.0 score of 9.2, marking it as critical. Security firm Depthfirst discovered the issue, reported it to the PHP maintainers, and confirmed that the vulnerability can be triggered by interrupting a session write at a precise moment, then leveraging a suitable gadget chain within the target application to run malicious code.
The fix is included in today’s PHP releases, most notably PHP 8.6.0, which empties the session file before each write and aborts the write if the emptying step fails. Earlier releases from October 21, which addressed two separate critical bugs known as PHP2Shell, do not contain the phpAfterShell patch. Servers that were updated on October 21 therefore remain exposed until the new versions are installed. The update also disables the upload‑progress feature by default, a setting that previously remained enabled in PHP 8.2.35 through 8.5.12 but is turned off in the patched 8.2.36, 8.3.37, 8.4.28, 8.5.13 and 8.6.0 builds.
The vulnerability resides in the way PHP writes session data to files. Each session entry is stored as a name followed by serialized data, with length fields indicating where strings end. When PHP writes a session file it locks the file but does not mark the write as completed. If the worker process dies mid‑write—such as from a hard memory‑limit failure in a threaded build—the file can retain a mixture of new and old data. By carefully crafting the length fields in the partially written data, an attacker can cause leftover bytes from the previous session to be interpreted as a separate serialized record, including an object. On the next request that invokes session_start(), PHP unserializes the record and instantiates the object.
Depthfirst’s proof‑of‑concept exploits the upload‑progress feature, which records file‑upload status in the user’s session. When upload progress is enabled, a multipart form upload triggers a session write before the application’s own code runs, providing a window for the attacker to interrupt the write. The attack does not require the attacker to be logged in; it merely needs a page that opens the session later. In the researchers’ tests, the malicious object appeared on the eleventh attempt after repeatedly forcing a mid‑write termination, illustrating the difficulty of achieving the exact timing required.
The injected object in the public demonstration is a harmless stdClass instance, but the same technique can be combined with a gadget chain in the target application to achieve arbitrary code execution. The researchers also disclosed a second bug—a memory‑corruption issue in a built‑in PHP class—that they used as a gadget chain in their own Linux tests. Details of that secondary bug are being withheld pending coordinated disclosure, and it is unclear whether today’s releases address it.
phpAfterShell Explained: How Hackers Could Turn a PHP Session Flaw Into Code Execution
The impact of phpAfterShell extends beyond remote code execution. By corrupting session data, an attacker could alter authentication state, permissions, or CSRF tokens before the application validates them, effectively hijacking user sessions or bypassing security checks. The flaw affects all PHP versions that still use the default file‑based session handler, including end‑of‑life releases 7.4, 8.0 and 8.1 if they are running unpatched builds. Official mitigation branches for those versions are not vulnerable, but older, unpatched binaries remain at risk.
Mitigation guidance from Depthfirst advises administrators who cannot immediately apply the update to disable upload progress by setting session.upload_progress.enabled to 0 in php.ini and restarting PHP workers. This step blocks the most common exploitation path but does not fully remediate the issue, as any other mechanism that allows attacker‑controlled data to be written into sessions could still be abused. Moving session storage to a backend that replaces records atomically—such as Redis or another database—also avoids the defect, though each alternative store must be evaluated for its own handling of interrupted writes.
Linux distribution packages may backport the fix without changing the PHP version number, so administrators should verify the presence of the patch rather than rely solely on the version string. The release notes do not explicitly call out the change, and sample php.ini files still contain the old upload‑progress setting in a commented line, meaning that hosting panels or custom configurations that re‑enable the feature will retain the vulnerability after upgrade.
In summary, phpAfterShell is a high‑severity flaw in PHP’s file‑based session handling that can be weaponized through a precise mid‑write interruption, most commonly via the upload‑progress feature. The vulnerability enables object injection and, when paired with an appropriate gadget chain, remote code execution, as well as session‑state manipulation. The immediate remedy is to upgrade to the latest PHP releases—starting with PHP 8.6.0—or apply the recommended configuration changes and consider alternative session stores. Organizations running legacy PHP installations should prioritize patching or migration, as the risk of exploitation remains significant despite no reported attacks to date.

Source: The Hacker News · Cybersecurity

ShieldPack media