D eprotection semi-automatique de binaire avec Metasm : celui qui - - PowerPoint PPT Presentation

d eprotection semi automatique de binaire
SMART_READER_LITE
LIVE PREVIEW

D eprotection semi-automatique de binaire avec Metasm : celui qui - - PowerPoint PPT Presentation

Metasm Manipulation structurelle Challenge T2 2007 Conclusion D eprotection semi-automatique de binaire avec Metasm : celui qui fond dans la bouche et pas dans la main. Alexandre Gazet Yoann Guillot A. Gazet & Y. Guillot D


slide-1
SLIDE 1

Metasm Manipulation structurelle Challenge T2 2007 Conclusion

D´ eprotection semi-automatique de binaire

avec Metasm : celui qui fond dans la bouche et pas dans la main. Alexandre Gazet Yoann Guillot

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 1/49

slide-2
SLIDE 2

Metasm Manipulation structurelle Challenge T2 2007 Conclusion

Plan

1

Metasm

2

Manipulation structurelle

3

Challenge T2 2007

4

Conclusion

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 2/49

slide-3
SLIDE 3

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Plan

1

Metasm Les d´ esassembleurs classiques Binding Backtracing

2

Manipulation structurelle

3

Challenge T2 2007

4

Conclusion

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 3/49

slide-4
SLIDE 4

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Metasm

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 4/49

slide-5
SLIDE 5

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Metasm

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 5/49

slide-6
SLIDE 6

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

D´ esassemblage

La r´ ef´ erence : IDA Pro Excellent sur du code clair : binaire MS Inadapt´ e sur un binaire prot´ eg´ e

Pas d’interpr´ etation du code Des hypoth` eses trop contraignantes

Des hypoth` eses Les deux branches d’un saut conditionnel sont ex´ ecut´ ees Deux instructions ne se superposent pas Un appel retourne

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 6/49

slide-7
SLIDE 7

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

D´ esassemblage

La r´ ef´ erence : IDA Pro Excellent sur du code clair : binaire MS Inadapt´ e sur un binaire prot´ eg´ e

Pas d’interpr´ etation du code Des hypoth` eses trop contraignantes

Des hypoth` eses Les deux branches d’un saut conditionnel sont ex´ ecut´ ees Deux instructions ne se superposent pas Un appel retourne

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 6/49

slide-8
SLIDE 8

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Hypoth` ese : un appel retourne

. t e x t :00403 E9F loc 403E9F : ; CODE XREF: .text : loc_40CDEF . t e x t :00403 E9F push ebp . t e x t :00403 EA0 push ecx . t e x t :00403 EA1 push ebp . t e x t :00403 EA2 c a l l sub 40BECD . t e x t :00403 EA7

  • utsb

. t e x t :00403 EA8 cmp edx , esp . t e x t :00403EAA push esp . t e x t :00403EAB i n c e s i

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 7/49

slide-9
SLIDE 9

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Mise en ´ echec

. t e x t :0040BECD sub 40BECD proc near ; CODE XREF: .text :00403EA2 . t e x t :0040BECD cmp eax , ebp . t e x t :0040BECF add dword ptr [ esp +0] , 1 . t e x t :0040BED4 te s t ebx , 1E2h . t e x t :0040BEDA retn 0Ch . t e x t :0040BEDA sub 40BECD endp

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 8/49

slide-10
SLIDE 10

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Binding

D´ efinition Expression symbolique des effets d’une instruction; ` a chaque instruction est associ´ ee sa s´ emantique. Instruction ADD :

a = d i . i n s t r u c t i o n . args . map r e s = Expression [ [ a [ 0 ] , :& , mask ] , :+ , [ a [ 1 ] , :& , mask ] ] binding [ : e f l a g z ] = Expression [ [ res , :& , mask ] , :==, 0] binding [ : e f l a g s ] = s i g n [ r e s ] binding [ : e f l a g c ] = Expression [ res , :>, mask ] binding [ : e f l a g o ] = Expression [ [ s i g n [ a [ 0 ] ] , :==, s i g n [ a [ 1 ] ] ] , : ’&&’ , [ s i g n [ a [ 0 ] ] , : ’!=’ , s i g n [ r e s ] ] ] binding [ i n s t r ] ={ a [ 0 ] = > r e s }

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 9/49

