当前位置: 首页 > article >正文

反调试—1

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);
	}


http://www.kler.cn/news/333236.html

相关文章:

  • websockets库使用(基于Python)
  • 【AI学习】Mamba学习(二):线性注意力
  • Qt系统学习篇(6)-QMainWindow
  • 新闻推荐系统:Spring Boot的可扩展性
  • Linux:Linux进程概念
  • 前端Vue项目的自动打包、上传与部署
  • 数据结构-链表笔记
  • PostgreSQL的pglz使用限制
  • 【递归】12. leetcode 1448 统计二叉树中好节点的数目
  • CSS画出三角形的做法
  • CNI(Container Network Interface)机制是一种用于容器网络的标准化接口,旨在为容器提供一致的网络插件模型。
  • Ps:将画板导出到 PDF
  • 关于 Angular SSR 应用 html 源代码中的 ng-state script 标签
  • SQL中如何进行 ‘’撤销‘’ 操作-详解
  • HTMLCSS练习
  • 鸿蒙harmonyos next flutter通信之BasicMessageChannel获取app版本号
  • Netty:高性能异步网络编程框架全解析
  • 08.useInterval
  • 树莓派5:换源(针对Debian12)+安装包管理器Archiconda(图文教程+详细+对初学者超级友好)
  • [Unity Demo]从零开始制作空洞骑士Hollow Knight第十三集:制作小骑士的接触地刺复活机制以及完善地图的可交互对象