CNT4704: Analysis of Computer Communication Network Special Topic: Buffer Overflow II: Defense Techniques Cliff Zou Fall 2011.

Slides:



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

Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
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.
Lecture 16 Buffer Overflow modified from slides of Lawrie Brown.
CMSC 414 Computer and Network Security Lecture 22 Jonathan Katz.
K. Salah1 Buffer Overflow The crown jewel of attacks.
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.
Preventing Buffer Overflow Attacks. Some unsafe C lib functions strcpy (char *dest, const char *src) strcat (char *dest, const char *src) gets (char *s)
1 RISE: Randomization Techniques for Software Security Dawn Song CMU Joint work with Monica Chew (UC Berkeley)
Lecture 16 Buffer Overflow
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2012.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2013.
Address Obfuscation: An Efficient Approach to Combat a Broad Range of Memory Error Exploits Sandeep Bhatkar, Daniel C. DuVarney, and R. Sekar Stony Brook.
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-
Chapter 6 Buffer Overflow. Buffer Overflow occurs when the program overwrites data outside the bounds of allocated memory It was one of the first exploited.
Natalia Yastrebova What is Coverity? Each developer should answer to some very simple, yet difficult to answer questions: How do I find new.
Computer Security and Penetration Testing
Mitigation of Buffer Overflow Attacks
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 10 “Buffer Overflow”.
Overflow Examples 01/13/2012. ACKNOWLEDGEMENTS These slides where compiled from the Malware and Software Vulnerabilities class taught by Dr Cliff Zou.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
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.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
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.
Group 9. Exploiting Software The exploitation of software is one of the main ways that a users computer can be broken into. It involves exploiting the.
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.
Beyond Stack Smashing: Recent Advances In Exploiting Buffer Overruns Jonathan Pincus and Brandon Baker Microsoft Researchers IEEE Security and.
Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade Crispin Cowan SANS 2000.
Chapter 10 Buffer Overflow 1. A very common attack mechanism o First used by the Morris Worm in 1988 Still of major concern o Legacy of buggy code in.
1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
Content Coverity Static Analysis Use cases of Coverity Examples
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
Buffer Overflow Buffer overflows are possible because C doesn’t check array boundaries Buffer overflows are dangerous because buffers for user input are.
Sabrina Wilkes-Morris CSCE 548 Student Presentation
Software Security Buffer Overflows more countermeasures
CMSC 345 Defensive Programming Practices from Software Engineering 6th Edition by Ian Sommerville.
Buffer Overflow Defenses
The Hardware/Software Interface CSE351 Winter 2013
Protecting Memory What is there to protect in memory?
Secure Programming Dr. X
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2016.
Secure Software Development: Theory and Practice
CMSC 414 Computer and Network Security Lecture 21
Software Security.
High Coverage Detection of Input-Related Security Faults
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Preventing Buffer Overflow Attacks
Software Security Lesson Introduction
Format String.
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
CSC 495/583 Topics of Software Security StackGuard & Format String Bug
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2011.
Buffer Overflow Defenses
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow II: Defense Techniques Cliff Zou Spring 2009.
Understanding and Preventing Buffer Overflow Attacks in Unix
Format String Vulnerability
Return-to-libc Attacks
CSCD 303 Essential Computer Security Spring 2013
Presentation transcript:

CNT4704: Analysis of Computer Communication Network Special Topic: Buffer Overflow II: Defense Techniques Cliff Zou Fall 2011

Acknowledgement This lecture uses some contents from: Dr. Erik Poll : software security Dr. Dawn Song: CS161: computer security Buffer Overflow Prevention Buffer Overflow Dr. Ninghui Li: CS426: Computer Security

Countermeasures We can take countermeasures at different points in time before we even begin programming during development when testing when executing code to prevent, to detect – at (pre)compile time or at runtime -, and to migitate problems with buffer overflows

Preventing Buffer Overflow Attacks Non-executable stack Static source code analysis. Run time checking: StackGuard, Libsafe, SafeC, (Purify). Randomization. Type safe languages (Java, ML). Detection deviation of program behavior Sandboxing Access control …

Prevention Don’t use C or C++ (use type-safe language) Legacy code Practical? Better programmer awareness & training Building Secure Software, J. Viega & G. McGraw, 2002 Writing Secure Code, M. Howard & D. LeBlanc, 2002 19 deadly sins of software security, M. Howard, D LeBlanc & J. Viega, 2005 Secure programming for Linux and UNIX HOWTO, D. Wheeler, www.dwheeler.com/secure-programs Secure C coding, T. Sirainen www.irccrew.org/~cras/security/c-guide.html

Dangerous C system calls source: Building secure software, J. Viega & G. McGraw, 2002

Secure Coding Avoid risky programming constructs Use fgets instead of gets Use strn* APIs instead of str* APIs Use snprintf instead of sprintf and vsprintf scanf & printf: use format strings Never assume anything about inputs Negative value, big value Very long strings

Prevention – use better string libraries there is a choice between using statically vs dynamically allocated buffers static approach easy to get wrong, and chopping user input may still have unwanted effects dynamic approach susceptible to out-of-memory errors, and need for failing safely

