来源:安全中国
我们来讲讲如何在Debugger这样的软件中生存——呵呵,她执行了病毒然后作内存分析 ;----------简单的代码做出重要的事情------------ .586p .model flat extrn GetProcAddress:PROC extrn GetModuleHandleA:PROC
extrn MessageBoxA:PROC extrn ExitProcess:PROC
.data szTitle db "IsDebuggerPresent Demonstration",0 msg1 db "Application Level Debugger Found",0 msg2 db "Application Level Debugger NOT Found",0 msg3 db "Error: Couldn’t get IsDebuggerPresent.",10 db "We CAN’T RUN under Win95",0 ;作了测试。。。证明不行
@IsDebuggerPresent db "IsDebuggerPresent",0 K32 db "KERNEL32",0
.code
antidebug: push offset K32 ; 取kernel32的base地址 call GetModuleHandleA or eax,eax ; 检测是否失败 jz error
push offset @IsDebuggerPresent ;得到函数地址 push eax ; 压入堆栈 call GetProcAddress ; ~~~!!~~可能产生错误 or eax,eax jz error
call eax ; 调用IsDebuggerPresent
or eax,eax ; 如果不等于 0,就说明有人在分析我们的代码 jnz debugger_found ;那就——呵呵,要做什么?你想作什么?那就作吧。。
debugger_not_found: push 0 ;显示"Debugger not found" push offset szTitle push offset msg2 ;呵呵,你知道这里做的事情。。。 push 0 call MessageBoxA jmp exit
error: push 00001010h ; WIN95我们不能运行。。。 push offset szTitle push offset msg3 push 0 call MessageBoxA jmp exit
debugger_found: push 00001010h ; 显示 "Debugger found!" push offset szTitle push offset msg1 ;你也可以做些其他的事 push 0 call MessageBoxA
exit: push 00000000h ; 退出 call ExitProcess
end antidebug
不过这样只是躲了——可是我们应该防止这种事情 呵呵,这就是SEH的妙用了 ;----------简单的代码做出重要的事情------------ .386p .model flat
extrn MessageBoxA:PROC extrn ExitProcess:PROC
.data
szTitle db "Structured Exception Handler example",0 szMessage db "Intercepted General Protection Fault!",0
.code
start: call setupSEH ; 标准的方法。。。。
exceptionhandler: mov esp,[esp+8] ;不明白别问我
push 00000000h ; 引发MessageBoxA push offset szTitle push offset szMessage push 00000000h call MessageBoxA
push 00000000h call ExitProcess ; 退出
setupSEH: push dword ptr fs:[0] ; 得到SEH局柄 mov fs:[0],esp ;创建新局柄
mov ebx,0BFF70000h ; 写入核地址 mov eax,012345678h xchg eax,[ebx]
end start 这个代码在win2k上容易出错(原因我不知道)——所以呵呵,我在白白那里看到了下面的好代码。。。 ;Author: whg ;Email: whg@whitecell.org ;Homepage:http://www.whitecell.org .386p .model flat,stdcall
extrn MessageBoxA: proc extrn ExitProcess: proc
.data
Msg db ’ERROR’,0
SetSehFrame: ;ecx=忽略错误继续执行地址 pop eax ;弹出返回地址 push ecx ;保存忽略错误继续执行地址 call PushExceptionProc jmp short Exception PushExceptionProc: push fs:dword ptr[0] mov fs:[0],esp call GetEspAddr push D [edx] ;保存原Esp地址值 mov [edx],esp jmp eax ClearSehFrame: pop eax ;弹出返回地址 call GetEspAddr mov esp,[edx] pop D [edx] ;恢复原Esp地址值 pop fs:dword ptr[0] pop ecx pop ecx ;弹出忽略错误继续执行地址 jmp eax
[1] [2] 下一页 |