Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.

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
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Basic Control Hijacking Attacks
Avishai Wool, lecture Introduction to Information Security Lecture 1.
1 Information Security – Theory vs. Reality , Winter 2011 Lecture 8: Control hijacking attacks Eran Tromer Slides credit: Dan Boneh, Stanford.
Intro to Exploitation Stack Overflows James McFadyen UTD Computer Security Group 10/20/2011.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
1 Control Hijacking Attacks Buffer overflows and format string bugs.
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 Control Hijacking Attacks Buffer overflows and format string bugs.
Control Hijacking Attacks Note: project 1 is out Section this Friday 4:15pm.
1 Buffer Overflow Attacks and Format String bugs.
Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.
CS426Fall 2010/Lecture 111 Computer Security CS 426 Lecture 11 Software Vulnerabilities: Input Validation Issues & Buffer Overflows.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2012.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Buffer overflows.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Control Hijacking Attacks
System Programming Topic 19
1 System Programming Topic 19 Software Vulnerabilities Topic 19: Software Vulnerabilities.
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.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Avishai Wool, lecture Introduction to Information Security Lecture 1.
Introduction to Honeypot, measurement, and vulnerability exploits
Overflow Examples 01/13/2012. ACKNOWLEDGEMENTS These slides where compiled from the Malware and Software Vulnerabilities class taught by Dr Cliff Zou.
Buffer Overflow. Introduction On many C implementations, it is possible to corrupt the execution stack by writing past the end of an array. Known as smash.
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
Section 3.4: Buffer Overflow Attack: Attack Techniques 1.
Control Hijacking Attacks Note: project 1 is out Section this Friday 2pm (Skilling 090)
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.
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.
Slides by Kent Seamons and Tim van der Horst Last Updated: Nov 11, 2011.
Control Hijacking Attacks Note: project 1 is out Section this Friday 4:15pm (Gates B03)
CS426Fall 2010/Lecture 141 Computer Security CS 426 Lecture 14 Software Vulnerabilities: Format String and Integer Overflow Vulnerabilities.
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Basic of Buffer Over Flow
Software Security. Bugs Most software has bugs Some bugs cause security vulnerabilities Incorrect processing of security related data Incorrect processing.
1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2010.
Refs: rootshell, antionline, your favorite hacker site…
Basic Control Hijacking Attacks
Introduction to Information Security
Introduction to Information Security , Spring 2016 Lecture 1: Introduction, Control Hijacking (1/2) Avishai Wool.
Basic Memory Corruption Attacks
Secure Software Development: Theory and Practice
Basic Memory Corruption Attacks
Information Security CS 526 Topic 8
CNT4704: Computer Networking Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2009.
Basic Control Hijacking Attacks
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Objective Explain basic fuzzing with concrete coding example
Preventing Buffer Overflow Attacks
CS703 - Advanced Operating Systems
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.
CNT4704: Analysis of Computer Communication Network Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2011.
Malware and Software Vulnerability Analysis Fuzzing Test Example Cliff Zou University of Central Florida.
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
Overflows, Injection, & Memory Safety
Presentation transcript:

Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control flow This lecture: three examples. – Buffer overflow attacks – Integer overflow attacks – Format string vulnerabilities

1. Buffer overflows Extremely common bug. – First major exploit: 1988 Internet Worm. fingerd. Developing buffer overflow attacks: – Locate buffer overflow within an application. – Design an exploit. Source: NVD/CVE  20% of all vuln :  10%

What is needed Understanding C functions and the stack Some familiarity with machine code Know how systems calls are made The exec() system call Attacker needs to know which CPU and OS are running on the target machine: – Our examples are for x86 running Linux – Details vary slightly between CPUs and OSs: Little endian vs. big endian ( x86 vs. Motorola ) Stack Frame structure (Unix vs. Windows) Stack growth direction

Linux process memory layout unused 0x run time heap shared libraries user stack 0x xC %esp brk Loaded from exec 0

Stack Frame Parameters Return address Stack Frame Pointer Local variables SP Stack Growth