Better string libraries libsafe.h provides safer, modified versions of eg strcpy strlcpy(dst,src,size) and strlcat(dst,src,size) with size the size of dst, not the maximum length copied. Used in OpenBSD glib.h provides Gstring type for dynamically growing null-terminated strings in C but failure to allocate will result in crash that cannot be intercepted, which may not be acceptable Strsafe.h by Microsoft guarantees null-termination and always takes destination size as argument C++ string class data() and c-str()return low level C strings, ie char*, with result of data()is not always null-terminated on all platforms...

Dynamic countermeasures Protection by kernel Non-executable stack memory (NOEXEC) prevents attacker executing her code Address space layout randomisation (ASLR) generally makes attacker's life harder E.g., harder to get return address place and injected code address Protection inserted by the compiler to prevent or detect malicious changes to the stack Neither prevents against heap overflows

Bugs to Detect in Source Code Analysis Some examples Crash Causing Defects Null pointer dereference Use after free Double free Array indexing errors Mismatched array new/delete Potential stack overrun Potential heap overrun Return pointers to local variables Logically inconsistent code Uninitialized variables Invalid use of negative values Passing large parameters by value Underallocations of dynamic data Memory leaks File handle leaks Network resource leaks Unused values Unhandled return codes Use of invalid iterators

Marking stack as non-execute Basic stack exploit can be prevented by marking stack segment as non-executable or randomizing stack location. Then injected code on stack cannot run Code patches exist for Linux and Solaris E.g., our olympus.eecs.ucf.edu has patched for stack radnomization Problems: Does not block more general overflow exploits: Overflow on heap, overflow func pointer Does not defend against `return-to-libc’ exploit. Some apps need executable stack (e.g. LISP interpreters).

Randomization Techniques For successful exploit, the attacker needs to know where to jump to, i.e., Stack layout for stack smashing attacks Heap layout for code injection in heap Shared library entry points for exploits using shared library Randomization Techniques for Software Security Randomize system internal details Memory layout Internal interfaces Improve software system security Reduce attacker knowledge of system detail to thwart exploit Level of indirection as access control

Randomize Memory Layout (I) Randomize stack starting point Modify execve() system call in Linux kernel Similar techniques apply to randomize heap starting point Randomize heap starting point Randomize variable layout

Randomize Memory Layout (II) Handle a variety of memory safety vulnerabilities Buffer overruns Format string vulnerabilities Integer overflow Double free Simple & Efficient Extremely low performance overhead Problems Attacks can still happen Overwrite data May crash the program Attacks may learn the randomization secret Format string attacks

Dynamic countermeasure: stackGuard Solution: StackGuard Run time tests for stack integrity. Embed “canaries” in stack frames and verify their integrity prior to function return.

Canary Types Random canary: Choose random string at program startup. Insert canary string into every stack frame. Verify canary before returning from function. To corrupt random canary, attacker must learn the random string.

Canary Types Additional countermeasures: use a random value for the canary XOR this random value with the return address include string termination characters in the canary value (why?)

StackGuard implemented as a GCC patch Program must be recompiled Low performance effects: 8% foR Apache Problem Only protect stack activation record (return address, saved ebp value)

Purify A tool that developers and testers use to find memory leaks and access errors. Detects the following at the point of occurrence: reads or writes to freed memory. reads or writes beyond an array boundary. reads from uninitialized memory.

Purify - Catching Array Bounds Violations To catch array bounds violations, Purify allocates a small "red-zone" at the beginning and end of each block returned by malloc. The bytes in the red-zone  recorded as unallocated. If a program accesses these bytes, Purify signals an array bounds error. Problem: Does not check things on the stack Extremely expensive

Further improvements PointGuard also protects other data values, eg function pointers, with canaries Higher performance impact than stackGuard ProPolice's Stack Smashing Protection (SSP) by IBM also re-orders stack elements to reduce potential for trouble Stackshield has a special stack for return addresses, and can disallow function pointers to the data segment

Dynamic countermeasures libsafe library prevents buffer overruns beyond current stack frame in the dangerous functions it redefines Dynamically loaded library. Intercepts calls to strcpy (dest, src) Validates sufficient space in current stack frame: |frame-pointer – dest| > strlen(src) If so, does strcpy. Otherwise, terminates application.

Dynamic countermeasures libverify enhancement of libsafe keeps copies of the stack return address on the heap, and checks if these match

None of these protections are perfect! even if attacks to return addresses are caught, integrity of other data other than the stack can still be abused clever attacks may leave canaries intact where do you store the "master" canary value a cleverer attack could change it none of this protects against heap overflows eg buffer overflow within a struct... New proposed non-control attack

Summary Buffer overflows are the top security vulnerability Any C(++) code acting on untrusted input is at risk Getting rid of buffer overflow weaknesses in C(++) code is hard (and may prove to be impossible) Ongoing arms race between countermeasures and ever more clever attacks. Attacks are not only getting cleverer, using them is getting easier