Https://inst.eecs.berkeley.edu/~cs161/su19/feedback Overflows, Injection, & Memory Safety https://inst.eecs.berkeley.edu/~cs161/su19/feedback.

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
1 Computer Architecture MIPS Simulator and Assembly language.
User-Level Memory Management in Linux Programming
Week 7 - Friday.  What did we talk about last time?  Allocating 2D arrays.
C and Data Structures Baojian Hua
Netprog: Buffer Overflow1 Buffer Overflow Exploits Taken shamelessly from: netprog/overflow.ppt.
Memory Layout C and Data Structures Baojian Hua
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.
Software bugs (and security implications). Software security Code can have perfect design and algorithm, but still have implementation vulnerabilities.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
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.
Buffer Overflow Computer Organization II 1 © McQuain Buffer Overflows Many of the following slides are based on those from Complete Powerpoint.
University of Washington Today Memory layout Buffer overflow, worms, and viruses 1.
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.
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
University of Washington Today Happy Monday! HW2 due, how is Lab 3 going? Today we’ll go over:  Address space layout  Input buffers on the stack  Overflowing.
Overflow Examples 01/13/2012. ACKNOWLEDGEMENTS These slides where compiled from the Malware and Software Vulnerabilities class taught by Dr Cliff Zou.
Buffer Overflows Many of the following slides are based on those from
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.
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.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2015.
Sairajiv Burugapalli. This chapter covers three main categories of classic software vulnerability: Buffer overflows Integer vulnerabilities Format string.
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.
CS426Fall 2010/Lecture 141 Computer Security CS 426 Lecture 14 Software Vulnerabilities: Format String and Integer Overflow Vulnerabilities.
C is a high level language (HLL)
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
CS 3214 Computer Systems Godmar Back Lecture 7. Announcements Stay tuned for Project 2 & Exercise 4 Project 1 due Sep 16 Auto-fail rule 1: –Need at least.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou Spring 2010.
CSC 482/582: Computer Security
Refs: rootshell, antionline, your favorite hacker site…
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.
Introduction to Information Security
The Hardware/Software Interface CSE351 Winter 2013
Machine-Level Programming V: Miscellaneous Topics
Module 30 (Unix/Linux Security Issues II)
CSCI206 - Computer Organization & Programming
CNT4704: Computer Networking Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2009.
Basic Control Hijacking Attacks
Software Security.
CSC 253 Lecture 8.
CSC 253 Lecture 8.
Memory Allocation CS 217.
Format String.
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
Pointers The C programming language gives us the ability to directly manipulate the contents of memory addresses via pointers. Unfortunately, this power.
Dynamic Memory A whole heap of fun….
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
The future of Software Security Dr. Si Chen
Malware and Software Vulnerability Analysis Buffer Overflow I: Attack Introduction Cliff Zou University of Central Florida.
Introduction to Static Analyzer
Buffer Overflows.
CNT4704: Analysis of Computer Communication Network Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2011.
Instructors: Majd Sakr and Khaled Harras
“Way easier than when we were students”
Understanding and Preventing Buffer Overflow Attacks in Unix
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
Week 7 - Friday CS222.
Format String Vulnerability
CSE 303 Concepts and Tools for Software Development
Presentation transcript:

https://inst.eecs.berkeley.edu/~cs161/su19/feedback Overflows, Injection, & Memory Safety https://inst.eecs.berkeley.edu/~cs161/su19/feedback

Announcements... HW0 due tonight! Find project partners Solo or with a partner, it is up to you Discussion size 101 > 102 > 103

SHIT... OR NET OF A MILLION SPIES

Internet of Shit... A device produced by the lowest bidder... That you then connect through the network This has a very wide attack surface Methods where an attacker might access a vulnerability And its often incredibly cost sensitive Very little support after purchase So things don't get patched No way for the user to tell what is "secure" or "not" But they can tell what is cheaper! And often it is insanely insecure: Default passwords on telnet of admin/admin... Trivial buffer overflows

Net Of A Million Spies... Device only communicates through a central service Greatly reduces the attack surface but... Most of the companies running the service are "Data Asset" companies Make their money from advertising, not the product themselves May actually subsidize the product considerably Some you know about: Google, Amazon Some you may not: Salesforce

#293 HRE-THR 850 1930 ALICE SMITH COACH SPECIAL INSTRUX: NONE

How could Alice exploit this? Find a partner and talk it through. #293 HRE-THR 850 1930 ALICE SMITHHHHHHHHHHH HHACH SPECIAL INSTRUX: NONE How could Alice exploit this? Find a partner and talk it through.

