CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

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.
Introduction to Information Security ROP – Recitation 5 nirkrako at post.tau.ac.il itamarg at post.tau.ac.il.
Procedure Calls Prof. Sirer CS 316 Cornell University.
Computer Architecture CSCE 350
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The University of Adelaide, School of Computer Science
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
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.
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See P&H 2.8 and 2.12.
Programming Project # 1 cs155 Due: Thursday, April 21 st, 11:59pm Shayan Guha Elizabeth Stinson.
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Computer Security Buffer Overflow lab Eu-Jin Goh.
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
Stacks and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Assembly, Stacks, and Registers Kevin C. Su 9/26/2011.
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.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Stack allocation and buffer overflow CSCE 531 Presentation by Miao XU
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.
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
Stack-based buffer overflows Yves Younan DistriNet, Department of Computer Science Katholieke Universiteit Leuven Belgium
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
JMU GenCyber Boot Camp Summer, Introduction to Penetration Testing Elevating privileges – Getting code run in a privileged context Exploiting misconfigurations.
Compiler Construction Code Generation Activation Records
1 Assembly Language: Function Calls Jennifer Rexford.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Section 5: Procedures & Stacks
Introduction to Information Security
Instructions for test_function
Chapter 14 Functions.
MIPS Assembly Language Programming
C function call conventions and the stack
Introduction to Information Security
Exploiting & Defense Day 2 Recap
Introduction to Compilers Tim Teitelbaum
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2013
Prof. Kavita Bala and Prof. Hakim Weatherspoon
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012
Advanced Buffer Overflow: Pointer subterfuge
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
MIPS Instructions.
The University of Adelaide, School of Computer Science
Understanding Program Address Space
EECE.3170 Microprocessor Systems Design I
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2013
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
EECE.3170 Microprocessor Systems Design I
Procedures and Calling Conventions
Where is all the knowledge we lost with information? T. S. Eliot
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.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2010.
Implementing Functions: Overview
Presentation transcript:

CS 155 Section 1 PP1 Eu-Jin Goh

Setting up Environment Demo

target1.c int foo( char *arg, char *out ) { strcpy( out, arg ); return 0; } int main( int argc, char *argv[] ) { char buf[64]; if ( argc != 2 ) { … } foo( argv[1], buf ); return 0; }

Stack in target1 – layout argv[1] == argv[0] == “/tmp/target1” argc $ra – to which main() will return $fp – for main’s stack frame buf[64] ptr to buf == “out”// args to foo() ptr to argv[1] == “arg”// args to foo()

sploit1 Need: 1.Location of return address addr on stack for $ra to overwrite need main()’s $ra (not foo()’s) 2. Address of the buffer (“buf” in target1) address we want to force the program to jump to 3.Distance between buffer and $ra –Size of overflow buffer

Buf addr addr of the target1 buf depends exploit overflow buffer size since exploit string lives above target1 buf on stack Once exploit buffer buf fixed, addr of target1 buf won’t change.

Details 1.Size of overflow buffer Buf addr = 0x9ffffb80 reg ebp = 0x9ffffbc8 Difference is 0x48 = 72 Buffer size = = 81 2.Addr of buf Buf = 0x9ffffe60

Crafting the exploit string Want target to jump to start of buf, place shellcode (size 45 bytes) at the start of the string $ra exists at offset 76 need exploit string[76] to contain the addr target1 buf (0x9ffffe60)

Hints 1.Various ways of seizing program flow control without overwriting return address 2.Learn what registers esp, ebp point to during stages of program execution 3.Learn what happens to registers and memory during LEAVE and RET calls

IA-32 review $esp : Stack Pointer (SP) : points to the top of the stack (lowest mem addy) Points to last used word in stack or next available word location on stack (implementation dependent) $ebp : Frame Pointer (FP) : points to fixed location within an activation record (stack frame) If $ebp for some stack frame is stored at addr X then $eip for that frame is stored at addr X + 4 Used to reference local vars and parameters since the distance from those to the frame pointer will not change whereas the distance from those to the stack pointer will (as other functions are called and the stack pointer is decrem’d …) $eip : instruction pointer (aka $ra) “The instruction pointer (EIP) register contains the offset in the current code segment for the next instruction to be executed.”

More IA-32 review When CALL procedure p(), Push eip : the return address ($ra) Push ebp : saves previous frame pointer Copy sp into fp : ebp = esp The new AR’s frame pointer will be the previous value of the stack pointer Advance sp (esp) for allocations on stack (that is, decrement it) When LEAVE procedure p(), This process is reversed Load ebp into esp Restore ebp from the stack

Interaction between EIP, EBP, ESP During CALL, value of eip register pushed onto stack Before RET, programmer should make sure that stack pointer (esp) is pointing to the eip on the stack; does this via: Move contents of $ebp into $esp Increment $esp by 4 $esp should now point to (contain addy of) $eip RET will load the value stored in $esp into the $eip register then jump to that value

The stack 0x9ffffef8| 0x9fffff9e| argv[1] : f9e = SHELLCODE 0x9ffffef4| 0x9fffff91| argv[0] : f91 = "/tmp/target1" 0x9ffffef0| 2| argc 0x9ffffeb8| 0x9fffff00| <--- argv[1] : f00 points to NULL 0x9ffffeb4| 0x9ffffef4| <--- argv[0] : ef4 points to f91 0x9ffffeb0| 2| <--- argc 0x9ffffeac| __libc_start_main+198 | <--- $ra : what we want to overwrite 0x9ffffea8| 0x9ffffec8| <--- $fp : frame pointer 0x9ffffea4| 0x9ffffef4| <--- argv[0] : ef4 points to f91 0x9ffffea0| _rtld_global| <--- garbage alignment stuff? 0x9ffffe9c|| last word of buf x9ffffe60|| beginning of buf x9ffffe5c|| 0x9ffffe58|| 0x9ffffe54| 0x9ffffe60| argv[1] <-- points to beginning of buf 0x9ffffe50| 0x9fffff9e| argv[0] <-- points to shellcode 0x9ffffe4c| 0x | 0x9ffffe48| 0x9ffffea8| <--- $fp in foo()