Binary deprotection with metasm
and stuff
Alexandre Gazet
Sogeti / ESEC R&D alexandre.gazet(at)sogeti.com
Yoann Guillot
Sogeti / ESEC R&D yoann.guillot(at)sogeti.com
HITB 2009 Metasm Debugger Analysis of a protection Compiler - - PowerPoint PPT Presentation
Binary deprotection with metasm and stuff Alexandre Gazet Yoann Guillot Sogeti / ESEC R&D Sogeti / ESEC R&D alexandre.gazet(at)sogeti.com yoann.guillot(at)sogeti.com HITB 2009 Metasm Debugger Analysis of a protection Compiler
Sogeti / ESEC R&D alexandre.gazet(at)sogeti.com
Sogeti / ESEC R&D yoann.guillot(at)sogeti.com
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
1
2
3
Binary deprotection with metasm 2/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Even supports cr7
Binary deprotection with metasm 3/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
1
2
3
Binary deprotection with metasm 4/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 5/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 6/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 7/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
1
2
3
Binary deprotection with metasm 8/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 9/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
1
2
3
Binary deprotection with metasm 10/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 11/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 12/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 12/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
. 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 :00403EA0 push ecx . t e x t :00403EA1 push ebp . t e x t :00403EA2 c a l l sub 40BECD . t e x t :00403EA7
. t e x t :00403EA8 cmp edx , esp . t e x t :00403EAA push esp . t e x t :00403EAB i n c e s i
Binary deprotection with metasm 13/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
. t e x t :0040BECD sub 40BECD proc near ; CODE XREF: .text :00 . t e x t :0040BECD cmp eax , ebp . t e x t :0040BECF add dword ptr [ esp +0] , 1 . t e x t :0040BED4 t e s t ebx , 1E2h . t e x t :0040BEDA retn 0Ch . t e x t :0040BEDA sub 40BECD endp
Binary deprotection with metasm 14/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
r e s = Expression [ [ a [ 0 ] , :& , mask ] , :+ , [ a [ 1 ] , :& , mask ] ] binding [ a [ 0 ] ] = r e s 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 ] ] ]
Binary deprotection with metasm 15/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
r e s = Expression [ [ a [ 0 ] , :& , mask ] , :+ , [ a [ 1 ] , :& , mask ] ] binding [ a [ 0 ] ] = r e s 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 ] ] ]
Binary deprotection with metasm 15/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
binding [ : esp ] = Expression [ : esp , : − ,
binding [ I n d i r e c t i o n [ : esp , 4] ] = d i . next addr
dword ptr [ esp ] = 0x403EA7 esp = esp−4
binding [ : eax ] = Expression : : Unknown binding [ : edx ] = Expression : : Unknown
Binary deprotection with metasm 16/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
binding [ : esp ] = Expression [ : esp , : − ,
binding [ I n d i r e c t i o n [ : esp , 4] ] = d i . next addr
dword ptr [ esp ] = 0x403EA7 esp = esp−4
binding [ : eax ] = Expression : : Unknown binding [ : edx ] = Expression : : Unknown
Binary deprotection with metasm 16/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
binding [ : esp ] = Expression [ : esp , : − ,
binding [ I n d i r e c t i o n [ : esp , 4] ] = d i . next addr
dword ptr [ esp ] = 0x403EA7 esp = esp−4
binding [ : eax ] = Expression : : Unknown binding [ : edx ] = Expression : : Unknown
Binary deprotection with metasm 16/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
Binary deprotection with metasm 17/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
c a l l loc 40becdh ; @403ea2h e826800000 [ . . . ] cmp eax , ebp ; @40becdh 39e8 add dword ptr [ esp +0] , 1 ; @40becfh 8344240001 t e s t ebx , 1e2h ; @40bed4h f7c3e2010000 r e t 0ch ; @40bedah c20c00
1
2
3
4
Binary deprotection with metasm 18/55
Metasm Analysis of a protection Decompilation Debugger Compiler Disassembler
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 : 40bedah 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 t e s t ebx , 1e2h ; @40bed4h f7c3e2010000 r e t 0ch ; @40bedah c20c00 x: loc_403ea8h
Binary deprotection with metasm 19/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
1
2
3
Binary deprotection with metasm 20/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 21/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 22/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 23/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 24/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 25/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
1
2
3
Binary deprotection with metasm 26/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 27/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
1
2
Binary deprotection with metasm 28/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 29/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 30/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 31/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 32/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 33/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
1
2
3
Binary deprotection with metasm 34/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 35/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
l od s d xor eax , ebx add eax , 859 f c f a e h sub ebx , eax push eax
dword p t r [ esp ] := ( dword p t r [ e s i ]ˆ ebx )+859 f c f a e h eax := ( dword p t r [ e s i ]ˆ ebx )+859 f c f a e h ebx := ebx+−(dword p t r [ e s i ]ˆ ebx )−859 f c f a e h e s i := e s i +4 esp := esp −4
Binary deprotection with metasm 36/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 37/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
dword p t r [ esp ] := ( dword p t r [ e s i ]ˆ ebx )+859 f c f a e h eax := ( dword p t r [ e s i ]ˆ ebx )+859 f c f a e h ebx := ebx −(dword p t r [ e s i ]ˆ ebx )−859 f c f a e h e s i := e s i +4 esp := esp −4
eax := 93h ebx := 0 fd8dh e s i := 100167 beh [ . . . ]
dword p t r [ esp ] := 0 c0000001h eax := 0 c0000001h ebx := 4000 fd8ch e s i := 100167 c2h esp := esp −4
Binary deprotection with metasm 38/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 39/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 40/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 41/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
l i s t = Reg . i t o s [ 3 2 ] . concat ( % w[ v i r t e a x ] ) Reg . i t o s [ 1 6 ] . concat ( % w[ v i r t a x ] ) Reg . i t o s [ 8 ] . concat ( % w[ v i r t a l ] ) Reg . s t o i . c l e a r Reg . i t o s . each { | sz , hh | hh . e a c h w i t h i n d e x { | r , i | Reg . s t o i [ r ] = [ i , sz ] } } Reg : : Sym . r e p l a c e l i s t . map { | s | s . to sym }
Binary deprotection with metasm 42/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 43/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 44/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
1
2
3
Binary deprotection with metasm 45/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 46/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
1
2
3
Binary deprotection with metasm 47/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 48/55
Metasm Analysis of a protection Decompilation Breaking obfuscation Breaking code virtualization Putting the pieces together Conclusion(s)
Binary deprotection with metasm 49/55
Metasm Analysis of a protection Decompilation
1
2
3
Binary deprotection with metasm 50/55
Metasm Analysis of a protection Decompilation
Binary deprotection with metasm 51/55
Metasm Analysis of a protection Decompilation
Binary deprotection with metasm 52/55
Metasm Analysis of a protection Decompilation
Binary deprotection with metasm 53/55
Metasm Analysis of a protection Decompilation
Binary deprotection with metasm 54/55
Metasm Analysis of a protection Decompilation
Binary deprotection with metasm 55/55