An overview Secologic Treffen Martin Johns

Slides:



Advertisements
Similar presentations
Buffer Overflows Nick Feamster CS 6262 Spring 2009 (credit to Vitaly S. from UT for slides)
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Smashing the Stack for Fun and Profit
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
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.
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
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.
Kernighan/Ritchie: Kelley/Pohl:
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
Buffer Overflows By Tim Peterson Joel Miller Dan Block.
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.
Buffer Overflow By: John Quach and Napoleon N. Valdez.
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.
Run time vs. Compile time
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Microprocessors Frame Pointers and the use of the –fomit-frame-pointer switch Feb 25th, 2002.
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.
Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Buffer overflows.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
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.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
Runtime Environments Compiler Construction Chapter 7.
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
Compiler Construction
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
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
Brian E. Brzezicki. This tutorial just illustrates the underlying concepts of buffer overflows by way of an extremely simple stack overflow  Most buffer.
University of Washington Today Happy Monday! HW2 due, how is Lab 3 going? Today we’ll go over:  Address space layout  Input buffers on the stack  Overflowing.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Topic 2d High-Level languages and Systems Software
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Smashing the Stack Overview The Stack Region Buffer Overflow
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
Lecture 8: Buffer Overflow CS 436/636/736 Spring 2013 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
Introduction to Information Security ROP – Recitation 5.
Buffer overflow and stack smashing attacks Principles of application software security.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
Compiler Construction Code Generation Activation Records
Information Security - 2. A Stack Frame. Pushed to stack on function CALL The return address is copied to the CPU Instruction Pointer when the function.
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.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
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.
Introduction to Information Security
Introduction to Information Security
Introduction to Compilers Tim Teitelbaum
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Advanced Buffer Overflow: Pointer subterfuge
Assembly Language Programming II: C Compiler Calling Sequences
Format String.
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Understanding and Preventing Buffer Overflow Attacks in Unix
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
Topic 2b ISA Support for High-Level Languages
Return-to-libc Attacks
Presentation transcript:

An overview Secologic Treffen 11.07.2005 Martin Johns C Insecurities An overview Secologic Treffen 11.07.2005 Martin Johns

Agenda Basics: The Stack Buffer Overflows Format String Vulnerabilities Heap Overflows DISCLAIMER The following slides are geared towards: The C language The Intel x86 processor family Unix-like and or Windows operating systems Depending on used language, processor or operating system some or all addressed topics may differ

Basics: Process Memory Layout Higher addresses Depending on the operating system the actual memory layout may somewhat differ Usage of memory below the heap Usage of memory above the stack Coherent memory is always read and written from lower addresses to higher addresses (not considering little/big endian) User Stack Unallocated memory Heap Program Text Lower addresses

Basics: The Stack vs. The Heap Higher addresses The Stack grows from the higher to the lower addresses The Heap (initially) grows from the lower to the higher addresses The Stack is used to store data that is local to functions The Heap is used to store data that is persistent between function calls Stack allocation is implicit char test[42]; Heap allocation is (usually) explicit char *test = malloc(42*sizeof(char)); User Stack Unallocated memory Heap Program Text Lower addresses

Basics: The Stack Higher addresses Direction of growth … Lower addresses

Command line arguments Basics: The Stack Higher addresses The Stack is used for: The Environment Command line arguments Environment Command line arguments … Direction of growth Lower addresses

Command line arguments Basics: The Stack Higher addresses The Stack is used for: The Environment Command line arguments Function parameters Return addresses Saved frame pointers Local variables Environment Command line arguments … Function parameters Return address Saved frame pointer Local variables of the function Stack frame Direction of growth Lower addresses

Basics: The Stack – Processor view (x86) Several processor inherent constructs define the Stack The register SP points to the top of the stack Instructions that are stack-aware modify the value of SP automatically push, pop call, return (enter, leave) The Frame Pointer The Frame Pointer is utilized by a function to access the local function context on the stack (function parameters, local variables) The register BP is used as Frame Pointer (assigned by the compiler) Instructions to modify this register are (originally) generated by the compiler Local variables and function parameters are referenced relatively to the Frame Pointer Function parameters have positive offsets Local variable have negative offsets

Basics: The function call Higher addresses b = something(15); Move SP to reserve space for function parameter Write value of function parameter on the stack Call function (implicitly moves return address on the stack) FP 0xdeadbeef SP 15 return adr. SP Lower addresses

