Buffer Overflows. Buffer Overflow. Many of the following slides are based on those from

Similar documents
Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics.

Buffer Overflow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

BUFFER OVERFLOW. Jo, Heeseung

Buffer Overflow. Jo, Heeseung

Introduction to Computer Systems , fall th Lecture, Sep. 28 th

Machine-Level Programming V: Miscellaneous Topics Sept. 24, 2002

Giving credit where credit is due

Machine-Level Prog. V Miscellaneous Topics

Linux Memory Layout The course that gives CMU its Zip! Machine-Level Programming IV: Miscellaneous Topics Sept. 24, Text & Stack Example

Sungkyunkwan University

Machine-Level Programming IV: Structured Data

Computer Systems CEN591(502) Fall 2011

Machine- Level Programming V: Advanced Topics

Buffer overflows (a security interlude) Address space layout the stack discipline + C's lack of bounds-checking HUGE PROBLEM


Machine Programming 5: Buffer Overruns and Stack Exploits

Buffer Overflow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Buffer overflows. Specific topics:

Buffer Overflow. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Machine-Level Prog. V Miscellaneous Topics

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Buffer overflow

CSC 252: Computer Organization Spring 2018: Lecture 9

CS , Fall 2001 Exam 1

Assembly Language: Function Calls

Assembly Language: Function Calls" Goals of this Lecture"

CS , Fall 2002 Exam 1

Buffer-Overflow Attacks on the Stack

Assembly Language: Function Calls" Goals of this Lecture"

CS241 Computer Organization Spring Buffer Overflow

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Buffer-Overflow Attacks on the Stack

Full Name: CISC 360, Fall 2008 Example of Exam

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

Buffer Overflow Attacks

Summary. Alexandre David

THEORY OF COMPILATION

Machine- Level Programming V: Advanced Topics

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux

X86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson

Machine-Level Programming V: Advanced Topics

Why do we need Pointers? Call by Value vs. Call by Reference in detail Implementing Arrays Buffer Overflow / The Stack Hack

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Betriebssysteme und Sicherheit Sicherheit. Buffer Overflows

CMPSC 497 Buffer Overflow Vulnerabilities

CS 161 Computer Security. Week of January 22, 2018: GDB and x86 assembly

Assembly Language Programming - III

Machine-level Programs Adv. Topics

ANITA S SUPER AWESOME RECITATION SLIDES

Buffer Overflow Attack

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

2 Sadeghi, Davi TU Darmstadt 2012 Secure, Trusted, and Trustworthy Computing Chapter 6: Runtime Attacks

CS642: Computer Security

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

Format string vulnerabilities

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

X86 Assembly Buffer Overflow III:1

Buffer Overflows. CSE 351 Autumn Instructor: Justin Hsia

Instruction Set Architecture

Buffer Overflows. CSE 410 Winter Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui

CS , Fall 2004 Exam 1

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

18-600: Recitation #4 Exploits

Instruction Set Architecture

Machine Programming 1: Introduction

Instruction Set Architecture

Buffer Overflows. CSE 351 Autumn 2018

CPS104 Recitation: Assembly Programming

Process Layout, Function Calls, and the Heap

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

Lecture 9: Buffer Overflow* CS 392/6813: Computer Security Fall Nitesh Saxena

Topics in Software Security Vulnerability

4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only

CPEG421/621 Tutorial

CS 3214 Spring # Problem Points Min Max Average Median SD Grader. 1 Memory Layout and Locality Bill

18-600: Recitation #4 Exploits (Attack Lab)

Buffer. This time. Security. overflows. Software. By investigating. We will begin. our 1st section: History. Memory layouts

CISC 360 Instruction Set Architecture

CIS 551 / TCOM 401 Computer and Network Security. Spring 2007 Lecture 2

CMSC 313 Lecture 12 [draft] How C functions pass parameters

Instruction Set Architecture

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

Blossom Hands-on exercises for computer forensics and security. Buffer Overflow

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING

CS61 Section Solutions 3

This time. Defenses and other memory safety vulnerabilities. Everything you ve always wanted to know about gdb but were too afraid to ask

Machine-Level Programming I: Introduction Jan. 30, 2001

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

Machine-Level Programming V: Advanced Topics

Intel assembly language using gcc

Lab 10: Introduction to x86 Assembly

Project 1 Notes and Demo

Project 1 Buffer Overflow

Transcription:

s Many of the following slides are based on those from 1 Complete Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective (CS:APP) Randal E. Bryant and David R. O'Hallaron http://csapp.cs.cmu.edu/public/lectures.html The book is used explicitly in CS 2505 and CS 3214 and as a reference in CS 2506.

