反调试 - r3 使用 NtQuerySystemInformation 获取 KdKdDebuggerEnable 和 KdDebuggerNotPresent

原理

NtQuerySystemInformation 被 ntdll.dll 导出,当第一个参数传入 0x23 (SystemInterruptInformation) 时,会返回一个 SYSTEM_KERNEL_DEBUGGER_INFORMATION 结构,里面的成员KdKdDebuggerEnable 和 KdDebuggerNotPresent 标志系统是否启用内核调试。

代码示例

// Test_Console_1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <Windows.h>
#include <intrin.h>

using namespace std;

typedef struct _SYSTEM_KERNEL_DEBUGGER_INFORMATION{
	BOOLEAN KernelDebuggerEnabled;
	BOOLEAN KernelDebuggerNotPresent;
} SYSTEM_KERNEL_DEBUGGER_INFORMATION, * PSYSTEM_KERNEL_DEBUGGER_INFORMATION;
typedef NTSTATUS(WINAPI* pNtQuerySystemInformation)(IN UINT SystemInformationClass,OUT PVOID SystemInformation,IN ULONG SystemInformationLength,OUT PULONG ReturnLength);

int main()
{
   // 取 NtQuerySystemInformation 地址
	pNtQuerySystemInformation NtQuerySystemInformation = (pNtQuerySystemInformation)GetProcAddress(LoadLibrary(L"ntdll.dll"), "ZwQuerySystemInformation");
	if (NtQuerySystemInformation == NULL) {
		goto main_end;
	}

	// 获取系统信息
	SYSTEM_KERNEL_DEBUGGER_INFORMATION KdDebuggerInfo;		
	if (NtQuerySystemInformation(
		0x23,																							// 要检索的系统信息的类型: SystemInterruptInformation
		&KdDebuggerInfo,																	// 接受请求信息
		sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION),		// 请求信息的字节大小
		NULL
	) != 0) {
		goto main_end;
	}

	// 判断调试器
	if (KdDebuggerInfo.KernelDebuggerEnabled || !KdDebuggerInfo.KernelDebuggerNotPresent) {
		cout << "发现调试器!" << endl;
	}
	else {
		cout << "没有调试器" << endl;
	}

main_end:
    getchar();
    return 0;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值