1 Introduction to Information Security 0368-3065, Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.

Slides:



Advertisements
Similar presentations
Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
Advertisements

David Brumley Carnegie Mellon University Credit: Some slides from Ed Schwartz.
Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il.
Computer Security: Principles and Practice EECS710: Information Security Professor Hossein Saiedian Fall 2014 Chapter 10: Buffer Overflow.
Computer Security: Principles and Practice First Edition by William Stallings and Lawrie Brown Lecture slides by Lawrie Brown Chapter 11 – Buffer Overflow.
Lecture 16 Buffer Overflow modified from slides of Lawrie Brown.
Nozzle: A Defense Against Heap Spraying Attacks Ben Livshits Paruj Ratanaworabhan Ben Zorn.
Basic Control Hijacking Attacks
CMSC 414 Computer and Network Security Lecture 22 Jonathan Katz.
Part III Counter measures The best defense is proper bounds checking but there are many C/C++ programmers and some are bound to forget  Are there any.
Foundations of Network and Computer Security J J ohn Black Lecture #30 Nov 26 th 2007 CSCI 6268/TLEN 5831, Fall 2007.
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
1 Information Security – Theory vs. Reality , Winter 2011 Lecture 8: Control hijacking attacks Eran Tromer Slides credit: Dan Boneh, Stanford.
Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns Jonathan Pincus Microsoft Research Brandon Baker Microsoft Carl Hartung CSCI 7143:
Preventing Buffer Overflow Attacks. Some unsafe C lib functions strcpy (char *dest, const char *src) strcat (char *dest, const char *src) gets (char *s)
Windows XP SP2 Stack Protection Jimmy Hermansson Johan Tibell.
Control Hijacking Attacks Note: project 1 is out Section this Friday 4:15pm.
Defenses from Malware. Preventing exploits Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
Eran Tromer Slides credit: Avishai Wool, Tel Aviv University
Lecture 16 Buffer Overflow
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2012.
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2013.
Address Space Layout Permutation
Control Hijacking Attacks
Mitigation of Buffer Overflow Attacks
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 10 “Buffer Overflow”.
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Avishai Wool, lecture Introduction to Information Security Lecture 1.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 22: Unconventional.
Buffer Overflow. Introduction On many C implementations, it is possible to corrupt the execution stack by writing past the end of an array. Known as smash.
Buffer Overflow Group 7Group 8 Nathaniel CrowellDerek Edwards Punna ChalasaniAxel Abellard Steven Studniarz.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
Control Hijacking Attacks Note: project 1 is out Section this Friday 2pm (Skilling 090)
Introduction to Information Security ROP – Recitation 5.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2.
CNIT 127: Exploit Development Ch 14: Protection Mechanisms.
Foundations of Network and Computer Security J J ohn Black CSCI 6268/TLEN 5550, Spring 2013.
Security Attacks Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
Control Hijacking Attacks Note: project 1 is out Section this Friday 4:15pm (Gates B03)
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 1.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade Crispin Cowan SANS 2000.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
Control Hijacking: Defenses
Introduction to Information Security
Mitigation against Buffer Overflow Attacks
Buffer Overflow Buffer overflows are possible because C doesn’t check array boundaries Buffer overflows are dangerous because buffers for user input are.
Basic Control Hijacking Attacks
The Hardware/Software Interface CSE351 Winter 2013
Basic Memory Corruption Attacks
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2016.
Introduction to Information Security
CSC 495/583 Topics of Software Security Stack Overflows (2)
Basic Memory Corruption Attacks
CSC 495/583 Topics of Software Security Return-oriented programming
CMSC 414 Computer and Network Security Lecture 21
Basic Control Hijacking Attacks
Software Security.
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Advanced Buffer Overflow: Pointer subterfuge
Preventing Buffer Overflow Attacks
Foundations of Network and Computer Security
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2011.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2009.
CNT4704: Analysis of Computer Communication Network Special Topic: Buffer Overflow II: Defense Techniques Cliff Zou Fall 2011.
Return-to-libc Attacks
Presentation transcript:

1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool

2 Preventing control-hijacking attacks 1. Fix bugs: –Static analysis Tools: Coverity, Purify, PREfast/PREfix... –Runtime analysis Tools: Valgrind –Rewrite software in a type-safe language (Java, ML) Difficult for existing (legacy) code … 2.Concede overflow, but prevent code execution 3. Add runtime code to detect overflows exploits –Halt process when overflow exploit detected –StackGuard, LibSafe, …

3 Control Hijacking Platform defenses: Hardware + Operating System

4 Marking memory as non-execute (W^X)

5 Examples: DEP control in Windows 7 DEP terminating a program Computer > right-click Properties > Advanced system settings > Performance (Settings) > Data Execution Prevention

6 “return to libc” attack Control hijacking without executing code args ret-addr sfp local buf stack exec() printf() “/bin/sh” libc.so

