Metasm Feelings
Alexandre Gazet
Sogeti / ESEC R&D alexandre.gazet(at)sogeti.com
Yoann Guillot
Sogeti / ESEC R&D yoann.guillot(at)sogeti.com
RECON 2010 - Montreal Metasm Tracer MSR NIC Plan Metasm 1 - - PowerPoint PPT Presentation
Metasm Feelings Alexandre Gazet Yoann Guillot Sogeti / ESEC R&D Sogeti / ESEC R&D alexandre.gazet(at)sogeti.com yoann.guillot(at)sogeti.com RECON 2010 - Montreal Metasm Tracer MSR NIC Plan Metasm 1 Tracer 2 MSR 3 NIC 4
Sogeti / ESEC R&D alexandre.gazet(at)sogeti.com
Sogeti / ESEC R&D yoann.guillot(at)sogeti.com
Metasm Tracer MSR NIC
1
2
3
4
Metasm Feelings 2/25
Metasm Tracer MSR NIC
1irc://freenode/metasm
Metasm Feelings 3/25
Metasm Tracer MSR NIC
Metasm Feelings 4/25
Metasm Tracer MSR NIC
ARM MIPS PowerPC Sh4
Metasm Feelings 5/25
Metasm Tracer MSR NIC
Metasm Feelings 6/25
Metasm Tracer MSR NIC
r e q u i r e ’ metasm ’ i n c l u d e Metasm np = OS. c u r r e n t . f i n d p r o c e s s ( ’ notepad ’ ) # read the v i r t u a l memory
a running p r o c e s s p np . memory [0 x40000 , 0x200 ] # i n j e c t a s h e l l c o d e sc = S h e l l c o d e . assemble ( Ia32 . new , ’ ’ jmp esp ’ ’ ) . e n c o d e s t r i n g np . memory [0 x40000 , sc . l e n g t h ] = sc
Metasm Feelings 7/25
Metasm Tracer MSR NIC
r e q u i r e ’ open−u r i ’ puts ’ ’ r e t r i e v i n g source code . . . ’ ’ html = open ( ’ http :// recon . cx /2010/ cfp . html ’ ) . read source = html [ / unsigned .∗\}/m ] abort ’ ’ no source found : ( ’ ’ i f not source e l f = Metasm : : ELF . c o m p i l e c ( Metasm : : Ia32 . new , source ) e l f . e n c o d e s t r i n g ; e l f . decode dasm = e l f . d i s a s s e m b l e r # s e l f m o d i f y plugin , handles t r i v i a l decoding l o o p s dasm . l o a d p l u g i n ’ s e l f m o d i f y ’ w = Metasm : : Gui : : DasmWindow . new ( ’ recon−cfp ’ , dasm , ’ buf ’ ) Metasm : : Gui . main
Metasm Feelings 8/25
Metasm Tracer MSR NIC
1
2
3
4
Metasm Feelings 9/25
Metasm Tracer MSR NIC
aCurrently using DataMapper
Metasm Feelings 10/25
Metasm Tracer MSR NIC
Metasm Feelings 11/25
Metasm Tracer MSR NIC
Metasm Feelings 12/25
Metasm Tracer MSR NIC
1
2
3
4
Metasm Feelings 13/25
Metasm Tracer MSR NIC
2http://www.openrce.org/blog/view/535/Branch_Tracing_with_Intel_MSR_Registers 3http://www.ivanlef0u.tuxfamily.org/?p=382
Metasm Feelings 14/25
Metasm Tracer MSR NIC
Metasm Feelings 15/25
Metasm Tracer MSR NIC
c l a s s MSR < Metasm : : DynLdr new api c < < EOS t y p e d e f s t r u c t KLDBG { SYSDBG COMMAND DbgCommandClass ; PVOID DbgCommand ; DWORD DbgCommandLen ; } KLDBG, ∗ PKLDBG; t y p e d e f enum SYSDBG COMMAND { SysDbgReadVirtual = 8 , SysDbgWriteVirtual = 9 , SysDbgReadMsr = 16 , SysDbgWriteMsr = 17 , } HANDLE WINAPI OpenServiceA ( HANDLE hSCManager , LPCSTR lpServiceName , DWORD dwDesiredAccess ) ; EOS end
Metasm Feelings 16/25
Metasm Tracer MSR NIC
def readmsr ( addr ) msr = a l l o c c s t r u c t ( ’SYSDBG MSR ’ , ’ msraddress ’ = > addr ) kldbg = a l l o c c s t r u c t ( ’KLDBG ’ ) kldbg [ ’ dbgcommandclass ’ ] = SYSDBGREADMSR kldbg [ ’ dbgcommand ’ ] = msr kldbg [ ’ dbgcommandlen ’ ] = msr . l e n g t h lpBytesReturned = 0. chr ∗8 d e v i c e i o c o n t r o l ( @hdevice , IOCTL , kldbg , kldbg . length , \ msr , msr . length , lpBytesReturned , NULL) return msr [ ’ data ’ ] end
Metasm Feelings 17/25
Metasm Tracer MSR NIC
Metasm Feelings 18/25
Metasm Tracer MSR NIC
Metasm Feelings 19/25
Metasm Tracer MSR NIC
1
2
3
4
Metasm Feelings 20/25
Metasm Tracer MSR NIC
Metasm Feelings 21/25
Metasm Tracer MSR NIC
Metasm Feelings 22/25
Metasm Tracer MSR NIC
Metasm Feelings 23/25
Metasm Tracer MSR NIC
4http://esec.fr.sogeti.com/blog/
Metasm Feelings 24/25
Metasm Tracer MSR NIC
http://metasm.cr0.org/ http://esec.fr.sogeti.com/blog/
Metasm Feelings 25/25