Security 5 min read

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.

By BashPilot Team
BashSecure Malware & vulnerability protection Scan, find and remove malware across every hosted account. Explore BashSecure

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.

find ClamAV and update signatures
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.

scan a single account gently
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.

server-wide scan with a summary
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 codeMeaningWhat to do
0No virus foundMove on, and remember this only covers known signatures
1Virus or malware foundRead that account's log and investigate each file
2Some errors occurredTreat 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. 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. 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. 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. 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.

PHP in uploads, recent changes and decode-and-run patterns
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.

Share LinkedIn X
Questions

Frequently asked questions

Does cPanel have a built-in malware scanner?

cPanel offers the ClamAV Scanner plugin, which you install from WHM's Manage Plugins page. Once it is installed, and the Exim service is enabled, customers get a Virus Scanner page that can scan mail, the home directory, public FTP space or public web space on demand.

Is Security Advisor in WHM a malware scanner?

No. Security Advisor runs a security scan of the server's configuration and advises you on issues such as missing brute force protection. cPanel's documentation does not describe it as checking files for malware, so use it alongside a malware scanner.

How do I scan all cPanel accounts for malware?

Loop over the users in `/etc/trueuserdomains`, run `clamscan -r -i` on each home directory at low priority with `nice` and `ionice`, and store each exit code. Code 0 means nothing was found, 1 means malware was found, and 2 means errors occurred, so that account needs another scan.

Why did ClamAV miss malware on my cPanel server?

ClamAV mainly recognises known signatures, while many website attacks use custom or obfuscated PHP. Add integrity checks against official releases, look for PHP files in upload folders, review recently changed files, and consider a scanner aimed specifically at web threats.

Should I use clamscan --remove on a hosting server?

Generally no. ClamAV's manual calls `--remove` generally a terrible idea outside something like an upload directory you are monitoring. A false positive can delete working code, and you lose the evidence. Review findings first, then move confirmed files out of the web root.

Put your servers on autopilot.

Connect a server in about a minute. The first week is on us.