1.程序窗口[chuang kou]句柄[ju bing]檢測
原理:用FindWindow函數[han shu]查找[cha zhao]具備相同學口[chuang kou]類名和標題的窗口[chuang kou],若是找到就說明[shuo ming]有OD在運行[yun hang]
//********************************************
//經過查找[cha zhao]窗口[chuang kou]類名來實現檢測OllyDBG
//********************************************
function AntiLoader():Boolean;
const
OllyName='OLLYDBG';
var
Hwnd:Thandle;
begin
Hwnd:=FindWindow(OllyName,nil);
if Hwnd<>0 then
Result:=True
else
Result:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'找到調試[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未找到調試[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
end;函數
2.用線程[xian cheng]環境塊檢測
原理:用ring3級下的調試[tiao shi]器對可執行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]進行調試[tiao shi]時,調試[tiao shi]器會把被調試[tiao shi]的可執行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]做爲一個子線程[xian cheng]進行跟蹤[gen zong].這時被調試[tiao shi]的可執行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]的PEB結構[jie gou]偏移0x02處的BeingDebugged的值爲1,若是可執行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]未被調試[tiao shi],則值爲0,因此能夠利用這個值來檢測程序是否被ring3級下的調試[tiao shi]器調試[tiao shi]
//***************************************
//使用PEB結構[jie gou]檢測OllyDBG
//***************************************
function AntiLoader():Boolean; //檢測調試[tiao shi]器;
var
YInt,NInt:Integer;
begin
asm
mov eax,fs:[$30]
//獲取PEB偏移2h處BeingDebugged的值
movzx eax,byte ptr[eax+$2]
or al,al
jz @No
jnz @Yes
@No:
mov NInt,1
@Yes:
Mov YInt,1
end;
if YInt=1 then
Result:=True;
if NInt=1 then
Result:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'發現調試[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未發現調試[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION);
end;
3.用API函數[han shu]IsDebuggerPresent檢測
原理:操做系統[xi tong][cao zuo xi tong]將調試[tiao shi]對象[dui xiang]設置[she zhi]爲在特殊環境中運行[yun hang],而kernel32.dll中的API函數[han shu]IsDebuggerPresent的功能是用於[yong yu]判斷進程[jin cheng]是否處於調試[tiao shi]環境中,這樣就能夠利用這個API函數[han shu]來查看進程[jin cheng]是否在調試[tiao shi]器中執行[zhi hang]
//****************************************
//利用IsDebuggerPresent函數[han shu]檢測OllyDBG
//****************************************
function AntiLoader():Boolean;
var
isDebuggerPresent: function:Boolean;
Addr: THandle;
begin
Addr := LoadLibrary('kernel32.dll');
isDebuggerPresent := GetProcAddress(Addr, 'IsDebuggerPresent');
if isDebuggerPresent then
Result:=True
else
Result:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'發現調試[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未發現提示[ti shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION);
end;oop
4.檢查程序[jian cha cheng xu]的父進程[jin cheng]
原理:Windows操做系統[xi tong][cao zuo xi tong]下的GUI可執行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]的父進程[jin cheng]都是explorer.exe(CUI可執行[zhi hang]程序[zhi hang cheng xu][ke zhi hang cheng xu]的父進程[jin cheng]是 CMD.exe,系統[xi tong]服務[xi tong fu wu]的父進程[jin cheng]是Service.exe,在實際使用的時候須要根據本身的程序類型[lei xing]來選擇[xuan ze]父進程[jin cheng]實現反跟蹤[gen zong]),而正被調試[tiao shi]器OD調試[tiao shi]的程序的父進程[jin cheng]是調試[tiao shi]器的執行[zhi hang]程序[zhi hang cheng xu]ollydbg.exe而不是別的.因此能夠利用檢查父進程[jin cheng]是否爲explorer.exe的方法[fang fa]來檢測OD.
//***************************************************
//檢查父進程[jin cheng]來檢測OllyDBG
//***************************************************
function AntiLoader():Boolean;
const
ParentName='\EXPLORER.EXE';
var
hSnap,hProcess:THandle;
szBuffer:array[0..MAX_PATH] of char;
FileName:array[0..MAX_PATH] of char;
Process32:PROCESSENTRY32;
LoopFlag:BOOL;
begin
////獲得全部進程[jin cheng]的列表[lie biao]快照[kuai zhao]
hSnap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if hSnap=INVALID_HANDLE_VALUE then
begin
Result:=False;
Exit;
end;
Process32.dwSize:=sizeof(PROCESSENTRY32);
//查找[cha zhao]進程[jin cheng]
LoopFlag:=Process32First(hSnap,Process32);
if LoopFlag=False then
begin
CloseHandle(hSnap);
Result:=False;
Exit;
end;
while Integer(LoopFlag)<>0 do
begin
if Process32.th32ProcessID=GetCurrentProcessId() then
begin
hProcess:=OpenProcess(PROCESS_ALL_ACCESS,FALSE,Process32.th32ParentProcessID);
if hProcess<>0 then
begin
if GetModuleFileNameEx(hProcess,0,FileName,MAX_PATH)<>0 then
begin
//取得系統[xi tong]目錄[xi tong mu lu]
GetWindowsDirectory(szBuffer,MAX_PATH);
//合併系統[xi tong]目錄[xi tong mu lu]和\EXPLORER.EXE
StrCat(szBuffer,ParentName);
//轉換[zhuan huan]成大寫之後比較當前調試[tiao shi]程序[tiao shi cheng xu]的進程[jin cheng]是否爲父進程[jin cheng]
if UpperCase(String(FileName))<>UpperCase(String(szBuffer)) then
Result:=True
else
Result:=False;
end;
end
else
Result:=False;
end;
LoopFlag:=Process32Next(hSnap,Process32);
end;
CloseHandle(hSnap);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'發現調試[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
else
MessageBox(Handle,'未發現調試[tiao shi]器!','提示[ti shi]',MB_OK+MB_ICONINFORMATION)
end;
5.檢查STARTUPINFO結構[jie gou]
原理:Windows操做系統[xi tong][cao zuo xi tong]中的explorer.exe建立進程[jin cheng]的時候會把STARTUPINFO結構[jie gou]中的值設爲0,而非explorer.exe建立進程[jin cheng]的時候會忽略這個結構[jie gou]中的值,也就是結構[jie gou]中的值不爲0,因此能夠利用這個來判斷OD是否在調試[tiao shi]程序[tiao shi cheng xu].
/************************************************
//經過檢測STARTUPINFO結構[jie gou]來檢測OllyDbg
//************************************************
function AntiLoader():Boolean;
var
Info:STARTUPINFO;
begin
GetStartupInfo(Info);
if (Info.dwX<>0) or (Info.dwY<>0) or (Info.dwXCountChars<>0) or (Info.dwYCountChars<>0) or
(Info.dwFillAttribute<>0) or (Info.dwXSize<>0) or (Info.dwYSize<>0) then
Result:=True
else
Result:=False;
end;
procedure TMainFrm.FormCreate(Sender: TObject);
begin
if AntiLoader then
MessageBox(Handle,'發現調試[tiao shi]器!','提示[ti shi]',MB_OK)
else
MessageBox(Handle,'未發現調試[tiao shi]器!','提示[ti shi]',MB_OK);
end;ui