CSC 495/583 Topics of Software Security Return-oriented programming

Slides:



Advertisements
Similar presentations
Defenses. Preventing hijacking attacks 1. Fix bugs: – Audit software Automated tools: Coverity, Prefast/Prefix. – Rewrite software in a type safe languange.
Advertisements

Integrity & Malware Dan Fleck CS469 Security Engineering Some of the slides are modified with permission from Quan Jia. Coming up: Integrity – Who Cares?
David Brumley Carnegie Mellon University Credit: Some slides from Ed Schwartz.
Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il.
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.
Part III Counter measures The best defense is proper bounds checking but there are many C/C++ programmers and some are bound to forget  Are there any.
Foundations of Network and Computer Security J J ohn Black Lecture #30 Nov 26 th 2007 CSCI 6268/TLEN 5831, Fall 2007.
Intro to Exploitation Stack Overflows James McFadyen UTD Computer Security Group 10/20/2011.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War.
Andrea Bittau, Adam Belay, Ali Mashtizadeh, David Maziéres, Dan Boneh
1 RISE: Randomization Techniques for Software Security Dawn Song CMU Joint work with Monica Chew (UC Berkeley)
Address Space Layout Permutation
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
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)
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
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
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
Using Memory Management to Detect and Extract Illegitimate Code for Malware Analysis Carsten Willems 1, Thorsten Holz 1, Felix Freiling 2 1 Ruhr-University.
CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.
Exploitation possibilities of memory related vulnerabilities
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 Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
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.
Lecture 9: Buffer Ovefflows and ROP EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014,
Introduction to Information Security ROP – Recitation 5.
Processes and Virtual Memory
On the Effectiveness of Address-Space Randomization Hovav Shacham, Matthew Page, Ben Pfaff, Eu-Jin Goh, Nagendra Modadugu, Dan Boneh.
Buffer Overflows Taught by Scott Coté.-. _ _.-. / \.-. ((___)).-. / \ /.ooM \ / \.-. [ x x ].-. / \ /.ooM \ -/ \ /-----\-----/---\--\ /--/---\-----/-----\ / \-
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.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 1.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade Crispin Cowan SANS 2000.
1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.
Introduction to Information Security
Secure Programming Dr. X
Shellcode COSC 480 Presentation Alison Buben.
Mitigation against Buffer Overflow Attacks
Remix: On-demand Live Randomization
Introduction to Operating Systems
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?
Introduction to Information Security
Jump Over ASLR: Attacking Branch Predictors to Bypass ASLR
CSC 495/583 Topics of Software Security Stack Overflows (2)
CMSC 414 Computer and Network Security Lecture 21
Software Security.
Summary by - Bo Zhang and Shuang Guo [Date: 03/31/2014]
Continuous, Low Overhead, Run-Time Validation of Program Executions
Introduction to Operating Systems
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Software Security Lesson Introduction
Format String.
Address Space Layout Randomization (ASLR) Dirk Gordon
Foundations of Network and Computer Security
Lecture 9: Buffer Overflow*
CSC 495/583 Topics of Software Security Format String Bug (2) & Heap
Dr. Si Chen Class15 CSC 495/583 Topics of Software Security Bypassing ASLR/NX with GOT Overwrite Dr. Si Chen
CSC 495/583 Topics of Software Security StackGuard & Format String Bug
Week 2: Buffer Overflow Part 1.
Week 2: Buffer Overflow Part 2.
Understanding and Preventing Buffer Overflow Attacks in Unix
Return-to-libc Attacks
Presentation transcript:

CSC 495/583 Topics of Software Security Return-oriented programming Class8 CSC 495/583 Topics of Software Security Return-oriented programming (ROP) Dr. Si Chen (schen@wcupa.edu)

Review

Format String Bug

Format String Bug What is a Format String? A Format String is an ASCII string that contains text and format parameters printf("%s %d\n", str, a); fprintf(stderr, "%s %d\n", str, a); sprintf(buffer, "%s %d\n", str, a); E.g. My name is Chen

Format String Bug The wrong way…

Example: fmt_wrong.c

Example: fmt_wrong.c %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x.%08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. %08x. the argument is passed directly to the “printf” function. the function didn’t find a corresponding variable or value on stack so it will start popping values off the stack

Advanced Usage: Format String Direct Access

What is this BUG used for? Disclose sensitive information: Variable(s) EBP value The correct location for putting Shellcode

What is this BUG used for? Disclose StackGuard Canary: By pass stack checking

What is this BUG used for? Read data in any memory address: %s to read data in an arbitrary memory address Write data in any memory address: printf not only allows you to read but also write %n

What is this BUG used for? Disclose Library Address When enable ASLR, the library address will change each time It’s impossible to call these functions in your shellcode (e.g. system()) Use this bug to disclose one function’s address in a given library. you can use it to deduce other function’s address

What is this BUG used for? Disclose Library Address When enable ASLR, the library address will change each time It’s impossible to call these functions in your shellcode (e.g. system()) Use this bug to disclose one function’s address in a given library. you can use it to deduce other function’s address

ELF executable

ELF executable for Linux Executable and Linkable Format (ELF) Linux Windows ELF file .exe (PE) .so (Shared object file) .dll (Dynamic Linking Library) .a .lib (static linking library) .o (intermediate file between complication and linking, object file) .obj

