ordinary Firstly, we followed all the steps advised by cpguard to make sure that nothing was left from the attack (that we know of). This may not be a fully comprehensive list and it would be great to hear if anyone can see gaps in what we did.
- We checked each server's cpguard update history to find out if we were affected - we were
- Based on the advice from cpguard, we looked for what the attacker had left behind
- We rotated what was exposed
-- Root and every local password
-- Root SSH private keys
-- Root shell history
-- MySQL root - Enhance uses socket authentication by default, so there's nothing to rotate here
-- Enhance API tokens - we changed this initially before deleting later
-- Root CA - Adam kindly offered to help do this
-- OPSSHIELD billing account - apparently customer records were taken, so we changed the password
These are the steps we took after that.
We took an inventory of our cluster (easier for us as we only have two servers)
-- Enhance roles i.e. web server, database, email, backup etc
-- Public IPv4 and IPv6
-- Firewalls in use including provider firewalls (for us that is Hetzner)
Record what cpguard was doing for us
-- IP whitelists and blacklists
-- Country blocks
-- WAF rules (if applicable)
-- Modules we had enabled
cPFence Licenses
-- We bought 2 licenses
Made sure we could get back into the servers
-- On Hertzner we have a dedicated server so we opened Robot on one tab, our control panel server is on a cloud server, so we opened Hetzner Console in another tab
Picked a quiet time
-- This will difficult for some as there is probably never a quiet time but for us, we picked a time during the night to make changes as the servers are unprotected for a few minutes and we needed to test things so didn't want to affect our client's businesses
Took backups
-- We took backups of client sites and a few other sensitive things that we would have hated to lose!
-- Uninstalling cpguard deletes its quarantine folder so we checked to make sure there was nothing in there that we might want back
Our order of work
We did the control panel server first and then the same steps with the secondary server. We finished the control panel server completely before moving on
Removal
We removed cpguard before installing cpfence so that there was no conflict. We downloaded the installer but we didn't follow cpguard's instructions completely, we split it so that we could see what it did before installing it
-- Downloaded without running:
cd /usr/local/src && curl -fsSL -o cpguard_uninstall.sh https://downloads.opsshield.com/cpguard/cpguard_uninstall.sh
-- Checked it
wc -l cpguard_uninstall.sh
grep -nE 'curl|wget|https?://|base64|eval|/dev/tcp|authorized_keys|shadow|.ssh' cpguard_uninstall.sh
-- Ran it
bash cpguard_uninstall.sh
-- Confirmed it was fully uninstalled
command -v cpgcli; ls /opt/cpguard /etc/cpguard 2>&1 | head -2
ls /etc/cron.d | grep -i cpg
pgrep -af 'cpg|cpguard' || echo "no cPGuard processes"
Checked sites were still loading
Installed cPFence
Installed on our control panel server first
Firewalls:
-- Provider firewall - we made sure that TCP 9095 is allowed from our office IP address (this is the port that cpfence's dashboard uses. Diffent setups might not need this and cpfence handles the server's own firewall
-- On our secondary server, we allowed TCP 9096 from the control panel server's IP addresses. This is how the cpfence dashboard is able to communicate with the secondary server
Downloaded and checked the installer:
cd /usr/local/src && curl -fsSL -o cpfence_install.sh https://api.cpfence.app/v4/install.sh
wc -l cpfence_install.sh
grep -oE 'https?://[a-zA-Z0-9./_-]+' cpfence_install.sh | sort -u
When we did this, we saw that the installer contacts api.cpfence.app
- Installed cpfence with the control panel licence key:
bash cpfence_install.sh -k cPFence-XXXXXXXXXXXXXXXX
We set where alerts will go and then checked status:
cpfence --set-email you@yourdomain.com
cpfence --status
Looked for License Active
Updated cpfence to the latest release which was 4.0.15. We have had conversations with cpfence and every package is signed and verified as of 4.0.15.
cpfence --check-updates
cpfence --update
Repeated this on the secondary server with it's license
Linked the cluster
Listed the cluster's Ip addresses with the cpfence helper on the control panel server:
curl -fsSL -o cpfence_whitelist.sh https://api.cpfence.app/whitelist_your_ips.sh
bash cpfence_whitelist.sh
Ran the add whitelist on the secondary server:
cpfence --add-whitelist-ip <IP address>
The control panel server does this bit for itself but the secondary servers don't, so we ran the commands the helper gave us on the secondary server.
- Whitelisted our own office IP
- We added our office IP on both servers so that cpfence's brute force protection wouldn't lock us out (it did, before we did this!)
cpfence --add-whitelist-ip <office IP>
Set up the cpfence dashboard (control panel server only)
cpfence --add-webui-ip <office IP>
cpfence --enable-webui
In System Settings > General Settings, we switched on "Restrict WebUI access to approved IPs"
We set up MFA under My account
-- Our panel hostname is behind Cloudflare, which doesn't pass port 9095, so we added a line to /etc/hosts on our own computers pointing the hostname at the server's IP
Tidied up
Deleted the downloaded scripts from /usr/local/src on both servers
Cancelled the cpguard licence and deleted cpguard's Enhance API token
Checked everything was working
Loaded several client sites, including a shop and a WordPress admin login
Checked the Enhance panel loaded and both servers showed as connected
Sent a test email from a site using an SMTP plugin
Ran the first malware scan (report only)
cpfence --full-scan
Auto quarantine is off by default, so the scan only reports. We reviewed the results before turning quarantine on
Reviewed the WordPress settings
WordPress cron: cpfence switches off WP-Cron, so we checked every site had a real cron job running wp-cli
Blacklisted plugins: we checked the list was empty, as cpfence uninstalls anything on it daily
Wordfence: we checked it could still write its firewall files (Wordfence > Tools > Diagnostics)
Ran the vulnerability report
Ours found 111 issues across 4 sites. Most cleared with a handful of plugin updates and by switching off two dormant sites
Alerts
Hetzner blocks outgoing mail on ports 25 and 465, so cpfence's alert emails weren't arriving. We're waiting for cpfence 4.0.16, which lets us use Google Workspace's SMTP relay without storing a password on the server