OverTheWire.org Walkthrough: Bandit

~ Level 20→21 ~

Level Description

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).

NOTE: Try connecting to your own network daemon to see if it works as you think

The following are commands that may be required to solve the level: ssh, nc, cat, bash, screen, tmux, and Unix ‘job control’ (bg, fg, jobs, &, CTRL-Z, …)


Research Before Solving

The screen command will be used for this level. This command is used to have multiple command line sessions open within the same window. More on this when we use it.


Solution Walkthrough

As usual, log in to the server, this time as bandit20. We will first use ls to list files in the home directory. We find a file by the name of suconnect. Note it's color of red, an indication of escalated priveleges. This means we are able to execute the file using ./suconnect

executing suconnect file

We are given nc as a command to solve the level, we are also advised by the executable file that the program will connect to a given port that is set up on the localhost. This is where tmux comes in. We must set up two prompt sessions, one will be used to listen while the other will be used to execute suconnect.

Type in the command tmux, you should see a new window open within your ssh client. We will now use the command of $tmux to force open a second instance. We can swap between the two instances by pressing ctrl+b simultaneously with an immediate follow up of shift+9 or shift+0. You should see session instances change in the bottom.

In one instance we will type echo GbKksEFF4yrVs6il55v6gwY5aVje5f0j | nc -l -p 55000 to echo last level's password and then open a port and start listening on it. We can now switch to our other instance using ctrl+b followed by shift+0 and execute the file in the home directory making sure to use the same port as we did in the first instance: ./suconnect 55000

executable states it's sending password password for bandit21

As can be seen, one instance confirms the passwords match and that the password for bandit21 is being sent. Swapping to our other instance shows the password for the next level. Congratulations!

Password: gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr