Cron job exploitation

Understanding Cron Job Vulnerabilities

What Makes Cron Jobs Dangerous

Cron jobs are scheduled tasks that run automatically at specified times with the privileges of their owner. They present excellent privilege escalation opportunities because they often run as root, execute scripts with weak permissions, or use relative paths that can be hijacked.

The Attack Principle: Exploit cron jobs that:

  • Execute scripts or commands you can modify

  • Use relative paths without specifying full binary locations

  • Run as higher-privileged users (especially root)

  • Process user-controllable input or files

  • Have weak file permissions on their executables or configuration

Why This Works: Cron jobs run with the privileges of the user who owns the crontab entry. If you can modify what a root cron job executes, you gain root privileges when the job runs.

Cron Job Discovery and Enumeration

System-Wide Cron Job Discovery

Cron Configuration Files:

# Main system crontab
cat /etc/crontab

# System cron directories
ls -la /etc/cron.d/
ls -la /etc/cron.daily/
ls -la /etc/cron.hourly/
ls -la /etc/cron.monthly/
ls -la /etc/cron.weekly/

# Check all cron directory contents
find /etc/cron* -type f -exec cat {} \; 2>/dev/null

# Anacron configuration (for systems without permanent uptime)
cat /etc/anacrontab 2>/dev/null

User-Specific Cron Jobs:

Systemd Timers (Modern Cron Alternative):

Cron Job Analysis and Permission Checking

Script and Binary Permissions:

Cron Log Analysis:

Direct Script Modification Attacks

Writable Cron Scripts

Finding Modifiable Scripts:

Script Modification for Privilege Escalation:

Path Hijacking in Cron Jobs

Understanding Cron PATH Issues

Why PATH Hijacking Works in Cron:

  • Cron jobs often run with minimal PATH (usually just /usr/bin:/bin)

  • Scripts may call commands without full paths

  • You can create malicious binaries in PATH directories

  • Cron doesn't inherit user's PATH modifications

Finding PATH-Vulnerable Cron Jobs:

PATH Hijacking Exploitation

Creating Malicious Binaries:

Common Command Hijacking:

Wildcard Injection in Cron Jobs

Understanding Wildcard Vulnerabilities

Why Wildcards Are Dangerous:

  • Cron jobs often use wildcards for file operations

  • Wildcards expand to include filenames you create

  • Malicious filenames can become command arguments

  • File creation is often user-controllable

Finding Wildcard Usage:

Wildcard Exploitation Techniques

Tar Wildcard Injection:

Chown Wildcard Injection:

Rsync Wildcard Injection:

Monitoring and Real-Time Exploitation

Real-Time Cron Monitoring

Using pspy for Process Monitoring:

Timing-Based Exploitation

Determining Cron Job Schedule:

Key Operational Considerations

Success Indicators

  • Cron job executes your modified script or command

  • Privilege escalation achieved (check with id after waiting for execution)

  • File creation in expected locations (SUID shells, backdoor users)

  • Log entries showing successful command execution

Common Failure Points

  • No writable cron files or scripts found

  • Absolute paths used in cron jobs prevent PATH hijacking

  • Timing issues - cron jobs may run infrequently

  • File permissions prevent modification of target files

  • SELinux/AppArmor prevents exploitation

Timing Considerations

  • Cron jobs timing varies from every minute to monthly

  • System load can affect cron execution timing

  • Race conditions require precise timing

  • Log monitoring may detect unusual cron activity

Cleanup and Stealth

  • Restore original files after exploitation

  • Remove temporary malicious files created during exploitation

  • Clear relevant logs if possible

  • Maintain cron job functionality to avoid detection

Cron job exploitation requires patience and careful analysis, but often provides reliable privilege escalation paths due to the automated nature of scheduled tasks and common configuration mistakes.

Last updated

Was this helpful?