阻止恶意远程线程

上传人:第*** 文档编号:34095725 上传时间:2018-02-20 格式:DOC 页数:18 大小:76.50KB
返回 下载 相关 举报
阻止恶意远程线程_第1页
第1页 / 共18页
阻止恶意远程线程_第2页
第2页 / 共18页
阻止恶意远程线程_第3页
第3页 / 共18页
阻止恶意远程线程_第4页
第4页 / 共18页
阻止恶意远程线程_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《阻止恶意远程线程》由会员分享,可在线阅读,更多相关《阻止恶意远程线程(18页珍藏版)》请在金锄头文库上搜索。

1、阻止恶意远程线程在 WIN2000/XP/2003 里,远程线程只有在建立新进程时,系统会用远程线程调用新进程的入口函数,除此之外,建立远程线程的一般是恶意程序,如何发现这些恶意程序并找到建立恶意程序的执行文件呢?下面本人提供一个最近完工的小程序。先说原理:在 WIN2000/XP/2003 里,建立本地线程和远程线程都是调用 ntdll.dll 里的 NtCreateThread 函数,只不过是如果建立本地线程,则进程句柄是-1,反之则是目标进程的句柄(一个大于 0 且小于 0xffffffff的具体数字) 。而本程序先驻留 ntdll+800h 处的空隙,之后拦截 NtCreateThre

2、ad,如果是建立本地线程则跳过,如果是建立远程线程,就跟踪到目标进程,在目标进程分配 4K 内存,把自身复制到目标进程,并且把远程线程的入口改为跟踪代码,经过跟踪代码的判断,而决定是否让远程线程执行。判断规则是:如果远程线程所处的模块没有 MZ 头和 PE 头,则拒绝;如果远程线程的入口是 LoadLibrary函数的地址,也拒绝;其他的就放行。由于要抢先拦截 NtCreateThread 函数,所以采用驱动的形式。编译方法:ml /c /coff /Cp %1.asmlink /subsystem:native /driver:wdm /release /align:16 /base:0x1

3、0000 /section:.text,RWE /out:%1.sys %1.objdel %1.obj安装驱动的方法:copy/y artwdm.sys %systemroot%/system32/driverssc create artwdm binpath= %systemroot%/system32/drivers/artwdm.sys type= kernel error= ignore start= systemsc start artwdm下面是源代码:.586p.model flat,stdcalloption casemap:noneassume fs:nothingassu

4、me gs:nothingincludelib ntoskrnl.lib ;必须从 WIN2000 DDK 复制到 MASM 的 INCLUDE 目录NtQuerySystemInformation proto :dword,:dword,:dword,:dword.constalign 4szdll db ntdll.dll,0align 4szNtQueryVirtualMemory db NtQueryVirtualMemory,0align 4szNtAllocateVirtualMemory db NtAllocateVirtualMemory,0align 4szNtWriteVi

5、rtualMemory db NtWriteVirtualMemory,0align 4szNtCreateThread db NtCreateThread,0align 4szMyLdrLoadDll db LdrLoadDll,0.data?dwTempVar dd ?szTempBuffer db 10000h dup(?).codestart:;int 3nopnopnopnoppushadcall _GetNtdllHandle ;获取 ntdll.dll 的地址mov ebx,eaxmov hntdll,eax.if !eaxjmp _exit.endifpush offset s

6、zMyLdrLoadDll ;获取 ntdll.LdrLoadDll 函数的地址push ebxcall _GetProcAddressmov lpLdrLoadDll,eax.if !eaxjmp _exit.endifpush offset szNtQueryVirtualMemory ;获取 ntdll.NtQueryVirtualMemory 函数的地址push ebxcall _GetProcAddressmov lpNtQueryVirtualMemory,eax.if !eaxjmp _exit.endifpush offset szNtAllocateVirtualMemory

7、 ;获取 ntdll.NtAllocateVirtualMemory 函数的地址push ebxcall _GetProcAddressmov lpNtAllocateVirtualMemory,eax.if !eaxjmp _exit.endifpush offset szNtWriteVirtualMemory ;获取 ntdll.NtWriteVirtualMemory 函数的地址push ebxcall _GetProcAddressmov lpNtWriteVirtualMemory,eax.if !eaxjmp _exit.endifpush offset szNtCreateTh

