• Aucun résultat trouvé

DBI for Computer Security: Uses and Comparative

N/A
N/A
Protected

Academic year: 2022

Partager "DBI for Computer Security: Uses and Comparative"

Copied!
100
0
0

Texte intégral

(1)

DBI for Computer Security: Uses and Comparative

Juan Antonio Artal , Ricardo J. Rodr´ıguez , Jos´e Merseguer

«All wrongs reversed

jaartal@gmail.com, rjrodriguez@fi.upm.es, jmerse@unizar.es

@RicardoJRdez ※ www.ricardojrodriguez.es

Universidad Polit´ ecnica de Madrid

Universidad de Zaragoza

Madrid, Spain Zaragoza, Spain

June 21th, 2013

3 rd Edition of Hack in Paris

Sequoia Lodge Hotel, Disneyland Paris

(2)

$whoami

$ whoami

(3)

$ whoami

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 2 / 44

(4)

$whoami

$ whoami

(5)

$ whoami

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 2 / 44

(6)

$whoami

$ whoami

(7)

$ whoami

CLS member since early beginnings (2000) Ph.D.student at University of Zaragoza

Working currently for Technical University of Madrid Performance analysis of complex systems

Secure software engineering

Fault-Tolerant systems (design and analysis) Malware analysis (techniques and relative stuff) Safety analysis in component-based systems

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 2 / 44

(8)

$whoami

$ whoami

CLS member since early beginnings (2000) Ph.D.student at University of Zaragoza

Working currently for Technical University of Madrid Performance analysis of complex systems

Secure software engineering

Fault-Tolerant systems (design and analysis)

Malware analysis (techniques and relative stuff)

Safety analysis in component-based systems

My Ph.D. viva is next Monday! Cross fingers!! ¨ ⌣

(9)

Development Code License

GPL v3

