64
Marx – Uncovering Class Hierarchies in C++ Programs NDSS 2017, San Diego Andre Pawlowski * , Moritz Contag * , Victor van der Veen , Chris Ouwehand , Thorsten Holz * , Herbert Bos , Elias Anthonasopoulos , Cristiano Giuffrida * Ruhr-Universität Bochum Vrije Universiteit Amsterdam University of Cyprus

Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Marx – Uncovering Class Hierarchies in C++ ProgramsNDSS 2017, San Diego

Andre Pawlowski∗, Moritz Contag∗, Victor van der Veen†, Chris Ouwehand†, Thorsten Holz∗,Herbert Bos†, Elias Anthonasopoulos‡, Cristiano Giuffrida†

∗ Ruhr-Universität Bochum † Vrije Universiteit Amsterdam ‡ University of Cyprus

Page 2: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Introduction

Page 3: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Introduction

• We present Marx, a tool to extract class hierarchies from legacy binaries.

• This eases static analysis of C++ applications.

• We use the results for security-related use cases:

1. Control-Flow Integrity

2. Type-safe Object Reuse

Marx – Uncovering Class Hierarchies in C++ Programs 1

Page 4: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Motivation

• C++ applications are hard to analyze statically.

• Class inheritance.

• Objects allocated on the heap.

• Indirect function calls (polymorphism).

• Solving these problems aids in the reverse engineering process.

• Exploit mitigations would profit from solutions to these problems.

• Counterfeit Object-oriented Programming.

• Fine-grained control over forward edge.

Marx – Uncovering Class Hierarchies in C++ Programs 2

Page 5: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Motivation

• C++ applications are hard to analyze statically.

• Class inheritance.

• Objects allocated on the heap.

• Indirect function calls (polymorphism).

• Solving these problems aids in the reverse engineering process.

• Exploit mitigations would profit from solutions to these problems.

• Counterfeit Object-oriented Programming.

• Fine-grained control over forward edge.

Marx – Uncovering Class Hierarchies in C++ Programs 2

Page 6: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Page 7: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

Function X[...]

new object A

Marx – Uncovering Class Hierarchies in C++ Programs 3

Page 8: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

[...]

Class B

Marx – Uncovering Class Hierarchies in C++ Programs 3

Page 9: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

shellcode_0

shellcode_1

[...]

Class Malicious

[...]

Class B

Marx – Uncovering Class Hierarchies in C++ Programs 3

Page 10: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

shellcode_0

shellcode_1

[...]

Class Malicious

[...]

Class B

Marx – Uncovering Class Hierarchies in C++ Programs 3

Page 11: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

shellcode_0

shellcode_1

[...]

Class Malicious

[...]

Class B

Marx – Uncovering Class Hierarchies in C++ Programs 3

Page 12: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

object in hierarchy?

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

[...]

Class B

call [[rdi] + offset]

Marx – Uncovering Class Hierarchies in C++ Programs 4

Page 13: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

object in hierarchy?

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

shellcode_0

shellcode_1

[...]

Class Malicious

[...]

Class B

call [[rdi] + offset]

Marx – Uncovering Class Hierarchies in C++ Programs 4

Page 14: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

object in hierarchy?

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

shellcode_0

shellcode_1

[...]

Class Malicious

[...]

Class B

call [[rdi] + offset]

Marx – Uncovering Class Hierarchies in C++ Programs 4

Page 15: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Control-Flow Integrity

Code

[...]

mov rdi, object

object in hierarchy?

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class A[...]

new object A

Object Avtblptr

var_0

[...]

shellcode_0

shellcode_1

[...]

Class Malicious

[...]

Class B

call [[rdi] + offset]

Marx – Uncovering Class Hierarchies in C++ Programs 4

Page 16: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

Page 17: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class Afunction_b1

function_b2

[...]

Class Bfunction_c1

function_c2

[...]

Class C

objectᾆ�function_a1()

Source Code

Indirect function calls are prominent C++ artifacts on binary level.

Marx – Uncovering Class Hierarchies in C++ Programs 5

