hackweb
notes on hacking and technology
IT EN
main menu
user menu
you are not logged in

Stack buffer overflow: the basics everything rests on

October 17, 2025 · 1 min read · #binary-exploitation #stack #memory

Local variables live on the stack, next to the function's return address. A gets() or an unbounded strcpy() writes past the buffer and reaches that pointer.

void vuln(){ char buf[64]; gets(buf); }  // no bound

With a 64-byte buffer + saved rbp, the 73rd group of bytes lands in the return address. Control it and you control where the CPU jumps at ret.

Finding the offset

cyclic 200      # De Bruijn pattern
# after the crash:
cyclic -l 0x6161... # exact offset of the return address

Defence

Stack canary (detects the overflow before ret), NX (non-executable stack), ASLR, and above all bounded functions (fgets, strncpy). Modern compilers with _FORTIFY_SOURCE catch many cases.


« back to home

latest posts
 
your IP address:
216.73.216.108
visitor #0
MOTD:
Every abstraction leaks somewhere.
Here we look at where.
topics