Eusecwest March 2, 2007.  Memory corruption vulnerability exposure can be mitigated through memory hardening practices  OS vendors have a unique opportunity.

Slides:



Advertisements
Similar presentations
Richard Johnson
Advertisements

Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
The Linux Kernel: Memory Management
Lecture 16 Buffer Overflow modified from slides of Lawrie Brown.
USING EMET TO DEFEND AGAINST TARGETED ATTACKS PRESENTED BY ROBERT HENSING – SENIOR CONSULTANT – MICROSOFT CORPORATION MICHAEL MATTES – SENIOR CONSULTANT.
DIEHARDER: SECURING THE HEAP. Previously in DieHard…  Increase Reliability by random positioning of data  Replicated Execution detects invalid memory.
Review: Software Security David Brumley Carnegie Mellon University.
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
Intro to Exploitation Stack Overflows James McFadyen UTD Computer Security Group 10/20/2011.
Stack buffer overflow
Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns Jonathan Pincus Microsoft Research Brandon Baker Microsoft Carl Hartung CSCI 7143:
Windows XP SP2 Stack Protection Jimmy Hermansson Johan Tibell.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Maziéres, Dan Boneh
1 RISE: Randomization Techniques for Software Security Dawn Song CMU Joint work with Monica Chew (UC Berkeley)
Address Obfuscation: An Efficient Approach to Combat a Broad Range of Memory Error Exploits Sandeep Bhatkar, Daniel C. DuVarney, and R. Sekar Stony Brook.
Address Space Layout Permutation
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Lecture 0 Appendix on Implementation Threats Material from Warren Page & Chpt 11, Information Security by Mark Stamp.
Computer Security and Penetration Testing
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
Software attacks Lorenzo Dematté Software attacks Advanced buffer overflow: heap smashing.
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
Mitigation of Buffer Overflow Attacks
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
Exploitation possibilities of memory related vulnerabilities
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
CNIT 127: Exploit Development Ch 4: Introduction to Heap Overflows
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.
Stack-based buffer overflows Yves Younan DistriNet, Department of Computer Science Katholieke Universiteit Leuven Belgium
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2.
Information Leaks Without Memory Disclosures: Remote Side Channel Attacks on Diversified Code Jeff Seibert, Hamed Okhravi, and Eric Söderström Presented.
Buffer overflow and stack smashing attacks Principles of application software security.
SEH overwrite and its exploitability Shuichiro Suzuki Fourteenforty Research Institute Inc. Research Engineer.
Buffer Overflows Taught by Scott Coté.-. _ _.-. / \.-. ((___)).-. / \ /.ooM \ / \.-. [ x x ].-. / \ /.ooM \ -/ \ /-----\-----/---\--\ /--/---\-----/-----\ / \-
CNIT 127: Exploit Development Ch 14: Protection Mechanisms.
Group 9. Exploiting Software The exploitation of software is one of the main ways that a users computer can be broken into. It involves exploiting the.
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.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 1.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Beyond Stack Smashing: Recent Advances In Exploiting Buffer Overruns Jonathan Pincus and Brandon Baker Microsoft Researchers IEEE Security and.
Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.
1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.
Lec. Waleed Bin Shahid.  You might have noticed a lot of issues related to software implementation.  The ultimate requirement of developer(s) is to.
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.
Return Oriented Programming
The Hardware/Software Interface CSE351 Winter 2013
Jump Over ASLR: Attacking Branch Predictors to Bypass ASLR
Exploiting & Defense Day 2 Recap
CSC 495/583 Topics of Software Security Return-oriented programming
A System for Protecting the Integrity of Virtual Function Tables
Software Security.
Trust Boundary Vulnerability Exploitation State of the Exploit
Advanced Buffer Overflow: Pointer subterfuge
Software Security Lesson Introduction
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
CSE451 Virtual Memory Paging Autumn 2002
Processes in Unix, Linux, and Windows
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

