Agenda. Motivation Generic unpacking Typical problems Results

Similar documents
A Survey of Obfuscations in Prevalent Packer Tools

ID: Sample Name: 11youtube3.com Cookbook: default.jbs Time: 08:17:42 Date: 12/04/2018 Version:

Virus Analysis. Introduction to Malware. Common Forms of Malware

T Jarkko Turkulainen, F-Secure Corporation

General Unpacking Overview and Techniques

Reverse Engineering Malware Binary Obfuscation and Protection

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

SA31675 / CVE

LdPinch Report. Feng Zhu Jinpeng Wei

Inside VMProtect. Introduction. Internal. Analysis. VM Logic. Inside VMProtect. Conclusion. Samuel Chevet. 16 January 2015.

Tim Ebringer The university of Melbourne, Australia Li Sun RMIT university, Australia Serdar Boztas RMIT university, Australia VB 2008 Ottawa,

Rootkits n Stuff

Comparison Of File Infection On The Windows And Linux lclee_vx / F-13 Labs, lychan25/f-13 Labs

Analyzing the packer layers of rogue anti-virus programs. Rachit Mathur, McAfee Labs Dr. Zheng Zhang, McAfee Labs

Random Code Variation Compilation Automated software diversity s performance penalties

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

The IA-32 Stack and Function Calls. CS4379/5375 Software Reverse Engineering Dr. Jaime C. Acosta

Practical Malware Analysis

CVE EXPLOIT USING 108 BYTES AND DOWNLOADING A FILE WITH YOUR UNLIMITED CODE BY VALTHEK

T Using debuggers to analyze malware. Antti Tikkanen, F-Secure Corporation

16.317: Microprocessor Systems Design I Fall 2014

Owning Command and Control: Reverse Engineering Malware. Risk Mitigators

Data Exfiltration Techniques

Implementing your own generic unpacker

Program Exploitation Intro

Overview of Compiler. A. Introduction

IA-32 Architecture. CS 4440/7440 Malware Analysis and Defense

Exploiting Stack Buffer Overflows Learning how blackhats smash the stack for fun and profit so we can prevent it

Autodesk AutoCAD DWG-AC1021 Heap Corruption

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta

Reverse Engineering Microsoft Binaries

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

ID: Sample Name: French.exe Cookbook: default.jbs Time: 15:57:57 Date: 24/03/2018 Version:

Pokas x86 Emulator for Generic Unpacking

Reversing Basics A Practical Approach

Optimizing Memory Bandwidth

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

TABLE OF CONTENT 1. Abstract: Terminology Introduction Basic Shellcoding Solving The Addressing Problem Hash API

Managing SonicWall Gateway Anti Virus Service

Reverse Engineering II: The Basics

CSC 8400: Computer Systems. Machine-Level Representation of Programs

W4118: PC Hardware and x86. Junfeng Yang

Searching and Sorting. Chen-Hanson Ting SVFIG August 25, 2018

WIBU protection knuth20 implementation analysis

Reverse Engineering II: The Basics

The Geometry of Innocent Flesh on the Bone

CSC 591 Systems Attacks and Defenses Return-into-libc & ROP

CS Bootcamp x86-64 Autumn 2015

The new signature generation method based on an unpacking algorithm and procedure for a packer detection

EECE.3170: Microprocessor Systems Design I Summer 2017

