Cron Job Privilege Escalation
Cron is reliable when a privileged job executes something you can influence: writable scripts, writable cron definitions, unsafe PATH usage, relative paths in writable directories, wildcard injections, unsafe temporary files, or missing binaries you can plant.
For systemd timer-based scheduled jobs see https://hackindex.io/platforms/linux/privilege-escalation/systemd-unit-and-timer-privilege-escalation.
Prerequisites Check
Grab everything cron reads across common distributions:
Read root's spool if accessible — this is already a misconfiguration:
What to note from output:
/etc/crontaband/etc/cron.d/*lines include a run-as user column/etc/cron.{hourly,daily,weekly,monthly}run throughrun-partsAnacron exists on endpoints where missed runs are replayed on next boot
Find Cron Activity Without Logs
On hardened systems, logs may be restricted or disabled. Use pspy to see cron processes as an unprivileged user:
Wait 2-3 minutes and watch for UID=0 processes on a regular cadence. Note the exact command line, run-as user, and schedule.
See https://hackindex.io/platforms/linux/privilege-escalation/privilege-escalation-enumeration-tools for pspy download methods including no-wget alternatives.
If pspy is unavailable, use file timestamps as a fallback — watch for mtime changes in output directories, log locations, and the scripts themselves:
Cron Execution Context
Cron does not use your interactive shell environment. It runs /bin/sh with a minimal environment (HOME, LOGNAME, SHELL, PATH). Check what PATH cron is using — this determines if PATH hijacking is viable:
If a target script expects a user profile to load credentials or PATH and sources them unsafely, that sourced file may be writable.
Writable Cron Scripts
Cleanest path — a privileged job executes a file you can modify:
If writable, append a payload:
Wait for cron to execute (up to the schedule interval), then:
If the script is not writable but lives in a writable directory, replace it entirely:
Writable Cron Definition Files
Writable files under /etc/cron.d/ or an editable /etc/crontab let you control what runs and as which user:
Important constraints:
Insecure Mode: Many cron versions refuse files in
/etc/cron.dthat are group-writable or world-writable. You will seeINSECURE MODEin logs. The file will not execute even if you wrote it. Fix permissions after writing if you have the abilityNaming rules: On Debian-style cron, files in
/etc/cron.dmust use only letters, digits, underscores, and hyphens — no dots
If writable, add a job:
PATH Hijacking Inside Cron Scripts
Applies when a privileged script calls commands without absolute paths and the cron PATH includes a writable directory:
If the script sets PATH=/tmp:/usr/bin and calls tar without an absolute path:
Wait for cron to fire.
For the full PATH hijacking technique see https://hackindex.io/platforms/linux/privilege-escalation/writable-path-hijacking.
Missing Binary Hijacking (Ghost Binaries)
A cron job tries to execute a binary that does not exist. If you can write to any directory in the cron PATH, plant it there:
If custom_backup is missing and /usr/local/bin is writable:
Wildcard Injection
When a privileged script runs a command with * in a directory you can write to, filenames become command-line arguments:
Example — script runs: cd /var/www/html && tar -cf /backup/web.tar *
And you can write to /var/www/html:
When tar runs with *, the filenames expand as arguments. --checkpoint=1 triggers after the first file, --checkpoint-action executes your script.
Symlink Race Conditions
If a root cron job runs chown, cp, or mv on files in a directory you control:
If root runs chown on your directory, it may follow the symlink and change ownership of /etc/shadow to your user. Then read it directly for offline cracking.
File Overwrite via Output Redirection Symlinks
If a root cron job redirects output to a predictable file in a writable directory:
If cron writes to /tmp/output.log, symlink it to a sensitive target before the job runs:
When the job runs and writes to /tmp/output.log, it actually writes to /etc/ld.so.preload. Poison it with a path to a malicious shared library:
/tmp/privesc.c
#include <stdlib.h>
#include <unistd.h>
void __attribute__((constructor)) init() {
setuid(0); setgid(0);
system("cp /bin/bash /tmp/.rootbash; chmod u+s /tmp/.rootbash");
}
Anacron and at/batch
Anacron runs missed jobs after a system resumes — check its timestamp files for manipulation opportunities:
The timestamp file contains the last run date. If writable, set it to an old date to force a missed-run replay on next boot.
at and batch schedule one-time jobs and are frequently overlooked:
run-parts from Writable Directories
If a cron line calls run-parts on a directory you can write to:
If writable, add a script using only letters, digits, underscores, and hyphens in the name:
References
-
Cron environment variables and syntax
-
Cron search paths and job loading behavior
-
cron.allow and cron.deny access control behavior
-
run-parts(8)man.archlinux.org/man/run-parts.8 (opens in new tab)
Filename constraints and --test behavior
-
Process monitoring without root for scheduler discovery
Was this helpful?
Your feedback helps improve this page.