Skip to content

Recovering from a defacement on cPanel — the clean-room restore

A clean-room restore procedure for a defaced cPanel account that does not just replace the index file and hope. Eight steps that close the entry point.

A customer’s homepage now reads “hacked by xyz crew.” The natural reflex is mv index.php index.php.bak; cp /backup/index.php . and move on. That works for ten minutes — until the attacker triggers their second-stage payload from the webshell you left behind. The clean-room restore takes more effort and ends with an account that cannot be reinfected the same way.

What’s happening

A defacement is the visible part of an account compromise. The webshell, the credential dump, and the persistence mechanism are still on the box. Restoring only the visible artifact leaves the underlying compromise in place. A clean-room restore moves the account to a fresh state with the entry point closed.

How to verify

ls -lt /home/<user>/public_html/ | head -20
find /home/<user>/public_html/ -name "*.php" -mtime -60 | head -30
whmapi1 listaccts | grep <user>
imunify-antivirus malware list --user <user>
grep "cwd=/home/<user>" /var/log/exim_mainlog | head

Establish a list of every recently-modified file, every malware detection on the account, and any outbound mail from suspicious paths.

The fix

The 8-step clean-room restore:

  1. Snapshot everything. tar czf /backup/incident/<user>-$(date +%Y%m%d-%H%M).tar.gz /home/<user> plus the access logs. This is your evidence; do not skip it.
  2. Identify the last-known-clean date. Ask the customer when they last saw the site working. Use the backup from one day before that date.
  3. Suspend the account to stop further damage. Postmortem-friendly workflow applies.
  4. Rename current public_html: mv /home/<user>/public_html /home/<user>/public_html.compromised. Do not delete — you may need it for forensic comparison.
  5. Create fresh public_html: mkdir /home/<user>/public_html && chown <user>:<user> /home/<user>/public_html.
  6. Restore from clean backup: tar xzf /backup/<user>-<known-clean-date>.tar.gz -C /home/<user>/public_html --strip-components=N (adjust strip-components based on your backup tarball structure).
  7. Rotate every credential: cPanel password, all mail account passwords, all FTP accounts, WordPress admin (if WP), database passwords (and update wp-config.php accordingly), any API keys stored in config files.
  8. Patch the entry: identify what was exploited (outdated plugin, weak password, etc.) and fix it before unsuspending. Run a fresh malware scan on the new public_html to confirm clean.

After all eight: unsuspend, monitor closely for 7 days, document the postmortem.

For environments where this should not happen in the first place, Stack Harbor handles compromise prevention and clean-room restores under cPanel server management.