Exploits Against Software and How To Avoid Them Nicolas T. Courtois - University College of London.

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.
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.
Exploits Against Software and Defences
CMSC 414 Computer and Network Security Lecture 22 Jonathan Katz.
Part III Counter measures The best defense is proper bounds checking but there are many C/C++ programmers and some are bound to forget  Are there any.
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.
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
1 RISE: Randomization Techniques for Software Security Dawn Song CMU Joint work with Monica Chew (UC Berkeley)
Lecture 16 Buffer Overflow
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
System Calls 1.
Address Space Layout Permutation
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Lecture 0 Appendix on Implementation Threats Material from Warren Page & Chpt 11, Information Security by Mark Stamp.
Computer Security and Penetration Testing
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,
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”.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
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.
On the Effectiveness of Address-Space Randomization Hovav Shacham, Matthew Page, Ben Pfaff, Eu-Jin Goh, Nagendra Modadugu, Dan Boneh.
A Survey on Runtime Smashed Stack Detection 坂井研究室 M 豊島隆志.
Buffer Overflows Taught by Scott Coté.-. _ _.-. / \.-. ((___)).-. / \ /.ooM \ / \.-. [ x x ].-. / \ /.ooM \ -/ \ /-----\-----/---\--\ /--/---\-----/-----\ / \-
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.
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.
Foundations of Network and Computer Security J J ohn Black CSCI 6268/TLEN 5550, Spring 2013.
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.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 1.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
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.
@Yuan Xue Worm Attack Yuan Xue Fall 2012.
Lec. Waleed Bin Shahid.  You might have noticed a lot of issues related to software implementation.  The ultimate requirement of developer(s) is to.
Secure Programming Dr. X
Major Problem Areas for Secure Programming
Mitigation against Buffer Overflow Attacks
Introduction to Operating Systems
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
Secure Programming Dr. X
Protecting Memory What is there to protect in memory?
Secure Software Development: Theory and Practice
CSC 495/583 Topics of Software Security Return-oriented programming
CMSC 414 Computer and Network Security Lecture 21
Software Security.
Introduction to Operating Systems
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Software Security Lesson Introduction
CS5123 Software Validation and Quality Assurance
Understanding and Preventing Buffer Overflow Attacks in Unix
Outline Introduction Memory protection Buffer overflows
Set-UID Privileged Programs
Return-to-libc Attacks
Presentation transcript:

Exploits Against Software and How To Avoid Them Nicolas T. Courtois - University College of London

Goals of Attackers

CompSec COMPGA01 Nicolas T. Courtois, December Break In Stage 1: Get to run some code (even without privileges). Stage 2: Gain admin access, usually by calling other local programs and exploiting their vulnerabilities.

CompSec COMPGA01 Nicolas T. Courtois, December Goals for Software Exploits crash software (can be DOS) crash hardware (e.g. hard drive) get some data or side channels inject arbitrary code these also happen accidentally…

What’s Wrong?

CompSec COMPGA01 Nicolas T. Courtois, December Software Vulnerabilities 1.Input validation problems 2.Buffer overflow 3.Format string vulnerabilities 4.Integer overflows, 5.CPU bugs 6.Failing to handle errors / exceptions properly 7.etc …

Vectors of Attack - Inputs

CompSec COMPGA01 Nicolas T. Courtois, December Software Input Exploits Exe programs: command line arguments environment variables configuration files / settings changed in the registry by another program … network packets etc … Dlls / Unix runtime precompiled libraries: function calls from other programs

CompSec COMPGA01 Nicolas T. Courtois, December Danger of Environment Variables In UNIX: Set LD_LIBRARY_PATH system variable to avoid the standard precompiled libraries… Hacker puts his own libraries in his own directory… Fix: modern C runtime libraries in Unix stopped using LD_LIBRARY_PATH variable when the euid is not the same as the ruid… Normal cases % of the time

CompSec COMPGA01 Nicolas T. Courtois, December Recall: In Unix each process has several user IDs: Real User ID == ruid, identifies the owner of the process Effective User ID == euid, determines current access rights

CompSec COMPGA01 Nicolas T. Courtois, December set-uid programs Definition: A “set-uid program” (property acquired at creation/compilation time) is a program that assumes the identity and has privileges of the owner of the program, though a different user uses it. Examples: passwd su, sudo BTW: if copied to a “user” directory, stop working!

CompSec COMPGA01 Nicolas T. Courtois, December More Attacks on PATH in Unix Now imagine that any “setuid program” contains the following line: system(“ls … ”); OOPS… there are several ways to use this to run any program as root…

