1
Guarding Vulnerable Code: Module 2: Mitigation
Mathias Payer, Purdue University http://hexhive.github.io
Guarding Vulnerable Code: Module 2: Mitigation Mathias Payer, - - PowerPoint PPT Presentation
Guarding Vulnerable Code: Module 2: Mitigation Mathias Payer, Purdue University http://hexhive.github.io 1 Defense: Testing vs. Mitigations Software Testing Mitigations Discover bugs Stop exploitation Development tool Always
1
Mathias Payer, Purdue University http://hexhive.github.io
2
3
* The Matter of Heartbleed. Zakir Durumeric, James Kasten, J. Alex Halderman, Michael Bailey, Frank Li, Nicholas Weaver, Bernhard Amann, Jethro Beekman, Mathias Payer, Vern Paxson. In ACM IMC'14 (best paper)
vulnerable after 48 hours
replaced certificates
vulnerable keys
Heartbleed vulnerable hosts
4
https://en.wikipedia.org/wiki/Pwn2Own
5
6
C/C++ void log(int a) { printf("Log: "); printf("%d", a); } void (*fun)(int) = &log; void init() { fun(15); } ASM log: ... fun: .quad log init: ... movl $15, %edi movq fun(%rip), %rax call *%rax
7
8
Code Heap Stack
9
Code Heap Stack
10
Attacker may read/write arbitrary data
– Code is read-only, vtables are read-only – Code pointers remain writable!
Code Heap Stack vtables RX R RW RW
11
12
– Generalization of non-control-data attacks
– Execution trace may not match non-exploit case
Nicholas Carlini, Antonio Barresi, Mathias Payer, David Wagner, and Thomas R. Gross “Control-Flow Bending”, Usenix SEC'15
13
system() vuln()
14
system() vuln() memcpy()
15
– Loop through two calls to the same function – Choose any caller as return location
– Attacker restricted to arbitrary targets on the stack – Each target can only be called once, in sequence
* Control-Flow Bending: On the Effectiveness of Control-Flow Integrity. Nicholas Carlini, Antonio Barresi, Mathias Payer, David Wagner, and Thomas R. Gross. In Usenix SEC'15
void func() { … bar(); … void bar() { … } bar(); … }
16
– Stateless defenses insufficient for stack attacks
– Bend execution to dispatcher/functional gadgets – In case study CFI not effective for 5/6 vulnerabilities
17
– Use valid vtables – Functions become gadgets – Chaining functions gives Turing-completeness
Felix Schuster, Thomas Tendyck, Christopher Liebchen, Lucas Davi, Ahmed-Reza Sadeghi, and Thorsten Holz. Counterfeit Object-Oriented Programming, Oakland'15
18
Memory/type safety Integrity Confidentiality Flow Integrity Bad things
C *C &C *&C Corruption
Code corruption Control-flow hijack
C &C *&C
SoftBound [PLDI09, POPL12, ISCA12]; CCured [POPL02]; DShield/nC [2x AsiaCCS17] Code Integrity [AMD06]; SafeO [FSE03]; WIT [SP08]; CPI [OSDI14]; OTI [NDSS18] ASLR [CCS03, 04, 10, 12]; DSR [DIMVA08]; PG [SEC03]; Diversity SoK [SP14]; CFI [CCS05]; MCFI [PLDI14]; FCFI [SEC14]; vTrust [NDSS17]; SoK [CSUR17]
19
– Overwriting arguments to exec()
– Overwriting is_admin flag
– Modify function pointer to (valid) alternate target
20
21
static control-flow graph
– Requires static analysis – Dynamic enforcement mechanism
* Control-Flow Integrity. Martin Abadi, Mihai Budiu, Ulfar Erlingsson, Jay Ligatti. CCS ‘05 * Control-Flow Integrity: Protection, Security, and Performance. Nathan Burow, Scott A. Carr, Joseph Nash, Per Larsen, Michael Franz, Stefan Brunthaler, Mathias Payer. ACM CSUR ‘17
22
23
Goal: minimize target sets, increase precision
24
– Function pointers can only be assigned – Data pointers to function pointers are forbidden
* Fine-Grained Control-Flow Integrity for Kernel Software. Xinyang Ge, Nirupama Talele, Mathias Payer, and Trent Jaeger. In EuroS&P'16
25
– Support legacy, binary code and modularity (libraries) – Leverage precise, dynamic analysis – Low performance overhead
* Fine-Grained Control-Flow Integrity through Binary Hardening Mathias Payer, Antonio Barresi, and Thomas R. Gross. In DIMVA'15
26
Object-Oriented Programming (COOP)
– Enforce type check of prototype for virtual calls – Sanitize VTable pointers before use
* VTrust: Regaining Trust on Your Virtual Calls. Chao Zhang, Scott A. Carr, Tongxin Li, Yu Ding, Chengyu Song, Mathias Payer, and Dawn Song. In NDSS'16
27
Greeter *o = new Greeter();
ShrinkWrap [ACSAC15]; VTrust [NDSS17]; LLVM-CFI [head] MCFI [CCS13, PLDI14]; RockJIT [CCS14]; PICFI [CCS15]; C-CFI [CCS15]; PathArmor [CCS15]; KCFI [EuroSP16] CFI? [CCS05]; FCFI [SEC14] kBouncer [SEC13]; CCFIR [SP13]; binCFI [SEC13]; ROPecker [NDSS14]; DynCFI [DIMVA15]
28
Greeter *o = new Greeter();
0xf000b400 int bar1(int b, int c, int d); int bar2(char *str); void bar3(char *str); void B::foo(char *str); class Greeter :: Base {... }; void Base::bar5(char *str); void Greeter::sayHi(char *str); class Related :: Greeter {... }; void Related::sayHi(char *str);
29
2007 2017
30
Firefox [1-10] 13,751 (99.33%) 4,632 (99.90%) >10 78 (0.57%) 47 (0.10%) Max 78 107
31
– Inherently stateless defense – Effectiveness depends on precision of analysis and
program functionality
– Low performance overhead
– Large target sets, statelessness – Backward edge often neglected
32
33
– Overwrite where with what?
– Guide execution to dispatch
34
Memory/type safety Integrity Confidentiality Flow Integrity Bad things
C *C &C *&C Corruption
Code corruption Control-flow hijack
C &C *&C
SoftBound [PLDI09, POPL12, ISCA12]; CCured [POPL02]; DShield/nC [2x AsiaCCS17] Code Integrity [AMD06]; SafeO [FSE03]; WIT [SP08]; CPI [OSDI14]; OTI [NDSS18] ASLR [CCS03, 04, 10, 12]; DSR [DIMVA08]; PG [SEC03]; Diversity SoK [SP14]; CFI [CCS05]; MCFI [PLDI14]; FCFI [SEC14]; vTrust [NDSS17]; SoK [CSUR17]
35
– Relocate to safe area – Use protected version for dispatch
* CFIXX: Object Type Integrity for C++ Virtual Dispatch. Nathan Burow, Derrick McKee, Scott A. Carr, and Mathias Payer. In ISOC NDSS '18 Code Heap Stack Safe memory area vtables
36
– Only constructor allowed to write vtable pointer – Deallocation invalidates vtable pointer – Dispatch uses vtable pointer
– VTable injection even with correct method signature – Swap vtable even in the same hierarchy – Fake object creation (COOP)
37
38
39
40
Memory/type safety Integrity Confidentiality Flow Integrity Bad things
C *C D *D &C *&C &D *&D Memory/type corruption
Code corruption Data-only attack Control-flow hijack
C &C &D *&C
41
42
43
– Effectiveness depends on analysis and complexity – Deployed in Microsoft Edge, Google Chrome – Limitation: large equivalence classes
– Protect object instead of dispatch – Single valid target per object
Source: https://github.com/HexHive/CFIXX
44