formal verification of program obfuscations
play

Formal verification of program obfuscations Sandrine Blazy joint - PowerPoint PPT Presentation

Formal verification of program obfuscations Sandrine Blazy joint work with Roberto Giacobazzi and Alix Trieu IFIP WG 2.11, 2015-11-10 1 Background: verifying a compiler Compiler + proof that the compiler does not introduce bugs CompCert, a


  1. Formal verification of program obfuscations Sandrine Blazy joint work with Roberto Giacobazzi and Alix Trieu IFIP WG 2.11, 2015-11-10 1

  2. Background: verifying a compiler Compiler + proof that the compiler does not introduce bugs CompCert, a moderately optimizing C compiler usable for critical embedded software • Fly-by-wire software, Airbus A380 and A400M, FCGU ( 3600 files): 
 mostly control-command code generated from Scade block diagrams + mini. OS • Commercially available since 2015 (AbsInt company) • Formal verification using the Coq proof assistant 2

  3. Methodology • The compiler is written inside the purely functional Coq programming language. Language Compiler • We state its correctness w.r.t. a formal Semantics specification of the language semantics. • We interactively and mechanically prove this. Correctness Proof • We decompose the proof in proofs for each compiler pass. Logical • We extract a Caml implementation of the Framework compiler. (here Coq) parser.ml compiler.ml pprinter.ml 3

  4. The formally verified part of the compiler side-e ff ects out of expressions type elimination Compcert C Clight C#minor loop simplifications Optimizations : constant prop., CSE, tail calls, stack allocation of «&»variables (LCM), (software pipelining) 
 CFG construction instruction expr. decomp. selection RTL CminorSel Cminor (instruction scheduling) register allocation (IRC) spilling, reloading linearization calling conventions of the CFG LTL LTLin Linear layout of stack frames asm code generation ASM Mach 4

  5. Let’s add some program obfuscations at the Clight source level and prove that they preserve the semantics of 
 Clight programs. 5

  6. Program 
 obfuscation 6

  7. Recreational obfuscation #define _ -F<00||--F-OO--; int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_ _-_-_-_ } Winner of the 1988 International Obfuscated C Code Contest 7

  8. Program obfuscation Goal: protect software, so that it is harder to reverse engineer 
 → Create secrets an attacker must know or discover in order to succeed • Diversity of programs • A recommended best practice 8

  9. Program obfuscation: state of the art • Trivial transformations: removing comments, 
 renaming variables • Hiding data: constant encoding, string encryption, 
 variable encoding, 
 variable splitting, 
 array splitting, array merging, array folding, 
 array flattening int original (int n) { 
 return 0; } • Hiding control-flow: opaque predicates, 
 function inlining and outlining, function interleaving, 
 loop transformations, 
 control-flow flattening int obfuscated (int n) { 
 if ((n+1)*n%2==0) 
 return 0; else return 1;} 9

  10. Program obfuscation: control-flow graph flattening int pc = 1; while (pc != 0) { i = 0; switch (pc) { case 1 : { i = 0; pc = 2; i <= 100 break; } 
 case 2 : { if (i <= 100) pc = 3; i++; else pc = 0; break; } case 3 : { i++; i = 0; pc = 2; while (i <= 100) { break; } i++; } } } 10

  11. Program obfuscation: control-flow graph flattening i = 0; int pc = 1; while (i <= 100) { while (pc != 0) { i++; } switch (pc) { case 1 : { pc=1; i = 0; pc = 2; break; } 
 pc !=0 case 2 : { if (i <= 100) switch pc pc = 3; 1 3 2 else pc = 0; break; } i++; i=0; i<=100 case 3 : { i++; pc=2; pc=3; pc=0; pc=2; pc = 2; break; } break; break; break; } } 11

  12. Obfuscation: issues • Fairly widespread use, but cookbook-like use No guarantee that program obfuscation is a semantics-preserving code transformation. → Formally verify some program obfuscations • How to evaluate and compare di ff erent program obfuscations ? Standard measures: cost, potency, resilience and stealth. → Use the proof to evaluate and compare program obfuscations 
 The proof reveals the steps that are required to reverse the obfuscation. 12

  13. Formal verification of 
 control-flow-graph flattening 13

  14. Clight semantics Small-step style with continuations, supporting the reasoning on non- terminating programs. Expressions: 17 rules (big-step) Statements: 25 rules (small-step) + many rules for unary and binary operators, memory loads and stores k ::= Kstop | Kseq2 k (* after s1 in s1;s2 *) 
 | Kloop1 s1 s2 k | Kloop2 s1 s2 k (* after si in (loop s1 s2) *) 
 | Kswitch k (* catches break statements *) 
 | Kcall oi f e le k σ ::= C f args k m 
 | R res k m 
 R S C | S f s k e le m (step σ 1 σ 1’) and also (plus σ 2 σ 2’) 14

  15. Correctness of control-flow flattening ≈ ≈ σ 1 σ 2 σ 1 σ 2 + ≈ ≈ σ 1’ σ 2’ σ 1' with m( σ 1’) < m( σ 1) step (S f s1;s2 k e le m) (S f s1 (Kseq s2 k) e le m) step (S f Skip (Kseq s k) e le m) (S f s k e le m) Theorem simulation: ∀ ( σ 1 σ 1':state), step σ 1 σ 1’ -> ∀ ( σ 2:state), σ 1 ≈ σ 2 -> ( ∃ σ 2', plus σ 2 σ 2' /\ σ 1' ≈ σ 2') ∨ (m( σ 1’) < m( σ 1) ∧ σ 1' ≈ σ 2). 15

  16. Matching relation between semantic states int pc = 1; while (pc != 0) { switch (pc) { case 1 : { i = 0; i = 0; pc = 2; break; } 
 case 2 : { i <= 100 if (i <= 100) pc = 3; else pc = 0; break; } i++; case 3 : { i++; Starting from the AST of the flattened pc = 2; break; program, we need to explain how to } rebuild the CFG from the generated switch } } cases. 16

  17. Matching relations 17

  18. Implementation and experiments 1200 lines of spec + 4250 lines of proofs + reused CompCert libraries The comparison with Obfuscator-LLVM revealed a slowdown in the execution of our obfuscated programs, due to a number of skip statements that are generated by the first pass of CompCert. Trick to facilitate the proof: use skip statements to materialize evaluation steps of non-deterministic expressions. Solution: add a pass that eliminates skip statements in skip;s sequences 18

  19. Experimental results 19

  20. Conclusion Competitive program obfuscator operating over C programs, integrated in the CompCert compiler Semantics-preserving code transformation Future work Combine CFG flattening with other simple obfuscations The proof measures the di ffi culty of reverse engineering the obfuscated code. - Study how to count the size of lambda-terms - Semantics of proofs as independent objects (focused proof systems) 20

  21. Questions ? 21

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