tutorial · bandit

Bandit Level 24

Write your first cron-triggered shell script and exfiltrate the next password to /tmp.
banditcronbashchmod
Optional narration
Marks this level complete in your browser.

Goal

A cron job runs regularly. For this level you need to create your own first shell script.

Important note: the script is removed once executed.

Hints

  • Find the cron runner and where it looks for scripts to execute.
  • Put your script in that directory with executable permissions.
  • Have your script copy the next password into a file you can read (typically under /tmp/<unique>).
Solution (click to reveal)
  1. SSH in:
ssh bandit24@bandit.labs.overthewire.org -p 2220
  1. Inspect /etc/cron.d to learn which directory is executed (often something like /var/spool/bandit24/):
cat /etc/cron.d/*
  1. Create a unique output file:
out=/tmp/bandit24_$RANDOM.txt
  1. Create a script that writes the next password into that file:
workdir=/var/spool/bandit24
script=$workdir/myjob.sh

cat > "$script" <<'EOF'
#!/bin/sh
cat /etc/bandit_pass/bandit24 > /tmp/bandit24_out.txt
EOF

chmod +x "$script"
  1. Wait ~1 minute for cron to run, then read the output:
cat /tmp/bandit24_out.txt

That output is the password for Level 25.

Notes

  • Keep a copy of your script in your home dir if you want to iterate.
  • Adjust paths based on what the cron script actually uses.