ELF executable for Linux ELF32-bit LSB Dynamically linked

Shared library ELF is loaded by ld-linux.so.2  in charge of memory mapping, load shared library etc.. You can call functions in libc.so.6

Return-oriented programming (ROP)

“Bad” behavior “Good” behavior Attacker code Application code Bad code versus bad behavior “Bad” behavior “Good” behavior Attacker code Application code Problem: this implication is false!

Return-oriented programming thesis any sufficiently large program codebase arbitrary attacker computation and behavior, without code injection (in the absence of control-flow integrity)

Traditional Stack Overflow NOP Sled Payload Saved EIP

Traditional Stack Overflow The simplest stack overflow exploit operates as follows: Send a payload with a NOP sled, shellcodem, and a pointer to the NOP sled The pointer to the NOP sled overwrites the saved return address and thereby takes over the stored EIP EIP now points to the machine code and the program executes arbitrary code

Industry response to code injection exploits Marks all writeable locations in a process’ address space as nonexecutable Deployment: Linux (via PaX patches); OpenBSD; Windows (since XP SP2); OS X (since 10.5); … Hardware support: Intel “XD” bit,AMD “NX” bit (and many RISC processors)

Traditional Stack Overflow Pros Very easy to trigger Simple to understand Being able to inject code means our payloads are powerful and flexible Cons Just make the stack non-­‐executable Lots of problems with bad characters, buffer sizes, payload detection, etc.

Return-to-libc Padding system() exit() “/bin/sh”

Return-to-libc Used primarily to streamline exploitation to bypass mitigation and situational limitations We want to spawn a shell. Send a payload that overwrites the saved EIP with the address of system(), the address of exit(), and a pointer to “/bin/sh” The system call will return directly to exit() which will then shut down the program cleanly

Return-to-libc Divert control flow of exploited program into libc code system(), printf(), … No code injection required Perception of return-into-libc: limited, easy to defeat Attacker cannot execute arbitrary code Attacker relies on contents of libc — remove system()?

Return-to-libc Pros ▫ Does not need executable stack ▫ Also pretty easy to understand and implement Cons ▫ Relies on access to library functions ▫ Can only execute sequential instructions, no branching or fancy stuff ▫ Can only use code in .text and loaded libraries

Mitigation against these classical attacks attacks Address Space Layout Randomization (ASLR) No execute bit

Address Space Layout Randomization (ASLR) Map your Heap and Stack randomly At each execution, your Heap and Stack will be mapped at different places It's the same for shared libraries So, now you cannot jump on an hardened address like in a classical attack

Address Space Layout Randomization (ASLR) Three executions of the same binary :

Data Execution Prevention (DEP): No eXecute bit (NX) NX bit is a CPU feature – On Intel CPU, it works only on x86_64 or with Physical Address Extension (PAE) enable Enabled, it raises an exception if the CPU tries to execute something that doesn't have the NX bit set The NX bit is located and setup in the Page Table Entry

Page Table Each process in a multi-tasking OS runs in its own memory sandbox. This sandbox is the virtual address space, which in 32-bit mode is always a 4GB block of memory addresses. These virtual addresses are mapped to physical memory by page tables, which are maintained by the operating system kernel and consulted by the processor. Each process has its own set of page tables. 

Page Table To each virtual page there corresponds one page table entry (PTE) in the page tables, which in regular x86 paging is a simple 4-byte record shown below:

Data Execution Prevention (DEP): No eXecute bit (NX) The last bit is the NX bit (exb) ● – 0 = disabled 1 = enabled –

Return-Oriented Programming: Exploits Without Code Injection ROP Introduction When Good Instructions Go Bad: Generalizing Return-Oriented Programming to RISC [1] -Buchanan, E.; Roemer, R.; Shacham, H.; Savage, S. (October 2008) ● Return-Oriented Programming: Exploits Without Code Injection [2] - Shacham, Hovav; Buchanan, Erik; Roemer, Ryan; Savage, Stefan. Retrieved 2009-08-12. ●

Ordinary programming: the machine level insn instruction pointer Instruction pointer (%eip) determines which instruction to fetch & execute Once processor has executed the instruction, it automatically increments %eip to next instruction Control flow by changing value of %eip

Return-oriented programming: the machine level insns … ret insns … ret C library insns … ret insns … ret insns … ret stack pointer Stack pointer (%esp) determines which instruction sequence to fetch & execute Processor doesn’t automatically increment %esp; — but the “ret” at end of each instruction sequence does

ROP: The Main Idea

ROP Gadget “The Gadget”: July 1945

Attack Process on x86 So, the real execution is: Gadget1 is executed and returns Gadget2 is executed and returns Gadget3 is executed and returns So, the real execution is: ●

Several ways to find gadgets How can we find gadgets? Several ways to find gadgets Old school method : objdump and grep Some gadgets will be not found: objdump aligns instructions Make your own tool which scans an executable segment Use an existing tool

Finding instruction sequences Any instruction sequence ending in “ret” is useful — could be part of a gadget Algorithmic problem: recover all sequences of valid instructions from libc that end in a “ret” insn Idea: at each ret (c3 byte) look back: are preceding i bytes a valid length-i insn? recurse from found instructions Collect instruction sequences in a trie

ROPgadget

Q & A