Software Security Lesson Introduction

Slides:



Advertisements
Similar presentations
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Advertisements

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.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
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.
Lecture 16 Buffer Overflow
Simple Buffer Overflow Example Dan Fleck CS469 Security Engineering Reference: Coming up: Buffer Overflows.
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
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-
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
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.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
Computer Security and Penetration Testing
BLENDED ATTACKS EXPLOITS, VULNERABILITIES AND BUFFER-OVERFLOW TECHNIQUES IN COMPUTER VIRUSES By: Eric Chien and Peter Szor Presented by: Jesus Morales.
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
Mitigation of Buffer Overflow Attacks
Brian E. Brzezicki. This tutorial just illustrates the underlying concepts of buffer overflows by way of an extremely simple stack overflow  Most buffer.
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 10 “Buffer Overflow”.
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
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.
Buffer overflow and stack smashing attacks Principles of application software security.
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
Web Security Firewalls, Buffer overflows and proxy servers.
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.
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.
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade Crispin Cowan SANS 2000.
Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.
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.
@Yuan Xue Worm Attack Yuan Xue Fall 2012.
Content Coverity Static Analysis Use cases of Coverity Examples
Let’s look at an example
Secure Programming Dr. X
Shellcode COSC 480 Presentation Alison Buben.
Overflows Mark Shtern.
Major Problem Areas for Secure Programming
Buffer Overflow By Collin Donaldson.
Mitigation against Buffer Overflow Attacks
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?
CSC 495/583 Topics of Software Security Stack Overflows (2)
Secure Software Development: Theory and Practice
CMSC 414 Computer and Network Security Lecture 21
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Format String.
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
Introduction to Static Analyzer
Buffer Overflows.
CS5123 Software Validation and Quality Assurance
Understanding and Preventing Buffer Overflow Attacks in Unix
System and Cyber Security
Outline Introduction Memory protection Buffer overflows
Format String Vulnerability
Return-to-libc Attacks
Presentation transcript:

Software Security Lesson Introduction Software vulnerabilities and how attackers exploit them. Defenses against attacks that try to exploit buffer overflows. Secure programming: Code “defensively”, expecting it to be exploited. Do not trust the “inputs” that come from users of the software system.

Software Vulnerabilities & How They Get Exploited Example: Buffer overflow - a common and persistent vulnerability Stack buffer overflows Stacks are used... in function/procedure calls for allocation of memory for... local variables parameters control information (return address)

A Vulnerable Password Checking Program #include <stdio.h> //#include <strings.h> //#include <string.h> #include <cstring> //#include <iostream.h> #include <iostream> using namespace std; int main(int argc, char *argv[]) {     int AccessGranted = -1;         char systemPassword[12] = "MyPwdabc";         char incomingPasswd[12];         gets(incomingPasswd);         printf(" target =%s password= %s  allow_login=%d\n",systemPassword,incomingPasswd,AccessGranted);         if (strncmp(incomingPasswd,systemPassword,10) == 0)                 AccessGranted = 1;         if (AccessGranted == -1)                 printf("Sorry, Cannot Access files \n target =%s password=%s allow_login=%d",systemPassword,incomingPasswd,AccessGranted);         else                 printf("[OK] .... read files now! ");

Stack Access Quiz Check the lines of code, when executed, accesses addresses in the stack frame for main(): int main(int argc, char *argv[]) { int allow_login = 0; char pwdstr[12]; char targetpwd[12] = "MyPwd123"; gets(pwdstr); if (strncmp(pwdstr,targetpwd, 12) == 0) allow_login = 1; if (allow_login == 0) printf("Login request rejected"); else printf("Login request allowed"); }

Understanding the Stack High Address Low Address

Attacker Bad Input Quiz What type of password string could defeat the password check code? (Check all that apply) Any password of length greater than 12 bytes that ends in ‘123’ Any password of length greater than 16 bytes that begins with ‘MyPwd123’ Any password of length greater than 8 bytes #include <stdio.h> //#include <strings.h> //#include <string.h> #include <cstring> //#include <iostream.h> #include <iostream> using namespace std; int main(int argc, char *argv[]) {     int AccessGranted = -1;         char systemPassword[12] = "MyPwdabc";         char incomingPasswd[12];         gets(incomingPasswd);         printf(" target =%s password= %s  allow_login=%d\n",systemPassword,incomingPasswd,AccessGranted);         if (strncmp(incomingPasswd,systemPassword,10) == 0)                 AccessGranted = 1;         if (AccessGranted == -1)                 printf("Sorry, Cannot Access files \n target =%s password=%s allow_login=%d",systemPassword,incomingPasswd,AccessGranted);         else                 printf("[OK] .... read files now! ");

