30
On deobfuscation in practice Vasily Bukasov Dmitry Schelkunov

On deobfuscation in practice

Embed Size (px)

Citation preview

Page 1: On deobfuscation in practice

On deobfuscation in practice

Vasily Bukasov

Dmitry Schelkunov

Page 2: On deobfuscation in practice

Obfuscation applications

• Software protection against computer piracy

• Malware protection against automatic detection and to impede analysis of a malicious code

Page 3: On deobfuscation in practice

Obfuscators and protectors

• Manual obfuscation requires a lot of resources

• It’s much easier to use obfuscators and protectors which promise a strong obfuscation

Page 4: On deobfuscation in practice

Common code protection techniques

•Code encryption (out of scope of our report)

•Code virtualization

•Code morphing

Page 5: On deobfuscation in practice

Code virtualization

• Converts a source assembler code to the specially generated byte-code• Inserts byte-code and byte-

code interpreter into the source PE file

Page 6: On deobfuscation in practice

Code virtualization

Byte-code mostly represents original assembler instructions so its execution has the same

effect as from the original instructions

Page 7: On deobfuscation in practice

Code virtualization

Get instruction byte-code

Byte-code fetching

loop

Get instruction arguments from VM context or from another location

Process instruction

Save result into VM context or into another location

Page 8: On deobfuscation in practice

VM context

• Contains variables associated with processor registers• Contains VM state• Its location can be easily found in

most cases

Page 9: On deobfuscation in practice

VM context location

•Dynamically allocated memory (VirtualAlloc, HeapAlloc)

•Global memory (access via spinlock)

• Stack

Page 10: On deobfuscation in practice

VM stack context layout

Stack of the protected code

Reserved area

VM context rSP

0 Not initialized

Page 11: On deobfuscation in practice

«Virtualized» additionvoid unoptimal_addition( int a, int b, int *p )

{

int u, v, t, *r;

u = a;

v = b;

r = p;

t = u + v;

*r = t;

}

Page 12: On deobfuscation in practice

Virtualized code executionGetting byte-code

Loading from VM context

Instruction execution

Saving to VM context

Getting byte-code

Loading from VM context

Instruction execution

Saving to VM context

This code is asking to be optimized

etc…

Page 13: On deobfuscation in practice

Code devirtualization

•We can locate VM context

•We can get CFG in most cases

•We can use common code optimization algorithms to deobfuscate a virtualized code

Page 14: On deobfuscation in practice

Code morphing

•Used to increase resistance to the static analysis

•Used for the CFG obfuscation

•Used to increase VM body analyzing complexity

Page 15: On deobfuscation in practice

Code morphing and CFG obfuscation

Therefore protectors don’t even try to do it

It’s a difficult task to decompile a machine code

Page 16: On deobfuscation in practice

Code morphing and CFG obfuscation

Data dependencies analysis is weak in protectors

Therefore they are limited in choice of obfuscation techniques

Page 17: On deobfuscation in practice

Code morphing common techniques

Recursive templates

Instruction

Instruction

Instruction

Instruction

TemplateTemplate

Template

Template

Page 18: On deobfuscation in practice

Code morphing common techniques

• Dead code insertion

• Garbage code insertion

• Opaque predicates

• Jump address calculation

• Code cloning

Page 19: On deobfuscation in practice

Morphed code deobfuscation

•Decompilation into IR• IR instruction emulation• Collecting variables values• Emulation-based

deobfuscation techniques

Page 20: On deobfuscation in practice

Ariadne engine• An engine for RE• Can be used as IDA plugin• Enables PE format analyzing,

disassembling and modifying• Supports GP, FPU, MMX, SSE,

SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, SSE4a, VMX, SMX

Page 21: On deobfuscation in practice

Ariadne engine• Supports assembler instructions

translation into Ariadne Intermediate Representation (AIR)• Supports IR instructions

emulation• Contains emulator-based code

tracing mechanisms

Page 22: On deobfuscation in practice

Ariadne engine

• Contains built-in trace deobfuscation (AIR Wave Deobfuscation Technology)

Page 23: On deobfuscation in practice

AIR Wave Deobfuscation Technology

• Static deobfuscation–based on the classical compiler

theory approaches

–doesn’t use emulation

Page 24: On deobfuscation in practice

AIR Wave Deobfuscation Technology

• Dynamic deobfuscation–uses Ariadne IR emulator–calculates values of variables–determines in a lot of cases where a

pointer points to–used for dereferenced pointers

deobfuscation

Page 25: On deobfuscation in practice

AIR Wave Deobfuscation Technology

•Deobfuscation techniques–dead code elimination

–variables propagation

–constant folding

–math simplifications

Page 26: On deobfuscation in practice

AIR Wave Deobfuscation Technology

•Deobfuscation techniques–loop unrolling–common subexpression

elimination–pointer analysis and alias

classification

Page 27: On deobfuscation in practice

Our results

•Many obfuscators/protectors provide a weak obfuscation

• Ariadne engine can be effectively used for deobfuscation

Page 28: On deobfuscation in practice

AIR Wave Deobfuscation Technology

Tested on …

See it for yourself

Page 29: On deobfuscation in practice

And our thanks go…

• To Rolf Rolles for his works about virtualization obfuscation unpacking

• To Leta Group for Ariadne sponsorship

Page 30: On deobfuscation in practice

Ariadne engine

http://ariadne.group-ib.ru