27
Romain Thomas - [email protected] LIEF: Library to Instrument Executable Formats

LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Romain Thomas - [email protected]

LIEF: Library to Instrument Executable Formats

Page 2: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Table of Contents

Introduction

Architecture

Demo

Conclusion

Page 3: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

About

I Romain Thomas - Security engineer at Quarkslab

I Working on obfuscation and software protection, reverse engineering

I Contributor to the Triton project(https://triton.quarkslab.com)

Page 4: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Layers of information

pefile, readelf, otool, LLVM . . .

LLVM, IDA, diStorm . . .

Intel PIN, Qemu,gdb, Triton . . .

Tools

Format

ELF, PE, Mach-O, COFF, XCOFF...

ContentDisassembler:x86, ARM, MIPS, AArch64 ...

BehaviorDBI, emulator, sandbox, debugger...

Figure: Layer of information in an executable

Page 5: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Howto?

I Get assembly code?

I Get symbols?

I Get imported functions?

Page 6: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Executable File Formats in a Nutshell

Page 7: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Executable File Formats in a Nutshell

Executable file format gives information such as:

I First instruction address to execute.

I Libraries used

I Target architecture (x86, ARM . . . )

Page 8: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Executable File Formats in a Nutshell

The three mainstream formats:

I ELF: Linux, Android . . .

I PE: Windows

I Mach-O: OS-X, iOS, . . .

Page 9: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Modification

Format modifications can be a starting point to:

I Packing

I Watermarking

I Hooking: Perform interposition on functions

I Persistent code injection

I Malware analysis (static unpacking . . . )

Page 10: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Purpose of LIEF

I Provide a cross-platform library to parse ELF, PE and Mach-Oformats

I Abstract common features from the different formats (section,header, entry point, symbols . . . )

I Enable format modifications

I Provide an API for different languages (Python, C++, C . . . )

Page 11: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Howto? (answers)

Get assembly code?

1 import lief2 binary = lief.parse("C:\\ Windows \\ explorer.exe") # PE3 asm = binary.get_section(".text")

Page 12: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Howto? (answers)

Get assembly code?

1 import lief2 binary = lief.parse("C:\\ Windows \\ explorer.exe") # PE3 asm = binary.get_section(".text")

Page 13: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Howto? (answers)

Get symbols?

1 import lief2 binary = lief.parse("/bin/ls") # ELF3 for symbol in binary.symbols:4 print(symbols)

Page 14: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Howto? (answers)

Get symbols?

1 import lief2 binary = lief.parse("/bin/ls") # ELF3 for symbol in binary.symbols:4 print(symbols)

Page 15: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Howto? (answers)

Get imported functions?

1 import lief2 binary = lief.parse("/usr/lib/libc++abi.dylib") # Mach -O3 for function in binary.imported_functions:4 print(function)

Page 16: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Howto? (answers)

Get imported functions?

1 import lief2 binary = lief.parse("/usr/lib/libc++abi.dylib") # Mach -O3 for function in binary.imported_functions:4 print(function)

Page 17: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Table of Contents

Introduction

Architecture

Demo

Conclusion

Page 18: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Overview

Abstract layer

C++

LIEF

Python / C

ELF

ELF::Binary ELF::Parser ELF::Builder

PE

PE::Binary PE::Parser PE::Builder

Mach-O

MACHO::Binary MACHO::Parser MACHO::Builder

Figure: Global architecture

Page 19: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Modification process

LIEF objectLIEF object

/bin/ls(modified)/bin/ls

Modification

ParserBuilder

Header

Sections

.text

.data

Segments

LOAD

DYNAMIC

Header

Sections

.text

.data

.new section

Segments

LOAD

DYNAMIC

Page 20: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Table of Contents

Introduction

Architecture

Demo

Conclusion

Page 21: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Demo!

Page 22: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Table of Contents

Introduction

Architecture

Demo

Conclusion

Page 23: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Roadmap

Some ideas for next versions:

I Graphical User Interface (Work in progress)

I Handle the OAT format (subset of the ELF format)

I PE API to hook functions

I PE/Mach-O fuzzer

I Handle the Dwarf format

Page 24: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

I Source code is available on GitHub:https://github.com/lief-project (Apache 2.0 license)

I Website: https://lief.quarkslab.com

Missing feature or bug?

[email protected]

Open an issue / pull request

Page 25: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

I Source code is available on GitHub:https://github.com/lief-project (Apache 2.0 license)

I Website: https://lief.quarkslab.com

Missing feature or bug?

[email protected]

Open an issue / pull request

Page 26: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

I Source code is available on GitHub:https://github.com/lief-project (Apache 2.0 license)

I Website: https://lief.quarkslab.com

Missing feature or bug?

[email protected]

Open an issue / pull request

Page 27: LIEF: Library to Instrument Executable Formats...Architecture Demo Conclusion. About I Romain Thomas - Security engineer at Quarkslab ... Executable File Formats in a Nutshell Executable

Thank you!