Laboratoire Exploration et recherche en Dtection LED Agence - - PowerPoint PPT Presentation

laboratoire exploration et recherche en d tection
SMART_READER_LITE
LIVE PREVIEW

Laboratoire Exploration et recherche en Dtection LED Agence - - PowerPoint PPT Presentation

Laboratoire Exploration et recherche en Dtection LED Agence Nationale de la Scurit des Systmes dInformation 2019 VMProtect Compression Imports protection Code mutation ... VIRTUALIZATION ANSSI Laboratoire


slide-1
SLIDE 1

Laboratoire Exploration et recherche en Détection

LED Agence Nationale de la Sécurité des Systèmes d’Information

2019

slide-2
SLIDE 2

VMProtect

◮ Compression ◮ Imports protection ◮ Code mutation ◮ ... ◮ VIRTUALIZATION

ANSSI Laboratoire Exploration et recherche en Détection 2/47

slide-3
SLIDE 3

File geometry

.text .rdata .data

ANSSI Laboratoire Exploration et recherche en Détection 3/47

slide-4
SLIDE 4

File geometry

.text .rdata .data f1 f2

ANSSI Laboratoire Exploration et recherche en Détection 3/47

slide-5
SLIDE 5

File geometry

.text .rdata .data f1 f2 .vmp0

ANSSI Laboratoire Exploration et recherche en Détection 3/47

slide-6
SLIDE 6

File geometry

.text .rdata .data .vmp0 itrp bytecode itrp / bytecode itrp / bytecode

ANSSI Laboratoire Exploration et recherche en Détection 3/47

slide-7
SLIDE 7

Interpreter code is obfuscated

. vmp0 :004047D3 and ah , d l ( junk ) . vmp0 :004047D5 mov eax , [ ebp +0] . vmp0 :004047D8 s a l dl , 3 ( junk ) . vmp0 :004047DB c l c ( junk ) . vmp0 :004047DC mov dh , 0E3h ( junk ) . vmp0 :004047DF t e s t esp , eax ( junk ) . vmp0 :004047E1 mov edx , [ ebp +4] . vmp0 :004047E4 t e s t eax , 0A4B7FFF0h ( junk ) . vmp0 :004047E9 t e s t bh , bh ( junk ) . vmp0 :004047EB pushf ( junk ) . vmp0 :004047EC not eax . vmp0 :004047EE t e s t cl , 5Ch ( junk ) . vmp0 :004047F1 c l c ( junk ) . vmp0 :004047F2 s t c ( junk ) . vmp0 :004047F3 not edx . vmp0 :004047F5 pushf ( junk ) . vmp0 :004047F6 jmp l o c 4053BF

ANSSI Laboratoire Exploration et recherche en Détection 4/47

slide-8
SLIDE 8

V2 Interpreter

push add

nor jmp

dispatcher

ANSSI Laboratoire Exploration et recherche en Détection 5/47

slide-9
SLIDE 9

V3 Interpreter

push add

nor jmp

ANSSI Laboratoire Exploration et recherche en Détection 6/47

slide-10
SLIDE 10

Native registers roles

x86 x64 vip esi rsi vsp ebp rbp virtual registers edi (x 16) rdi (x 24) decryption mask ebx rbx

  • pcode (@handler entry)

eax rax

ANSSI Laboratoire Exploration et recherche en Détection 7/47

slide-11
SLIDE 11

VM instruction set

Most important invariant across samples

◮ Based on the same template ◮ Opcodes permutated ◮ Bytecode encryption varies

Who does what ?

ANSSI Laboratoire Exploration et recherche en Détection 8/47

slide-12
SLIDE 12

Bytecode extraction

◮ Locate dispatcher / handlers ◮ Symbolic execution ◮ Extract decryption formulas ◮ Recognize opcodes by their effect on the virtual stack

ANSSI Laboratoire Exploration et recherche en Détection 9/47

slide-13
SLIDE 13

Front-end x86 code encrypted bytecode

protected binary

decrypted bytecode VM semantics VM instruction set discovery

ANSSI Laboratoire Exploration et recherche en Détection 10/47

slide-14
SLIDE 14

Bytecode instruction set

Stack-oriented machine

◮ push X, pop Y, load, store

ANSSI Laboratoire Exploration et recherche en Détection 11/47

slide-15
SLIDE 15

Bytecode instruction set

Stack-oriented machine

◮ push X, pop Y, load, store ◮ ALU : add, nor, shifts, mul, div

ANSSI Laboratoire Exploration et recherche en Détection 11/47

slide-16
SLIDE 16

Bytecode instruction set

Stack-oriented machine

◮ push X, pop Y, load, store ◮ ALU : add, nor, shifts, mul, div ◮ Control flow : jmp

ANSSI Laboratoire Exploration et recherche en Détection 11/47

slide-17
SLIDE 17

Bytecode instruction set

Stack-oriented machine

◮ push X, pop Y, load, store ◮ ALU : add, nor, shifts, mul, div ◮ Control flow : jmp ◮ VM exits : fixed-arity call, exitvm

ANSSI Laboratoire Exploration et recherche en Détection 11/47

slide-18
SLIDE 18

Bytecode instruction set

Stack-oriented machine

◮ push X, pop Y, load, store ◮ ALU : add, nor, shifts, mul, div ◮ Control flow : jmp ◮ VM exits : fixed-arity call, exitvm ◮ misc : cpuid, rdtsc, FPU, checksum...

ANSSI Laboratoire Exploration et recherche en Détection 11/47

slide-19
SLIDE 19

Operators expansion

  • peration

translates into not a nor a a and a b nor (not a) (not b)

  • r a b

