OverTheWire: Bandit Level 25 to Level 26

Level goal: 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.

Indeed, logging in is easy, simply run the usual command which allow you to login using SSH key instead of login credentials

ssh -i bandit26.sshkey bandit26@localhost

bandit25_1

However, after you logged into bandit26, you will be logged out immediately, “Connection to localhost closed.”

As hinted by the question, let’s take a look at the bash used by bandit26,

bandit25@melinda:~$ cat /etc/passwd | grep bandit26
 bandit26:x:11026:11026:bandit level 26:/home/bandit26:/usr/bin/showtext

Instead of /bin/bash, bandit26 is using /usr/bin/showtext, which is apparently not a shell. Let’s look at the content of the file

bandit25@melinda:~$ cat /usr/bin/showtext
 #!/bin/sh
 more ~/text.txt
 exit 0

The way to obtain the password for this level is extremely creative, I salute the team who designed this portion of the challenge, it’s really good.

As we know, we will be logged out immediately after we gain access to the server using the SSH key. The way to get the level 27 password is to gain access to the file before your shell gets terminated.

Think about it, how can that be possibly done? The hint is that you are able to “log in” to the system, just that when it spawns a shell, it terminates the shell immediately – the exact code is “exit 0” as we have see in the showtext “shell”.

Here’s the solution:

First, minimize your terminal so that when you are logged into bandit26 via ssh command, the large “bandit26” ASCII art banner will force a “more” message to prompt you to continue the output. You may refer to the screenshot as an illustraton of how I have minimized my terminal,

bandit25_2

ssh -i bandit26.sshkey -t bandit26@localhost cat text.txt

bandit25_3

Now that you have forces the terminal to prompt you to continue the display via “more” or “–More–(50%)” in this case, press “v” to enter “vim”, a built-in text editor on Unix machines. You will see the output as per below,

bandit25_4

Now, press “:e /etc/bandit_pass/bandit26” to edit the password file of bandit26.

bandit25_5

There you go, you have the password to proceed to level 27!!

Let’s review what we have done. We have forces the terminal to display a “more” output, where we can open a VIM text editor and open the password file of bandit26 using the file opening command within the VIM text editor. We are able to open this password file containing the bandit26 password because we have logged into the bandit26 account and this is right before the “exit 0” portion of the code boot us out from the machine.

The password to gain access to the next level is 5czgV9L3Xx8JPOyRbXh6lQbmIOWvPT6Z. However, level 27 is not up yet, therefore level 26 is the final bandit challenge as of now.

Advertisements

5 thoughts on “OverTheWire: Bandit Level 25 to Level 26

  1. You didn’t go looking in the readme file in the bandit26 home directory. So you have only half finished level 26

      • how can you access the readme file? it says permission denied.
        also thanks for this guide, it helped me out a bunch.

        how did you manage to figure out that you needed to minimize the terminal to force the more message while in pseudo-tty allocation?

        do you have references of where you got the commands “v” for vim and “:e” for edit?
        are those commands that you can use while only in a minimized terminal with pseudo-tty allocation?

      • Hi Ken, sorry for the late reply. I’m glad that my guide has been helpful to you!

        To figure out the part where we need to minimise our terminal is simple. Please refer to the part where the challenge provide us with hints that the user “shell” is /usr/bin/showtext.

        Notice the second line uses the more command. In such cases, run man more on your linux machine and you will see a list of possible commands that you can use while using more to display the content within a file.

        The concept is similar to when you are using an Linux Server which only has command-line interface, there is no GUI. To display the text of a file, you can use cat. What if the file is very long and you want to view the first few lines? You can use head. What about somewhere in the middle of the file which “scrolls through” too quickly for you to read it? That is where more comes in, it allows you to control the display of the content. On the bottom left, you can see that it even shows you how many percent of the content has been displayed already.

        Go try it!

Leave a Message

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s