How to Impress Girls with Browser Memory Protection Bypasses

Similar documents
Bypassing Browser Memory Protections in Windows Vista

Bypassing Memory Protections: The Future of Exploitation

Bypassing Windows Hardware-enforced Data Execution Prevention

風 水. Heap Feng Shui in JavaScript. Alexander Sotirov.

Exploiting nginx chunked overflow bug, the undisclosed attack vector

Software Vulnerabilities

Custom Penetration Testing

Hotpatching and the Rise of Third-Party Patches

Software Vulnerability Exploitation Trends. Exploring the impact of software mitigations on patterns of vulnerability exploitation

C# and Other Languages

CVE Adobe Flash Player Integer Overflow Vulnerability Analysis

EMET 4.0 PKI MITIGATION. Neil Sikka DefCon 21

Turn the Page: Why now is the time to migrate off Windows Server 2003

AppSecUSA New York City 2013

Defense in Depth: Protecting Against Zero-Day Attacks

OWASP Spain Barcelona 2014

MSc Computer Science Dissertation

Sandy. The Malicious Exploit Analysis. Static Analysis and Dynamic exploit analysis. Garage4Hackers

Ivan Medvedev Principal Security Development Lead Microsoft Corporation

I Control Your Code Attack Vectors Through the Eyes of Software-based Fault Isolation. Mathias Payer, ETH Zurich

SECURITY B-SIDES: ATLANTA STRATEGIC PENETRATION TESTING. Presented by: Dave Kennedy Eric Smith

Computer Security: Principles and Practice

Return-oriented programming without returns

Creating a More Secure Device with Windows Embedded Compact 7. Douglas Boling Boling Consulting Inc.

Format string exploitation on windows Using Immunity Debugger / Python. By Abysssec Inc

Eugene Tsyrklevich. Ozone HIPS: Unbreakable Windows

ASL IT SECURITY XTREME XPLOIT DEVELOPMENT

Fast Byte-Granularity Software Fault Isolation

Buffer Overflows. Code Security: Buffer Overflows. Buffer Overflows are everywhere. 13 Buffer Overflow 12 Nov 2015

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

esrever gnireenigne tfosorcim seiranib

Adobe Flash Player and Adobe AIR security

Windows Phone 7 Internals and Exploitability

Application-Specific Attacks: Leveraging the ActionScript Virtual Machine

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

Software security. Buffer overflow attacks SQL injections. Lecture 11 EIT060 Computer Security

Attacking Obfuscated Code with IDA Pro. Chris Eagle

3. Broken Account and Session Management. 4. Cross-Site Scripting (XSS) Flaws. Web browsers execute code sent from websites. Account Management

HTC Windows Phone 7 Arbitrary Read/Write of Kernel Memory 10/11/2011

Windows XP SP3 Registry Handling Buffer Overflow

telnetd exploit FreeBSD Telnetd Remote Exploit Für Compass Security AG Öffentliche Version 1.0 Januar 2012

ERNW Newsletter 51 / September 2015

Heap-based Buffer Overflow Vulnerability in Adobe Flash Player

Risks with web programming technologies. Steve Branigan Lucent Technologies

Zing Vision. Answering your toughest production Java performance questions

Some Anti-Worm Efforts at Microsoft. Acknowledgements

Stack Allocation. Run-Time Data Structures. Static Structures

Exploiting Trustzone on Android

Bug hunting. Vulnerability finding methods in Windows 32 environments compared. FX of Phenoelit

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

An Analysis of Address Space Layout Randomization on Windows Vista

CORE SECURITY. Exploiting Adobe Flash Player in the era of Control Flow Guard. Francisco Falcon Black Hat Europe 2015 November 12-13, 2015

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Introduction to Information Security

Practical taint analysis for protecting buggy binaries

MWR InfoSecurity Advisory. Interwoven Worksite ActiveX Control Remote Code Execution. 10 th March Contents

Background. How much does EMET cost? What is the license fee? EMET is freely available from Microsoft without material cost.

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

Jordan University of Science and Technology

Modern Binary Exploitation Course Syllabus

Attacking Host Intrusion Prevention Systems. Eugene Tsyrklevich

AJAX Storage: A Look at Flash Cookies and Internet Explorer Persistence

Web Conferencing Version 8.3 Troubleshooting Guide

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Linux exploit development part 2 (rev 2) - Real app demo (part 2)