not (nor a b) sub a b not (add (not a) b) xor a b and (or a b) (or (not a) (not b)) flags (sub a b) add (and ~0x815 (flags (and (sub a b) (sub a b))) (and 0x815 (flags (add (not a) b)))

ANSSI Laboratoire Exploration et recherche en Détection 12/47

slide-20
SLIDE 20

From bytecode back to CISC

slide-21
SLIDE 21

Source

loop: dec eax test eax, eax jnz loop

ANSSI Laboratoire Exploration et recherche en Détection 14/47

slide-22
SLIDE 22

Bytecode

[+] 43bc7d : pop r4 [+] 43bc82 : pop r2 [+] 43bc87 : pop r8 [+] 43bc8c : pop r9 [+] 43bc91 : pop r6 [+] 43bc96 : pop r10 [+] 43bc9b : pop r3 [+] 43bca0 : pop r1 [+] 43bca5 : pop r14 [+] 43bcaa : pop r15 [+] 43bcaf : pop r5 [+] 43bcb4 : push 0x

✁ ✁ ✁ ✁

[+] 43bcbc : push r9 [+] 43bcc1 : add32 [+] 43bcc5 : pop r7 [+] 43bcca : pop r5 [+] 43bccf : push 0x43bc08 [+] 43bcd7 : push r5 [+] 43bcdc : push r5 [+] 43bce1 : nor32 [+] 43bce5 : pop r0 [+] 43bcea : push r5 [+] 43bcef : push r5 [+] 43bcf4 : nor32 [+] 43bcf8 : pop r9 [+] 43bcfd : nor32 [+] 43bd01 : pop r0 [+] 43bd06 : pop r7 [+] 43bd0b : push 0x44cba5 [+] 43bd13 : push vsp [+] 43bd17 : push 4:16 [+] 43bd1d : push r0 [+] 43bd22 : push 0x

✁ ✁ ✁bf

[+] 43bd2a : nor32 [+] 43bd2e : pop r9 [+] 43bd33 : shr32 [+] 43bd37 : pop r9 [+] 43bd3c : add32 [+] 43bd40 : pop r11 [+] 43bd45 : load32 [+] 43bd49 : pop r12 [+] 43bd4e : pop r11 [+] 43bd53 : pop r7 [+] 43bd58 : push r12 [+] 43bd5d : push r4 [+] 43bd62 : add32 [+] 43bd66 : pop r11 [+] 43bd6b : pop r15 [+] 43bd70 : push r5 [+] 43bd75 : push r10 [+] 43bd7a : push r0 [+] 43bd7f : push r14 [+] 43bd84 : push r10 [+] 43bd89 : push r8 [+] 43bd8e : push r5 [+] 43bd93 : push r3 [+] 43bd98 : push r1 [+] 43bd9d : push r2 [+] 43bda2 : push r4 [+] 43bda7 : push r15 [+] 43bdac : jmp

ANSSI Laboratoire Exploration et recherche en Détection 15/47

slide-23
SLIDE 23

Bytecode

[+] 43bc7d : pop r4 [+] 43bc82 : pop r2 [+] 43bc87 : pop r8 [+] 43bc8c : pop r9 [+] 43bc91 : pop r6 [+] 43bc96 : pop r10 [+] 43bc9b : pop r3 [+] 43bca0 : pop r1 [+] 43bca5 : pop r14 [+] 43bcaa : pop r15 [+] 43bcaf : pop r5 [+] 43bcb4 : push 0xffffffff [+] 43bcbc : push r9 [+] 43bcc1 : add32 [+] 43bcc5 : pop r7 [+] 43bcca : pop r5 [+] 43bccf : push 0x43bc08 [+] 43bcd7 : push r5 [+] 43bcdc : push r5 [+] 43bce1 : nor32 [+] 43bce5 : pop r0 [+] 43bcea : push r5 [+] 43bcef : push r5 [+] 43bcf4 : nor32 [+] 43bcf8 : pop r9 [+] 43bcfd : nor32 [+] 43bd01 : pop r0 [+] 43bd06 : pop r7 [+] 43bd0b : push 0x44cba5 [+] 43bd13 : push vsp [+] 43bd17 : push 4:16 [+] 43bd1d : push r0 [+] 43bd22 : push 0xffffffbf [+] 43bd2a : nor32 [+] 43bd2e : pop r9 [+] 43bd33 : shr32 [+] 43bd37 : pop r9 [+] 43bd3c : add32 [+] 43bd40 : pop r11 [+] 43bd45 : load32 [+] 43bd49 : pop r12 [+] 43bd4e : pop r11 [+] 43bd53 : pop r7 [+] 43bd58 : push r12 [+] 43bd5d : push r4 [+] 43bd62 : add32 [+] 43bd66 : pop r11 [+] 43bd6b : pop r15 [+] 43bd70 : push r5 [+] 43bd75 : push r10 [+] 43bd7a : push r0 [+] 43bd7f : push r14 [+] 43bd84 : push r10 [+] 43bd89 : push r8 [+] 43bd8e : push r5 [+] 43bd93 : push r3 [+] 43bd98 : push r1 [+] 43bd9d : push r2 [+] 43bda2 : push r4 [+] 43bda7 : push r15 [+] 43bdac : jmp

ANSSI Laboratoire Exploration et recherche en Détection 16/47

slide-24
SLIDE 24

Prologue

[+] 43bc7d : pop r4 [+] 43bc82 : pop r2 [+] 43bc87 : pop r8 [+] 43bc8c : pop r9 [+] 43bc91 : pop r6 [+] 43bc96 : pop r10 [+] 43bc9b : pop r3 [+] 43bca0 : pop r1 [+] 43bca5 : pop r14 [+] 43bcaa : pop r15 [+] 43bcaf : pop r5

ANSSI Laboratoire Exploration et recherche en Détection 17/47

slide-25
SLIDE 25

Epilogue

[+] 43bd70 : push r5 [+] 43bd75 : push r10 [+] 43bd7a : push r0 [+] 43bd7f : push r14 [+] 43bd84 : push r10 [+] 43bd89 : push r8 [+] 43bd8e : push r5 [+] 43bd93 : push r3 [+] 43bd98 : push r1 [+] 43bd9d : push r2 [+] 43bda2 : push r4 [+] 43bda7 : push r15 [+] 43bdac : jmp

ANSSI Laboratoire Exploration et recherche en Détection 18/47

slide-26
SLIDE 26

Virtual registers permutation

r0 r1 r2 r3 r4 eax ebx ecx eax r5 r0 r1 r2 r3 r4 r5 ecx ebx

ANSSI Laboratoire Exploration et recherche en Détection 19/47

slide-27
SLIDE 27

Body

[+] 43bcb4 : push 0xffffffff [+] 43bcbc : push r9 [+] 43bcc1 : add32 [+] 43bcc5 : pop r7 [+] 43bcca : pop r5 [+] 43bccf : ... [+] 43bcd7 : ... [+] 43bcdc : ... [+] 43bce1 : ...

ANSSI Laboratoire Exploration et recherche en Détection 20/47

slide-28
SLIDE 28

How do we simplify the body ?

slide-29
SLIDE 29

Mutable registers

✂✄ ♣
✂☎

...

✂✆ ♣ ✝ ✞✟ 0xffffffff ♣ ✝ ✞✟ ✂r ❛ ✠ ✠ ✡ ☎ ♣
✂☛ ♣
✂✆

...

ANSSI Laboratoire Exploration et recherche en Détection 22/47

slide-30
SLIDE 30

SSA form

☞ ✌ ☞ ✍✎ ☞ ✌ ☞ ✍✏

...

☞ ✌ ☞ ✍✑ ☞ ✒ ✓✔ 0xffffffff ☞ ✒ ✓✔ ✍✕ ✖ ✗ ✗ ✘ ✏ ☞ ✌ ☞ ✍✙ ☞ ✌ ☞ ✍✑

... .1 .1 .1 .1 .1

✳ ✏

ANSSI Laboratoire Exploration et recherche en Détection 23/47

slide-31
SLIDE 31

Explicit operands IR

✚ ✛ ✛ ✜ ✢ ✣ ✤ ✣ ✥ ✣ ✤ ✣ ✦ ❘ ✧ ★ ❂ ✚ ✛ ✛ ✦ ✧ ✥ ✣ ✩✪ ✫ R ✣ ✩✪ ✫ ★

ANSSI Laboratoire Exploration et recherche en Détection 24/47

slide-32
SLIDE 32

Mostly stackless

✬✭ ✮ ✯ ✱ ✬ ✰ ✮ ✶ ✲ ✬ ✴.1 + 0xffffffff ✵✷✸✹ 0x43bc08 ✬✺ ✮ ✶ ✲ ✻ ✼✽ ✸ ✾✿❀✬ ✬✭ ✮ ✯ ✬✭ ✮ ✯ ❁ ✬ ✴ ✮ ✯ ✲ ✻ ✼✽ ✸ ✾✿❀✬ ✬✭ ✮ ✯ ✬✭ ✮ ✯ ❁ ✬ ✰ ✮ ✯ ✱ ✬✺ ✮ ✯ ✲ ✿❀ ✬ ✾✿❀ ✬ ✬✭ ✮ ✯ ✬✭ ✮ ✯ ❁ ✾✿ ❀ ✬ ✬✭ ✮ ✯ ✬✭ ✮ ✯ ❁ ✵✷✸✹ 0x44c❜ ✼ ✭ ✬ ✴ ✮ ❃ ✲ ✻ ✼✽ ✸ ... ✬ ✴ ✮ ❄ ✲ ✻ ✼✽ ✸ ... ✬ ✶ ✶ ✮ ✶ ✲ ✻a ✽ ✸ ✮ ✮ ✮ ✬ ✶ ✯ ✮ ✶ ✲ ❅ ❀✼ ❆ ❃ ✯ ✾ ✈ ✸✵ ❇ ✾ ✸✹ ✬ ✾✿❀ ✬ ✺ ♦ ❈❈❈❜❉ ✬✺ ✮ ✯ ❁ ❄ ❁❁ ✵ ❀ ✵ ✬ ✶ ✶ ✮ ✯ ✵ ❀ ✵ ✬ ✰ ✮3 ✬ ✶ ✶ ✮ ✶ ✲ ✻a ✽ ✸ ✮ ✮ ✮ ✬ ✶ ✭ ✮ ✯ ✲ ✬ ❄ ✮ ✶ ❇ ✬ ✶ ✯ ✮ ✶

...

❊❋ ✵ ✬ ✶ ✭ ✮ ✯

ANSSI Laboratoire Exploration et recherche en Détection 25/47

slide-33
SLIDE 33

Mostly stackless

■ ❏ ❑
■ ▼ ◆
  • ❖.1 + 0xffffffff
P◗❙❚ 0x43bc08
■ ▼ ◆ ❱ ❲❳ ❙ ❨❩❬●
  • ❍ ■ ❏
  • ❍ ■ ❏
■ ❏ ◆ ❱ ❲❳ ❙ ❨❩❬●
  • ❍ ■ ❏
  • ❍ ■ ❏
■ ❏ ❑
■ ❏ ◆ ❩❬
  • ❨❩❬
  • ❍ ■ ❏
  • ❍ ■ ❏
❭ ❨❩ ❬
  • ❍ ■ ❏
  • ❍ ■ ❏
❭ P◗❙❚ 0x44c❪ ❲ ❍
■ ❫ ◆ ❱ ❲❳ ❙ ...
■ ❴ ◆ ❱ ❲❳ ❙ ...
▼ ■ ▼ ◆ ❱a ❳ ❙ ■ ■ ■
❏ ■ ▼ ◆ ❵ ❬❲ ❝ ❫ ❏ ❨ ❞ ❙P ❡ ❨ ❙❚
  • ❨❩❬
❢ ❣❣❣❪❤
■ ❏ ❭ ❴ ❭❭ P ❬ P
▼ ■ ❏ P ❬ P
■3
▼ ■ ▼ ◆ ❱a ❳ ❙ ■ ■ ■
❍ ■ ❏ ◆
■ ▼ ❡
❏ ■ ▼

...

✐❥ P
❍ ■ ❏

ANSSI Laboratoire Exploration et recherche en Détection 26/47

slide-34
SLIDE 34

Liveness

❦❧ ♠ ♥ q ❦ s ♠ t ✉ ❦ ✇.1 + 0xffffffff ①②③④ 0x43bc08 ❦⑤ ♠ t ✉ ⑥ ⑦ ⑧ ③ ⑨ ⑩❶❦ ❦❧ ♠ ♥ ❦❧ ♠ ♥ ❷ ❦ ✇ ♠ ♥ ✉ ⑥ ⑦ ⑧ ③ ⑨ ⑩❶❦ ❦❧ ♠ ♥ ❦❧ ♠ ♥ ❷ ❦ s ♠ ♥ q ❦⑤ ♠ ♥ ✉ ⑩❶❦ ⑨ ⑩❶❦ ❦❧ ♠ ♥ ❦❧ ♠ ♥ ❷ ⑨ ⑩❶❦ ❦❧ ♠ ♥ ❦❧ ♠ ♥ ❷ ①②③④ 0x44c ❸ ⑦ ❧ ❦ ✇ ♠ ❹ ✉ ⑥ ⑦ ⑧ ③ ... ❦ ✇ ♠ ❺ ✉ ⑥ ⑦ ⑧ ③ ... ❦ t t ♠ t ✉ ⑥a ⑧ ③ ♠ ♠ ♠ ❦ t ♥ ♠ t ✉ ❻ ❶⑦ ❼ ❹ ♥ ⑨ ❽ ③ ① ❾ ⑨ ③④ ❦ ⑨ ⑩ ❶❦ ⑤ ❿ ➀➀➀❸ ➁ ❦⑤ ♠ ♥ ❷ ❺ ❷❷ ① ❶ ① ❦ t t ♠ ♥ ① ❶ ① ❦ s ♠3 ❦ t t ♠ t ✉ ⑥a ⑧ ③ ♠ ♠ ♠ ❦ t ❧ ♠ ♥ ✉ ❦ ❺ ♠ t ❾ ❦t ♥ ♠ t

...

➂➃ ① ❦ t ❧ ♠ ♥

ANSSI Laboratoire Exploration et recherche en Détection 27/47

slide-35
SLIDE 35

Dead Store Elimination

➄➅ ➆ ➇ ➈ ➉ ➊ ➄ ➋ ➆ ➌ ➍ ➎xffffffff ➏ ➐ ➑➒ 0x43bc08 ➄➎ ➆ ➇ ➊ ➓➔ → ➑ ➣↔ ↕ ➄ ➣↔ ↕ ➄ ➄ ➅ ➆ ➇ ➄ ➅ ➆ ➇ ➙ ➣↔ ↕ ➄ ➄ ➅ ➆ ➇ ➄➅ ➆ ➇ ➙➙ ➏ ➐ ➑➒ 0x44c ➛ ➔ ➅ ➄➌ ➇ ➆ ➌ ➊ ➜ ↕ ➔ ➝ ➞ ➇ ➣ ➟ ➑➏ ➍ ➣ ➑➒ ➄ ➣↔ ↕ ➄ ➎ ➠ ➡➡➡ ➛ ➢ ➄ ➎ ➆ ➇ ➙ ➤ ➙➙ ➏ ↕ ➏ ➉ ➏ ↕ ➏ ➉ ➄➌ ➅ ➆ ➇ ➊ ➄ ➤ ➆ ➌ ➍ ➄ ➌ ➇ ➆ ➌

...

➥ ➦ ➏ ➄ ➌ ➅ ➆ ➇

ANSSI Laboratoire Exploration et recherche en Détection 28/47

slide-36
SLIDE 36

How to restore original operators ?

➧➨ ➩ ➫ ➭ ➯ ➲ ➧ ➳ ➩ ➵ ➸ ➺xffffffff ➻ ➼ ➽➾ 0x43bc08 ➧➺ ➩ ➫ ➲ ➚➪ ➶ ➽ ➹➘ ➴ ➧ ➹➘ ➴ ➧ ➧ ➨ ➩ ➫ ➧ ➨ ➩ ➫ ➷ ➹➘ ➴ ➧ ➧ ➨ ➩ ➫ ➧➨ ➩ ➫ ➷➷ ➻ ➼ ➽➾ 0x44c ➬ ➪ ➨ ➧➵ ➫ ➩ ➵ ➲ ➮ ➴ ➪ ➱ ✃ ➫ ➹ ❐ ➽➻ ➸ ➹ ➽➾ ➧ ➹➘ ➴ ➧ ➺ ❒ ❮❮❮ ➬ ❰ ➧ ➺ ➩ ➫ ➷ Ï ➷➷ ➻ ➴ ➻ ➯ ➻ ➴ ➻ ➯ ➧➵ ➨ ➩ ➫ ➲ ➧ Ï ➩ ➵ ➸ ➧ ➵ ➫ ➩ ➵

...

Ð Ñ ➻ ➧ ➵ ➨ ➩ ➫

ANSSI Laboratoire Exploration et recherche en Détection 29/47

slide-37
SLIDE 37

Algebraic transform

ÒÓ Ô Õ Ö × Ø Ò Ù Ô Ú Û Üxffffffff Ý Þ ßà 0x43bc08 ÒÜ Ô Õ Ø áâ ã ß äâ å æ ÒÓ Ô Õ ÒÓ Ô Õ ç Ý Þ ßà 0x44cè â Ó ÒÚ Õ Ô Ú Ø é ê â æ ë Õ äì ß Ý Û äß à Ò äâ å æ Ü í î Ü ä å ê ï ÒÜ Ô Õ çç î çç Ý ê Ý × Ý ê Ý × ÒÚ Ó Ô Õ Ø Òî Ô Ú Û ÒÚ Õ Ô Ú

...

ð ñ Ý ÒÚ Ó Ô Õ

ANSSI Laboratoire Exploration et recherche en Détection 30/47

slide-38
SLIDE 38

Recognize conditional load from stack

òó ô õ ö ÷ ø òù ô ú û üxffffffff ý þ ÿ✥ 0x43bc08 òü ô õ ø ✂❛ ÿ ✁❛ ✄ ☎ òó ô õ ò ó ô õ r ý þ ÿ✥ 0x44c ❜ ❛ ó òú õ ô ú ø ✶ ✆ ❛ ☎ ✝ õ ✁✈ ÿý û ✁ÿ✥ ò ✁❛ ✄ ☎ ü ♥ ✞ ü ✁✄ ✆ ✟ ò ü ô õ rr ✞ rr ý ✆ ý ÷ ý ✆ ý ÷ òú ó ô õ ø ò ✞ ô ú û òú õ ô ú

...

✠ ✡ ý òú ó ô õ

ANSSI Laboratoire Exploration et recherche en Détection 31/47

slide-39
SLIDE 39

Introduce "if"

☛☞ ✌ ✍ ✱ ✎ ✏ ☛ ✾ ✌ ✑ ✒ ✓xffffffff ✔ ✕ ✖✗ 0x43bc08 ☛✓ ✌ ✍ ✏ ✘✙ ✚ ✖ ✛✙ ✜ ✢ ☛ ☞ ✌ ✍ ☛☞ ✌ ✍ ✣ ✔ ✕ ✖✗ 0x44c ✤ ✙ ☞ ☛✑ ✍ ✌ ✑ ✏ ✦ ✧ ✛✤ ✦ ★ ✩ ✪ ☛ ✓ ✌ ✍ ✣ 0x44c ✤ ✙ ☞ ✫ ✬ ✖ ✫ ✓ ✭ ✮3bc08 ✔ ✯ ✔ ✎ ✔ ✯ ✔ ✎ ☛✑ ☞ ✌ ✍ ✏ ☛✮ ✌ ✑ ✒ ☛✑ ✍ ✌ ✑

...

✰ ✲ ✔ ☛✑ ☞ ✌ ✍

ANSSI Laboratoire Exploration et recherche en Détection 32/47

slide-40
SLIDE 40

Branch destination

✳ ✴ ✳ ✵✷ ✸1

...

✵ ✹ ✸ ✺ ✻ ✼ ✽ ✵ ✿ ✸ ❀ ❁ ❂xffffffff

...

✳ ❃ ❄ ❅ ✵✷ ✸ ❀ ❆ ❇ ✳ ✵✷.1 + if (bit #6 flags (and r5.2 r5.2)) 0x44cba5

else 0x43bc08

ANSSI Laboratoire Exploration et recherche en Détection 33/47

slide-41
SLIDE 41

CISC

❈ ❉ ❈ ❊eloc

... r5.2 = dec r9.1 ...

❈ ❋
  • ❍ reloc
■ ❏ ❈ ❊ ❡ ❑ ❉ ▲ ▼ ◆ ❖ P◗ P❘nd r5.2 r5.2)) 0x44cba5

