cPanel Malware Scanner: What ClamAV Finds and Misses
A clean ClamAV result on a cPanel server means less than most people assume. Here is how to run the scan well and what to check afterwards.
The cPanel malware scanner most admins reach for is the ClamAV plugin behind cPanel's Virus Scanner page. It is free, it is a sensible first check, and it can give false comfort if you read too much into a clean result. ClamAV is good at recognising known files. Website compromises often involve a few custom lines of PHP pasted into a file that was fine yesterday, so it pays to know how to run the scan properly and what to look at next.
Install the scanner in WHM
Go to WHM, then cPanel, then Manage Plugins, and click Install for ClamAV Scanner. The same plugin powers the Virus Scanner interface in each customer's cPanel, as long as the Exim Mail Server service is enabled. You can turn that interface on or off in Feature Manager. ClamAV holds its signature database in memory while it runs, so check free RAM first on a small server.
Customers can then scan their mail folders, whole home directory, public FTP space or public web space on demand. That is handy for a single account. For a whole server you will want the command line.
Scan one account from the command line
On cPanel servers the ClamAV tools normally sit in /usr/local/cpanel/3rdparty/bin/. Confirm that on your system and refresh the signatures before you scan.
ls -l /usr/local/cpanel/3rdparty/bin/clamscan /usr/local/cpanel/3rdparty/bin/freshclam
/usr/local/cpanel/3rdparty/bin/freshclam
Scanning a busy shared server at full speed will slow every site on it, so run at low priority. This example checks one account's web files and writes a report.
mkdir -p /root/malware-scans
nice -n 19 ionice -c3 /usr/local/cpanel/3rdparty/bin/clamscan -r -i -l /root/malware-scans/USERNAME.log /home/USERNAME/public_html
echo "exit code: $?"
-r makes the scan recursive, -i prints only infected files and -l saves the report. Note where the data lives before you widen the path. Addon domains may sit outside public_html, in which case scan the whole home directory and exclude mail with --exclude-dir='/mail/', which takes a regular expression.
Scan every account, and track what did not finish
A loop over /etc/trueuserdomains gives you each cPanel user once. The part that matters is recording the exit code per account, because clamscan has three outcomes and only one of them means clean.
C=/usr/local/cpanel/3rdparty/bin/clamscan
mkdir -p /root/malware-scans
for u in $(awk '{print $2}' /etc/trueuserdomains | sort -u); do
h=$(getent passwd "$u" | cut -d: -f6)
[ -d "$h" ] || continue
nice -n 19 ionice -c3 "$C" -r -i --exclude-dir='/mail/' -l "/root/malware-scans/$u.log" "$h" > /dev/null 2>&1
echo "$u $?" >> /root/malware-scans/summary.txt
done
awk '$2 != 0' /root/malware-scans/summary.txt
| Exit code | Meaning | What to do |
|---|---|---|
| 0 | No virus found | Move on, and remember this only covers known signatures |
| 1 | Virus or malware found | Read that account's log and investigate each file |
| 2 | Some errors occurred | Treat the account as not checked. Read the log and scan again |
Run a job like this in screen or tmux, since it can take hours on a large server. Add it to cron only after you have seen what it does to the load.
Handle what it finds
-
1
Do not delete yet
A flagged file may be part of a working plugin. Some detections are false positives, and removing the wrong one breaks a customer's site. The checks in cPanel Malware Scan False Positive? will help you decide.
-
2
Keep a copy outside the web root
A malicious file is evidence. Its timestamp and contents can tell you when the attack happened and what it was after.
-
3
Find the entry point
Check the access logs around the file's modification time and review the account's plugins. Cleaning without closing the hole means doing all of this again next week.
-
4
Check the rest of the account
Attackers rarely leave one file. WordPress Hacked on cPanel? covers how to hunt for the rest.
Check what ClamAV is likely to miss
Signature scanners struggle with code written or obfuscated for one attack. A few quick checks often catch what the scan did not. These are searches, so read the results before you act on them. Plenty of legitimate software contains base64_decode, and it only looks alarming when wrapped around eval.
find /home/USERNAME/public_html/wp-content/uploads -type f -name '*.php'
find /home/USERNAME/public_html -type f -name '*.php' -mtime -7
grep -rlE 'eval\s*\(\s*(base64_decode|gzinflate|str_rot13)' --include='*.php' /home/USERNAME/public_html
For WordPress, comparing files against the official release is even stronger, and WP-CLI checksums make that a one-line job. If you want a second engine aimed at web threats, ClamAV vs Maldet explains how the two work together.
The limit of any on-demand scan
Everything so far looks at files after they landed. Between two scans, an attacker has as long as they like, and a request that abuses a vulnerable plugin may not write a file at all. On a shared server you also need each finding tied to the right account, or a list of paths becomes a morning of detective work.
BashSecure for cPanel is built around that. WHM gets a server view, and every finding stays tied to its cPanel account, domain, file and request. It examines file contents rather than trusting extensions and watches new files in real time. Live Defense can log or stop dangerous PHP behaviour while a request runs. Confirmed files go into reversible quarantine with their path, owner and permissions preserved, and an interrupted scan stays marked incomplete instead of being shown as clean.