Bandit2->3
Level Goal
The password for the next level is stored in a file called spaces in this filename located in the home directory
Commands useful to solve the level
Helpful Reading Material
- Filenames Spaces Linux Contains Spoilers
Where to start?
For this level again, the solution is written in the helpful material. For more explanations, you can read the Walkthrough.
Part 1 : Analysing the directory files
After listing the contents of the directory with ls, we can notice the following :
bandit2@bandit:~$ ls
spaces in this filename
bandit2@bandit:~$
Which seems to indicate that there are 4 files in this directory : spaces, in, this and filename.
Let's look into the ls man page, and try to look for an option that lists one file per line.
Hint
Options can also be numbers
Solution
The -1 option is the option we were looking for
However when using the option we previously found we see the following :
bandit2@bandit:~$ ls -1
spaces in this filename
bandit2@bandit:~$
which is exactly the same prompt as before. However, as this option allows us to list one file per line, we know
for sure that spaces in this filename is actually the name of a unique file.
Part 2 : Printing the file
Now that we know that the file is called spaces in this filename, we need to refer find a way to print this file.
Hint
By looking into the QUOTING section of the gnu bash manual, can you retrieve all the quoting mechanism that are available to us in order to print this file?
Solution
There are 3 quoting mechanism that allow us to print this file :
-
By escaping the spaces with the filename :
spaces\ in\ this\ filename. As the\preserves the litteral value of the character immediately following it. -
By enclosing the filename within simple quotes :
'spaces in this filename'. As the simple quotes preserve the litteral value of all the characters they enclose -
By enclosing the filename within double quotes :
"spaces in this filename". As the double quotes preserve the litteral value of all the characters they enclose, appart from$,`and\. As the character we need to preserve is the space, we can also use the double quotes to achieve this goal.
Full Solution
cat "spaces in this filename"to print the password to stdout.
You can now jump to the next level