Basics: The function prolog Higher addresses int something(int para){ int local_var; ... } Save the old FP on the stack Move the FP to the new frame Move the SP to reserve space for the local variables FP 0xdeadbeef 15 return adr. SP FP saved FP SP local_var SP Lower addresses

Basics: The function epilog Higher addresses int something(int para){ ... return (0); } Write the return value to the register AX Move the SP back to the FP Restore the old FP Pop the stored old FP Pop the return address and leave the function FP 0xdeadbeef SP 15 return adr. SP FP saved FP SP local_var SP Lower addresses

Buffer Overflows on the stack C Insecurities Buffer Overflows on the stack

Buffer Overflows A C buffer is represented by a pointer variable which points to the first address of the buffer The programming language has no mechanism to enforce the buffer boundaries Therefore it lies in the responsibilities of the program to respect the buffer boundaries If a misbehaving program and ignores the buffer boundaries the adjacent memory regions may get overwritten

Buffer Overflow on the stack Higher addresses int something(int para){ char buf[8]; ... strcpy(buf, “secolog”); } … function parameter return address saved FP buf[4] – buf[7] buf[0] – buf[3] FP SP *buf Lower addresses

Buffer Overflow on the stack Higher addresses int something(int para){ char buf[8]; ... strcpy(buf, “secolog”); ... strcpy(buf, “secure analysis”); } … function parameter return address saved FP log seco FP SP *buf Lower addresses

Buffer Overflow on the stack Higher addresses int something(int para){ char buf[8]; ... strcpy(buf, “secolog”); ... strcpy(buf, “secure analysis”); } The saved Frame Pointer gets overwritten … function parameter return address saved FP re a secu FP SP *buf Lower addresses

Buffer Overflow on the stack Higher addresses int something(int para){ char buf[8]; ... strcpy(buf, “secolog”); ... strcpy(buf, “secure analysis”); } The saved Frame Pointer gets overwritten The return address gets overwritten … function parameter return address naly re a secu FP SP *buf Lower addresses

Buffer Overflow on the stack Higher addresses int something(int para){ char buf[8]; ... strcpy(buf, “secolog”); ... strcpy(buf, “secure analysis”); } The saved Frame Pointer gets overwritten The return address gets overwritten … function parameter sis_ naly re a secu FP SP *buf Lower addresses

Exploiting a Buffer Overflow Using a stack based Buffer Overflow to hijack execution: Construct a buffer that contains executable code (the shellcode) Guess the memory address of the vulnerable buffer on the stack Pad the constructed shellcode Before the shellcode: As many NOP instructions as possible Behind the shellcode: The guessed address of the beginning of the shellcode (or the nops) The constructed buffer has to be big enough to overwrite the return address on the stack

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); } argc[1] contains the constructed malicious data The malicious data is big enough to overflow the buffer and overwrite the rerturn address … parameter return address saved FP size of the malicious data FP SP *buf

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); } argc[1] contains the constructed malicious data The data starts with the NOPs … parameter return address saved FP FP SP *buf

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); } argc[1] contains the constructed malicious data The data starts with the NOPs In the middle follows the Shellcode … parameter return address saved FP NOP NOP NOP NOP FP SP *buf

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); } argc[1] contains the constructed malicious data The data starts with the NOPs In the middle follows the Shellcode The remaining buffer is filled with the (guessed) malicious return address … parameter return address saved FP shellcode NOP NOP NOP NOP FP SP *buf

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); } argc[1] contains the constructed malicious data The data starts with the NOPs In the middle follows the Shellcode The remaining buffer is filled with the (guessed) malicious return address … new return address shellcode NOP NOP NOP NOP FP SP *buf

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); } The new return address points to a location in the buffer At least if the guessed location of the stack was correct … new return address shellcode NOP NOP NOP NOP FP SP *buf

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); return(0); } The Stack Pointer is moved to the Frame Pointer The old Frame Pointer is popped from the stack The old value was overwritten, the location of the FP is therefore meaningless The return address is popped from the stack into the Instruction Register (IR) … new return address shellcode NOP NOP NOP NOP SP SP FP SP SP *buf

Buffer Overflow on the stack int something(int,int){ char buf[512]; ... strcpy(buf,argc[1]); return(0); } The new return address points to a location in the buffer The program executes the NOPs and the following shellcode … new return address shellcode NOP NOP NOP NOP SP *buf