CompSec COMPGA01 Nicolas T. Courtois, December More Attacks on PATH in Unix

CompSec COMPGA01 Nicolas T. Courtois, December Another Known Exploit in Unix The IFS variable: the characters that the system considers as white space now add “ s ” to the IFS set of characters –system(ls) becomes system(l) –a function l in the current directory will be run as root …

Buffer Overflow

CompSec COMPGA01 Nicolas T. Courtois, December Software Buffer Overflow Exploits I will explain in details only 1 type of buffer overflow attack … Stack Smashing There are many other types of software vulnerabilities … Study of these requires a lot of technical expertise about programming, compilers, assembly and CPUs …

CompSec COMPGA01 Nicolas T. Courtois, December Buffer Overflow History Extremely common since the 1980s. Consistently about 50 % of all CERT advisories. Usually leads to a total compromise of the machine …

CompSec COMPGA01 Nicolas T. Courtois, December Can Programmers Get It Right? Lot of evidence around that they cannot. the behavior of Turing machines is very HARD to analyse, –cf. Rice thm. it is usually easier to rewrite code from the scratch than to find all bugs in it software economics, time to market, code re-use etc … Major problems also occur at the compiler and runtime level … (even CPUs have bugs that can be used for exploits).

CompSec COMPGA01 Nicolas T. Courtois, December Problems with C and C++ C and C++ particularly dangerous –Fast, therefore used in servers and all critical code (performance-wise and security-wise) –allows arbitrary manipulation of pointers but not outside the virtual 2 Gbyte space allocated by the OS

CompSec COMPGA01 Nicolas T. Courtois, December Software Under Attack Main goal: inject arbitrary code through standard input channels of the program. Input-dependent vulnerabilities. Excessively common in software we use every day … Unix and Windows alike …

CompSec COMPGA01 Nicolas T. Courtois, December Exploit = specially crafted input that allows a certain task to be accomplished compromising the security policy usually executing arbitrary code. Goal: execute with the privilege level of the program: web server running as superuser … Ordinary programs running as user … Furthermore, injected code may use another vulnerability to permit privilege escalation.

Buffer Overflow Attack: Stack Smashing and Code Injection in C

CompSec COMPGA01 Nicolas T. Courtois, December Buffer Overflow in C char command[256]= “” ; allocated from the stack. Now imagine we input longer data than 256 bytes and use strcpy(command,*input_data). In theory: “ undefined behaviour ”.. In practice: we can predict what will happen.

CompSec COMPGA01 Nicolas T. Courtois, December historical roots Since ever, in CPU assembly and in compiling structured programs, the habit is to save the state of the CPU when calling a sub-routine. And saving the return address. It is essential which comes first … otherwise there would be no such attack. This is saved on the process stack.

CompSec COMPGA01 Nicolas T. Courtois, December Process Memory Layout Stack Grows toward low memory Heap Grows toward high memory Text 0xC x x

CompSec COMPGA01 Nicolas T. Courtois, December Calling a Sub-Routine in C Stack PUSH PULL on every CPU since ever … Stack

CompSec COMPGA01 Nicolas T. Courtois, December Stack Frames for one C Function f Stack params of f return address saved bottom of stack local variables built in this order

CompSec COMPGA01 Nicolas T. Courtois, December exploit on f Stack params of f return address saved bottom of stack local variables increasingaddresses void f(params) { char command[256]=“”; … strcpy(command,sth) } size easy to guess overwrite

CompSec COMPGA01 Nicolas T. Courtois, December exploit on f Stack params of f return address saved bottom of stack local variables increasingaddresses void f(params) { char command[256]=“”; … strcpy(command,sth) } easy to guess overwrite shell code 0x

CompSec COMPGA01 Nicolas T. Courtois, December when f finishes Stack params of f return address saved bottom of stack local variables return address shell code 0x the frame buffer was de-allocated, data still there

CompSec COMPGA01 Nicolas T. Courtois, December Reliability up to very high, up to 100% (there are stable exploits, never ever fail and produce consistent results)

What Hackers Do?

Can We Fix It?

CompSec COMPGA01 Nicolas T. Courtois, December Solutions (1) use type and memory safe languages (Java, ML) clean the de-allocated frame buffer: slow!!! Partial solutions (not perfect) certain forms of access control? –yes, replace pointers by use of “un-forgeable reference” tokens sandboxing and “secure” VM techniques. store things in a different order: ASLR = Address Space Layout Randomisation – at the runtime! –suddenly it makes a lot of sense to recompile the Apache web server software on each server. Reason: 75 K copies, Slammer worm. OpenBSD (enabled by default) Linux – weak form of ASLR by default since kernel (much better with the Exec Shield patch for Linux). Windows Vista and Windows Server 2008: –ASLR enabled by default, although only for those executables and dynamic link libraries specifically linked to be ASLR- enabled. So only very few programs such as Internet Explorer 8 enable these protections…