How to Sandbox IIS Automatically without 0 False Positive and Negative

Replication on Virtual Machines

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Hacking your perimeter. Social-Engineering. Not everyone needs to use zero. David Kennedy (ReL1K) Twitter: Dave_ReL1K

Java and Java Virtual Machine Security

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

United States Department of Agriculture

API Monitoring System for Defeating Worms and Exploits in MS-Windows System

Habanero Extreme Scale Software Research Project

Penetration Testing with Kali Linux

Enhanced Mitigation Experience Toolkit 5.1

Jonathan Worthington Scarborough Linux User Group

CS Computer Security Thirteenth topic: System attacks. defenses

An Overview of Java. overview-1

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

SkyRecon Cryptographic Module (SCM)

Assembly Language: Function Calls" Jennifer Rexford!

Java Interview Questions and Answers

Firefox, Opera, Safari for Windows BMP file handling information leak. September Discovered by: Mateusz j00ru Jurczyk, Hispasec Labs

Cloud Computing. Up until now

Introduction. Figure 1 Schema of DarunGrim2

Internals of Windows Memory Management (not only) for Malware Analysis

Off-by-One exploitation tutorial

Advanced IBM AIX Heap Exploitation. Tim Shelton V.P. Research & Development HAWK Network Defense, Inc. tshelton@hawkdefense.com

Security for Mac Computers in the Enterprise

Last update: February 23, 2004

TO HACK AN ASP.NET WEBSITE?

Secure Web Application Coding Team Introductory Meeting December 1, :00 2:00PM Bits & Pieces Room, Sansom West Room 306 Agenda

RightNow CX November 2011 Workstation Specifications

SYMANTEC ADVANCED THREAT RESEARCH. An Analysis of Address Space Layout Randomization on Windows Vista

DAWSON -- Synthetic Diversity for Intrusion Tolerance 1

Securing software by enforcing data-flow integrity

From SQL Injection to MIPS Overflows

Using a Patched Vulnerability to Bypass Windows 8 x64 Driver Signature Enforcement. MJ0011 th_decoder@126.com

Transcription:

BlackHat USA 2008 How to Impress Girls with Browser Memory Protection Bypasses Mark Dowd & Alexander Sotirov markdowd@au1.ibm.com alex@sotirov.net Setting back browser security by 10 years

Part I: Introduction

Thesis Introduction Vista protections are largely ineffective at preventing browser exploitation Overview Whirlwind tour of Vista protection mechanisms GS, SafeSEH, DEP, ASLR Techniques for exploiting protection limitations All protections broken Conclusion Full paper available at http://taossa.com

Additional Research Objectives Despite conventional wisdom, girls really are impressed by this research Field testing conducted by Mark and Alex Photographic evidence!

Girls are not impressed by us yet!

Demo Exploiting IE despite all protections on Vista ASLR and DEP turned on Third party plugins NOT required for exploitation This works with IE8 as well

Part II: Vista Protection Features

Memory Protection Mechanisms

Memory Protection Mechanisms Detect memory corruption: GS stack cookies SEH chain validation Heap corruption detection Stop common exploitation patterns: GS (variable reordering) SafeSEH DEP ASLR

GS Stack Cookies GS prevents the attacker from using an overwritten return address on the stack Adds a stack cookie between the local variables and return address Checks the cookie at the function epilogue

GS Variable Reordering Prevents the attacker from overwriting other local variables or arguments String buffers go above other variables Arguments copied below local variables source code standard stack frame stack frame with /GS void vuln(char* arg) buf copy of arg { i i char buf[100]; return address buf int i; arg stack cookie strcpy(buf, arg); return address... arg (unused) }

SafeSEH Prevents the attacker from using an overwritten SEH record. Allows only the following cases: Handler found in SafeSEH table of a DLL Handler in a DLL linked without /SafeSEH If DEP is disabled, we have one more case: Handler on a non-image page, but not on the stack

SEH Chain Validation New protection in Windows Server 2008, much more effective than SafeSEH Puts a cookie at the end of the SEH chain The exception dispatcher walks the chain and verifies that it ends with a cookie If an SEH record is overwritten, the SEH chain will break and will not end with the cookie Present in Vista SP1, but not enabled