Page 18: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

High Level

Function Xfunction_a1

function_a2

[...]

Class Afunction_b1

function_b2

[...]

Class Bfunction_c1

function_c2

[...]

Class C

At high level, a class may inherit from another.

Marx – Uncovering Class Hierarchies in C++ Programs 5

Page 19: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

Memory

Function Xfunction_a1

function_a2

[...]

Class Afunction_b1

function_b2

[...]

Class Bfunction_c1

function_c2

[...]

Class C

X

Inheritance relationships are not readily available in the binary.

Marx – Uncovering Class Hierarchies in C++ Programs 5

Page 20: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

Code

[...]

mov rdi, object

call [[rdi] + offset]

[...]

Memory

Function Xfunction_a1

function_a2

[...]

vtable Afunction_b1

function_b2

[...]

vtable Bfunction_c1

function_c2

[...]

vtable C

X

Classes are (loosely) represented by vtables instead.

Marx – Uncovering Class Hierarchies in C++ Programs 5

Page 21: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

• Marx statically recovers the class hierarchy from an x86-64 binary (Itanium ABI).

• Represents class hierarchy as set of vtables.

• Ties set of vtables to indirect function call.

• Analysis steps:

1. Identify vtables,2. inspect their usages,

3. refine results using heuristics,4. merge results across modules.

Marx – Uncovering Class Hierarchies in C++ Programs 6

Page 22: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

• Marx statically recovers the class hierarchy from an x86-64 binary (Itanium ABI).

• Represents class hierarchy as set of vtables.

• Ties set of vtables to indirect function call.

• Analysis steps:

1. Identify vtables,2. inspect their usages,

3. refine results using heuristics,4. merge results across modules.

Marx – Uncovering Class Hierarchies in C++ Programs 6

Page 23: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

1. Vtable Candidates

Page 24: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Vtable Identification

Object A

Heap or Stack

vtblptr A

Vtable A

­0x10  metadata_0

­0x08  metadata_1

 0x00  A::func_a1

 0x08  A::func_a2

...

Data Memory

Marx – Uncovering Class Hierarchies in C++ Programs 7

Page 25: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Vtable Identification

Object A

Heap or Stack

vtblptr A

Vtable A

­0x10  metadata_0

­0x08  metadata_1

 0x00  A::func_a1

 0x08  A::func_a2

...

Data Memory

Marx – Uncovering Class Hierarchies in C++ Programs 7

Page 26: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Vtable Identification

Object A

Heap or Stack

vtblptr A

Vtable A

­0x10  metadata_0

­0x08  metadata_1

 0x00  A::func_a1

 0x08  A::func_a2

...

Data Memory resides in read­only memory(e.g., .rodata)

Marx – Uncovering Class Hierarchies in C++ Programs 7

Page 27: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Vtable Identification

Object A

Heap or Stack

vtblptr A

Vtable A

­0x10  metadata_0

­0x08  metadata_1

 0x00  A::func_a1

 0x08  A::func_a2

...

Data Memory

only firstfunction entryis referenced

Marx – Uncovering Class Hierarchies in C++ Programs 7

Page 28: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Vtable Identification

Object A

Heap or Stack

vtblptr A

Vtable A

­0x10  metadata_0

­0x08  metadata_1

 0x00  A::func_a1

 0x08  A::func_a2

...

Data Memorymetadata fields

are withindefined range

or 0

Marx – Uncovering Class Hierarchies in C++ Programs 7

Page 29: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Vtable Identification

Object A

Heap or Stack

vtblptr A

Vtable A

­0x10  metadata_0

­0x08  metadata_1

 0x00  A::func_a1

 0x08  A::func_a2

...

Data Memory

point into codesection or arerelocationentries

Marx – Uncovering Class Hierarchies in C++ Programs 7

Page 30: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

2. Vtable Usages

Page 31: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Overwrite Analysis

call constructor A

write vtblptr B

Function X ↴[...]

new object B

call constructor B

Constructor B ↴