Causes for Buffer Overflows Library functions, that don’t check buffer boundaries: strcpy(), strcat(), sprintf(),… Library functions, that rely on the programmer to pass correct buffer boundaries: char buf1[4]; char buf2[8]; buf2 = “1234567”; strncpy(buf1,buf2,8); Careless pointer arithmetic: while(<some condition>){ *buf1++ = *buf2++ } (cause of the Blaster Worm) Careless type casting of variables

Advanced Buffer Overflow techniques Small buffers Trampolining Return-into-libc / arc injection [Pointer manipulation] [Off By One]

Exploiting a small buffer Sometimes an overflowable buffer is too small to contain an executable shellcode In this situations the attacker can try to place the shellcode at a different location in the memory Environment variables Non vulnerable buffers on the stack Buffer on the heap As long as the attacker is able to guess the memory location of these buffers, he can manipulate the return address accordingly

Trampolining In some situations the attacker is not able to determine (guess) the absolute address of the manipulated stack region Instead of modifying the return address to a location on the stack, the attacker points the return address to a location in the program code (the “Trampoline”) The reference location in the program code contains a sequence of instructions which enables involuntary a transfer of the control flow to the attackers code on the stack Example: JMP to a value that is kept in a register The location of those regions in the program code are usually static and therefore easy guessable This exploitation technique is especially popular on W32 operating systems (apparently kernel32.dll contains a couple of usable code sequences)

Trampolining: “pop pop pop return” The situation: The attacker is able to place shellcode on the stack The attacker is also able to overflow the return address The stack contains a pointer to the shellcode (e.g. a function parameter) The program code contains a sequence of pop-instructions followed by a return instruction

Trampolining: “pop pop return” (II) The Stack The stack contains the shellcode The stack contains a pointer to the shellcode The attacker is able to overflow a buffer shellcode shellcode … pointer to shellcode some value return address saved FP buffer The program code FP vulnerable buffer pop EAX pop EBX pop ECX pop EBP return SP

Trampolining: “pop pop return” (II) The Stack The attacker overflows the return address with the location of the trampoline shellcode … pointer to shellcode some value return address saved FP buffer The program code FP vulnerable buffer pop EAX pop EBX pop ECX pop EBP return SP

Trampolining: “pop pop return” (II) The Stack The attacker overflows the return address with the location of the trampoline shellcode … pointer to shellcode some value trampoline address The program code FP vulnerable buffer pop EAX pop EBX pop ECX pop EBP return SP

Trampolining: “pop pop return” (II) The Stack When the function returns, the control flow is transferred to the “trampoline” shellcode … pointer to shellcode some value trampoline address SP The program code FP pop EAX pop EBX pop ECX pop EBP return IP SP

Trampolining: “pop pop return” (II) The Stack When the function returns, the control flow is transferred to the “trampoline” The trampoline code removes unwanted data from the stack shellcode … pointer to shellcode some value SP The program code pop EAX pop EBX pop ECX pop EBP return IP

Trampolining: “pop pop return” (II) The Stack When the function returns, the control flow is transferred to the “trampoline” The trampoline code removes unwanted data from the stack shellcode … pointer to shellcode some value SP The program code pop EAX pop EBX pop ECX pop EBP return IP

Trampolining: “pop pop return” (II) The Stack When the function returns, the control flow is transferred to the “trampoline” The trampoline code removes unwanted data from the stack shellcode … pointer to shellcode some value SP The program code pop EAX pop EBX pop ECX pop EBP return IP

Trampolining: “pop pop return” (II) The Stack When the function returns, the control flow is transferred to the “trampoline” The trampoline code removes unwanted data from the stack shellcode … pointer to shellcode some value SP The program code pop EAX pop EBX pop ECX pop EBP return IP

Trampolining: “pop pop return” (II) The Stack When the function returns, the control flow is transferred to the “trampoline” The trampoline code removes unwanted data from the stack The return instruction uses the pointer to the shellcode shellcode … pointer to shellcode SP SP The program code pop EAX pop EBX pop ECX pop EBP return IP

Trampolining (III) Other “Trampolines” Using a pointer to a buffer on the Heap Instead of “pop pop return”: Jump to an address stored in a register