Attacker Code Execution We type a correct password (MyPwd123) of less than 12 characters: The login request is allowed. Now let us type “BadPassWd” when we are asked to provide the password: The login request is rejected.

Attacker Code Execution

Attacker Code Execution If we type a really long string, we will overflow into the return address space.

Attacker Code Execution We can carefully overflow the return address so it contains the value of an address where we put some code we want executed.

Buffer Overflow Quiz Which of these vulnerabilities applies to the code: The target password was too short, this made it easy to overflow the buffer. The code did not check the input and reject password strings longer than 12 bytes. The code did not add extra, unused variables. If this is done then when the user inputs a long password, it won’t overflow into the return address.

ShellCode Shell Code: creates a shell which allows it to execute any code the attacker wants. Whose privileges are used when attacker code is executed? The host program’s System service or OS root privileges LEAST Privilege is IMPORTANT

National Vulnerability Database (NVD) Quiz How many CVE (Common Vulnerability and Exposure) vulnerabilities do you think NVD will have? [1] Close to 500, [2] A few thousand, [3] Close to 70000 If you search the NVD, how many buffer overflow vulnerabilities will be reported from the last three months? [1] less than 10, [2] Several hundred, [3] Close to one hundred How many buffer overflow vulnerabilities in the last 3 years? [1] Over a thousand, [2] fifty thousand, [3] five hundred 7000; 100; 1000

Variations of Buffer Overflow Return-to-libc: the return address is overwritten to point to a standard library function. Heap Overflows: data stored in the heap is overwritten. Data can be tables of function pointers. OpenSSL Heartbleed Vulnerability: read much more of the buffer than just the data, which may include sensitive data.

Heap Overflow Buffer overflows that occur in the heap data area. Stack Typical heap manipulation functions: malloc()/free() Higher Address Stack char* p = malloc (256); memset (p, ‘A’, 1024); Heap Lower Address

Heap Overflow – Example Overwrite the function pointer in the adjacent buffer Higher Address Function Pointer Function Pointer Chunk 2 Chunk 1 Before heap overflow After heap overflow

Defense Against Buffer Overflow Attacks Programming language choice is crucial. The language... Should be strongly typed Should do automatic bounds checks Should do automatic memory management Examples of Safe languages: Java, C++, Python

Defense Against Buffer Overflow Attacks Why are some languages safe? Buffer overflow becomes impossible due to runtime system checks The drawback of secure languages Possible performance degradation

Defense Against Buffer Overflow Attacks When Using Unsafe Languages: Check input (ALL input is EVIL) Use safer functions that do bounds checking Use automatic tools to analyze code for potential unsafe functions.

Defense Against Buffer Overflow Attacks Analysis Tools… Can flag potentially unsafe functions/constructs Can help mitigate security lapses, but it is really hard to eliminate all buffer overflows. OWASP Tools Of This Type OWASP SonarQube Project OWASP Orizon Project OWASP LAPSE Project OWASP O2 Platform OWASP WAP-Web Application Protection Examples of analysis tools can be found at: https://www.owasp.org/index.php/Source_Code_Analysis_Tools

Thwarting/Spoiling Buffer Overflow Attacks Stack Canaries: When a return address is stored in a stack frame, a random canary value is written just before it. Any attempt to rewrite the address using buffer overflow will result in the canary being rewritten and an overflow will be detected. Reason the random value will point to any place in memory that most likely not an executable or meaningful!

Countermeasure – Stack Protection Canary for tamper detection No code execution on stack … Before using the return address, check if the canary value on stack is the same as value stored in a register Injected code Return address Overwriting return address will always overwrite the canary value Canary Stack growth direction passwordok Unbounded write overwrites contents of stack userid password

Thwarting Buffer Overflow Attacks Address Space Layout Randomization (ASLR) randomizes stack, heap, libc, etc. This makes it harder for the attacker to find important locations (e.g., libc function address). Use a non-executable stack coupled with ASLR. This solution uses OS/hardware support.

Buffer Overflow Attacks Quiz Do stack canaries prevent return-to-libc buffer overflow attacks? Does ASLR protect against read-only buffer overflow attacks? Can the OpenSSL heartbleed vulnerability be avoided with non-executable stack? Yes No Yes No Yes No

Software Security Lesson Summary Understand how software bug/ vulnerabilities can be exploited Several defenses possible against attacks Buffer overflows remain a problem Web security: Important for web Secure coding -- check all input!