PHP2Shell Zero-Day: How to Check If Your Server Was Hit Before the Patch
Amazon Threat Intelligence confirmed that attackers began exploiting the PHP2Shell vulnerabilities four days before the official security patches shipped on Wednesday. If you run PHP anywhere in your stack, the patch itself is no longer your only problem — you now need to assume your server may have been probed or compromised during that four-day exposure window. This guide gives you a concrete, step-by-step audit: how to identify the vulnerable versions, search your logs for exploitation attempts, and lock down PHP2Shell before attackers return.
The key takeaway up front: patching is step one, but log forensics is step two. Most admins will patch and move on. The ones who get breached are the ones who never checked whether the exploit already landed.
Step-by-Step: Audit and Remediate PHP2Shell
Follow these steps in order. Do not skip the log review — it tells you whether you’re patching a clean system or responding to an active incident.
Step 1: Identify Your PHP Version and Exposure
Run this on every host, container, and CI runner:
php -v
php -m | grep -i php2shell
Cross-reference the output against the vendor advisory. Any build older than the Wednesday patch release is in the exposed window. Build a quick inventory:
| Environment | Check Command | Vulnerable If |
|---|---|---|
| Bare metal / VM | php -v |
Version predates patch build |
| Docker | docker images | grep php |
Image tag older than patched tag |
| Kubernetes | kubectl get pods -o wide |
Any pod on stale image |
| Shared hosting | cPanel → MultiPHP Manager | PHP version not updated |
Step 2: Search Logs for Exploitation Attempts
The four-day pre-patch window is the critical period. Grep your web server and PHP logs for anomalous requests:
# Apache
grep -Ei "php2shell|shell_exec|passthru|proc_open" /var/log/apache2/access.log
# Nginx
grep -Ei "\.php\?.*(cmd|exec|shell)" /var/log/nginx/access.log
# PHP-FPM
grep -Ei "warning|error" /var/log/php*-fpm.log | grep -i "shell"
Look specifically for:
- Requests hitting
.phpendpoints with encoded payloads (%00,%2e%2e, base64 strings). - A spike in
POSTrequests to upload or file-manager scripts. - Outbound connections from your web user (
www-data) to unfamiliar IPs — a classic post-exploitation signal.
Step 3: Patch Immediately (and Verify)
Apply the vendor patch, then confirm the new build is live — a common failure is patching one node and forgetting the load-balanced siblings.
# Debian/Ubuntu
sudo apt update && sudo apt install --only-upgrade php
# RHEL/Alma/Rocky
sudo dnf upgrade php
# Docker
docker pull php:<patched-tag> && docker compose up -d
Step 4: Harden the PHP Config
Even patched, reduce the blast radius:
; php.ini
disable_functions = shell_exec,passthru,proc_open,popen,system,exec
expose_php = Off
allow_url_include = Off
open_basedir = /var/www:/tmp
Step 5: Rotate Secrets and Review Persistence
If logs show any successful exploitation, treat the host as compromised: rotate database credentials, API keys, and SSH keys, then check for rogue cron jobs, new users, and modified web roots.
What You Should Know About the Pre-Patch Exploitation Window
The four-day gap matters because detection tools keyed only to “is it patched?” will report clean on a machine that was already popped. A few practical realities:
- WAF rules are a stopgap, not a fix. If you can’t patch instantly, block the known PHP2Shell request signatures at the edge — but attackers rotate payloads, so this buys hours, not weeks.
- Container sprawl is the usual blind spot. Ephemeral CI runners and old Docker images frequently escape patch cycles. Rebuild images from a patched base rather than patching in place.
- Shared hosting users are at the mercy of the provider. If your host hasn’t updated MultiPHP, migrate or escalate — you cannot patch it yourself.
- Log retention is your evidence. If your logs roll over in under 7 days, you may have already lost the pre-patch window. Extend retention to 30+ days now.
For teams debating tooling: a lightweight file-integrity monitor (AIDE, Tripwire) plus centralized logging (Loki, ELK) catches post-exploitation behavior that a version check never will.
Frequently Asked Questions (FAQ)
What is PHP2Shell and why is it dangerous?
PHP2Shell is a set of PHP vulnerabilities that allow remote code execution through crafted requests. Because PHP powers a huge share of the web, unpatched instances are high-value targets — and Amazon’s data shows attackers weaponized it before the fix was public.
Was my server attacked during the four-day window?
You can only know by reviewing logs from that period. Grep access and PHP-FPM logs for encoded payloads, suspicious POST requests, and unexpected outbound connections from the web user. If logs are gone, assume exposure and rotate credentials.
Do I need to patch if I use a managed host?
Yes — verify it. Managed and shared hosts often lag. Check your PHP version directly with php -v and confirm it matches the patched build. If it doesn’t, open a ticket and demand an update timeline.
How do I know the patch actually applied?
Re-run php -v and compare the build date to the advisory. For containers, confirm the running image digest matches the patched tag — pulling the image isn’t enough if the old container is still running.
Final Verdict
Patching PHP2Shell is necessary but not sufficient. The four-day pre-patch exploitation window means your real job is a two-part response: patch every instance, then prove you weren’t already compromised. Start with the log grep in Step 2 — it takes ten minutes and tells you whether you’re doing maintenance or incident response. If you find hits, rotate secrets and rebuild from clean images. If you find nothing, extend log retention and add file-integrity monitoring so the next zero-day doesn’t catch you blind.