我们来讲讲如何在Debugger这样软件Software中生存——呵呵她执行了病毒然后作内存分析
;----------简单代码做出重要事情------------
.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 off K32 ; 取kernel32base地址
call GetModuleHandleA
or eax,eax ; 检测是否失败
jz error
push off @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 off szTitle
push off msg2 ;呵呵你知道这里做事情
push 0
call MessageBoxA
jmp exit
error:
push 00001010h ; WIN95我们不能运行
push off szTitle
push off msg3
push 0
call MessageBoxA
jmp exit
debugger_found:
push 00001010h ; 显示 "Debugger found!"
push off szTitle
push off 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 upSEH ; 标准思路方法
exceptionhandler:
mov esp,[esp+8] ;不明白别问我
push 00000000h ; 引发MessageBoxA
push off szTitle
push off szMessage
push 00000000h
call MessageBoxA
push 00000000h
call ExitProcess ; 退出
upSEH:
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: [email protected]
;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 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
最新评论