Patched, Sure — But Were We Already Breached? A 10-Point Forensic Checklist with ssh and grep
What happened The day a critical PHP RCE vulnerability went public, we managed to patch our production e-commerce site within hours. I filed the report and thought I was done — until a question kept nagging at me: "Wh
What happened
The day a critical PHP RCE vulnerability went public, we managed to patch our production e-commerce site within hours. I filed the report and thought I was done — until a question kept nagging at me:
"What about the window between disclosure and patch? Were we already compromised?"
There's always a gap, even if only a few hours, between a vulnerability going public and your patch landing. "Patched" does not mean "not breached" — they are two separate lines in a report. But this is a small production server with no EDR and no forensic tooling. So I set myself constraints: ssh and grep only, strictly read-only, under one hour.
The approach — define ten numbers that should be zero
Working backwards from the traces an attacker would leave, I defined ten checks where a clean server should return zero. Everything is read-only, so it's safe to run on a live box.
1. Untracked PHP/shell files. If the site is under git, this is the fastest check:
git status --porcelain | grep -E '\.(php|sh)$'
A healthy site should have exactly one entry point: index.php.
2. PHP files modified since before the patch.
find . -newermt '2026-10-22 00:00' -name '*.php' \
-not -path './vendor/*' -not -path './var/*'
The only hits should be the files we changed ourselves.
3. Executables in upload/cache directories. A .php file in a directory that should only hold images is an instant red flag.
4. Classic webshell patterns.
grep -rlE 'eval\(\s*(base64_decode|gzinflate)|(system|passthru|shell_exec)\(\$_' \
--include='*.php' .
5. Cron. Check crontab -l for root, the deploy account, and apache, plus /etc/cron.d, for anything you don't recognize.
6. Processes. ps -u apache should show nothing but httpd / php-fpm.
7. Established connections. ss -tnp state established — anything besides 80/443/22/DB is suspicious.
8. Direct .php requests returning 200. On a framework-based site, a .php file hit directly (bypassing the rewrite) should never return 200.
zcat access_log-*.gz | awk '$7 ~ /\.php/ && $9 == 200' | wc -l
9. Top POST paths. POSTs should cluster on legitimate forms and APIs — nowhere else.
10. Dangerous strings in query strings. Grep the logs for php://, auto_prepend_file, allow_url_include, and phpinfo.
The gotchas — sudo, globs, and empty variables
The thing that cost me the most time wasn't attacker traces. It was shell behavior.
The log directory was root-only, so I wrote sudo zcat *access* — and got zero results. Brief panic ("the logs are gone!?") until I remembered: the glob expands as the regular user, before sudo runs. In a directory you can't read, it matches nothing. The fix is to run the whole script as root:
sudo bash -s <<'EOF'
cd /var/log/httpd
zcat *access*.gz | wc -l
EOF
Second trap: empty variables inside a heredoc. If F=$(ls ... | head -1) comes back empty, then tail -1 $F becomes a bare tail with no arguments — which silently eats stdin, i.e. the rest of your heredoc, and the script just stops. No error, exit code 0, partial output. Ever since, every variable gets a "${F:?}" existence check.
The result — all zeros
After checking one week of logs (25,584 requests) plus the filesystem, cron, processes, and connections across all ten items:
- Direct
.phpcalls returning 200: 0 (666 scan-looking requests, all 404) - Webshells detected: 0
- Unknown cron entries, processes, or outbound connections: 0
- Untracked or suspiciously modified files: 0
"Everything was zero" sounds like a non-result, but the zero itself is a line in the report. It let me write two separate statements: "we patched" and "we found no evidence of compromise during the disclosure-to-patch window." That's what the hour bought. (The mitigation we'd put in, session.upload_progress.enabled=Off, stays in place.)
Takeaways
- "Patched" and "not breached" are separate report items. You can't claim the second without checking.
- No expensive EDR needed: pick ten numbers that should be zero on a healthy server, and you have a post-incident check.
- All ten checks are read-only, so they're safe on a live production server.
- The real traps are in the shell: glob expansion happens before sudo, and an empty variable inside a heredoc can silently swallow the rest of your script.
Next time we handle a vulnerability, the patch ticket will include the ten-point post-check from the start.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.