CompSec COMPGA01 Nicolas T. Courtois, December Solutions (2) Automated protections with canaries: store known data at the end of the buffer. Check. StackGuard, ProPolice, PointGuard = extensions of GCC, automatic. similar protections also by default in MsVisual Studio Time performance overhead: about +10%. Is this secure? –what value should the canary have? what if the same C routine is called twice?

CompSec COMPGA01 Nicolas T. Courtois, December Attack Against StackGuard (Canaries)

CompSec COMPGA01 Nicolas T. Courtois, December Solutions (3) hire a programmer with extensive understanding of software attacks –less attacks, will not eliminate them Cheaper solutions: make sure that stack space is marked as impossible to execute () –DEP = Data Execution Protection. Linux PaX (a patch for Linux), Supported in Windows XP SP2 too, not widely used yet. –Requires DEP, requires PAE mode. blacklist parts of C language! –ongoing process.

CompSec COMPGA01 Nicolas T. Courtois, December W  X Page Protections - Unix CPU has page protection implemented in combination of hardware / OS kernel –for each 4K memory page, permission bits specified in page table entry in kernel: read, write Exclusive OR –Each page should be either writable or executable, but not both: W  X –exe program (a.k.a. text) pages: X, not W –data (stack, heap) pages: W, not X Remark: In Linux PaX, for older processors, the mechanism of W  X is implemented in a tricky way based on segment limit registers => memoryx2, negligible performance degradation.

CompSec COMPGA01 Nicolas T. Courtois, December DEP = Data Execution Prevention - Windows The “X” idea: Memory pages MUST be explicitly marked as executable to be able to execute code. Windows - Since XP SP2. Hardware mechanism. Both Intel and AMD implemented it. –NX bit.Not active by default. Choice dictated by legacy programs… –Compatibility problems. PAE mode needed. Can also be enforced purely in software (cf. Linux PaX).

CompSec COMPGA01 Nicolas T. Courtois, December DEP Solves The Problem? Only prevents injection of code. the ‘return-to-libc’ exploit: The hacker can overwrite not with code but with a system call plus parameters that will contain the instructions for the shell (!!!). –System(“command123”) Details depend a lot on OS. –this attack works for simple OS with monolithic kernel… –and in many other cases Calling the OS functions by direct jumps is not a secure practice… –old attack, many changes since… Stack return address saved bottom of stack local variables shell code 0x command123 system()

CompSec COMPGA01 Nicolas T. Courtois, December Preventing Attacks on System Calls details depend a lot on OS… Can we prevent the ‘return-to-libc’ exploits with Windows dlls? Answer: In Windows, at boot time the order and location of system calls WILL be randomised. Lowers considerably the chances to succeed, (does not eliminate the attack) Stack return address saved bottom of stack local variables shell code 0x command123 ms*.dll

CompSec COMPGA01 Nicolas T. Courtois, December DEP Solves The Problem? Can still jump to some code injected on the heap Does not prevent against attacks on the heap…

CompSec COMPGA01 Nicolas T. Courtois, December Input Validation Application-specific: check if intended length and format. –use special encoding for inputs –use encrypted inputs, check length the attack is unlikely to do anything intended? –If stream cipher, can flip bits to change one character … Routines that remove dangerous characters. –In PHP, using the htmlentities() function. –In an SQL request, use mysql_real_escape_string()

CompSec COMPGA01 Nicolas T. Courtois, December C Tips – Replace by sprintf(buf, … ) snprintf(buf, buflen, … ), scanf( “ %s ”, buf) scanf( “ %10s ”, buf), strcpy(buf, input)strncpy(buf, input, 256) etc …

CompSec COMPGA01 Nicolas T. Courtois, December Solutions (4) Automated tools working on: Source code: These find lots of bugs, but not all. Ready exe: Taintcheck: fix ready exe files …

CompSec COMPGA01 Nicolas T. Courtois, December Solutions (5) Replacement libraries: Example: libsafe – dynamically linked library, will intercept calls to strcpy and check buffer sizes.. StackShield – an assembler file processor for GCC keeps backup copies of SFP and RET at the beginning of local variables, compare before exiting the function.

CompSec COMPGA01 Nicolas T. Courtois, December Solutions (6) Instruction Set Randomization (ISR) – runtime encryption of CPU instructions … different for each program, makes code injection impossible.

Heap Overflow not on the exam