8、read ;获取 ntdll.NtCreateThread 函数的地址push ebxcall _GetProcAddressmov esi,eax.if !esijmp _exit.endifmov ecx,cr0btc ecx,16mov cr0,ecxmov dword ptr ebx+32h,fgm.if byte ptr esi+5!=0bah ;判断 ntdll.NtCreateThread 函数的第二条指令是不是 mov edx,xxxxxxxx(指令长度 5 字节,以 0bah 开头, 刚好替换成一条 call 指令)jmp _exit.endifadd esi,10 ;ESI

9、 指向被替换指令 mov edx,xxxxxxxx 的尾部mov eax,esi-4 ;保存原来指令的操作数 xxxxxxxxmov dword ptr _HookNtCreateThread+1,eaxlea edi,ebx+800h ;EDI 指向驻留地址(ntdll.dll+800h)处mov eax,edisub eax,esi ;计算两条指令的相对地址mov dword ptr esi-4,eax ;修改 NtCreateThread 函数的第二条指令为 call 指令mov byte ptr esi-5,0e8h ;修改 NtCreateThread 函数的第二条指令为 call

10、指令mov esi,offset _HookNtCreateThreadmov ecx,offset _AssertRemoteThreadEnd-offset _HookNtCreateThreadrep movsb ;拦截代码驻留 ntdll.dll+800hmov ecx,cr0bts ecx,16mov cr0,ecx_exit:popadxor eax,eaxret 8;以上代码在驱动入口执行,权限为 RING0_GetNtdllHandle proc ;获取 ntdll.dll 的地址之函数xor eax,eaxpushadinvoke NtQuerySystemInformati

11、on,11,offset szTempBuffer,10000h,offset dwTempVar.if !eaxmov edi,dwTempVaradd edi,offset szTempBuffermov esi,offset szdll.while dword ptr szTempBufferpushfdpush esipush edicldxor eax,eaxsub edi,100hmov ecx,30hrepnz scasbsub edi,10push 10push edicall _Mytolowermov ecx,9repz cmpsbsetz alpop edipop esi

12、popfd.if alsub edi,11chmov eax,edi+8mov esp+1ch,eax.break.endifsub edi,11chdec dword ptr szTempBuffer.endw.endifpopadret_GetNtdllHandle endp_Mytolower proc lpName,dwSize ;大写转小写函数pushadmov esi,lpNamemov edi,esimov ecx,dwSize.repeatlodsb.if al=A & al70000000hmov esi,ebpmov esi,esi+4 ;定位调用 NtCreateThre

13、ad()的代码地址, 放在 ESI.endiflea edi,ebp-20hpush edipush 20hpush edipush 0push esipush -1call lpNtQueryVirtualMemoryebx ;定位调用 NtCreateThread()的代码地址所处的模块地址.if !eaxmov eax,edi+4sub esi,eaxmov ecx,offset dwModuleRva-offset _AssertRemoteThreadmov ebp-400h+ecx,esi ;把调用 NtCreateThread()的代码地址所处的模块 RVA 值放入 dwModu

14、leRva 变量里mov ecx,offset szModuleName-offset _AssertRemoteThreadlea edi,ebp-400h+ecxpush 78hpush edi ;EDI 指向局部缓冲区里的代码当中的 szModuleName 缓冲区push eaxmov ecx,offset lpGetModuleFileName-offset _AssertRemoteThreadcall dword ptr ebp-400h+ecx ;把调用 NtCreateThread()的代码地址所处的模块的模块名放入 szModuleName 缓冲区里.endiflea es

15、i,ebp+0chmov eax,esi+14hmov eax,eax+0b0hmov ecx,offset _AssertRemoteThreadJmp-offset _AssertRemoteThread-5mov dword ptr ebp-400h+ecx,eax ;替换远程线程的开始地址,使其指向我的跟踪代码的地址lea ecx,ebp-4lea edx,ebp-8mov dword ptr ecx,1000hmov dword ptr edx,0push 4push 1000hpush ecxpush 0push eush dword ptr esi+0chcall lpNtAll

16、ocateVirtualMemoryebx ;在目标进程分配 4K 内存 ,把跟踪代码复制过去,目标进程就会先执行跟踪代码,进行判断后再执行远程线程.if eaxjmp _HookNtCreateThreadExit.endifmov ecx,offset _AssertRemoteThreadEnd-offset _AssertRemoteThreadlea edx,ebp-400hpush 0push ecxpush eush dword ptr ebp-8push dword ptr esi+0chcall lpNtWriteVirtualMemoryebx ;复制跟踪代码.if !eaxmov edx,ebp-8mov eax,esi+14hmov dword ptr eax+0b0h,edx ;如果在目标进程分配内存失败就恢

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号