π§ TetCTF 2024
My writeups, aimed to be more descriptive for beginners.
Last updated
My writeups, aimed to be more descriptive for beginners.
Last updated
Author: zx
Can you unlock it?
Server: http://103.3.61.46/TetCTF2024-babyasm/babyasm.html
The babyasm.html file checks if the input is a total of 27 characters and fits the flag format TetCTF{...}, then passes the last 20 characters Including '}' into the wasm function.
When looking at the console log, it can be seen that there is an error when trying to run the file in firefox. Same when trying to use command line tools to decompile it. The solution is to use a chrome-based browser.
The picture above shows how debugging web assembly looks like. The main file and wasm can be seen by clicking babyasm.html and 8fa74aba. A breakpoint can be added by clicking the address to the left of the code, and when the breakpoint is hit, it can either be passed by clicking the blue play button in the top left or clicking the step button to run the following lines. The Scope section to the left allows the user to see all declared variables and the stack, which is useful to follow what's going on in the code.
With the above knowledge, the goal is to simply follow along and reverse engineer what's happening to the input. I started with aaaa... as an input and then abcd... as an input to come up with the following:
There is a global set of constants (g), a target (t), and 20 character inputs. 83 is added to every input and the results are calculated in the order 2, 3, 4, 1. We get a system of equations, four unknowns and four equations and just need to solve five sets of four equations to get the flag.
I briefly tried a math solver approach before running into issues with the way xor is handled, before I gave up and just went with a brute force approach which is fine since the search space is very limited (instant).
At first I used the global array from the decompiled wasm, but couldn't find a solution. I didn't go through to see what the mechanism is, but it seems the global array alternates between two different sets which is why the first line is commented. I initially thought the global array was being "corrupted" mistakenly, and would just run a dummy submission after every test to "fix" it, so I did get stuck before realizing.
Running the above code gives us the flag:
TetCTF{WebAss3mblyMystique}
Author: ndh
flip
You are allowed to inject a software fault.
Server: nc 139.162.24.230 31339
flip v2
Changing in main() is not allowed.
Server: nc 139.162.24.230 31340
The way main.py works is it loads the "encrypt" binary into memory and allows the user to modify the plaintext as well as flip a specific bit in the binary.
The offsets at the top of main.py correspond to the location in memory for plaintext and key in the binary. When reading the input from the user, the pt is checked to be 16 bytes, i needs to be within the bound of the binary (21032 bytes), and j needs to select a bit from 0-7. The goal is to determine what plaintext and bit to flip to be able to determine the randomized key based on a single program output.
When I went to brute force what would happen to the binary when I flipped each bit and to check if perhaps it may just output the key directly, I ended up solving both flip and flip v2. I'm not entirely sure why there not more solves for this since I spent way longer on the other challenges. The following is the full script I used to brute force each bit flip output.
Because this checks around 100 byte positions every couple seconds, I added many print statements so I would notice when a match was found. The timeout could probably be even lower to solve it quicker, but this solves both challenges in a minute or two. The first three solutions it finds are (byte=4545, bit=4), (byte=4551, bit=5), and (byte=5463, bit=1). I cancelled it soon after finding the third solution so there may be more.
Now the hard part: testing locally to make sure we don't get banned. Refer to the main.py snippet at the top, any exception hit causes ban_client(), which would be a shame after solving the challenge. Here are the docker commands to build and test locally.
You can then nc to localhost 31339, and input the pt (16 bytes of 0s) and solution (e.g. 4545 4). For flip v1, any of the solutions will work, so test locally first before testing at the remote to get the flag.
TetCTF{fr0m_0n3_b1t_fl1pp3d_t0_full_k3y_r3c0v3ry}
The only difference with flip v2 is that you can't flip a bit in main.
That means we can't use one of the first two solutions we found. Good thing we found more than just those.
TetCTF{fr0m_0n3_b1t_fl1pp3d_t0_full_k3y_r3c0v3ry_d043a7ff4cf6285a}
Author: Stirring
Tet is coming, TetCTF is coming again. Like every year, I continued to register to play CTF, read the rules to prepare for the competition. After reading the rules, my computer seemed unusual, it seemed like it was infected with malicious code somewhere. Can you find out?
Find the malicious code and tell me the IP and Port C2
What was the first flag you found?
After registering an account, I no longer remember anything about my account. Can you help me find and get the second flag?
Format : TetCTF{IP:Port_Flag1_Flag2}
Ex: TetCTF{1.1.1.1:1234_Hello_HappyForensics}
The hardest 100 points welcome-equivalent solve of my life.
We're given a raw dump (TETCTF-2024-20240126-203010.raw) that's 5.4 GB (!!!), and a Backup.ad1 file that's 222 MB and need to find the malicious code and then something about their account.
Some grep-fu:
We can combine this with file redirection to get binary snippets put in a file to explore with your method of choice (vim/hex editor/strings/cat/etc.). An example: grep -ia -C 10 tetctf TET*.raw > tetctfmatch.bin. We can then strings tetctfmatch.bin | less
to get a quick idea if we want to explore further, and can open the file to see all the hex or cat it to a file to strip out all the non-printable binary characters (since sometimes text is obfuscated with nulls in between each character so it won't be listed in strings).
After an hour or two of this, it'll be clear that the raw file captures the process of accessing and registering at the tetctf website, doing google searches, and various accesses to pastebin and downloads. There's a dummy pastebin link scattered in the binary that is just a placeholder flag, and another pastebin link that is locked. However, with enough analysis of how web traffic is saved in the binary, it's clear that pastebin contents are saved with the following postfix: - Pastebin.com
There are many pastebins in the raw file (seemingly just from general web browsing), but that prefix always follows when it's in relation to a capture of the actual content on the page. Doing a grep for that will show many instances of the second part of the flag.
Flag 2: R3c0v3rry_34sy_R1ght? - Pastebin.com
Comparatively the first part of the challenge is a lot less straight-forward. There is a suspicious zip file that's listed many times in the raw file: https://www.file.io/GN6v/download/eKHCxsHdpFZc
. This file is seen to be a zip file that was later extracted, and is related to the part in the description regarding being infected after reading the rules. Some other interesting snippets in the raw:
A rough idea can be gathered from this, where a malicious word document was downloaded and run. From here, there's no way around it but to go back to the ad1 file that seemed relatively useless with the same methods. Basically, the files in it can be extracted if you download FTK Imager (link: https://www.exterro.com/ftk-imager). They ask for a ton of info for the download (which isn't verified aside from email format), and it's only compatible with Windows, two things that stopped me from doing this for a few hours.
Once you install it, you can add the .ad1 and then right click one of the top level entries to extract all the files. I extracted them to a shared folder that I use between all my VMs.
At this point, things were a bit of a blur and I went in circles, (a red herring minikatz direction, various system logs, etc.), but knew the end goal was to find something related to a malicious word file. I eventually stumbled upon the Word template files, which included ./Roaming/Microsoft/Templates/normal/word/vbaProject.bin
. I may have needed to unzip a doc to see it, don't remember for sure.
There are some IP addresses and ports in there which seems weird, and looking at the output of strings on the file, there is a suspicious base64 string: Vmxjd2VFNUhSa2RqUkZwVFZrWndTMVZ0ZUhkU1JsWlhWRmhvVldGNlZrbFdSM2hQVkd4R1ZVMUVhejA9
. Putting it in cyberchef to base64 decode it, it seems like garbage, but don't give up.
We now have the flag!
TetCTF{172.20.25.15:4444_VBA-M4cR0_R3c0v3rry_34sy_R1ght?}
Easiest points of my life. Due to weird point scaling, this was worth 10x the other 3 challenges I solved (which were worth the same 100 points as the Welcome challenge ).