(http://gplv3.fsf.org/) Intel Open Source License

(http://opensource.org/licenses/

intel-open-source-license.html) Specified in each source file

Source available at

http://webdiis.unizar.es/~ricardo/files/

HIP2013.tar.gz (VS2008 project + this slides)

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 3 / 44

(10)

Development Code License

Development Code License

GPL v3

(http://gplv3.fsf.org/) Intel Open Source License

(http://opensource.org/licenses/

intel-open-source-license.html) Specified in each source file

Source available at

http://webdiis.unizar.es/~ricardo/files/

HIP2013.tar.gz (VS2008 project + this slides)

no add-ons. . . trust me ¨ ⌣

(11)

Outline

1 An Introduction to DBI

What (the hell) is Dynamic Binary Instrumentation (DBI)?

How does DBI work?

Uses of DBI in Computer Security

2 DBI Frameworks

DBI Framework: What is?

Types of DBI frameworks Analysis and Comparative

3 Applying DBI to Computer Security. . . Developing DBAs with Pin: Pintools DBI vulnerability search

Taint analysis Reverse Engineering

4 Conclusions and Acknowledgments

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 4 / 44

(12)

An Introduction to DBI

Outline

1 An Introduction to DBI

What (the hell) is Dynamic Binary Instrumentation (DBI)?

How does DBI work?

Uses of DBI in Computer Security

2 DBI Frameworks

DBI Framework: What is?

Types of DBI frameworks Analysis and Comparative

3 Applying DBI to Computer Security. . . Developing DBAs with Pin: Pintools DBI vulnerability search

Taint analysis Reverse Engineering

4 Conclusions and Acknowledgments

(13)

DBI: What is? (I)

DBI: Dynamic Binary Instrumentation

Main Words

Instrumentation ??

Dynamic ??

Binary ??

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 6 / 44

(14)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (I)

DBI: Dynamic Binary Instrumentation

Main Words

Instrumentation ??

Dynamic ??

Binary ??

(15)

DBI: What is? (II)

Instrumentation?

Instrumentation

“Being able to observe, monitor and modify the behaviour of a computer program” (Gal Diskin)

Arbitrary addition of code in executables to collect some information

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 7 / 44

(16)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (II)

Instrumentation?

Instrumentation

“Being able to observe, monitor and modify the behaviour of a computer program” (Gal Diskin)

Arbitrary addition of code in executables to collect some information Analyse and control everything around an executable code

Collect some information

Arbitrary code insertion

(17)

DBI: What is? (III)

Instrumentation ??

Dynamic ??

Binary ??

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 8 / 44

(18)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (III)

Instrumentation What is happening. . .

Dynamic ??

Binary ??

(19)

DBI: What is? (III)

Instrumentation What is happening. . .

Dynamic ??

Binary ??

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 8 / 44

(20)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (IV)

Dynamic?

Code analysis Static

BEFORE execution

All possible execution paths are explored → not extremely good for performance

Dynamic

DURING the execution

Just one execution path (it may depend on the input data!)

(21)

DBI: What is? (V)

Instrumentation What is happening. . .

Dynamic ??

Binary ??

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 10 / 44

(22)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (V)

Instrumentation What is happening. . . Dynamic DURING the execution. . .

Binary ??

(23)

DBI: What is? (V)

Instrumentation What is happening. . . Dynamic DURING the execution. . .

Binary ??

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 10 / 44

(24)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (IV)

Binary?

Dynamic analysis

Source code available Source code Compiler

No source code (common case ¨ ⌣ ) Binary

Static (i.e., creating a new binary – with extras) Dynamic

Environment

Emulation

Virtual

Debugging

(25)

DBI: What is? (VI)

Instrumentation What is happening. . . Dynamic DURING the execution. . .

Binary ??

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 12 / 44

(26)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (VI)

Instrumentation What is happening. . .

Dynamic DURING the execution. . .

Binary of a binary (executable). . .

(27)

DBI: What is? (VII)

DBI advantages

Binary instrumentation: advantages

Programming language (totally) independent Machine-mode vision

We can instrument proprietary software

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 13 / 44

(28)

An Introduction to DBI What (the hell) is Dynamic Binary Instrumentation (DBI)?

DBI: What is? (VII)

DBI advantages

Binary instrumentation: advantages

Programming language (totally) independent Machine-mode vision

We can instrument proprietary software

Dynamic Instrumentation: advantages No need to recompile/relink each time Allow to find on-the-fly code

Dynamically generated code

Allow to instrument a process in execution already (attach)

(29)

DBI: What is? (IIX)

DBI disadvantages

Main disadvantages

Overhead (by the instrumentation during execution)

⇓ performance (analyst hopelessness!)

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 14 / 44

(30)

An Introduction to DBI How does DBI work?

How does DBI work? (I)

Recall: arbitrary code addition during the execution of a binary

Running code

(31)

How does DBI work? (I)

Recall: arbitrary code addition during the execution of a binary

What do I insert? → instrumentation function

Running code Arbitrary

code

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 15 / 44

(32)

An Introduction to DBI How does DBI work?

How does DBI work? (I)

Recall: arbitrary code addition during the execution of a binary

What do I insert? → instrumentation function Where? → addition places

Running code Arbitrary

code

(33)

How does DBI work? (II)

Placing DBI in the context of dynamic analysis

Definition (informal)

Executable transformation Total control over execution No need of architectural support

Binary

Hardware Debugger

Debugging

Hardware Binary

Virtualization

Hardware Binary

DBI Binary

Emulation Hardware Emulador

Virtualization Total control?

Emulation

Executable transformation Debugging

Architectural support (a must. . . )

J-Y. Marion, D. ReynaudDynamic Binary Instrumentation for Deobfuscation and Unpacking.DeepSec, 2009

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 16 / 44

(34)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics

(35)

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 17 / 44

(36)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics

Call-graphs generation

Memory leaks detection

(37)

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 17 / 44

(38)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics

Call-graphs generation

Memory leaks detection

Instruction profiling

Data dependency profiling

(39)

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 17 / 44

(40)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

Race conditions detection

(41)

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

Race conditions detection Computer Architecture:

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 17 / 44

(42)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

Race conditions detection Computer Architecture:

Trace generators (memory)

(43)

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

Race conditions detection Computer Architecture:

Trace generators (memory) Branch (and cache) predictors

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 17 / 44

(44)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

Race conditions detection Computer Architecture:

Trace generators (memory)

Branch (and cache) predictors

Memory failures recovery

(45)

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

Race conditions detection Computer Architecture:

Trace generators (memory) Branch (and cache) predictors Memory failures recovery

Simulation of speculation strategies

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 17 / 44

(46)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (I)

Non security-related uses

Code coverage and metrics Call-graphs generation Memory leaks detection Instruction profiling Data dependency profiling Threads profiling

Race conditions detection Computer Architecture:

Trace generators (memory) Branch (and cache) predictors Memory failures recovery

Simulation of speculation strategies

(47)

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 18 / 44

(48)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis

Vulnerability detection

(49)

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis Vulnerability detection

Test cases / fuzzing generation

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 18 / 44

(50)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis Vulnerability detection

Test cases / fuzzing generation

Advance monitoring (NSA way)

(51)

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis Vulnerability detection

Test cases / fuzzing generation Advance monitoring (NSA way) Reverse Engineering

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 18 / 44

(52)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis Vulnerability detection

Test cases / fuzzing generation Advance monitoring (NSA way) Reverse Engineering

Privacy monitoring

(53)

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis Vulnerability detection

Test cases / fuzzing generation Advance monitoring (NSA way) Reverse Engineering

Privacy monitoring Sandboxing

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 18 / 44

(54)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (II)

Secuirty-related uses

Data control flow analysis Vulnerability detection

Test cases / fuzzing generation Advance monitoring (NSA way) Reverse Engineering

Privacy monitoring

Sandboxing

. . .

(55)

Uses of DBI in Computer Security (III)

Some security tools that use DBI. . .

Vulnerability search SAGE (Microsoft) Sogetis

Fuzzgrind Avalanche Determine Pincov Taintdroid VERA TraceSurfer . . .

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 19 / 44

(56)

An Introduction to DBI Uses of DBI in Computer Security

Uses of DBI in Computer Security (IV)

Its popularity is in crescendo (1)

Covert Debugging: Circumventing Software Armoring, D. Quist &

Valsmith, BH USA 2007/DefCon 15

Generic Unpacking of Self-modifying, Aggressive, Packed Binary Programs (P. Bania, CoRR abs/0905.4581 2009)

Tarte Tatin Tools: a set of plugins for malware analysis with Pin, (D.

Reynaud, DeepSec 2009)

Dynamic Binary Instrumentation for Deobfuscation and Unpacking (J-Y. Marion & D. Reynaud, DeepSec 2009)

Dumping Shellcode with Pin (S. Porst, Zynamics 2010)

Binary Instrumentation for Security Professionals (G. Diskin, BH USA 2011)

Shellcode Analysis using Dynamic Binary Instrumentation (D. Radu &

(57)

Uses of DBI in Computer Security (V)

Its popularity is in crescendo (2)

Hacking using Dynamic Binary Instrumentation (G. Diskin, HITB 2012 AMS)

Improving Unpacking Process using DBI techniques (R.J. Rodr´ıguez, RootedCON 2012)

Improving Software Security with Dynamic Binary Instrumentation (R. Johnson, InfoSec Southwest 2012)

Vulnerability Analysis and Practical Data Flow Analysis &

Visualization (J.W. Oh, CanSecWest 2012)

Light and Dark side of Code Instrumentation (D. Evdokimov, CONFidence 2012)

Dynamic Binary Instrumentation Frameworks: I know you’re there spying on me (F. Falcon & N. Riva, RECon 2012)

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 21 / 44

(58)

DBI Frameworks

Outline

1 An Introduction to DBI

What (the hell) is Dynamic Binary Instrumentation (DBI)?

How does DBI work?

Uses of DBI in Computer Security

2 DBI Frameworks

DBI Framework: What is?

Types of DBI frameworks Analysis and Comparative

3 Applying DBI to Computer Security. . . Developing DBAs with Pin: Pintools DBI vulnerability search

Taint analysis Reverse Engineering

4 Conclusions and Acknowledgments

(59)

DBI Framework: What is? (I)

Provide a bunch of APIs for tool development DBA: Dynamic Binary Analysis tool

DBAs types:

Light-weight

Heavy-weight (the use intermediate code)

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 23 / 44

(60)

DBI Frameworks DBI Framework: What is?

DBI Framework: What is? (I)

Provide a bunch of APIs for tool development DBA: Dynamic Binary Analysis tool

DBAs types:

Light-weight

Heavy-weight (the use intermediate code) Main components

Core: just-in-time (JIT) compiler Controls execution of a binary Library (this is your own developed tool)

Where?

What?

$ < DBI fw core > < myLibrary > < binaryToInstrument >

(61)

DBI Framework: What is? (II)

Use modes (most common) JIT

Modification of a (small) set of instructions before executing them More robust

Good way for repetitive behaviour binaries (e.g., loops) Probe

Memory patching

Less overhead (it executes native code) Not supported by all DBI fws.

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 24 / 44

(62)

DBI Frameworks DBI Framework: What is?

DBI Framework: What is? (II)

Use modes (most common) JIT

Modification of a (small) set of instructions before executing them More robust

Good way for repetitive behaviour binaries (e.g., loops) Probe

Memory patching

Less overhead (it executes native code) Not supported by all DBI fws.

Granularity

Instruction Basic Superblock Trace Routine Image Block

++ – –

(63)

DBI Framework: What is? (II)

Use modes (most common) JIT

Modification of a (small) set of instructions before executing them More robust

Good way for repetitive behaviour binaries (e.g., loops) Probe

Memory patching

Less overhead (it executes native code) Not supported by all DBI fws.

Granularity

Instruction Basic Superblock Trace Routine Image Block

++ – –

→ Some not supported in some DBI fws.. . .

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 24 / 44

(64)

DBI Frameworks Types of DBI frameworks

Types of DBI frameworks (I)

DB fws in the wild

Pin DynInst

Valgrind Dtrace HDtrans

DynamoRIO Systemap

(65)

Types of DBI frameworks (I)

DB fws in the wild

Pin DynInst

Valgrind Dtrace HDtrans

DynamoRIO Systemap

Mmm. . . what is the much better?

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 25 / 44

(66)

DBI Frameworks Types of DBI frameworks

Types of DBI frameworks (I)

DB fws in the wild

Pin DynInst

Valgrind Dtrace HDtrans

DynamoRIO Systemap

Mmm. . . what is the much better?

Selection criteria

Software being maintained

License gives access to the source code Free

API provided

(67)

Types of DBI frameworks (II)

Differences y similarities

Characteristics

Ph.D. thesis, Univ. Cambridge Source code available (GNU GPL v2) Heavy-weight DBAs (using VEX IR as intermediate code)

http://www.valgrind.org Instruction Basic block Superblock Trace Routine IMage

Framework Version Supported Arch. O.S. Granularity

Valgrind

3.8.1 (18/09/2012) Arm, PowerPC, s390, x86, x64 Android, OSX, Linux I S

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 26 / 44

(68)

DBI Frameworks Types of DBI frameworks

Types of DBI frameworks (II)

Differences y similarities

Characteristics Intel

Source code available (but proprietary license) It allows to attach a process in execution http://www.pintool.org/

Instruction Basic block Superblock Trace Routine IMage

Framework Version Supported Arch. O.S. Granularity

Valgrind

3.8.1 (18/09/2012) Arm, PowerPC, s390, x86, x64 Android, OSX, Linux I S

Pin

2.12 (10/10/2012) Arm, IA-64, x86, x64 Windows, Linux I B T R M

(69)

Types of DBI frameworks (II)

Differences y similarities

Characteristics MIT, HP, Google

Source code available (BSD-2) Really good docs

http://www.dynamorio.org/

Instruction Basic block Superblock Trace Routine IMage

Framework Version Supported Arch. O.S. Granularity

Valgrind

3.8.1 (18/09/2012) Arm, PowerPC, s390, x86, x64 Android, OSX, Linux I S

Pin

2.12 (10/10/2012) Arm, IA-64, x86, x64 Windows, Linux I B T R M

DynamoRIO

3.2.0-3 (01/03/2012) x86, x64 Windows, Linux I B T

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 26 / 44

(70)

DBI Frameworks Types of DBI frameworks

Types of DBI frameworks (II)

Differences y similarities

Similarities

Injected code in C/C++

No need of having the source code of binary to be

instrumented GNU/Linux x86 Instruction Basic block Superblock Trace Routine IMage

Framework Version Supported Arch. O.S. Granularity

Valgrind

3.8.1 (18/09/2012) Arm, PowerPC, s390, x86, x64 Android, OSX, Linux I S

Pin

2.12 (10/10/2012) Arm, IA-64, x86, x64 Windows, Linux I B T R M

(71)

DBI frameworks comparative (I)

DBA tool for comparative

Counting executed instructions

Two granularities: instruction and basic block

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 27 / 44

(72)

DBI Frameworks Analysis and Comparative

DBI frameworks comparative (I)

DBA tool for comparative

Counting executed instructions

Two granularities: instruction and basic block

Comparative Aim

Evaluate the performance of selected DBI fws.

Slowdown: t instrumented

t no instrumented

(73)

DBI frameworks comparative (I)

DBA tool for comparative

Counting executed instructions

Two granularities: instruction and basic block

Comparative Aim

Evaluate the performance of selected DBI fws.

Slowdown: t instrumented

t no instrumented

Diving into the APIs

Pin: ↑ Documentation, ↑↑ Examples, ↑ Tutorials

DynamoRIO: ↑↑ Documentation, ↑ Examples, ↑ Tutorials Valgrind: ↓ Documentation, ↓ Examples, ↓ Tutorials

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 27 / 44

(74)

DBI Frameworks Analysis and Comparative

DBI frameworks comparative (II)

Experimental settings Hardware

Intel Core2 Duo 2GHz 667MHz, 2GiB DDR2, HDD 120GB Software

Fedora Core 14 32bits, gcc 4.5.1, GNU Fortran 4.5.1, r3

(75)

DBI frameworks comparative (II)

Experimental settings Hardware

Intel Core2 Duo 2GHz 667MHz, 2GiB DDR2, HDD 120GB Software

Fedora Core 14 32bits, gcc 4.5.1, GNU Fortran 4.5.1, r3

Benchmark

Own benchmark created for the comparative Considered benchmarks (e.g., SPEC) discarded Different categories:

Integer computation Float computation I/O

Use of memory

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 28 / 44

(76)

DBI Frameworks Analysis and Comparative

DBI frameworks comparative (III): Results (1)

Average of memory consumption

(77)

DBI frameworks comparative (III): Results (2)

Slowdown by instrumentations

PIN −O0 Valgrind −O0 DRIO −O0 PIN −O3 Valgrind −O3 DRIO −O3 0

2 4 6 8 10 12 14 16 18 20

Slowdown

Instructions Basic blocks

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 30 / 44

(78)

DBI Frameworks Analysis and Comparative

DBI frameworks comparative (III): Results (3)

Conclusions

X Running optimised code or (int/float) computation → DynamoRIO X Slower solution → Valgrind

Memory consumption X ↓ Pin

X ↑ DynamoRIO

Some funny things discovered during the research. . .

No. of instructions differs among the DBI fws. → each one starts in a different point

Bug detected when 80-bit numbers rounding in 32 and 64 bits archs.

(Valgrind)

Already reported :( (https://bugs.kde.org/show_bug.cgi?

id=19791)

(79)

DBI frameworks comparative (III): Results (4)

Technical Report

Estudio comparativo de frameworks de Instrumentaci´ on Din´ amica de Ejecutables (J.A. Artal)

Fro Spanish guys. . . (we should write some paper soon on this)

http://webdiis.unizar.es/~ricardo/files/PFC.Estudio.Frameworks.

DBI/Memoria_PFC_EstudioDBI.pdf

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 32 / 44

(80)

Applying DBI to Computer Security. . .

Outline

1 An Introduction to DBI

What (the hell) is Dynamic Binary Instrumentation (DBI)?

How does DBI work?

Uses of DBI in Computer Security

2 DBI Frameworks

DBI Framework: What is?

Types of DBI frameworks Analysis and Comparative

3 Applying DBI to Computer Security. . . Developing DBAs with Pin: Pintools DBI vulnerability search

Taint analysis Reverse Engineering

4 Conclusions and Acknowledgments

(81)

Developing DBAs with Pin: Pintools (I)

VM + code cache + API instrumentation

DBA → Pintool VM: JIT + emulator + dispatcher

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 34 / 44

(82)

Applying DBI to Computer Security. . . Developing DBAs with Pin: Pintools

Developing DBAs with Pin: Pintools (I)

VM + code cache + API instrumentation

DBA → Pintool VM: JIT + emulator + dispatcher

1 JIT compiles and instruments the binary code

2 Launched by the dispatcher

3 Stored in code cache

(83)

Developing DBAs with Pin: Pintools (I)

VM + code cache + API instrumentation

DBA → Pintool VM: JIT + emulator + dispatcher

1 JIT compiles and instruments the binary code

2 Launched by the dispatcher

3 Stored in code cache Works on the O.S.: user-space

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 34 / 44

(84)

Applying DBI to Computer Security. . . Developing DBAs with Pin: Pintools

Developing DBAs with Pin: Pintools (II)

An example: inscount.cpp

(85)

DBI vulnerability search (I): Double Free

Demo: DoubleFreeDBA.dll

Vulnerability description

CWE-415 (http://cwe.mitre.org/data/definitions/415.html) Call free() with the same @ → corrupt memory

“Doubly freeing memory may result in a write-what-where condition, allowing an attacker to execute arbitrary code”

DBA developed with Pin (DoubleFreeDBA.dll) Where?

APIs RtlAllocateHeap (after), RtlAllocateFree (before) What?

RtlAllocateHeap: keeps returned @ in a list

RtlAllocateFree: removes @ from list, and reports if not found!

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 36 / 44

(86)

Applying DBI to Computer Security. . . DBI vulnerability search

DBI vulnerability search (I): Double Free

Demo: DoubleFreeDBA.dll

Vulnerability description

CWE-415 (http://cwe.mitre.org/data/definitions/415.html) Call free() with the same @ → corrupt memory

“Doubly freeing memory may result in a write-what-where condition, allowing an attacker to execute arbitrary code”

DBA developed with Pin (DoubleFreeDBA.dll) Where?

APIs RtlAllocateHeap (after), RtlAllocateFree (before) What?

RtlAllocateHeap: keeps returned @ in a list

RtlAllocateFree: removes @ from list, and reports if not found!

(87)

DBI vulnerability search (II): Buffer Overflow (1)

Demo: BufferOverflowDBA.dll

Vulnerability description

CWE-120 (http://cwe.mitre.org/data/definitions/120.html) Copy a buffer without restrictions → arbitrary code execution

“Buffer overflows often can be used to execute arbitrary code [...].

Buffer overflows generally lead to crashes [...].”

DBA developed with Pin (BufferOverflowDBA.dll) Works around scanf

Where?→ API scanf (before) What?

Checks parameters seeking buffers without limits

Improvements: extend to other vulnerable APIs (e.g., strcpy)

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 37 / 44

(88)

Applying DBI to Computer Security. . . DBI vulnerability search

DBI vulnerability search (II): Buffer Overflow (1)

Demo: BufferOverflowDBA.dll

Vulnerability description

CWE-120 (http://cwe.mitre.org/data/definitions/120.html) Copy a buffer without restrictions → arbitrary code execution

“Buffer overflows often can be used to execute arbitrary code [...].

Buffer overflows generally lead to crashes [...].”

DBA developed with Pin (BufferOverflowDBA.dll) Works around scanf

Where?→ API scanf (before) What?

Checks parameters seeking buffers without limits

Improvements: extend to other vulnerable APIs (e.g., strcpy)

(89)

DBI vulnerability search (II): Buffer Overflow (2)

Demo: ProtectRetAddrDBA.dll

Vulnerability description

CWE-120 (http://cwe.mitre.org/data/definitions/120.html) Copy a buffer without restrictions → arbitrary code execution

“Buffer overflows often can be used to execute arbitrary code [...].

Buffer overflows generally lead to crashes [...].”

DBA developed with Pin (ProtectRetAddrDBA.dll)

Where? → every CALL (before) o RETN (before) in .text section What?

CALL → stores legitimate return address (EIP + size (CALL)) RETN → checks if retn address is in the list. . .

Detected 6 retn changes in ntdll.dll library!!

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 38 / 44

(90)

Applying DBI to Computer Security. . . DBI vulnerability search

DBI vulnerability search (II): Buffer Overflow (2)

Demo: ProtectRetAddrDBA.dll

Vulnerability description

CWE-120 (http://cwe.mitre.org/data/definitions/120.html) Copy a buffer without restrictions → arbitrary code execution

“Buffer overflows often can be used to execute arbitrary code [...].

Buffer overflows generally lead to crashes [...].”

DBA developed with Pin (ProtectRetAddrDBA.dll)

Where? → every CALL (before) o RETN (before) in .text section What?

CALL → stores legitimate return address (EIP + size (CALL)) RETN → checks if retn address is in the list. . .

Detected 6 retn changes in ntdll.dll library!!

(91)

DBI vulnerability search (III): Taint analysis

Demo: TaintAnalysisDBA.dll

DBA developed with Pin (TaintAnalysisDBA.dll) Taint analysis of scanf parameters

Where? → API scanf (after) What?

Trace all registers/memory zones contaminated from the input data

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 39 / 44

(92)

Applying DBI to Computer Security. . . Taint analysis

DBI vulnerability search (III): Taint analysis

Demo: TaintAnalysisDBA.dll

DBA developed with Pin (TaintAnalysisDBA.dll) Taint analysis of scanf parameters

Where? → API scanf (after) What?

Trace all registers/memory zones contaminated from the input data

Friendly reminder: Make a demo. . .

(93)

DBI vulnerability search (IV): Reverse Engineering

Demo: EasyPasswordDBA.dll – very naif example

DBA developed with Pin (EasyPasswordDBA.dll) Seeking for the correct key

Hook when calling to string comparison lstrcmpA Where?

API lstrcmpA (before) What?

Log all function parameters

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 40 / 44

(94)

Applying DBI to Computer Security. . . Reverse Engineering

DBI vulnerability search (IV): Reverse Engineering

Demo: EasyPasswordDBA.dll – very naif example

DBA developed with Pin (EasyPasswordDBA.dll) Seeking for the correct key

Hook when calling to string comparison lstrcmpA Where?

API lstrcmpA (before) What?

Log all function parameters

This is not longer valid for current apps. . . isn’t it? ¨ ⌣

(95)

DBI vulnerability search (IV): Reverse Engineering

Demo: EasyPasswordDBA.dll – very naif example

DBA developed with Pin (EasyPasswordDBA.dll) Seeking for the correct key

Hook when calling to string comparison lstrcmpA Where?

API lstrcmpA (before) What?

Log all function parameters

This is not longer valid for current apps. . . isn’t it? ¨ ⌣ Friendly reminder: Make a demo. . .

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 40 / 44

(96)

Conclusions and Acknowledgments

Outline

1 An Introduction to DBI

What (the hell) is Dynamic Binary Instrumentation (DBI)?

How does DBI work?

Uses of DBI in Computer Security

2 DBI Frameworks

DBI Framework: What is?

Types of DBI frameworks Analysis and Comparative

3 Applying DBI to Computer Security. . . Developing DBAs with Pin: Pintools DBI vulnerability search

Taint analysis Reverse Engineering

4 Conclusions and Acknowledgments

(97)

Conclusions

DBI frameworks: fast and easy development → high potential NO need of (too much) advanced O.S. programming knowledge

We can focus in what really matters: our DBA tool Disadvantages:

DBI API knowledge Execution time

Recall about the DBI fws. comparison. . .

X Running optimised code or (int/float) computation → DynamoRIO X Slower solution → Valgrind

Memory consumption X ↓ Pin

X ↑ DynamoRIO

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 42 / 44

(98)

Conclusions and Acknowledgments

Acknowledgments

Gal Diskin

Dimitry “D1g1” Evdokimov Francisco Falcon & Nahuel Riva CrackLatinoS (CLS)

Hack in Paris staff, thank you guys & gals!

(99)

Acknowledgments

Gal Diskin

Dimitry “D1g1” Evdokimov Francisco Falcon & Nahuel Riva CrackLatinoS (CLS)

Hack in Paris staff, thank you guys & gals!

To you for hearing me stoically. . .

J.A. Artal, R.J. Rodr´ıguez, J. Merseguer DBI for Computer Security: Uses and Comparative June 21th, 2013 43 / 44

(100)

DBI for Computer Security: Uses and Comparative

Juan Antonio Artal , Ricardo J. Rodr´ıguez , Jos´e Merseguer

«All wrongs reversed

jaartal@gmail.com, rjrodriguez@fi.upm.es, jmerse@unizar.es

@RicardoJRdez ※ www.ricardojrodriguez.es

Universidad Polit´ ecnica de Madrid

Universidad de Zaragoza

Madrid, Spain Zaragoza, Spain

June 21th, 2013

3 rd Edition of Hack in Paris

Références

Documents relatifs

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des

The more information technology becomes sophisticated, the more complex methods and tools are used to fight with criminal activities, especially with computer terrorism [23]..

Destroy property and stolen Computer files and records Information system Intellectual Property Publishing of information, which is obscene in electronic form. Cyber stalking

In this paper some pipeline leak detection methodologies are studied to come up with a design structure that could ease pipeline leak detection and monitoring

Since basic Pig Latin is made for batch processing, it was necessary to enhance Piglet’s input language by streaming operators such as Socket_Read, Socket_Write and Window as well

Measuring the amount of positive and negative reviews given by developer is also an important measure from the quality control perspective, because if some reviewer gives

The proposed method lets us answer questions about the relation of code and test groups to investigate how tests intended for a functionality cover the associated procedures; and

In the context of CGPE, where we represent polynomial evaluation expres- sions with DAGs, we can benefit from this work on instruction selection by combining it with the