else 0x43bc08 eax before eax after test eax eax

■ P❥ ❙◗

ANSSI Laboratoire Exploration et recherche en Détection 34/47

slide-42
SLIDE 42

How do we undo the virtual registers permutation ?

slide-43
SLIDE 43

Global SSA variables

♣ ❚ ❯❱ ❲ ❳ ❨ ❩ ❬ ❭ ❳

...

❪ ❫ ♣ ♣ ❚ ❯❱ ❲ ❴ ❨ ❪ ❬ ❭ ❵

...

❪ ❫ ♣ ♣ ❝ ♣ ❲❞ ❨ ❳ ❬ ❭ ❢

...

❚ ❯✉ ❲8.1

ANSSI Laboratoire Exploration et recherche en Détection 36/47

slide-44
SLIDE 44

Data-flow analysis on stack state

❣ ❤ ✐❦ ❧ ♠

...

♦ q ❣ ❣ ❤ ✐❦ ❧ s

...

♦ q ❣ ❣ t ❣ ❧ ✇

...

❤ ✐① ❧ ✇ ❧ ♠ ② ② ❧ s

ANSSI Laboratoire Exploration et recherche en Détection 37/47

slide-45
SLIDE 45

Simple case : v1 == v2

③ ④ ⑤⑥ ⑦ ⑧

