using smt solvers for binary analysis and exploitation
play

Using SMT solvers for binary analysis and exploitation A primer on - PowerPoint PPT Presentation

Using SMT solvers for binary analysis and exploitation A primer on SMT, SMT solvers, Z3 & angr Carl Svensson August 29, 2018 Nixucon 2018 About me Carl Svensson, 27 MSc in Computer Science, KTH Head of Security, KRY/LIVI


  1. Using SMT solvers for binary analysis and exploitation A primer on SMT, SMT solvers, Z3 & angr Carl Svensson August 29, 2018 Nixucon 2018

  2. About me • Carl Svensson, 27 • MSc in Computer Science, KTH • Head of Security, KRY/LIVI • CTF-player, HackingForSoju 1 •  calle.svensson@zeta-two.com •  @zetatwo •  https://zeta-two.com

  3. Reverse engineering in 15 seconds? • Take stufg, e.g. software, apart • Understand how it works • Many possible goals • How can I reach a specifjc state? 2

  4. What is SMT? • Satisfjability modulo theories, SMT • A bunch of variables • A bunch of theories • Theory = A bunch of rules • A bunch of formulas • Can we fjnd values for all values s.t. all formulas are satisifed? 3

  5. SMT: Example 1 4 x + 13 = 37

  6. SMT: Example 2 5 x + y + 13 = 37 − z x − 2 · y + 10 = 10 · z 4 · x − z + 13 = 37 + y

  7. SMT: Example 3 6

  8. Microsoft to the rescue • Can we automate? Yes! • Microsoft Research • Z3 Theorem Prover • General purpose • Own language • Bindings for several languages • Open source & cross platform 7

  9. Using Z3 in Python 8

  10. Using Z3 in RE Throwback Thursday: Starcraft 9

  11. Throwback Thursday: Starcraft • Commercial software • Released in 1998 • Simple protections • Good starting point • Requires a serial key • Can we create our own? 10

  12. Getting to the core: Installer 11

  13. Getting to the core: Serial key input 12

  14. Getting to the core: Resource strings 13

  15. Getting to the core: Decompilation 14

  16. Getting to the core: Call graph 15

  17. Getting to the core: Call graph 16

  18. Getting to the core: Decompilation 17

  19. Z3: Formulating formulas 18

  20. Z3: Formulating formulas 19

  21. Symbolic execution • Symbols vs. concrete values • Pro: Explore ”all” paths • Con: Exponential complexity 20

  22. Once again, with fee... angr • ”python framework for analyzing binaries” • ”both static and dynamic symbolic (concolic)” • Computer Security Lab at UC Santa Barbara • Uses Z3 internally 21

  23. Angr management: Extracting the code 22

  24. Angr management: Minimizing the code 23

  25. Angr management: Writing the explorer 24

  26. Can we use even less efgort? • Extracting code is cumbersome • Can’t we use the code in place? • ”Call” directly into validator • Symbolic argument • Patch away irrelevant parts 25

  27. Full fury: Writing the explorer 26

  28. Full fury: Writing the explorer 27

  29. Full fury: Writing the explorer 28

  30. Using Z3 in RE What about exploitation? 29

  31. Exploitation • IP control • Satisfy condition 30

  32. Exploitation with angr • Find execution path • Constrain execution • Satisfy condition 31

  33. Example from Security Fest CTF • Function pointer lookup • Index OOB • Hook messy function 32

  34. angr exploitation example 33

  35. angr exploitation example 34

  36. angr exploitation example 35

  37. angr exploitation example 36

  38. angr exploitation example > python exploit_angr . py 2147483648 RDX: f f f f f f f f f f f f f f f e > ./ bowrain_581bbadaafd23051a25ccb4adc80b670 . . . : 2147483648 [ 1 ] f a u l t ( core dumped) 37 Choice : 17059 segmentation

  39. Using Z3 in RE Even deobfuscation?! 38

  40. Obfuscation • Make code hard to read • for humans • for computers • Control fmow fmattening • Packer • Dropper • VM • Dead code 39

  41. Deobfuscation in general • Undo the mess • Hard problem 40

  42. Deobfuscation of dead code with angr • Prove that dead code is dead • Prove uniqueness of value 41

  43. Example: indirect jmp deobfuscator 42

  44. Example from mobile app • Find ”jmp reg” • Search callgraph backwards • Search forward • Simplify expression • Replace code 43

  45. Example: indirect jmp deobfuscator 44

  46. Example: indirect jmp deobfuscator 45

  47. Example: indirect jmp deobfuscator 46

  48. Example: indirect jmp deobfuscator 47

  49. Thanks for listening! 47

Recommend


More recommend