首页
社区
课程
招聘
[讨论]ntopenprocess inlinehook之后能还原 卸载吗
发表于: 2017-7-27 19:55 2825

[讨论]ntopenprocess inlinehook之后能还原 卸载吗

2017-7-27 19:55
2825

ntopenprocess inlinehook  之后 不能卸载  恢复吗   恢复之后会蓝屏  是吗 能恢复吗 

win7的182号  ntraiseharderror 能恢复

换成  ntopenprocess 不行了

2017/07/27 时间测试成功

下面把代码发给大家 研究

#include"ntddk.h"  
#pragma pack(1) //写这个内存以一字节对齐 如果不写是以4字节的对齐的    
typedef struct ServiceDescriptorEntry {//这个结构就是为了管理这个数组而来的 内核api所在的数组 才有这个结构的 这个是ssdt    
	unsigned int *ServiceTableBase;//就是ServiceTable ssdt数组    
	unsigned int *ServiceCounterTableBase; //仅适用于checked build版本 无用    
	unsigned int NumberOfServices;//(ServiceTableBase)数组中有多少个元素 有多少个项    
	unsigned char *ParamTableBase;//参数表基址 我们层传过来的api的参数 占用多少字节 多大    
} ServiceDescriptorTableEntry_t, *PServiceDescriptorTableEntry_t;
#pragma pack(1)    
_declspec(dllimport) ServiceDescriptorTableEntry_t KeServiceDescriptorTable;//(名字不要写错)  //导入ssdt表  
ULONG lao_ntopkey;
UCHAR tezhengma2[5];
void yebaohuguanbi()//页保护关闭    
{
	__asm{//去掉内存保护    
		cli
			mov  eax, cr0
			and  eax, not 10000h
			mov  cr0, eax
	}
}
void yebaohukaiqi()//页保护开启    
{
	__asm{//恢复内存保护      
		mov  eax, cr0
			or   eax, 10000h
			mov  cr0, eax
			sti
	}
}
VOID xiezai1(PDRIVER_OBJECT qudongduixiang)
{
	yebaohuguanbi();//页保护关闭    
	RtlCopyMemory((PVOID)lao_ntopkey, tezhengma2, 5);//把现在inline hook后 的代码还原   
	yebaohukaiqi();//页保护开启    
	KdPrint(("驱动卸载历程 已经执行\n"));
}
void guolvlicheng()
{
	KdPrint(("进入到我的过滤历程来了 当前进程%s\n", (char*)PsGetCurrentProcess() + 0x16c));
}
_declspec(naked)
void lisaisaide_ntopenkey()//我的ntopenkey  
{
	__asm
	{
		call guolvlicheng //直接call 这个函数 不用转换  
			pop eax
			push 0xc4
			jmp eax               //测试下 看会蓝屏吗  
	}
}
void inline_hook_ntopenkey()
{
	unsigned int wodehanshudizhi1 = (unsigned int)&lisaisaide_ntopenkey;
	UCHAR tezhengma1[5];
	ULONG pianyi1 = 0;//call wodehanshudizhi1 的特征码 就是e8后面跟的便宜  
	tezhengma1[0] = 0xe8;
	pianyi1 = wodehanshudizhi1 - 5 - lao_ntopkey;//lao_ntopkey就是od反汇编 最前面的地址  
	*(ULONG*)&tezhengma1[1] = pianyi1;//特征码计算完毕  
	yebaohuguanbi();//页保护关闭   //拷贝内存的时候关开  
	RtlCopyMemory(tezhengma2, (PVOID)lao_ntopkey, 5);
	RtlCopyMemory((PVOID)lao_ntopkey, tezhengma1, 5);//5个字节的特征码 拷贝到原始ssdt的ntopenkey函数的汇编代码 改写  
	yebaohukaiqi();//页保护开启    
}
NTSTATUS DriverEntry(PDRIVER_OBJECT qudongduixiang, PUNICODE_STRING zhucebiao)
{
	lao_ntopkey = KeServiceDescriptorTable.ServiceTableBase[122];//系统老的nt_openkey  
	inline_hook_ntopenkey();
	qudongduixiang->DriverUnload = xiezai1;
	return STATUS_SUCCESS;
}

QQ群582865430 过游戏驱动保护 研究 修改内核 写外挂 交流


[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

最后于 2018-8-17 16:44 被神大蛇编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 12848
活跃值: (9108)
能力值: ( LV9,RANK:280 )
在线值:
发帖
回帖
粉丝
2

我觉得问题不在于不能卸载  而在于你恢复钩子之后驱动马上被unload了,然而cpu还在你的钩子函数里跑,当然会爆炸了
解决方法就是unload驱动的时候Sleep个几秒等你的钩子函数完全跑完(这是偷懒方法,逃)

2017-7-27 22:20
0
雪    币: 436
活跃值: (111)
能力值: ( LV7,RANK:110 )
在线值:
发帖
回帖
粉丝
3
增加引用计数,  卸载时比较引用计数  _(:з)∠)_
2017-7-28 10:00
0
游客
登录 | 注册 方可回帖
返回
//