slide-11
SLIDE 11

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Binding

Instruction CALL :

addrReturn = Expression [ Expression [ d i . address , :+ , d i . b i n l e n g th ] . reduce ] } binding = { : esp = > Expression [ : esp , :−,

  • psz ] ,

I n d i r e c t i o n [ : esp ,

  • psz ,

d i . address ] = > addrReturn }

En pratique :

dword ptr [ esp ] = 0x4010CE esp = esp−4

Instruction RDTSC :

binding = { : eax = > Expression : : Unknown , : edx = > Expression : : Unknown }

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 10/49

slide-12
SLIDE 12

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Binding

Instruction CALL :

addrReturn = Expression [ Expression [ d i . address , :+ , d i . b i n l e n g th ] . reduce ] } binding = { : esp = > Expression [ : esp , :−,

  • psz ] ,

I n d i r e c t i o n [ : esp ,

  • psz ,

d i . address ] = > addrReturn }

En pratique :

dword ptr [ esp ] = 0x4010CE esp = esp−4

Instruction RDTSC :

binding = { : eax = > Expression : : Unknown , : edx = > Expression : : Unknown }

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 10/49

slide-13
SLIDE 13

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Binding

Instruction CALL :

addrReturn = Expression [ Expression [ d i . address , :+ , d i . b i n l e n g th ] . reduce ] } binding = { : esp = > Expression [ : esp , :−,

  • psz ] ,

I n d i r e c t i o n [ : esp ,

  • psz ,

d i . address ] = > addrReturn }

En pratique :

dword ptr [ esp ] = 0x4010CE esp = esp−4

Instruction RDTSC :

binding = { : eax = > Expression : : Unknown , : edx = > Expression : : Unknown }

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 10/49

slide-14
SLIDE 14

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Backtracing, la th´ eorie

D´ efinition ´ Emulation symbolique par remont´ ee du flot d’instructions.

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 11/49

slide-15
SLIDE 15

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Backtracing, la pratique

Flot d’ex´ ecution :

c a l l loc 40becdh ; @403ea2h e826800000 cmp eax , ebp ; @40becdh 39e8 add dword ptr [ esp +0] , 1 ; @40becfh 8344240001 te s t ebx , 1e2h ; @40bed4h f7c3e2010000 r e t 0ch ; @40bedah c20c00

Backtracing x dword ptr [esp] for 40bedah ret 0ch

1

backtrace 40becfh add dword ptr [esp+0], 1 dword ptr [esp] => dword ptr [esp]+1

2

backtrace up 40becdh->403ea2h dword ptr [esp]+1

3

backtrace 403ea2h call loc 40becdh dword ptr [esp]+1 ⇒ 403ea8h

4

backtrace result : 403ea8h

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 12/49

slide-16
SLIDE 16

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Les d´ esassembleurs classiques Binding Backtracing

Metasm

Listing produit :

loc 403e9fh : push ebp ; @403e9fh 55 push ecx ; @403ea0h 51 push ebp ; @403ea1h 55 c a l l loc 40becdh ; @403ea2h e826800000 noreturn db 6eh ; @403ea7h // Xrefs : 40 bedah loc 403ea8h : cmp edx , esp ; @403ea8h 39e2 push esp ; @403eaah 54 [ . . . ] − − − − − − − − − − − − − − − − − − − − − − − − // Xrefs : 403 ea2h loc 40becdh : cmp eax , ebp ; @40becdh 39e8 add dword ptr [ esp +0] , 1 ; @40becfh 8344240001 te s t ebx , 1e2h ; @40bed4h f7c3e2010000 r e t 0ch ; @40bedah c20c00 x: loc_403ea8h

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 13/49

slide-17
SLIDE 17

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Plan

1

Metasm

2

