Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of...

23
Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research Institute for Secure Computing @ TU Darmstadt, Germany Joint Work with Daniel Lehmann, Ahmad-Reza Sadeghi (TU Darmstadt) Fabian Monrose (UNC Chapel Hill) USENIX Security Symposium 2014, San Diego, CA, USA

Transcript of Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of...

Page 1: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Stitching the GadgetsOn the Ineffectiveness of Coarse-Grained

Control-Flow Integrity Protection

Lucas DaviIntel Collaborative Research Institute for Secure

Computing @ TU Darmstadt, Germany

Joint Work withDaniel Lehmann, Ahmad-Reza Sadeghi (TU Darmstadt)

Fabian Monrose (UNC Chapel Hill)

USENIX Security Symposium 2014, San Diego, CA, USA

Page 2: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

2

Open Question:Practical and secure mitigation of code

reuse attacks

Turing-completeness of return-orientedprogramming

8/21/2014

Page 3: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

3

Hot Research Topic:“Practical” (coarse-grained) Control Flow Integrity (CFI)

Recently, many solutions proposed

kBouncer[USENIX Sec’13]

ROPecker[NDSS’14]

ROPGuard[Microsoft EMET]

CFI for COTS Binaries

[USENIX Sec’13]

CCFIR[IEEE S&P’13]

MSBlueHat

Prize

MSBlueHat

Prize

http://technet.microsoft.com/en-us/security/jj653751

EMET

8/21/2014

Page 4: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

4

This Talk:Negative result – all current (published)

coarse-grained CFI solutions can bebypassed

8/21/2014

Page 5: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Our Contributions

Systematic Security AnalysisPointing out the conceptual weaknesses of coarse-grained

CFI solutions including Microsoft’s EMET

5

Systematic Security Analysis

Generic Attack

Real World Exploits

8/21/2014

Page 6: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Our Contributions

6

Systematic Security Analysis

Generic Attack

Real World Exploits

Our Attack is GenericOnly CFI policies considered, not specific CFI solutions,

bypassing even the Über-CFI that combines all CFI policies

The only work showing Turing-completeness

8/21/2014

Page 7: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Our Contributions

7

Systematic Security Analysis

Generic Attack

Real World Exploits

Concrete Attack Instantiations under Strong Adversary Model

Very small code base: 840kb

8/21/2014

Page 8: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

ROP Adversary Model/Assumption

8

Data Area

Code Area

Application Gadget Space(e.g., Shared

Libraries)

MEMORYApplication Address Space

Shared Libraries

MOV

ADD

ESP

CALL

LNOP

XOR

LOAD

STORE

ROP Payload 3

2 Adversary knows the memory layout (memory disclosure)

4Adversary can write ROP payload in the data area (stack/heap)

1 Adversary can hijack control-flow (buffer overflow)

Adversary can construct gadgets

See our JIT-ROP attackSnow et al, IEEE S&P 2013 &

BlackHat USA8/21/2014

Page 9: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Generic ROP Defense:Control-Flow Integrity (CFI)

Restricting indirect control-flow targets to a pre-defined control-flow graph

9 8/21/2014

Page 10: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Original CFI Label Checking[Abadi et al., CCS 2005 & TISSEC 2009]

label_AENTRYasm_ins, …EXIT

BBL A

A

C B

label_BENTRYasm_ins, …EXIT

BBL B

10

CFI CHECK

EXIT(A) -> label_B ?

8/21/2014

Page 11: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Original CFI: Benefits and Limitations

11 8/21/2014

Page 12: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Coarse-Grained CFI:Aims at practical CFI forreal-world deployment

12 8/21/2014

Page 13: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

General Idea

1

2

53

4 6

2

1

11

2 2

Reducing number of

labels

8/21/201413

Page 14: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Coarse-Grained CFI Proposals

Last Branch Record (LBR)

Win API /Critical Function

Application

POP PUSH

Stack

kBouncer[USENIX Sec’13]

ROPecker[NDSS’14]

ROPGuard[Microsoft EMET]

HO

OK

Paging

HO

OK

BinaryInstrumentation

14

CFI for COTS Binaries

[USENIX Sec’13]

CCFIR[IEEE S&P‘13]

8/21/2014

Page 15: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Main Coarse-Grained CFI Policies

CFI Policy 1: Call-PrecededSequences

Returns need to target a call-preceded instruction

CFI Policy 2: Behavioral-Based Heuristics

