Challenge Info
| Property | Value |
|---|---|
| CTF | PascalCTF 2026 |
| Challenge | Heap |
| Category | Pwn |
| Points | 450+ |
| Solves | idk |
Description
idk honestly
Files provided:
averagelibc.so.6ld-linux-x86-64.so.2
Connection info:
| |
Vulnerability Discovery
Before diving into the exploitation steps, let’s analyze the vulnerable function responsible for the bug. The core issue is in the way the program handles user input for the message field. The function responsible for reading the message does not properly check the length of the input, and uses a scanf("%s", ...), which stops reading at the first null byte but does not prevent the user from overflowing the intended buffer size. This means that if the user provides more data than the buffer can hold, the excess bytes will overwrite adjacent memory regions.
In the context of heap management, this overflow allows an attacker to overwrite the metadata of the next heap chunk, specifically the size field. By carefully crafting the input, it is possible to set the size of the next chunk to an arbitrary value, which is a classic heap overflow vulnerability. This is particularly dangerous because it enables advanced exploitation techniques such as tcache poisoning and chunk overlap, which can ultimately lead to arbitrary code execution or information disclosure.
The vulnerable logic can be summarized as follows:
| |
Solution
Step 1: Heap Setup
Allocate three chunks to fill up the initial heap and make chunk placement predictable.
| |
Step 2: Heap Overflow
Step 3: Tcache Poisoning
Allocate and free the corrupted chunk to place it in the tcache bin, then reallocate to overlap and control sensitive data.
Final Exploit
| |
Flag
| |
Takeaways
- Heap overflows and tcache poisoning are still super fun
- Always check your input lengths
- Messing with chunk metadata never gets old
Notes
- For the chunk overlap, I allocated C4 after corrupting its size (0x71 instead of the original value).
- Then I re-allocated a chunk of size 0x70, which let me overwrite sensitive data and prep the payload for the win.
- The overflow itself was just 39 bytes into the message field of C3, with the last 7 bytes being the corrupted size for the next chunk.