看流星社区

 找回密码
 注册账号
查看: 4798|回复: 1

过HS多开源码,直接HOOK KiFastCallEntry改函数R3注入。

[复制链接]

该用户从未签到

发表于 2013-2-13 17:26:31 | 显示全部楼层 |阅读模式

  1. #pragma once
  2. #ifndef DUOKAI_H
  3. #define DUOKAI_H

  4. #ifndef __cplusplus
  5. extern "C"
  6. {
  7. #endif
  8.   #include <ntddk.h>
  9.   #include <windef.h>
  10.   #include <string.h>
  11. #ifndef __cplusplus
  12. };
  13. #endif

  14. #define _device_name L"\\device\\device_name"
  15. #define _symbol_name L"\\??\\symbol_name"

  16. #define PAGEDCODE code_seg("PAGED")
  17. #define LOCKEDCODE code_seg()
  18. #define INITCODE code_seg("INIT")

  19. #define PAGEDDATA data_seg("PAGED")
  20. #define LOCKEDDATA data_seg()
  21. #define INITDATA data_seg("INIT")

  22. typedef struct _DEVICE_EXTENSION
  23. {
  24.   UNICODE_STRING device_name;
  25.   UNICODE_STRING symbol_name;
  26.   PDEVICE_OBJECT device_object;
  27. }DEVICE_EXTENSION,*PDEVICE_EXTENSION;

  28. VOID DriverUnLoad(PDRIVER_OBJECT driver);
  29. NTSTATUS DispatchIrp(PDEVICE_OBJECT driver,PIRP irp);
  30. VOID Get_Version(PDRIVER_OBJECT driver);
  31. VOID GetCall_addr();

  32. VOID GetKiFastCallEntry();
  33. VOID Hook_KiFastCallEntry();
  34. VOID My_KiFastCallEntry();
  35. VOID Un_KiFastCallEntry();
  36. extern "C"
  37. typedef
  38. NTSYSCALLAPI NTSTATUS NTAPI typedef_NtOpenProcess  ( __out PHANDLE  ProcessHandle,  
  39.                       __in ACCESS_MASK  DesiredAccess,  
  40.                       __in POBJECT_ATTRIBUTES  ObjectAttributes,  
  41.                       __in_opt PCLIENT_ID  ClientId   
  42.                       ) ;
  43. typedef_NtOpenProcess* t_NtOpenProcess;
  44. extern "C"
  45. typedef
  46. NTSYSCALLAPI NTSTATUS NTAPI typedef_NtReadVirtualMemory  ( __in HANDLE  ProcessHandle,  
  47.                           __in_opt PVOID  BaseAddress,  
  48.                           __out_bcount(BufferSize) PVOID  Buffer,  
  49.                           __in SIZE_T  BufferSize,  
  50.                           __out_opt PSIZE_T  NumberOfBytesRead   
  51.                           ) ;
  52. typedef_NtReadVirtualMemory* t_NtReadVirtualMemory;
  53. extern "C"
  54. typedef
  55. NTSYSCALLAPI NTSTATUS NTAPI typedef_NtWriteVirtualMemory  ( __in HANDLE  ProcessHandle,  
  56.                            __in_opt PVOID  BaseAddress,  
  57.                            __in_bcount(BufferSize) CONST VOID *  Buffer,  
  58.                            __in SIZE_T  BufferSize,  
  59.                            __out_opt PSIZE_T  NumberOfBytesWritten   
  60.                            ) ;
  61. typedef_NtWriteVirtualMemory* t_NtWriteVirtualMemory;
  62. #endif
  63. //-------------------------------------------------------------
  64. #include "duokai.h"
  65. #include "hook.h"
  66. #include "KiFastCallEntry.h"

  67. #pragma PAGEDCODE
  68. extern "C" NTSTATUS DriverEntry(PDRIVER_OBJECT driver,PUNICODE_STRING un_string)
  69. {
  70.   //////////////////////////////////////////////////////////////////////////
  71.   Get_Version(driver);
  72.   hook_NtCreateMutant();
  73.   hook_NtOpenMutant();
  74.   //------------------注入支持
  75. //  GetCall_addr();
  76. //  GetKiFastCallEntry();
  77. //  Hook_KiFastCallEntry();
  78.   //-----------------------------
  79.   NTSTATUS status=STATUS_SUCCESS;
  80.   driver->MajorFunction[IRP_MJ_CREATE]=DispatchIrp;
  81.   driver->MajorFunction[IRP_MJ_CLOSE]=DispatchIrp;
  82.   driver->MajorFunction[IRP_MJ_READ]=DispatchIrp;
  83.   driver->MajorFunction[IRP_MJ_WRITE]=DispatchIrp;
  84.   driver->MajorFunction[IRP_MJ_DEVICE_CONTROL]=DispatchIrp;
  85.   driver->DriverUnload=DriverUnLoad;

  86.   PDEVICE_EXTENSION deviceextension;
  87.   UNICODE_STRING device_name;
  88.   RtlInitUnicodeString(&device_name,_device_name);

  89.   PDEVICE_OBJECT device_object;
  90.   status=IoCreateDevice(driver,sizeof(deviceextension),&device_name,FILE_DEVICE_UNKNOWN,NULL,FALSE,&device_object);
  91.   if(!NT_SUCCESS(status))
  92.   {
  93.     KdPrint(("创建设备失败!\n"));
  94.     return status;
  95.   }
  96.   KdPrint(("创建设备成功!\n"));

  97.   device_object->Type |= DO_BUFFERED_IO;
  98.   deviceextension=(PDEVICE_EXTENSION)device_object->DeviceExtension;
  99.   deviceextension->device_name=device_name;
  100.   deviceextension->device_object=device_object;

  101.   UNICODE_STRING symbol_object;
  102.   RtlInitUnicodeString(&symbol_object,_symbol_name);
  103.   deviceextension->symbol_name=symbol_object;
  104.   status=IoCreateSymbolicLink(&symbol_object,&device_name);
  105.   if(!NT_SUCCESS(status))
  106.   {
  107.     KdPrint(("创建符号链接失败!\n"));
  108.     IoDeleteDevice(device_object);
  109.     return status;
  110.   }
  111.   KdPrint(("创建符号链接成功!\n"));
  112.   return STATUS_SUCCESS;
  113. }

  114. #pragma PAGEDCODE
  115. VOID DriverUnLoad(PDRIVER_OBJECT driver)
  116. {
  117.   PDEVICE_OBJECT driver_object;
  118.   driver_object=driver->DeviceObject;
  119.   while(driver_object!=NULL)
  120.   {
  121.     PDEVICE_EXTENSION deviceextension=(PDEVICE_EXTENSION)driver_object->DeviceExtension;
  122.     UNICODE_STRING symbol_name=deviceextension->symbol_name;
  123.     IoDeleteSymbolicLink(&symbol_name);
  124.     driver_object=driver_object->NextDevice;
  125.     IoDeleteDevice(deviceextension->device_object);
  126.   }
  127.   //------------------------
  128.   UNhook_NtCreateMutant();
  129.   Unhook_NtOpenMutant();
  130. //  Un_KiFastCallEntry();
  131.   KdPrint(("删除设备成功!\n"));
  132. }

  133. #pragma PAGEDCODE
  134. NTSTATUS DispatchIrp(PDEVICE_OBJECT driver,PIRP irp)
  135. {
  136.   irp->IoStatus.Status=STATUS_SUCCESS;
  137.   irp->IoStatus.Information=0;
  138.   IoCompleteRequest(irp,IO_NO_INCREMENT);
  139.   return STATUS_SUCCESS;
  140. }
  141. //---------------------------------------------------------------------
  142. #pragma once
  143. #ifndef HOOK_H
  144. #define HOOK_H

  145. #define Version_win7   61
  146. #define Version_2008   60
  147. #define Version_xp     51
  148. //---------------------------------
  149. ULONG u_NtCreateMutant;   //保存CreateMutant的地址
  150. ULONG u_NtOpenMutant;     //保存NtOpenMutant的地址
  151. int in_NtOpenThread;          //保存NtOpenThread的序号
  152. int in_NtOpenProcess;        //保存NtOpenprocess的序号
  153. int in_NtReadVirtualMemory;  //保存NtReadVirtualMemory的序号
  154. int in_NtWriteVirtualMemory; //保存NtWriteVirtualMemory的序号
  155. //-------------------------------
  156. ULONG addr_NtOpenThread;
  157. ULONG push0_addr_NtOpenProcess;
  158. ULONG push_addr_NtOpenProecss;
  159. ULONG call_addr_NtOpenProecss;   //保存NtOpenProcess的call地址
  160. ULONG addr_NtOpenProecss;
  161. BYTE push0_addr_NtReadVirtualMemory;
  162. ULONG push_addr_NtReadVirtualMemory;
  163. ULONG call_addr_NtReadVirtualMemory;
  164. ULONG addr_NtReadVirtualMemory;
  165. BYTE push0_addr_NtWriteVirtualMemory;
  166. ULONG push_addr_NtWriteVirtualMemory;
  167. ULONG call_addr_NtWriteVirtualMemory;
  168. ULONG addr_NtWriteVirtualMemory;

  169. typedef struct _ServiceDescriptorTable {
  170.   PVOID ServiceTableBase; //System Service Dispatch Table 的基地址  
  171.   PVOID ServiceCounterTable;
  172.   //包含着 SSDT 中每个服务被调用次数的计数器。这个计数器一般由sysenter 更新。
  173.   unsigned int NumberOfServices;//由 ServiceTableBase 描述的服务的数目。  
  174.   PVOID ParamTableBase; //包含每个系统服务参数字节数表的基地址-系统服务参数表
  175. }*PServiceDescriptorTable;  
  176. extern "C" extern PServiceDescriptorTable KeServiceDescriptorTable;

  177. #pragma pack(1)
  178. typedef struct jmp_code
  179. {
  180.   BYTE e9;
  181.   ULONG jmpaddr;
  182. }_jmpcode,*pjmpcode;
  183. #pragma pack()

  184. #pragma PAGEDCODE
  185. ULONG* Getssdt_this(int index)
  186. {
  187.   ULONG* Get_Funaddr,GetFun;
  188.   GetFun=(ULONG)KeServiceDescriptorTable->ServiceTableBase;
  189.   KdPrint(("SSDT表的地址为:%x\n",GetFun));
  190.   Get_Funaddr=(PULONG)(GetFun+index*4);
  191.   KdPrint(("---序号=%d,地址=%x",index,Get_Funaddr));
  192.   return Get_Funaddr;
  193. }

  194. #pragma PAGEDCODE
  195. ULONG Getssdt_addr(int index)
  196. {
  197.   ULONG* Get_Funaddr,GetFun,addr_GetFun;
  198.   GetFun=(ULONG)KeServiceDescriptorTable->ServiceTableBase;
  199.   KdPrint(("SSDT表的地址为:%x\n",GetFun));
  200.   Get_Funaddr=(PULONG)(GetFun+index*4);
  201.   KdPrint(("---序号=%d,地址=%x",index,Get_Funaddr));
  202.   addr_GetFun=*Get_Funaddr;
  203.   KdPrint(("地址为:%x",addr_GetFun));
  204.   return addr_GetFun;
  205. }

  206. KIRQL kirql;
  207. #pragma PAGEDCODE
  208. VOID PAGED_Open()
  209. {
  210.   __asm
  211.   {
  212.     cli
  213.     push eax
  214.     mov eax,cr0
  215.     and eax,not 10000h
  216.     mov cr0,eax
  217.     pop eax
  218.   }
  219.   kirql=KeRaiseIrqlToDpcLevel();
  220. }

  221. #pragma PAGEDCODE
  222. VOID PAGED_Exit()
  223. {
  224.   KeLowerIrql(kirql);
  225.   __asm
  226.   {
  227.     push eax
  228.     mov eax,cr0
  229.     or eax,10000h
  230.     mov cr0,eax
  231.     pop eax
  232.     sti
  233.   }
  234. }


  235. #pragma PAGEDCODE
  236. VOID Get_Version(PDRIVER_OBJECT driver)
  237. {
  238.   ULONG MajorVersion,MinorVersion,BuildVersion;
  239.   PsGetVersion(&MajorVersion,&MinorVersion,&BuildVersion,NULL);
  240.   DWORD dw_version=MajorVersion*10+MinorVersion;
  241.   switch(dw_version)
  242.   {
  243.   case Version_xp:
  244.     KdPrint(("当前操作系统windows xp......\n"));
  245.     in_NtOpenThread=0x80;
  246.     in_NtOpenProcess=0x7A;
  247.     in_NtReadVirtualMemory=0xBA;
  248.     in_NtWriteVirtualMemory=0x115;
  249.     break;
  250.   default:
  251.     driver->DriverUnload=DriverUnLoad;
  252.     break;
  253.   }
  254. }
  255. //////////////////////////////////////////////////////////////////////////

  256. extern "C"
  257. typedef
  258. NTSYSAPI
  259. NTSTATUS
  260. (__stdcall *Nt_CreateMutant)(
  261.          OUT PHANDLE MutantHandle,
  262.          IN ACCESS_MASK DesiredAccess,
  263.          IN POBJECT_ATTRIBUTES ObjectAttributes,
  264.          IN BOOLEAN InitialOwner
  265.          );
  266. Nt_CreateMutant* nt_CreateMutant;

  267. static unsigned int i=0;
  268. #pragma PAGEDCODE
  269. extern "C"
  270. NTSTATUS
  271. __stdcall
  272. My_NtCreateMutant(
  273.         OUT PHANDLE MutantHandle,
  274.         IN ACCESS_MASK DesiredAccess,
  275.         IN POBJECT_ATTRIBUTES ObjectAttributes,
  276.         IN BOOLEAN InitialOwner
  277.          )
  278. {
  279.   if(ObjectAttributes!=NULL && ObjectAttributes->ObjectName!=NULL && ObjectAttributes->ObjectName->Buffer!=NULL)
  280.   {
  281.     KdPrint(("互斥体名为:%wZ\r\n",ObjectAttributes->ObjectName));
  282.     UNICODE_STRING Mutant_name_Create;
  283.     RtlInitUnicodeString(&Mutant_name_Create,L"WvsClientMtx");
  284.     if(ObjectAttributes && RtlEqualUnicodeString(&Mutant_name_Create,ObjectAttributes->ObjectName,FALSE))
  285.     {
  286.       KdPrint(("hook CreateMutant成功!\r\n"));
  287.       i++;
  288.       UNICODE_STRING un_game_mutex;
  289.       switch(i)
  290.       {
  291.       case 0:
  292. //由于内核下不知道怎么随机字符所以出现了如此情景,汇编写麻烦所以直接就
  293.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx");
  294.         break;
  295.       case 1:
  296.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx1");
  297.         break;
  298.       case 2:
  299.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx2");
  300.         break;
  301.       case 3:
  302.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx3");
  303.         break;
  304.       case 4:
  305.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx4");
  306.         break;
  307.       case 5:
  308.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx5");
  309.         break;
  310.       case 6:
  311.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx6");
  312.         break;
  313.       case 7:
  314.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx7");
  315.         break;
  316.       case 8:
  317.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx8");
  318.         break;
  319.       case 9:
  320.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMtx9");
  321.         break;
  322.       case 10:
  323.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt10");
  324.         break;
  325.       case 11:
  326.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt11");
  327.         break;
  328.       case 12:
  329.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt12");
  330.         break;
  331.       case 13:
  332.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt13");
  333.         break;
  334.       case 14:
  335.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt14");
  336.         break;
  337.       case 15:
  338.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt15");
  339.         break;
  340.       case 16:
  341.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt16");
  342.         break;
  343.       case 17:
  344.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt17");
  345.         break;
  346.       case 18:
  347.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt18");
  348.         break;
  349.       case 19:
  350.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt19");
  351.         break;
  352.       case 20:
  353.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt20");
  354.         break;
  355.       case 21:
  356.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt21");
  357.         break;
  358.       case 22:
  359.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt22");
  360.         break;
  361.       case 23:
  362.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt23");
  363.         break;
  364.       case 24:
  365.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt24");
  366.         break;
  367.       case 25:
  368.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt25");
  369.         break;
  370.       case 26:
  371.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt26");
  372.         break;
  373.       case 27:
  374.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt27");
  375.         break;
  376.       case 28:
  377.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt28");
  378.         break;
  379.       case 29:
  380.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt29");
  381.         break;
  382.       case 30:
  383.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt30");
  384.         break;
  385.       case 31:
  386.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt31");
  387.         break;
  388.       case 32:
  389.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt32");
  390.         break;
  391.       case 33:
  392.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt33");
  393.         break;
  394.       case 34:
  395.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt34");
  396.         break;
  397.       case 35:
  398.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt35");
  399.         break;
  400.       case 36:
  401.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt36");
  402.         break;
  403.       case 37:
  404.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt37");
  405.         break;
  406.       case 38:
  407.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt38");
  408.         break;
  409.       case 39:
  410.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt39");
  411.         break;
  412.       case 40:
  413.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt40");
  414.         break;
  415.       case 41:
  416.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt41");
  417.         break;
  418.       case 42:
  419.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt42");
  420.         break;
  421.       case 43:
  422.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt43");
  423.         break;
  424.       case 44:
  425.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt44");
  426.         break;
  427.       case 45:
  428.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt45");
  429.         break;
  430.       case 46:
  431.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt46");
  432.         break;
  433.       case 47:
  434.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt47");
  435.         break;
  436.       case 48:
  437.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt48");
  438.         break;
  439.       case 49:
  440.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt49");
  441.         break;
  442.       case 50:
  443.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt50");
  444.         break;
  445.       case 51:
  446.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt51");
  447.         break;
  448.       case 52:
  449.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt52");
  450.         break;
  451.       case 53:
  452.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt53");
  453.         break;
  454.       case 54:
  455.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt54");
  456.         break;
  457.       case 55:
  458.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt55");
  459.         break;
  460.       case 56:
  461.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt56");
  462.         break;
  463.       case 57:
  464.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt57");
  465.         break;
  466.       case 58:
  467.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt58");
  468.         break;
  469.       case 59:
  470.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt59");
  471.         break;
  472.       case 60:
  473.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt60");
  474.         break;
  475.       case 61:
  476.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt61");
  477.         break;
  478.       case 62:
  479.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt62");
  480.         break;
  481.       case 63:
  482.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt63");
  483.         break;
  484.       case 64:
  485.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt64");
  486.         break;
  487.       case 65:
  488.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt65");
  489.         break;
  490.       case 66:
  491.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt66");
  492.         break;
  493.       case 67:
  494.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt67");
  495.         break;
  496.       case 68:
  497.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt68");
  498.         break;
  499.       case 69:
  500.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt69");
  501.         break;
  502.       case 70:
  503.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt70");
  504.         break;
  505.       case 71:
  506.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt71");
  507.         break;
  508.       case 72:
  509.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt72");
  510.         break;
  511.       case 73:
  512.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt73");
  513.         break;
  514.       case 74:
  515.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt74");
  516.         break;
  517.       case 75:
  518.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt75");
  519.         break;
  520.       case 76:
  521.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt76");
  522.         break;
  523.       case 77:
  524.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt77");
  525.         break;
  526.       case 78:
  527.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt78");
  528.         break;
  529.       case 79:
  530.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt79");
  531.         break;
  532.       case 80:
  533.         RtlInitUnicodeString(&un_game_mutex,L"WvsClientMt80");
  534.         break;
  535.       default:
  536.         i=0;
  537.         break;
  538.       }
  539.       RtlCopyUnicodeString(ObjectAttributes->ObjectName,&un_game_mutex);
  540.       return ((NTSTATUS(NTAPI*)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,BOOLEAN))nt_CreateMutant)(MutantHandle,DesiredAccess,ObjectAttributes,InitialOwner);
  541.     }
  542.   }
  543.   return ((NTSTATUS(NTAPI*)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,BOOLEAN))nt_CreateMutant)(MutantHandle,DesiredAccess,ObjectAttributes,InitialOwner);
  544. }

  545. #pragma INITCODE
  546. VOID hook_NtCreateMutant()
  547. {
  548.   ULONG* un_NtCreateMutant;
  549.   un_NtCreateMutant=Getssdt_this(0x2B);
  550.   u_NtCreateMutant=Getssdt_addr(0x2B);
  551.   KdPrint(("当前SSDT表中NtCreateMutant的地址为:%x",u_NtCreateMutant));
  552.   nt_CreateMutant=(Nt_CreateMutant*)u_NtCreateMutant;
  553.   PAGED_Open();
  554.   *un_NtCreateMutant=(ULONG)My_NtCreateMutant;
  555.   PAGED_Exit();
  556. }

  557. #pragma PAGEDCODE
  558. VOID UNhook_NtCreateMutant()
  559. {
  560.   ULONG ntcreatemutant;
  561.   ntcreatemutant=(ULONG)KeServiceDescriptorTable->ServiceTableBase+0x2B*4;
  562.   PAGED_Open();
  563.   *((ULONG*)ntcreatemutant)=(ULONG)u_NtCreateMutant;
  564.   PAGED_Exit();
  565. }

  566. extern "C"
  567. typedef
  568. NTSYSAPI
  569. NTSTATUS
  570. (__stdcall *Nt_OpenMutant)(
  571.        OUT PHANDLE MutantHandle,
  572.        IN ACCESS_MASK DesiredAccess,
  573.        IN POBJECT_ATTRIBUTES ObjectAttributes
  574.        );
  575. Nt_OpenMutant* nt_openmutant;

  576. #pragma PAGEDCODE
  577. extern "C"
  578. NTSTATUS
  579. __stdcall
  580. My_NtOpenMutant(
  581.         OUT PHANDLE MutantHandle,
  582.         IN ACCESS_MASK DesiredAccess,
  583.         IN POBJECT_ATTRIBUTES ObjectAttributes
  584.        )
  585. {
  586.   if(ObjectAttributes!=NULL && ObjectAttributes->ObjectName!=NULL && ObjectAttributes->ObjectName->Buffer!=NULL)
  587.   {
  588.     KdPrint(("互斥体为为:%wZ\r\n",ObjectAttributes->ObjectName));
  589.     UNICODE_STRING Mutant_name_Open;
  590.     RtlInitUnicodeString(&Mutant_name_Open,L"DBWinMutex");
  591.     if(ObjectAttributes && RtlEqualUnicodeString(&Mutant_name_Open,ObjectAttributes->ObjectName,FALSE))
  592.     {
  593.       KdPrint(("hook OpenMutant成功!\r\n"));
  594.       return STATUS_SUCCESS;
  595.     }
  596.   }
  597.   return ((NTSTATUS(NTAPI*)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES))nt_openmutant)(MutantHandle,DesiredAccess,ObjectAttributes);
  598. }

  599. #pragma INITCODE
  600. VOID hook_NtOpenMutant()
  601. {
  602.   ULONG* un_NtOpenMutant;
  603.   un_NtOpenMutant=Getssdt_this(0x78);
  604.   u_NtOpenMutant=Getssdt_addr(0x78);
  605.   KdPrint(("当前系统NtOpenMutant的地址为:%x\n",u_NtOpenMutant));
  606.   nt_openmutant=(Nt_OpenMutant*)u_NtOpenMutant;
  607.   PAGED_Open();
  608.   *un_NtOpenMutant=(ULONG)My_NtOpenMutant;
  609.   PAGED_Exit();
  610. }

  611. #pragma PAGEDCODE
  612. VOID Unhook_NtOpenMutant()
  613. {
  614.   ULONG ntopenmutant;
  615.   ntopenmutant=(ULONG)KeServiceDescriptorTable->ServiceTableBase+0x78*4;
  616.   PAGED_Open();
  617.   *((ULONG*)ntopenmutant)=(ULONG)u_NtOpenMutant;
  618.   PAGED_Exit();

  619. }

  620. #pragma PAGEDCODE
  621. VOID GetCall_addr()
  622. {
  623.   addr_NtOpenThread=Getssdt_addr(in_NtOpenThread);
  624.   addr_NtOpenThread+=0xA;
  625.   __asm
  626.   {
  627.     push eax
  628.     push ebx
  629.     mov eax,addr_NtOpenThread
  630.     mov ebx,[eax+1]
  631.     add eax,ebx
  632.     add eax,5
  633.     mov call_addr_NtOpenProecss,eax
  634.     pop ebx
  635.     pop eax
  636.   }
  637.   KdPrint(("NtOpenProess的call地址为:%x\n",call_addr_NtOpenProecss));
  638.   call_addr_NtReadVirtualMemory=call_addr_NtOpenProecss;
  639.   KdPrint(("NtReadVirtualMemory的call地址为:%x\n",call_addr_NtReadVirtualMemory));
  640.   call_addr_NtWriteVirtualMemory=call_addr_NtOpenProecss;
  641.   KdPrint(("NtWriteVirtualMemory的call地址为:%x\n",call_addr_NtWriteVirtualMemory));
  642.   push_addr_NtOpenProecss=Getssdt_addr(in_NtOpenProcess);
  643.   addr_NtOpenProecss=push_addr_NtOpenProecss;
  644.   t_NtOpenProcess=(typedef_NtOpenProcess*)push_addr_NtOpenProecss;
  645.   __asm
  646.   {
  647.     push eax
  648.     mov eax,push_addr_NtOpenProecss
  649.     add eax,1
  650.     mov eax,[eax]
  651.     mov push0_addr_NtOpenProcess,eax
  652.     pop eax
  653.   }
  654.   KdPrint(("NtOpenProecss的第一个push地址为:%x\n",push0_addr_NtOpenProcess));
  655.   __asm
  656.   {
  657.     push eax
  658.     mov eax,push_addr_NtOpenProecss
  659.     add eax,5
  660.     add eax,1
  661.     mov eax,[eax]
  662.     mov push_addr_NtOpenProecss,eax
  663.     pop eax
  664.   }
  665.   KdPrint(("NtOpenProcess的第二个push地址为:%x\n",push_addr_NtOpenProecss));
  666.   push_addr_NtReadVirtualMemory=Getssdt_addr(in_NtReadVirtualMemory);
  667.   addr_NtReadVirtualMemory=push_addr_NtReadVirtualMemory;
  668.   t_NtReadVirtualMemory=(typedef_NtReadVirtualMemory*)push_addr_NtReadVirtualMemory;
  669.   __asm
  670.   {
  671.     push eax
  672.     mov eax,push_addr_NtReadVirtualMemory
  673.     add eax,1
  674.     mov eax,[eax]
  675.     mov push0_addr_NtReadVirtualMemory,al
  676.     pop eax
  677.   }
  678.   KdPrint(("NtReadVirtualMemory的第一个push地址为:%x\n",push0_addr_NtReadVirtualMemory));
  679.   __asm
  680.   {
  681.     push eax
  682.     mov eax,push_addr_NtReadVirtualMemory
  683.     add eax,2
  684.     mov eax,[eax+1]
  685.     mov push_addr_NtReadVirtualMemory,eax
  686.     pop eax
  687.   }
  688.   KdPrint(("NtReadVirtualMemory的第二个push地址为:%x\n",push_addr_NtReadVirtualMemory));
  689.   push_addr_NtWriteVirtualMemory=Getssdt_addr(in_NtWriteVirtualMemory);
  690.   addr_NtWriteVirtualMemory=push_addr_NtWriteVirtualMemory;
  691.   t_NtWriteVirtualMemory=(typedef_NtWriteVirtualMemory*)push_addr_NtWriteVirtualMemory;
  692.   __asm
  693.   {
  694.     push eax
  695.     mov eax,push_addr_NtWriteVirtualMemory
  696.     add eax,1
  697.     mov eax,[eax]
  698.     mov push0_addr_NtWriteVirtualMemory,al
  699.     pop eax
  700.   }
  701.   KdPrint(("NtWriteVirtualMemory的第一个push地址为:%x\n",push0_addr_NtWriteVirtualMemory));
  702.   __asm
  703.   {
  704.     push eax
  705.     mov eax,push_addr_NtWriteVirtualMemory
  706.     add eax,2
  707.     mov eax,[eax+1]
  708.     mov push_addr_NtWriteVirtualMemory,eax
  709.     pop eax
  710.   }
  711.   KdPrint(("NtWriteVirtualMemory的第二个push地址为:%x\n",push_addr_NtWriteVirtualMemory));
  712. }

  713. #endif
  714. //-----------------------------------------------------------------------
  715. #ifndef KIFASTCALLENTRY_H
  716. #define KIFASTCALLENTRY_H
  717. #include "hook.h"
  718. #define _exe_name "Maple_Valley.ex"

  719. ULONG addr_KiFastCallEntry;
  720. ULONG ret_KiFastCallEntry;


  721. ANSI_STRING str_NtOpenProcess;
  722. ANSI_STRING estr_NtOpenProcess;
  723. PEPROCESS eprocess_NtOpenProcess;
  724. #pragma PAGEDCODE
  725. extern "C"
  726. NTSTATUS __declspec(naked) my_NtOpenProcess( __out PHANDLE  ProcessHandle,  
  727.                  __in ACCESS_MASK  DesiredAccess,  
  728.                  __in POBJECT_ATTRIBUTES  ObjectAttributes,  
  729.                  __in_opt PCLIENT_ID  ClientId   
  730.                 )
  731. {

  732.   __asm
  733.   {
  734.     pushad
  735.     pushfd
  736.   }
  737.   eprocess_NtOpenProcess=IoGetCurrentProcess();
  738.   RtlInitAnsiString(&estr_NtOpenProcess,(PCSZ)((ULONG)eprocess_NtOpenProcess+0x174));
  739.   KdPrint(("进程名:%s  push_1:%x  push_2:%x call:%x\r\n",((ULONG)eprocess_NtOpenProcess+0x174),push0_addr_NtOpenProcess,push_addr_NtOpenProecss,call_addr_NtOpenProecss));
  740.   RtlInitAnsiString(&str_NtOpenProcess,_exe_name);
  741.   if(RtlEqualString(&estr_NtOpenProcess,&str_NtOpenProcess,TRUE))
  742.   {
  743.     __asm
  744.     {
  745.       popfd
  746.       popad
  747.       push push0_addr_NtOpenProcess
  748.       push push_addr_NtOpenProecss
  749.       mov eax,addr_NtOpenProecss
  750.       add eax,0xF
  751.       push eax
  752.       jmp call_addr_NtOpenProecss
  753.     }
  754.   }
  755.   __asm
  756.   {
  757.     popfd
  758.     popad
  759.     jmp addr_NtOpenProecss
  760.   }
  761. //  return t_NtOpenProcess(ProcessHandle,DesiredAccess,ObjectAttributes,ClientId);
  762. }

  763. ANSI_STRING str_NtReadVirtualMemory;
  764. ANSI_STRING estr_NtReadVirtualMemory;
  765. PEPROCESS eprocess_NtReadVirtualMemory;
  766. #pragma PAGEDCODE
  767. extern "C"
  768. NTSTATUS __declspec(naked) my_NtReadVirtualMemory(__in HANDLE  ProcessHandle,  
  769.                     __in_opt PVOID  BaseAddress,  
  770.                     __out_bcount(BufferSize) PVOID  Buffer,  
  771.                     __in SIZE_T  BufferSize,  
  772.                     __out_opt PSIZE_T  NumberOfBytesRead   
  773.                     )
  774. {
  775.   __asm
  776.   {
  777.     pushad
  778.     pushf
  779.   }
  780.   eprocess_NtReadVirtualMemory=IoGetCurrentProcess();
  781.   RtlInitAnsiString(&estr_NtReadVirtualMemory,(PCSZ)((ULONG)eprocess_NtReadVirtualMemory+0X174));
  782.   RtlInitAnsiString(&str_NtReadVirtualMemory,_exe_name);
  783.   if(RtlEqualString(&estr_NtReadVirtualMemory,&str_NtReadVirtualMemory,TRUE))
  784.   {
  785.     __asm
  786.     {
  787.       popf
  788.       popad
  789.       push push0_addr_NtReadVirtualMemory
  790.       push push_addr_NtReadVirtualMemory
  791.       mov eax,addr_NtReadVirtualMemory
  792.       add eax,0xC
  793.       push eax
  794.       jmp call_addr_NtReadVirtualMemory
  795.     }
  796.   }
  797.   __asm
  798.   {
  799.     popf
  800.     popad
  801.     jmp addr_NtReadVirtualMemory
  802.   }
  803. //  return t_NtReadVirtualMemory(ProcessHandle,BaseAddress,Buffer,BufferSize,NumberOfBytesRead);
  804. }


  805. ANSI_STRING str_NtWriteVirtualMemory;
  806. ANSI_STRING estr_NtWriteVirtualMemory;
  807. PEPROCESS eprocess_NtWriteVirtualMemory;
  808. #pragma PAGEDCODE
  809. extern "C"
  810. NTSTATUS __declspec(naked) my_NtWriteVirtualMemory(__in HANDLE  ProcessHandle,  
  811.                      __in_opt PVOID  BaseAddress,  
  812.                      __in_bcount(BufferSize) CONST VOID *  Buffer,  
  813.                      __in SIZE_T  BufferSize,  
  814.                      __out_opt PSIZE_T  NumberOfBytesWritten   
  815.                            )
  816. {
  817.   __asm
  818.   {
  819.     pushad
  820.     pushf  
  821.   }
  822.   eprocess_NtWriteVirtualMemory=IoGetCurrentProcess();
  823.   RtlInitAnsiString(&estr_NtWriteVirtualMemory,(PCSZ)((ULONG)eprocess_NtWriteVirtualMemory+0x174));
  824.   RtlInitAnsiString(&str_NtWriteVirtualMemory,_exe_name);
  825.   if(RtlEqualString(&estr_NtWriteVirtualMemory,&str_NtWriteVirtualMemory,TRUE))
  826.   {
  827.     __asm
  828.     {
  829.       popf
  830.       popad
  831.       push push0_addr_NtWriteVirtualMemory
  832.       push push_addr_NtWriteVirtualMemory
  833.       mov eax,addr_NtWriteVirtualMemory
  834.       add eax,0xC
  835.       push eax
  836.       jmp call_addr_NtWriteVirtualMemory
  837.     }
  838.   }
  839.   __asm
  840.   {
  841.     popf
  842.     popad
  843.     jmp addr_NtWriteVirtualMemory
  844.   }
  845. //  return t_NtWriteVirtualMemory(ProcessHandle,BaseAddress,Buffer,BufferSize,NumberOfBytesWritten);
  846. }

  847. #pragma INITCODE
  848. VOID GetKiFastCallEntry()
  849. {
  850.   __asm
  851.   {
  852.     mov ecx, 0x176
  853.     rdmsr                 // read the value of the IA32_SYSENTER_EIP register
  854.     mov addr_KiFastCallEntry, eax
  855.   }
  856. }

  857. _jmpcode jmpcode_KiFastCallEntry;
  858. pjmpcode pjmpcode_KiFastCallEntry;
  859. #pragma PAGEDCODE
  860. VOID Hook_KiFastCallEntry()
  861. {
  862.   BYTE* _bp;
  863.   _bp=(BYTE*)addr_KiFastCallEntry;
  864.   do
  865.   {
  866.     if((*(_bp-10)==0x8B)&&(*(_bp-8)==0x8B)&&(*(_bp-3)==0x8A)&&(*(_bp)==0x8B)&&(*(_bp+1)==0x3F)&&(*(_bp+2)==0x8B))
  867.     {
  868.       break;
  869.     }
  870.     _bp++;
  871.   }while(1);
  872.   addr_KiFastCallEntry=(ULONG)_bp;
  873.   KdPrint(("向KiFastCallEntry的地址为:%x\n",addr_KiFastCallEntry));
  874.   ret_KiFastCallEntry=addr_KiFastCallEntry+5;
  875.   ULONG my_fun;
  876.   __asm
  877.   {
  878.     push eax
  879.     mov eax,My_KiFastCallEntry
  880.     mov my_fun,eax
  881.     pop eax
  882.   }
  883.   pjmpcode_KiFastCallEntry=(pjmpcode)addr_KiFastCallEntry;
  884.   jmpcode_KiFastCallEntry.e9=pjmpcode_KiFastCallEntry->e9;
  885.   jmpcode_KiFastCallEntry.jmpaddr=pjmpcode_KiFastCallEntry->jmpaddr;
  886.   PAGED_Open();
  887.   pjmpcode_KiFastCallEntry->e9=0xE9;
  888.   pjmpcode_KiFastCallEntry->jmpaddr=(ULONG)(my_fun-addr_KiFastCallEntry-5);
  889.   PAGED_Exit();
  890. }

  891. #pragma PAGEDCODE
  892. VOID __declspec(naked) My_KiFastCallEntry()
  893. {
  894.   __asm
  895.   {
  896.     pushad
  897.     pushf
  898.     mov edi,dword ptr [edi]
  899.     mov ebx,dword ptr [edi+eax*4]
  900.     cmp addr_NtOpenProecss,ebx
  901.     jz lib_NtOpenProcess
  902.     cmp addr_NtReadVirtualMemory,ebx
  903.     jz lib_NtReadVirtualMemory
  904.     cmp addr_NtWriteVirtualMemory,ebx
  905.     jz lib_NtWriteVirtualMemory
  906.     popf
  907.     popad
  908.     mov edi,dword ptr [edi]
  909.     mov ebx,dword ptr [edi+eax*4]
  910.     jmp ret_KiFastCallEntry
  911. lib_NtOpenProcess:
  912.     popf
  913.     popad
  914.     mov ebx,my_NtOpenProcess
  915.     jmp ret_KiFastCallEntry
  916. lib_NtReadVirtualMemory:
  917.     popf
  918.     popad
  919.     mov ebx,my_NtReadVirtualMemory
  920.     jmp ret_KiFastCallEntry
  921. lib_NtWriteVirtualMemory:
  922.     popf
  923.     popad
  924.     mov ebx,my_NtWriteVirtualMemory
  925.     jmp ret_KiFastCallEntry
  926.   }
  927. }

  928. #pragma PAGEDCODE
  929. VOID Un_KiFastCallEntry()
  930. {
  931.   PAGED_Open();
  932.   pjmpcode_KiFastCallEntry->e9=jmpcode_KiFastCallEntry.e9;
  933.   pjmpcode_KiFastCallEntry->jmpaddr=jmpcode_KiFastCallEntry.jmpaddr;
  934.   PAGED_Exit();
  935. }
  936. #endif
复制代码

该用户从未签到

发表于 2013-2-26 18:39:01 | 显示全部楼层
能多开吗这个,
点击按钮快速添加回复内容: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

小黑屋|手机版|Archiver|看流星社区 |网站地图

GMT+8, 2024-4-18 21:40

Powered by Kanliuxing X3.4

© 2010-2019 kanliuxing.com

快速回复 返回顶部 返回列表