CNIT 127: Exploit Development Ch 3: Shellcode. Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object.

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Smashing the Stack for Fun and Profit
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Computer Security: Principles and Practice EECS710: Information Security Professor Hossein Saiedian Fall 2014 Chapter 10: Buffer Overflow.
Computer Security: Principles and Practice First Edition by William Stallings and Lawrie Brown Lecture slides by Lawrie Brown Chapter 11 – Buffer Overflow.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
RIVERSIDE RESEARCH INSTITUTE Helikaon Linux Debugger: A Stealthy Custom Debugger For Linux Jason Raber, Team Lead - Reverse Engineer.
Countermeasures 0x610~0x Seokmyung Hong.
COSC 120 Computer Programming
The Process Model.
X86 ISA Compiler Baojian Hua Front End source code abstract syntax tree lexical analyzer parser tokens IR semantic analyzer.
Attacks Using Stack Buffer Overflow Boxuan Gu
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
System Calls 1.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
MIPS coding. SPIM Some links can be found such as:
Hello ASM World: A Painless and Contextual Introduction to x86 Assembly rogueclown DerbyCon 3.0 September 28, 2013.
Buffer Overflows : An In-depth Analysis. Introduction Buffer overflows were understood as early as 1972 The legendary Morris Worm made use of a Buffer.
Code Generation Gülfem Savrun Yeniçeri CS 142 (b) 02/26/2013.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
The ISA Level The Instruction Set Architecture (ISA) is positioned between the microarchtecture level and the operating system level.  Historically, this.
CNIT 127: Exploit Development Ch 4: Introduction to Format String Bugs.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
Buffer Overflow CS461/ECE422 Spring Reading Material Based on Chapter 11 of the text.
Topic 2d High-Level languages and Systems Software
Exploitation Of Windows Buffer Overflows. What is a Buffer Overflow A buffer overflow is when memory is copied to a location that is outside of its allocated.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
Syscall Proxying   Simulating Remote Execution Maximiliano Cáceres  Caesars Palace, Las Vegas, NV, USA · July 31st, 2002.
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
CNIT 127: Exploit Development Ch 1: Before you begin.
Operating Systems Process Creation
Shellcode Development -Femi Oloyede -Pallavi Murudkar.
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
Assembly 08. Outline Local Labels Jump Lengths External Libraries Macros 1.
CNIT 127: Exploit Development Lecture 7: 64-bit Assembler Not in textbook.
Security Attacks Tanenbaum & Bo, Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
EXPLOITATION CRASH COURSE – FALL 2013 UTD Computer Security Group – Andrew Folloder csg.utdallas.edu (credit: Scott Hand)
Assembly 09. Outline Strings in x86 esi, edi, ecx, eax stosb, stosw, stosd cld, std rep loop 1.
ROP Exploit. ROP Return Oriented Programming (ROP): is a hacking exploit technique where you exploit buffer overflow to inject a chain of gadgets. Each.
Lecture 5 Page 1 CS 111 Online Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command.
Practical Session 3.
Introduction to Information Security
Instruction Set Architecture
Protecting Memory What is there to protect in memory?
Introduction to Information Security
Assembly language.
Static and dynamic analysis of binaries
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
Process Creation Processes get created (and destroyed) all the time in a typical computer Some by explicit user command Some by invocation from other running.
CSC 495/583 Topics of Software Security Stack Overflows (2)
Software Development with uMPS
Lecture 5: Process Creation
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Week 2: Buffer Overflow Part 1.
Week 2: Buffer Overflow Part 2.
System Calls System calls are the user API to the OS
System and Cyber Security
Computer Architecture and System Programming Laboratory
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Return-to-libc Attacks
Presentation transcript:

CNIT 127: Exploit Development Ch 3: Shellcode

Topics Protection rings Syscalls Shellcode nasm Assembler ld GNU Linker objdump to see contents of object files strace System Call Tracer Removing Nulls Spawning a Shell

Understanding System Calls

Shellcode Written in assembler Translated into hexadecimal opcodes Intended to inject into a system by exploiting a vulnerability Typically spawns a root shell, but may do something else

System Calls (or Syscalls) Syscalls directly access the kernel, to: – Get input – Produce output – Exit a process – Execute a binary file – And more They are the interface between protected kernel mode and user mode

