Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.

Slides:



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

Smashing the Stack for Fun and Profit
INSTRUCTION SET ARCHITECTURES
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Buffer Overflows By Tim Peterson Joel Miller Dan Block.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
Buffer Overflow By: John Quach and Napoleon N. Valdez.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Windows XP SP2 Stack Protection Jimmy Hermansson Johan Tibell.
Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Maziéres, Dan Boneh
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.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2012.
Software bugs (and security implications). Software security Code can have perfect design and algorithm, but still have implementation vulnerabilities.
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.
Assembly, Stacks, and Registers Kevin C. Su 9/26/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.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
Brian E. Brzezicki. This tutorial just illustrates the underlying concepts of buffer overflows by way of an extremely simple stack overflow  Most buffer.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
CSCD 303 Essential Computer Security Spring 2013 Lecture 17 Buffer Overflow Attacks.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Smashing the Stack Overview The Stack Region Buffer Overflow
Buffer Overflows This presentation is an amalgam of presentations by Mark Michael, Randy Marchany and Ed Skoudis. I have edited and added material. Dr.
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
Buffer Overflow Group 7Group 8 Nathaniel CrowellDerek Edwards Punna ChalasaniAxel Abellard Steven Studniarz.
Section 3.4: Buffer Overflow Attack: Attack Techniques 1.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Part I The Basic Idea software sequence of instructions in memory logically divided in functions that call each other – function ‘IE’ calls function.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2015.
JMU GenCyber Boot Camp Summer, Introduction to Penetration Testing Elevating privileges – Getting code run in a privileged context Exploiting misconfigurations.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
Reminder Bomb lab is due tomorrow! Attack lab is released tomorrow!!
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
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.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
Analyzing C/C++ Vulnerabilities -- Mike Gerschefske.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2010.
Overflows Mark Shtern.
Refs: rootshell, antionline, your favorite hacker site…
Instructions for test_function
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?
© Craig Zilles (adapted from slides by Howard Huang)
CSC 495/583 Topics of Software Security Stack Overflows (2)
Recitation: Attack Lab
CNT4704: Computer Networking Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2009.
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Active Worms, Buffer Overflow Attacks and BGP Attacks
Smashing the Stack for Fun and Profit
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou University of Central Florida.
CNT4704: Analysis of Computer Communication Network Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2011.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
© Craig Zilles (adapted from slides by Howard Huang)
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
Several Tips on Project 1
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2010.
Presentation transcript:

Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt

Netprog: Buffer Overflow2 Serious Stuff Try a web search for “buffer overflow exploit” “Smashing the Stack for Fun and Profit” Check alt.2600, rootshell.com, antionline.com – you can find long lists of exploits based on buffer overflow. Even the original version of ssh had a problem! (after they made a big deal that there were no buffer overflow problems in their code).

Netprog: Buffer Overflow3 The Problem void foo(char *s) { char buf[10]; strcpy(buf,s); printf(“buf is %s\n”,s); } … foo(“thisstringistoolongforfoo”);

Netprog: Buffer Overflow4 Exploitation The general idea is to give servers very large strings that will overflow a buffer. For a server with sloppy code – it’s easy to crash the server by overflowing a buffer (SEGV typically). It’s sometimes possible to actually make the server do whatever you want (instead of crashing).

Netprog: Buffer Overflow5 Background Necessary C functions and the stack. A little knowledge of assembly/machine language. How system calls are made (at the machine code level). exec() system calls How to “guess” some key parameters.

Netprog: Buffer Overflow6 CPU/OS dependency Building an exploit requires knowledge of the specific CPU and operating system of the target. I’ll just talk about x86 and Linux, but the methods work for other CPUs and OSs. Some details are very different, but the concepts are the same.

Netprog: Buffer Overflow7 C Call Stack When a function call is made, the return address is put on the stack. Often the values of parameters are put on the stack. Usually the function saves the stack frame pointer (on the stack). Local variables are on the stack.