#293 HRE-THR 850 1930 ALICE SMITH FIRST SPECIAL INSTRUX: NONE

#293 HRE-THR 850 1930 ALICE SMITH FIRST SPECIAL INSTRUX: TREAT AS HUMAN. Passenger last name: “Smith First Special Instrux: Treat As Human.”

char name[20]; void vulnerable() { ... gets(name); }

char name[20]; char instrux[80] = "none"; void vulnerable() { ... gets(name); }

char name[20]; int seatinfirstclass = 0; void vulnerable() { ... gets(name); }

char name[20]; int authenticated = 0; void vulnerable() { ... gets(name); }

char line[512]; char command[] = "/usr/bin/finger"; void main() { ... gets(line); execv(command, ...); }

char name[20]; int (*fnptr)(); void vulnerable() { ... gets(name); }

void vulnerable() { char buf[64]; ... gets(buf); }

void still_vulnerable?() { char *buf = malloc(64); ... gets(buf); }

text segment (program) Linux (32-bit) process memory layout -0xFFFFFFFF Reserved for Kernel user stack shared libraries run time heap static data segment text segment (program) unused -0xC0000000 -0x40000000 -0x08048000 $esp brk Loaded from exec -0x00000000

text segment (program) callee saved registers -0xC0000000 -0x40000000 -0x08048000 -0x00000000 user stack shared libraries run time heap static data segment text segment (program) unused arguments return address stack frame pointer exception handlers local variables callee saved registers To previous stack frame pointer To the point at which this function was called

void safe() { char buf[64]; ... fgets(buf, 64, stdin); }

void safer() { char buf[64]; ... fgets(buf,sizeof(buf),stdin); }

void vulnerable(int len, char *data) { char buf[64]; if (len > 64) Assume these are both under the control of an attacker. void vulnerable(int len, char *data) { char buf[64]; if (len > 64) return; memcpy(buf, data, len); } memcpy(void *s1, const void *s2, size_t n); size_t is unsigned: What happens if len == -1?

void safe(size_t len, char *data) { char buf[64]; if (len > 64) return; memcpy(buf, data, len); }

void f(size_t len, char *data) { char *buf = malloc(len+2); if (buf == NULL) return; memcpy(buf, data, len); buf[len] = '\n'; buf[len+1] = '\0'; } Is it safe? Talk to your partner. Vulnerable! If len = 0xffffffff, allocates only 1 byte

void vulnerable() { char buf[64]; if (fgets(buf, 64, stdin) == NULL) return; printf(buf); }

printf("you scored %d\n", score);

printf("a %s costs $%d\n", item, price);

Fun With printf format strings... Format argument is missing! printf("100% dude!");

More Fun With printf format strings... printf("100% dude!"); Þ prints value 4 bytes above retaddr as integer printf("100% sir!"); Þ prints bytes pointed to by that stack entry up through first NUL printf("%d %d %d %d ..."); Þ prints series of stack entries as integers printf("%d %s"); Þ prints value 4 bytes above retaddr plus bytes pointed to by preceding stack entry printf("100% nuke’m!"); What does the %n format do??

%n writes the number of characters printed so far into the corresponding format argument. int report_cost(int item_num, int price) { int colon_offset; printf("item %d:%n $%d\n", item_num, &colon_offset, price); return colon_offset; } report_cost(3, 22) prints "item 3: $22" and returns the value 7 report_cost(987, 5) prints "item 987: $5" and returns the value 9

%hn is the same, but writes a short instead of int %n writes the number of characters printed so far into the corresponding format argument. int report_cost(int item_num, int price) { short int colon_offset; printf("item %d:%hn $%d\n", item_num, &colon_offset, price); return colon_offset; } report_cost(3, 22) prints "item 3: $22" and returns the value 7 report_cost(987, 5) prints "item 987: $5" and returns the value 9

Fun With printf format strings... printf("100% dude!"); Þ prints value 4 bytes above retaddr as integer printf("100% sir!"); Þ prints bytes pointed to by that stack entry up through first NUL printf("%d %d %d %d ..."); Þ prints series of stack entries as integers printf("%d %s"); Þ prints value 4 bytes above retaddr plus bytes pointed to by preceding stack entry printf("100% nuke’m!"); Þ writes the value 3 to the address pointed to by stack entry

void safe() { char buf[64]; if (fgets(buf, 64, stdin) == NULL) return; printf("%s", buf); }

And Now: Lets Walk Through A Stack Overflow Idea: We override a buffer on the stack... In the buffer we place some code of our choosing "Shellcode" Override the return address to point to code of our choosing Lets step through the process on an x86...