本帖最后由 aswcy815174418 于 2021-9-6 00:21 编辑
测试环境:Windows XP SP3 32位
效果看图片
代码如下:
[C] 纯文本查看 复制代码 #include "ntifs.h"
#define i 0x101
#define PROCESS_NAME "notepad.exe"
typedef struct _SERVICE_TABLE {
ULONG* FunAddr;
ULONG Count;
ULONG ServiceLimit;
UCHAR* ParaSize;
}SERVICE_TABLE,*PSERVICE_TABLE;
typedef struct _SERVICE_TABLE_ENTANCE {
SERVICE_TABLE Blue_Table;
SERVICE_TABLE Yellow_Table;
SERVICE_TABLE Reserve1;
SERVICE_TABLE Reserve2;
}SERVICE_TABLE_ENTANCE;
__declspec(dllimport) SERVICE_TABLE_ENTANCE KeServiceDescriptorTable;
typedef UCHAR* (*pGetName)(__in PEPROCESS Process);
typedef NTSTATUS(*pfun)(HANDLE ProcessHandle, NTSTATUS ExitStatus);
ULONG HookAddr;
NTSTATUS HOOK(HANDLE ProcessHandle, NTSTATUS ExitStatus,...) {
pfun NtTerminateProcess = (pfun)HookAddr;
NTSTATUS status;
PEPROCESS pEProcess;
//有这两个条件就是自己关闭的,非任务管理器
if (ProcessHandle == 0|| ProcessHandle==-1) {
return NtTerminateProcess(ProcessHandle, ExitStatus);
}
try{
//我去windbg获取的这个函数地址,直接贴了,没遍历获取
pGetName PsGetProcessImageFileName = (pGetName)0x80528784;
status = ObReferenceObjectByHandle(ProcessHandle, FILE_READ_DATA, NULL, KernelMode, &pEProcess, NULL);
UCHAR* str = PsGetProcessImageFileName(pEProcess);
if (!strcmp(str, PROCESS_NAME)) {
DbgPrint("拦截到%s", str);
return STATUS_ACCESS_DENIED;
}
}
except (1){
return NtTerminateProcess(ProcessHandle, ExitStatus);
}
return NtTerminateProcess(ProcessHandle, ExitStatus);
}
NTSTATUS CancelHOOK() {
KeServiceDescriptorTable.Blue_Table.FunAddr[i] = HookAddr;
return STATUS_SUCCESS;
}
NTSTATUS Unload(PDRIVER_OBJECT pDriver) {
CancelHOOK();
DbgPrint("已经卸载");
return STATUS_SUCCESS;
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver, PUNICODE_STRING ppath) {
pDriver->DriverUnload = Unload;
HookAddr = KeServiceDescriptorTable.Blue_Table.FunAddr[i];
KeServiceDescriptorTable.Blue_Table.FunAddr[i] = HOOK;
DbgPrint("%x %x", HookAddr,HOOK);
return STATUS_SUCCESS;
}
|