Lecture 008

Memory Layout

Stack: run-time. 8MB limit Heap: malloc() Data: global, static variable, string constant Text: Code, Libraries

Memory

Memory

Buffer Overflow

Buffer Overflow Example

The Code

The Code

The Assembly

The Assembly

Result

Avoid Buffer Overflow

Using a Good Library

Salt(Add) with Random Allocated Stack Space On Higher Address

Random Stack Space

Random Stack Space

System-Level Protection

x86-64 marked stack as non-executable by default (seg-fault)

Stack Canaries

Compiler-added canaries (used by default)

Canaries

Canaries

Canaries in Stack

Canaries in Stack

Return-Oriented Programming

Why We Use it:

Gadgets: sequence of code ending with ret(0xc3)

Gadgets

Gadgets

xxd a.out | grep c3

Union

Union

Union

Share Memory Space Allow Strange Code

Share Memory Space Allow Strange Code

Little Endian

Little Endian

Big Endian

Big Endian

Table of Content