Manipulation structurelle Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

3

Challenge T2 2007

4

Conclusion

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 14/49

slide-18
SLIDE 18

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Securitech 2006 - Challenge 10

Poeut.exe Binaire massivement obfusqu´ e IDA d´ epass´ e Metasm d´ esassemble parfaitement mais :

Reordonnancement des blocs d’instructions ⇒ n´ ecessit´ e de d´ evelopper un front-end graphique

yEd - Graph Editor Visualisation de graphes Utilise un fichier graphml Objets internes de Metasm les InstructionBlock

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 15/49

slide-19
SLIDE 19

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Graphe sauvage

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 16/49

slide-20
SLIDE 20

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Pr´ edicats biais´ es

Pr´ edicats obscurs La fonction pr´ edicat renvoie toujours vrai ou toujours faux Pr´ edicats r´ esistants ` a une analyse manuelle/statique Une des deux branches n’est jamais ex´ ecut´ ee

i f ( xˆ4

* ( x −5)ˆ2 >= 0){

goto r e a l co d e ; } e l s e { goto no where ; } f s t p qword ptr [ esp +8] f s t p qword ptr [ esp ] c a l l thunk pow f s t p qword ptr [ ebp−0x20 ] mov eax , dword ptr [ ebp−0ch ] sub eax , 5 push eax f i l d dword ptr [ esp ] l e a esp , dword ptr [ esp +4] f l d qword ptr [ xref 8048590h ] f s t p qword ptr [ esp +8] f s t p qword ptr [ esp ] c a l l thunk pow f l d qword ptr [ ebp−20h ] fmulp ST(1)

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 17/49

slide-21
SLIDE 21

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Pr´ edicats biais´ es

Al´ ea total La fonction pr´ edicat renvoie indiff´ eremment vrai ou toujours faux Les s´ emantiques des deux branches sont ´ equivalentes

i f ( rand ( ) %2 ) { real code A ; } e l s e { real code B ; }

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 18/49

slide-22
SLIDE 22

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Duplication de flot

Insertion massive d’al´ ea total : Constructions en diamant.

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 19/49

slide-23
SLIDE 23

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

´ El´ ements neutres

D´ efinition Instruction ou groupe d’instructions ayant une s´ emantique nulle : aucun impact r´ eel sur le contexte d’ex´ ecution.

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 20/49

slide-24
SLIDE 24

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

´ El´ ements neutres : al´ ea apparent

Impl´ ementation :

te s t esp , ebx ; @402039h 85e3 cmp ebx , edx ; @40203bh 39d3 mov byte ptr [ edx ] , a l ; @40203dh 8802 add dword ptr [ esp +0] , 6 ; @40203fh 8344240006 i n c edx ; @402044h 42 jmp loc 40b25dh ; @402045h e913920000

R´ eponse au probl` eme Utilisation du binding des instructions Incoh´ erences du data flow au niveau des flags :

Deux ´ ecritures successives ´ Ecriture mais pas de lecture

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 21/49

slide-25
SLIDE 25

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

´ El´ ements neutres : faux appels

Impl´ ementation :

push eax ; @408dadh 50 push ecx ; @408daeh 51 push ebp ; @408dafh 55 [ . . . ] c a l l loc 4037f2h ; @40932fh [ . . . ] push esp ; @4037f4h 54 push ecx ; @4037f5h 51 [ . . . ] add dword ptr [ esp +8] , 9 ; @4037f9h 8344240809 add esp , 8 ; @403800h 83 c408 [ . . . ] r e t 0ch ; @403808h c20c00 x: loc_40933dh

R´ eponse au probl` eme Cr´ eation du flot d’ex´ ecution Simulation d’une pile Pattern particulier : modifie l’adresse de retour

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 22/49

slide-26
SLIDE 26

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

´ Epilogue brut

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 23/49

slide-27
SLIDE 27

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Analyse des flots d’ex´ ecution

R´ eponse au probl` eme

1

Parcours de l’arbre d’objets internes InstructionBlock

2

Inline de fonction si n´ ecessaire