7 Defense against “return to libc”: randomization ASLR : ( Address Space Layout Randomization) –Map shared libraries to random location in process memory  Attacker cannot jump directly to exec function –Deployment on 32-bit OS: Windows Vista:8 bits of randomness for DLLs –aligned to 64K page in a 16MB region  256 choices Linux (via PaX):16 bits of randomness for libraries –More effective on 64-bit architectures Other randomization methods: –System-call randomization: randomize system-call IDs –Instruction Set Randomization (ISR) Generally: Software Diversity

8 ASLR Example Booting twice loads libraries into different locations:

9 Control Hijacking Runtime defense

Run time checking: StackGuard Many run-time checking techniques … –we only discuss methods relevant to overflow protection Solution 1: StackGuard –Run time tests for stack integrity. –Embed “canaries” in stack frames and verify their integrity prior to function return. top of stack Frame 1 Frame 2 localcanary sfp ret args localcanary sfp ret args 10

Canary Types Random canary: –Random string chosen at program startup. –Insert canary string into every stack frame. –Verify canary before returning from function. Exit program if canary changed. Turns potential exploit into DoS. –To corrupt, attacker must learn current random string. Terminator canary: Canary = {0, newline, linefeed, EOF} –String functions will not copy beyond terminator. –Attacker cannot use string functions to corrupt stack. 11

StackGuard (Cont.) StackGuard implemented as a GCC patch. –Program must be recompiled. Small performance effects: (8% for Apache) Note: Canaries don’t provide full proof protection. –Some stack smashing attacks leave canaries unchanged 12

StackGuard enhancements: ProPolice ProPolice (IBM) - gcc (-fstack-protector) –Rearrange stack layout to prevent overflow into pointers. args ret addr SFP CANARY local string buffers local non-buffer variables Stack Growth pointers, but no arrays String Growth copy of pointer args Protects pointer args and local pointers from a buffer overflow 13

MS Visual Studio /GS [since 2003] Compiler /GS option: –Combination of ProPolice and Random canary. –If cookie mismatch, default behavior is to call _exit(3) Function prolog: sub esp, 8 // allocate 8 bytes for cookie mov eax, DWORD PTR ___security_cookie xor eax, esp // xor cookie with current esp mov DWORD PTR [esp+8], eax // save in stack Function epilog: mov ecx, DWORD PTR [esp+8] xor ecx, esp call add esp, 8 Enhanced /GS in Visual Studio 2010: – /GS protection added to all functions, unless can be proven unnecessary 14

/GS stack frame args ret addr SFP CANARY local string buffers local non-buffer variables Stack Growth pointers, but no arrays String Growth copy of pointer args exception handlers Canary protects ret- addr and exception handler frame 15

16 Control Hijacking Heap spray attacks (object oriented languages: C++, Javascript)

Heap-based control hijacking Compiler generated function pointers (e.g. C++ code) Suppose vtable is on the heap next to a string object: ptr data Object T FP1 FP2 FP3 vtable method #1 method #2 method #3 ptr buf[256] data object T vtable 17

Heap-based control hijacking Compiler generated function pointers (e.g. C++ code) After overflow of buf we have: ptr data Object T FP1 FP2 FP3 vtable method #1 method #2 method #3 ptr buf[256] data object T vtable shell code 18

A reliable exploit? shellcode = unescape("%u4343%u4343%..."); overflow-string = unescape(“%u2332%u4276%...”); cause-overflow( overflow-string ); // overflow buf[ ] Problem:attacker does not know where browser places shellcode on the heap ptr buf[256] data shellcode vtable ??? 19

Heap Spraying [SkyLined 2004] Idea:1. use Javascript to spray heap with shellcode (and NOP slides) 2. then point vtable ptr anywhere in spray area heap vtable NOP slide shellcode heap spray area 20

JavaScript heap spraying var nop = unescape(“%u9090%u9090”) while (nop.length < 0x100000) nop += nop var shellcode = unescape("%u4343%u4343%..."); var x = new Array () for (i=0; i<1000; i++) { x[i] = nop + shellcode; } Pointing func-ptr almost anywhere in heap will cause shellcode to execute. 21

Vulnerable buffer placement Placing vulnerable buf[256] next to object O: –By sequence of JavaScript allocations and frees make heap look as follows: –Allocate vulnerable buffer in Javascript and cause overflow –Successfully used against a Safari PCRE overflow [DHM’08] object O free blocks heap 22

Many heap spray exploits Improvements: Heap Feng Shui [S’07] –Reliable heap exploits on IE without spraying –Gives attacker full control of IE heap from Javascript [RLZ’08] 23

(partial) Defenses Protect heap function pointers (e.g. PointGuard) Better browser architecture: –Store JavaScript strings in a separate heap from browser heap OpenBSD heap overflow protection: Nozzle [RLZ’08] : detect sprays by prevalence of code on heap non-writable pages prevents cross-page overflows 24