// ThreatHuntingLabs  ·  writeup

PHP2Shell: Tracing Web Server Exploitation — Hunt Lead

ThreatHuntingLabs Guided KQLZeekauditdLinux EDR TelemetryWiresharktshark

Case Context

A Hunt Lead on Threat Hunting Labs: a short investigation released alongside a live threat, in this case PHP2Shell, a pair of critical memory-handling flaws in PHP itself (CVE-2026-109618 and CVE-2026-109619) disclosed in October 2026.

Written under Threat Hunting Labs’ write-up pilot: this covers the investigation and what it found, not the lab’s questions or answers.

One Linux web server running Apache with PHP, flagged as compromised, and a short observation window. Six telemetry sources to work with: Linux EDR process and file events, auditd, Linux Sysmon, Zeek HTTP and connection logs, derived endpoint alerts and Suricata alerts, plus a redacted PCAP of the web traffic. A day after release THL added a seventh: Apache’s own access and error logs, extracted from the web container.

Hunt Lead environment: one compromised Linux web server and six log sources

Executive Summary

A single external client sent 30 multipart POST requests to the web service in well under a minute, in a fixed four-request cycle repeated every few seconds. Each cycle pushed PHP into a memory-exhaustion failure during request start-up, sent a small request carrying PHP’s session upload-progress field, then sent a payload request. Once the payload switched to a 4 KB body full of forged in-memory structures carrying a shell command, the Apache worker handling it stopped responding and, at the same moment, spawned a system shell that ran an identity-discovery command and wrote its output to disk. That happened five times; every command completed successfully. The server advertised PHP 8.4.26, one release before the first fixed 8.4 version. Read alone, the web logs show a run of requests with no response; the host telemetry shows code execution as the web user, and the PCAP shows how the exploit was put together. Nothing in the web-worker chains goes beyond proving execution: no download, no persistence and no lateral movement. The evidence matches the published descriptions of both PHP2Shell flaws, but it can’t prove which code path was hit.

Attack Flow

flowchart LR
    A(["External client"]) -->|~15 MB POST, 1,000+ fields| B["Apache + PHP 8.4.26 worker"]
    B -->|memory limit exhausted, fatal error| A
    A -->|small POST, session upload-progress field| B
    A -->|4 KB POST, forged structures + command| B
    B -.->|no response| A
    B -->|then segfaults| F["Worker crash"]
    B -->|worker spawns| C["System shell"]
    C -->|runs| D["Identity-discovery command<br/>exit code 0"]
    C -->|redirects output| E[("Output file on disk")]

The cycle repeats every few seconds; the last step lands five times.

How the Hunt Went

Starting from the host. The brief pointed at process execution, so I started with the EDR table and looked for any web or PHP worker launching a shell. That returned five rows straight away: the Apache worker starting a shell every few seconds, all with the same short command line. A web server should essentially never do this, so the rest of the hunt was about proving what those shells did and where the trigger came from.

Finding the source. With the shell times in hand I pivoted to the Zeek HTTP logs and summarised POST requests by client. Only one client showed up, and its 30 POSTs to the web service started just before the first shell launch and stopped just after the last. Shared timing is correlation, not a recorded link, so this placed the client at the scene rather than tying any single request to any single shell.

Following the process chain. The first query only went one generation deep. Filtering on the shells’ own children showed each one launching the same identity-discovery command, and the parent IDs lined up exactly with the five shell PIDs, giving five complete web-worker → shell → command chains. One detail worth remembering: the recorded process name for the shell didn’t match how the command line invoked it. Hunt queries need to match on what the sensor records, not on what the command line suggests.

Linking command to file. The shells’ command lines redirect the command’s output to a file, and a file-creation event carries the same process entity ID as the first shell, so the write is attributed directly to that shell rather than inferred from timing. Only one creation event exists even though all five shells write to the same path, which most likely means later runs overwrote an existing file. The EDR records the operation, not the contents, so the page can say output was written, not what it said.

Missing responses ≠ failure. The POSTs closest to the shell launches have no HTTP response status at all. On the web logs alone that looks like requests that never completed. The host disagrees: each command has an exit code of 0 in the EDR, and auditd independently records a successful execve for the same processes, with the two clocks a little out of step. auditd also records 13 Apache workers terminating abnormally across the same window, and the signals split cleanly. Five are segmentation faults (signal 11), and their PIDs are exactly the five Apache parents of the shells: each worker spawned its shell and then crashed. The other eight are aborts (signal 6). That explains the missing responses: the worker died after the command ran, not before.

auditd: five successful execve calls for the command, a few seconds apart, with the process details covered

auditd ANOM_ABEND records: 13 Apache worker crashes, alternating aborts (signal 6) and segmentation faults (signal 11) within seconds of each other

Into the PCAP

The logs proved what ran; the redacted PCAP of the same window shows how. With port 8080 decoded as HTTP, every request is a multipart POST to the same PHP page, and they fall into a strict four-step cycle:

