Stack Overflow
200 points7 of 7 teams solved itFirst blood: seal_emoji_iOS_14.2 at 3:47 PM
🚀 Launch Your Lab Environment
Click here to open a pre-configured terminal on WolfCTF Portal:
👉 https://portal.wolfctf.com/labs/pacise26-ctf-stackoverflow
Log in with your LDAP account (same credentials as this CTFd), then click "Start Terminal". Starter files are in /home/student/courses/ctf/pacise26/stackoverflow/. Inside the terminal, run:
cp /home/student/courses/ctf/pacise26/stackoverflow/* ~/ && cd ~
gcc stackoverflow.c -o stackoverflow -m32 -fno-stack-protector -z execstack -no-pie
You only need to log into the portal once - your session lasts 24 hours.
Stack Overflow - Beginner PWN Challenge
Classic ret2func warmup. A 32-bit binary with no stack canary, no NX, no PIE - all mitigations are off. There's a convenient hacked() function already in the binary that will read and print flag.txt for you. Your job is to overflow gets() in return_input() and overwrite the saved return address so the program jumps into hacked() instead of returning to main.
Target
nc 157.245.222.186 19998
Source (simplified)
void hacked() { /* reads flag.txt and prints it */ }
void return_input(void) {
char array[50];
gets(array); // <-- overflow here
printf("You said: %s\n", array);
}
int main(void) {
return_input();
return 0;
}
Hints
- Use
gdb+ GEF'spattern create/pattern offsetto find the exact distance from the start ofarray[]to the saved return address. - Use
objdump -d ./stackoverflow | grep '<hacked>:'to find the address ofhacked(). It's fixed because the binary is compiled with-no-pie. - Payload:
b'A' * offset + p32(hacked_addr) - The binary on the remote server is exactly the same as the one you compile locally from
stackoverflow.c(same flags, same source).
Goal
Trigger hacked() on the remote server and receive the flag in its output.
Flag format: pacise26{...}
- stackoverflow.c 1.1 KB