Skip to content

Scanning and cleaning malware on a cPanel account — a repeatable runbook

A step-by-step runbook for finding and removing malware from a cPanel account: scan with the server tools, identify injected files and backdoors, clean safely, and verify the account is clear.

When an account is flagged as infected — by a customer report, a blocklist warning, a spam complaint, or a scanner alert — the work is methodical, not heroic. A repeatable runbook beats ad-hoc cleanup: scan with the server’s tools, separate real malware from false positives, remove the injected code and the backdoor that planted it, reset what the attacker may have touched, and verify before declaring the account clean. The discipline that matters most is doing things in order, because cleaning files while leaving a backdoor or a cron job means the account reinfects within days.

What’s happening

Malware on a cPanel account usually takes a few recognizable forms: injected code added to legitimate PHP files (a base64/eval block at the top of index.php), standalone backdoor scripts (web shells with innocuous names dropped in uploads or the docroot), spam/SEO doorway generators, and persistence mechanisms (a cron job or a modified .htaccess/wp-config.php that re-deploys the payload). The visible damage — defacement, spam, blocklisting — is downstream of these.

cPanel servers commonly run a scanner: ImunifyAV (free) or Imunify360 (paid, with active protection), and ClamAV is available as a WHM plugin. These flag suspicious files but they are leads, not verdicts — scanners produce false positives, especially on minified JS and legitimate obfuscation. The reliable approach combines a scanner pass with manual confirmation (recently modified files, known injection signatures) and ends with replacing application code from clean sources rather than hand-editing every infected file. Because cleanup can delete files, every run starts with a backup.

How to verify

Start with a backup, then run the server scanner and a manual sweep in parallel:

# Always: capture the account before cleanup (files + DB)
/scripts/pkgacct <cpaneluser>            # full account backup to /home

# ImunifyAV / Imunify360 on-demand scan of one account
imunify-antivirus malware on-demand start --path /home/<cpaneluser>
imunify-antivirus malware malicious list | grep <cpaneluser>

# Or ClamAV directly
clamscan -ri --no-summary /home/<cpaneluser>/public_html

Run the manual checks that catch what signature scanners miss — recent changes and injection signatures:

# Files modified in the last 7 days (attackers leave fresh timestamps)
find /home/<cpaneluser>/public_html -type f -name '*.php' -mtime -7 \
  -printf '%TY-%Tm-%Td %p\n' | sort

# Common web-shell / injection signatures
grep -rIlE 'eval\(|base64_decode\(|gzinflate\(|str_rot13\(|assert\(|system\(|shell_exec\(|passthru\(' \
  /home/<cpaneluser>/public_html --include='*.php' | head -40

Check the persistence layer and CMS integrity so cleanup is not undone:

# Persistence: cron and prepend directives
crontab -l -u <cpaneluser>
grep -niE 'auto_prepend|auto_append' /home/<cpaneluser>/public_html/.htaccess

# WordPress: what was tampered with?
cd /home/<cpaneluser>/public_html
wp core verify-checksums --allow-root
wp plugin verify-checksums --all --allow-root
wp user list --role=administrator --allow-root

The scanner’s malicious list plus the find/grep hits give you the file list; verify-checksums shows exactly which application files were altered; the cron and auto_prepend checks reveal persistence. Together these define the full scope before you delete anything.

The fix

  1. Back up the account first, even though it is infected — run /scripts/pkgacct <cpaneluser> (or copy files + database off-server) before touching anything. You need it to recover mistaken deletions, trace the entry point, and document the incident. Cleanup without a backup risks turning an infection into data loss.
  2. Contain the account during cleanup — put the site in maintenance or restrict access to your operator IP via .htaccess, so the attacker is not re-injecting while you work and visitors are not served malware mid-clean. For a badly compromised account, suspending it in WHM is the cleanest containment.
  3. Replace application code from clean sources — do not hand-clean every infected core file. For WordPress, wp core download --force and reinstall all plugins/themes from official sources; verify-checksums told you what was altered. Replacing beats cleaning because it guarantees no injected fragment survives.
  4. Remove standalone backdoors and injected files — delete the web shells and rogue PHP surfaced by the scanner and the grep/find (unfamiliar files in uploads, randomly named PHP at the docroot). These are the reinfection vector; verify each against a known-good reference before deleting, but do not leave any behind.
  5. Kill the persistence layer — remove malicious cron entries (crontab -e -u <cpaneluser>), strip auto_prepend/auto_append injections from .htaccess, and clean injected rows from the database. Skipping this is the single most common reason a “cleaned” account comes back.
  6. Reset every credential and rotate keys — change cPanel, FTP, SSH, database, and CMS admin passwords, delete any admin account the attacker created, and rotate API keys. A leaked or reused credential is a frequent entry point; rotating closes the door you may not have located.
  7. Find and close the entry point — the malware got in somehow: an outdated plugin/theme, a writable upload path, or a stolen password. Use the timeline from find -mtime and the scanner to identify the likely vector and patch it, or the account will simply be reinfected through the same hole.
  8. Re-scan, verify, and request delisting — after cleanup, run the scanner again and confirm a clean result, re-run the manual find/grep, and watch for any reappearing files over the next day. If the account was blocklisted (Google Safe Browsing, an RBL), request review/delisting only once you have confirmed it is genuinely clean.

A clean account is one where the scanner is clear, the manual sweep finds nothing fresh, persistence is gone, and the entry point is closed — verify all four, not just the first. Stack Harbor runs malware cleanup and verification as a repeatable process under managed cPanel operations — start a conversation when an account needs cleaning.