Netprog: Buffer Overflow8 Stack Direction On Linux (x86) the stack grows from high addresses to low. Pushing something on the stack moves the Top Of Stack towards the address 0.

Netprog: Buffer Overflow9 A Stack Frame Parameters Return Address Calling Stack Pointer Local Variables Addresses SP SP+offset low high

Netprog: Buffer Overflow10 Sample Stack 18 addressof(y=3) return address saved stack pointer y x buf x=2; foo(18); y=3; void foo(int j) { int x,y; char buf[100]; x=j; … }

Netprog: Buffer Overflow11 “Smashing the Stack”* The general idea is to overflow a buffer so that it overwrites the return address. When the function is done it will jump to whatever address is on the stack. We put some code in the buffer and set the return address to point to it! *taken from the title of an article in Phrack 49-7

Netprog: Buffer Overflow12 Before and After void foo(char *s) { char buf[100]; strcpy(buf,s); … address of s return-address saved sp buf address of s pointer to pgm Small Program

Netprog: Buffer Overflow13 Issues How do we know what value the pointer should have (the new “return address”). –It’s the address of the buffer, but how do we know what address this is? How do we build the “small program” and put it in a string?

Netprog: Buffer Overflow14 Guessing Addresses Typically you need the source code so you can estimate the address of both the buffer and the return-address. An estimate is often good enough! (more on this in a bit).

Netprog: Buffer Overflow15 Building the small program Typically, the small program stuffed in to the buffer does an exec(). Sometimes it changes the password db or other files…

Netprog: Buffer Overflow16 exec() example #include char *args[] = {"/bin/ls", NULL}; void execls(void) { execv("/bin/ls",args); printf(“I’m not printed\n"); }

Netprog: Buffer Overflow17 Generating a String You can take code like the previous slide, and generate machine language. Copy down the individual byte values and build a string. To do a simple exec requires less than 100 bytes.

Netprog: Buffer Overflow18 A Sample Program/String Does an exec() of /bin/ls: unsigned char cde[] = "\xeb\x1f\x5e\x89\x76\x08\x31\xc0” “\x88\x46\x07\x89\x46\x0c\xb0\x0b" "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c” “\xcd\x80\x31\xdb\x89\xd8\x40\xcd" "\x80\xe8\xdc\xff\xff\xff/bin/ls";

Netprog: Buffer Overflow19 Some important issues The small program should be position- independent – able to run at any memory location. It can’t be too large, or we can’t fit the program and the new return-address on the stack!

Netprog: Buffer Overflow20 Sample Overflow Program (see other slides on pages 3-5…)

Netprog: Buffer Overflow21 Attacking a real program Recall that the idea is to feed a server a string that is too big for a buffer. This string overflows the buffer and overwrites the return address on the stack. Assuming we put our small program in the string, we need to know it’s address.

Netprog: Buffer Overflow22 NOPs Most CPUs have a No-Operation instruction – it does nothing but advance the instruction pointer. Usually we can put a bunch of these ahead of our program (in the string). As long as the new return-address points to a NOP we are OK.

Netprog: Buffer Overflow23 Using NOPs Real program (exec /bin/ls or whatever) new return address nop instructions Can point anywhere in here

Netprog: Buffer Overflow24 Estimating the stack size We can also guess at the location of the return address relative to the overflowed buffer. Put in a bunch of new return addresses!

Netprog: Buffer Overflow25 Estimating the Location Real program new return address nop instructions new return address

Netprog: Buffer Overflow26 Other Potential Problems Buffer overflow is just the most common programming problem exploited. Integer arithmetic can also be a problem! –foo = malloc(num * sizeof(struct blah)); –what if num is 2^32-1? what if num is -1?

Netprog: Buffer Overflow27 Summary Don't use strcpy. Check the return value on all calls to library functions like malloc (as well as all system calls). Don't use multiplication (or addition). Might as well not use subtraction or division either. It's probably best to avoid writing programs at all…