Encryption Wrapper. on OSX



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

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

Example of Standard API

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

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

Operating System Structure

How do Users and Processes interact with the Operating System? Services for Processes. OS Structure with Services. Services for the OS Itself

ELEC 377. Operating Systems. Week 1 Class 3

W4118 Operating Systems. Junfeng Yang

OS Virtualization Frank Hofmann

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

FAME Operating Systems

CPS221 Lecture: Operating System Structure; Virtual Machines

ADVANCED MAC OS X ROOTKITS

COS 318: Operating Systems

OS Concepts and structure

Linux Kernel Architecture

Chapter 2 System Structures

Components of a Computer System

Operating System Structures

Networking Operating Systems (CO32010)

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

Assembly Language: Function Calls" Jennifer Rexford!

Host-based Intrusion Prevention on Windows and UNIX. Dr. Rich Murphey White Oak Labs

Remote administration, admission management, procedural enforcement and automated backup of networked workstations.

Lecture 25 Symbian OS

CHAPTER 15: Operating Systems: An Overview

CS161: Operating Systems

CS61: Systems Programing and Machine Organization

Virtual Private Systems for FreeBSD

This is DEEPerent: Tracking App behaviors with (Nothing changed) phone for Evasive android malware

Red Hat Linux Internals

Operating System Organization. Purpose of an OS

Operating Systems OS Architecture Models

Chapter 3 Operating-System Structures

XNU:asecurityevaluation

System Structures. Services Interface Structure

Topic 5a Operating System Fundamentals

Module 20: The Linux System

COS 318: Operating Systems. Virtual Machine Monitors

What is an RTOS? Introduction to Real-Time Operating Systems. So what is an RTOS?(contd)

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

Security Overview of the Integrity Virtual Machines Architecture

Off-by-One exploitation tutorial

Unix Security Technologies: Host Security Tools. Peter Markowsky <peterm[at]ccs.neu.edu>

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

theguard! ApplicationManager System Windows Data Collector

Attacking Obfuscated Code with IDA Pro. Chris Eagle

MACH: AN OPEN SYSTEM OPERATING SYSTEM Aakash Damara, Vikas Damara, Aanchal Chanana Dronacharya College of Engineering, Gurgaon, India

Multiprogramming. IT 3123 Hardware and Software Concepts. Program Dispatching. Multiprogramming. Program Dispatching. Program Dispatching

Mobile Operating Systems. Week I

Cloud Operating Systems for Servers

Sierraware Overview. Simply Secure

Automatic load balancing and transparent process migration

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

x86 ISA Modifications to support Virtual Machines

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

Outline. Outline. Why virtualization? Why not virtualize? Today s data center. Cloud computing. Virtual resource pool

Best Practices: Implementing Large Scale Collections with F- Response

NetCrunch 6. AdRem. Network Monitoring Server. Document. Monitor. Manage

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

MINIX3: A Reliable and Secure Operating System

NSA Security-Enhanced Linux (SELinux)


Host/Platform Security. Module 11

eggon SDK for ios 7 Integration Instructions

Virtual Machines. COMP 3361: Operating Systems I Winter

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

Andreas Herrmann. AMD Operating System Research Center

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Code Injection From the Hypervisor: Removing the need for in-guest agents. Matt Conover & Tzi-cker Chiueh Core Research Group, Symantec Research Labs

Operating Systems. Lecture 03. February 11, 2013

Virtualization System Vulnerability Discovery Framework. Speaker: Qinghao Tang Title:360 Marvel Team Leader

Automating Linux Malware Analysis Using Limon Sandbox Monnappa K A monnappa22@gmail.com

Research and Design of Universal and Open Software Development Platform for Digital Home

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Operating System Components

Between Mutual Trust and Mutual Distrust: Practical Fine-grained Privilege Separation in Multithreaded Applications

Toasterkit - A NetBSD Rootkit. Anthony Martinez Thomas Bowen

Advanced ANDROID & ios Hands-on Exploitation

Operating System Overview. Otto J. Anshus

Virtual Machine Security

Software Vulnerabilities

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

Outline: Operating Systems

Analysis of Open Source Drivers for IEEE WLANs

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Reversing in OS X - what s different

The Value of Physical Memory for Incident Response

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

Chapter 14 Virtual Machines

Transcription:

Encryption Wrapper on OSX

Overview OSX Kernel What is an Encryption Wrapper? Project Implementation

OSX s Origins and Design

NeXTSTEP Legacy NextStep v1 NextStep v3.3 Mac OS X Jobs creates NeXT Apple acquisition PPC Rhapsody Mac OS X i386 1985 1989 1995 2001 2005

