Attacking Obfuscated Code with IDA Pro. Chris Eagle



Similar documents
Fine-grained covert debugging using hypervisors and analysis via visualization

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

Lecture 26: Obfuscation

File Disinfection Framework (FDF) Striking back at polymorphic viruses

Identification and Removal of

Parasitics: The Next Generation. Vitaly Zaytsev Abhishek Karnik Joshua Phillips

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

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

Binary Code Extraction and Interface Identification for Security Applications

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

Sandy. The Malicious Exploit Analysis. Static Analysis and Dynamic exploit analysis. Garage4Hackers

Bug hunting. Vulnerability finding methods in Windows 32 environments compared. FX of Phenoelit

Introduction to Reverse Engineering

Analysis of FileVault 2: Apple's full disk encryption. Omar Choudary Felix Grobert Joachim Metz

Reverse Engineering by Crayon: Game Changing Hypervisor and Visualization Analysis

How to Sandbox IIS Automatically without 0 False Positive and Negative

Adi Hayon Tomer Teller

Hotpatching and the Rise of Third-Party Patches

Melde- und Analysestelle Informationssicherung MELANI Torpig/Mebroot Reverse Code Engineering (RCE)

for Malware Analysis Daniel Quist Lorie Liebrock New Mexico Tech Los Alamos National Laboratory

Monitoring, Tracing, Debugging (Under Construction)

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

Peeking into Pandora's Bochs { Instrumenting a Full System Emulator to Analyse Malicious Software

Peeking into Pandora s Bochs. Instrumenting a Full System Emulator to Analyse Malicious Software

Storm Worm & Botnet Analysis

umps software development

API Monitoring System for Defeating Worms and Exploits in MS-Windows System

Software Reversing Engineering (a.k.a. Reversing) Spiros Mancoridis. What is Reverse Engineering? Software Reverse Engineering: Reversing

Custom Penetration Testing

Bypassing Browser Memory Protections in Windows Vista

DS-5 ARM. Using the Debugger. Version Copyright ARM. All rights reserved. ARM DUI0446P

Instrumentation Software Profiling

Lecture 1 Introduction to Android

Exploiting nginx chunked overflow bug, the undisclosed attack vector

CSC 2405: Computer Systems II

Real-time Debugging using GDB Tracepoints and other Eclipse features

CVE Adobe Flash Player Integer Overflow Vulnerability Analysis

1 The Java Virtual Machine

Assembly Language: Function Calls" Jennifer Rexford!

Anti-Virus Evasion Techniques and Countermeasures

Automatic Logging of Operating System Effects to Guide Application-Level Architecture Simulation

Automatic Network Protocol Analysis

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

Encryption Wrapper. on OSX

CAS : A FRAMEWORK OF ONLINE DETECTING ADVANCE MALWARE FAMILIES FOR CLOUD-BASED SECURITY

DS-5 ARM. Using the Debugger. Version Copyright ARM. All rights reserved. ARM DUI 0446M (ID120712)

An Implementation Of Multiprocessor Linux

From Georgia, with Love Win32/Georbot. Is someone trying to spy on Georgians?

DS-5 ARM. Using the Debugger. Version 5.7. Copyright 2010, 2011 ARM. All rights reserved. ARM DUI 0446G (ID092311)

ELEC 377. Operating Systems. Week 1 Class 3

CS61: Systems Programing and Machine Organization

A Day in the Life of a Cyber Tool Developer

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

Red Hat Linux Internals

CS Computer Security Thirteenth topic: System attacks. defenses

Dongwoo Kim : Hyeon-jeong Lee s Husband

Chapter 14 Analyzing Network Traffic. Ed Crowley

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

Get the Better of Memory Leaks with Valgrind Whitepaper

So You Want To Analyze Malware? Tools, Techniques, and Mindset

Nios II IDE Help System

Android Packer. facing the challenges, building solutions. Rowland YU. Senior Threat Researcher Virus Bulletin 2014

Behavior-based Spyware Detection

Application Note C++ Debugging

PE Explorer. Heaventools. Malware Code Analysis Made Easy

ios applications reverse engineering Julien Bachmann

Introduction to Embedded Systems. Software Update Problem