s What is a buffer overflow? How can it be exploited? How can it be avoided? Through programmer measures Through system measures (and how effective are they?) 2

String Library Code Implementation of Unix function gets No way to specify limit on number of characters to read 3 /* Get string from stdin */ char *gets(char *dest) { int c = getc(); char *p = dest; while (c!= EOF && c!= '\n') { *p++ = c; c = getc(); *p = '\0'; return dest;

Vulnerable Buffer Code int main() { printf("type a string:"); echo(); return 0; 4 /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ gets(buf); puts(buf);

Executions 5 unix>./bufdemo Type a string:123 123 unix>./bufdemo Type a string:12345 Segmentation Fault unix>./bufdemo Type a string:12345678 Segmentation Fault

6 Return Address Saved %ebp [3] [2] [1] [0] buf %ebp /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ gets(buf); puts(buf); echo: pushl %ebp # Save %ebp on stack movl %esp,%ebp subl $20,%esp # Allocate space on stack pushl %ebx # Save %ebx addl $-12,%esp # Allocate space on stack leal -4(%ebp),%ebx # Compute buf as %ebp-4 pushl %ebx # Push buf on stack call gets # Call gets...

Example unix> gdb bufdemo 7 (gdb) break echo Breakpoint 1 at 0x8048583 (gdb) run Breakpoint 1, 0x8048583 in echo () (gdb) print /x *(unsigned *)$ebp $1 = 0xbffff8f8 (gdb) print /x *((unsigned *)$ebp + 1) $3 = 0x804864d Before call to gets Return Address Saved %ebp [3] [2] [1] [0] buf %ebp Return 08 04 Address 86 4d Saved bf ff %ebp f8 f8 0xbffff8d8 [3] xx [2] xx [1] xx [0] xx buf 8048648: call 804857c <echo> 804864d: mov 0xffffffe8(%ebp),%ebx # Return Point

Example #1 8 Before Call to gets Input = 123 Return Address Saved %ebp [3] [2] [1] [0] buf %ebp Return 08 04 Address 86 4d Saved bf ff %ebp f8 f8 0xbffff8d8 [3] 00 [2] 33 [1] 32 [0] 31 buf No Problem

Example #2 9 Input = 12345 Return Address Saved %ebp [3] [2] [1] [0] buf echo code: %ebp Return 08 04 Address 86 4d Saved bf ff %ebp 00 35 0xbffff8d8 [3] 34 [2] 33 [1] 32 [0] 31 buf Saved value of %ebp set to 0xbfff0035 Bad news when later attempt to 8048592: push %ebx 8048593: call 80483e4 <_init+0x50> # gets 8048598: mov 0xffffffe8(%ebp),%ebx 804859b: mov %ebp,%esp restore %ebp 804859d: pop %ebp # %ebp gets set to invalid value 804859e: ret

Example #3 10 Input = 12345678 Return Address Saved %ebp [3] [2] [1] [0] buf %ebp Return 08 04 Address 86 00 Saved 38 37 %ebp 36 35 0xbffff8d8 [3] 34 [2] 33 [1] 32 [0] 31 buf Invalid address No longer pointing to desired return point 8048648: call 804857c <echo> 804864d: mov 0xffffffe8(%ebp),%ebx # Return Point %ebp and return address corrupted

Malicious Use of 11 return address tof void foo(){ bar();... right after call to bar() void bar() { char buf[64];... tof foo stack frame buf[] bar stack frame B = &buf[0]

Malicious Use of 12 void foo(){ bar();... void bar() { return char buf[64]; address gets(buf); tob... right after call to gets() buf[] tof foo bar tob dest gets gets()can now write whatever it wants, beginning at buf[0]

Malicious Use of 13 void foo(){ bar();... void bar() { return char buf[64]; address gets(buf); tob... right before return from gets() And new pointer that overwrites return address with address of buffer And padding (which overwrites rest of bar() s frame Input string to gets() contains byte representation of executable code buf[] tof tob foo bar dest gets

Malicious Use of 14 void foo(){ bar();... right after return to bar() from gets() void bar() { char buf[64]; gets(buf);... to buf[] padding foo buf[] code bar When bar() executes ret, will jump to exploit code

Avoiding Overflow Vulnerability 15 /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ fgets(buf, 4, stdin); puts(buf); Use Library Routines that check/limit string lengths fgets instead of gets strncpy/strlcpy instead of strcpy snprintf instead of sprintf Don t use scanf with %s conversion specification Use fgets to read the string http://lwn.net/articles/507319/