Assembly, Stacks, and Registers Kevin C. Su 9/26/2011.

Slides:



Advertisements
Similar presentations
Calling sequence ESP.
Advertisements

15/18-213: Introduction to Computer Systems
Recitation 4 Outline Buffer overflow –Practical skills for Lab 3 Code optimization –Strength reduction –Common sub-expression –Loop unrolling Reminders.
Smashing the Stack for Fun and Profit
University of Washington Procedures and Stacks II The Hardware/Software Interface CSE351 Winter 2013.
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
David Brumley Carnegie Mellon University Credit: Some slides from Ed Schwartz.
Review: Software Security David Brumley Carnegie Mellon University.
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
RECITATION - 09/20/2010 BY SSESHADR Buflab. Agenda Reminders  Bomblab should be finished up  Exam 1 is on Tuesday 09/28/2010 Stack Discipline Buflab.
Security Protection and Checking in Embedded System Integration Against Buffer Overflow Attacks Zili Shao, Chun Xue, Qingfeng Zhuge, Edwin H.-M. Sha International.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
September 22, 2014 Pengju (Jimmy) Jin Section E
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
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-
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Fall 2008CS 334: Computer SecuritySlide #1 Smashing The Stack A detailed look at buffer overflows as described in Smashing the Stack for Fun and Profit.
Carnegie Mellon Introduction to Computer Systems /18-243, spring 2009 Recitation, Jan. 14 th.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
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.
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.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
Reminder Bomb lab is due tomorrow! Attack lab is released tomorrow!!
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.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Analyzing C/C++ Vulnerabilities -- Mike Gerschefske.
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.
Section 5: Procedures & Stacks
Exploiting & Defense Day 1 Recap
Buffer Overflows ...or How I Learned to Never Trust the User
Buffer Overflow Buffer overflows are possible because C doesn’t check array boundaries Buffer overflows are dangerous because buffers for user input are.
CS 177 Computer Security Lecture 9
Instructions for test_function
Recitation 5: Attack Lab
C function call conventions and the stack
The Hardware/Software Interface CSE351 Winter 2013
CSCE 212 Computer Architecture
Recitation: Attack Lab
143A: Principles of Operating Systems Lecture 4: Calling conventions
Exploiting & Defense Day 2 Recap
Introduction to Compilers Tim Teitelbaum
The Stack & Procedures CSE 351 Spring 2017
Introduction to Computer Systems
Recitation: Attack Lab
CMSC 414 Computer and Network Security Lecture 21
Machine-Level Programming III: Procedures /18-213/14-513/15-513: Introduction to Computer Systems 7th Lecture, September 18, 2018.
Carnegie Mellon Machine-Level Programming III: Procedures : Introduction to Computer Systems October 22, 2015 Instructor: Rabi Mahapatra Authors:
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
Recitation: Attack Lab
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
MIPS Instructions.
Smashing the Stack for Fun and Profit
The Stack & Procedures CSE 351 Winter 2018
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
X86 Assembly Review.
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.
Return-to-libc Attacks
Presentation transcript:

