What is a buffer overflow attack?

Answer

A buffer overflow occurs when a program writes data beyond the bounds of an allocated fixed-size buffer in memory, overwriting adjacent memory regions. In C/C++ programs, this can overwrite: return addresses (classic stack overflow — redirect execution to attacker's shellcode), function pointers, or heap metadata (heap overflow). Stack-based overflow: attacker crafts input larger than the buffer, overwrites the return address to point to injected shellcode or existing executable code (ROP — Return Oriented Programming). Famous examples: Morris Worm (1988), Code Red, Blaster. Modern mitigations: Stack canaries: random values before return addresses, checked before returning. ASLR (Address Space Layout Randomization): randomizes memory addresses, making exploitation harder. DEP/NX (Data Execution Prevention): marks data regions as non-executable. Safe languages: Rust, Java, Python perform bounds checking automatically. Compiler flags: -fstack-protector, -D_FORTIFY_SOURCE.