give it your all
~# cat Question
If you scream loud enough, the flag will magically appear :)
nc challs.nusgreyhats.org 55433
chall.c
Understanding the script
The
vuln
function reads input into theinput
buffer using the vulnerablegets
function, which does not performbounds checking
and can lead tobuffer overflow
.Before reading input, it sets up a signal handler using
signal(SIGSEGV, get_flag)
, which means if a segmentation fault occurs (SIGSEGV
), theget_flag
function will be called.
Exploit
Overview:
The exploit script uses the
pwn
library in Python to interact with the challenge server.The payload is constructed to overflow the
input
buffer and overwrite the return address.The payload consists of:
b"A"0x1000
: Fills theinput
buffer to cause a buffer overflow.b"A"0x8
: Fills the saved base pointer (rbp
) to maintain the stack alignment.p64(0x0000000000001249)
: Encodes the address of theget_flag
function (0x0000000000001249
in this case) to overwrite the return address.
Triggering the Signal:
The exploit script sends the payload to the server using
p.sendline(payload)
.When the server receives the payload and overflows the
input
buffer, it will overwrite the return address on the stack with the address of theget_flag
function.This causes the program to continue execution at the
get_flag
function, which opens and reads theflag.txt
file, giving us the flag.
In summary, the SIGSEGV
signal is triggered by intentionally causing a buffer overflow in the vuln
function.
Flag: flag{r3kt_d4_st4ck_hehe_good_warmup}
Last updated