Software Vulnerabilities



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

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

Buffer Overflows. Security 2011

Off-by-One exploitation tutorial

Stack Overflows. Mitchell Adair

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

MSc Computer Science Dissertation

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

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

I Control Your Code Attack Vectors Through the Eyes of Software-based Fault Isolation. Mathias Payer, ETH Zurich

CSCE 465 Computer & Network Security

Cataloguing and Avoiding the Buffer Overflow Attacks in Network Operating Systems

Return-oriented programming without returns

Buffer Overflows. Code Security: Buffer Overflows. Buffer Overflows are everywhere. 13 Buffer Overflow 12 Nov 2015

Defense in Depth: Protecting Against Zero-Day Attacks

Hotpatching and the Rise of Third-Party Patches

Betriebssysteme KU Security

Bypassing Browser Memory Protections in Windows Vista

Attacking Host Intrusion Prevention Systems. Eugene Tsyrklevich

Practical taint analysis for protecting buggy binaries

Introduction to Information Security

Hands-on Hacking Unlimited

Assembly Language: Function Calls" Jennifer Rexford!

Heap-based Buffer Overflow Vulnerability in Adobe Flash Player

Bypassing Memory Protections: The Future of Exploitation

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

Bypassing Windows Hardware-enforced Data Execution Prevention

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

Securing software by enforcing data-flow integrity

Chapter 15 Operating System Security

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

Automating Mimicry Attacks Using Static Binary Analysis

Where s the FEEB? The Effectiveness of Instruction Set Randomization

CS Computer Security Thirteenth topic: System attacks. defenses

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

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

How To Detect A Buffer Overflow Vulnerability In Binary Code

Title: Bugger The Debugger - Pre Interaction Debugger Code Execution

Violating Database - Enforced Security Mechanisms

esrever gnireenigne tfosorcim seiranib

Attacking x86 Windows Binaries by Jump Oriented Programming

Introduction. Figure 1 Schema of DarunGrim2

Working with Buffers

Introduction to computer and network security. Session 2 : Examples of vulnerabilities and attacks pt1

Modern Binary Exploitation Course Syllabus

From SQL Injection to MIPS Overflows

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

CSC 405 Introduction to Computer Security

Eugene Tsyrklevich. Ozone HIPS: Unbreakable Windows

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

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

CS 161 Computer Security

1. General function and functionality of the malware

Custom Penetration Testing

Return-oriented Programming: Exploitation without Code Injection

EECS 354 Network Security. Introduction

Application-Specific Attacks: Leveraging the ActionScript Virtual Machine

An Analysis of Address Space Layout Randomization on Windows Vista

64-Bit NASM Notes. Invoking 64-Bit NASM

Lecture Overview. INF3510 Information Security Spring Lecture 4 Computer Security. Meaningless transport defences when endpoints are insecure

Fine-Grained User-Space Security Through Virtualization. Mathias Payer and Thomas R. Gross ETH Zurich

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

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

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

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

SYMANTEC ADVANCED THREAT RESEARCH. An Analysis of Address Space Layout Randomization on Windows Vista

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

Operating Systems. Privileged Instructions

Vigilante: End-to-End Containment of Internet Worms

Exploiting Trustzone on Android

Fighting malware on your own

CS61: Systems Programing and Machine Organization

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

Reverse Engineering and Computer Security

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

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

X86-64 Architecture Guide

Payment Card Industry (PCI) Terminal Software Security. Best Practices

AutoPaG: Towards Automated Software Patch Generation with Source Code Root Cause Identification and Repair

Enlisting Hardware Architecture to Thwart Malicious Code Injection

Using fuzzing to detect security vulnerabilities

Fuzzing for software vulnerability discovery

Exploiting nginx chunked overflow bug, the undisclosed attack vector

static void insecure (localhost *unix)

Windows XP SP3 Registry Handling Buffer Overflow

Dynamic Behavior Analysis Using Binary Instrumentation

On Gray-Box Program Tracking for Anomaly Detection

