T3: Escaping the Blizzard
Beware of Blizzard Bear skills, he even managed to hack your old text-based service. Talk about a blast from the 90's!
Last updated
Beware of Blizzard Bear skills, he even managed to hack your old text-based service. Talk about a blast from the 90's!
Last updated
The following post by 0xb0b is licensed under CC BY 4.0
We find the keycard for the third Side Quest hidden in the task of the 12th day of the TryHackMe Advent Of Cyber. With the following task, it gives us a hint to check for something where the balance shifts. From the rhymes, it sounds like to look for an IDOR: Where balances shift and numbers soar, look for an entry - an open door
Day 12: If I can’t steal their money, I’ll steal their joy!
We scan for further directories of the walkthrough machine and find, among others, the directory transactions.
We call this, but it requires an ID.
We receive such an ID after a transaction has been carried out. On closer inspection, this could be something MD5 hashed.
We enter the parameter ID with the value from our last transaction and receive a status.
We try to crack our transaction hash using crackstation.net
. And find out that in our case it is the value 1339 MD5 hashed.
The idea now is to look for further transactions, perhaps another one hides a further reference to the keycard. We intercept a request using Burp Suite and forward it to the Intruder module. Here we mark the value that is passed via the ID.
On tab payloads, we define the necessary parameters to query further IDs. We chose the payload type numbers and limit the number range 1330
to 1350
for the time being. Under Payload processing, we specify that these values should be hashed.
We start the attack and filter by the response length. One response stands out in particular, with a length of 367
. Here we find something encoded in base64 in the status.
We decode this string and see a path that points to an image.
We request the path and find the third keycard.
We can deactivate the firewall with the password of the keycard. We can pass the value to a website on port 21337
.
After we have deactivated the firewall, we start with an Nmap scan and find three other open ports in addition to port 21337
. We have port 22
SSH, port 80
a web server and on port 1337
an unknown service.
The site offers a service to generate building and construction approvals with a form for construction request and a contact form.
We carry out a directory scan. We find the backup directory, which could contain interesting sensitive information.
In that backup directory is a binary called enc, some recommended passwords and a zip file.
Next, we try to connect to the service on port 1337
. There we can create, read and edit permit entries. That text based mentioned in the room description that Blizzard Bear managed to hack.
Let's see how the binary behaves on entering some example values. If we enter something not expected, the application loops.
We download the zip file, the password file and the binary. We can see that the zip file contains the maybe first flag (foothold.txt), a binary called secureStorage and a Dockerfile. So let's stick with that for now.
We check the enc binary and run it. It looks like it encrypts a given password.
Using zip2john and trying to crack that password with the given password list does not yield to anything.
We craft a simple script to encrypt each password of the recommended-passwords.txt
and save the encrypted password to encrypted-passwords.txt
.
We try to crack the zip again, now with the encrypted passwords, and are successful.
We extract the contents of the zip file and have access to the first flag.
Here is just a rough overview of the exploit. The script for this was created by Aquinas, all credits belong to him. His intention and detailed procedure to craft the script can be found in his writeup, which will be linked here as soon as it is online:
We run the secureStorage file and see the same banner printed, like on port 1337. This might be the way to get a foothold.
In the Docker file, we can see that this binary is exposed to port 1337
using socat, and the flag is placed in the root directory. Furthermore, we see that the libc.so.6
and ld-lindux-x86-64.so.2
is placed in the same directory as secureStorage. We can already assume here that when we reach foothold, it is in a docker container, and we must break out of it.
But for now, let's move on to the analysis of the binary. For this we are using BinaryNinja. In the main function, it loops infinitely for the menu.
The function show()
does not appear to be conspicuous for the time being.
The create()
function seems to be vulnerable to a heap based buffer overflow. Here, memory is allocated using malloc
and then written to using read()
.
If the size allocated by malloc(((uint64_t)rax_6))
is smaller than the size specified in sizes[rax_1] + 0x10
, the read
function will write past the bounds of the allocated buffer.
The memory is overwritten in the edit()
function
A collection of heap based buffer overflow techniques can be taken from this repository :
Which heap based buffer overflow techniques are available to us depends on the glibc version. To determine the version, we determine the addresses of known functions and pass it to libc.rip
.
We run the application using gef, set a breakpoint and run p system
and p malloc
to retrieve the addresses.
We pass those into libc.rip and see that libc 2.39
is used.
Not too many techniques are possible for these.
We do not find any free()
used in the rest of the code.
Therefore, we need a technique that does not use free()
. Among them is the house of tangerine.
Following techniques are combined:
Leak libc and heap addresses. (House Of Orange)
Corrupt tcache metadata. (House Of Tangerine)
Redirect malloc to a desired address.
Craft a payload for ret2libc execution.
Unsorted Bin Leak (House of Orange)
Goal: Leak libc and heap addresses.
Steps:
Overflow the top chunk size, forcing it into the unsorted bin.
Allocate from the unsorted bin to leak a libc pointer (present in the bin metadata).
Perform a similar allocation to leak a heap pointer by crafting data that spills into heap metadata.
Tcache Corruption (House of Tangerine)
Background on Tcache Bins:
When a chunk is freed, it is placed into a "bin" organized by size.
If multiple chunks share the same size, they are linked together in the bin via pointers.
Allocating the first chunk (head) from the bin updates the pointer to point to the next chunk.
Goal: Manipulate malloc to return a specific address.
Steps:
Prepare the Bin:
Place at least two chunks of the same size into the same bin.
Corrupt the Pointer:
Modify the pointer of the first chunk (head) to point to the desired target address.
Tcache uses XOR encoding (vuln_tcache >> 12
), so a heap leak is required to calculate the correct pointer.
Allocate Twice:
First allocation removes the corrupted head, setting the target address as the new head.
Second allocation returns the target address.
Arbitrary Read/Write and ret2libc
Goal: Gain control over the program's execution flow.
Steps:
Use the manipulated malloc to leak a stack address (e.g., __libc_argv
).
Calculate offsets to overwrite the saved return address on the stack.
Craft a ret2libc payload to call system("/bin/sh")
.
This script is developed by Aquinas. All rights and credit are attributed to him:
It takes several attempts to get a shell, it may take up to 10 attempts, if not more. It could be more successful with the Attack box. We get a foothold and are root on the system. In the current directory, we find the second flag.
As predicted we are in a docker container, running deepce.sh we see that groups are exploitable.
LinPeas gives us a better impression of what exactly is exploitable. Either a core_pattern breakout
or an uevent_helper breakout
is possible.
The core_pattern breakout seems promising, as it matches the theme of the room.
A Docker core_pattern
breakout leverages the misconfiguration of the core_pattern
kernel parameter in a containerized environment to break out of a Docker container and escalate privileges on the host. This is possible when the host system is configured to store or process core dumps in a way that exposes sensitive data or allows interaction between the container and the host.
Privileged Container: The container must be running in privileged mode or have CAP_SYS_ADMIN capabilities to modify /proc/sys/kernel/core_pattern
.
Writable Host Filesystem: Access to write to host directories (e.g., via mounted volumes).
Vulnerable Configuration: The host's core_pattern
is configured insecurely or can be overridden by the container.
An example can be found here:
If we can successfully write our script to /proc/sys/kernel/core_pattern
prefixed with a pipe, the kernel will execute our program outside of the container.
But first, lets test if we can simulate a crash that then writes to a file we have defined in core_pattern
.
Seems like it worked.
Now we need to write our shell script and this has to be accessible from the host.
We can show the mounts and find the overlay folder. If we write to /
on the container, it is actually at /var/lib/docker/overlay2/221c28c3554db6a8781a1558e327ee54b8a3d6b7266507ee7ccd8af24a05c444/diff/
We place our shell.sh
in /
of the docker container.
We write the path to the shell script prefixed with a pipe to execute it outside the container.
With the following command, we force a crash.
And get a connection back to our listener. We are root on the host and find the final flag at /root/root.txt
.