...

⑨ ⑩ ③ ③ ④ ⑤⑥ ⑦ ⑧

...

⑨ ⑩ ③ ③ ❶ ③ ❷

...

④ ⑤❸ ⑦ ⑧ ⑦ ⑧

ANSSI Laboratoire Exploration et recherche en Détection 38/47

slide-46
SLIDE 46

Cancel pair

❹ ❺ ❻❼ ❽ ❾

...

❿ ➀ ❹ ❹ ❺ ❻❼ ❽ ❾

...

❿ ➀ ❹ ❹ ➁ ❹ ➂

...

❺ ❻➃ ❽ ❾ ❽ ❾

ANSSI Laboratoire Exploration et recherche en Détection 39/47

slide-47
SLIDE 47

General case

➄ ➅ ➆➇ ➈ ➉

...

➊ ➋ ➄ ➄ ➅ ➆➇ ➈ ➌

...

➊ ➋ ➄ ➄ ➍ ➄ ➈ ➎

...

➅ ➆➏ ➈ ➎ ➈ ➉ ➐ ➐ ➈ ➌

ANSSI Laboratoire Exploration et recherche en Détection 40/47

slide-48
SLIDE 48

Introduce phi function

➑ ➒ ➓➔ → ➣

...

↔ ↕ ➑ ➑ ➒ ➓➔ → ➙