Data Execution Prevention (DEP) Prevents the attacker from jumping to data: Uses the NX bit in modern CPUs Modes of operation OptIn protects only apps compiled with /NXCOMPAT. Default mode on XP and Vista OptOut protects all apps unless they opt out. Default mode on Server 2003 and 2008 AlwaysOn/AlwaysOff as you d expect DEP is always enabled for 64-bit processes Internet Explorer on Vista x64 is still a 32-bit process with no DEP

Data Execution Prevention (DEP) Can be enabled and disabled at runtime with NtSetInformationProcess() Skape and Skywing s attack against DEP Permanent DEP in Vista Important: DEP does not prevent the program from allocating RWX memory

Address Space Layout Randomization (ASLR) Dramatically lowers exploit reliability Relies on nothing being statically placed Several major components Image Randomization Heap Randomization Stack Randomization PEB/TEB Randomization

Address Space Layout Randomization (ASLR) Binaries opted-in to ASLR will be randomized Configurable: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Con trol\session Manager\Memory Management\MoveImages Stragegy 1: DLL randomization Random offset from 0x78000000 up to 16M chosen ( Image Bias ) DLLs packed together near the top of memory (First DLL Ending with Image Bias) Known DLLs order also mixed up at boot time Constant across different processes (mostly..) Strategy 2: EXE randomization Random image base chosen within 16M of preferred image base DLLs also use this strategy if DLL Range is used up Granularity of Address Space: 64K

Address Space Layout Randomization (ASLR)

Address Space Layout Randomization (ASLR) Heap randomization strategy: Move the heap base Address where heap begins is selected linearly with NtAllocateVirtualMemory() Random offset up to 2M into selected region is used for real heap base 64K alignment Stack randomization strategy: Selecting a random hole in the address space Random 5-bit value chosen (X) Address space searched X times for space to allocate the stack Stack base also randomized Stack begins at random offset from selected base (up to half a page) DWORD aligned

Girls are getting slightly more interested

Part III: Breaking Vista Protections

Functions containing certain types of variables are not protected: structures (ANI vulnerability) arrays of pointers or integers void func(int count, int data) { int array[10]; int i; GS: Function Heuristics } for (i = 0; i < count; i++) array[i] = data;

The function might use overwritten stack data before the cookie is checked: callee saved registers copy of pointer and string buffer arguments local variables string buffers gs cookie exception handler record saved frame pointer return address arguments stack frame of the caller GS: Use of Overwritten Data o v e r f l o w

Triggering an exception will give us control of the program execution before the GS cookie check. overwrite a pointer or counter variable overflow to the top of the stack application specific exceptions GS: Exception Handling SEH records on the stack are not protected by GS, but we have to bypass SafeSEH.

Opt-In Attacks Features requiring opt-in SafeSEH DEP ASLR

Opt-In Attacks - SafeSEH If DEP is disabled, we can just point an overwritten SEH handler to the heap If DEP is enabled, SafeSEH protections can be bypassed if a single unsafe DLL is loaded Flash9f.ocx

Opt-In Attacks - DEP Vista runs in opt-in mode by default Applications need to specifically opt-in to receive DEP protections No need to bypass something that isn t there.. DEP not enabled in IE7 or Firefox 2 IE8 and Firefox 3 opted-in

Opt-In Attacks - ASLR Vista randomizes only binaries that opt-in A single non-randomized binary is sufficient to bypass ASLR (and DEP) Some major 3 rd party plugins do not opt-in Flash Java Microsoft does not utilize ASLR for all binaries.net runtime!

Heap Spraying Heap spraying JavaScript (bypasses ASLR) Java (bypasses ASLR and DEP)

Heap spraying can bypass ASLR Consume large amounts of address space with controllable data Only the beginning of the heap is randomized The maximum offset is 2MB Heap Spraying If we allocate a chunk larger than 2MB, some part of it will be at a predictable address +0MB +2MB +3MB

JavaScript heap spraying Defeats ASLR (but not DEP) Heap Spraying - JavaScript 64KB-aligned allocations allow us to put arbitrary data at an arbitrary address Allocate multiple 1MB strings, repeat a 64KB pattern 64KB 64KB

Heap Spraying - Java The Sun JVM allocates all memory RWX DEP not an issue ASLR mitigated Executable heap spraying code: public class Test extends Applet { static String foo = new String("AAAA..."); static String[] a = new String[50000]; } public void init() { for (int i=0; i<50000; i++) { a[i] = foo + foo; } }

