CS426Fall 2010/Lecture 141 Computer Security CS 426 Lecture 14 Software Vulnerabilities: Format String and Integer Overflow Vulnerabilities.

Slides:



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

Lecture 20 Arrays and Strings
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Avishai Wool, lecture Introduction to Information Security Lecture 1.
Detecting Format String Vulnerabilities with Type Qualifier Umesh Shankar, Kunal Talwar, Jeffrey S. Foster, David Wanger University of California at Berkeley.
1 Lecture 7  Fundamental data types in C  Data type conversion:  Automatic  Casting  Character processing  getchar()  putchar()  Macros on ctype.h.
Preventing Buffer Overflow Attacks. Some unsafe C lib functions strcpy (char *dest, const char *src) strcat (char *dest, const char *src) gets (char *s)
Control Hijacking Attacks Note: project 1 is out Section this Friday 4:15pm.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
1 Buffer Overflow Attacks and Format String bugs.
Exploiting Format String Vulnerabilities
Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2012.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
Static Analysis for Security Amir Bazine Per Rehnberg.
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.
System Programming Topic 19
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.
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
1 System Programming Topic 19 Software Vulnerabilities Topic 19: Software Vulnerabilities.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
CS390S, Week 4: Format String Vulnerabilities & Integer Overflows Pascal Meunier, Ph.D., M.Sc., CISSP January 31, 2007 Developed thanks to the support.
CS5261 Information Security CS 526 Topic Software Vulnerabilities Topic 12-13: Software Vulnerabilities.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Avishai Wool, lecture Introduction to Information Security Lecture 1.
Software attacks int ConcatString(char *buf1, char *buf2, size_t len1, size_t len2) { char buf[256]; if((len1 + len2) > 256) return -1; memcpy(buf, buf1,
Overflow Examples 01/13/2012. ACKNOWLEDGEMENTS These slides where compiled from the Malware and Software Vulnerabilities class taught by Dr Cliff Zou.
File I/O, Project 1: List ADT Bryce Boe 2013/07/02 CS24, Summer 2013 C.
Introduction to Programming
CSCE 548 Integer Overflows Format String Problem.
1 IS 2150 / TEL 2810 Introduction to Security James Joshi Associate Professor, SIS Lecture 12.2 Nov 20, 2012 Integer Issues.
Section 3.4: Buffer Overflow Attack: Attack Techniques 1.
Fundamental Data Types, Operators and Expressions Kernighan/Ritchie: Kelley/Pohl: Chapter 2 Chapter 2, 3.
Memory Layout, File I/O Bryce Boe 2013/06/27 CS24, Summer 2013 C.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
Information Security CS 526 Topic 9
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2015.
S ECURE P ROGRAMMING 6. B UFFER O VERFLOW (S TRINGS AND I NTEGERS ) P ART 2 Chih Hung Wang Reference: 1. B. Chess and J. West, Secure Programming with.
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
Introduction to Computer Organization & Systems Topics: Command Line Bitwise operators COMP Spring 2014 C Part V.
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.
Arrays, Strings, and Memory. Command Line Arguments #include int main(int argc, char *argv[]) { int i; printf("Arg# Contents\n"); for (i = 0; i < argc;
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
C is a high level language (HLL)
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
1 Homework Continue with K&R Chapter 5 –Skipping sections for now –Not covering section 5.12 Continue on HW5.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2010.
CSC 482/582: Computer Security
Content Coverity Static Analysis Use cases of Coverity Examples
Stack and Heap Memory Stack resident variables include:
Module 30 (Unix/Linux Security Issues II)
A bit of C programming Lecture 3 Uli Raich.
Introduction to Information Security , Spring 2016 Lecture 1: Introduction, Control Hijacking (1/2) Avishai Wool.
Information Security CS 526 Topic 8
CNT4704: Computer Networking Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2009.
Basic Control Hijacking Attacks
Conversions of the type of the value of an expression
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Secure Coding in C and C++ Integer Security
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou University of Central Florida.
Introduction to Static Analyzer
Operations and Arithmetic
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
Format String Vulnerability
Presentation transcript:

CS426Fall 2010/Lecture 141 Computer Security CS 426 Lecture 14 Software Vulnerabilities: Format String and Integer Overflow Vulnerabilities

CS426Fall 2010/Lecture 142 Format string problem int func(char *user) { fprintf( stdout, user); } Problem: what if user = “%s%s%s%s%s%s%s” ?? –Most likely program will crash: DoS. –If not, program will print memory contents. Privacy? –Full exploit using user = “ %n ” Correct form: int func(char *user) { fprintf( stdout, “%s”, user); }

CS426Fall 2010/Lecture 143 Format string attacks (“%n”) printf(“%n”, &x) will change the value of the variable x –in other words, the parameter value on the stack is interpreted as a pointer to an integer value, and the place pointed by the pointer is overwritten

CS426Fall 2010/Lecture 144 History Danger discovered in June Examples: –wu-ftpd 2.* :remote root. –Linux rpc.statd:remote root –IRIX telnetd:remote root –BSD chpass:local root

CS426Fall 2010/Lecture 145 Vulnerable functions Any function using a format string. Printing: printf, fprintf, sprintf, … vprintf, vfprintf, vsprintf, … Logging: syslog, err, warn

CS426Fall 2010/Lecture 146 Integer Overflow Integer overflow: an arithmetic operation attempts to create a numeric value that is larger than can be represented within the available storage space. Example: Test 1: short x = 30000; short y = 30000; printf(“%d\n”, x+y); Test 2: short x = 30000; short y = 30000; short z = x + y; printf(“%d\n”, z); Will two programs output the same? What will they output?

C Data Types short int 16bits [-32,768; 32,767] unsigned short int 16bits [0; 65,535] unsigned int 16bits [0; 4,294,967,295] Int 32bits [-2,147,483,648; 2,147,483,647] long int 32 bits [-2,147,483,648; 2,147,483,647] signed char 8bits [-128; 127] unsigned char 8 bits[0; 255] CS426Fall 2010/Lecture 147

CS426Fall 2010/Lecture 148 When casting occurs in C? When assigning to a diffreent data type For binary operators +, -, *, /, %, &, |, ^, –if either operand is an unsigned long, both are cast to an unsigned long –in all other cases where both operands are 32-bits or less, the arguments are both upcast to int, and the result is an int For unary operators –~ changes type, e.g., ~((unsigned short)0) is int –++ and -- does not change type

CS426Fall 2010/Lecture 149 Where Does Integer Overflow Matter? Allocating spaces using calculation. Calculating indexes into arrays Checking whether an overflow could occur Direct causes: –Truncation; Integer casting

Integer Overflow Vulnerabilities Example (from Phrack) int main(int argc, char *argv[]) { unsigned short s; int i; char buf[80]; if (argc < 3){ return -1; } i = atoi(argv[1]); s = i; if(s >= 80) { printf(“No you don't!\n"); return -1; } printf("s = %d\n", s); memcpy(buf, argv[2], i); buf[i] = '\0'; printf("%s\n", buf); return 0; } CS426Fall 2010/Lecture 1410

CS426Fall 2010/Lecture 1411 Integer Overflow Vulnerabilities Example Example: const long MAX_LEN = 20K; Char buf[MAX_LEN]; short len = strlen(input); if (len < MAX_LEN) strcpy(buf, input); Can a buffer overflow attack occur? If so, how long does input needs to be?

CS426Fall 2010/Lecture 1412 Another Example int ConcatBuffers(char *buf1, char *buf2, size_t len1, size_t len2) { char buf[0xFF]; if ((len1 + len2) > 0xFF) return -1; memcpy(buf, buf1, len1); memcpy(buf+len1, buf2, len2); return 0; }

CS426Fall 2010/Lecture 1413 Yet Another Example // The function is supposed to return false when // x+y overflows unsigned short. // Does the function do it correctly? bool IsValidAddition(unsigned short x, unsigned short y) { if (x+y < x) return false; return true; }

CS426Fall 2010/Lecture 1414 Readings for This Lecture Wikipedia Format string attack Integer overflow

CS426Fall 2010/Lecture 1415 Coming Attractions … Malwares