Introduction. Figure 1 Schema of DarunGrim2

Software Vulnerabilities

Pentesting ios Apps Runtime Analysis and Manipulation. Andreas Kurtz

Dynamic Spyware Analysis

Testing for Security

Leak Check Version 2.1 for Linux TM

Self Protection Techniques in Malware

Operating System Overview. Otto J. Anshus

Anti-RE Techniques in DRM Code

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Modern Binary Exploitation Course Syllabus

Mobile Application Hacking for Android and iphone. 4-Day Hands-On Course. Syllabus

Security & Exploitation

ABAP Debugging Tips and Tricks

esrever gnireenigne tfosorcim seiranib

Helping you avoid stack overflow crashes!

Dynamic analysis of malicious code

ios Testing Tools David Lindner Director of Mobile and IoT Security

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

CS3600 SYSTEMS AND NETWORKS

Reverse Engineering and Computer Security

The Value of Physical Memory for Incident Response

Transcription:

Attacking Obfuscated Code with IDA Pro Chris Eagle

Outline Introduction Operation Demos Summary 2

First Order Of Business MOVE UP AND IN! There is plenty of room up front I can't increase the font size in IdaPro 3

Background IDA Pro Interactive Disassembler Professional http://www.datarescue.com/idabase Premier disassembly tool for reverse engineers Handles many families of assembly language Runs on Windows Linux in the works! 4

What? ida-x86emu is a plugin for IDA Pro that allows for emulated execution of x86 instruction set Written in C++ Currently packaged as VC++ 6.0 project Available here: http://sourceforge.net/projects/ida-x86emu 5

Why? Hand tracing assembly language is a pain in the ass Anti-reverse engineering techniques attempt to obfuscate code paths Allows automated unpacking/decrypting of "protected" binaries UPX, burneye, shiva, telock, ASPack, 6

Primary Motivation Getting at protected executables Most viruses/worms are protected in some way Often UPX, telock, ASPack Challenge for static reverse engineering is getting past the protection ida-x86emu allows you to "run" through the decryption routine within IDA Pro 7

Outline Introduction Operation Demos Summary 8

IDA Pro Load the binary of interest IDA builds a database to characterize each byte of the binary Performs detailed analysis of code Recognizes function boundaries and library calls Recognizes data types for known library calls 9

Obfuscated Code Challenging for IDA Usually only get sensible output for entry point function Protected program appears as data rather than code because it is obfuscated/encrypted Jumps into middle of instructions confuse flow analysis 10

The Plugin Two pieces User interface Windows-specific gui code Handles dialog boxes x86 emulator Platform independent Executes a single instruction at a time Reads from IDA database or user-supplied memory block 11

Console 12

Using It Alt-F8 brings it up eip initialized to cursor Step and go The plugin tells IDA to reorganize its code display based on ACTUAL code paths Defeats jump into the middle of an instruction type obfuscation 13

Features Run to Cursor No breakpoints yet Plugin supplies its own stack Stack push places arguments on the stack Useful if you want to setup a function call Plugin supplies its own heap Redirect library functions to plugin provided equivalents 14

Limitations Slow Because of emulated execution and IDA interactions Can't follow calls into dynamically linked functions Can't follow system calls in statically linked functions 15

Emulator Memory Code and static data must be fetched from IDA database Other references must be directed to either stack or heap Every memory reference checked Could easily add Valgrind type analysis 16

Memory Layout Emulation options allow you to specify memory layout 17

Emulated Stack Used by all stack operations in the program Stack contents displayed in main emulation window Auto scrolls to most recent reference Allows pushing data onto stack outside of program control Useful to setup and run individual functions 18

Emulated Stack Pushed right to left per C convention 19

Emulated Heap Simple linked list memory allocator Does not emulate any specific allocation algorithm Specifically, no in-band control info Won't mimic heap overflow problems Can detect access outside allocated blocks 20

Function Hooking Heap functions only at the moment Two methods Manual invocation of emulator equivalent function Result in eax, actual call statement in code must be "skipped" Automatic hooked invocation of emulator equivalent function call statement redirected to emulated library function 21

Manual Function Hooking Required parameters, if any, taken from stack Result into eax No change to eip 22

