文章目录
使用PEB进行反调试
使用PEB中的BeginDebug字段来检测是否处于调试环境。
//若返回值为TRUE则表示处于调试状态
bool CheckDebug()
{
bool bDebuged = false;
_asm push eax;
_asm mov eax, fs:[0x30];// eax保存PEB首地址
_asm mov al,byte ptr ds:[eax + 2];//BeginDebug字段的值
_asm mov bDebuged, al;
_asm pop eax
return bDebuged;
}
使用 IsDebuggerPresent()来判断是否是处于调试环境。
原理和上面一个一样;如:
// IsDebuggerPresent()返回值为True则表示处于调试状态
bool bDebug = IsDebuggerPresent();//它使用的方式,和上一个是一样的
if (bDebug)
{
MessageBox(NULL, L"正在被调试", L"注意", 0);
}
else
{
MessageBox(NULL, L"现在很安全", L"恭喜", 0);
}
检测PEB的GLobal来判断是否处于调试环境
在PEB+0x68处为peb的global字段,当其值=0x70时表示处于调试环境。
bool CheckDebug()
{
DWORD dwSign = 0;
_asm push eax;
_asm mov eax, fs:[0x30];
_asm mov eax, [eax + 0x68];
_asm mov dwSign, eax;
_asm pop eax
return dwSign==0x70;
}
使用 NtQueryInformationProcess 进行反调试
API在ntdll.lib
中,要使用的话必须导入库文件。
#pragma comment(lib,"ntdll.lib")
NtQueryInformationProcess
源码实现:
//没注释,要我自己跟,我还没来得及跟。。。先就这样吧。
NTSTATUS NTAPI NtMyQueryInformationProcess(
IN HANDLE ProcessHandle,
IN PROCESSINFOCLASS ProcessInformationClass,
OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength,
OUT PULONG ReturnLength OPTIONAL
)
{
_asm {
mov eax, 16h
xor ecx, ecx
lea edx, [esp + 4]
call dword ptr fs : [0C0h]
add esp, 4
ret 14h
mov eax, 17h