Bandit
This is a collection of challenges built around common Linux utilities.
Level 0
To start off we follow the instructions found here https://overthewire.org/wargames/bandit/bandit0.html and ssh to bandit.labs.overthewire.org on port 2220 as the user bandit0. To do this I will be using the Debian Windows Subsystem for Linux (mostly because putty can be annoying to work with). Just as a note, I will not be explaining these solutions, simply showing what commands can be used to find the flag. That being said, I am also using this an an exercise to test my bash-fu a little.
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.
Level 2
The password for the next level is stored in a file called - located in the home directory
Level 3
The password for the next level is stored in a file called spaces in this filename located in the home directory
Level 4
The password for the next level is stored in a hidden file in the inhere directory.
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.
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
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
Level 8
The password for the next level is stored in the file data.txt next to the word millionth
Level 9
The password for the next level is stored in the file data.txt and is the only line of text that occurs only once
Level 10
The password for the next level is stored in the file data.txt in one of the few human-readable strings, beginning with several ‘=’ characters.
Note that for this challenge there are multiple lines that match the regular expression ^=+
so we must use the knowledge that the flag is 32 characters long.
Level 11
The password for the next level is stored in the file data.txt, which contains base64 encoded data
Level 12
The password for the next level is stored in the file data.txt, where all lowercase (a-z) and uppercase (A-Z) letters have been rotated by 13 positions
Level 13
The password for the next level is stored in the file data.txt, which is a hexdump of a file that has been repeatedly compressed. For this level it may be useful to create a directory under /tmp in which you can work using mkdir. For example: mkdir /tmp/myname123. Then copy the datafile using cp, and rename it using mv (read the manpages!)
Level 14
The password for the next level is stored in /etc/bandit_pass/bandit14 and can only be read by user bandit14. For this level, you don’t get the next password, but you get a private SSH key that can be used to log into the next level. Note: localhost is a hostname that refers to the machine you are working on
Level 15
The password for the next level can be retrieved by submitting the password of the current level to port 30000 on localhost.
Level 16
The password for the next level can be retrieved by submitting the password of the current level to port 30001 on localhost using SSL encryption.
Helpful note: Getting “HEARTBEATING” and “Read R BLOCK”? Use -ign_eof and read the “CONNECTED COMMANDS” section in the manpage. Next to ‘R’ and ‘Q’, the ‘B’ command also works in this version of that command…
Level 17
The credentials for the next level can be retrieved by submitting the password of the current level to a port on localhost in the range 31000 to 32000. First find out which of these ports have a server listening on them. Then find out which of those speak SSL and which don’t. There is only 1 server that will give the next credentials, the others will simply send back to you whatever you send to it.
Okay, I have to admit that my solution here is ugly, but was able to get it into a form that you could copy and paste. The basic flow of this solution goes:
Do an nmap scan for open ports between 31000-32000 on 127.0.0.1, enumerate the service versions on each open port, then output in grepable formate to stdout
ignore all lines starting with
#
or containingStatus
grab the portion of the output with the open ports results
Cut the remaining strings off at the work
Ignored
change all commas to new lines (this will make it so each port's results are on it's own line)
trim all spaces and tabs
ignore all lines that contain the word
echo
(We want to avoid the echo servers)grab the first field, which is the port number of the valid port
Put this value into an environment variable named
PORT
Use
$PORT
to connect to the correct port and pipe in the correct password from/etc/bandit_pass/bandit16
to get the flag
While technically two commands, I'd say it is pretty compact. This page was super helpful in working with the nmap output: https://github.com/leonjza/awesome-nmap-grep#print-the-top-10-ports
Level 18
There are 2 files in the homedirectory: passwords.old and passwords.new. The password for the next level is in passwords.new and is the only line that has been changed between passwords.old and passwords.new
NOTE: if you have solved this level and see ‘Byebye!’ when trying to log into bandit18, this is related to the next level, bandit19
Level 19
The password for the next level is stored in a file readme in the homedirectory. Unfortunately, someone has modified .bashrc to log you out when you log in with SSH.
Because the .bashrc
for this user automatically kicks you, we simply run the command via ssh instead of logging in.
Level 20
To gain access to the next level, you should use the setuid binary in the homedirectory. Execute it without arguments to find out how to use it. The password for this level can be found in the usual place (/etc/bandit_pass), after you have used the setuid binary.
Level 21
There is a setuid binary in the homedirectory that does the following: it makes a connection to localhost on the port you specify as a commandline argument. It then reads a line of text from the connection and compares it to the password in the previous level (bandit20). If the password is correct, it will transmit the password for the next level (bandit21)
Level 22
A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.
The cronjob in this challenge is simply writing to the following file:
Level 23
A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.
NOTE: Looking at shell scripts written by other people is a very useful skill. The script for this level is intentionally made easy to read. If you are having problems understanding what it does, try executing it to see the debug information it prints.
Level 24
A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.
NOTE: This level requires you to create your own first shell-script. This is a very big step and you should be proud of yourself when you beat this level!
NOTE 2: Keep in mind that your shell script is removed once executed, so you may want to keep a copy around…
Level 25
A daemon is listening on port 30002 and will give you the password for bandit25 if given the password for bandit24 and a secret numeric 4-digit pincode. There is no way to retrieve the pincode except by going through all of the 10000 combinations, called brute-forcing.
This could certainly be sped up quite a bit with multithreading, but I didn't feel it was necessary.
Level 26
Logging in to bandit26 from bandit25 should be fairly easy… The shell for user bandit26 is not /bin/bash, but something else. Find out what it is, how it works and how to break out of it.
Looking at the /etc/passwd
entry for bandit26
we see that it is calling a shell script instead of an actual shell. This script simple calls more
on a file. If we change the size of our terminal so that the file cannot fit, then we can abuse the v
command in more. This will open an editor for the file, in this case the default editor is vim, and we can use that editor to view the password file with the following vim command:
Level 27
Good job getting a shell! Now hurry and grab the password for bandit27!
The solution to this challenge is nearly identical to the last. Only this time we spawn a shell instead of editing a file.
Level 28
There is a git repository at ssh://bandit27-git@localhost/home/bandit27-git/repo. The password for the user bandit27-git is the same as for the user bandit27.
Clone the repository and find the password for the next level.
Level 29
There is a git repository at ssh://bandit28-git@localhost/home/bandit28-git/repo. The password for the user bandit28-git is the same as for the user bandit28.
Clone the repository and find the password for the next level.
For this challenge the password is hidden in a previous commit, which we can see with git log
Level 29
There is a git repository at ssh://bandit29-git@localhost/home/bandit29-git/repo. The password for the user bandit29-git is the same as for the user bandit29.
Clone the repository and find the password for the next level.
For this challenge the password is hidden in a previous commit, which we can see with git log
Level 30
There is a git repository at ssh://bandit30-git@localhost/home/bandit30-git/repo. The password for the user bandit30-git is the same as for the user bandit30.
Clone the repository and find the password for the next level.
Level 31
There is a git repository at ssh://bandit31-git@localhost/home/bandit31-git/repo. The password for the user bandit31-git is the same as for the user bandit31.
Clone the repository and find the password for the next level.
For this challenge we simply need to push a file with specific contents to the repo, but it is originally ignored due to the .gitignore. We get past this with the -f
flag.
Level 32
After all this git stuff its time for another escape. Good luck!
It looks like we are stuck in yet another jail shell. This one seems to translate every character to uppercase, but by using characters that can't be translated to uppercase we can escape the shell.
Last updated