CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2.

Slides:



Advertisements
Similar presentations
Windows Heap Exploitation (Win2KSP0 through WinXPSP2)
Advertisements

Windows Heap Overflows David Litchfield. Windows Heap Overflows Introduction This presentation will examine how to exploit heap based buffer overflows.
Part IV: Memory Management
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
Integrity & Malware Dan Fleck CS469 Security Engineering Some of the slides are modified with permission from Quan Jia. Coming up: Integrity – Who Cares?
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
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.
User-Level Memory Management in Linux Programming
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
COMP3221: Microprocessors and Embedded Systems Lecture 12: Functions I Lecturer: Hui Wu Session 2, 2005.
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.
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
September 22, 2014 Pengju (Jimmy) Jin Section E
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
A survey of Buffer overflow exploitation on HTC touch mobile phone Advanced Defense Lab CSIE NCU Chih-Wen Ou.
System Calls 1.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Fall 2008CS 334: Computer SecuritySlide #1 Smashing The Stack A detailed look at buffer overflows as described in Smashing the Stack for Fun and Profit.
Reliable Windows Heap Exploits
Computer Security and Penetration Testing
Software attacks Lorenzo Dematté Software attacks Advanced buffer overflow: heap smashing.
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
Stack and Heap Memory Stack resident variables include:
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 10 “Buffer Overflow”.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
Buffer Overflow Attack-proofing by Transforming Code Binary Gopal Gupta Parag Doshi, R. Reghuramalingam The University of Texas at Dallas 11/15/2004.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
CNIT 127: Exploit Development Ch 4: Introduction to Heap Overflows
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
Lecture 9: Buffer Ovefflows and ROP EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014,
Buffer overflow and stack smashing attacks Principles of application software security.
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.
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.
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.
Chapter 10 Chapter 10 Implementing Subprograms. Implementing Subprograms  The subprogram call and return operations are together called subprogram linkage.
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.
Mitigation against Buffer Overflow Attacks
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
Security mechanisms and vulnerabilities in .NET
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Advanced Buffer Overflow: Pointer subterfuge
Memory Segments Code (.code) Data (.data) Stack Heap
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
The future of Software Security Dr. Si Chen
CSE 153 Design of Operating Systems Winter 2019
CSC 497/583 Advanced Topics in Computer Security
Understanding and Preventing Buffer Overflow Attacks in Unix
COMP755 Advanced Operating Systems
Windows Heap Overflows
Week 3: Format String Vulnerability
Return-to-libc Attacks
Presentation transcript:

CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2

Topics Stack Protection Heap-Based Buffer Overflows Other Overflows

Stack Protection

Windows Stack Protections Microsoft Visual C++.NET provides – /GS compiler flag is on by default – Tells compiler to place security cookies on the stack to guard the saved return address – Equivalent of a canary – 4-byte value (dword) placed on the stack after a procedure call – Checked before procedure return – Protects saves return address and EBP

How is the Cookie Generated? When a process starts, Windows combines these values with XOR – DateTime (a 64-bit integer counting time intervals of 100 nanoseconds) – Process ID – Thread ID – TickCount (number of milliseconds since the system started up) – Performance Counter (number of CPU cycles)

Predicting the Cookie If an attacker can run a process on the target to get system time values Some bits of the cookie can be predicted

Effectively 17 bits of Randomness

How Good is 17 Bits? 2^17 = 131,072 So an attacker would have to run an attack 100,000 times or so to win by guessing the cookie

Prologue Modification __security_cookie value placed in the stack at a carefully calculated position To protect the EBP and Return value – From link Ch 8m

Epilogue Modification Epilogue to a function now includes these instructions – From link Ch 8m

__security_check_cookie Current cookie value is in ecx Compared to authoritative value stored in the.data section of the image file of the procedure If the check fails, it calls a security handler, using a pointer stored in the.data section

Parameter Order Before Windows Server 2003, local variables were placed on the stack in the order of their declaration in the C++ source code Now all arrays are moved to the bottom of the list, closest to the saved return address This prevents buffer overflows in the arrays from changing the non-array variables

