Links 1

Writeup for Links 1 (Pwn) - Imaginary CTF (2022) πŸ’œ

Video Walkthrough

VIDEO

Description

I love linked lists, but I can never remember the exact syntax how to implement them in C. Can you check over this implementation and make sure I didn't screw anything up?

download challenge binary

Source

Open flag

void main(void)
{
  FILE *pFVar1;

  setbuf(stdout,(char *)0x0);
  pFVar1 = fopen("./flag.txt","r");
  __isoc99_fscanf(pFVar1,&DAT_004021b5,flag);
  do {
    menu();
  } while( true );
}

View elements in the linked list

Write elements to the list

Write data to an element in the list

View time

Solution

The write function uses a custom linked list implementation and can be broadly broken down into three sections.

  1. add/modify head element

  2. add element to tail

  3. modify element in the middle

When we add an element to the list, a 72-byte chunk is allocated from the heap with malloc.

The 72 byte element is structured like [64:data, 8:pointer_to_next_element]

The vulnerability arises when we write data to the node.

If we write more than the 64 intended bytes, we'll overflow the element and overwrite the pointer to the element in the list.

Since the flag is loaded into the .bss section by main

We can easily find and submit the address of bss.flag (0x4040c0) after our 64 bytes of padding to overwrite the next element with the address of the flag. When we view the list, it will print the flag.

Solve Script

Last updated