StepRequestWhat the server did
1~15.6 MB body, well over 1,000 form fieldsWarned that max_input_vars was exceeded, then died with Allowed memory size of 8388608 bytes exhausted during request start-up, before any PHP script ran. 200 with the error page
2192 bytes: a fixed session ID plus a PHP_SESSION_UPLOAD_PROGRESS fieldNo response: PHP reports zend_mm_heap corrupted and the worker aborts (signal 6)
3~12.6 MB bodyThe same start-up memory exhaustion, at a different allocation size
4Small payload: the same session fields plus sprayed fieldsFirst two cycles (~90 KB, hundreds of numbered fields): 200 with session errors, one carrying an 11 KB session cookie made of the same 64-character session ID repeated ~178 times. Next five cycles (4,278 bytes): no response; the worker spawns a shell, then segfaults (signal 11)

All 30 POSTs in Wireshark by declared Content-Length: ~15.6 MB, 192 bytes, ~12.6 MB, then the grooming or 4,278-byte payload request, repeating every few seconds

Step 1's response: PHP/8.4.26 exceeds max_input_vars, then dies with a start-up memory-exhaustion fatal error before any script runs

What that looks like. Steps 1 and 3 force allocation failures in the middle of request parsing, which is exactly the condition the first PHP2Shell advisory describes. Step 2 uses the session upload-progress mechanism the second advisory’s mitigations target, and the corrupted session cookie in step 4’s early responses looks like state from one request bleeding into the next. I can’t prove from traffic alone how the two combine, or which flaw did the work; the lead’s own analysis is careful about that too.

The payload. The 4,278-byte requests carry fifteen identical 167-byte fields. In hex each one is a forged in-memory structure: small integer header fields, several hard-coded little-endian 0x7f… user-space addresses, and the shell command string at the end with its length stored just in front of it, the way PHP lays out its own strings. Hard-coded addresses would normally be fragile against ASLR, but Apache’s prefork workers are forked from one parent and share its memory layout, so addresses that work in one worker work in the next.

The first forged structure in a payload request: header fields, hard-coded 0x7f… addresses and a length byte, with the command string that follows covered

The grooming. The two ~90 KB requests before them are heap grooming. The second one carries 998 fields named a0000[0] upward, each holding sixteen x characters: the [0] makes PHP build a separate small array per field, packing the heap with hundreds of same-sized allocations so later objects land somewhere predictable. Add the session ID and upload-progress fields and it comes to exactly 1,000 inputs, PHP’s default max_input_vars, where the 15 MB requests deliberately blow straight past it. The grooming requests got normal responses; once the forged structures arrived, the workers stopped answering.

Heap-grooming request: the session hook fields followed by hundreds of a0000[0]-style array fields

Closing the gap between network and host. Two things tie the PCAP to the host far more tightly than “same client, same minute”:

There’s still no shared process ID between a packet and a process, so this stays correlation, but it’s about as strong as network-to-host correlation gets. Counting the gaps: 14 of the 30 requests never got a response, and auditd accounts for 13 of them. All eight upload-progress requests line up with the eight worker aborts and all five payloads with the five segfaults; the fourteenth, one of the large requests, has no matching crash record. Apache’s own logs explain that one (below).

Apache’s Own Logs

THL added the web container’s Apache logs after the lead went out, and they give the server’s side of the same burst: 17 access records and 21 error-log lines.

The error log counts the same crashes. Thirteen AH00052: child pid … exit signal lines, eight Abort (6) and five Segmentation fault (11), in exactly the order auditd recorded them. Before each of the eight aborts sits a bare zend_mm_heap corrupted: PHP’s own allocator noticed its heap had been damaged and called abort(). That lines up with the upload-progress request in step 2, so step 2 is where memory gets corrupted. The segfaults after the payloads have no heap message: those workers ran the shell before anything checked.

Apache error log: zend_mm_heap corrupted before each Abort (6), and Segmentation fault (11) exits after each payload

Two things that would trip up a careless join:

The access log closes the last gap. It holds 17 completed requests, all POST /index.php with status 200, one more than the 16 responses in the PCAP. The extra one is one of the last 15.6 MB requests (stream 24), which has no server packets at all in the capture. Apache answered it; the capture just didn’t record the reply. That makes the 14 missing responses 13 worker crashes plus one capture gap, with nothing unexplained. (The access records also carry a byte counter, but without the server’s LogFormat it can’t be read as request or response size, so I’ve left it alone.)

Techniques Encountered

TacticTechniqueWhere it showed up
Initial AccessT1190 Exploit Public-Facing ApplicationMemory-exhaustion, session upload-progress and forged-structure POSTs against a vulnerable PHP 8.4.26 web service
ExecutionT1059.004 Unix ShellApache worker spawning a system shell five times
DiscoveryT1033 System Owner/User DiscoveryEach shell running an identity check as the web user, output redirected to a file

Prioritising Findings: Pyramid of Pain

The client IP and the output filename sit at the bottom of the pyramid: both are trivial for an attacker to change on the next run, and the lead explicitly asks for a hunt that doesn’t depend on either. The top of the pyramid here is the behaviour: a web-facing worker process starting a shell, and that shell immediately running discovery. That relationship holds no matter which client sends the requests, which PHP2Shell variant is used, or where the output lands.

Detection Opportunities

What I Practiced

Credential

All five objectives answered with evidence; verified Hunt Lead badge earned 23 October 2026.

PHP2Shell Hunt Lead badge

Verify: https://www.threathuntinglabs.com/leads/php2shell/completed/426951d89c117cd50f81be2d43592637

The lead is free, including its researcher analysis and hunt pack: investigate PHP2Shell on Threat Hunting Labs.