r/SelfHosting • • 6d ago

Found out about the php2shell fixes from a hosting email. How do you keep track of PHP updates on servers you barely touch?

This is kind of embarrassing, but I didn't hear about the php2shell fixes from any process of my own, I heard about them from a hosting email. Then I spent an evening SSHing into boxes to work out which ones even run PHP.

A handful of small client sites on VPSes plus a couple of internal tools, all headless. Some are on distro packages, one is on a PPA, and one is a Docker image I haven't rebuilt in about a year, which I now realise means it never got the fix.

What do you actually do to stay on top of this? Automatic updates, some monitoring tool, a spreadsheet?

I'd like the next one to not be a surprise.

10 Upvotes

5 comments sorted by

2

u/Stock_Feedback_9648 6d ago

Three things cover most of it. 1) unattended-upgrades (or dnf-automatic), and add the PPA to its allowed origins, since by default it only takes the distro security pocket, so the PPA box would've missed the fix. 2) The Docker image is the real gap: nothing rebuilds it. A scheduled CI rebuild with --pull (weekly is plenty) plus Diun or Renovate to tell you when the base image changes solves that, and a Trivy scan of running images flags stale PHP. 3) A tiny inventory: ansible all -m shell -a 'php -v', or a cron script that writes php -v and package versions somewhere, tells you in seconds which boxes are affected next time. For the news side, your distro's security-announce list plus watching php/php-src releases on GitHub means you hear about it before the hosting email does.

3

u/siteflux 5d ago

the docker one is the sneaky one, if you never rebuild it you never get the base image patch. i'd pin the php version in a compose file and let a nightly watch check which containers are out of date, that kills the spreadsheet.

1

u/jaysuncle 5d ago

I have scripts that run every day checking for updates. I get status notifications from these scripts.

1

u/FarToe1 5d ago

It's a problem, even for a fulltime sysadmin. The amount and speed of critical disclosures is overwhelming and difficult to stay on top of, even with reading lots of websites, rss feeds, reddit and mailing lists. Noise to signal is huge.

Do at least this;

  1. Isolate. Don't expose anything to the internet unless you absolutely have to. Use VPNs, cloudflare tunnels with access controls etc if you need to access your stuff away from home. If you're serving content to the public, put it on its own VM/machine that's on a DMZ network so that if it does get pwned, it can't reach anything else.
  2. Update and reboot frequently. Make sure your services are robust and everything can survive frequent reboots. For internet facing machines, I do this daily, using a simple script called by cron. (Unattended-upgrades works well on debian and derivatives but it's easy to misconfigure so it's not giving the protection you think) A simple script might be "apt-get update, apt-get upgrade -y, reboot" and works on all linux distros. For non-DMZ machines, maybe weekly or fortnightly. There is an argument not to force reboot and to use needs-restart like monitoring, but that can still leave you on older kernels or can be bypassed by memory resident nasties. A reboot takes 2 minutes and if the machine is configured properly, everything just works afterwards. This does require you to be using a mainstream and well supported distro that pushes security updates promptly, and make sure you have security updates enabled in your repos if they're separate. Also don't forget packages installed using something other than your main package manager, so use those if you can when installing new software.

Those two things can remove a lot of pressure from you. It's nice to learn about these exploits and when you check, find your servers have already updated and are protected.

(Disclaimer: Updating frequently does carry a chance of picking up a nasty from a compromised supply-chain release, but generally distro packages are well checked. The risk seems to be more from non-repo installs; pip, npm etc. The bottom line is that no method is truly safe, so ensure you have good backups of what's important, including an offline one)

1

u/CollegeElectricalKid 2d ago

Distro packages plus unattended-upgrades covers most of it. The Docker image is the one that will bite you, because nothing updates it unless you rebuild, so put docker build pull on a schedule. I keep a tiny inventory file with every server, how PHP got there and which version it's on, plus a monthly reminder to run php -v everywhere. My client sites are on Contabo VPSes and their October email was clear that the host side was theirs and PHP on my box was mine, which is fair. Also worth knowing that 8.2 hits end of life on 31 December, so plan those jumps now.