Protection Rings Although the x86 provides four rings, only rings 0 and 3 are used by Windows or Unix Ring 3 is user-land Ring 0 is kernel- land Links Ch 3a-3c

Protecting the Kernel Protected kernel mode – Prevents user applications from compromising the OS If a user mode program attempts to access kernel memory, this generates an access exception Syscalls are the interface between user mode and kernel mode

Libc C library wrapper C functions that perform syscalls Advantages of libc – Allows programs to continue to function normally even if a syscall is changed – Provides useful functions, like malloc – (malloc allocates space on the heap) See link Ch 3d

Syscalls use INT 0x80 1.Load syscall number into EAX 2.Put arguments in other registers 3.Execute INT 0x80 4.CPU switches to kernel mode 5.Syscall function executes

Syscall Number and Arguments Syscall number is an integer in EAX Up to six arguments are loaded into – EBX, ECX, EDX, ESI, EDI, and EPB For more than six arguments, the first argument holds a pointer to a data structure

exit() The libc exit function does a lot of preparation, carefully covering many possible situations, and then calls SYSCALL to exit

Disassembling exit gdb e – disassemble main – disassemble exit – disassemble __run_exit_handlers All that stuff is error handling, to prepare for the syscall, which is at the label _exit disassemble _exit

Disassembling _exit syscall 252, exit_group() (kill all threads) syscall 1, exit() (kill calling thread) – Link Ch 3e

Writing Shellcode for the exit() Syscall

Shellcode Size Shellcode should be a simple and compact as possible Because vulnerabilities often only allow a small number of injected bytes – It therefore lacks error-handling, and will crash easily

Seven Instructions exit_group exit

Simplest code for exit(0)

nasm and ld nasm creates object file ld links it, creating an executable ELF file

objdump Shows the contents of object files

C Code to Test Shellcode From link Ch 3k Textbook version explained at link Ch 3i

Compile and Run Textbook omits the "-z execstack" option Next, we'll use "strace" to see all system calls when this program runs That shows a lot of complex calls, and "exit(0)" at the end

Using strace

Injectable Shellcode

Getting Rid of Nulls We have null bytes, which will terminate a string and break the exploit

Replacing Instructions This instruction contains nulls – mov ebx,0 This one doesn't – xor ebx,ebx This instruction contains nulls, because it moves 32 bits – mov eax,1 This one doesn't, moving only 8 bits – mov al, 1

OLD NEW

objdump of New Exit Shellcode

Spawning a Shell

Beyond exit() There's no use for exit() – any illegal instruction can make the program crash We want shellcode that offers the attacker a shell, so the attacker can type in arbitrary commands

Five Steps to Shellcode 1.Write high-level code 2.Compile and disassemble 3.Analyze the assembly 4.Clean up assembly, remove nulls 5.Extract commands and create shellcode

fork() and execve() Two ways to create a new process in Linux Replace a running process – Uses execve() Copy a running process to create a new one – Uses fork() and execve()

C Program to Use execve() See link Ch 3l

Recompile with Static objdump of main is long, but we only care about main and __execve

main() Pushes 3 Arguments Calls __execve

Man Page execve() takes three arguments

execve() Arguments 1.Pointer to a string containing the name of the program to execute – "/bin/sh" 2.Pointer to argument array – happy 3.Pointer to environment array – NULL

Objdump of __execve Puts four parameters into edx, ecx, ebx, and eax INT 80

Game Show Questions

Which item converts executable code into assembler? A.syscall B.nasm C.ld D.objdump E.strace 40

Which item lists all system calls when a program is run? A.syscall B.nasm C.ld D.objdump E.strace 41

Which item is used to go from user mode to kernel mode? A.syscall B.nasm C.ld D.objdump E.strace 42

Which item converts assembly code into object code? A.syscall B.nasm C.ld D.objdump E.strace 43

What instruction should be used to replace "mov eax,0" in shellcode? A.int 0x80 B.or eax, eax C.xor eax, eax D.cmp eax, eax E.None of the above 44

What instruction should be used to replace "mov eax,1" in shellcode? A.int 0x80 B.mov ah, 1 C.xor eax, eax D.mov al, 1 E.None of the above 45