Constructor A ↴write vtblptr A

return

return

A

B

Hierarchy CodeObject

init. variable_1

Marx – Uncovering Class Hierarchies in C++ Programs 8

Page 32: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Overwrite Analysis

call constructor A

write vtblptr B

Function X ↴[...]

new object B

call constructor B

Constructor B ↴

Constructor A ↴write vtblptr A

return

return

A

B

Hierarchy CodeObject B

Object

vtblptr

variable_1

init. variable_1

Marx – Uncovering Class Hierarchies in C++ Programs 8

Page 33: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Overwrite Analysis

call constructor A

write vtblptr B

Function X ↴[...]

new object B

call constructor B

Constructor B ↴

Constructor A ↴write vtblptr A

return

return

A

B

Hierarchy CodeObject B

Object

vtblptr

variable_1

init. variable_1

Marx – Uncovering Class Hierarchies in C++ Programs 8

Page 34: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Overwrite Analysis

call constructor A

write vtblptr B

Function X ↴[...]

new object B

call constructor B

Constructor B ↴

Constructor A ↴write vtblptr A

return

return

A

B

Hierarchy CodeObject B

Object

vtblptr A

variable_1

init. variable_1

Marx – Uncovering Class Hierarchies in C++ Programs 8

Page 35: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Overwrite Analysis

call constructor A

write vtblptr B

Function X ↴[...]

new object B

call constructor B

Constructor B ↴

Constructor A ↴write vtblptr A

return

return

A

B

Hierarchy CodeObject B

Object

vtblptr A

variable_1

init. variable_1

Marx – Uncovering Class Hierarchies in C++ Programs 8

Page 36: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Overwrite Analysis

call constructor A

write vtblptr B

Function X ↴[...]

new object B

call constructor B

Constructor B ↴

Constructor A ↴write vtblptr A

return

return

A

B

Hierarchy CodeObject B

Object

vtblptr A ⟶ B

variable_1

init. variable_1

Marx – Uncovering Class Hierarchies in C++ Programs 8

Page 37: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Overwrite Analysis

call constructor A

write vtblptr B

Function X ↴[...]

new object B

call constructor B

Constructor B ↴

Constructor A ↴write vtblptr A

return

return

A

B

Hierarchy CodeObject B

Object

vtblptr B

variable_1

init. variable_1

Marx – Uncovering Class Hierarchies in C++ Programs 8

Page 38: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Path Generation

• In a function, build paths visiting

1. indirect calls,

2. direct calls to new, and3. instructions operating on vtables.

• Resolve indirect function calls for known vtables in current context.

• Follows calls with a call depth of 2.

Marx – Uncovering Class Hierarchies in C++ Programs 9

Page 39: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

3. Vtable Heuristics

Page 40: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Function Heuristics

Vtable A

HierarchyClass A

virt. func_a1()

virt. func_a2()

Class B

virt. func_a1()

virt. func_b1()

­0x10 0

­0x08 0

 0x00 A::func_a1

 0x08 A::func_a2

Vtable B

­0x10 0

­0x08 0

 0x00 B::func_a1

 0x08 A::func_a2

 0x10 B::func_b1

Data Memory

Marx – Uncovering Class Hierarchies in C++ Programs 10

Page 41: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Function Heuristics

Vtable A

HierarchyClass A

virt. func_a1()

virt. func_a2()

Class B

virt. func_a1()

virt. func_b1()

­0x10 0

­0x08 0

 0x00 A::func_a1

 0x08 A::func_a2

Vtable B

­0x10 0

­0x08 0

 0x00 B::func_a1

 0x08 A::func_a2

 0x10 B::func_b1

Data Memory

Marx – Uncovering Class Hierarchies in C++ Programs 10

Page 42: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Function Heuristics

Vtable A

HierarchyClass A

virt. func_a1()

virt. func_a2()

Class B

virt. func_a1()

virt. func_b1()

­0x10 0

­0x08 0

 0x00 A::func_a1

 0x08 A::func_a2

Vtable B

­0x10 0