Overwriting Parameters

We've changed the cookie, but if the parameters are used in a write operation before the function returns, we could – Overwrite the authoritative cookie value in the.data section, so the cookie check passes – Overwrite the handler pointer to the security handler, and let the check fail Handler could point to injected code Or set handler to zero and overwrite the default exception handler value

Heap-Based Buffer Overflows

Purpose of the Heap Consider a Web server HTTP requests vary in length May vary from 20 to 20,000 bytes or longer (in principle) Once processed, the request can be discarded, freeing memory for re-use For efficiency, such data is best stored on the heap

The Process Heap Every process running on Win32 has a process heap The C function GetProcessHeap() returns a handle to the process heap A pointer to the process heap is also stored in the Process Environment Block

The Process Heap This code returns that pointer in eax Many of the underlying functions of the Windows API use this default process heap

Dynamic Heaps A process can create as many dynamic heaps as required All inside the default process heap Created with the HeapCreate() function

From link Ch 8o

Working with the Heap Application uses HeapAllocate() to borrow a chunk of memory on the heap – Legacy functions left from Win16 are LocalAlloc() & GlobalAlloc(), but they do the same thing— there's no difference in Win32 When the application is done with the memory, if calls HeapFree() – Or LocalFree() or GlobalFree()

How the Heap Works The stack grows downwards, towards address 0x The heap grows upwards Heap starts with 128 LIST_ENTRY structures that keep track of free blocks

Vulnerable Heap Operations When a chunk is freed, forward and backward pointers must be updated This enables us to control a write operation, to write to arbitrary RAM locations – Image from mathyvanhoef.com, link Ch 5b

Details There is a lot more to it, involving these structures – Segment list – Virtual Allocation list – Free list – Lookaside list For details, see link Ch8o

Exploiting Heap-Based Overflows: Three Techniques Overwrite the pointer to the exception handler Overwrite the pointer to the Unhandled Exception Filter Overwrite a pointer in the PEB

Overwrite a Pointer in the PEB RtlEnterCriticalSection, called by RtlAcquirePebLock() and RtlReleasePebLock() Called whenever a process exits with ExitProcess() PEB location is fixed for all versions of Win NT Your code should restore this pointer, and you may also need to repair the heap

Win 2003 Server Does not use these pointers in the PEB But there are Ldr* functions that call pointers we can control – Includeing LdrUnloadDll()

Vectored Exception Handling Introduced with Windows XP Traditional frame-based exception handling stores exception registration records on the stack Vectored exception handling stores information about handlers on the heap A heap overflow can change them

Overwrite a Pointer to the Unhandled Exception Filter First proposed at Blackhat Amsterdam (2001) An application can set this value using SetUnhandledExceptionFilter() – Disassemble that function to find the pointer

Repairing the Heap The overflow corrupts the heap This will probably cause your shellcode to cause an access violation Simplest repair process is to just make the heap look like a fresh, empty heap – With the one block we are using on it

Restore the Exception Handler you Abused Otherwise, you could create an endless loop If your shellcode causes an exception

COM Objects and the Heap Component Object Model (COM) Objects – An object that can be created when needed by another program – It has methods that can be called to perform a task – It also has attributes (stored data) COM objects are created on the heap

Vtable in Heap All COM classes have one or more interfaces, which are used to connect them to a program – Figure from link Ch 8p

COM Objects Contain Data If the programmer doesn't check, these data fields could be overflowed, into the next object's vtable – Image from link Ch 8q

From link Ch 8q Image on next slide from link Ch 8r

Example: ActiveX

DLL Exports WriteIniFileString()

ShellExecute()

Exploiting IE 6 Doesn't work on IE 7 on Win 2008 – Link Ch 8x

Other Overflows

Overflows in the.data Section If a buffer is placed before function pointers in the.data section Overflowing the buffer can change the pointers

TEB/PEB Overflows In principle, buffers in the TEB used for converting ASCII to Unicode could be overflowed Changing pointers There are no public examples of this type of exploit