Identification and Removal of



Similar documents
Attacking Obfuscated Code with IDA Pro. Chris Eagle

Lecture 26: Obfuscation

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

Software Fingerprinting for Automated Malicious Code Analysis

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

Hotpatching and the Rise of Third-Party Patches

Diving into a Silverlight Exploit and Shellcode - Analysis and Techniques

Introduction to Reverse Engineering

Reverse Engineering and Computer Security

Fighting malware on your own

Assembly Language: Function Calls" Jennifer Rexford!

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

REpsych. : psycholigical warfare in reverse engineering. def con 2015 // domas

Self Protection Techniques in Malware

Binary Code Extraction and Interface Identification for Security Applications

esrever gnireenigne tfosorcim seiranib

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

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

Introduction. Figure 1 Schema of DarunGrim2

Inside a killer IMBot. Wei Ming Khoo University of Cambridge 19 Nov 2010

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

Stack Overflows. Mitchell Adair

An Iteration Obfuscation Based on Instruction Fragment Diversification and Control Flow Randomization

Violating Database - Enforced Security Mechanisms

All Your Code Belongs To Us Dismantling Android Secrets With CodeInspect. Steven Arzt Secure Software Engineering Group Steven Arzt 1

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

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

1. General function and functionality of the malware

Removing Sentinel SuperPro dongle from Applications and details on dongle way of cracking Shub-Nigurrath of ARTeam Version 1.

Jakstab: A Static Analysis Platform for Binaries

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

Harnessing Intelligence from Malware Repositories

EU FP6 LOBSTER. personal view on the future of ero-day Worm Containment. European Infrastructure for accurate network monitoring

Stack Allocation. Run-Time Data Structures. Static Structures

Platform-independent static binary code analysis using a metaassembly

Efficient Program Exploration by Input Fuzzing

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

Return-oriented programming without returns

Software Code Protection Through Software Obfuscation

INTRODUCTION TO MALWARE & MALWARE ANALYSIS

Automating Mimicry Attacks Using Static Binary Analysis

Hypervisor-Based, Hardware-Assisted System Monitoring

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

Detecting the One Percent: Advanced Targeted Malware Detection

64-Bit NASM Notes. Invoking 64-Bit NASM

Where s the FEEB? The Effectiveness of Instruction Set Randomization

Custom Penetration Testing

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

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

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

Fine-grained covert debugging using hypervisors and analysis via visualization

X86-64 Architecture Guide

The Value of Physical Memory for Incident Response

Off-by-One exploitation tutorial

Dynamic Behavior Analysis Using Binary Instrumentation

Storm Worm & Botnet Analysis

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

NGBPA Next Generation BotNet Protocol Analysis

Reversing C++ Paul Vincent Sabanal. Mark Vincent Yason

Analysis and Diversion of Duqu s Driver

Mobile Payment Security

Software Vulnerabilities

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Character Translation Methods

Static detection of C++ vtable escape vulnerabilities in binary code

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

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

Adi Hayon Tomer Teller

What Happens In Windows 7 Stays In Windows 7

Advanced artefact analysis Advanced static analysis

Computer Virus Strategies and Detection Methods

Buffer Overflows. Security 2011

Instruction Set Architecture

Static Analysis of Virtualization- Obfuscated Binaries

TO APPEAR IN: IEEE TRANSACTIONS ON DEPENDABLE AND SECURE COMPUTING 1. Proactive Detection of Computer Worms Using Model Checking

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

A Museum of API Obfuscation on Win32

1 Classical Universal Computer 3

Indicator Expansion Techniques Tracking Cyber Threats via DNS and Netflow Analysis

Obfuscation: know your enemy

Title: Bugger The Debugger - Pre Interaction Debugger Code Execution

Dynamic Spyware Analysis

Computer Organization and Architecture

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

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

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

Advanced ANDROID & ios Hands-on Exploitation

Code Obfuscation Literature Survey

Attacking x86 Windows Binaries by Jump Oriented Programming

Introduction. Current personal firewalls are focused on combating usermode malware. Overview. What about protection against rootkits?

1 Step 1: Select... Files to Encrypt 2 Step 2: Confirm... Name of Archive 3 Step 3: Define... Pass Phrase

System/Networking performance analytics with perf. Hannes Frederic Sowa

Bypassing Anti- Virus Scanners

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Transcription:

RIVERSIDE RESEARCH INSTITUTE Deobfuscator: An Automated Approach to the Identification and Removal of Code Obfuscation Ei Eric Laspe, Reverse Engineer Jason Raber, Lead Reverse Engineer

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

The Problem: Obfuscated Code Malware authors use code obfuscation techniques es to hide their malicious code Obfuscation costs reverse engineers time: Complicates instruction sequences Disrupts control flow Makes algorithms difficult to understand Manual obfuscation removal is a tedious and error-prone process

Example: PUSH_POP_MATH PUSH an immediate, then POP into a register and do some math on it Obfuscated code: PUSH a value POP it into EDX Math on EDX Resolves to: Emulate Result NOP Unnecessary Instructions

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

Malware Example: RustockB Good malware example that implemented obfuscation patterns to hide a decryption routine Many useless and confusing instructions Push regs, math, pop regs Pushes and pops in various obfuscated forms Control flow obscured Mangled jumps Unnecessary data cross-references references

RustockB Control Flow

RustockB Control Flow Unref d Obfuscated Instruction Pop Obfuscated Jump Obfuscated Push Obfuscated Jump Obfuscated Jump

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

The Solution: The Deobfuscator IDA Pro Plug-in Combines instruction emulation and pattern recognition Determines proper code control flow Interprets and transforms instruction sequences to enhance code readability Uses a binary injector to make both static and dynamic analysis easier