3

Recherche de constructions en diamant

4

Cr´ eation, nettoyage puis comparaison des flots

5

Factorisation si n´ ecessaire

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 24/49

slide-28
SLIDE 28

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

´ Epilogue avec flots factoris´ es

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 25/49

slide-29
SLIDE 29

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

´ Epilogue r´ eordonn´ e

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 26/49

slide-30
SLIDE 30

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Vue finale

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 27/49

slide-31
SLIDE 31

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Pr´ esentation Complexification du graphe de contrˆ

  • le

Insertion d’´ el´ ements neutres D´ eprotection

Touche finale

Nettoyage de tout le graphe du binaire Production d’un listing assembleur propre Utilisation du compilateur compris dans Metasm pour produire un binaire d´ epourvu de la protection

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 28/49

slide-32
SLIDE 32

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Plan

1

Metasm

2

Manipulation structurelle

3

Challenge T2 2007 Introduction Obfuscation Machine virtuelle R´ esolution

4

Conclusion

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 29/49

slide-33
SLIDE 33

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

T2 2007

t207.exe http://www.t2.fi/challenge/ But : trouver un mot de passe pour deverouiller le programme Binaire tr` es simple [demo/1] Charge un driver obfusqu´ e [demo/2]

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 30/49

slide-34
SLIDE 34

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

D´ esobfuscation

Les types d’obfuscation Junk code Op´ erations obfusqu´ ees Anti ring3 Duplication de code

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 31/49

slide-35
SLIDE 35

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Junk code

junk r o r edi , 0dh xchg ebx , edi r o r ebx , 13h xchg ebx , edi

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 32/49

slide-36
SLIDE 36

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Op´ erations obfusqu´ ees

rotation de bits push eax push ecx r o l dword ptr [ esp +4] , c l pop ecx pop eax

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 33/49

slide-37
SLIDE 37

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Anti ring3

test ring0 pushfd push eax xor eax , eax mov ax , cs cmp eax , 9 j l e loc 131d5h r d t s c imul eax , ecx jmp eax ; x : unknown loc 131d5h : pop eax popfd

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 34/49

slide-38
SLIDE 38

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Duplication de code

duplication push e s i push ebx pushfd r d t s c imul ecx , ebx cmp cl , 7 fh jnb loc 21aba popfd pop ebx pop e s i loc 21abah : popfd pop ebx pop e s i

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 35/49

slide-39
SLIDE 39

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Machine virtuelle

Structure de handler Des op´ erations simples Des constructions similaires Op´ erations param´ etr´ ees par [ebp] [demo/3]

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 36/49

slide-40
SLIDE 40

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Addition virtuelle

Handler d’addition loc 15336 : mov ecx , dword ptr [ ebp+0ch ] xor ecx , 842 b1208h mov ecx , dword ptr [ ebx+ecx ] mov eax , dword ptr [ ebp+8] xor eax , 842 b1208h add dword ptr [ ebx+eax ] , ecx

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 37/49

slide-41
SLIDE 41

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Transition entre handlers

transition au handler suivant mov ecx , dword ptr [ ebp+0] xor ecx , 149 f0c63h mov ebp , dword ptr [ ebp+4] xor ebp , 842 b1208h add ebp , dword ptr [ ebx+14h ] add ecx , dword ptr [ ebx+14h ] jmp ecx ; x : unknown

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 38/49

slide-42
SLIDE 42

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Architecture virtuelle

next_handler next_instr arg0 key_1 key_2

handler

next_handler next_instr arg0 key_1 key_2

handler

arg1

ciphered instruction ciphered instruction

mov eax, [ebp+8] xor eax, h1_key_2 mov [ebx+eax], 0 mov eax, [ebp] xor eax, h1_key_1 mov ebp, [ebp+4] xor ebp, h1_key_2 add eax, [ebx+14h] add ebp, [ebx+14h] jmp eax mov eax, [ebp+8] xor eax, h2_key_2 mov ecx, [ebp+12] xor ecx, h2_key_2 mov ecx, [ebx+ecx] add [ebx+eax], ecx

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 39/49

