13/July/1999Third USENIX Windows NT Symposium1 Detours: Binary Interception of Win32 Functions Galen Hunt and Doug Brubacher Systems and Networking Group.

Slides:



Advertisements
Similar presentations
A Binary Agent Technology for COTS Software Integrity Richard Schooler Anant Agarwal InCert Software.
Advertisements

ITEC 352 Lecture 25 Memory(3). Review Questions RAM –What is the difference between register memory, cache memory, and main memory? –What connects the.
Monitoring Data Structures Using Hardware Transactional Memory Shakeel Butt 1, Vinod Ganapathy 1, Arati Baliga 2 and Mihai Christodorescu 3 1 Rutgers University,
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Operating System Security : David Phillips A Study of Windows Rootkits.
Dec 5, 2007University of Virginia1 Efficient Dynamic Tainting using Multiple Cores Yan Huang University of Virginia Dec
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Nullcon Goa 2010http://nullcon.net Intelligent Debugging and in-memory Fuzzers By Vishwas Sharma Amandeep Bharti Rohan Thakur.
Paradyn Project Paradyn / Dyninst Week College Park, Maryland March 26-28, 2012 Self-propelled Instrumentation Wenbin Fang.
Enabling Efficient On-the-fly Microarchitecture Simulation Thierry Lafage September 2000.
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
Itamargi at post.tau.ac.il Nirkrako at post.tau.ac.il.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
INTRODUCTION OS/2 was initially designed to extend the capabilities of DOS by IBM and Microsoft Corporations. To create a single industry-standard operating.
Run-Time Storage Organization
1 CE6130 現代作業系統核心 Modern Operating System Kernels 許 富 皓.
@ NCSU Zhi NCSU Xuxian Microsoft Research Weidong Microsoft NCSU Peng NCSU ACM CCS’09.
1 RISE: Randomization Techniques for Software Security Dawn Song CMU Joint work with Monica Chew (UC Berkeley)
Dreams in a Nutshell Steven Sommer Microsoft Research Institute Department of Computing Macquarie University.
Previous Next 06/18/2000Shanghai Jiaotong Univ. Computer Science & Engineering Dept. C+J Software Architecture Shanghai Jiaotong University Author: Lu,
Automated Tracing and Visualization of Software Security Structure and Properties Symposium on Visualization for Cyber Security 2012 (VizSec’12) Seattle,
Software Architecture Classification for Estimating the Costs of COTS Integration Yakimovich, Bieman, Basili; icse 99.
Welcome to the Power of 64-bit Computing …now available on your desktop! © 1998, 1999 Compaq Computer Corporation.
Support for Debugging Automatically Parallelized Programs Robert Hood Gabriele Jost CSC/MRJ Technology Solutions NASA.
PMaC Performance Modeling and Characterization Performance Modeling and Analysis with PEBIL Michael Laurenzano, Ananta Tiwari, Laura Carrington Performance.
Java Introduction to JNI Prepared by Humaira Siddiqui.
VAMPIR. Visualization and Analysis of MPI Resources Commercial tool from PALLAS GmbH VAMPIRtrace - MPI profiling library VAMPIR - trace visualization.
Win32 Programming Lesson 20: Advanced DLL Techniques.
Native Client: A Sandbox for Portable, Untrusted x86 Native Code
CS533 Concepts of Operating Systems Jonathan Walpole.
Win32 Programming Lesson 22: DLL Magic Part Deux All your base are belong to us…
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
Software Engineering in Robotics Interfacing to external functions Henrik I. Christensen –
Environment Selection Application  Firefox 1.0 or 2.0  Apache Operating System  Linux  Windows XP Instrumentation Package  JIT (DynamoRio,
Instrumentation in Software Dynamic Translators for Self-Managed Systems Bruce R. Childers Naveen Kumar, Jonathan Misurda and Mary.
Hidden Processes: The Implication for Intrusion Detection
Dynamic Link Libraries: Inside Out. Dynamic Link Libraries  About Dynamic-Link Libraries  Dynamic-Link Libraries Hands On  Dynamic Link Library Reference.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
EXTENSIBILITY, SAFETY AND PERFORMANCE IN THE SPIN OPERATING SYSTEM
CSCI Rational Purify 1 Rational Purify Overview Michel Izygon - Jim Helm.
AMD64/EM64T – Dyninst & ParadynMarch 17, 2005 The AMD64/EM64T Port of Dyninst and Paradyn Greg Quinn Ray Chen
CNIT 127: Exploit Development Ch 8: Windows Overflows Part 2.
Industrial Strength Software Hacking Simon McPartlin Berlin, December 3 rd, 2015.
University of Maryland Instrumentation with Relocatable Program Code Tugrul Ince Department of Computer Science University of Maryland, College Park, MD.
1 University of Maryland Runtime Program Evolution Jeff Hollingsworth © Copyright 2000, Jeffrey K. Hollingsworth, All Rights Reserved. University of Maryland.
Dynamic Taint Analysis for Automatic Detection, Analysis, and Signature Generation of Exploits on Commodity Software Paper by: James Newsome and Dawn Song.
Windows workshop 2010 Understanding Software Dependencies in Windows Roland Yap School of Computing National University of Singapore Singapore
Lecture 7 Rootkits Hoglund/Butler (Chapter 5-6). Avoiding detection Two ways rootkits can avoid detection –Modify execution path of operating system to.
© 2006 Andrew R. BernatMarch 2006Generalized Code Relocation Generalized Code Relocation for Instrumentation and Efficiency Andrew R. Bernat University.
© 2002 IBM Corporation Confidential | Date | Other Information, if necessary Copyright © 2009 Ericsson, Made available under the Eclipse Public License.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
RealTimeSystems Lab Jong-Koo, Lim
Object Files & Linking. Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution.
Smalltalk Implementation Harry Porter, October 2009 Smalltalk Implementation: Optimization Techniques Prof. Harry Porter Portland State University 1.
Static and dynamic analysis of binaries
Performance Optimizations in Dyninst
Internet and Java Foundations, Programming and Practice
Introduction to Compilers Tim Teitelbaum
Chapter 3: Windows7 Part 1.
Hidden Processes: The Implication for Intrusion Detection
Chapter 4: Threads.
Efficient x86 Instrumentation:
Multi-modules programming
Introduction to Virtual Machines
Outline Operating System Organization Operating System Examples
System Calls System calls are the user API to the OS
Introduction to Virtual Machines
Dynamic Binary Translators and Instrumenters
Computer Architecture and System Programming Laboratory
Plug-In Architecture Pattern
Presentation transcript:

13/July/1999Third USENIX Windows NT Symposium1 Detours: Binary Interception of Win32 Functions Galen Hunt and Doug Brubacher Systems and Networking Group Microsoft Research One Microsoft Way Redmond, WA

13/July/1999Third USENIX Windows NT Symposium2 Problem:  You want to do compelling research! You have a great idea for some really compelling systems research!  You want it to be relevant! You want to prove it on commercial systems with commercial applications!  You don’t have source code! (Or you don’t want to use source code!)

13/July/1999Third USENIX Windows NT Symposium3 Detours  Is a library for instrumenting and intercepting function calls in Win32 binaries.  Replaces the first instructions of a target function with jmp to a detour function.  Preserves original function semantics through a trampoline function.  Enables interception and instrumentation of Win32 binary programs.

13/July/1999Third USENIX Windows NT Symposium4 Outline Motivation & Introduction  Implementation  Demonstration  Related Work  Conclusions

13/July/1999Third USENIX Windows NT Symposium5 Problem Rephrased:  How do you get your code into an application’s address space?  How do you get your code invoked?

13/July/1999Third USENIX Windows NT Symposium6 How do you get your code into an application’s address space?  First: Place code into a DLL.  Then do one of the following:  Link application with your DLL.  Only works if you have.obj files.  Modify application.imports to include DLL.  Detours includes routines for editing.imports.  Inject DLL into running process.  Detours calls OpenProcess(), VirtualAllocEx(), WriteProcessMemory(), and CreateRemoteThread()  Inject DLL into process at creation time.  Detours calls CreateProcess() w/ CREATE_SUSPENDED.

13/July/1999Third USENIX Windows NT Symposium7 Rewriting a Binary: COFF Header.text.data.imports.exports.detour Header.imports Payloads Payload COFF Header.text.data.imports.exports

13/July/1999Third USENIX Windows NT Symposium8 How do you get your code invoked?  Replace first instructions of target with a jump to the detour.  Insert replaced instructions into trampoline.  Trampolines can be allocated and initialized either statically or dynamically (see paper for dynamic).

13/July/1999Third USENIX Windows NT Symposium9 Detouring a Function: ;; Target Function Sleep: push ebp[1 byte] mov ebp,esp[2 bytes] push ebx[1 bytes] push esi[1 byte] push edi.... ;; Trampoline Function UntimedSleep: jmp Sleep ;; Detour Function TimedSleep:.... ;; Target Function Sleep: jmp TimedSleep[5 bytes] push edi.... ;; Trampoline Function UntimedSleep: push ebp mov ebp,esp push ebx push esi jmp Sleep+5 ;; Detour Function TimedSleep:.... Before: After:

13/July/1999Third USENIX Windows NT Symposium10 Invoking Your Code: StartTarget 1. Call 2. Return StartTarget 1. Call 6. Return Detour 2. Jump Trampoline 3. Call 5. Return Target 4. Jump Before: After:

13/July/1999Third USENIX Windows NT Symposium11 An Entire Example: SleptTicks 1: #include 2: #include 3: LONG slept = 0; 4: __declspec(dllexport) DETOUR_TRAMPOLINE(VOID WINAPI UntimedSleep (DWORD), Sleep); 5: __declspec(dllexport) VOID WINAPI TimedSleep(DWORD dwMilliseconds) 6: { 7: DWORD begin = GetTickCount (); 8: UntimedSleep ( dwMilliseconds ); 9: InterlockedExchangeAdd ( &slept, GetTickCount() – begin ); 10: } 11: __declspec(dllexport) DWORD WINAPI GetSleptTicks() 12: { 13: return slept; 14: } 15: BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) 16: { 17: if ( reason == DLL_PROCESS_ATTACH ) 18: DetourFunctionWithTrampoline ( UntimedSleep, TimedSleep ); 19: if ( reason == DLL_PROCESS_DETACH ) 20: DetourRemoveTrampoline ( UntimedSleep ); 21: }

13/July/1999Third USENIX Windows NT Symposium12 Micro-Benchmark Performance: Interception Technique Intercepted Function Empty FunctionCoCreateInstance Time Overhead Time Overhead Direct113 nsn/a 14.8  s n/a Call Replacement143 ns30 ns 15.2  s 360 ns DLL Redirection143 ns30 ns 15.2  s 360 ns Detour145 ns32 ns 15.2  s 360 ns Breakpoint Trap230k ns229k ns  s 265k ns Overhead:6 cycles for Empty Function 71 cycles for CoCreateInstance (5 Args.) 1 cache line

13/July/1999Third USENIX Windows NT Symposium13 Coign: ADPS using Detours 1. Find Objects in Application 2. Identify Interfaces and Measure Communication 3. Partition and Distribute  Convert desktop applications into distributed applications from binary files.

13/July/1999Third USENIX Windows NT Symposium14 Coign: COM API Extension Coign Profiling Runtime COM APIs Windows NT Coign Distributed Runtime COM APIs Windows NT COM APIs Windows NT Application Profiling:Distributed Execution:

13/July/1999Third USENIX Windows NT Symposium15 Coign Demo

13/July/1999Third USENIX Windows NT Symposium16 Other Applications of Detours  Detailed Analysis of DCOM (Millennium Falcon).  Intercept entry-points between DCOM layers.  Distributed COM-based Win32 API (COP).  Intercept large subset of Win32 API.  First-Chance Exception Filter  Intercept KiUserExceptionDispatcher.  Debugger support for non-standard loaders  Intercept WaitForDebugEvent (DebugString event to LoadDll event).  API Trace Facility.  Test Harnesses.  DLL Versioning  Attach manifest payload to binaries.

13/July/1999Third USENIX Windows NT Symposium17 Related Work  Code Patching [Gill ’51]  Age-old technique for modifying binaries.  Jump to patch, then either return or jump to target.  Binary Rewriters [Atom ’94, Etch ’97, EEL ’95]  Static binary rewriters.  Register allocation  For Detours the target, detour, and trampoline maintain same call signature to ensure registers are automatically preserved by compiler.  Fine granularity: instructions & basic blocks.  DyninstAPI [Hollingsworth & Buck ’98]  Dynamic binary rewriter.  Mediating Connectors [Balzer & Goldman, 1999]  DLL Redirection.

13/July/1999Third USENIX Windows NT Symposium18 Conclusions:  Detours provides fast (<100 cycles), light (<18KB.lib), flexible library for instrumenting Win32 binaries.  Trampoline preserve target semantics.  Enables compelling systems research.  Free for non-commercial & research use:  Future Work:  Alpha and Windows 95/98 Ports