Eusecwest March 2, 2007

 Memory corruption vulnerability exposure can be mitigated through memory hardening practices  OS vendors have a unique opportunity to fight memory corruption vulnerabilities through hardening the memory manager  Microsoft is raising the technology bar to combat external threats

 Red Hat Enterprise Linux  Images ▪ Section reordering ▪ DLL randomization ▪ EXE randomization*  Stack ▪ Protected control flow data* ▪ Local variable protection* ▪ Segment randomization ▪ Non-executable  Heap ▪ Segment randomization ▪ Non-executable

 OpenBSD  Images ▪ DLL randomization ▪ Section reordering  Stack ▪ Protected control flow data* ▪ Local variable protection ▪ Segment randomization ▪ Non-executable  Heap ▪ Non-executable ▪ Segment randomization  Apple OS X  Images ▪ No protection  Stack ▪ Non-executable  Heap ▪ No protection

 Windows Vista  Images ▪ EXE randomization ▪ DLL randomization  Stack ▪ Protected exception handlers ▪ Protected control flow data ▪ Local variable protection ▪ Segment randomization ▪ Non-executable  Heap ▪ Protected heap management data ▪ Segment randomization ▪ Non-executable

 A quick look at what you’ve already been exposed to:  Stack Cookies (/GS) ‏  Heap Mitigations (XP SP2) ‏  Structured Exception Handling (SafeSEH)  Unhandled Exception Filter (MS06-051) ‏  Hardware DEP/NX

 New features you’ve probably heard about  Privilege Separation  IE Protected Mode  Kernel Patch Protection  Code Integrity  New features we are covering today  Address Space Layout Randomization  Windows Vista Dynamic Memory Allocator

 New in Windows Vista  Address Space Layout Randomization ▪ The History of ASLR ▪ Architectural Considerations ▪ Vista ASLR Technical Details ▪ Testing Methodology  Dynamic Memory Allocator ▪ A Short Lesson in Heap Exploitation ▪ Improvements in Vista Heap Management ▪ Vista Dynamic Memory Allocator Internals ▪ Testing Methodology

 Windows Vista ASLR is a technology that makes exploitation of a vulnerability a statistical problem  Address Space Layout Randomization allows for the relocation of memory mappings, making the a process address space layout unpredictable

 ASLR Theory  Exploitation relies on prior knowledge of the memory layout of the targeted process  Published Research  PaX Documentation ▪ PaX Team ( ‏  “On the Effectiveness of Address Space Layout Randomization” ▪ Shacham, et al Stanford University

 Windows Vista Process Model  Most applications are threaded  Windows Vista Memory Management  File mappings must align at 64k boundaries  Shared mappings must be used to keep memory overhead low and preserve physical pages  Fragmentation of the address space must be avoided to allow for large allocations  Supports hardware NX

 Image Mapping Randomization  Random base address chosen for each image loaded once per boot  8 bits of entropy  Fix-ups applied on page-in  Images are mapped at the same location across processes  99.6% Effective

 Heap Randomization  Random offset chosen for segment allocation using 64k alignment (5-bit entropy) ‏  Stack Randomization  Random offset chosen for segment allocation using 64k or 256k alignment.  Random offset within first half of the first page

 Three pieces to the strategy  Address Space Randomization  Non-Executable Pages  Service Restart Policy

 Assumptions  ASLR will only protect against remote exploitation  ASLR requires NX to remain effective  ASLR requires a limit on the number of exploitation attempts to remain effective

 Prior to Windows Vista, NX could be disabled in a process if PERMANENT flag was not set  Loading a DLL that is not NX compatible ▪ No relocation information ▪ Loaded off removable media ▪ Open handle to a data mapping of the file  Call NtSetInformationProcess with the MEM_EXECUTE_OPTION_ENABLE flag

 In Windows Vista, NX cannot be disabled once turned on for a process  Most processes enable NX by default

 Reducing the brute force space  Code symmetry ▪ Each location shifts stack pointer 20 bytes  Advanced return address location ▪ Emulation - EEREAP kernel32+0xa1234:kernel32+0xb1234:user32+0x01234:advapi32+0x51234: retn 16pop ebxjz 0x lea esp, [esp+20] pop ebpsub esp, 16pop eax retn 8 xor eax, eaxcall eax ret

 Partial overwrites  Given known addresses at known offsets, partial overwrites yield predictable results without full knowledge of the address space layout  With randomization in play, bounded overflows can be used reliably for a single partial overwrite

 Partial overwrites  A single partial overwrite can be used to execute a payload or gain additional partial overwrites D:\>partial banner1: a banner2: f hello world! D:\>partial own banner1: a banner2: f owned!

 Partial overwrites  A single partial overwrite can be used to execute a payload or gain additional partial overwrites int main(int argc, char **argv)‏ { struct Object obj1; char buf[32]; struct Object obj2; … printf("banner1: %08x banner2: %08x\n", banner1, banner2); if(argv[1] != 0)‏ strncpy(buf, overflow, sizeof(overflow)); obj1.func(); return 0; } partial!main+0x5a: ea 6a30 push 30h ec 68b push offset partial!overflow f1 8d4dc4 lea ecx,[ebp-3Ch] f4 51 push ecx f5 e call partial!strncpy ( )‏ fa 83c40c add esp,0Ch

 Partial overwrites  A single partial overwrite can be used to execute a payload or gain additional partial overwrites 0:000> bp f5 0:000> g banner1: a banner2: f Breakpoint 0 hit partial!main+0x65: f5 e call partial!strncpy ( )‏ 0:000> dt obj1 Local 0x12ff38 Type Object +0x000 next : (null)‏ +0x004 val : x008 func : 0x a partial!ILT+5(_banner1)+0 0:000> p partial!main+0x6a: fa 83c40c add esp,0Ch 0:000> dt obj1 Local 0x12ff38 Type Object +0x000 next : 0x Object +0x004 val : x008 func : 0x f partial!ILT+10(_banner2)+0 0:000> g owned!

 Information Leaking  Uninitialized memory  Use multiple attempts to gain address layout information that will get you code execution  Additional image map locations can usually be inferred from one DLL address  Heap spraying reduces the need for accuracy  Non-randomized data as arguments to functions  SharedUserData / ReadOnlySharedMemoryBase  Non-relocatable resource dlls  3 rd party binaries

 Software Development Process  Create NX and ASLR compatible binaries  Keep service restart policies in mind  Ensure information leak bugs are addressed  Technology  Use hardware that supports NX

 The majority of currently exploited vulnerabilities in Microsoft products are overflows into heap memory  Heap exploitation relies on corrupting heap management data or attacking application data within the heap

Class objects contain a list of function pointers for each virtual function in the class called a vtable class MyClass { public: MyClass(); virtual ~MyClass(); virtual MemberFunction(); int MemberVariable; }; Overwriting virtual function pointers is the simplest method of heap exploitation VTable Overwrites

HEAP_ENTRY Overflow  Scenario: Heap-based buffer overflow allows for writing into adjacent free heap block  Attack: Overwrite FLINK and BLINK values and wait for HeapAlloc() ‏  Allows one or two 4-byte writes to controlled locations mov dword ptr [ecx],eax mov dword ptr [eax+4],ecx EAX = Flink, EBX = Blink FREE HEAP BLOCK _HEAP_ENTRY +0x000 Size +0x002 PreviousSize +0x004 SmallTagIndex +0x005 Flags +0x006 UnusedBytes +0x007 SegmentIndex _LIST_ENTRY +0x000 Flink +0x004 Blink

HEAP_ENTRY Overflow Mitigations in XP SP2  List integrity checked during heap allocation  8-bit Cookie  Verified on allocation after removal from free list LIST_ENTRY->Flink->Blink == LIST_ENTRY->Blink->Flink == LIST_ENTRY

HEAP_ENTRY Overflow Mitigations in XP SP2  Defeated by attacking the lookaside list  First heap overwrite takes control of Flink value in a free chunk with a lookaside list entry  Allocation of the corrupted chunk puts the corrupt Flink value into the lookaside list  Next HeapAlloc() of the same sized chunk will return the corrupted pointer

 Heap segment randomization  HEAP_ENTRY integrity checks  Block entry randomization  Linked-list validation and substitution  Function pointer hardening  Terminate on Error

 HEAP_ENTRY  Checksum for Size and Flags  Size, Flags, Checksum, and PreviousSize are XOR’d against random value  Adds extra resilience against overflows into Flink and Blink values

 Linked-lists  Forward and backward pointer validation on unlink from any list  Lookaside lists  Replaced by Low-Fragmentation Heap

 Function pointer hardening  CommitRoutine and InterceptRoutine function pointers encoded  CRT atexit() destructors encoded  Terminate on Error  Opt-in API that cannot be disabled  Ensures program cleanup does not utilize tainted heap structures

 The Low-Fragmentation Heap is enabled by default in Windows Vista  The LFH replaces lookaside lists and is similar in nature  128 buckets of static sized buffers  Utilized for reoccuring allocations of the same size

 HEAP_ENTRY  Doubly-linked list pointers are only validated when unlinking a node InsertHeadList(ListHead, Entry)‏ Flink = ListHead->Flink; Entry->Flink = Flink; Entry->Blink = ListHead; Flink->Blink = Entry; ListHead->Flink = Entry; InsertTailList(ListHead, Entry)‏ Blink = ListHead->Blink; Entry->Flink = ListHead; Entry->Blink = Blink; Blink->Flink = Entry; ListHead->Blink = Entry;  Attack If list head pointers can be corrupted prior to an insert, the destination of a 4-byte write can be controlled The address of the free chunk being inserted into the list will be written to the corrupted linked list pointer  Assessment Writing the address of the chunk may be only be helpful in limited circumstances It is difficult to find a list head to overwrite

 HEAP_UCR_DESCRIPTOR  Attack Repeated large allocations will result in the allocation of a new segment HEAP_UCR_DESCRIPTOR is at a static offset from first allocation in a segment If fake descriptor points at allocated memory, the next heap allocation will write a HEAP_UCR_DESCRIPTOR to a controlled address  Assessment Limited control of the data written should effectively reduce this to a partial DWORD overwrite Increased complexity with multi-stage attack requires a high degree of control such as active scripting Unused Allocated Heap UCR Descriptor

 HEAP_UCR_DESCRIPTOR  Attack Repeated large allocations will result in the allocation of a new segment HEAP_UCR_DESCRIPTOR is at a static offset from first allocation in a segment If fake descriptor points at allocated memory, the next heap allocation will write a HEAP_UCR_DESCRIPTOR to a controlled address  Assessment Limited control of the data written should effectively reduce this to a partial DWORD overwrite Increased complexity with multi-stage attack requires a high degree of control such as active scripting Unused Allocated Heap UCR Descriptor Unused Allocated Heap Overflow UCR Descriptor Function Ptr 0x000a1234

 HEAP_UCR_DESCRIPTOR  Attack Repeated large allocations will result in the allocation of a new segment HEAP_UCR_DESCRIPTOR is at a static offset from first allocation in a segment If fake descriptor points at allocated memory, the next heap allocation will write a HEAP_UCR_DESCRIPTOR to a controlled address  Assessment Limited control of the data written should effectively reduce this to a partial DWORD overwrite Increased complexity with multi-stage attack requires a high degree of control such as active scripting Unused Allocated Heap Overflow UCR Descriptor _HEAP_UCR_DESCRIPTOR +0x000 ListEntry +0x008 SegmentEntry +0x010 Address +0x014 Size Address points to the next reserved region and defines where a HEAP_UCR_DESCRIPTOR will be written on the next segment allocation Function Ptr 0x000a1234 Ptr XXXX

 _LFH_BLOCK_ZONE  Attack New SubSegments are created at the location specified by the FreePointer in the LFH_BLOCK_ZONE structure Control of the FreePointer allows writing a HEAP_SUBSEGMENT to an arbitrary location Allocation size and number of allocations affect fields in the HEAP_SUBSEGMENT structure  Assessment Limited control of the data written should effectively reduce this to a partial DWORD overwrite Increased complexity attack requires a high degree of control such as active scripting _LFH_BLOCK_ZONE +0x000 ListEntry +0x008 FreePointer +0x00c Limit _HEAP_SUBSEGMENT +0x000 LocalInfo +0x004 UserBlocks +0x008 AggregateExchg +0x010 BlockSize +0x012 Flags +0x014 BlockCount +0x016 SizeIndex +0x017 AffinityIndex +0x010 Alignment +0x018 SFreeListEntry +0x01c Lock

Default exploit mitigations on popular client operating systems

 OS vendors have a unique opportunity to fight memory corruption vulnerabilities through hardening the memory manager  Microsoft is committed to closing the gap as much as possible and Windows Vista will have the strongest pro- active vulnerability defense of any Windows release  These protections will continue to evolve to prevent wide- spread exploitation of software vulnerabilities  Exploitation mitigations do not solve the problem of software vulnerabilities, but do provide a stop-gap during times of exposure

 Thank you for attending  Please contact us at for feedback on Microsoft’s mitigation