binary program analysis theory and practice
play

Binary Program Analysis: Theory and Practice (what you code is not - PowerPoint PPT Presentation

Binary Program Analysis: Theory and Practice (what you code is not what you execute) Emmanuel Fleury <emmanuel.fleury@labri.fr> Joint work with: Grald Point <gerald.point@labri.fr> , Aymeric Vincent <aymeric.vincent@labri.fr>


  1. Binary Program Analysis: Theory and Practice (what you code is not what you execute) Emmanuel Fleury <emmanuel.fleury@labri.fr> Joint work with: Gérald Point <gerald.point@labri.fr> , Aymeric Vincent <aymeric.vincent@labri.fr> . LaBRI, Université Bordeaux 1, France June 13, 2013 E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 1 / 46

  2. Overview Binary Program Analysis 1 CFG Recovery 2 Insight: A Binary Analysis Framework 3 E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 2 / 46

  3. Overview Binary Program Analysis 1 Program Analysis Why Analyze Binary Program? Object of Study: Binary Programs Binary Code vs. Source Code What You Code Is Not What You Execute Analysis goals CFG Recovery 2 Insight: A Binary Analysis Framework 3 E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 3 / 46

  4. Program Analysis Definition Program analysis is the process of automatically deriving properties about the behavior of computer programs. Dynamic Program Analysis Static Program Analysis Analysis is performed by executing the Analysis is performed without actually program on chosen inputs. Traces of executing the program. An abstract the actual executions are collected and model of the program is issued and processed. Properties about program symbolically executed. Properties about behavior is deduced based on the program behavior is deduced from the analysis of these concrete executions. analysis of these symbolic executions. Techniques Techniques Software Testing Abstract Interpretation Performance Analysis Data-flow Analysis . . . Model-checking Theorem Proving . . . E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 4 / 46

  5. Input Program Formats for Analysis Abstract Model : All unnecessary information for the analysis have been removed. Only necessary information remains. Source Code : Keep track of high-level information about the program such as variables , types , functions . But also, variable and function names , and pragmas or code decorations . Bytecode : May vary depending on the bytecode considered, but keep track of few high-level information about the program such as types and functions . But, programs are unstructured . Binary File : Only keep track of the instructions in an unstructured way (no for-loop, no clear argument passing in procedures, . . . ). No type , no naming . But, the binary file may enclose meta-data that might be helpful (symbols, debug, . . . ). Memory Dump : Pure assembler instructions with a full memory state of the current execution. We do not have anymore the meta-data of the executable file. E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 5 / 46

  6. Input Program Formats for Analysis Abstract Model : All unnecessary information for the analysis have been removed. Only necessary information remains. Source Code : Keep track of high-level information about the program such as variables , types , functions . But also, variable and function names , and pragmas or code decorations . Bytecode : May vary depending on the bytecode considered, but keep track of few high-level information about the program such as types and functions . But, programs are unstructured . Binary File : Only keep track of the instructions in an unstructured way (no for-loop, no clear argument passing in procedures, . . . ). No type , no naming . But, the binary file may enclose meta-data that might be helpful (symbols, debug, . . . ). Memory Dump : Pure assembler instructions with a full memory state of the current execution. We do not have anymore the meta-data of the executable file. E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 5 / 46

  7. Input Program Formats for Analysis Abstract Model : All unnecessary information for the analysis have been removed. Only necessary information remains. Source Code : Keep track of high-level information about the program such as variables , types , functions . But also, variable and function names , and pragmas or code decorations . Bytecode : May vary depending on the bytecode considered, but keep track of few high-level information about the program such as types and functions . But, programs are unstructured . Binary File : Only keep track of the instructions in an unstructured way (no for-loop, no clear argument passing in procedures, . . . ). No type , no naming . But, the binary file may enclose meta-data that might be helpful (symbols, debug, . . . ). Memory Dump : Pure assembler instructions with a full memory state of the current execution. We do not have anymore the meta-data of the executable file. E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 5 / 46

  8. Input Program Formats for Analysis Abstract Model : All unnecessary information for the analysis have been removed. Only necessary information remains. Source Code : Keep track of high-level information about the program such as variables , types , functions . But also, variable and function names , and pragmas or code decorations . Bytecode : May vary depending on the bytecode considered, but keep track of few high-level information about the program such as types and functions . But, programs are unstructured . Binary File : Only keep track of the instructions in an unstructured way (no for-loop, no clear argument passing in procedures, . . . ). No type , no naming . But, the binary file may enclose meta-data that might be helpful (symbols, debug, . . . ). Memory Dump : Pure assembler instructions with a full memory state of the current execution. We do not have anymore the meta-data of the executable file. Binary code is the closest format of what will be executed ! E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 5 / 46

  9. Why Analyze Binary Program? The Lack of High-Level Source Code Low-level assembly code built-in the source code Legacy code Commercial Off-the-shelf software (COTS) Application stores (for cell phones and tablets) Malware or any “ hostile ” programs Technology forecasting Mistrust in the Compilation Chain C compiler possibly buggy Optimization probably buggy, yet optimized code reduce hardware cost Checking low-level bugs (exploitability of a stack buffer-overflow) Bugs with a strong interconnection with hardware What you code is not what you execute 1 (see further example) 1 Inspired by G. Balakrishnan and T. Reps. E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 6 / 46

  10. Binary Code vs. Source Code (1/3) We want to analyze binary code . It can come as: an executable file, an object file, a dynamic library, a firmware, a memory dump, . . . We don’t rely on getting the corresponding high-level source code . E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 7 / 46

  11. Binary Code vs. Source Code (1/3) We want to analyze binary code . It can come as: an executable file, an object file, a dynamic library, a firmware, a memory dump, . . . We don’t rely on getting the corresponding high-level source code . Until now, most of the analysis techniques have been designed for source code analysis. So, what do we loose exactly at looking at binary programs only ? E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 7 / 46

  12. Binary Code vs. Source Code (2/3) int Compile this to assembly addition(int x, int y) { Compile this to a binary object return x + y; Let’s compare those versions. } E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 8 / 46

  13. Binary Code vs. Source Code (2/3) int Compile this to assembly addition(int x, int y) { Compile this to a binary object return x + y; Let’s compare those versions. } $ gcc -S -m32 addition-function.c .file "addition -function.c" .text .globl addition .type addition , @function addition: .LFB0: pushl %ebp movl %esp , %ebp movl 12(% ebp), %eax movl 8(% ebp), %edx addl %edx , %eax popl %ebp ret .LFE0: .size addition , .-addition .ident "GCC:␣(Debian␣4.7.3 -4)␣4.7.3" .section .note.GNU -stack ,"",@progbits E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 8 / 46

  14. Binary Code vs. Source Code (2/3) int Compile this to assembly addition(int x, int y) { Compile this to a binary object return x + y; Let’s compare those versions. } $ gcc -S -m32 addition-function.c $ objdump -d addition-function.o .file "addition -function.c" addition - function.o : .text file format elf32 -i386 .globl addition .type addition , @function Disassembly of section .text: addition: .LFB0: 00000000 <addition >: pushl %ebp 0: 55 push %ebp movl %esp , %ebp 1: 89 e5 mov %esp ,% ebp movl 12(% ebp), %eax 3: 8b 45 0c mov 0xc(% ebp),%eax movl 8(% ebp), %edx 6: 8b 55 08 mov 0x8(% ebp),%edx addl %edx , %eax 9: 01 d0 add %edx ,% eax popl %ebp b: 5d pop %ebp ret c: c3 ret .LFE0: .size addition , .-addition .ident "GCC:␣(Debian␣4.7.3 -4)␣4.7.3" .section .note.GNU -stack ,"",@progbits E. Fleury (LaBRI, France) Binary Program Analysis: Theory and Practice June 13, 2013 8 / 46

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend