监控应用层通信_hook_kifastcallentry(系统服务调用)
2017-02-02 00:36
561 查看
#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 sosuohookdiandizhi(); void yebaohuguanbi(); void yebaohukaiqi(); unsigned int lao_ntopenfile;//老的ntopenfile函数的地址 ULONG dizhi1 = 0;//KiFasetCallEntry汇编代码中的 (call ntcreatefile)下一句的地址 ULONG dizhi2 = 0;//KiFasetCallEntry汇编代码中要hook的地址 typedef NTSTATUS(*hanshuzhizhen1)( __out PHANDLE FileHandle, __in ACCESS_MASK DesiredAccess, __in POBJECT_ATTRIBUTES ObjectAttributes, __out PIO_STATUS_BLOCK IoStatusBlock, __in_opt PLARGE_INTEGER AllocationSize, __in ULONG FileAttributes, __in ULONG ShareAccess, __in ULONG CreateDisposition, __in ULONG CreateOptions, __in_bcount_opt(EaLength) PVOID EaBuffer, __in ULONG EaLength ); VOID xiezai1(PDRIVER_OBJECT qudongduixiang) { yebaohuguanbi();//页保护关闭 KeServiceDescriptorTable.ServiceTableBase[66] = (unsigned int)lao_ntopenfile;//还原ntcreatefile yebaohukaiqi();//页保护开启 UCHAR tezhengma[5] = { 0x2b, 0xe1, 0xc1, 0xe9, 0x02 }; yebaohuguanbi();//页保护关闭 RtlCopyMemory((PVOID)dizhi2, tezhengma, 5);//还原kifastcallentry yebaohukaiqi();//页保护开启 KdPrint(("已经执行到驱动卸载历程\n")); } 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 lisaisaide_guolvhanshu(ULONG ServiceTableBase, ULONG NumberOfServices)//李赛赛的过滤函数 注意不要在这里加 __declspec (naked)这个不是汇编代码 注意传过来的参数是ulong类型 { //KdPrint(("进入到我的的过滤函数来了 欧耶 可以监控应用层传过来的请求(调用nt函数的信息)\n")); if (ServiceTableBase == (ULONG)KeServiceDescriptorTable.ServiceTableBase) { if (NumberOfServices==190) { KdPrint(("看那些进入KiFasetCallEntry调用ntopenkey进程名是%s\n", (char*)PsGetCurrentProcess() + 0x16c)); } } } __declspec (naked) VOID lisaisaide_KiFasetCallEntry()//李赛赛的KiFasetCallEntry { __asm { pushad pushfd push eax push edi call lisaisaide_guolvhanshu //调用我们的过滤函数 popfd popad pop eax sub esp,ecx //call lisaisaide_KiFasetCallEntry 替换掉的5个字节的代码 shr ecx,2 jmp eax } } VOID hook_KiFasetCallEntry()//inlinehookKiFasetCallEntry { ULONG pianyi1 = 0; UCHAR tezhengma[5]; pianyi1 = (ULONG)lisaisaide_KiFasetCallEntry - 5 - dizhi2; tezhengma[0] = 0xe8; *(ULONG*)&tezhengma[1] = pianyi1; //KdPrint(("李赛赛的KiFasetCallEntry地址%x 计算出来的 偏移%x\n", (ULONG)lisaisaide_KiFasetCallEntry, pianyi1)); yebaohuguanbi();//页保护关闭 RtlCopyMemory((PVOID)dizhi2, tezhengma, 5);//inlinehook_KiFasetCallEntry yebaohukaiqi();//页保护开启 } NTSTATUS lisaisaide_NtCreateFile( //李赛赛的_NtCreateFile函数 __out PHANDLE FileHandle, __in ACCESS_MASK DesiredAccess, __in POBJECT_ATTRIBUTES ObjectAttributes, __out PIO_STATUS_BLOCK IoStatusBlock, __in_opt PLARGE_INTEGER AllocationSize, __in ULONG FileAttributes, __in ULONG ShareAccess, __in ULONG CreateDisposition, __in ULONG CreateOptions, __in_bcount_opt(EaLength) PVOID EaBuffer, __in ULONG EaLength ) { __asm { pushad mov eax, [ebp + 0x4] mov dizhi1, eax popad } //KdPrint(("通过内核栈得到地址call ebx下一句的地址%x\n", dizhi1));//得到地址正确 sosuohookdiandizhi();//搜索hook KiFastCallEntry //yebaohuguanbi();//页保护关闭 //KeServiceDescriptorTable.ServiceTableBase[66] = (unsigned int)lao_ntopenfile;//还原ntcreatefile //yebaohukaiqi();//页保护开启 hook_KiFasetCallEntry(); //开始hook return ((hanshuzhizhen1)lao_ntopenfile)(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, AllocationSize, FileAttributes, ShareAccess, CreateDisposition, CreateOptions, EaBuffer, EaLength); } ULONG sosuohookdiandizhi()//搜索hook KiFastCallEntry { UCHAR *p = (UCHAR *)dizhi1; for (ULONG i = 0; i < 300;i++) { if (*p==0x2b&&*(p+1)==0xe1&&*(p+2)==0xc1&&*(p+3)==0xe9&&*(p+4)==0x02) { //KdPrint(("找到地址kifastcallentry的hook点地址 %x\n",(ULONG)p)); dizhi2 = (ULONG)p; return (ULONG)p; } p--; } //KdPrint(("没有找到hook点的地址%x 是错误的", (ULONG)p)); return 0; } NTSTATUS DriverEntry(PDRIVER_OBJECT qudongduixiang,PUNICODE_STRING zhucebiao) { lao_ntopenfile = KeServiceDescriptorTable.ServiceTableBase[66];//保存老的ntopenfile函数地址 yebaohuguanbi();//页保护关闭 KeServiceDescriptorTable.ServiceTableBase[66] = (unsigned int)lisaisaide_NtCreateFile;//ssdthook_ntopenfile 属于ssdthook yebaohukaiqi();//页保护开启 qudongduixiang->DriverUnload = xiezai1; return STATUS_SUCCESS; }
相关文章推荐
- iOS8中,程序接收不到应用调用系统服务提示的解决方案
- 上层应用调用自定义的系统服务注意事项
- 例说linux内核与应用数据通信(一):添加一个系统调用
- android应用与服务的通信之学生查询系统案例源码
- Windows系统调用架构分析—也谈KiFastCallEntry函数地址的获取 + 一个hook的实现
- 如何用Google APIs和Google的应用系统进行集成(3)----调用Google 发现(Discovery)API的RESTful服务
- 例说linux内核与应用数据通信(一):加入一个系统调用
- Android系统篇之----Hook系统的AMS服务实现应用启动的拦截功能
- ESB v6.6 关于“应用系统中增加账号及密码配置后,对应服务调用时允许进行账号及密码认证功能”
- 系统服务开发汇总iOS开发系列--调用系统应用
- 怎样用Google APIs和Google的应用系统进行集成(3)----调用Google 发现(Discovery)API的RESTful服务
- 用C#开发Windows服务监控系统使用
- 工作流管理在自来水营销管理系统(客户服务中心)中的应用(原创)
- 剖析Windows系统服务调用机制
- Select()系统调用及文件描述符集fd_set的应用
- Windows 系统调用.COM.微软语言引擎简单应用(C#)
- 剖析Windows系统服务调用机制
- Hook 系统服务隐藏端口
- 剖析Windows系统服务调用机制
- windows 系统调用.WinAPI.直接绘制屏幕的应用.实列.CS屏幕中心点作弊器(1.6匪徒连狙专用)