Chapter 6 Weaknesses Exploited

Slides:



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

Smashing the Stack for Fun and Profit
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.
Lecture 16 Buffer Overflow modified from slides of Lawrie Brown.
CMSC 414 Computer and Network Security Lecture 22 Jonathan Katz.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
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.
Software and Security Buffer Overflow 1.
Teaching Buffer Overflow Ken Williams NC A&T State University.
Application and OS Attacks 1 Application and OS Attacks.
Teaching Buffer Overflow Ken Williams NC A&T State University.
Run-time Environment and Program Organization
Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.
SQL Injection and Buffer overflow
Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
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-
Application Security Tom Chothia Computer Security, Lecture 14.
Buffer overflows.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Lecture 0 Appendix on Implementation Threats Material from Warren Page & Chpt 11, Information Security by Mark Stamp.
Lecture 6: Buffer Overflow CS 436/636/736 Spring 2014 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
Computer Security and Penetration Testing
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
Attacking Applications: SQL Injection & Buffer Overflows.
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
Brian E. Brzezicki. This tutorial just illustrates the underlying concepts of buffer overflows by way of an extremely simple stack overflow  Most buffer.
CIS 450 – Network Security Chapter 7 – Buffer Overflow Attacks.
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.
Overflow Examples 01/13/2012. ACKNOWLEDGEMENTS These slides where compiled from the Malware and Software Vulnerabilities class taught by Dr Cliff Zou.
Chapter-4 Software Security Why Software?  Why is software as important to security as crypto, access control and protocols?  Virtually all of information.
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
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.
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
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.
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.
Beyond Stack Smashing: Recent Advances In Exploiting Buffer Overruns Jonathan Pincus and Brandon Baker Microsoft Researchers IEEE Security and.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
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.
Lec. Waleed Bin Shahid.  You might have noticed a lot of issues related to software implementation.  The ultimate requirement of developer(s) is to.
Shellcode COSC 480 Presentation Alison Buben.
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.
Protecting Memory What is there to protect in memory?
The Hardware/Software Interface CSE351 Winter 2013
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
CSC 495/583 Topics of Software Security Return-oriented programming
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Software Security Lesson Introduction
Format String.
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
Smashing the Stack for Fun and Profit
Understanding and Preventing Buffer Overflow Attacks in Unix
Format String Vulnerability
Overflows, Injection, & Memory Safety
Presentation transcript:

Chapter 6 Weaknesses Exploited

Weaknesses Bad software is everywhere, and… …flaws can cause security problems In this chapter Various overflow conditions Format string vulnerabilities How weaknesses are found Defenses Human factors

Technical Weaknesses Buffer overflow Process address space: 4 sections Fixed-sized code block (code/text) Static data (data) Dynamic data (heap) “Scratch paper” (stack)

Technical Weaknesses C program example

Stack Frame Stack frame allocated for functions Stack holds… Local variables Book keeping info, such as Input arguments Return address Saved frame pointer, etc.

Stack Frame Stack frame in action

Memory Organization Text == code Data == static variables low address Text == code Data == static variables Heap == dynamic data Stack == “scratch paper” Dynamic local variables Parameters to functions Return address text data heap   SP stack high address