slide-43
SLIDE 43

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

´ Enum´ eration des handlers

´ Enum´ eration directe impossible N´ ecessite de suivre le flot virtuel pas ` a pas La taille du binaire indique la pr´ esence de nombreux handlers Analyse comportementale de chaque handler par backtrack [demo/4]

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 40/49

slide-44
SLIDE 44

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

R´ esultat de l’analyse

Binding du handler handler 13491h : // ” reg0 ” <− Expressio n [” reg0 ” , :+ , ” reg1 ”] // handler type : add reg , reg mov eax , dword ptr [ ebp+0ch ] xor eax , 8 d3f5d8bh mov eax , dword ptr [ ebx+eax ] mov ecx , dword ptr [ ebp+8] xor ecx , 8 d3f5d8bh add dword ptr [ ebx+ecx ] , eax

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 41/49

slide-45
SLIDE 45

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Code virtuel basique

Les premi` eres instructions virtuelles entrypo int 2 1 9 feh 2 1 ea6 h : nop mov r68 , 28h add r68 , ho st esp mov r64 , dword ptr [ r68 ] mov dword ptr [ esp ] , r64 mov r64 , 4 add esp , r64 mov r68 , 2ch add r68 , ho st esp mov r64 , dword ptr [ r68 ] mov dword ptr [ esp ] , r64 mov r64 , 4 add esp , r64 trap

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 42/49

slide-46
SLIDE 46

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Macro-instructions virtuelles

Niveau d’abstraction sup´ erieur Reconnaissance de patterns caract´ eristiques Reconstruction d’un assembleur plus haut niveau Apparition des fonctions (call, ret)

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 43/49

slide-47
SLIDE 47

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Macro-code virtuel

Les premi` eres instructions virtuelles entrypo int 2 1 9 feh 2 1 ea6 h : mov dword ptr [ esp ] , dword ptr [ ho st esp +28h ] add esp , 4 mov dword ptr [ esp ] , dword ptr [ ho st esp+2ch ] add esp , 4 mov ebp , esp add esp , 234h mov r64 , dword ptr [ ebp+200h ] xor r64 , 1 j r z loc 2d630h 2d8ffh , r64 s y s c a l l a l l o c p t r r64 , 0ch mov dword ptr [ ebp+200h ] , r64 lo c 2 d6 3 0 h 2 d8 ffh :

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 44/49

slide-48
SLIDE 48

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

D´ ecompilation

La s´ emantique des instructions est tr` es simple La forme du code fait penser ` a du C V´ erifions

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 45/49

slide-49
SLIDE 49

Metasm Manipulation structurelle Challenge T2 2007 Conclusion Introduction Obfuscation Machine virtuelle R´ esolution

Validation

R´ esolution purement statique

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 46/49

slide-50
SLIDE 50

Metasm Manipulation structurelle Challenge T2 2007 Conclusion

Plan

1

Metasm

2

Manipulation structurelle

3

Challenge T2 2007

4

Conclusion

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 47/49

slide-51
SLIDE 51

Metasm Manipulation structurelle Challenge T2 2007 Conclusion

Conclusions g´ en´ erale

Poeut : application inverses de transformations Suppression d’´ el´ ements neutres ajout´ es. Factorisation de flots dupliqu´ es, R´ eduction du graphe de contrˆ

  • le,

Niveau d’abstraction constant. T2 : remont´ ee des niveaux d’abstraction Quelques millions d’instructions dans un driver, une machine virtuelle, 112 handlers, 800 lignes de macro-assembleur, 300 lignes de C, Extraction progressive de la s´ emantique.

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 48/49

slide-52
SLIDE 52

Metasm Manipulation structurelle Challenge T2 2007 Conclusion

Remerciements L’infˆ ame Serpillierre, Le(s) concepteur(s) du T2. http://esec.fr.sogeti.com/blog Vos questions ?

  • A. Gazet & Y. Guillot

D´ eprotection semi-automatique de binaire 49/49