反调试防护-API1

IsDebuggerPresent()
CheckRemoteDebuggerPresent()

其内部实际调用NtQueryInformationProcess()

bool _stdcall ThreadCall()
{
	
	while (true)
	{
		BOOL  pbDebuggerPresent = FALSE;
		CheckRemoteDebuggerPresent(GetCurrentProcess(), &pbDebuggerPresent);
		if (pbDebuggerPresent !=0)
		{
			printf("debug\n");
			system("pause");
			exit(-1);
		}
		if (IsDebuggerPresent()!=0)
		{
			printf("debug\n");
			system("pause");
			exit(-1);
		}
	}
}

int main()
{
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ThreadCall, NULL, 0, NULL);
	system("pause");
	return 0;
}

FS/GS寄存器

debug标志:

X86:FS:0x30

FS指向TEB,FS:30指向PEB,PEB+2指向debug标志。

X64:  GS:0x60

GS指向TEB,GS:60指向PEB,PEB+2指向debug标志。


NtGlobalFlag标志:

在PEB里面


—raedfsdword():
bool _stdcall ThreadCall()
{
	
	while (true)
	{
		//	DWORD dwPeb = __readfsdword(0x30);
		//	UCHAR BeingDebugged = *(UCHAR *)(dwPeb + 2);
		
		//	ULONGLONG ullPeb = __readgsqword(0x60);
		//	UCHAR BeingDebugged = *(UCHAR *)(ullPeb + 2);

		//	DWORD dwPeb = __readfsdword(0x30);
		//	DWORD NtGlobalFlag = *(DWORD *)(dwPeb + 0x68);
		//  if (NtGlobalFlag == 0x70) printf("debug");

		//	ULONGLONG dwPeb = __readgsqword(0x60);
		//	DWORD NtGlobalFlag = *(DWORD *)(dwPeb + 0xbc);
		//  if (NtGlobalFlag == 0x70) printf("debug");
	}
}

int main()
{
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ThreadCall, NULL, 0, NULL);
	system("pause");
	return 0;
}

Heap标志:

bool _stdcall ThreadCall()
{
	
	while (true)
	{
		/*DWORD dwPeb = __readfsdword(0x30);
		DWORD ProcessHeap = *(DWORD*)(dwPeb + 0x18);
		DWORD dwFlags = *(DWORD*)(ProcessHeap + 0x40);
		DWORD dwForceFlags = *(DWORD*)(ProcessHeap + 0x44);
		if (dwFlags != 0x2 || dwForceFlags != 0)
		{
			printf("debug\n");
			system("pause");
			exit(0);
		}*/
		UINT64 dwPeb = __readgsqword(0x60);
		UINT64 ProcessHeap = *(PUINT64)(dwPeb + 0x30);
		DWORD dwFlags = *(DWORD*)(ProcessHeap + 0x70);
		DWORD dwForceFlags = *(DWORD*)(ProcessHeap + 0x74);
		if (dwFlags != 0x2 || dwForceFlags != 0)
		{
			printf("debug\n");
			system("pause");
			exit(0);
		}
	}
}

int main()
{
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ThreadCall, NULL, 0, NULL);
	system("pause");
	return 0;
}

上面有些都是依靠api,如果对方挂钩了,api就失效,只有手动实现标志位检查

ZwQueryInformationProcess手动实现

拿PEB:
bool _stdcall ThreadCall()
{
	MyZwQueryInformationProcess Func = (MyZwQueryInformationProcess)GetProcAddress(GetModuleHandleA("ntdll.dll"), "ZwQueryInformationProcess");
	PROCESS_BASIC_INFORMATION pbi = { 0 };
	while (true)
	{
		Func(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
		CHAR flag = *((PCHAR)(pbi.PebBaseAddress) + 2);
		if (flag == TRUE)
		{
			printf("debug\n");
			system("pause");
			exit(0);
		}
	}
}

int main()
{
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ThreadCall, NULL, 0, NULL);
	system("pause");
	return 0;
}
调试端口:
bool _stdcall ThreadCall()
{
	MyZwQueryInformationProcess Func = (MyZwQueryInformationProcess)GetProcAddress(GetModuleHandleA("ntdll.dll"), "ZwQueryInformationProcess");
	DWORD isDebugPort = 0;
	while (true)
	{
		Func(GetCurrentProcess(), ProcessDebugPort, &isDebugPort, sizeof(isDebugPort), NULL);
		if (isDebugPort == TRUE)
		{
			printf("debug\n");
			system("pause");
			exit(0);
		}
	}
}

int main()
{
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ThreadCall, NULL, 0, NULL);
	system("pause");
	return 0;
}
隐藏端口:
    DWORD isProcessDebugFlags = 0;
	func(GetCurrentProcess(), (PROCESSINFOCLASS)0x1F, &isProcessDebugFlags,             sizeof(isProcessDebugFlags), NULL);
	if (isProcessDebugFlags == 0)
	{
		printf("debug\n");
		system("pause");
		exit(0);
	}



DWORD isProcessDebugObjectHandle = 0;
	func(GetCurrentProcess(), (PROCESSINFOCLASS)0x1E, &isProcessDebugObjectHandle, sizeof(isProcessDebugObjectHandle), NULL);
	if (isProcessDebugObjectHandle != 0)
	{
		printf("debug\n");
		system("pause");
		exit(0);
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值