Transcription:

Software Vulnerabilities -- stack overflow

Code based security Code based security discusses typical vulnerabilities made by programmers that can be exploited by miscreants Implementing safe software in C/C++ is almost impossible However, a huge amount of unsafe codes exist worldwide On the other hand, native codes are still appealing due to performance issues Steps have been taken both by hardware and software vendors: High-level languages: Java (J2EE),.NET framework (C#) ASLR: Address Space Layout Randomization Using safe libraries Input validator Antivirus, IDS NX/XN bit: CPU support for non-executable memory ranges 2

Code based security/buffer overflow Occurs when the boundary of a buffer is exceeded by data thus overwriting adjecent memory locations Typically causing the program to halt with exception Segmentation fault (Linux) Access violation at 0x11223344 (Windows) Can be exploited by overwriting interesting variables, memory locations (return address, pointers, file names,etc) Forcing the program to change its control flow by injecting malicious code Most preferred targets: Setuid/setgid programs Network servers: remote access 3

Code based security/buffer overflow Morris worm (1988): overflow in fingerd 6000 machines are infected (10% of Internet) CodeRed (2001): overflow in Microsoft IIS 300 000 machines are infected in 14 hours SQL Slammer (2003): overflow in MS-SQL server 75 000 machines are infected in 10 minutes Stack Overflow in FreeBSD kernel (2010) In 2003, 75% of vulnerabilities were buffer overflow related according to CERT Today web based vulnerabilities are more common, however, in case of servers it is still essential 4

Code based security/stack overflow Stack has already been introduced Stack overflow can occur when a procedure copies usercontrolled data to a local buffer on the stack without verifying its size. Dangerous functions: strcpy, sprintf, strcat, gets, fgets, Local data overwrites other values on the stack up to return address When the procedure returns EIP is set to the address residing at the location of the return address. control flow can be changed Insert code to that modified address will be executed. 5

Stack Stack is built up from several stack frames belonging to functions. Each stack frame comprises: Function parameters Return address Saved Frame Pointer (Frame pointer of the preceding frame) Local variables Previous frame Higher memory addresses Function parameters Return address Saved EBP (SFP) Local variables Free memory EBP 6

The stack in calling and returning from function addnum LIFO principles Grows towards lower memory addresses ESP: stack pointer, points to the top of the stack 7

mov dword ptr [b],3 ; Moving 3 to the address pointed by variable b mov eax,dword ptr [b]; Storing that value in register eax push eax ; Pushing b to stack and decreasing ESP its widthness 3 (b) int main(void){ int a, b, c; a=7; b=3; c = addnum(a,b); printf("result is: %d", a+b); 8

mov dword ptr [a],7 ; Moving 7 to the address pointed by variable a mov ecx,dword ptr [a]; Storing that value in register ecx push ecx ; Pushing a to stack and decreasing ESP by its widthness 3 (b) 7 (a) int main(void){ int a, b, c; a=7; b=3; c = addnum(a,b); printf("result is: %d", a+b); 9

call addnum ; pushing the address of the next instruction (return addr.) ; (0x00411459) to the stack and calling function addnum & ; decreasing esp 3 (b) 7 (a) 0x00411459 (ret addr.) int main(void){ int a, b, c; a=7; b=3; c = addnum(a,b); printf("result is: %d", a+b); 10

Every function starts with function prologue: push ebp ; Saves the previous frame pointer (EBP also called Saved FP) mov ebp,esp ; Currently the EBP points to SFP sub esp, 0x10 ; Saving space for the local variables of the function 3 (b) 7 (a) 0x00411459 (ret addr.) Saved EBP (SFP) int addnum(int a, int b){ int c = 4; c = a + b; return c; 11

Every function starts with function prologue: push ebp ; Saves the previous frame pointer (EBP also called Saved FP) mov ebp,esp ; Currently the EBP points to SFP sub esp, 0x10 ; Saving space for the local variables of the function 3 (b) 7 (a) 0x00411459 (ret addr.) Saved EBP (SFP),EBP int addnum(int a, int b){ int c = 4; c = a + b; return c; 12

Every function starts with function prologue: push ebp ; Saves the previous frame pointer (EBP also called Saved FP) mov ebp,esp ; Currently the EBP points to SFP sub esp, 0x10 ; Saving space for the local variables of the function 3 (b) 7 (a) 0x00411459 (ret addr.) Saved EBP (SFP) Space for local variables EBP int addnum(int a, int b){ int c = 4; c = a + b; return c; 13

Every function ends with function epilogue. mov esp,ebp ; restoring the stack pointer to SFP, unallocating space for locals pop ebp ; restoring the value of EBP thus point into SFP of preceding frame ret ; popping return address and returning to that, increasing ESP 3 (b) 7 (a) 0x00411459 (ret addr.) Saved EBP (SFP) EBP, ESP int addnum(int a, int b){ int c = 4; c = a + b; return c; 14

Every function ends with function epilogue. mov esp,ebp ; restoring the stack pointer to SFP, unallocating space for locals pop ebp ; restoring the value of EBP thus point into SFP of preceding frame ret ; popping return address and returning to that, increasing ESP 3 (b) 7 (a) 0x00411459 (ret addr.) int addnum(int a, int b){ int c = 4; c = a + b; return c; 15

Every function ends with function epilogue. mov esp,ebp ; restoring the stack pointer to SFP, unallocating space for locals pop ebp ; restoring the value of EBP thus point into SFP of preceding frame ret ; popping return address and returning to that, increasing ESP 3 (b) 7 (a) int addnum(int a, int b){ int c = 4; c = a + b; return c; 16

add esp,8 ; decreasing the stack after the RET instruction of addnum 3 (b) 7 (a) int main(void){ int a, b, c; a=7; b=3; c = addnum(a,b); printf("result is: %d", a+b); 17

Code based security/stack overflow int main(int argc, char* argv[] ) { dangereous(argv[1]); printf( Is everything all right? ); void dangerous(char * buf){ char buffer[100]; strcpy(buffer, buf); Previous frame Higher memory addresses Previous frame Function parameters Function parameters Return address buffer address Saved EBP (frame pointer) EBP SHELLCODE buffer[100] Free memory 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 Free 0x90 memory 0x90 0x90 NOP sled 18

Code based security/stack overflow NOP sled: Put in front of the shellcode and jump into that area. Instructions should always reach the beginig of the shellcode. The simplest version is a sequence of 0x90 (no operations - nop) Reason to apply: Bigger chance to find our shellcode On local systems the position of return address can be calculated (no ASLR) Remote addresses are unknown Where to put the shellcode? Into the local buffer with a preceeding nop sled Remote attacks possible, but the memory page the buffer residing at must be executable. The location of the buffer must be known. Into Environment variables Easy to implement. Good for tiny buffers, however, only for local attacks. Stack must be executable. Address of a function inide the program Remote attacks possible with no executable stack. More frames to put on stack. 19

Memory segmentation (ELF binaries) 0xFFFFFFFF Kernel Environment variables Stack Data segment (heap) Data segment (.bss) Data segment (.data) Code segment (.text) Stack segment includes Local variables Values required for procedure call Data segment heap: dynamically allocated memory. bss: Uninitialized global & static variables.data: Initialized global & static vairbales Code Segment: Executable instructions Typically read-only Shared libraries 20

Code based security/software ASLR There are many workarounds for protecting against stack and heap overflow. One of the most effective ones is ASLR: Address Space Layout (Load) Randomization Randomizes the base address of stack and heap. Stack Heap RND RND void alt_main(int argc, char* argv[]){... void spamstack(int i, int ac, char* av[] ){ if (! i) alt_main(ac, av); spamstack(--i); int main(int argc, char* argv[]){ srand ( time(null) ); malloc(rand() % 123456 + 1); // rnd heap spamstack(rand() % 123456 + 1, argc, argv); 21