SerialFlow
Writeup for SerialFlow (Web) - HackTheBox Cyber Apocalypse CTF (2024) 💜
Last updated
Writeup for SerialFlow (Web) - HackTheBox Cyber Apocalypse CTF (2024) 💜
Last updated
SerialFlow is the main global network used by KORP, you have managed to reach a root server web interface by traversing KORP's external proxy network. Can you break into the root server and open pandoras box by revealing the truth behind KORP?
We can download the source code and see most of the app's functionality is in app.py
.
Once again, the goal is clearly RCE since we have a flag.txt
file at /flag
with a randomised name.
I wasted a lot of time on rabbit holes and realise in hindsight, I should of investigated the memcached
session stuff as it stands out as unusual.
A quick Google search of memcached python vuln
returns some general pentesting techniques but also an interesting PoC video titled Remote Code Execution (RCE) in Python pylibmc through memcached injection
. However, the exploit was demonstrated 10 years ago at BlackHat 2014 so it's unlikely to be applicable, right?
Well, if we adjust our search options to "in the past year" one of the top results is the Top 10 web hacking techniques from Portswigger. Guess which vulnerability is featured there? 😼
That's right! Exploiting Flask-Session with Memcached command injection utilizing crc32 collision and python pickle deserialization for RCE by D4D.
The article explains the exploit better than I can but essentially, we can leverage the /set
route to set the Flask session cookie value for the key uicolor
. Memcached terminates commands and data sequences using CRLF so we want to inject using quoted strings (\015\012
).
Next, we want to encode a payload. Since python pickle is used to deserialise data before saving to Memcached, we can construct a malicious pickle that when deserialised, will trigger RCE.
Let's jump straight into testing the PoC! The only thing I changed is the command to curl
(we want to verify the command executes) and the cache key/name to 420
.
We generate the payload, then simply replace our cookie value and make a call to the /set
endpoint.
I struggled for a while here, until I realised that curl
is not installed on the machine lol 🤦♂️ If we change the command to whoami
and test locally, we'll see root
pop up in the logs 🙏
Furthermore, if we update the command to cat /flag*.txt
, the flag will be printed in the server terminal! The problem is, we can't see the output on the remote instance 🤔
I tried to get a reverse shell, but it never made the connection (although I heard later others did have success with this). Ultimately, I ended up changing the cmd
to cp /flag*.txt application/templates/index.html
.
We might need to send the request several times, as the server seems to crash regularly. Eventually, the command will execute and index.html
will be replaced with the flag. Therefore, when we follow the redirect, the flag is displayed.
Flag: HTB{y0u_th0ught_th15_wou1d_b3_s1mpl3?}