Return-into-libc / Arc Injection Depending on the system configuration, it may be prohibited to execute code on the stack Instead of placing malicious code on the stack, the control flow is directed to a location in the program code Before the modification of the control flow the stack is manipulated, to contain a valid stack frame This stack frame will trick the program code to perform as the attacker wishes A popular target is the libc These kind of attacks are sometimes also calls “Arc Injection” A “standard” Buffer Overflow adds a new node to the control flow graph This kind of attack adds a new ark

Return-into-libc / Arc Injection (II) Example: system() High level libc system call, which spawns a new process void system(char* arg){ ... } system(“/bin/sh”); system() expects a stack frame which contains a pointer to a C-string as only function parameter This string contains the path to the binary (and the arguments) A successful return to libC attack would construct a stack frame which provides the described conditions

Format String Vulnerabilities C Insecurities Format String Vulnerabilities

Format String Vulnerabilities ANSI C contains a mechanism to allow a function to use a dynamic number of arguments Usually the first argument of the function contains the information, how many more arguments were passed to the function Example: The first argument of printf() is the format string, which determines the number and type of the additional arguments: printf(“%s %d”, charpoiner, int); What happens, when the number of expected arguments and the number of passed arguments differ?

Format String Vulnerabilities (II) Higher addresses a = 1; b = 2; printf (“%d %d %d”,a,b); … function parameter return address saved FP Lower addresses

Format String Vulnerabilities (II) Higher addresses a = 1; b = 2; printf (“%d %d %d”,a,b); The first function argument is a pointer to the format string The function determines the number of arguments The first referenced argument is the value 1 The second referenced argument is the value 2 The third referenced argument is ??? … 2 1 pointer to FS return address saved FP Lower addresses

Format String Vulnerabilities (III) The printf() function family printf() uses format specifiers to identify the number and types of passed values %i, %d, %u, %x: Integer or char arguments The value is directly printed %p: Pointer argument The value is directly printed %s Pointer argument The value is interpreted as an char pointer Standard format specifiers are processed sequentially Direct argument access It is possible to access an argument directly %5$d accesses the 5th argument and interprets it as an int A malicious format string is therefore able to directly access every location on the stack

Format String Vulnerabilities (IV) Writing to memory printf() is able to write the amount of printed bytes to a given memory location To achive this, the format specifier %n is used Example: int i; printf(“Hello world\n%n”, &i); printf(“Last output: %d bytes\n”, i); Scenario: The attacker is able to control (parts of) the format string The attacker is able to store data on the stack  The attacker is able to overwrite arbitrary memory locations

Format String Vulnerabilities (V) Possible attack targets Return addresses on the stack Internal pointers, function pointer, C++-specific structures like VTABLE entries Overwriting a NULL terminator in some string to create a possible buffer overflow Changing arbitrary data in memory

Format String Vulnerabilities (VI) Higher addresses printf (fstring); The attacker is able to control the content of fstring The attacker was able to place data on the stack … pointer to fstring return address saved FP Stack frame of printf() fstring = “...%12$n“ Lower addresses

Format String Vulnerabilities (VI) Attacker controlled Data (e.g. the format string) Higher addresses printf (fstring); The attacker is able to control the content of fstring The attacker was able to place data on the stack This data contains a pointer to the return address The malicious format string references this pointer The attacker is able to overwrite the return address The value which is written is controlled by the length of the format string badb … dbad pointer to fstring return address saved FP fstring = “...%12$n“ Lower addresses

C Insecurities Heap Overflows

Heap Overflows The causes for heap overflows are the same as the reasons for buffer overflows on the stack Unsafe library functions Careless pointer arithmetic The exploitation of heap overflows is fundamentally different The heap contains no return addresses that could be overwritten Possible attacks Overwriting of data structures Function pointers VTable entries (C++) Manipulating control data

Overwriting C++ VTables Higher addresses myObj *x = new myObj(); The VTable of a C++ object points to a table containing function pointers to the virtual functions member variables VTable Pointer C++ Object *virtual function1 *virtual function2 … Lower addresses

Overwriting C++ VTables (II) Higher addresses The scenario: The attacker is able to overflow a buffer on the heap The malicious data: The shellcode member variables VTable Pointer … member variables … buf[] Lower addresses

Overwriting C++ VTables (II) Higher addresses The scenario: The attacker is able to overflow a buffer on the heap The malicious data: The shellcode Fake VTable-entries pointing to the shellcode member variables VTable Pointer … SSSS … SSSS Lower addresses

