با سلام به آقای اینپرایز عزیز و معذرت به خاطر دوری طولانی مدت. و ممنون از این بحثی که آغاز شده.
در زیر به چند روش اولیه برای antidebugging اشاره میکنم.
1 :تابع isdebuggerpresent: (kernel32.dll)
این تابع مشخص میکند که آیا پروسه ما تحت یک دیباگر صورت میگیرد یا خیر.
مقدار بازگشتی : اگز جواب بله باشد <>0 در غیر اینصورت =0 میباشد.
(فقط با دیباگر های سطح ring3 عمل میکند)
.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're probably under Win95",0
@IsDebuggerPresent db "IsDebuggerPresent",0
K32 db "KERNEL32",0
.code
antidebug1:
push offset K32 ; Obtain KERNEL32 base address
call GetModuleHandleA
or eax,eax ; Check for fails
jz error
push offset @IsDebuggerPresent ; Now search for the existence
push eax ; of IsDebuggerPresent. If
call GetProcAddress ; GetProcAddress returns an
or eax,eax ; error, we assume we're in
jz error ; Win95
call eax ; Call IsDebuggerPresent
or eax,eax ; If it's not 0, we're being
jnz debugger_found ; debugged
debugger_not_found:
push 0 ; Show "Debugger not found"
push offset szTitle
push offset msg2
push 0
call MessageBoxA
jmp exit
error:
push 00001010h ; Show "Error! We're in Win95"
push offset szTitle
push offset msg3
push 0
call MessageBoxA
jmp exit
debugger_found:
push 00001010h ; Show "Debugger found!"
push offset szTitle
push offset msg1
push 0
call MessageBoxA
exit:
push 00000000h ; Exit program
call ExitProcess
end antidebug1
2: توقف application level debugger با SEH :
در ابتدا FS را ذخیره میکنیم .
push dword ptr fs:[0]
و اکنون زمان ان است که شی را وادار کنیم به handler ما اشاره کند.
push offset SEH_Handler
mov fs:[0],esp
برای برگرداندن SEH این دوشتور را انجام دهید.
pop dword ptr fs:[0]
مثال :
(نحوه کامپایل : tasm32 /m3 /ml sehtest,,;
tlink32 /Tpe /aa sehtest,sehtest,,import32.lib
)
.386p
.model flat ; Good good... 32 bit r0x0r
extrn MessageBoxA:PROC ; Defined APIs
extrn ExitProcess:PROC
.data
szTitle db "Structured Exception Handler example",0
szMessage db "Intercepted General Protection Fault!",0
.code
start:
call setupSEH ; The call pushes the offset
; past it in the stack rigth?
; So we will use that :)
exceptionhandler:
mov esp,[esp+8] ; Error gives us old ESP
; in [ESP+8]
push 00000000h ; Parameters for MessageBoxA
push offset szTitle
push offset szMessage
push 00000000h
call MessageBoxA
push 00000000h
call ExitProcess ; Exit Application
setupSEH:
push dword ptr fs:[0] ; Push original SEH handler
mov fs:[0],esp ; And put the new one (located
; after the first call)
mov ebx,0BFF70000h ; Try to write in kernel (will
mov eax,012345678h ; generate an exception)
xchg eax,[ebx]
end start
.386p
.model flat ; Good good... 32 bit r0x0r
extrn MessageBoxA:PROC ; Defined APIs
extrn ExitProcess:PROC
.data
szTitle db "Structured Exception Handler example",0
szMessage db "Intercepted General Protection Fault!",0
.code
start:
call setupSEH ; The call pushes the offset
; past it in the stack rigth?
; So we will use that :)
exceptionhandler:
mov esp,[esp+8] ; Error gives us old ESP
; in [ESP+8]
push 00000000h ; Parameters for MessageBoxA
push offset szTitle
push offset szMessage
push 00000000h
call MessageBoxA
push 00000000h
call ExitProcess ; Exit Application
setupSEH:
push dword ptr fs:[0] ; Push original SEH handler
mov fs:[0],esp ; And put the new one (located
; after the first call)
mov ebx,0BFF70000h ; Try to write in kernel (will
mov eax,012345678h ; generate an exception)
xchg eax,[ebx]
end start
(بازم در مقابل SI نمی تواند عمل کند)
3: شناسایی SI :در win9x
سرویس vmm به نام get_ddb . (00010146 h) :
mov eax, Device_ID
mov edi, Device_Name
int 20h ; VMMCall Get_DDB
dd 00010146h
mov [DDB], ecx
این تابع مشخص میکند که ایا vxd برای وسیله مورد نظر نصب شده است. در صورت نسب بودن یک ddb برای ان بر میگرداند.
Device_ID : device identifier (این پارامتر برای توابع مبتنی بر نام صفر قرار بگیرد)
Device_Name: An eight-character device name that is padded with blank
characters. This parameter is only required if Device_ID is zero. The
device name is case-sensitive.
خوب ممکنه براتون شگفت انگیز باشه که این کد کار میکنه. فیلد Device_ID . vxd ی که SI نصب میکند همیشه ثابت است و میتوانیم از این موضوع برای شناساییSi بهره ببریم.
این مقدار 202h است.
mov eax,00000202h
VxDCall VMM_Get_DDB
xchg eax,ecx
jecxz NotSoftICE
jmp DetectedSoftICE
4: شناسایی SI :در win9x روش 2
وقفه 2fh :
INT 2F - MS Windows - GET DEVICE API ENTRY POINT
AX = 1684h
BX = virtual device (VxD) ID (see #1921)
ES:DI = 0000h:0000h
Return: ES:DI -> VxD API entry point, or 0:0 if the VxD does not support an API
Note: some Windows enhanced-mode virtual devices provide services that
applications can access. For example, the Virtual Display Device
(VDD) provides an API used in turn by WINOLDAP.
بنابراین شما در bxکافی است 202h قرار دهید تا وجود si را ثابت کنید.
4: شناسایی SI : عمومی
استفاده از تابع : createfile
.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
db "(c) 1999 Billy Belcebu/iKX",0
nfnd db "found! ",10
SICE9X db ".SICE",0
SICENT db ".NTICE",0
.code
DetectSoftICE:
push 00000000h ; Check for the presence of
push 00000080h ; SoftICE for Win9x envirome-
push 00000003h ; nts...
push 00000000h
push 00000001h
push 0C0000000h
push offset SICE9X
call CreateFileA
inc eax
jz NoSICE9X
dec eax
push eax ; Close opened file
call CloseHandle
lea edi,answ1 ; SoftICE found!
call PutFound
NoSICE9X:
push 00000000h ; And now try to open SoftICE
push 00000080h ; for WinNT...
push 00000003h
push 00000000h
push 00000001h
push 0C0000000h
push offset SICENT
call CreateFileA
inc eax
jz NoSICENT
dec eax
push eax ; Close file handle
call CloseHandle
lea edi,answ2 ; SoftICE for WinNT found!
call PutFound
NoSICENT:
push 00h ; Show a MessageBox with the
push offset szTitle ; results
push offset szMessage
push 00h
call MessageBoxA
push 00h ; Terminate program
call ExitProcess
PutFound:
mov ecx,0Bh ; Change "not found" by
lea esi,nfnd ; "found"; address of where
rep movsb ; to do the change is in EDI
ret
end DetectSoftICE