Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 2 min read

A patch isn't one task. It's an inventory.

When PHP2Shell was disclosed on October 21, I expected an afternoon of package updates. It took five days. The fix itself was simple. The problem was that "our PHP" was seven services running four different versions, e

When PHP2Shell was disclosed on October 21, I expected an afternoon of package updates.

It took five days.

The fix itself was simple. The problem was that "our PHP" was seven services running four different versions, each installed its own way.

What we actually had

Service PHP Fix
Service A 8.2 mitigation on 8.2
Service B 8.4 runtime update to 8.4.27
Service C 8.5 moved to 8.5
Service D 8.5 moved to 8.5
Service E 8.2 runtime upgrade to 8.2.35
Service F 8.3 Docker image pinned to 8.3.36
Site builds 8.2 build images pinned to 8.2.35

Four PHP lines, installed different ways: runtimes, Docker images, build images. No single command updates all of that.

One fix even went in twice: we first opened a PR pinning a patched Docker image, then closed it and updated the runtime instead.

"Updated" isn't "patched"

A package manager tells you what's installed. An attacker cares about what's running. Those drift apart in a few predictable places:

  • Long-running processes. PHP-FPM pools keep running the old binary until they restart.
  • Containers. The host is patched, the image isn't.
  • Build images. CI keeps producing new deploys on an old base image.
  • The forgotten box. The small internal app nobody remembers until you search.

The checklist I use now

Run these per server or container. The point is to compare what's on disk with what's running.

# 1. Version on disk
php -v | head -1
php-fpm -v 2>/dev/null | head -1   # can differ from the CLI

# 2. Are running FPM processes older than the patch?
ps -eo pid,lstart,args | grep '[p]hp-fpm'

# 3. Still running a binary or extension that was replaced on disk? (Linux, needs sudo)
sudo ls -l /proc/*/exe 2>/dev/null | grep 'php.*deleted'      # the PHP binary itself
sudo grep -l 'php.*(deleted)' /proc/*/maps 2>/dev/null         # extensions and libraries loaded into it

# 4. Containers: which PHP is inside each one?
for c in $(docker ps -q); do
  echo "$(docker inspect -f '{{.Name}} {{.Config.Image}}' $c): $(docker exec $c php -r 'echo PHP_VERSION;' 2>/dev/null)"
done

# 5. Build images: what base do new deploys use?
grep -rn "^FROM .*php" --include=Dockerfile* .

If check 3 prints anything, that process is still running the old PHP. Restart the pool. Run it with sudo: without it you can't read other users' processes (the FPM master runs as root, workers as www-data), the errors are hidden, and an empty result looks like a clean one. It also only finds processes that got a new binary and weren't restarted. A container that never got the new image has nothing deleted to find, which is what check 4 is for.

Then test the paths that matter. For a store that means checkout and payments, end to end, not just "the homepage loads".

What I'd do before the next one

  • Keep a list: every service, its PHP version, how it runs (server, container, build image), who owns it.
  • Pin versions explicitly in Dockerfiles and CI. "php:8.2" moves; "php:8.2.35" doesn't.
  • Make "restart and verify" part of the patch, not a follow-up.

A patch isn't one task. It's an inventory. You either build the list before the CVE, or you build it during the incident.

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.