NeXTSTEP Legacy Operating System Design Object Oriented (APIs, KPIs) OpenStep API (now cocoa) Objective-C Finder :-(

NeXTSTEP Design Applications NeXT GUI / OpenStep API Display PostScript *{ 4.3BSD Loadable Kernel Servers DriverKit Mach 2.0/2.5 * Berkeley - Carnegie Mellon Universities

CMU s Mach Original Goals An operating system to create operating systems Designed to replace the huge complex buggy Unix kernel Promoted portability, stability and simplicity

Mach Original Concept: a MicroKernel Applications User Kernel Real Operating System Mach Operating System

Monolithic MicroKernel Kernel Applications User Kernel APIs (libc,...) APIs (syscalls,...) VFS FAT32 ISO9660 ext2fs Sockets TCP UDP IP Drivers Memory Mng Scheduler IPC Hardware Mng Hardware

Mach, a MicroKernel

Mach Basics Task: simple resources container (VM, ports, threads,...) Thread: basic execution unit (shares task s resources with other threads, only owns an execution context) Port: message queue protected with privileges Message: data that a thread can send or receive Memory object: container for data (mapped in the task s virtual address space)

Mach Basics... No user/group/world notions No FS notions like working directory Pure/simple/secure oriented object concept Only one object can own/receive messages on a specific port A thread needs to have the right on a specific port to send a message to it

Mach Memory Management I/O I/O VGA RAM Task A Task B

Mach IPC (RPC w MIG) funca( hello, 1); void funca(char* s, int i) { // mig generated code msg.s = s; msg.i = i; mach_msg(port, msg); } Thread A Task A // mig generated code mach_msg(port, msg); funca(msg.s, msg.c); void funca(char *s, int i) {... } Thread B Task B Computer A

Mach is responsible for... Preemptive multitasking (schedule user/kernel threads) Interrupt Management Protected Memory Virtual Memory Management IPC Real-Time Support Debugging support Console I/O

From CMU to Apple Implementation

CMU s implementations Applications User APIs (libc,...) Kernel 4.3BSD Mach Mach 1.0-2.5 3.0

OSX s NeXTSTEP s implementation implementation Applications User APIs (libc,...) Kernel FreeBSD 4.3BSD Loadable IOKit Kernel Servers DriverKit Mach 2.0/2.5 3.0

Monolithic system calls (FreeBSD, Linux,...) 4GB SYS_write() 3GB kernel user user -> system switch write() system -> user switch 0 GB

MicroKernel system calls task switch 4GB receive(msg) receive(msg) SYS_write(msg.content) dispatch(msg) rpc_write_call(msg) dispatch(msg) ret = write(msg) task switch task switch task switch Mach BSD user kernel server task task send_result_back(msg) write() 0 GB

OSX: Colocation User APIs (libc,...) Kernel Applications FreeBSD IOKit Mach 3.0

BSD on top of Mach How to wrap a secure and simple micro-kernel into an insecure and complex monolithic-kernel?

BSD on top of Mach Applications User APIs (libc,...) Kernel syscalls syscalls UNIX Pthread Unix Process Signal Task Thread Exceptions Messages/ Ports Memory Management Scheduler Scheduler IPC

IOKit Driver framework Fully object Oriented C++ (w/o exceptions, templates and rtti) Enable to easily reuse code

IOKit driver.c static int hello_init(void) { return initlaucher(); } static void hello_exit(void) { } module_init(hello_init); module_exit(hello_exit); driver.c static int hello_init(void) { #ifdef v2 initnewv2stuff(); #endif return initlaucher(); } static void hello_exit(void) { } module_init(hello_init); module_exit(hello_exit); RocketLauncher v1.0 RocketLauncher v2

IOKit driver.cpp driver.h class rocketlv2 : public rocketl { }; driver.cpp bool rocketl::init() { return initlaucher(); } bool rocketlv2::init() { if (initnewv2stuff()) return rocketl::init(); return FALSE; } RocketLauncher v1.0 RocketLauncher v2

IOKit Meta Class Reference Counting Inheritance WorkLoop (tasklets)

IOKit s author

Binary Formats a.out coff PE ELF Mach-O

Mach-O Fat Header Fat Arch #1 Fat Arch #2 Mach-0 File #1 Multi-Archi Mach-0 File #2 Kernel is a Mach-O (kernel is always 32bits) $ file /mach_kernel /mach_kernel: Mach-O universal binary with 2 architectures /mach_kernel (for architecture i386): Mach-O executable i386 /mach_kernel (for architecture ppc): Mach-O executable ppc

Mach-O Header LC_UUID LC_SEGMENT / LC_SEGMENT_64 LC_SYMTAB LC_DSYMTAB LC_THREAD... Load commands Load command 1 Load command n Data LC_SEGMENT TEXT eax 0x0 ebx Section text Section cstring LC_THREAD 0x0 ecx 0x0 edx 0x0 edi 0x0 esi 0x0 ebp 0x0 eip 0x00001f70

Design Considerations BSD designed by the academic world for the academic world Mach designed by the academic world for BSD NeXTSTEP designed for the education world OSX designed for???

Encryption Wrapper

What is binary encryption? Encrypt the binary image Decrypt the code at runtime Delay as much as possible the code decryption Guarantee that no single snapshot contains the whole unencrypted program

Threats Reverse engineers Crackers Forensic investigators

Why encrypt? Adding an anti piracy protection Prevent unauthorized user from executing it Adding a reverse engineering protection Prevent static attacks (binary static analysis) Hindering forensic analysis, just in case...

What is binary encryption? Header Load commands Segment command 1 Segment command n Segment TEXT Section 1 data text Header Load commands Segment command 1 Segment command n encryption Segment wrapper TEXT Section 1 data text ( TEXT, text) section start: 00001f70 pushl $0x00 00001f72 movl %esp,%ebp 00001f74 andl $0xf0,%esp 00001f77 subl $0x10,%esp ( TEXT, text) section 8>^KB^@^@<89>^^P<FF><85> $<FF><FF><FF><8B><85><F6>^O<85 ><91><FC><FF><FF><8B><9D>$ <FF><FF><FF><85><DB>^O<84>{^A^ @^@<8B><85>^@<FF><FF><FF>^O Section 1 data cstring Section 1 data cstring

Page Fault Header Load commands _main: Page Fault 0x1feb pushl %ebp 0x1fec movl %esp,%ebp 0x1fee subl $0x08,%esp 0x1ff1 calll _hello (0x2000) 0x1ff6 leave 0x1ff7 ret 0x1000 0x1feb... 0x2000 0x2000... pushl %ebp pushl %ebp 0x1000 Segment command 1 Segment command n Segment TEXT Pager.GetPage() DeviceDriver.Read() ( TEXT, text) section MapPage() Section 1 data text 0x1feb pushl %ebp... _hello: 0x2000 pushl... %ebp 0x2000 0x2000 pushl %ebp... Section 1 data cstring Task A hello.exe

What didn t work... Patch the Kernel Source Add a custom Pager Fake Device Kernel Pager Device

Patch the Kernel Source Too invasive... No one on OSX installs other kernels than the ones released by Apple Really hard to recompile a custom kernel, no support Using kernel module is really mandatory (cf. Apple) Kernel Pager Device

What is a pager? Responsible for reading/writing pages to the backing store Abstraction layer between the Kernel and the backing store Kernel Pager Backing Store

OSX s Pager Pager selection is hard coded (VNode pager,...) No clean mechanism to add a custom pager The only way is by hooking OSX s page fault handler (dirty) Kernel Pager Device

Fake Device 0x1000 0x1feb... pushl %ebp hello.exe 0x2000...Device Read 0x2000 pushl %ebp 8>^KB^@^@<89>^^P<FF><85> $<FF><FF><FF><8B><85><F6>^O<85 ><91><FC><FF><FF><8B><9D>$ <FF><FF><FF><85><DB>^O<84>{^A^ @^@<8B><85>^@<FF><FF><FF>^O file A file B Task A /mnt/fake

Fake Device Can limit accesses to kernel only However, can t guarantee that the client is really our driver Can t guarantee the amount of unencrypted pages

What works? Segment TEXT Section 1 data text ( TEXT, text) section Exceptions Hooking 0x1000 8>^KB^@^@<89>^^P<FF><85> $<FF><FF><FF><8B><85><F start: 00001f70 Fix Page pushl $0x00 Fault 00001f72 movl %esp,%ebp Protection Exception VM_PROT_NONE Page Fault Kernel Pager 0x1000 Backing 8>^KB^@^@<89>^^P<FF><85> $<FF><FF><FF><8B><85><F Store

Exceptions Hooking Clear Mach API to override task exception handler No overhead (no need to call the original handler) Thanks to Mach the User-land and the Kernel-land are both clients of Mach. The same code works in both lands

Demo

Reference Inside the Mac OS X Kernel - Lucy <whoislucy(at)gmail.com> Meet Mach - James Scott IOKit Fundamentals - Apple Phrack p58-10 Binary Encryption on Unix - grugq <grugq@lokmail.net> The NeXT Chapter - kernelthread.com Infecting the Mach-o Object Format - Neil Archibald MACH Kernel Interface Manual - CMU