Endian-ness
x86 family is a little-endian architecture: multi-byte values are stored least-significant byte first
0x11223344 –> \0x44\0x33\0x22\0x11
Memory Layout
[ HIGH ]
Kernel Space
Stack (grows down): procedure-local data and control
Memory Mapping (grows down): shared libraries, mapped files
Heap (grows up): dynamic data, limit controlled by brk/sbrk
BSS: uninitialized static vars, filled with zero
Data: initialized static vars
Text: program code
[ LOW 0x0 ]
Stack Frames
Calling Conventions
Stack Frame Layout
% ebp + 12 | Argument 2
% ebp + 8 | Argument 1
Return Address
% ebp –> Saved %ebp
Local Data
% esp –> Stack top
Key stack-based buffer overflow vulnerability
Overwriting the return address!
- fxn returns using a corrupted stack frame
- attacker controls the return address
- code jumps to a location of the attacker’s choosing
Low vs high-level languages
Shellcode
NOP Sled
Stack Overflow Defenses
PLT & GOT
Return-oriented programming
call & ret
ASLR
Address space layout randomization
- traditional attacks require attackers to know/guess certain addresses
- idea: randomize code & data addresses –> difficult to guess
- OS level defense (no recompilation needed)
printf
Heap Overflows