Modes of Operation The plug-in has six modes: Anti-disassembly replaces anti-disassembly with simplified code Passive simple peep-hole rules Aggressive uses aggressive assumptions about memory contents Ultra more aggressive assumptions Remove NOPs jumps over slack space Collapse moves consecutive code blocks together to eliminate NOPs and JMPs

IDA Pro Integration Deobfuscator plug-in invoked with Alt-Z Uses structures created by IDA Pro disassembly and analysis Depending on the mode selected, it can: Follow jumps and calls Track registers and emulate the stack

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

Demonstration Demo code protected with anti-disassembly code and obfuscation Note the obfuscated jump at the end of this graph Run iteratively, the Deobfuscator will remove obfuscation and improve code flow readability

Run 1 Anti-Disassembly Two matching patterns JZ_JMPJMP CALL_MATH

Pattern: JZ_JMP Two useless jumps Before Deobfuscation: Useless Jumps After Deobfuscation: NOP d Jumps

Pattern: CALL_MATH EDX gets the return address of the CALL $5 Then, there is some math on EDX Before Deobfuscation: EDX = 401033 After Deobfuscation: Emulated Result NOP d Pop & Math

Output Injection A text file is generated by the Deobfuscator plug-in Then, we inject the binary with a PERL script Or just modify the IDA Pro database

Reload Now, we see the obfuscated code begin to disappear The Deobfuscator replaces obfuscation patterns and injects NOPs over useless code to create slack space

Slack Space Slack space is useful for patterns that need additional bytes to create a simplified instruction Example: Obfuscated Code PUSH EAX * NOP NOP NOP NOP POP EBX Needs two bytes Needs five bytes Transformed Code 1 MOV EBX, EAX NOP NOP NOP NOP Transformed Code 2 MOV EBX, IMMED NOP *Code that was removed by an earlier run of the Deobfuscator

Run 2 Passive, Aggressive, & Ultra Three matching patterns MOV_MATHMATH MATH_MOV_OR_POP MATH_MOV_OR_POP

Pattern: MOV_MATH Move an immediate into EAX and XOR it with another known register value Before Deobfuscation: Move into EAX EAX Math After Deobfuscation: Emulated Result NOP d Math

Pattern: MATH_MOV_OR_POP Do math on EDX, then MOV an immediate or POP from the stack into EDX before using it again Before e Deobfuscation: o EDX Math After Deobfuscation: NOP d Math

Finishing Up The Deobfuscator has finished matching obfuscation patterns Slack space is no longer needed, so we run one of the clean-up modes to simplify the appearance of the control flow NOP Remove injects JMPs to remove NOPs from control flow Collapse mode moves code to slack space to eliminate NOPs and JMPs

NOP Remove Before: After:

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

RustockB: Before & After Deobfuscated!

RustockB Decryption Pseudo-code for (i = 7; i > 0; i--) { Address = 0x00401B82 // Starting address of encrypted region Key1 = 0x4DFEE1C0 // Decryption key 1 Key2 = 0x0869ECC50869ECC5 // Decryption key 2 Key3 = 0 // Decryption key 3 Key4 = 0 // Decryption key 4 (Accumulator) for (j = 0x44DC; j > 0; j--, Address += 4) // 0x44DC = size of encrypted region } { } for (k = 2; k > 0; k--) { Key4 = k * 4 XOR Key4, 0x5E57B7DE XOR Key4, Key3 Key4 += Key2 XOR Key1, k [Address] -= Key4 Key3 += Key1 } for (i = 0x44DC, Address = 0x00401B82, Sum = 0; i > 0; i--, Address += 4) Sum += [Address] // Add up the encrypted region (a DWORD at a time) in EAX for (i = 0x44DC, Address = 0x00401B82; i > 0; i--, Address += 4) XOR [Address], Sum // XOR each DWORD of the encrypted region with the sum in EAX

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

Sample Source Code The Simple Solution: A Simple Problem: //------------------------------------------------------------------------------- // CALL NULL - A function call that just returns //------------------------------------------------------------------------------- int CALL_NULL(insn_t call, FILE *outfile, int *instr_offset) { if (call.itype == NN_call && call.operands[0].type == o_near) { if (!get_next_instruction(call.operands[0].addr)) return 0; insn_t ret = cmd; // Function that just returns if (ret.itype == NN_retn) { *instr_offset t = call.size; msg("\n%a CALL_NULL\n", call.ea); // NOP the call fprintf(outfile, "%X 5 90 90 90 90 90\n", get_fileregion_offset(call.ea)); // NOP the return fprintf(outfile, "%X 1 90\n", get_fileregion_offset(ret.ea)); } } return 1; } return 0;

Overview The Problem: Obfuscation Malware Example: RustockB The Solution: Deobfuscator Demonstration RustockB: Before & After Sample Source Code Summary

Summary Most malware authors that wish to protect their IP use obfuscation techniques The Deobfuscator detects and simplifies many of these obfuscation and antidisassembly patterns Over time, the repository of patterns will be developed to characterize most generic cases of obfuscation

Future Development Iterative patching of IDA database

Future Development Iterative patching of IDA database Code collapsing

Future Development Iterative patching of IDA database Code collapsing Grammar Black-box control flow

Contact For more information on this and other tools, contact: Eric Laspe, Reverse Engineer elaspe@rri-usa.org 937-427-7042 7042 Jason Raber, Lead Reverse Engineer jraber@rri-usa.org 937-427-7085 Visit us online: http://www.rri-usa.org/isrsoftware.html i h