Prohibit a chain of N shortsequences each consistingof less than S instructions

15

Application

CALL A

asm_ins

asm_ins

CALL B

asm_ins

CALL C

asm_ins

RET

> S

< S

< S < S < S

1 2 N

Threshold SettingkBouncer: (N=8; S<=20)ROPecker: (N=11; S<=6)

8/21/2014

Page 16: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Most Restrictive Coarse-Grained CFI

CFI Policy kBouncer ROPecker ROPGuardEMET

CFI for COTS Binaries

Über-CFI

CFI Policy 1Call-Preceded Sequences

CFI Policy 2Behavioral-Based Heuristics

Time of CFI Check WinAPI 2 Pages Sliding

Window /Critical

Functions

WinAPI/Critical

Functions

IndirectBranch

Any Time

No Restriction CFI Policy

16

Here only the core policies shown. However, we consider all other deployed policies in our analysis.

8/21/2014

Page 17: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Our Methodology

Common Library

kernel32.dll

Sequence Finder (IDA Pro)

Sequence Filter(D Program)

List of Call-Preceded

Sequences

Gadget Generation (manual)

Sequence Subset 1

Sequence Subset n

MOV

ADD

ESP

CALL

LNOP

XOR

Provide filters onReg, Ins, Opnd, Length

Search for Gadgets

LOAD

STORE

17 8/21/2014

Page 18: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

(Excerpt of) Turing-Complete Gadget Set in CFI-Protected kernel32.dll

18

Gadget Type CALL-Preceded Sequenceending in a RET instruction

LOADRegister

EBP := pop ebpESI := pop esi; pop ebpEDI := pop edi; leaveECX := pop ecx; leaveEBX := pop edi; pop esi; pop ebx; pop ebpEAX := mov eax,edi; pop edi; leaveEDX := mov eax,[ebp-8]; mov edx,[ebp-4]; pop edi; leave

LOAD/STOREMemory

LD(EAX) := mov eax,[ebp+8]; pop ebpST(EAX) := mov [esi],eax; xor eax,eax; pop esi; pop ebpST(ESI) := mov [ebp-20h],esiST(EDI) := mov [ebp-20h],edi

Arithmetic/Logical

ADD/SUB := sub eax,esi; pop esi; pop ebpXOR := xor eax,edi; pop edi; pop esi; pop ebp

Branches unconditional branch 1 := leaveunconditional branch 2 := add esp,0Ch; pop ebpconditional LD(EAX) := neg eax; sbb eax,eax; and eax,[ebp-4]; ………………………………………………………….leave

8/21/2014

Page 19: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Long NOP Gadget

19

ROP Gadget 1

Store Registers

PrepareLong NOP

Long NOP

ResetRegisters

ROP Gadget 2

ESI

EDI

EBX

Stack

StaticConstants

Arbitrary Data Area (36 Bytes)

ESI

EDI

8/21/2014

Page 20: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Real-World Exploitation

20

Adobe Reader 9.1 CVE-2010-0188

MPlayer Lite r33064 m3u Buffer Overflow Exploit

Both detected by Microsoft EMET and coarse-grained CFI

Exploit Transformation

Common Library

kernel32.dll

Successful ExploitDetails in Paper

8/21/2014

Page 21: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Lessons Learned

Fundamental problems of coarse-grained CFI

1. Too many call sites available

Turing-complete gadget set possible on small code base

→ Restrict returns to valid/hot call sites (shadow stack)

2. Heuristics are ad-hoc and ineffective

Our generic Long NOP evades heuristics and handles all side effects

→ Adjusted sequence length leads to high false positive

3. Too many indirect jump and call targets

Resolving indirect jumps and calls is non-trivial

Original CFI: Vulcan framework remains blackbox

→ Compromise: Compiler support 21 8/21/2014

Page 22: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Summary and Future Work Summary

We systematically analyze the security of all recently proposed “practical” defenses against code reuse attacks

We show Turing-completeness of ROP even over less than 1MB code base

And, we provide real-world exploits

Our ongoing work: fine-grained CFI

Hardware/Software Co-design [DAC 2014]; collaboration with Intel

Software Solutions; collaboration with Microsoft

Future work

CFI for dynamic code or JIT-enabled applications

Improved code randomization schemes

22 8/21/2014

Page 23: Stitching the Gadgets - USENIX · 2019-12-18 · Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection Lucas Davi Intel Collaborative Research

Thank you!

For more information see

www.trust.cased.de

8/21/201423