TSA Cyber Champion
Vibe Check List
Binary Exploitation
Vibe Check List v2
Binary Exploitation
Vibe Check List
Description
Analysis
this is a typical heap CRUD challenge, the chunks are stored in the following structure
typedef struct {
char desc[0x50];
custom_data *next;
int ID;
int priority;
} custom_data;with one global variable head forming a singly linked list.
these are the implementations decompiled with ghidra
addTask
allows us to allocate a chunk and link it to the linked list, we're not able to control size and index or ID of the allocation
displayTasks display will traverse linked list and prints the content until it reaches its tail
deleteTask select and index or ID to be free, also will remove it from the linked list
modifyTask edit a chunk within the linked list
Vulnerability
The vulnerability lies in the Add and Modify functions, where the program uses scanf to input 80 characters or 0x50 characters into the desc field. Although it initially seems harmless, it becomes problematic due to the nature of strings themselves, which are:
a collection/array of characters terminated by a null byte.
This characteristic is also reflected in the use of scanf with the format specifier %s. This means the result of scanf is an input of up to 0x50 characters plus one null byte at the end, making the actual memory input 81 bytes. This vulnerability is commonly referred to as an "off-by-one" error.

Exploitation
with the null byte overwrite, we can perform the operation ptr & 0xff on the next pointer of a chunk and corrupt the linked list. this enables us to create chunk overlaps, allowing the modification of chunk metadata as follows
from this chunk overlap, we can overwrite the size of a chunk or construct a fake chunk with a large size and then free it (as it is linked to the list) inserting it to the unsorted bin and leak the libc address.

using the same chunk overlap, we can also overwrite a next pointer to an arbitrary address, enabling arbitrary read and write operations.
with libc, we can perform an arbitrary read to leak the stack address via environ. Then, using arbitrary write, we can overwrite the saved stack address from the main stack frame to execute Return-Oriented Programming (ROP).
here's the final exploit being ran againts the remote server

here's the full exploit script:
Flag: TSA{y0u_4r3_my_h0m1e_n0w_b3c4us3_y0u_4r3_v1b1ng_4nd_g0t_s0m3_r1zz_t00_beb340723a}
Vibe Check List v2
Description
Analysis
this challenge is similar to the previous one with some modification which are as follows:
replacement of
scanfcalls withreadlinefunctioncustom mangling of next pointer in the linked list
seccomp being applied
Vulnerability
although the off-by-one issue no longer exists, during modifyTask, the size edit is determined by the length of the data inside the chunk.
If the data fully fills the chunk, strlen will also count the bytes beyond the data and as the mangled pointer of the chunk is located immediately afterwards it without a NULL byte as a separator, it will also count it as the length that is able to be edited.

As a result, it is possible to hijack the next pointer of the chunk.
Note that this vulnerability only exists in the modifyTask, as the addTask inputs data with a hard-coded size.
Exploitation
first, to bypass mangling, since the key is symmetric, both demangling and mangling use the same key and the same mathematical operations.
moreover, it is not necessary to recover the entire key to recreate the operation. consider the following operation that is used:
this can be simplified as:
if the chunk is the first chunk and also the tail of the linked list (i.e., next is NULL), then:
thus, we can obtain the value of the obfuscated key, which can then be used for both mangling and demangling operations, as demonstrated in the following test script.

next, we can hijack the next pointer to create overlapping chunks and UAF.
the rest of the exploitation process is similar to the previous one, except that the ROP chain is used not to spawn a shell but to perform an ORW as seccomp exists
here's the exploit being ran againts the remote server

here's the full exploit script:
Flag: TSA{1_d0n7_kn0w_h0w_y0u_c4n_r34d_7h1s_bu7_1_kn0w_y0ur_4ur4_1s_+1000000_5b27789b2a}
Last updated