SSDTHOOK 12123321

#include <ntddk.h>

typedef struct _KSERVICE_TABLE_DESCRIPTOR {
	PULONG_PTR Base;
	PULONG Count;
	ULONG Limit;
	PUCHAR Number;
} KSERVICE_TABLE_DESCRIPTOR, * PKSERVICE_TABLE_DESCRIPTOR;

extern PKSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable;

//输入函数名自动获取服务号
#define SYSTEMCALL_INDEX(ServiceFunction) (*(PULONG)((PUCHAR)ServiceFunction + 1))

typedef NTSTATUS(*pfAddr)(
	PHANDLE            ProcessHandle,
	ACCESS_MASK        DesiredAccess,
	POBJECT_ATTRIBUTES ObjectAttributes,
	PCLIENT_ID         ClientId
	);
pfAddr pMyNtOpenProcess = 0;//保存原本的函数地址

//把这个函数替换去SSDT
 NTSTATUS MyZwOpenProcess(
	PHANDLE            ProcessHandle,
	ACCESS_MASK        DesiredAccess,
	POBJECT_ATTRIBUTES ObjectAttributes,
	PCLIENT_ID         ClientId
)
{
	 	 //DbgBreakPoint();
	 DbgPrintEx(77, 0, "ProcessID:%x\r\n", ClientId->UniqueProcess);
	 return pMyNtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId);
}

 //关闭写保护
void PageProtectClose()
{
	__asm
	{
		cli//关闭中断
		mov eax,cr0
		and eax, not 10000h
		mov cr0,eax
	}	
}



//开启写保护
void PageProtectOpen()
{
	__asm
	{
		mov eax,cr0
		or eax,10000h
		mov cr0,eax
		sti
	}
}

VOID DriverUnload(PDRIVER_OBJECT pDriverObject)
{
	DbgBreakPoint();
	PageProtectClose();
	KeServiceDescriptorTable->Base[0xbe] = (ULONG)pMyNtOpenProcess;
	PageProtectOpen();
}

NTSTATUS DriverEntry(PDRIVER_OBJECT pDrvier, PUNICODE_STRING pReg)
{
	PageProtectClose();//关闭页保护
	ULONG uIndex = SYSTEMCALL_INDEX(ZwOpenProcess);
	pMyNtOpenProcess =KeServiceDescriptorTable->Base[uIndex];//保存原本的NtOpenProcess
	KeServiceDescriptorTable->Base[uIndex] = MyZwOpenProcess;//替换NtOpenProcess
	PageProtectOpen();//开启页保护

	pDrvier->DriverUnload = DriverUnload;
	return STATUS_SUCCESS;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值