Overwriting C++ VTables (II) Higher addresses The scenario: The attacker is able to overflow a buffer on the heap The malicious data: The shellcode Fake VTable-entries pointing to the shellcode Pointer to the fake VTable replacing the original VTable pointer member variables VTable Pointer … FFFF … FFFF SSSS … SSSS Lower addresses

Overwriting C++ VTables (II) Higher addresses The scenario: The attacker is able to overflow a buffer on the heap The malicious data: The shellcode Fake VTable-entries pointing to the shellcode Pointer to the fake VTable replacing the original VTable pointer On execution of one of the objects virtual functions the shellcode is called member variables PPPP … FFFF … FFFF SSSS … SSSS VTable Pointer Lower addresses

Manipulating control data C programs rarely store function pointers on the heap Most heap implementations store control information next to the allocated memory An attack on this control information is therefore implementation depended Example: Doug Lea malloc() (Linux) Free memory blocks are administered in doubly linked lists These lists are called “bins” Every bin links to blocks of certain sizes (8, 64, 512, 4096,…) Every allocated memory block begins with a header of control data Size of the block (SIZE) Size of the previous block (PSIZE) Status of the previous block (PStatus) Pointer to pervious block in bin (BK) Pointer to next block in bin (FD)

Manipulating control data (II) Note: BK and FD point to the previous/next block in the bin – not to the neighbors on the heap If two neighboring blocks are freed, their memory is united Block 2 … allocated memory BK | FD PSIZE | PStatus SIZE Block 1

Manipulating control data (II) Block 1 Note: BK and FD point to the previous/next block in the bin – not to the neighbors on the heap If two neighboring blocks are freed, their memory is united Block 2 is removed from its bin … allocated memory BK | FD PSIZE | PStatus SIZE

Overwriting C++ VTables (II) … FD BK … FD BK … FD BK

Overwriting C++ VTables (II) When a block is removed from its bin, the pointers of the list are modified acordingly Pseudocode: this.FD->BK = this.BK this.BK->FD = this.FD Disclaimer: This is only a sketch The internals are somewhat more complicated But the concept is valid … FD BK … FD BK … FD BK

Overwriting C++ VTables (II) When a block is removed from its bin, the pointers of the list are modified acordingly Pseudocode: this.FD->BK = this.BK this.BK->FD = this.FD Observation: this.FD represents a pointer to a place in memory that is written to this.BK is the value that is written to this place in memory The attack: If the attacker is able to control FD and BK, he is able to write arbitrary values to arbitrary locations … FD BK … FD BK

Manipulating control data (II) When a block is removed from its bin, the pointers of the list are modified acordingly Pseudocode: this.FD->BK = this.BK this.BK->FD = this.FD Observation: this.FD represents a pointer to a place in memory that is written to this.BK is the value that is written to this place in memory The attack: If the attacker is able to control FD and BK, he is able to write arbitrary values to arbitrary locations Block 2 … allocated memory BK | FD PSIZE | PStatus SIZE buf[] Block 1

C Insecurities Conclusion

Conclusion (Allmost) every illegal memory access can cause an exploitable vulnerability Buffer overflows on the stack allow the construction of robust exploit code Exploits can be targeted more loosely Ideal for automatic exploitation via worms The exploitation of heap overflows and format string vulnerabilities require more detailed knowledge of the situation If this is provided, these vulnerabilities are as serious as stack based buffer overflows Target for tailored attacks

Bibliography Michael Howard: “Fix Those Buffer Overruns!”, 2002, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure05202002.asp Michael Howard: “Reviewing Code for Integer Manipulation Vulnerabilities”, 2003, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure04102003.asp Michael Howard: “An Overlooked Construct and an Integer Overflow Redux“, 2003, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure09112003.asp Aleph One: "Smashing The Stack For Fun And Profit", Phrack 49, Volume 7, http://www.phrack.org/phrack/49/P49-14 Matt Conover: "w00w00 on Heap Overflows", http://www.w00w00.org/files/articles/heaptut.txt Rix: "Smashing C++ VPTRS", Phrack 56, Volume 11, http://www.phrack.org/phrack/56/p56-0x08 J.C. Foster, V. Osipov, N. Bhella, N. Heinen: “Buffer Overflow Attacks”, Syngress, 2005