Headquarters Improved

In the zip file, we are given a fake flag file, a binary and a source code file

└─# file *
flag:            ASCII text

headquarters2:   ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically 
                 linked, interpreter /lib64/ld-linux-x86-64.so.2, 
                 BuildID[sha1]=405527b137cdb2606c3e9d388dca0960ba70c686, for 
                 GNU/Linux 3.2.0, not stripped

headquarters2.c: C source, ASCII text

[...]
└─# cat flag
sctf{FAKE_FLAG}

Static analysis

Lets take a look at the c file

We can see that there is an admin() function but no calls to it in main()

There is also a buffer overflow vulnerability at the gets() call

Protections

The PIE and Canary bits are disabled, hence we are able to perform a ret2win attack

Finding buffer size

GDB

I will be using pwndbg as my debugger for this challenge

Firstly, lets generate a cyclic string of length 100

Next, lets run the program and input it into the name field

Whoops! We have got a segmentation fault. Lets inspect the value of ret that we overwritten

Our buffer size is 40

Retgadget

Due to a stack alignment issue known as the MOVAPs issue (https://ropemporium.com/guide.htmlarrow-up-right, under common pitfalls), we shall add an extra ret gadget into our payload

Solve script

flag: sctf{st0p_br34k1n9_1n_9uy5}

Last updated