CMSC 414 Computer and Network Security Lecture 21

Slides:



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

Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il.
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.
CMSC 414 Computer and Network Security Lecture 22 Jonathan Katz.
Review: Software Security David Brumley Carnegie Mellon University.
Breno de MedeirosFlorida State University Fall 2005 Buffer overflow and stack smashing attacks Principles of application software security.
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.
CMSC 414 Computer and Network Security Lecture 23 Jonathan Katz.
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
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.
Teaching Buffer Overflow Ken Williams NC A&T State University.
CMSC 414 Computer and Network Security Lecture 18 Jonathan Katz.
Lecture 16 Buffer Overflow
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
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.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
Mitigation of Buffer Overflow Attacks
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
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 Group 7Group 8 Nathaniel CrowellDerek Edwards Punna ChalasaniAxel Abellard Steven Studniarz.
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.
Lecture 13 Page 1 CS 236 Online Major Problem Areas for Secure Programming Certain areas of programming have proven to be particularly prone to problems.
Buffer overflow and stack smashing attacks Principles of application software 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.
Security Attacks Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Analyzing C/C++ Vulnerabilities -- Mike Gerschefske.
CMSC 414 Computer and Network Security Lecture 17 Jonathan Katz.
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.
Introduction to Information Security
Secure Programming Dr. X
Shellcode COSC 480 Presentation Alison Buben.
Major Problem Areas for Secure Programming
Buffer Overflow By Collin Donaldson.
Mitigation against Buffer Overflow Attacks
Return Oriented Programming
Protecting Memory What is there to protect in memory?
Introduction to Information Security
Protecting Memory What is there to protect in memory?
Secure Programming Dr. X
Module 30 (Unix/Linux Security Issues II)
Protecting Memory What is there to protect in memory?
Introduction to Information Security
CSC 495/583 Topics of Software Security Stack Overflows (2)
Recitation: Attack Lab
Summary by - Bo Zhang and Shuang Guo [Date: 03/31/2014]
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Software Security Lesson Introduction
Format String.
Lecture 9: Buffer Overflow*
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.
Week 2: Buffer Overflow Part 2.
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.
Several Tips on Project 1
Format String Vulnerability
Return-to-libc Attacks
Presentation transcript:

CMSC 414 Computer and Network Security Lecture 21 Jonathan Katz

Examples using gdb

Even more devious… overflow buf EBP EIP Frame of the calling function In the overflow, a pointer back into the buffer appears in the location where the system expects to find return address Attacker puts actual assembly instructions into his input string, e.g., binary code of execve(“/bin/sh”)

NOP sled If exact address of injected shellcode is unknown, use NOP sled to provide a margin of error

Severity of attack? Theoretically, attacker can cause machine to execute arbitrary code with the permissions of the program itself

Heap overflows The examples just described all involved overflowing the stack Also possible to overflow buffers on the heap More difficult to get arbitrary code to execute, but imagine the effects of overwriting Passwords Usernames Filenames Variables Function pointers (possible to execute arbitrary code)

Defenses

Defenses (overview) Prevent overflows from existing Safe programming techniques/languages Input validation Static/dynamic analysis Prevent overflows from being exploited Intercept function calls (e.g., Libsafe) Canaries (StackGuard) Non-executable stack, data execution prevention (DEP) Address space layout randomization/ASLR Development/ compile time compile time O/S

Safe programming techniques Use arrays instead of pointers Make buffers (slightly) longer than necessary to avoid “off-by-one” errors

Safe programming techniques We have seen that strcpy is unsafe strcpy(buf, str) simply copies memory contents into buf starting from *str until “\0” is encountered, ignoring the size of buf Avoid strcpy(), strcat(), gets(), etc. Use strncpy(), strncat(), instead Even these are not perfect… (e.g., no null termination) Still need to be careful when copying multiple inputs into a buffer

Safe programming languages E.g., using Java prevents many of the problems that arise when using C C variants have been developed that ensure that certain classes of overflows cannot occur E.g., Cyclone

Input validation (This is a general issue, not just in the context of buffer overflows) Two approaches Whitelisting Allow input that matches up with approved whitelist Blacklisting Discard input that matches up with disallowed blacklist The usual tradeoffs between usability/complexity and security

Length checking Beware off-by-one errors Even when using strncpy, the programmer must use the right value for the number of bytes to copy … strncpy(record,user,MAX_STRING_LEN-1); strcat(record,”:”); strncat(record,fname,MAX_STRING_LEN-1);

Input validation Blacklisting can often be easily circumvented E.g., checking for a NOP sled Replace NOP with a sequence of instructions whose net effect is to do nothing (inc eax, dec eax, …) Whitelisting can be more difficult to bypass E.g., checking for printable ASCII There are legal instructions that fall in this range!

ASCII printable instructions (Partial list) AND EAX SUB EAX PUSH EAX POP EAX PUSH ESP POP ESP

What can be done? AND EAX val1, AND EAX val2 If val1, val2 are ASCII-printable strings that are complements of each other, this zeros EAX SUB EAX v1, SUB EAX v2, SUB EAX v3 If v1, v2, v3 ASCII-printable strings chosen appropriately, wrap around occurs and the net effect is an addition PUSH EAX, POP ESP Copies EAX into ESP

What can be done? In principle, could build exploit using these instructions (very hard) Alternative: inject loader code that generates shellcode on the stack

EIP loader code increasing addresses ESP stack Build shellcode on the stack. What happens when the EIP and ESP meet?