Advanced Computer Networks Smashing the Stack for Fun and Profit

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

Buffer Overflow & Format Strings

Buffer Overflows Defending against arbitrary code insertion and execution

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

Writing Exploits. Nethemba s.r.o.

Beyond Stack Smashing: Recent Advances in Exploiting. Jonathan Pincus(MSR) and Brandon Baker (MS)

Memory Corruption 101 From Primitives to Exploit

String Oriented Programming Exploring Format String Attacks. Mathias Payer

CSE 565 Computer Security Fall 2018

Reserve Engineering & Buffer Overflow Attacks. Tom Chothia Computer Security, Lecture 17

malloc() is often used to allocate chunk of memory dynamically from the heap region. Each chunk contains a header and free space (the buffer in which

Assembly Language: Function Calls

Assembly Language: Function Calls" Goals of this Lecture"

Function Call Convention

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

Lecture 6: Buffer Overflow. CS 436/636/736 Spring Nitesh Saxena

Assembly Language: Function Calls" Goals of this Lecture"

Buffer Overflows. A brief Introduction to the detection and prevention of buffer overflows for intermediate programmers.

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

CMPSC 497 Buffer Overflow Vulnerabilities

Lecture 08 Control-flow Hijacking Defenses

Buffer Overflow Attacks

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

Lecture 4 September Required reading materials for this class

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

CS 645: Lecture 3 Software Vulnerabilities. Rachel Greenstadt July 3, 2013

Exercise 6: Buffer Overflow and return-into-libc Attacks

Software Security: Buffer Overflow Attacks (continued)

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

CSC 2400: Computing Systems. X86 Assembly: Function Calls

Architecture-level Security Vulnerabilities

Offensive Security My First Buffer Overflow: Tutorial

Buffer overflow background

Buffer-Overflow Attacks on the Stack

HW 8 CS681 & CS392 Computer Security Understanding and Experimenting with Memory Corruption Vulnerabilities DUE 12/18/2005

CS 392/681 Lab 6 Experiencing Buffer Overflows and Format String Vulnerabilities

18-600: Recitation #4 Exploits

Betriebssysteme und Sicherheit Sicherheit. Buffer Overflows

ROP It Like It s Hot!

Secure Programming Lecture 3: Memory Corruption I (Stack Overflows)

Basic Buffer Overflows

Software Security: Buffer Overflow Defenses

Stack Vulnerabilities. CS4379/5375 System Security Assurance Dr. Jaime C. Acosta

CMSC 414 Computer and Network Security

Buffer Overflow Vulnerability

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

Lab 2: Buffer Overflows

CSE 127 Computer Security

Buffer overflow prevention, and other attacks

CSE 127 Computer Security

20: Exploits and Containment

Security Workshop HTS. LSE Team. February 3rd, 2016 EPITA / 40

Buffer overflow is still one of the most common vulnerabilities being discovered and exploited in commodity software.

CSc 466/566. Computer Security. 20 : Operating Systems Application Security

Is stack overflow still a problem?

Biography. Background

Topics. What is a Buffer Overflow? Buffer Overflows

Architecture-level Security Vulnerabilities. Julian Stecklina

Buffer Overflow and Protection Technology. Department of Computer Science,

Exploiting Stack Buffer Overflows Learning how blackhats smash the stack for fun and profit so we can prevent it

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

Security and Privacy in Computer Systems. Lecture 5: Application Program Security

PRESENTED BY: SANTOSH SANGUMANI & SHARAN NARANG

Lecture 04 Control Flow II. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Based on Michael Bailey s ECE 422

CS 161 Computer Security

Roadmap: Security in the software lifecycle. Memory corruption vulnerabilities

INTRODUCTION TO EXPLOIT DEVELOPMENT

CSE 127 Computer Security

Outline. Memory Exploit

Buffer Overflow Vulnerability Lab Due: September 06, 2018, Thursday (Noon) Submit your lab report through to

Stack-Based Buffer Overflow Explained. Marc Koser. East Carolina University. ICTN 4040: Enterprise Information Security

CSC 438 Systems and Software Security, Spring 2014 Instructor: Dr. Natarajan Meghanathan Question Bank for Module 6: Software Security Attacks

Buffer Overflow Attacks

Advanced Buffer Overflow

Buffer Overflow Attack (AskCypert CLaaS)

Smashing the Buffer. Miroslav Štampar

ISA 564, Laboratory I: Buffer Overflows

Native Language Exploitation

Heap Off by 1 Overflow Illustrated. Eric Conrad October 2007

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING

Systems I. Machine-Level Programming V: Procedures

CSE Lecture In Class Example Handout

CS4264 Programming Assignment 1 Buffer Overflow Vulnerability Due 02/21/2018 at 5:00 PM EST Submit through CANVAS

Robust Shell Code Return Oriented Programming and HeapSpray. Zhiqiang Lin

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

Vulnerabilities in C/C++ programs Part I

Lecture Embedded System Security A. R. Darmstadt, Runtime Attacks

Buffer Overflow Vulnerability Lab

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015

From Over ow to Shell

Sample slides and handout

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

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

1 Recommended Readings

Lecture 09 Code reuse attacks. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017

(Early) Memory Corruption Attacks

Countermeasures in Modern Operating Systems. Yves Younan, Vulnerability Research Team (VRT)

Program Security and Vulnerabilities Class 2

CS 161 Computer Security

CSE 127: Computer Security. Memory Integrity. Kirill Levchenko

Transcription:

Smashing the Stack for Fun and Profit 1

appeared in: Phrack 49 Volume Seven, Issue Forty-Nine by: Aleph One (Elias Levy) Where the title comes from 2

The stack Buffer Overflows Shellcode Be aware of the inaccuracy Examples Outline 3

Function parameters Prolog Stackframe (local variables) Epilog The Stack 4

Function parameters Prolog Stackframe CALL P (local variables) P: ENTER size, 0 LEAVE RET n Epilog The Stack 5

Prolog (1) (2) ESP ESP Return Addr Return Addr Dyn. Link size (1) (2) CALL P ENTER size, 0 ESP Push( EIP ) EIP = Addr( P ) Push( ) = ESP ESP = ESP -size The Stack 6

Epilog (1) (2) Return Addr Dyn. Link ESP Return Addr ESP ESP LEAVE RET n ESP = POP( ) POP( EIP ) ESP = ESP +n The Stack 7

' x Param2 (int 9) Param1 (int 6) Return Address -00-04 -08-0C int main( void ) { } int x; x = foo( 6, 9 ); printf( The answer is: %d\n, x ); return 0; Dynamic Link -10 int foo( int a, int b ) { bar [4.. ] bar [0..3] c -00-04 -08 char bar[5]; int c = a * b; itoa( c, bar, 13 ); return atoi( bar ); } The Stack today this is not always true 8

' x Param2 (int 9) Param1 (int 6) Return Address -00-04 -08-0C int main( void ) { } int x; x = foo( 6, 9 ); printf( The answer is: %d\n, x ); return 0; Dynamic Link -10 int foo( int a, int b ) { c bar [1..4] bar [0] -00-04 -08 char bar[5]; int c = a * b; itoa( c, bar, 13 ); return atoi( bar ); } The Stack 9

int main( void ) { ' x Return Address -00-04 int x = 0; foo( ); if (x) { printf( Unreachable code\n ); } return 0; Dynamic Link *ret bar [0..3] -08-00 -04-08 } void foo( void ) { char bar[4]; int *ret= bar +12; (*ret) += 6; } The Stack Changing the return address 10

A buffer overflow is an anomalous condition where a process attempts to store data beyond the boundaries of a fixed-length buffer. The result is that the extra data overwrites adjacent memory locations. The overwritten data may include other buffers, variables and program flow data. Wikipedia, April 2007 Return Address Dynamic Link bar [0..3] -00-04 -08 Buffer Overflows 11

A shellcode is a relocatable piece of machine code used as the payload in the exploitation of a software bug which typically allows an unauthorised user to communicate with the computer via the operating system's command line as a result of exploiting a vulnerability in software running on the machine. Normally stored as a null terminated string, it usually cannot contain null characters. Wikipedia, April 2007 int main( void ) { } char *callee = "/bin/bash", *parameters = NULL; execve( callee, parameters, NULL ); exit( 0 ); Shellcode 12

Return Address ' prev. Dynamic Link bar [4..7] bar [0..3] -00-04 -08 Position of the buffer Absolute Relative to the ret addr. Position of the callee string Amount of memory 0-terminating char arrays Things to take into account 13

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 00 01 02 0 3 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F JJ JJ SC SC SC SC SC SC SC SC SC SC SC SC SC SC 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F SC CC CC 2F 62 69 6E 2F 62 61 73 68???????? / b i n / b a s h Things to take into account 14

References [Levy, 1996] E. Levy. (1996) Smashing the stack for fun and profit, Phrack Magazine 7(49): file 0x0D [Heffner, 2007] C. J. Heffner. (2007) Smashing the modern stack for fun and profit, URL: http://www.craigheffner.com/security/stacksmash.html [Mössenböck, 2006] HP. Mössenböck. (2006) Fortgeschrittene Techniken des Übersetzerbaues, Course Notes, Institut für Systemsoftware, JKU, Linz [Wikipedia, 2007a] Wikimedia Foundation Inc. (2007) Buffer Overflow, Wikipedia, April 2007, URL: http://en.wikipedia.org/wiki/buffer_overflow [Wikipedia, 2007b] Wikimedia Foundation Inc. (2007) Shellcode, Wikipedia, April 2007, URL: http://en.wikipedia.org/wiki/shellcode References 15

(1) Give the structure of a buffer overflow cf. slide 14 (2) Explain the JMP/CALL technique cf. [Levy, 1996] line 652-677 Exam questions 16