Introduction to Information Security

Slides:



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

Recitation 4 Outline Buffer overflow –Practical skills for Lab 3 Code optimization –Strength reduction –Common sub-expression –Loop unrolling Reminders.
Smashing the Stack for Fun and Profit
Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il.
Buffer Overflow Causes. ©2002, Jedidiah R. Crandall, Susan L. Gerhart, Jan G. Hogle. Buffer Overflow Causes Author: Jedidiah.
Review: Software Security David Brumley Carnegie Mellon University.
Buffer Overflow. Process Memory Organization.
Buffer Overflows Ian Kayne For School of Computer Science, University of Birmingham 16 th February 2009.
Practical Session 8 Computer Architecture and Assembly Language.
Attacks Using Stack Buffer Overflow Boxuan Gu
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Lecture 6: Buffer Overflow CS 436/636/736 Spring 2014 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
1 #include void silly(){ char s[30]; gets(s); printf("%s\n",s); } main(){ silly(); return 0; }
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
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
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 22: Unconventional.
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)
Part II Let’s make it real Memory Layout of a Process.
Stack-based buffer overflows Yves Younan DistriNet, Department of Computer Science Katholieke Universiteit Leuven Belgium
Introduction to Information Security ROP – Recitation 5.
Where’s the FEEB?: Effectiveness of Instruction Set Randomization Nora Sovarel, David Evans, Nate Paul University of Virginia Computer Science USENIX Security.
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.
Buffer Overflow Attacks 1 Basic Idea Sample Attacks Protection , Computer & Network Security.
Introduction to InfoSec – Recitation 3 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (infosec15 at modprobe.net)
Practical Session 8. Position Independent Code- self sufficiency of combining program Position Independent Code (PIC) program has everything it needs.
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.
1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.
Exploiting & Defense Day 1 Recap
Introduction to Information Security
Shellcode COSC 480 Presentation Alison Buben.
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 Walk-Through
Return Oriented Programming
The Hardware/Software Interface CSE351 Winter 2013
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
Introduction to Information Security
Homework Reading Machine Projects Labs PAL, pp ,
Exploiting & Defense Day 2 Recap
Recitation: Attack Lab
Buffer Overflow Walk-Through
CMSC 414 Computer and Network Security Lecture 21
Summary by - Bo Zhang and Shuang Guo [Date: 03/31/2014]
Buffer Overflow.
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Assembly Language Programming II: C Compiler Calling Sequences
Lecture 9: Buffer Overflow*
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Week 2: Buffer Overflow Part 2.
Preventing Buffer Overflows (for C programmers)
Instructors: Majd Sakr and Khaled Harras
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
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
System and Cyber Security
Computer Architecture and Assembly Language
FIGURE Illustration of Stack Buffer Overflow
Format String Vulnerability
Return-to-libc Attacks
Presentation transcript:

Introduction to Information Security Stack Overflow

Buffer Overflow Low-level languages (assembly, C, C++) don't have boundary checks Careless programmers and large inputs may cause buffer to overflow This usually leads to a crash Denial of Service (DoS) But sometimes, the input can be crafted to affect the execution flow Control Hijacking s s x if (x->field > 1) ... x->method()

Stack Overflow When a function is called Its return address is pushed unto the stack It is jumped to, and allocates a stack frame When the function returns It deallocates its stack frame Its return address is popped off the stack and jumped to What if we overflow a buffer until we overflow its return address? A crash! Or maybe... 0x120 0x11C 0x118 0x114 0x110 0x10C 0x108 0x104 0x100 BUF RET ... ... BUF

Stack Overflow The buffer is at 0x108 We can write code unto the buffer And rewire the return address to jump to it 0x120 0x11C 0x118 0x114 0x110 0x10C 0x108 0x104 0x100 RET BUF ... 0x108 0xeb 0x12 0xc0 0xb0 0x5a 0x2f

The Return Address But what is the return address? When a program crashes, it creates a core dump – a snapshot of its state just before it crashed Core dumps can be opened in GDB, to view the program's memory image (among other things)

pushed unto the stack as the return address The Code But what code do we write? Raw opcodes (not an ELF file) that opens a shell – a shellcode JMP _GET_BIN_BASH _GOT_BIN_BASH: MOV EAX, 0x0B POP EBX MOV ECX, 0x00 INT 0x80 # system call: execve("/bin/sh", NULL) _GET_BIN_BASH: CALL _GOT_BIN_BASH .STRING "/bin/sh" MOV EAX, 0x0B MOV EBX, "/bin/sh" MOV ECX, 0x00 INT 0x80 # system call: execve("/bin/sh", NULL) MOV EAX, 0x0B MOV EBX, "/bin/sh" MOV ECX, 0x00 INT 0x80 # system call: execve("/bin/sh", NULL) # and popped right off # This one you solve yourself  pushed unto the stack as the return address

NOP Slides We don't have to jump precisely to our code We can land nearby and "slide" to it on NOPs 0x??? RET BUF ... 0x5a 0x2f 0x90 \xeb\r\xb8\x0b\x00\x00\x00[\xb9\x00\x00\x00\x00\xcd\x80\xe8\xee\xff\xff\xff/bin/sh\x00 \x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90 \xeb\r\xb8\x0b\x00\x00\x00[\xb9\x00\x00\x00\x00\xcd\x80\xe8\xee\xff\xff\xff/bin/sh\x00

Null Bytes Many stack overflows are caused by use of insecure standard functions like strcpy or strcat These functions copy until a null byte ('\x00') is reached On one hand – the input size is not checked! Today, more secure functions like strncpy and strncat are used instead On the other hand – the shellcode can't contain null bytes What can we do with MOV ECX, 0? XOR ECX, ECX What can we do with .STRING "/bin/bash"? .ASCII "/bin/bash#" Load it, and then fix it b9 00 00 00 00 31 c9 2f 62 69 6e 2f 62 61 73 68 00 2f 62 69 6e 2f 62 61 73 68 23

Related Vulnerabilities Addendum Related Vulnerabilities

Format String Vulnerabilities Another way to find out the stack address printf("%s", input) is OK printf(input) is not What if input is "%d"?

Integer Overflow Checking the input size should do it, right? Not unless the programmers keep being careless If int x = 10, then x > 5 is false If int x = 4294967295, is x > 5 still false?

Heap Spray Overflows can happen on the heap as well as the stack "Use after free" vulnerability More common than you think, especially in complex, multi-threaded code The attacker allocates lots of "mines" (that is – sprays the heap with them) When the freed object is used, it may trigger a mine Can be used to hijack control Can be used to escape a sandbox