­0x08 0

 0x00 B::func_a1

 0x08 A::func_a2

 0x10 B::func_b1

Data Memory

Differentpointer, yieldsno information

Marx – Uncovering Class Hierarchies in C++ Programs 10

Page 43: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Function Heuristics

Vtable A

HierarchyClass A

virt. func_a1()

virt. func_a2()

Class B

virt. func_a1()

virt. func_b1()

­0x10 0

­0x08 0

 0x00 A::func_a1

 0x08 A::func_a2

Vtable B

­0x10 0

­0x08 0

 0x00 B::func_a1

 0x08 A::func_a2

 0x10 B::func_b1

Data Memory

Same functionentry, probably

samehierarchy

Marx – Uncovering Class Hierarchies in C++ Programs 10

Page 44: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach

4. Inter-Modular Dependencies

Page 45: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Inter-Modular Dependencies

Applications may consist of several modules.

Shared Library

Application

Marx – Uncovering Class Hierarchies in C++ Programs 11

Page 46: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Inter-Modular Dependencies

Independent analysis yields, e. g., three distinct hierarchies.

D

E F

Shared Library

G

H I

J

K L

Application

Marx – Uncovering Class Hierarchies in C++ Programs 11

Page 47: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Approach – Inter-Modular Dependencies

Unless we merge results across modules, we underestimate the hierarchy.

D

E F

Shared Library

G

H I

J

K L

Application

Marx – Uncovering Class Hierarchies in C++ Programs 11

Page 48: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation

Page 49: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Class Hierarchy Reconstruction

Application No. of Hierarchies Exactly Reconstructed Time (h)

MySQL Server 78 69 (88%) 11:36MongoDB 158 137 (87%) 1:08Node.js 59 55 (93%) 0:33

Application Overestimated Underestimated Not Found

MySQL Server 1 (1%) 7 (9%) 1 (1%)MongoDB 0 8 (5%) 13 (8%)Node.js 2 (3%) 2 (3%) 0

48 min analysis time on average for 5 real-world applications.

Marx – Uncovering Class Hierarchies in C++ Programs 12

Page 50: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Class Hierarchy Reconstruction

Application No. of Hierarchies Exactly Reconstructed Time (h)

MySQL Server 78 69 (88%) 11:36MongoDB 158 137 (87%) 1:08Node.js 59 55 (93%) 0:33

Application Overestimated Underestimated Not Found

MySQL Server 1 (1%) 7 (9%) 1 (1%)MongoDB 0 8 (5%) 13 (8%)Node.js 2 (3%) 2 (3%) 0

48 min analysis time on average for 5 real-world applications.

Marx – Uncovering Class Hierarchies in C++ Programs 12

Page 51: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Class Hierarchy Reconstruction

Application No. of Hierarchies Exactly Reconstructed Time (h)

MySQL Server 78 69 (88%) 11:36MongoDB 158 137 (87%) 1:08Node.js 59 55 (93%) 0:33

Application Overestimated Underestimated Not Found

MySQL Server 1 (1%) 7 (9%) 1 (1%)MongoDB 0 8 (5%) 13 (8%)Node.js 2 (3%) 2 (3%) 0

48 min analysis time on average for 5 real-world applications.

Marx – Uncovering Class Hierarchies in C++ Programs 12

Page 52: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Class Hierarchy Reconstruction

Application No. of Hierarchies Exactly Reconstructed Time (h)

MySQL Server 78 69 (88%) 11:36MongoDB 158 137 (87%) 1:08Node.js 59 55 (93%) 0:33

Application Overestimated Underestimated Not Found

MySQL Server 1 (1%) 7 (9%) 1 (1%)MongoDB 0 8 (5%) 13 (8%)Node.js 2 (3%) 2 (3%) 0

48 min analysis time on average for 5 real-world applications.

Marx – Uncovering Class Hierarchies in C++ Programs 12

Page 53: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Binary Hardening

• Use MARX’ results to harden legacy binaries.

• Implemented and tested two applications:

1. Control-Flow Integrity . . . . . . . . . . . . . . . . . . . . . . .“binary-level Vtable Verification (VTV)”

2. Type-safe Object Reuse . . . . . . . . . . . . . . . . .“binary-level Cling”, bucketing by hierarchy

• Lack of precision of analysis?

Marx – Uncovering Class Hierarchies in C++ Programs 13

Page 54: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Binary Hardening

• Use MARX’ results to harden legacy binaries.

• Implemented and tested two applications:

1. Control-Flow Integrity . . . . . . . . . . . . . . . . . . . . . . .“binary-level Vtable Verification (VTV)”

2. Type-safe Object Reuse . . . . . . . . . . . . . . . . .“binary-level Cling”, bucketing by hierarchy

• Lack of precision of analysis?

Marx – Uncovering Class Hierarchies in C++ Programs 13

Page 55: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Precision

• Type-safe Object Reuse allows imprecision, lowered security.

• Control-Flow Integrity may break applications.

• Enrich static results with dynamic analysis (unit tests).• Fall-back to computationally intensive slow path (PathArmor).

• Please refer to the paper for further details.

Marx – Uncovering Class Hierarchies in C++ Programs 14

Page 56: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Precision

• Type-safe Object Reuse allows imprecision, lowered security.

• Control-Flow Integrity may break applications.

• Enrich static results with dynamic analysis (unit tests).• Fall-back to computationally intensive slow path (PathArmor).

• Please refer to the paper for further details.

Marx – Uncovering Class Hierarchies in C++ Programs 14

Page 57: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Evaluation – Precision

• Type-safe Object Reuse allows imprecision, lowered security.

• Control-Flow Integrity may break applications.

• Enrich static results with dynamic analysis (unit tests).• Fall-back to computationally intensive slow path (PathArmor).

• Please refer to the paper for further details.

Marx – Uncovering Class Hierarchies in C++ Programs 14

Page 58: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Conclusion

Page 59: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Limitations

• Approach is compiler-dependent, optimizations may break assumptions.

• Abstract base classes may not yield a vtable for us to discover.

• Analysis is prone to path explosion (inter/intra-procedural path generation).

• Applications building upon results have to tolerate imprecision.

Marx – Uncovering Class Hierarchies in C++ Programs 15

Page 60: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Limitations

• Approach is compiler-dependent, optimizations may break assumptions.

• Abstract base classes may not yield a vtable for us to discover.

• Analysis is prone to path explosion (inter/intra-procedural path generation).

• Applications building upon results have to tolerate imprecision.

Marx – Uncovering Class Hierarchies in C++ Programs 15

Page 61: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Limitations

• Approach is compiler-dependent, optimizations may break assumptions.

• Abstract base classes may not yield a vtable for us to discover.

• Analysis is prone to path explosion (inter/intra-procedural path generation).

• Applications building upon results have to tolerate imprecision.

Marx – Uncovering Class Hierarchies in C++ Programs 15

Page 62: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Conclusion

• Marx succeeds in recovering the majority of class hierarchies.

• Large, real-world applications.

• Promising results.

• Results are applicable to security-related use cases on the binary level.

• Our C++ open-source implementation based on libVEX is available at

https://github.com/RUB-SysSec/Marx.

Marx – Uncovering Class Hierarchies in C++ Programs 16

Page 63: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Thank you for your attention.

Marx – Uncovering Class Hierarchies in C++ Programs 16

Page 64: Marx – Uncovering Class Hierarchies in C++ Programs - NDSS ... · Andre Pawlowski, Moritz Contag, Victor van der Veen, Chris Ouwehand, Thorsten Holz, Herbert Bos, Elias Anthonasopoulos,

Conclusion

• Marx succeeds in recovering the majority of class hierarchies.

• Large, real-world applications.

• Promising results.

• Results are applicable to security-related use cases on the binary level.

• Our C++ open-source implementation based on libVEX is available at

https://github.com/RUB-SysSec/Marx.

Marx – Uncovering Class Hierarchies in C++ Programs 17