Automatic Function Hooking Step through hooked call statement causes emulator equivalent to be executed instead 23

Windows Structured Exception Handling (SEH) Work in progress telock for example uses SEH as an anti-re technique Point FS register at dummy Thread Environment Block Few recognized exceptions Divide by zero, INT3, single step, Debug registers 24

SEH (continued) Emulated program must have setup an exception handler Emulator creates SEH data structures, pushes them on the stack and jumps to user defined exception handler 25

Outline Introduction Operation Demos Summary 26

UPX Demo One of the most common obfuscators Reversible using UPX itself UPX corruptors exist that break UPX's reversing capability Simple unpacking loop, no tricks No problem for the plugin Doesn't rebuild import table yet 27

ASPack Demo ASPack requires LoadLibrary, GetProcAddress Used to retrieve VirtualAlloc and VirtualFree Currently emulator mimics VirtualAlloc and VirtualFree Skip LoadLibrary and GetProcAddress calls Hook VirtualAlloc and VirtualFree calls 28

telock Demo Sets up Windows exception handlers, then generates exceptions to jump into handlers Grab some memory for TEB and point FS register at it Execute a malloc or manually push a bunch of data Enable Windows SEH in plugin and execute code 29

Burneye Demo Early ELF protector by Team TESO Embeds the entire protected ELF binary within a protective unwrapper Offers layers of obfuscation/encryption Once decrypted, the protected binary can be dumped out of the IDA database Plugin provides a dump block to file capability 30

Shiva Demo Shiva is a binary protector Similar goals to Burneye Multilevel encryption protects binary Polymorphic stage 1 decryptor Embedded key recovery functions for last stage decryption 31

32

Shiva Key Recovery Shiva contains 5 different types of encrypted blocks Each block gets its own key Blocks of same type share the same key In this case we need to recover 5 keys in order to decrypt all of the types of blocks 33

Key Obfuscation Shiva contains a key reconstruction function for each type of crypt block Block decryption sequence Identify block type (0-IV) Call appropriate key reconstruction function Decrypt block Clear the key 34

Key Construction Functions are obfuscated Similar to layer 1 decrypt Differ from one binary to the next Resistant to script-based recovery But They are easy to locate A table points to the start of each function 35

Key Extraction The plugin can be used to run the functions and collect the keys! Setup desired parameters on the stack Pointer parameters need to point to valid memory blocks Grab memory on stack Manually invoke malloc Point eip at the function and step 36

Using the Keys With 5 keys in hand it is possible to decrypt all of the crypt blocks The plugin can be used to invoke Shiva's decryption function Setup the stack Pointer to the block Pointer to the key Step through the decryption function 37

Outline Introduction Operation Demos Summary 38

To Do Breakpoints More library calls Better memory displays Memory use reporting Improved exception handling 39

Summary Acts as something of a "universal" decryption script for protected binaries Dramatically reduces time to reverse protected binaries Emulator code can be used independently of gui code to create automated unwrappers Combine with ELF or PE parser Suggestions welcome 40

Questions? Thanks for coming Contact info: Chris Eagle 41

References Armouring the ELF: Binary encryption on the UNIX platform, grugq & scut, http://www.phrack.org/phrack/58/p58-0x05 Shiva: Advances in ELF Runtime Binary Encryption, Clowes & Mehta, Black Hat USA 2003, http://www.blackhat.com/presentations/bh-usa-03/bh-us- 03-mehta/bh-us-03-mehta.pdf Strike/Counter Strike: Reverse Engineering Shiva, Eagle, Black Hat Federal 2003, http://www.blackhat.com/presentations/bh-federal-03/bhfederal-03-eagle/bh-fed-03-eagle.pdf 42

References Shiva-0.96, Clowes & Mehta, http://www.blackhat.com/presentations/bh-usa-03/bh-us- 03-mehta/bh-us-03-shiva-0.96.tar Burneye-1.0.1, scut, http://teso.scene.at/releases/burneye- 1.0.1-src.tar.bz2 IDA Pro, Data Rescue, http://www.datarescue.com/idabase/ The Ultimate Packer for executables http://upx.sourceforge.net/ 43