Bandit 3

As we learned in the previous Bandit 2, it’s important to find a way to check a specific file’s content, and in Linux, we usually use the cat command. Furthermore, in the previous Bandit 2, we covered how to check a ‘dashed file’ content and successfully accomplished it. However, we also have another challenge: viewing the content of a file with a ‘spaced file name,’ which is what we will cover in this walkthrough.

Spaced File

Most of the time, we use spaces while naming our files. Let’s say we have a text file we want to call ‘This is yesha.blog website’; then, of course, the file is going to have spaces. So lets try to find the spaced file by running the following command in our system:

Now, if we try to open this file and see the content inside of it by echoing the following command:

We will get the following output:

We notice here that the system is not able to open the file, but why? This is because each input ‘word’ is one single argument, so technically, the arguments are separated by spaces. If the user tries to use filenames with spaces directly, they will be treated as separate arguments rather than just one argument. Because remember, the terminal is sensitive, and the user needs to be specific with their input. So in this case, we have multiple ways to solve that.

One of the main ways is to echo the spaced filename between quotation marks, by running the following command:

We also escape every space using the backslash key by running the following command:

Notice here the last word doesn’t include any backslash key because there is no word following it.

Giving Information

As we solved the previous Bandit 2 challenge, we obtained the password for this machine. We also have the machine hostname required for the SSH process:

  • Machine Hostname: bandit2@bandit.labs.overthewire.org
  • Password: rRGizSaX8Mk1RTb1CNQoXTcYZWU6lgzi
  • Flag Location: The password is stored in a file called spaces in this filename located in the home directory

Finding The Flag

After SSHing the machine, we list the files in the home directory by using the following command:

As we can see from the output, the targeted spaced file is called ‘spaces in this filename’, so we can echo the commands we have covered and demonstrated above. As we mentioned, there are many ways, but one of the main ways is echoing the filename between quotes like this:

We can also use the other way, which is using the backslash key like this:


In conclusion, despite encountering a file with a spaced filename, we successfully accessed the necessary information by employing alternative methods. This underscores the adaptability and versatility of command-line utilities in managing diverse file naming conventions.

Ready to progress to the next Bandit level? Click here.


Posted

in