What are buffer overflows? Suppose a web server contains a function: void func(char *str) { char buf[128]; strcpy(buf, str); do-something(buf); } When the function is invoked the stack looks like: What if *str is 136 bytes long? After strcpy : strret-addrsfpbuf top of stack str top of stack *str ret

Basic stack exploit Problem: no range checking in strcpy(). Suppose *str is such that after strcpy stack looks like: When func() exits, the user will be given a shell ! Note: attack code runs in stack. To determine ret guess position of stack when func() is called top of stack *str ret Code for P Program P: exec( “/bin/sh” ) (exact shell code by Aleph One)

Many unsafe C lib functions strcpy (char *dest, const char *src) strcat (char *dest, const char *src) gets (char *s) scanf ( const char *format, … ) “Safe” versions strncpy(), strncat() are misleading – strncpy() may leave buffer unterminated. – strncpy(), strncat() encourage off by 1 bugs.

Exploiting buffer overflows Suppose web server calls func() with given URL. – Attacker sends a 200 byte URL. Gets shell on web server Some complications: – Program P should not contain the ‘\0’ character. – Overflow should not crash program before func() exists. Sample remote buffer overflows of this type: – (2005) Overflow in MIME type field in MS Outlook. – (2005) Overflow in Symantec Virus Detection Set test = CreateObject("Symantec.SymVAFileQuery.1") test.GetPrivateProfileString "file", [long string]

Control hijacking opportunities Stack smashing attack: – Override return address in stack activation record by overflowing a local buffer variable. Function pointers: (e.g. PHP 4.0.2, MS MediaPlayer Bitmaps) – Overflowing buf will override function pointer. Longjmp buffers: longjmp(pos) (e.g. Perl 5.003) – Overflowing buf next to pos overrides value of pos. Heap or stack buf[128] FuncPtr

Heap-based control hijacking Compiler generated function pointers (e.g. C++ code) Suppose vtable is on the heap next to a string object: ptr data Object T FP1 FP2 FP3 vtable method #1 method #2 method #3 ptr buf[256] data object T vtable

Heap-based control hijacking Compiler generated function pointers (e.g. C++ code) After overflow of buf we have: ptr data Object T FP1 FP2 FP3 vtable method #1 method #2 method #3 ptr buf[256] data object T vtable shell code

Other types of overflow attacks Integer overflows: (e.g. MS DirectX MIDI Lib) Phrack60 void func(int a, char v) { char buf[128]; init(buf); buf[a] = v; } – Problem: a can point to `ret-addr’ on stack.

Integer overflow : Example int main(int argc, char **argv) { char buf[80]; unsigned short s; int i; i = atoi(argv[1]); s = i; if(s >= 80) { error_msg(); return -1; } memcpy(buf, argv[2], i); } What happens if called with argv[1] = 65536?

Double Free Double free : double free space on heap. – Can cause mem mgr to write data to specific location – Examples: CVS server

Source: NVD/CVE Integer overflow stats

Finding buffer overflows To find overflow: – Run web server on local machine – Issue requests with long tags All long tags end with “$$$$$” – If web server crashes, search core dump for “$$$$$” to find overflow location Many automated tools exist (called fuzzers – next lecture) Then use disassemblers and debuggers (e.g. IDA-Pro ) to construct exploit

Format string bugs

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); }

History First exploit discovered in June Examples: – wu-ftpd 2.* :remote root – Linux rpc.statd:remote root – IRIX telnetd:remote root – BSD chpass:local root

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

Exploit Dumping arbitrary memory: – Walk up stack until desired pointer is found. – printf( “%08x.%08x.%08x.%08x|%s|”) Writing to arbitrary memory: – printf( “hello %n”, &temp) -- writes ‘6’ into temp. – printf( “%08x.%08x.%08x.%08x.%n”)

Overflow using format string char errmsg[512], outbuf[512]; sprintf (errmsg, “Illegal command: %400s”, user); sprintf( outbuf, errmsg ); What if user = “%500d ” – Bypass “%400s” limitation. – Will overflow outbuf.