The short answer
Use cPanel’s Security Advisor and command line tools to scan files, look for suspicious code, and check for unknown cron jobs. Once identified, remove the files, update software and harden the server.
Why detecting malware matters
Malware can silently compromise a cPanel server, stealing credentials, injecting malicious scripts into sites, or using the server for spam and DDoS attacks. A compromised server also risks data loss, downtime, and damage to client trust. Small businesses and agencies rely on uptime and data integrity; any breach can lead to legal liabilities and lost revenue. Early detection is vital because malware often hides in user directories, alters PHP scripts, or creates hidden cron jobs. By spotting anomalies quickly, you can isolate infected accounts, remove malicious code, and restore clean backups before the attacker escalates privileges or spreads to other accounts.
# Example: list files modified in the last 24 hours in all accounts
find /home -type f -mtime -1 -print
# Example: check for suspicious cron jobs in /var/spool/cron
cat /var/spool/cron/*When reviewing the output, look for files with unfamiliar names, recent modification dates, or code that references external domains. In cron lists, watch for entries that call unknown binaries or use unusual scheduling patterns.
What to look for
Malware often leaves traces that differ from normal server files. Look for files with random or nonsensical names, especially in directories like /tmp, /var/tmp, public_html, or hidden folders such as .well-known. Check for scripts that were not part of your original website code, especially PHP files that contain base64‑encoded strings, eval calls, or references to external domains. Unexpected changes to configuration files, such as a new or modified .htaccess that adds redirects, rewrites, or disables security directives, are also strong signals of compromise.
Another common sign is the presence of unauthorized cron jobs. Review the crontab for each user (crontab -l) and system‑wide schedules in /etc/cron.*. Look for entries that run unknown scripts, use wget/curl to fetch remote code, or execute at unusual intervals. High CPU or memory usage, especially from web‑server processes, can indicate malicious scripts running in loops or mining cryptocurrency. Correlate spikes with log timestamps to pinpoint suspicious activity.
- Unknown files in web directories or temporary folders
- Modified
.htaccesswith unexpected redirects or disables - New or altered cron jobs running unknown scripts
- Unusual spikes in CPU or memory usage
- Outbound connections to unknown IP addresses
cat /etc/crontab; crontab -l; ls -lAh /tmp /var/tmp /home/*/public_html | grep -iE '\.php$|\.sh#x27;; grep -i 'eval\|base64_decode' -R /home/*/public_html/*.phpIf the commands list unknown scripts, altered cron entries, or files containing eval/base64 patterns, investigate those files further and consider isolating the affected account.
Using Security Advisor and cPanel tools
Log in to WHM and locate the Security Advisor under the "Security Center" menu. Click "Run Security Advisor" to let cPanel scan the system for known vulnerabilities, outdated packages, and suspicious files. The report will list any issues with clear severity levels and provide a one‑click fix option for many items. After the scan, open the "File Integrity" tool from the same Security Center. It compares current file checksums against the original cPanel baseline, highlighting any modified or unknown files that could be malicious.
Next, review the relevant logs for unusual activity. In WHM, go to "Metrics » Raw Access Logs" or use SSH to view the Apache error log, cPanel error log, and the mail log. Look for repeated 404 errors, unknown CGI executions, or login attempts from unfamiliar IPs. Filtering the logs with simple grep commands can surface anomalies quickly. Document any suspicious entries and correlate them with the files flagged by the File Integrity tool.
- Run Security Advisor from WHM > Security Center.
- Check File Integrity for altered core files.
- Search logs for repeated 404s, unknown scripts, or failed logins.
- Note file paths and timestamps of suspicious entries.
- Create a backup or snapshot before making changes.
grep -iE "error|failed|404" /usr/local/apache/logs/error_log | tail -n 50The Security Advisor output should show a clean status or list specific packages to update. In the File Integrity report, focus on files outside the standard cPanel directories or with unexpected timestamps. Log entries that reference those files or show repeated access attempts are strong indicators of compromise and should be investigated further.
Command line scanning steps
Use the find command to locate files with uncommon extensions or names that are often used by backdoors. For example, search for any PHP files that contain the string eval( or base64_decode(. Run the command from the root of the web document root to avoid scanning system files that could be critical. The output will list candidate files that you should examine with a text editor or grep to confirm malicious content. This step is safe and non‑destructive, but always keep a backup before making changes.
Next, use grep with a list of known suspicious patterns such as system(, exec(, shell_exec(, and passthru(. Combine this with -R for recursive search and -l to list only file names. The resulting list will show files that contain these patterns. You can then open each file to verify if the code is legitimate or a backdoor. This process is quick and does not modify any files, but it gives you a focused set of files to investigate further.
- Search for PHP files with uncommon extensions
- Look for eval() or base64_decode() usage
- Check for system() and exec() calls
# Find PHP files that contain eval or base64_decode
find /home/*/public_html -type f -name "*.php" -exec grep -lE "eval\(|base64_decode\(" {} +
# Recursively list files containing system() or exec()
grep -R -lE "system\(|exec\(|shell_exec\(|passthru\(" /home/*/public_htmlWhen reviewing the output, pay attention to files that are not part of your application code, have recent modification dates, or are located in unexpected directories. A single file containing suspicious functions is often enough to trigger a deeper investigation.
Removing and cleaning infected files
When you locate a malicious file on a cPanel server, the safest first step is to move it to a quarantine directory rather than delete it outright. Use mv /home/username/public_html/evil.php /home/username/quarantine/. This preserves the file for forensic analysis while removing it from the live site. Once verified as malware, delete the file with rm /home/username/quarantine/evil.php. Always double‑check the path before executing the command to avoid accidental loss of legitimate data.
After removal, restore any affected directories from a recent backup that predates the infection. Use cPanel’s backup manager or the command line rsync -a --delete /backup/path/ /home/username/public_html/. Verify file integrity with checksums or compare file sizes. Finally, ensure all software on the server is up to date: run yum update on CentOS or apt-get update && apt-get upgrade on Debian, and enable automatic security updates where possible. This closes the vulnerabilities that allowed the malware to spread.
What to avoid when cleaning
When you start a cleanup, avoid deleting files that belong to the operating system or cPanel itself. Removing or moving files such as /usr/bin, /etc/passwd, or the cPanel control panel binaries can render the server unusable and may trigger security alerts. Likewise, do not disable built‑in protections like ModSecurity, CSF, or the default Apache mod_deflate configuration. Turning off these layers removes a critical defense and can expose the site to further exploitation.
Another risky action is to delete or alter configuration files without a full backup. Files such as /etc/ssh/sshd_config, /etc/php.ini, or the Apache virtual host files control how the server authenticates users and serves content. Changing or removing these without a snapshot means you may lose access or break services, and a mis‑configured file can create new vulnerabilities. Always take a backup before making any changes and test the server in a staging environment if possible.
Keeping the server clean
Maintain a regular update schedule for the operating system, web stack, and all installed applications. Use the distribution's package manager to apply security patches promptly, and enable automatic updates where appropriate. Subscribe to vendor security mailing lists so you are aware of critical releases. In addition, run daily integrity checks with tools such as rkhunter or chkrootkit to spot unexpected changes in system binaries and configuration files. Keep a log of scan results and compare them over time to detect anomalies early.
Implement layered hardening measures to reduce the attack surface. Disable unused services, enforce strong password policies, and require key‑based SSH authentication with two‑factor support. Restrict file permissions to the minimum necessary and use mod_security or similar WAF rules for Apache/Nginx. Schedule regular backups and test restoration procedures. Finally, consider a lightweight host‑based intrusion detection system that alerts you to suspicious activity, allowing you to intervene before malware can establish itself.
- Enable automatic OS and application updates.
- Run daily integrity scans with
rkhunterorchkrootkit. - Limit services to only those required for your site.
- Enforce key‑based SSH login and strong passwords.
- Deploy a web application firewall (WAF) for Apache/Nginx.
## Example commands (review before execution)
# Update packages (Debian/Ubuntu)
apt-get update && apt-get upgrade -y
# Update packages (CentOS/RHEL)
yum update -y
# Install and run a basic malware scan
yum install -y clamav && freshclam && clamscan -r /home
# Run a rootkit checkReview the output for any files flagged as infected or any warnings about altered system binaries. If the scan reports suspicious items, investigate their locations, verify their legitimacy, and consider restoring clean copies from backups.
If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.
Questions people ask
What are the most common signs of malware on cPanel?
Malware on a cPanel server often shows up as sudden slow performance, unexplained CPU or memory spikes, unknown cron jobs, new or altered files in the webroot, unfamiliar processes running under the web user, and outbound traffic to suspicious IPs. These clues warrant a deeper check.
Which cPanel tools help detect infections?
cPanel provides several built‑in tools for infection detection. The “Security” section lists “Virus Scanner” and “Malware Scan” if installed. The “File Manager” can be used to spot unfamiliar files. The “Cron Jobs” list reveals hidden tasks, and the “Process Manager” shows unknown processes. Combining these with a command‑line scanner like ClamAV gives a solid overview.
How do I safely remove malicious files?
To remove malware safely, first back up the affected account or take a snapshot. Identify the infected files using a scanner or manual review. Then delete or quarantine those files with `rm` or `mv` to a safe location. After removal, run a fresh scan to confirm no remnants remain, and check file permissions and ownerships are correct.
What steps should I take after cleaning to avoid reinfection?
After cleaning, update all software including cPanel, PHP, and CMS plugins. Harden SSH by disabling root login and using key authentication. Change all passwords and enable two‑factor authentication where possible. Set up a regular backup schedule, monitor logs for unusual activity, and consider a scheduled malware scan to catch future threats early.