Coverage-Guided Fuzzing of Individual Functions Without Source Code

Coverage-Guided Fuzzing of Individual Functions Without Source Code

Coverage-guided Fuzzing of Individual Functions Without Source Code Alessandro Di Federico Politecnico di Milano October 25, 2018 1 Index Coverage-guided fuzzing An overview of rev.ng Experimental results 2 1 Generate a lot of different inputs 2 Feed them to a program 3 Wait for it to reach an invalid state 4 Collect a report for the analyst Fuzzing 3 Fuzzing 1 Generate a lot of different inputs 2 Feed them to a program 3 Wait for it to reach an invalid state 4 Collect a report for the analyst 4 Features Pros: • Easy to setup • It can find subtle bugs Cons: • It might require large amount of resources • Semi-decidable 5 Privilege inputs leading to cover new code paths A huge leap forward Coverage-guided fuzzing 6 A huge leap forward Coverage-guided fuzzing Privilege inputs leading to cover new code paths 7 A huge leap forward int main() { if(A&&B){ crash (); } else{ all_good(); } } 8 The Control-flow Graph A B 9 First run Input: 0000 0000 0000 0000 A B 10 First run Input: 0000 0000 0000 0000 A B 11 First run Input: 0000 0000 0000 0000 A B 12 First run Input: 0000 0000 0000 0000 A B 13 Second run Input: 0000 0000 0000 0001 A B 14 Second run Input: 0000 0000 0000 0001 A B 15 Second run Input: 0000 0000 0000 0001 A B 16 Second run Input: 0000 0000 0000 0001 A B 17 This input is not interesting! 18 Third run Input: 0001 0000 0000 0000 A B 19 Third run Input: 0001 0000 0000 0000 A B 20 Third run Input: 0001 0000 0000 0000 A B 21 Third run Input: 0001 0000 0000 0000 A B 22 Third run Input: 0001 0000 0000 0000 A B 23 This input is interesting! It led us to discover a new basic block 24 Fourth run Input: 0011 0000 0000 0000 A B 25 Fourth run Input: 0011 0000 0000 0000 A B 26 Fourth run Input: 0011 0000 0000 0000 A B 27 Fourth run Input: 0011 0000 0000 0000 A B 28 Fourth run Input: 0011 0000 0000 0000 A B 29 american fuzzy lop • It made coverage-guided fuzzing popular • Developed by lcamtuf • Performs instrumentation to detect executed basic blocks • Two key modes of operation: • Source mode • Binary mode 30 int main() { record (1); if(A&&B){ record (2); crash (); } else{ record (3); all_good(); } record (4); } Source mode Instrumentation is performed at compiler-level 31 Source mode Instrumentation is performed at compiler-level int main() { record (1); if(A&&B){ record (2); crash (); } else{ record (3); all_good(); } record (4); } 32 • QEMU is the chosen emulator • It incurs in a sensible slowdown Binary mode An emulator is employed to detect executed basic blocks 33 Binary mode An emulator is employed to detect executed basic blocks • QEMU is the chosen emulator • It incurs in a sensible slowdown 34 libfuzzer • Alternative to afl • It requires the source code to be available • Based on LLVM 35 What’s LLVM? LLVM is a compiler framework Famous for its C/C++ frontend (clang) and its intermediate representation (the LLVM IR) 36 libfuzzer can be a lot faster It doesn’t fork int main() { while (true) { char *new_input = random_input(); target(new_input); } } 37 Index Coverage-guided fuzzing An overview of rev.ng Experimental results 38 Everything you’ll see here is architecture-agnostic What is rev.ng? rev.ng is a unified framework for binary analysis based on QEMU and LLVM 39 What is rev.ng? rev.ng is a unified framework for binary analysis based on QEMU and LLVM Everything you’ll see here is architecture-agnostic 40 How does QEMU work? 41 A dynamic binary translator AArch64 ARM Alpha CRIS Unicore AArch64 SPARC ARM SPARC64 SuperH x86 SystemZ x86-64 PowerPC QEMU IR MIPS PowerPC64 PowerPC XCore SystemZ MIPS MIPS64 SPARC OpenRISC TCI MicroBlaze x86-64 x86 RISC V 42 The frontend is a lifter AArch64 ARM Alpha CRIS Unicore AArch64 SPARC ARM SPARC64 SuperH x86 SystemZ x86-64 PowerPC QEMU IR MIPS PowerPC64 PowerPC XCore SystemZ MIPS MIPS64 SPARC OpenRISC TCI MicroBlaze x86-64 x86 RISC V 43 rev.ng translates offline QEMU translates at run-time 44 QEMU translates at run-time rev.ng translates offline 45 rev.ng: a static binary translator Collect md5sum.arm entry points Lift to QEMU IR Collect new Translate entry points to LLVM IR Link runtime md5sum.x86-64 functions 46 Alpha ARM CRIS AArch64 Unicore RISC V SPARC64 Hexagon SPARC x86 QEMU IR SuperH x86-64 SystemZ MicroBlaze PowerPC OpenRISC PowerPC64 MIPS64 XCore MIPS 47 Alpha ARM CRIS AArch64 Unicore RISC V SPARC64 Hexagon SPARC x86 LLVM IR SuperH x86-64 SystemZ MicroBlaze PowerPC OpenRISC PowerPC64 MIPS64 XCore MIPS 48 Alpha ARM CRIS AArch64 Unicore RISC V SPARC64 Hexagon SPARC x86 rev.ng SuperH x86-64 SystemZ MicroBlaze PowerPC OpenRISC PowerPC64 MIPS64 XCore MIPS 49 Alpha ARM CRIS AArch64 Unicore RISC V SPARC64 Hexagon SPARC x86 rev.ng SuperH x86-64 SystemZ MicroBlaze PowerPC OpenRISC PowerPC64 MIPS64 XCore MIPS 50 We can employ libfuzzer directly We produce LLVM IR 51 We produce LLVM IR We can employ libfuzzer directly 52 Steps 1 Lift the program to LLVM IR 2 Identify all the functions 3 Identify a function to fuzz 4 Create the fuzzing function 5 Compile fuzzing function 6 Instrument using libfuzzer 7 Launch the fuzzer 53 Steps 1 Lift the program to LLVM IR 2 Identify all the functions 3 Identify a function to fuzz MANUAL 4 Create the fuzzing function MANUAL 5 Compile fuzzing function 6 Instrument using libfuzzer 7 Launch the fuzzer 54 Index Coverage-guided fuzzing An overview of rev.ng Experimental results 55 1 The LLVM optimizer has a wider view on the code 2 The translation is performed offline We are sensibly faster than QEMU 56 We are sensibly faster than QEMU 1 The LLVM optimizer has a wider view on the code 2 The translation is performed offline 57 Runtime (seconds) 4000 3000 2000 1000 458.sjeng Native 2000 464.h264ref 1500 QEMU 1000 400.perlbench rev.ng 500 471.omnetpp 58 401.bzip2 462.libquantum 483.xalancbmk 473.astar 429.mcf 403.gcc 445.gobmk 456.hmmer On average, 68% faster than QEMU 59 Not directly, but embedded in another program (less) A practical case study We want to fuzz the PCRE library 60 A practical case study We want to fuzz the PCRE library Not directly, but embedded in another program (less) 61 Steps (again) 1 Lift the program to LLVM IR 2 Identify all the functions 3 Identify a function to fuzz 4 Create the fuzzing function 5 Compile fuzzing function 6 Instrument using libfuzzer 7 Launch the fuzzer 62 Steps (again) 1 Lift the program to LLVM IR 2 Identify all the functions 3 Identify a function to fuzz 4 Create the fuzzing function 5 Compile fuzzing function 6 Instrument using libfuzzer 7 Launch the fuzzer 63 Fuzzing function (simplified) int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { char input_string[] ="Test␣string!"; void *compiled_re; compiled_re = pcre_compile(data); pcre_exec(compiled_re, input_string, strlen(input_string)); pcre_free(compiled_re); return 0; } 64 We were able to find a known vulnerability in PCRE 65 Comparing with afl Are we faster than afl? • afl fuzzing worked directly on PCRE (without less) • Used black-box mode 66 Performances Execs per second Total execs 1 min 10 min 60 min 60 min afl 3 582 3 495 3 682 13 187 295 rev.ng 150 617 79 701 78 306 271 217 728 67 Summary • We do not require the source code • We can fuzz any entry point • We are sensibly faster than existing techniques 68 Future works • Improve performances • Perform symbolic execution (through KLEE) 69 Future works Backup slides 70 Very effective! 71 License This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 72.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    72 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us