Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.

Slides:



Advertisements
Similar presentations
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
Advertisements

Stack buffer overflow.
Stack buffer overflow
Computer Security Buffer Overflow lab Eu-Jin Goh.
Some Example C Programs. These programs show how to use the exec function.
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
Buffer overflows.
Exploiting Buffer Overflows on AIX/PowerPC HP-UX/PA-RISC Solaris/SPARC.
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
CS415 C++ Programming Takamitsu Kawai x4212 G11 CERC building WV Virtual Environments Lab West Virginia University.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
Chapter 10 Chapter 10 Implementing Subprograms. Implementing Subprograms  The subprogram call and return operations are together called subprogram linkage.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
BIG DATA Initiative SMART SubstationBig Data Solution.
Content Coverity Static Analysis Use cases of Coverity Examples
Buffer Overflow By Collin Donaldson.
Sabrina Wilkes-Morris CSCE 548 Student Presentation
LINKED LISTS.
Stack and Heap Memory Stack resident variables include:
Computer Organization and Design Pointers, Arrays and Strings in C
C Primer.
Quiz 11/15/16 – C functions, arrays and strings
Exploiting & Defense Day 2 Recap
Checking Memory Management
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
More Recursion.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Lecture 5: Process Creation
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Fork and Exec Unix Model
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Command Line Arguments
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
SEED Workshop Buffer Overflow Lab
Advanced Buffer Overflow: Pointer subterfuge
Assembly Language Programming I: Introduction
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Stack buffer overflow.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Dynamic Memory Allocation
Software Security Lesson Introduction
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah –
C Characters and Strings – Review Lab assignments
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Tutorial 3 Tutorial 3.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah –
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
Simulating Reference Parameters in C
Introduction to Static Analyzer
Module 2-3: Passing pointers
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
15213 C Primer 17 September 2002.
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.
Presentation transcript:

Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail

All materials is licensed under a Creative Commons “Share Alike” license. http://creativecommons.org/licenses/by-sa/3.0/ Attribution condition: You must indicate that derivative work "Is derived from Xeno Kovah's ‘Intro x86-64’ class, available at http://OpenSecurityTraining.info/IntroX86-64.html" Attribution condition: You must indicate that derivative work "Is derived from Xeno Kovah's 'Intro x86-64’ class, available at http://OpenSecurityTraining.info/IntroX86-64.html”

Are you ready to feel the POWER (buffer over)flow through you?!?! http://img3.wikia.nocookie.net/__cb20090813201436/starwars/images/1/17/Naga_Sadow_WotC.jpg 53

BasicBufferOverflow.c: Don’t be lame! Force it to call AwesomeSauce()! #include <stdio.h> #include <stdlib.h> #include <string.h> int lame(__int64 value){ __int64 array1[4]; __int64 array2[4]; array2[0] = array2[1] = array2[2] = array2[3] = value; memcpy(&array1, &array2, 4 * sizeof(__int64)); return 1; } int lame2(__int64 size, __int64 value){ memcpy(&array1, &array2, size * sizeof(__int64)); void AwesomeSauce(){ printf("Awwwwwww yeaaahhhhh! All awesome, all the time!\n"); int main(unsigned int argc, char ** argv){ __int64 size, value; size = _strtoi64(argv[1], "", 10); value = _strtoi64(argv[2], "", 16); if(!lame(value) || !lame2(size,value)){ AwesomeSauce(); else{ printf("I am soooo lame :(\n"); return 0xdeadbeef; Awesome http://www.tropicaltraditions.com/images/organic_applesauce.jpg 53

HINT! Seriously though, make a stack diagram, it will help… http://i2.kym-cdn.com/photos/images/newsfeed/000/127/137/TrollQuote.JPG

http://www.myteespot.com/images/Images_d/img_fAauYb.jpg Lab time! 53

Solution Simple, right? :) 53

The stack looks like this at line 9 in lame() before the memcpy(): 00000000`0012FE80 arg1 = ecx = value 00000000`0012FE78 return address = 00000001400010f0 00000000`0012FE70 undef 00000000`0012FE68 array2[3] = undef 00000000`0012FE60 array2[2] = undef 00000000`0012FE58 array2[1] = undef 00000000`0012FE50 array2[0] = undef 00000000`0012FE48 array1[3] = value 00000000`0012FE40 array1[2] = value 00000000`0012FE38 array1[1] = value 00000000`0012FE30 array1[0] = value RSP+0x20

The stack looks like this at line 10 in lame() after the memcpy(): 00000000`0012FE80 arg1 = ecx = value 00000000`0012FE78 return address = 00000001400010f0 00000000`0012FE70 undef 00000000`0012FE68 array2[3] = value 00000000`0012FE60 array2[2] = value 00000000`0012FE58 array2[1] = value 00000000`0012FE50 array2[0] = value 00000000`0012FE48 array1[3] = value 00000000`0012FE40 array1[2] = value 00000000`0012FE38 array1[1] = value 00000000`0012FE30 array1[0] = value RSP+0x20

but still actually = value The stack looks like this at line 17 in lame2() before the memcpy(): addresses look familiar? 00000000`0012FE80 arg1 = ecx = value 00000000`0012FE78 return address = 00000001400010f0 00000000`0012FE70 undef 00000000`0012FE68 array2[3] = “undef” but still actually = value 00000000`0012FE60 array2[2] = “undef” 00000000`0012FE58 array2[1] = “undef” 00000000`0012FE50 array2[0] = “undef” 00000000`0012FE48 array1[3] = value 00000000`0012FE40 array1[2] = value 00000000`0012FE38 array1[1] = value 00000000`0012FE30 array1[0] = value RSP+0x20

The stack looks like this at line 17 in lame2() before the memcpy(): addresses look familiar? 00000000`0012FE80 arg1 = ecx = value 00000000`0012FE78 return address = value! WINNER! 00000000`0012FE70 value 00000000`0012FE68 array1[3] = value 00000000`0012FE60 array1[2] = value 00000000`0012FE58 array1[1] = value 00000000`0012FE50 array1[0] = value 00000000`0012FE48 00000000`0012FE40 00000000`0012FE38 00000000`0012FE30 So set the size to 6 QWORDs to copy, and set the value to the address of AwesomeSauce() and collect your winner winner chicken dinner! RSP+0x20

Exploit mitigations This is a good example of how MS’s compiler has exploit mitigations baked in. I was trying to just take my old, simple, and explicitly exploitable piece of code and port it to x86-64. But when I would put my buffers so that the big one would overwrite the small one, it placed the big buffer next to the stack pointer. This is smart since presumably writes will tend to be from the small to the big. But even if it’s from the big to the small, it still won’t naturally overflow into the stack pointer with contents from the buffer

Exploit mitigations 2 params params params params params params return address return address return address big buffer return address return address big buffer big buffer big buffer big buffer return address big buffer small buffer small buffer big buffer big buffer small buffer small buffer small buffer small buffer small buffer http://msdn.microsoft.com/en-us/library/bb430720.aspx

True power can not be had so simply, novice… NX, ASLR, SEHOP…all these would stand in your way. For a taste of true power, you must start start down a different path…a darker path http://img3.wikia.nocookie.net/__cb20090813201436/starwars/images/1/17/Naga_Sadow_WotC.jpg http://opensecuritytraining.info/Exploits1.html