Simplified Stack Example low  void func(int a, int b){ char buffer[10]; } void main(){ func(1, 2); : SP buffer ret return address SP a SP b SP high 

Smashing the Stack What happens if buffer overflows? ??? : Program “returns” to wrong location SP buffer overflow ret SP ret… A crash is likely NOT! overflow a SP b SP high 

Smashing the Stack Trudy has a better idea… Code injection low  Trudy has a better idea… : Code injection Trudy can run code of her choosing… On your machine! SP evil code ret ret SP a SP b SP high 

Smashing the Stack Trudy may not know… Solutions Address of evil code : Trudy may not know… Address of evil code Location of ret on stack Solutions Precede evil code with NOP “landing pad” Insert ret many times NOP : NOP evil code ret ret ret : ret :

Stack Smashing Note that injected code is usually known as “shellcode” Other overflow attacks are possible Some inject code, some don’t We discuss a few more examples later

Stack Smashing Summary A buffer overflow must exist in the code Not all buffer overflows are exploitable Things must align just right If exploitable, attacker can inject code Trial and error is likely required Fear not, lots of help available online Smashing the Stack for Fun and Profit, Aleph One Stack smashing is “attack of the decade” Regardless of the decade… Also heap overflow, integer overflow, etc.

Stack Smashing Example Program asks for a serial number that the attacker does not know Attacker does not have source code Attacker does have the executable (exe) Program quits on incorrect serial number

Example By trial and error, attacker discovers apparent buffer overflow Note that 0x41 is “A” Looks like ret overwritten by 2 bytes!

Example Next, disassemble bo.exe to find The goal is to exploit buffer overflow to jump to address 0x401034

Example Find that, in ASCII, 0x401034 is “@^P4” Byte order is reversed? Why? X86 processors are “little-endian”

Example Reverse the byte order to “4^P@” and… Success! We’ve bypassed serial number check by exploiting a buffer overflow What just happened? We overwrote the return address on the stack

Example Note that in this example… We overwrote return address and jumped to somewhere interesting We did not inject any code Other interesting places to jump to? Without injecting code, that is? Often called “return to libc” attacks

Example Attacker did not require access to the source code Only tool used was a disassembler to determine address to jump to Possible to find desired address by trial and error? Necessary if attacker does not have exe For example, a remote attack

Example Source code of the buffer overflow Flaw easily found by attacker Without the source code!

Stack Smashing Prevention 1st choice: employ non-executable stack “No execute” NX bit (if available) Seems like the logical thing to do, but some real code executes on the stack (Java, for example) 2nd choice: use safe languages (Java, C#) 3rd choice: use safer C functions For unsafe functions, there are safer versions For example, strncpy instead of strcpy

Stack Smashing Prevention low  Canary Run-time stack check Push canary onto stack Canary value: Constant 0x000aff0d Or may depends on ret : buffer overflow canary overflow ret a high  b

Microsoft’s Canary Microsoft added buffer security check feature to C++ with /GS compiler flag Based on canary (or “security cookie”) Q: What to do when canary dies? A: Check for user-supplied “handler” Handler shown to be subject to attack Claims that attacker can specify handler code If so, formerly “safe” buffer overflows become exploitable when /GS is used!

ASLR Address Space Layout Randomization Randomize place where code loaded in memory Makes most buffer overflow attacks probabilistic Vista uses 256 random layouts So about 1/256 chance buffer overflow works? Similar thing in Mac and other OSs Attacks against Microsoft’s ASLR do exist Possible to “de-randomize”

Buffer Overflow A major threat yesterday, today, and tomorrow Can greatly reduced overflow attacks Use safe languages/safer functions Educate developers, use tools, etc. Buffer overflows will exist for a long time Legacy code Bad software development practices

Race Condition Security processes should be atomic Occur “all at once” Race conditions can arise when security- critical process occurs in stages Attacker makes change between stages Often, between stage that gives authorization, but before stage that transfers ownership Example: prepaid debit card

Race Condition Adding cash to card Race condition? User inserts card into card reader machine Machine reads value of card: x User insert cash into machine: y User presses “enter” key Machine writes x+y to card Machine ejects card Race condition?

Race Condition Attacks on cash card protocol? Insert 2 cards, sandwiched together Card that is read has $100 value, unread card has $1 value Step 2: Machine reads x = 100 Insert $2, so y = 2 Pull out read card, leaving unread one Press “enter”…

Race Conditions Race conditions appear to be common in software May be more common than buffer overflows But race conditions harder to exploit Buffer overflow is “low hanging fruit” today To prevent race conditions… Make security-critical processes atomic Occur all at once, not in stages Not so easy to accomplish in practice

Heap Overflow Heap used for dynamic variables For example, malloc in C Can overflow one array into another Makes it possible to change data Like example on next slide

Simple Buffer Overflow Consider boolean flag for authentication Buffer overflow could overwrite flag allowing anyone to authenticate! Boolean flag buffer F O U R S C … T F In some cases, Trudy can be more systematic

Heap Overflow Example BEFORE: buf2 = 22222222 AFTER: buf2 = 11122222

Heap Overflow Bookkeeping info stored on heap Can attacker exploit this?

Heap Overflow Data structure to keep track of free memory Assume it is a doubly-linked list Heap overflow attacks?

Heap Overflow Here we free block B “Unlink” B from heap If overflow in A, can overwrite B’s pointers…

Heap Overflow Overwrite B’s pointers Then free B Now if we ever get to B, will go to shellcode

Integer Overflow Many “integer” problems This example… What if len is negative? Note that memcpy thinks len is unsigned

Format String Vulnerabilities Format string example printf(“The magic number is %d\n”, 42); Format strings: Parameter Meaning Passed by… %d int value %u unsigned int %x hex %s string reference %n bytes written so far

Format Strings and the Stack Formatting functions retrieve parameters from the stack Assuming that’s where they’re stored… Consider printf(“a has value %d at address %d\n”, a, &a); What if there are too few arguments? For example printf(“a has value %d at address %d\n”);

Format Strings and the Stack Consider again printf(“a has value %d at address %d\n”, a, &a); Here, x1 and x2 are other things on the stack high  : a address of a x1 x2 low  “a has … \n”

Format Strings and the Stack What if there are too few arguments? For example printf(“a has value %d at address %d\n”); What happens? high  : x1 x2 x3 x4 low  “a has … \n” Print stuff on stack Is this useful?

Format String Issue 1 We can “walk” the stack That is, print out items on the stack For example printf(“%08x %08x %08x %08x %08x\n”); As a bonus, it’s nicely formatted…

Format String Issue 2 What would this do? printf(“%s%s%s%s%s%s%s%s%s%s%s”); For each %s function printf will… Fetch a number from the stack Treat the number as an address Print out whatever is at that address, until NULL character Such an “address” might not exist!

Format String Example What about something like this… void print_error(char *s){ char buffer[100]; snprintf(buffer, sizeof(buffer), “Error: %s”, s); printf(buffer);} Suppose Trudy has control over what goes into the string s Then some interesting possibilities…

Format String Issue 3 Suppose Trudy sets string s to 1st %d  2nd %d  high  : %d low  1234567 buffer “Error: %s…” return %s  printf Suppose Trudy sets string s to \x78\x56\x34\x12 %d%d%d%s Note \x78…\x12 is little endian for 1234567 What does code on previous slide do?

Format String Issue 4 The %n format is used to print the number of characters written so far Q: What does this do? int i; printf(“abcde%n, &i); A: Writes 5 to variable i Can Trudy take advantage of this?

Format String Issue 4 Similar attack as “issue 3”… …except use %n in place of %s Then a value written to address 1234567 What value? Some claim that this allows writing of arbitrary value Is this really true?

Format String Defenses Source code auditing Relatively few format strings Remove support for %n format Would this create any problems? Keep track of number of arguments General buffer overflow prevention For example, ASLR (next slide…)

More Defenses Mentioned by author NX approach Canary ASLR Safe/safer languages

Finding Weaknesses How do attackers find weaknesses? Technical analysis Study source code (if available) Disassemble executables (SRE) Decompile (good luck with that!) Black box analysis Study vendor patches Full disclosure websites Zero day exploit?

Finding Weaknesses Social engineering Impersonation Dumpster diving Nuclear power plant company example Impersonation Dumpster diving Shoulder surfing Fake email For example, ask for passwords Phishing

Virus Hoaxes Example: jdbgmgr.exe I found the little bear in my machine because of that I am sending this message in order for you to find it in your machine. The procedure is very simple: … Known as the teddy bear virus because this is the icon:

Exploitation Engines Developing a buffer overflow attack Metasploit Tedious, lots of trial and error Until Metasploit was invented… Metasploit Knows about lots of attacks Has lots of payloads Doesn’t require much thought/effort

Metasploit Payloads include Bind shell to current port Bind shell to arbitrary port Reverse shell Windows VNC Server DLL inject Reverse VNC DLL inject Inject DLL into running application Create local admin user The Meterpreter (run command of attacker’s choosing)

Metasploit Web Interface

Metasploit Advantages for attackers? Advantages for good guys? Reduces “development cycle” Resulting attacks much more reliable Advantages for good guys? Helps identify false positives Help improve IDS Improved penetration testing Improved management awareness