--------------------------------
This is my write-up of the OverTheWire wargame Leviathan. If you notice any problems please contact me to let me know.
--------------------------------
--[ Level 0 ]
The only direction we get in this wargame is that data can be found in the home directories.
So, after we SSH in to [email protected]
, we can search the home directory
We see
We will check the .backup
directory
And we see
Opening the file with cat
revealed a large amount of text so we can narrow it down with grep
And it outputs the password in the terminal.
--------------------------------
--[ Level 1 ]
When we list the contents of the home directory we see an executable file named check
. When we run it, it asks for a password
So it seems it is testing the input against a stored string. We can run ltracer
to see the library calls the script makes.
Checking the man page for strcmp
we can see that it is a C function that compares strings. Therefore, we can assume ‘sex’ is the password.
And we have the password for the next level.
--------------------------------
--[ Level 2 ]
When we list the contents of the home directory we see an executable file named printfile
.
Attempting to get into /etc/leviathan_pass/leviathan3
gives us
Running ltrace
on it reveals limited information
We need a file that isn’t disallowed so we can see where it goes after the access()
call. It is probably best to make our own file for this purpose.
The access()
call and the call to /bin/cat
seem to be a bit different.
The quotes in the system()
call lead me to believe that if you put two files as arguments to printfile
, access()
might read it as a single file, but cat
will probably read it as two individual files. That might get around our file privilege problem.
I tried a few combinations until a single file with a space in the name offered some promise
Here we see that /bin/cat
has tried to process the file two files
as two
and files
, while access()
has processed it as a single file.
Knowing this we just have to get the file two
to print the contents of /etc/leviathan_pass/leviathan3
.
I had tried a symbolic link previously in an attempt to get two files to pass through access()
but it hadn’t worked. But with this file we should be able to do it correctly.
And it worked! It prints the password and a /bin/cat: files: No such file or directory
to confirm to us that we were spot on.
--------------------------------
--[ Level 3 ]
Again in the home directory there is an executable. This one is called level3
.
We run ltrace
on it
Now I must admit I puzzled over the “h0no33” and “kakaka” strings inputing them into the password field and wondering what I was gettting wrong before noticing the second strcmp()
call further down…
And there we have it.
--------------------------------
--[ Level 4 ]
Listing the files in the home directory we see the directory .trash
that contains the executable bin
.
Seems like binary, I ran it through an online translator and the password is revealed.
--------------------------------
--[ Level 5 ]
The executable is this level is called leviathan5
. Let’s run it
We will run an ltrace
on it
We’ll try adding a symbolic link to the password file from the /tmp/file.log
file
The password prints to the terminal.
--------------------------------
--[ Level 6 ]
For this level we run the executable we have come to expect
So looks like we need to brute force a PIN. I modified a simple bash script from ‘Bandit’ to work here
1
2
3
4
5
6
7
8
9
#!/bin/bash
START=0000
LAST_PIN=9999
for i in `seq $START $LAST_PIN`;
do
~/leviathan6 $i
done
We then give it the appropriate permissions and run it
After the word ‘Wrong’ prints 10,000 times in the terminal, we get a shell open up
And that is Leviathan.
--------------------------------
--------------------------------