Headquarters

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

└─# file *
flag:           ASCII text, with no line terminators

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

headquarters.c: C source, ASCII text

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

lets take a look at the source code

Seems like we have to overwrite the admin_key variable with 0xdeadbeef

lets do this with a buffer overflow attack

Ghidra Disassembly

Opening the binary in ghidra, we can take a look at the stack layout of the main function

Disassembly view in ghidra

Stack layout (illustrated)

Illustrated Stack Layout of the main function

Our goal is to overwrite the admin_key variable from the name variable

Our input variable is located at RBP -0x14 and the variable we need to overwrite is located at RBP -0xc

The buffer size is 8

Writing solve script

Running solve script

flag:

sctf{1m_4dm1n_n0w}

Last updated