...

↔ ↕ ➑ ➑ ➛ ➑ ➜ → ➝ ➞ ➟ ➠→ ➣ ➡ → ➙ ➢ ➒ ➓➤ → ➝ → ➣ ➥ ➥ → ➙

ANSSI Laboratoire Exploration et recherche en Détection 41/47

slide-49
SLIDE 49

Cancel pair

➦ ➧ ➨➩ ➫ ➭

...

➯ ➲ ➦ ➦ ➧ ➨➩ ➫ ➳

...

➯ ➲ ➦ ➦ ➵ ➦ ➸ ➫ ➺ ➻ ➼ ➽➫ ➭ ➾ ➫ ➳ ➚ ➧ ➨➪ ➫ ➺ ➫ ➭ ➶ ➶ ➫ ➳

ANSSI Laboratoire Exploration et recherche en Détection 42/47

slide-50
SLIDE 50

Getting rid of phi functions

◮ Global liveness analysis ◮ Global dead store elimination ◮ Most phi functions disappear ◮ Why ?

ANSSI Laboratoire Exploration et recherche en Détection 43/47

slide-51
SLIDE 51

Entry stacks from two predecessors

➹ ➘ ➴

esi eax ...

➹ ➘ ➴

esi eax ... reloc reloc

➷ ➹ ➬ ➴

constant

ANSSI Laboratoire Exploration et recherche en Détection 44/47

slide-52
SLIDE 52

Recovering native registers ?

◮ Yes, partially ◮ Use VM entries and exits ◮ Register allocation still necessary

ANSSI Laboratoire Exploration et recherche en Détection 45/47

slide-53
SLIDE 53

Recovering call graph ?

◮ Yes, with heuristics ◮ Recognize call/ret patterns ◮ Recognize functions

ANSSI Laboratoire Exploration et recherche en Détection 46/47

slide-54
SLIDE 54

That’s all folks !

"la comparaison entre l’assembleur et le bytecode est parlante même si on ne comprend pas l’assembleur" –SSTIC relecteur 4 ANSSI Laboratoire Exploration et recherche en Détection 47/47