Heap Overflows. What is a Heap? malloc(), free(), realloc() Stores global variables Automatic memory allocation/deallocation Allocated at runtime Implemented.

Slides:



Advertisements
Similar presentations
Secure Coding in C and C++ Dynamic Memory Management
Advertisements

Dynamic memory allocation
Smashing the Stack for Fun and Profit
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
DIEHARDER: SECURING THE HEAP. Previously in DieHard…  Increase Reliability by random positioning of data  Replicated Execution detects invalid memory.
Buffer Overflows By Tim Peterson Joel Miller Dan Block.
Intro to Exploitation Stack Overflows James McFadyen UTD Computer Security Group 10/20/2011.
CSE 451: Operating Systems Section 1. Why are you here? 9/30/102.
Gabe Kanzelmeyer CS 450 4/14/10.  What is buffer overflow?  How memory is processed and the stack  The threat  Stack overrun attack  Dangers  Prevention.
Stack buffer overflow.
Stack buffer overflow
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
Buffer Overflow. Process Memory Organization.
Run-Time Storage Organization
Computer Security Buffer Overflow lab Eu-Jin Goh.
Unix Process Environment. main Function A C program starts execution with a function called main. The prototype for the main function is: int main (int.
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
BLENDED ATTACKS EXPLOITS, VULNERABILITIES AND BUFFER-OVERFLOW TECHNIQUES IN COMPUTER VIRUSES By: Eric Chien and Peter Szor Presented by: Jesus Morales.
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
Buffer Overflow Maddikayala, jagadish. CSCI 5931 Web Security Prof. T. Andrew Yang Monday Feb. 23.
Mitigation of Buffer Overflow Attacks
Brian E. Brzezicki. This tutorial just illustrates the underlying concepts of buffer overflows by way of an extremely simple stack overflow  Most buffer.
Rpisec.org/2013/ /exploitation.zip For the lazy – rpisec.org/2013/ Windows & Linux Binaries! … macs? RPISEC - 09/13/2013Intro to Memory Corruption1.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Smashing the Stack Overview The Stack Region Buffer Overflow
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
CNIT 127: Exploit Development Ch 4: Introduction to Heap Overflows
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.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
+ Dynamic memory allocation. + Introduction We often face situations in programming where the data is dynamics in nature. Consider a list of customers.
Buffer overflow and stack smashing attacks Principles of application software security.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
EXPLOITATION CRASH COURSE – FALL 2013 UTD Computer Security Group – Andrew Folloder csg.utdallas.edu (credit: Scott Hand)
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
About Exploits Writing ABOUT EXPLOITS WRITING Gerardo Richarte 
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Memory-Related Perils and Pitfalls in C
Heap Overflow Attacks.
Buffer Overflows ...or How I Learned to Never Trust the User
Buffer Overflow By Collin Donaldson.
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.
Buffer Overflow Attacks
Basic memory structure & binary exploitation
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
CSE 451 C refresher.
Objective Explain basic fuzzing with concrete coding example
SEED Workshop Buffer Overflow Lab
Stack buffer overflow.
Software Security Lesson Introduction
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
CSE451 Fall 2008 Section 1 Roxana Geambasu
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
The future of Software Security Dr. Si Chen
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
Program Execution in Linux
Malware and Software Vulnerability Analysis Fuzzing Test Example Cliff Zou University of Central Florida.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
Run-time environments
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2010.
Presentation transcript:

Heap Overflows

What is a Heap? malloc(), free(), realloc() Stores global variables Automatic memory allocation/deallocation Allocated at runtime Implemented in glibc

What is a Heap?

Basic Heap Overflows /*notvuln.c*/ int main( int argc, char** argv) { char * buf; buf =(char*)malloc(1024); printf(“buf=%p”, buf); strcpy(buf, argv[1]); free(buf); }

Basic Heap Overflows /*basicheap.c*/ int main( int argc, char** argv) { char *buf; char *buf2; buf = (char*)malloc(1024); buf2 = (char*)malloc(1024); printf(“buf=%p buf2=%p\n”, buf, buf2); strcpy(buf, argv[1]); free(buf2); }

Basic Heap Overflows lstrace./basicheap `perl –e ‘print “A” x 5000’` … malloc(1024) = 0x080495b0 malloc(1024) = 0x080499b8 strcpy(0x080495b0, “AAAAAAAAAAAAAAAAAAAA”…) = 0x080495b0 free(0x080499b8) = --- SIGSEGV (Segmentation fault) killed by SIGSEGV +++ Heap Overflow!

Heap Overflows Overwrite the next chunk header

Heap Overflows Trace the behavior of free() using gdb buf=0x80495b0 bu2=0x80499b8 buf2’s boundary tags are overwritten

Heap Overflows (gdb) run `python –c ‘print “A”*1024+”\xff\xff\xff\xff”+””\xf0\xff\xff\xff”’` Set a breakpoint on _int_free() (called by free) Right before free is called, we see: (gdb) print/x $edi $10 = 0xfffffff0 (gdb) print/x $esi $11 = 0x80499b0

Heap Overflows free() arithmatic: –Address of the previous chunk = (Current chunk address) - (sizeof(previous buffer)) Since we overwrote the (sizeof(previous buffer)), we can control the address of the previous chunk free() writes to the address of what it thinks is the previous chunk After some more free() sillyness, we can eventually control where free() writes, and redirect program execution to the stack

Advanced Heap Overflows Can also overflow malloc() –trickier: once again corrupt chunk headers to redirect flow of execution –malloc() uses similar arithmatic to Not as easy because of differences in each version of glibc

Sources “The Shellcoder’s Handbook” (Jack Koziol) ml erflow.html