StarForce 3 - Brief insight into a hidden world. By [yates] [ [

ID: Sample Name: TBSERV.exe Cookbook: default.jbs Time: 01:52:14 Date: 23/11/2017 Version:

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Malware Analysis and Antivirus Technologies: Antivirus Engine Basics

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

Digital Forensics Lecture 3 - Reverse Engineering

Mario Vuksan and Tomislav Pericin, ReversingLabs FILE ANALYSIS AND UNPACKING: THE AGE OF 40M NEW SAMPLES PER YEAR

Packer Analysis Report-Debugging and unpacking the NsPack 3.4 and 3.7 packer.

SA30285 / CVE

COMPUTER ENGINEERING DEPARTMENT

Undetectable Metamorphic Viruses. COMP 116 Amit Patel

Static Analysis I PAOLO PALUMBO, F-SECURE CORPORATION

06 - Anti Dynamic Analysis

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

ID: Sample Name: MSVCR100.dll Cookbook: default.jbs Time: 16:59:36 Date: 30/04/2018 Version:

4. Jump to *RA 4. StackGuard 5. Execute code 5. Instruction Set Randomization 6. Make system call 6. System call Randomization

Lecture 4 CIS 341: COMPILERS

CSCD 303 Essential Computer Security Fall 2017

anti-virus and anti-anti-virus

Lecture 10 Return-oriented programming. Stephen Checkoway University of Illinois at Chicago Based on slides by Bailey, Brumley, and Miller

CPS104 Recitation: Assembly Programming

Proposed Common Configuration Method

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

UMBC. 1 (Feb. 9, 2002) seg_base + base + index. Systems Design & Programming 80x86 Assembly II CMPE 310. Base-Plus-Index addressing:

Equa%onal Reasoning of x86 Assembly Code. Kevin Coogan and Saumya Debray University of Arizona, Tucson, AZ

Betriebssysteme und Sicherheit Sicherheit. Buffer Overflows

Malware Analysis and Antivirus Technologies: Using Debuggers to Analyze Malware

Objectives. ICT106 Fundamentals of Computer Systems Topic 8. Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8

Protecting Against Unexpected System Calls

BITDEFENDER. White paper

Inspecting and Manipulating binaries

In executable we have several anti-debugging, anti-tracing and anti-patching tricks:

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

Branching and Looping

Towards the Hardware"

EECE416 :Microcomputer Fundamentals and Design. X86 Assembly Programming Part 1. Dr. Charles Kim

ROPInjector: Using Return- Oriented Programming for Polymorphism and AV Evasion

Return-orientated Programming

Stack Shape Analysis to Detect Obfuscated calls in Binaries

16.317: Microprocessor Systems Design I Spring 2015

Lab 3. The Art of Assembly Language (II)

like a boss Automatically Extracting Obfuscated Strings from Malware

Get Max Internet Security where to buy software for students ]

Security-Aware Processor Architecture Design. CS 6501 Fall 2018 Ashish Venkat

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

The X86 Assembly Language Instruction Nop Means

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing

Transcription:

Who we are Product: ewido security suite Protection against Trojans, Adware, Spyware,... First release: Christmas 2003 Emulation research since 2002 Used for generic unpacking

Agenda Motivation Generic unpacking Typical problems Results

Motivation How PE compression engines work Static unpacking When static unpacking engines fail

How PE compression engines work Malware is detected by searching for known patterns Malware is detected by heuristics analysis PE compression engines compress or encrypt the content of portable executables Compression/encryption cause pattern matching and heuristics analysis fail

How PE compression engines work Structure of PE compression engines is usually the same Look at a very simple one to show the most important issues Lamecrypt encrypts the body by XOR Loader is appended to decrypt at runtime

How PE compression engines work Loader of Lamecrypt mob ebx, 0001D600 decryptloop: xor [ebx+00401000], 90 dec ebx cmp ebx, -1 jnz decryptloop jmp 0041DA48

Static unpacking Analyze decompress-/decrypt-algorithm Decompress/decrypt with specific routine Which PE compression engine was employed? Pick required parameters Invoke the specific routine

Static unpacking Special routine for Lamecrypt void decrypt_lamecrypt(byte* image, DWORD size) { if (checksig(entrypoint+0x0f, 4B83FBFF75F39D )) { DWORD offset = getdword(entryoint+0x0a); DWORD size = getdword(entrypoint+0x04); for (DWORD i=0; i<size; i++) image[i] = image[i] ^ 0x90; } }

When static unpacking engines fail Unknown PE compression engine No specific routine No way to decrypt/decompress Modified PE compression engine Detection fails and required parameters cannot be extracted

When static unpacking engines fail Bagle Uses its own PE compression engine to hide the malicious activity Could be detected easily by heuristics Even simple compression engines are effective

When static unpacking engines fail Bagle... mov esi, 00401000 mov edi, esi mov ecx, 00004F4B cld decryptloop: lodsb xor al, 13 stosb loop decryptloop

When static unpacking engines fail Yodacrypter Modified PE compression engine Modification is very easy (open source) Often used with backdoors

When static unpacking engines fail Yodacrypter original loader pushad call +00 pop ebp sub ebp, 00401DF3 mov ecx, 97B lea edi, [ebp+00401e3b] modified loader pushad call +00 pop ebp sub ebp, 00401F0 mov ecx, 15 add ebp, 3 mov ecx, 97B lea edi, [ebp+00401e3b]

When static unpacking engines fail Unknown PE compression engines Attacks on detection Attacks on parameters

Generic unpacking What do we need? How to unpack every PE compression engine CPU simulation Memory simulation Operating system simulation

What do we need? Decompress/decrypt PE compression engine without knowing which PE compression engine was employed Decompress/decrypt without parameters or algorithm

Unpack every PE compression engine Execute the malware, wait a little and perform a memory scan Every PE compression engine needs to unpack/decrypt its content in memory Ultimate generic unpacker

Unpack every PE compression engine Very unsafe! Extension: instead of execution Emulation If the emulation can achieve a near-perfect simulation of the reality Ultimate and safe generic unpacker

CPU Simulation Known to handle polymorphic viruses Step by step each instruction is simulated

CPU Simulation mob ebx, 0001D600 set sim_ebx to 0001D600 calculate address, map, xor with 0x90 decryptloop: xor [ebx+00401000], 90 dec ebx decrease sim_ebx by one cmp ebx, -1 jnz decryptloop

CPU Simulation PE compression engines execute millions of instructions All of them have to be emulated! Speed is the most important problem 450kb executable packed with UPX 6 million instructions to unpack

Memory Simulation Has to be very fast Decompression routines transfer lots of bytes 450kb packed executable Theoretically 900.000 memory operations The number of operations often doubles

Memory Simulation Need to simulate stack, executable image, heap Needs to be flexible Some anti-debugging techniques rely on write access exceptions Simulate read/write access

Operating System Simulation Import table needs to be rewritten LoadLibrary/GetProcAddress Some PE compression engines check CRC File system APIs Bagle tries to fool emulation with seldom APIs

Operating System Simulation Simulate each API directly Our generic unpacker support more than 100 APIs

Operating System Simulation 1000BF88: RegisterWindowMessage(ArmReReadMessage); 1000BF94: PostMessageA 1000F4F7: GetCurrentProcessId 1000F57F: CreateFileA("\\.\SICE",..., 3,...) 1000F593: GetLastError -> 2 1000F57F: CreateFileA("\\.\NTICE",..., 3,...) 1000F593: GetLastError -> 2 1000F57F: CreateFileA("\\.\SIWDEBUG",..., 3,...) 1000F593: GetLastError -> 2 1000F57F: CreateFileA("\\.\SIWVID",..., 3,...) 1000F593: GetLastError -> 2

Operating System Simulation 100082BC: RegOpenKeyEx(80000000, CLSID\{C9DC10FD- D921-13D1B2E4-0060975B8649},..); 100078C8: GetSystemTime 10008230: GetTempPath (return c:\temp\) 10008262: CreateFileA("c:\temp\58AB070C.TMP",..., 3,...) 100078C8: GetSystemTime 10008113: RegOpenKeyEx(80000002, Software\The Silicon Realms Toolworks\Armadillo,..); 1000812C: RegQueryValueEx(0,{65EED8A09843E1F6},..); 10008143: RegCloseKey

Operating System Simulation 479576: LoadLibraryA(advapi32.dll) 479646: GetProcAddress(77DA0000, 100194A8->RegCloseKey) 479646: GetProcAddress(77DA0000, 100194CA->RegOpenKeyExA) 479646: GetProcAddress(77DA0000, 100194DA->RegSetValueExA) 479646: GetProcAddress(77DA0000, 100194EC->RegCreateKeyExA) 479576: LoadLibraryA(shell32.dll) 479646: GetProcAddress(5, 1001950C->ShellExecuteA)

Typical Problems Error tracing When to stop? Speed

Error Tracing What do you do if your emulation engine does not emulate correctly? Millions of instructions Error tracing very complex Solution: automatically debug during emulation Comparison reveals most errors

Error Tracing Load_Real_Exe(); Start_Debugger_For_Real_Exe(); while (!different) { Emulate_One_Instruction(); Execute_One_Instruction_With_Debugger(); Compare_Emulation_With_Reality(); }

When to stop? When can we stop the emulation? Undecidable Fallback: maximum time-out Heuristic checks

When to stop? Possible heuristic rules Entry point signatures from standard entry points Stop at some API functions Relationship between emulated opcodes/simulated API functions

Speed Speed is the most important problem CPU simulation needs to be as fast as possible Measure speed on AMD64 3000+ Measure speed on Athlon XP 1200

Speed Usual algorithm 1 while (true) { Decode_Instruction(r.eip); Lookup_Simulation_Function(); Execute_This_Instruction(); }

Speed Usual algorithm 2 void Xor_Simulation_Function() { Decode_Mod_Rm(op_1, op_2); if (op_2 is memory) ReMap_Memory(op_2); op_1 = op_1 XOR op_2; }

Speed Usual algorithm - Speed (UPX) CPU Instructions Time(ms) Speed (MIPS) AMD64 5.939.677 859 6,9 Athlon XP 5.939.677 1317 4,5

Speed Code usually does not change Fast decoding cache Generate special code at runtime Reduces conditional jumps Form blocks and link them together Reduces unpredictable jumps

Speed Improved emulation algorithm 1 while (true) { if (Is_Instruction_In_Cache(r.eip)) Jump_To_Instruction_Code(); else Translate_Instruction(); }

Speed Improved emulation algorithm 2 void Translate_Instruction() { Decode_Instruction(r.eip); Generate_Individual_Code(); Insert_Code_Into_Cache(); Chain_Code_Block(); }

Speed Improved algorithm - Speed (UPX) comparison CPU Instructions Time(ms) Speed (MIPS) AMD64 5.939.677 67 (859) 89 (6,9) Athlon XP 5.939.677 104 (1317) 57 (4,5)

Results Generic unpacking not often used in anti-virus engines Showed that generic unpacking is possible in practise

Results Armadillo, ASPack, Exegriper, FSG, Lamecrypt, Mew, Morphine, Neolite, Netwalker, PCShrink, PECompact, PEPack, Petite, PEX, PKLite32, StonesPECrypter, UPack, UPX, Winkript, YodaCrypter Can be unpacked in 20-300ms (80-100MIPS) All variants and modified versions

Recent improvements Improved code quality Performed compiler like optimization Improved perfomance: Lamecrypt 486 MIPS (34 MIPS) UPX 553 MIPS (89 MIPS)

Questions/Comments? You can also write an e-mail to tobias.graf@ewido.net