Heap Spraying - Java Screenshot 0:031>!vadump BaseAddress: RegionSize: State: Protect: Type: 22cc0000 058a0000 00001000 MEM_COMMIT 00000040 PAGE_EXECUTE_READWRITE 00020000 MEM_PRIVATE

Stack Spraying Alternative to Heap Spraying with potential bonuses Shellcode Meta-Data (saved EIP, etc) Pointers to user-controlled data Overwrite target in addition to shellcode buffer There are several difficulties Cannot be indefinitely expanded Often control contents directly Need recursive functions in a lot of cases

Stack Spraying Problems easily solved by.net and Java! Thread constructors allow stack size of your choosing High degree of control over stack contents Creating pointers is simple too: objects/arrays/etc as parameters/local variables Also usable to exhaust large parts of the address space

Method 1: Overwrite Targets Stack Spraying Fill the stack with useful pointers to overwrite Saved EIPs are probably most useful Create a recursive function to fill the entire stack Overwrite anywhere in the memory region for the win! Method 2: Generate Code Large amount of local variables Fill with executable code DEP will prevent execution, but this is also true of heap spraying

Stack Spraying

Stack Spraying Method 3: Pointer Spraying Languages don t allow pointer creation directly Declaring objects/arrays will create pointers Useful for exploits requiring indirection

Stack Spraying and ASLR

Stack spraying is definitely impressive!

.NET and IE IE allows embedding of.net User Controls.NET equivalent of a Java applets Embedded in a web page using the <OBJECT> tag <OBJECT classid="controlname.dll#namespace.classname"> Unlike ActiveX, no warning in Internet Zone User controls are.net DLLs That s right DLLs can be embedded in web pages! Similar to native DLLs with some additional metadata They can t contain native code (IL-Only) Loaded into the process with LoadLibrary

.NET shellcode Loading User Controls is interesting in the context of memory protections We can define memory region sizes Page protections are arbitrary In XP, Image base is directly controllable by the attacker On Vista, ASLR prevents direct load address control IL-Only binaries are always randomized, despite opting out of ASLR Load address can still be influenced

Large DLL Method 1 Create a large DLL (~100MB) Must consume less than Standard DLL range Approximate load location easily guessable.net Controls - Large DLLs

Large DLL Method 2 Create even larger DLL (~200MB) Approximate load location easily guessable Additional bonus: Select addresses that will bypass character restrictions.net Controls - Large DLLs

.NET Controls - Large DLLs Problem: 100M+ is too much to download Pages will take too long to load Solution 1: Binary Padding For a given section, make the VirtualSize very large, and SizeOfRawData 0 or small Zero-padded when mapped Repeating instruction add byte ptr [eax], al Needs EAX to point to writable memory Solution 2: Compression HTTP can zip up content on the fly Achieved with Content-Encoding header

Large DLL Method 3 Create large DLL (Virtual Padding) Create smaller 16M DLL with shellcode etc Compress smaller DLL with HTTP.NET Controls - Large DLLs

Small DLL Method Embed a large number of small DLLs (4-8K) About 300 of them is enough (~20M) They all get placed on 64K boundaries in Standard DLL Range Target any one of the DLLs in range.net Controls - Small DLLs

.NET Controls Statically Located DLLs Ideal situation is to have statically positioned, self-supplied.net DLLs ASLR enforced on IL-Only binaries Loader checks if binary is a.net IL-Only binary and relocates it anyway (no opting out) Is this effective? Not quite Flagging an IL-Only binary depends on version information read from.net COR header!

.NET Controls Statically Located DLLs Code from MiCreateImageFileMap(): if( (pcorheader->majorruntimeversion > 2 (pcorheader->majorruntimeversion == 2 && pcorheader->minorruntimeversion >= 5) ) && (pcorheader->flags & COMIMAGE_FLAGS_ILONLY) ) { pimagecontrolarea->pbinaryinfo->pheaderinfo->bflags = PINFO_IL_ONLY_IMAGE; } Statically position DLL in 3 Simple steps Opt out of ASLR (unset IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE) Select ImageBase of your choosing Change version in COR header (2.5 -> 2.4 is sufficient)

Demo.NET Controls Statically Located DLLs

.NET FTW!

Part IV: Conclusion

Conclusion Vista memory protections are ineffective at preventing browser exploitation Large degree of control attacker has to manipulate process environment Open plugin architecture Single point of failure More work needed on secure browser architecture Questions?