Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il.

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

ROP is Still Dangerous: Breaking Modern Defenses Nicholas Carlini et. al University of California, Berkeley USENIX Security 2014 Presenter: Yue Li Part.
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.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
David Brumley Carnegie Mellon University Credit: Some slides from Ed Schwartz.
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Review: Software Security David Brumley Carnegie Mellon University.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
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)
Carnegie Mellon Introduction to Computer Systems /18-243, spring 2009 Recitation, Jan. 14 th.
Mitigation of Buffer Overflow Attacks
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
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)
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
CNIT 127: Exploit Development Ch 1: Before you begin.
Introduction to Information Security ROP – Recitation 5.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Where’s the FEEB?: Effectiveness of Instruction Set Randomization Nora Sovarel, David Evans, Nate Paul University of Virginia Computer Science USENIX Security.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
Buffer Overflow Attack- proofing of Code Binaries Ramya Reguramalingam Gopal Gupta Gopal Gupta Department of Computer Science University of Texas at Dallas.
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.
EXPLOITATION CRASH COURSE – FALL 2013 UTD Computer Security Group – Andrew Folloder csg.utdallas.edu (credit: Scott Hand)
1 Assembly Language: Function Calls Jennifer Rexford.
Introduction to InfoSec – Recitation 3 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (infosec15 at modprobe.net)
ROP Exploit. ROP Return Oriented Programming (ROP): is a hacking exploit technique where you exploit buffer overflow to inject a chain of gadgets. Each.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
1 Introduction to Information Security , Spring 2016 Lecture 2: Control Hijacking (2/2) Avishai Wool.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
9/30/20161 Defeating DEP, the Immunity Debugger way Pablo Solé Immunity.
Introduction to Information Security
Mitigation against Buffer Overflow Attacks
Return Oriented Programming
Jump-Oriented Programming
Introduction to Information Security
Homework Reading Labs PAL, pp
Introduction to Information Security
Exploiting & Defense Day 2 Recap
Aaron Miller David Cohen Spring 2011
Homework In-line Assembly Code Machine Language
Assembly Language Programming Part 2
CSC 495/583 Topics of Software Security Return-oriented programming
Assembly Language Programming V: In-line Assembly Code
CMSC 414 Computer and Network Security Lecture 21
Summary by - Bo Zhang and Shuang Guo [Date: 03/31/2014]
Assembly Language Programming II: C Compiler Calling Sequences
Fundamentals of Computer Organisation & Architecture
Practical Session 4.
Lecture 9: Buffer Overflow*
Homework Reading Machine Projects Labs PAL, pp
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
Multi-modules programming
Week 2: Buffer Overflow Part 1.
Week 2: Buffer Overflow Part 2.
CSC 497/583 Advanced Topics in Computer Security
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.
System and Cyber Security
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Return-to-libc Attacks
Presentation transcript:

Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il

Return Oriented Programming Return oriented programming is a different way to control the flow of EIP in a program Motivation: Write or Execute: as a result of overflows, the first prevention technique is to make: o Executable memory segments read-o o nly o Writeable memory segments Non-Executable. Most slides in this presentation were taken as is from: Return-oriented Programming: Exploitation without Code Injection By Erik Buchanan, Ryan Roemer, Stefan Savage, Hovav Shacham from the University of California, San Diego

Getting started Need control of memory around %esp Rewrite stack: o Buffer overflow on stack o Format string vuln to rewrite stack contents Move stack: o Overwrite saved frame pointer on stack; on leave/ret, move %esp to area under attacker control o Overflow function pointer to a register spring for %esp: o set or modify %esp from an attacker-controlled register o then return

Schematic: return to libc Control hijacking without executing code Avishai Wool, lecture args ret-addr sfp local buf stack exec() printf() “/bin/sh” libc.so

Return to libc Stack progress trace

Returning to Code Chunks (aka Gadgets) Instead of working with small “opcodes” and %eip, we now use larger chunks of code and %esp All the “larger chunks” do multiple register manipulations, and we must consider the effect of all of them. Not everything we want is possible directly, so we have to be creative and work around the problem. All chunks end with 0xc3 (RET) We are effectively using a new ‘language’ to code.

Chunk guidelines All chunk ends with 0xc3 Chunks should be as minimal as possible, containing minimum amount of data Chunks are better if they appear in more “stable” and common libraries such as: libc. (and can then be reused for different binaries). Chunks can not contain Junks. o If the CPU can not interpret the junk in the chunk, it will stop the program with illegal instruction exception.

ROP – Machine level Stack pointer (%esp) determines which instruction sequence to fetch & execute o Processor doesn’t automatically increment %esp; — but the “ret” at end of each instruction sequence does

No-op equivalent No-op instruction does nothing but advance %eip o Return-oriented equivalent: o point to return instruction o advances %esp o Useful in nop sled

Loading Immediates Instructions can encode constants Return-oriented equivalent: o Store on the stack; o Pop into register to use

Control flow Ordinary programming: o (Conditionally) set %eip to new value Return-oriented equivalent: o (Conditionally) set %esp to new value

Multiple instruction sequence Sometimes more than one instruction sequence needed o to encode logical unit Example: load from memory into register: o Load address of source word into %eax o Load memory at (%eax) into %ebx

Conditional Jump #0 Negative causes the carry flag to be turn on. Carry flag can be used in conjunction with ADC.

Conditional Jump #1 ADDR TO: XOR EAX,EAX ; RET ADDR TO: POP ECX ; RET DWORD 0 ADDR TO: ADC CL, AL ; RET ADDR TO: ROL ECX, 1; RET ADDR TO: XCHG EAX, ECX ; RET ADDR TO: ADD ESP, EAX ; RET. ADDR TO: POP ESP ; RET # Go somewhere else. ADDR TO: EXIT

Gadget summary We can write complex shellcode by returning to relevant gadgets. All gadgets end with ret. (0xc3) Gadgets can not contain junk (everything must be interpretable) “JMP” is analogous to finding code that modifies the ESP. We don’t have to maintain the original alignment of code (on x86). Example: o MOV EAX, 0x5DC3 o This is interpreted into: B8 5D C3 o However, o POP EBP o RETN o This is interpreted into: o 5D C3 Using rop_ptrace.py we debug the executable and are able to locate relevant gadgets To have we everything flowing correctly and make sure we are aware of where ESP and EIP are pointing to at all times.

Infosec ROP Tools./rop_ptrace.py./memmap.py./disas_at_va.py

./rop_ptrace.py./rop_ptrace.py o Usage:./rop_ptrace.py [filename] [depth] “OPCODE” rop_ptrace.py helps you by loading the binary into memory, therefore causing the creation of all linked shared objects (SO). The list of libraries can also be shown via shell command ‘ldd filename’. After loading the binary and waiting for the SOs to load it will search for code chunks ending with ROP and then look back until [depth] bytes. rop_ptrace.py then codes and disassembles the chunk rop_ptrace.py uses distorm3 to disassemble and python- ptrace library to debug the executable.

./rop_ptrace.py cont. [rop_ptrace.py example]

./memmap.py Usage:./memmap.py [filename] o Prints the libraries, memories mapped to, and their permissions. Usage:./memmap.py [filename] [string] o Attempts to locate the string within the mapped memory sections. memmap.py uses python-ptrace

./memmap.py cont. [memmap.py example]

./disas_at_va.py cont. disas_at_va.py [filename] [va] [length] o Disassembles [length] number of bytes at virtual address [va] after loading the binary [filename] to memory. Uses python-ptrace and distorm3.