OverTheWire - Leviathan Walkthrough - Levels 0-4

OverTheWire’s wargames are offered to help learn and practice security concepts in the form of fun-filled games.
The Leviathan wargame is a little bit more advanced than Bandit but still doesn’t require any knowledge about programming. It is best to first play Bandit and then Leviathan.
It consists of a total of 6 Levels. At each level, you have to find the password for the next level to continue playing. Each Level is a user that you connect as, using SSH in the leviathan.labs.overthewire.org
server.
In this post, we will present the solutions for Levels 0-4 of the Leviathan wargame.
NOTE: These walkthroughs are written and published to help other members of the community that are stuck at some Level. It is strongly advised to first try the challenges yourself until you can progress no more, and only then come back here to see the solution.
Level 0
The goal of this level is to log into the game using SSH and find the password for the next level. You can use SSH from a computer using any operating system:
- Windows
- macOS
- Linux
It is best to use a Linux distribution, to practice the things you learn in each challenge but it is not required. There are many guides on how to use SSH on Windows. For Linux and macOS users, you can simply use the ssh
utility that is available from your terminal.
The host which we need to connect is leviathan.labs.overthewire.org
and the port is 2223
. We can use the -p
flag to define the port we want to connect to. The username is leviathan0
and the password is also leviathan0
.
Log in to leviathan0
:
Password: leviathan0
If we list the home directory:
We see this .backup
directory, which we list again:
We can cat
it and grep
for the password:
Level 1
Log in to leviathan1
, using the password found from Level 0:
If we list the home directory:
The check
executable runs with leviathan2
permissions using the setuid bit, so if we exploit it we can cat the password for level 2.
We can use ltrace
to see the library calls of the program:
As we can see it simply compares the 3 char input we give with the word sex, so this is our password:
Now we got a shell and we can show the password for the next level:
Level 2
Log in to leviathan2
, using the password found from Level 1:
If we list the home directory:
The printfile
executable runs with leviathan3
permissions using the setuid bit, so if we exploit it we can cat the password for level 3.
If we run the program:
So lets try to print a file:
It works fine, lets try to print the password file:
We can use ltrace
to see the library calls of the program:
According to man
pages for access
:
access() checks whether the calling process can access the file pathname. If pathname is a symbolic link, it is derefer‐
enced.
So symbolic linking won’t work.
If we play a bit with the parameters that the program takes, we can see that there is no input sanitization. So nothing stops us from creating a dangerous file like:
Now if we try to print this file with the printfile
program:
We got a shell, and now we can cat
the password file:
Level 3
Log in to leviathan3
, using the password found from Level 2:
If we list the home directory:
The level3
executable runs with leviathan4
permissions using the setuid bit, so if we exploit it we can cat the password for level 4.
If we run the program:
We can use ltrace
to see the library calls of the program:
As we can see it simply compares the input we give with the word snlprintf, so this is our password:
Level 4
Log in to leviathan4
, using the password found from Level 3:
If we list the home directory:
There is a hidden directory .trash
:
If we run the program:
If we convert it to decimal:
84 105 116 104 52 99 111 107 101 105 10
If we convert it to ascii, we will see this is our password (emitting the NL line feed char):
Tith4cokei