Assembly, Stacks, and Registers Kevin C. Su 9/26/2011

 BombLab  Assembly review  Stacks ◦ EBP / ESP  Stack Discipline  Buffer Overflow  BufLab  Summary

 Hopefully everyone has started by now  If there are any questions/if you need help, ◦ the staff list: ◦ Office hours: Sun-Thurs 5:30 to 8:30  Due tomorrow at midnight.

 BombLab  Assembly Review  Stacks ◦ EBP / ESP  Stack Discipline  Buffer Overflow  BufLab  Summary

 Instructions ◦ mov ◦ add/sub/or/and/… ◦ leal ◦ test/cmp ◦ jmp/je/jg/…  Differences between ◦ test / and ◦ mov / leal

 x86 ◦ 6 General Purpose Registers ◦ EBP / ESP  x86-64 ◦ 14 General Purpose Registers ◦ RBP / RSP ◦ Difference between RAX and EAX

 x86 ◦ Argument 1: %ebp+8 ◦ Argument 2: %ebp+12 ◦ …  x86-64 ◦ Argument 1: %rdi ◦ Argument 2: %rdx ◦ …

 Assembly  Stacks ◦ EBP / ESP  Stack Discipline  Buffer Overflow  BufLab  Summary

 Vital role in handling procedure calls  Similar to “Stack” data structure  FILO  %esp => points to the top of the stack  %ebp => points to the base of the stack

 Example stack ◦ foo calls:  bar(argument 1)

 PUSH – pushes an element onto the stack

 POP – pops an element off of the stack

 Stack layout for a function call

 Function Parameters ◦ Pushed on by the calling function  First parameter starts at %EBP + 8 ◦ Why?  Calling foo(x, y, z) ◦ In what order do we push the arguments on the stack and why?

 Return address ◦ What is it’s address in terms of %EBP?  For the called function to return  (This will be a target for buflab)

 Saved %EBP ◦ Positioned above the last stack frame  Remember, ◦ %ESP = %EBP ◦ %EBP = popped old %EBP ◦ Pop the return address  %EBP and %ESP are back to their old values

 Next is space for all local variables ◦ What happens to them after the function is over?  This is where the buffer overflow will occur  Callee may also have to save registers

 BombLab  Assembly Review  Stacks ◦ EBP / ESP  Stack Discipline  Buffer Overflow  BufLab  Summary

 %ebp ◦ Where does it point? ◦ What happens during a function call?  %esp ◦ Where does it point? ◦ What happens during a function call?

 Order of objects on the stack ◦ Argument 2 ◦ Argument 1 ◦ Return Address ◦ Saved %ebp ◦ Local variables for called function  Grows downwards!

 Calling a function ◦ Push arguments ◦ Push return address ◦ Jump to new function ◦ Save old %ebp on stack ◦ Subtract from stack pointer to make space

 Returning ◦ Pop the old %ebp ◦ Pop the return address and return to it  Think eip = stack.pop()

 Useful things ◦ Return address  %ebp + 4 ◦ Old %ebp  %ebp ◦ Argument 1  %ebp + 8 ◦ Argument 2  %ebp + 12

 BombLab  Assembly Review  Stacks ◦ EBP / ESP  Buffer Overflow  BufLab  Summary

 Covered in lecture tomorrow ◦ Make sure to pay attention!  Seminal Paper ◦ Smashing the Stack for Fun and Profit  A method of gaining control over a program  Actual exploitation ◦ Server is running a program ◦ Buffer Overflow vulnerability ◦ Take control of program => Take control of server

 Calling the function foo(1, 2) ◦ Note how the stack is set up (useful for BufLab) 0x Argument 2 0x Argument 1 0x A AD Return Address 0xFF FF FF C8 Old %EBP BUF[11] BUF[10] BUF[9] BUF[8] Last 4 bytes of BUF BUF[7] BUF[6] BUF[5] BUF[4] Middle 4 bytes of BUF BUF[3] BUF[2] BUF[1] BUF[0] First 4 bytes of BUF …

 strcpy(BUF, userInput) //char BUF[12]  Let user input = 0x ABCDEFDEADBEEEF 0x Argument 2 0x Argument 1 0x A AD Return Address 0xFF FF FF C8 Old %EBP BUF[11] BUF[10] BUF[9] BUF[8] Last 4 bytes of BUF BUF[7] BUF[6] BUF[5] BUF[4] Middle 4 bytes of BUF BUF[3] BUF[2] BUF[1] BUF[0] First 4 bytes of BUF …

 Let user input = 0x ABCDEFDEADBEEEF  First 4 copied in (What’s the endianness?) 0x Argument 2 0x Argument 1 0x A AD Return Address 0xFF FF FF C8 Old %EBP BUF[11] BUF[10] BUF[9] BUF[8] Last 4 bytes of BUF BUF[7] BUF[6] BUF[5] BUF[4] Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Let user input = 0x ABCDEFDEADBEEEF  Next 4 0x Argument 2 0x Argument 1 0x A AD Return Address 0xFF FF FF C8 Old %EBP BUF[11] BUF[10] BUF[9] BUF[8] Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Let user input = 0x ABCDEFDEADBEEF  Last 4 available bytes 0x Argument 2 0x Argument 1 0x A AD Return Address 0xFF FF FF C8 Old %EBP 0xEF BE AD DE Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Let user input = 0x ABCDEFDEADBEEF  What if the user entered in 8 more bytes? 0x Argument 2 0x Argument 1 0x A AD Return Address 0xFF FF FF C8 Old %EBP 0xEF BE AD DE Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Let user input = 0x ABCDEFDEADBEEF  Concatenate 0x x Argument 2 0x Argument 1 0x A AD Return Address 0x Old %EBP 0xEF BE AD DE Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Let user input = 0x ABCDEFDEADBEEF  Concatenate 0x x Argument 2 0x Argument 1 0x Return Address 0x Old %EBP 0xEF BE AD DE Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Oh no! We’ve overwritten the return address  What happens when the function returns? 0x Argument 2 0x Argument 1 0x Return Address 0x Old %EBP 0xEF BE AD DE Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Function will return to 0x ◦ Controlled by user 0x Argument 2 0x Argument 1 0x Return Address 0x Old %EBP 0xEF BE AD DE Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 Instead of entering garbage, we could’ve entered arbitrary code. Then we’d have control of the program. 0x Argument 2 0x Argument 1 0x Return Address 0x Old %EBP 0xEF BE AD DE Last 4 bytes of BUF 0xEF CD AB 90 Middle 4 bytes of BUF 0x First 4 bytes of BUF …

 BombLab  Assembly Review  Stacks ◦ EBP / ESP  Buffer Overflow  BufLab  Summary

 Buffer Overflows are the premise of BufLab  You will inject code, then make the program execute your code  You can use this to branch to other existing functions, set arbitrary values in variables, or execute anything you want!

 BombLab  Assembly Review  Stacks ◦ EBP / ESP  Buffer Overflow  BufLab  Summary

 Purpose of %ebp  Purpose of %esp

 Essential for function calls  3 important things stored on stack: ◦ Arguments ◦ Return address ◦ Old %EBP  Which would be a target for BufLab?

 Unbounded string copy  Allow a user to overwrite any part of the stack  Can execute arbitrary code ◦ Set variables ◦ Call functions ◦ Shellcode too

 Pick up your datalabs.  Style grading: ◦ Comments ◦ Clear code, broken into logical pieces ◦ Meaningful variable names  If you haven’t corrected your recitation in autolab, please do it after this class.

 Questions?  Good luck on BufLab (out tomorrow).