Wargames - Bandit (Levels 0 to 7)
Table of Contents
Well, here we are again, in the middle of the night - I am bored and I am preparing for idekCTF 2024. What’s better than sitting and solving some more CTF stuff? I’m gonna start with Bandit - and go all the way up slowly as per the recommended order on the Wargames homepage.
The first few levels (or Bandit itself, really) are really simple - mostly about teaching you about Unix/Linux utilities, and various other tools you might need while doing CTF challenges.
Level 0
The goal of this level is for you to log into the game using SSH. The host to which you need to connect is bandit.labs.overthewire.org, on port 2220. The username is bandit0 and the password is bandit0. Once logged in, go to the Level 1 page to find out how to beat Level 1.
Well, the idea is clear. Connect through SSH using:
Fill in the given password at the prompt, and you’re in!
Level 0 -> Level 1
The password for the next level is stored in a file called readme located in the home directory. Use this password to log into bandit1 using SSH. Whenever you find a password for a level, use SSH (on port 2220) to log into that level and continue the game.
Simple enough! Let’s use cat
to read the file readme
.
A quick exit
to get out, let’s connect to level 1.
Level 1 -> Level 2
The password for the next level is stored in a file called - located in the home directory.
Alright, we got the password from the previous level. Let’s connect in through SSH.
At the password prompt, I will use the password I got from the previous level. The filename, as given by the problem, is -
- a special character. I will still use cat
, but escape the filename with a backslash \
so cat
properly understands the filename.
}
We’re done! Let’s get out and move on to level 3.
Level 2 -> Level 3
The password for the next level is stored in a file called spaces in this filename located in the home directory.
Still a simple challenge. Anyone can cat
files that have spaces in their names by wrapping the entire path in quotes. Let’s give this a try.
}
We’re done!
Level 3 -> Level 4
The password for the next level is stored in a hidden file in the inhere directory.
Hidden directories huh… Let’s put ourselves into the inhere
directory first, and try printing the directory listing.
Nothing. I know just the trick for this - the -a
option for ls
.
Aha. Let’s cat
out our password, and get out.
}
Level 4 -> Level 5
The password for the next level is stored in the only human-readable file in the inhere directory. Tip: if your terminal is messed up, try the “reset” command.
Let’s start by cd
ing into the inhere
directory again. I will use the file
command to see the types of the file - “human-readable” is a hint from the problem text.
There’s only one file with the type “ASCII text” - let’s cat
it!
}
Level 5 -> Level 6
The password for the next level is stored in a file somewhere under the inhere directory and has all of the following properties:
- human-readable
- 1033 bytes in size
- not executable
Let’s try printing the directory listing.
Right… There’s a lot of folders, and possibly files. But don’t fret! A Linux utility is available for us to help us out with this - find
.
# output too long, omitted here.
Dangit. That’s a whole lot of files. Let’s check the problem text and see the requirements. It has to be a human-readable file, and it has to be 1033 bytes in size. It also has to be non-executable, but we will skip that for now. find
provides a few filters to help us out with this - -type f
allows us to only search for files, skipping all directories, while -size 1033c
filters out files with the precise size of 1033 bytes (yes, the c
suffix is for bytes!). Let’s see it in action.
Only one file - we can also do a few checks on the file to see if it matches up with the rest of the description.
)
Yup, precisely what we wanted - ASCII text, 1033 bytes, and non-executable, by the lack of the x
bit on the permissions. Let’s cat
it to see the content, and away we go!.
Level 6 -> Level 7
The password for the next level is stored somewhere on the server and has all of the following properties:
- owned by user bandit7
- owned by group bandit6
- 33 bytes in size
Sounds like another find
! Finding by user and group would be hard, but thankfully, find
also provides us filters for all those operations! -user <user>
and -group <group>
filter files owned by that user and group, respectively!
# long output, omitted
# long output, omitted
Amidst a sea of permission denied
, we see a file that doesn’t have that problem! Let’s cat
the file to see its content, and let’s move on to the next level.
}