发新话题
打印

[转载]病毒是如何抗动态测试

[转载]病毒是如何抗动态测试

信息来源:www.smatrix.org

我们来讲讲如何在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

Exception proc pRecord,pFrame,pContext,pDispatch
call PushSehBackProc
call ClearSehFrame
jmp ecx
PushSehBackProc:
pop ecx
mov eax,pContext
mov [eax.cx_Eip],ecx
xor eax,eax ;忽略错误继续执行
ret
Exception endp

GetEspAddr:
call PushOffsetEspAddr
dd ?
PushOffsetEspAddr:
pop edx
ret


.code

Start:
call PushErrorProc
call MessageBoxA,0,offset Msg,offset Msg,0
ret
PushErrorProc:
pop ecx
call SetSehFrame
mov ds:[0],eax
call ClearSehFrame
ret
end Start
作了如此多我们的代码就安全了吗??
No!!
对方还有Soft-ICE 这个极品——呵呵,刚才的那些代码遇到她就。。。为死去的人默哀三分钟〉〉
可是道高一尺,魔高一丈——还是有办法的。。。
看下面的代码
;----------简单的代码做出重要的事情------------
.586p
.model flat

extrn CreateFileA:PROC
extrn CloseHandle:PROC
extrn MessageBoxA:PROC
extrn ExitProcess:PROC

.data

szTitle db "SoftICE detection",0

szMessage db "SoftICE for Win9x : "
answ1 db "not found!",10
db "SoftICE for WinNT : "
answ2 db "not found!",10


nfnd db "found! ",10

SICE9X db "\\.\SICE",0
SICENT db "\\.\NTICE",0

.code

NoSoftICE:
push 00000000h ; 针对SoftICE for Win9x的检测
push 00000080h
push 00000003h
push 00000000h
push 00000001h
push 0C0000000h
push offset SICE9X
call CreateFileA

inc eax
jz NoSICE9X
dec eax

push eax ; 关闭局柄
call CloseHandle

lea edi,answ1 ; SoftICE for win9x found!找到了找到了——呵呵,你死了
call PutFound
NoSICE9X:
push 00000000h ;针对SoftICE for WinNT的检测
push 00000080h
push 00000003h
push 00000000h
push 00000001h
push 0C0000000h
push offset SICENT
call CreateFileA

inc eax
jz NoSICENT
dec eax

push eax ; 关闭局柄
call CloseHandle

lea edi,answ2 ; SoftICE for WinNT found!——呵呵,你想怎样就怎样
call PutFound
NoSICENT:
push 00h
push offset szTitle ; 显示结果
push offset szMessage
push 00h
call MessageBoxA

push 00h ; 结束程序
call ExitProcess

PutFound:;在这里是找到后的表情——you know what i meant??
mov ecx,0Bh
lea esi,nfnd
rep movsb
ret

end NoSoftICE
以后有机会在谈些反静态分析的方法

TOP

发新话题