看流星社区

 找回密码
 注册账号
查看: 4033|回复: 2

过GPK驱动代码,看懂的带走,看不懂的留下。

[复制链接]

该用户从未签到

发表于 2012-10-18 20:29:55 | 显示全部楼层 |阅读模式
  1. #include "Shadow_hook.h"

  2. #pragma INITCODE
  3. extern "C" NTSTATUS DriverEntry(PDRIVER_OBJECT driver_object,PUNICODE_STRING u_string)
  4. {
  5.   _GetVersion(driver_object);
  6.   Hook_NtCreateMutant();
  7.   NTSTATUS status=STATUS_SUCCESS;
  8.   driver_object->MajorFunction[IRP_MJ_CREATE]=DispatchIrp;
  9.   driver_object->MajorFunction[IRP_MJ_READ]=DispatchIrp;
  10.   driver_object->MajorFunction[IRP_MJ_WRITE]=DispatchIrp;
  11.   driver_object->MajorFunction[IRP_MJ_CLOSE]=DispatchIrp;
  12.   driver_object->MajorFunction[IRP_MJ_DEVICE_CONTROL]=DispatchIrp;
  13.   driver_object->DriverUnload=DrvierUnLoad;

  14.   PDEVICEEXTENSION pdevex;
  15.   UNICODE_STRING device_string;
  16.   RtlInitUnicodeString(&device_string,_device_name);
  17.   PDEVICE_OBJECT device_object;
  18.   status=IoCreateDevice(driver_object,sizeof(pdevex),&device_string,FILE_DEVICE_UNKNOWN,0,FALSE,&device_object);
  19.   if(!NT_SUCCESS(status))
  20.   {
  21.     KdPrint(("创建设备失败!\n"));
  22.     return status;
  23.   }
  24.   KdPrint(("创建设备成功!\n"));
  25.   device_object->Flags |= DO_BUFFERED_IO;
  26.   pdevex=(PDEVICEEXTENSION)device_object->DeviceExtension;
  27.   pdevex->device_name=device_string;
  28.   pdevex->device_object=device_object;
  29.   
  30.   UNICODE_STRING symbol_name;
  31.   RtlInitUnicodeString(&symbol_name,_symbolic_name);
  32.   pdevex->device_symbolic=symbol_name;
  33.   status=IoCreateSymbolicLink(&symbol_name,&device_string);
  34.   if(!NT_SUCCESS(status))
  35.   {
  36.     KdPrint(("创建符号链接失败!\n"));
  37.     IoDeleteDevice(device_object);
  38.     return status;
  39.   }
  40.   KdPrint(("创建符号链接成功!\n"));
  41.   return STATUS_SUCCESS;
  42. }

  43. #pragma PAGEDCODE
  44. VOID DrvierUnLoad(PDRIVER_OBJECT driver)
  45. {

  46.   PDEVICE_OBJECT deviceobject;
  47.   UNICODE_STRING symbolname;
  48.   RtlInitUnicodeString(&symbolname,_symbolic_name);
  49.   IoDeleteSymbolicLink(&symbolname);
  50.   IoDeleteDevice(driver->DeviceObject);
  51. //  deviceobject=driver->DeviceObject;
  52. //  while(deviceobject!=NULL)
  53. //  {
  54. //    PDEVICEEXTENSION deviceex=(PDEVICEEXTENSION)deviceobject->DeviceExtension;
  55. //    UNICODE_STRING symbolname=deviceex->device_symbolic;
  56. //    IoDeleteSymbolicLink(&symbolname);
  57. //    deviceobject=deviceobject->NextDevice;
  58. //    IoDeleteDevice(deviceex->device_object);
  59. //  }
  60.   KdPrint(("删除设备成功!\n"));
  61.   UnHook_NtCreateMutant();
  62. }

  63. #pragma PAGEDCODE
  64. NTSTATUS DispatchIrp(PDEVICE_OBJECT device_object,PIRP irp)
  65. {
  66.   NTSTATUS status;
  67.   ULONG uin;
  68.   ULONG uout;
  69.   ULONG ucontrol;
  70.   PIO_STACK_LOCATION stirp=IoGetCurrentIrpStackLocation(irp);
  71.   ULONG irpindex=stirp->MajorFunction;
  72.   switch(irpindex)
  73.   {
  74.   case IRP_MJ_DEVICE_CONTROL:
  75.     status=STATUS_SUCCESS;
  76.     uin=stirp->Parameters.DeviceIoControl.InputBufferLength;
  77.     uout=stirp->Parameters.DeviceIoControl.OutputBufferLength;
  78.     ucontrol=stirp->Parameters.DeviceIoControl.IoControlCode;
  79.     switch(ucontrol)
  80.     {
  81.     case Un_hook:
  82.       Hook_NtUserSendInput();
  83.       KdPrint(("与应用程序通讯成功,所以地址已打印到调试器中……\n"));
  84.       break;
  85.     case function_unhook:
  86.       Get_NtCreateThread();
  87.       Get_NtProtectVirtualMemory();
  88.       Get_NtQueueAcpThread();
  89.       Get_NtTerminateProcess();
  90.       Get_NtWirteVirtualMemory();
  91.       Get_ObCheckObjectAccess();
  92.       break;
  93.     }
  94.     break;
  95.   case IRP_MJ_CREATE:
  96.     break;
  97.   case IRP_MJ_READ:
  98.     break;
  99.   case IRP_MJ_WRITE:
  100.     break;
  101.   case IRP_MJ_CLOSE:

  102.     break;
  103.   }
  104.   irp->IoStatus.Status=STATUS_SUCCESS;
  105.   irp->IoStatus.Information=0;
  106.   IoCompleteRequest(irp,IO_NO_INCREMENT);
  107.   return STATUS_SUCCESS;
  108. }
  109. //----------------------------------------------------------------------------------
  110. #pragma once
  111. #include "Shadow_.h"

  112. #define Version_2008   60
  113. DWORD KeServiceDescriptorTableShadow=0;

  114. //-----------------------------------
  115. int inxp_NtUserSendInput=0;
  116. int inxp_NtUserQuerySendMessage=0;
  117. int in_NtCreateThreadEx=0;
  118. int in_NtCreateThread=0;
  119. int in_NtProtectVirtualMemory=0;
  120. int in_NtQueueApcThread=0;
  121. int in_TerminateProcess=0;
  122. int in_NtWriteVirtualMemory=0;
  123. int in_NtCreateMutant=0;
  124. //--------------------------------
  125. ULONG push_NtCreateThread;
  126. ULONG push_NtProtectVirtualMemory;
  127. ULONG push_NtWriteVirtualMemory;
  128. ULONG addr_ObCheckObjectAccess;    //ObCheckObjectAccess的地址
  129. ULONG addr_NtCreateMutant;
  130. //--------------------------

  131. typedef struct _ServiceDescriptorTable
  132. {
  133.   PVOID ServiceTableBase; //System Service Dispatch Table 的基地址  
  134.   PVOID ServiceCounterTable;
  135.   //包含着 SSDT 中每个服务被调用次数的计数器。这个计数器一般由sysenter 更新。
  136.   unsigned int NumberOfServices;//由 ServiceTableBase 描述的服务的数目。  
  137.   PVOID ParamTableBase; //包含每个系统服务参数字节数表的基地址-系统服务参数表
  138. }*PServiceDescriptorTable;  
  139. extern "C" extern PServiceDescriptorTable KeServiceDescriptorTable;

  140. #pragma pack(1)
  141. typedef struct _bycode
  142. {
  143.   BYTE data[3];
  144.   ULONG addr;
  145. }bycode,*pbycode;
  146. typedef struct _push_code
  147. {
  148.   BYTE push;
  149.   ULONG addr;
  150.   BYTE retn;
  151. }push_code,*ppush_code;
  152. typedef struct _bytecode
  153. {
  154.   BYTE push;
  155.   ULONG addr;
  156.   BYTE push1;
  157.   ULONG addr1;
  158. }bytecode,*pbytecode;
  159. typedef struct _bytecode1
  160. {
  161.   BYTE push;
  162.   BYTE pushaddr;
  163.   BYTE push1;
  164.   ULONG pushaddr1;
  165. }bytecode1,*pbytecode1;
  166. typedef struct _bytecode2
  167. {
  168.   BYTE mov[2];
  169.   BYTE push;
  170.   BYTE mov1[2];
  171.   BYTE push1;
  172. }bytecode2,*pbytecode2;
  173. #pragma pack()

  174. KIRQL kirql;
  175. #pragma PAGEDCODE
  176. VOID PAGED_Open()
  177. {
  178.   __asm
  179.   {
  180.     push eax
  181.     mov eax,cr0
  182.     and eax,not 10000h
  183.     mov cr0,eax
  184.     pop eax
  185.   }
  186.   kirql=KeRaiseIrqlToDpcLevel();
  187. }

  188. #pragma PAGEDCODE
  189. VOID PAGED_Exit()
  190. {
  191.   KeLowerIrql(kirql);
  192.   __asm
  193.   {
  194.     push eax
  195.     mov eax,cr0
  196.     or eax,10000h
  197.     mov cr0,eax
  198.     pop eax
  199.   }

  200. }

  201. #pragma PAGEDCODE
  202. VOID __stdcall _GetVersion(PDRIVER_OBJECT driver)
  203. {
  204.   ULONG MajorVerion,MinVersion,BulidViersion;
  205.   PsGetVersion(&MajorVerion,&MinVersion,&BulidViersion,NULL);
  206.   ULONG uas=MajorVerion*10+MinVersion;
  207.   switch(uas)
  208.   {
  209.   case Version_2008:
  210.     KdPrint(("当前操作系统是:Server 2008\n"));
  211.     KeServiceDescriptorTableShadow=(DWORD)KeServiceDescriptorTable+0x40;
  212.     inxp_NtUserSendInput=0x20D;
  213.     inxp_NtUserQuerySendMessage=0x1F7;
  214.     in_NtCreateThreadEx=0x17E;
  215.     in_NtCreateThread=0x4E;
  216.     in_NtProtectVirtualMemory=0xD2;
  217.     in_NtQueueApcThread=0xFF;
  218.     in_TerminateProcess=0x14E;
  219.     in_NtWriteVirtualMemory=0x166;
  220.     in_NtCreateMutant=0x43;
  221.     break;
  222.   default:
  223.     driver->DriverUnload=DrvierUnLoad;
  224.     break;
  225.   }
  226. }

  227. #pragma PAGEDCODE
  228. ULONG Get_KeServiceDescriptorTableShadow_addr(int index)
  229. {
  230.   KdPrint(("获取Shadow SSDT地址信息.\n"));
  231.   DWORD Shadow_addr=KeServiceDescriptorTableShadow;
  232.   Shadow_addr+=0x10;
  233.   DWORD Shadow_sl=Shadow_addr+8;  //shadow函数的数量

  234.   DWORD get_sl=*((PDWORD)Shadow_sl);
  235.   KdPrint(("Shadow表的地址为: addr=%x 数量=%x\n",Shadow_addr,get_sl));
  236.   PDWORD Fun_addr=PDWORD(Shadow_addr);
  237.   Fun_addr=PDWORD(*Fun_addr);
  238.   //for(DWORD i=0;i<get_sl;i++)
  239.   //{
  240.   //  KdPrint(("当前函数ID=%d,函数地址=%x\n",i,*Fun_addr));
  241.   //  Fun_addr++;
  242.   //}
  243.   Fun_addr+=index;
  244.   KdPrint(("当前ID=%d,函数地址=%x\n",index,*Fun_addr));
  245.   return *Fun_addr;
  246. }

  247. #pragma PAGEDCODE
  248. ULONG GetSsdt_addr(int index)
  249. {
  250.   ULONG* addr_funtion,getfuntion,funtion;
  251.   getfuntion=(ULONG)KeServiceDescriptorTable->ServiceTableBase;
  252.   KdPrint(("当前KeServiceDescriptorTable表的地址为:%x\n",getfuntion));
  253.   addr_funtion=(PULONG)(getfuntion+index*4);
  254.   funtion=*addr_funtion;
  255.   KdPrint(("当前函数序号index=%d  函数地址:%x\n",index,funtion));
  256.   return funtion;
  257. }

  258. #pragma PAGEDCODE
  259. ULONG* GetSSdt_this(int index)
  260. {
  261.   ULONG* addr_funtion,x_funtion;
  262.   x_funtion=(ULONG)KeServiceDescriptorTable->ServiceTableBase;
  263.   addr_funtion=(ULONG*)(x_funtion+index*4);
  264.   return addr_funtion;
  265. }

  266. pbycode _pbycode;
  267. #pragma PAGEDCODE
  268. void Hook_NtUserSendInput()
  269. {
  270.   ULONG addr_NtUserQuerSendMessage=Get_KeServiceDescriptorTableShadow_addr(inxp_NtUserQuerySendMessage);
  271.   __asm
  272.   {
  273.     push eax
  274.     mov eax,addr_NtUserQuerSendMessage
  275.     add eax,3
  276.     mov eax,[eax]
  277.     sub eax,0xbf8   ;__safe_se_handler_table的首地址
  278.     add eax,0xc18
  279.     mov addr_NtUserQuerSendMessage,eax
  280.     pop eax
  281.   }
  282.   KdPrint(("NtUserSendInput的第二个push地址为:%x\n",addr_NtUserQuerSendMessage));
  283.   ULONG addr_NtUserSendInput=Get_KeServiceDescriptorTableShadow_addr(inxp_NtUserSendInput);
  284.   _pbycode=(pbycode)addr_NtUserSendInput;
  285.   PAGED_Open();
  286.   _pbycode->data[0]=0x6A;
  287.   _pbycode->data[1]=0x18;
  288.   _pbycode->data[2]=0x68;
  289.   _pbycode->addr=addr_NtUserQuerSendMessage;
  290.   PAGED_Exit();
  291. }

  292. bytecode bytecode_NtCreateThread;
  293. pbytecode pbytecode_NtCreateThread;
  294. #pragma PAGEDCODE
  295. VOID Get_NtCreateThread()
  296. {
  297.   ULONG u_NtCreateThreadEx=GetSsdt_addr(in_NtCreateThreadEx);
  298.   __asm
  299.   {
  300.     push eax
  301.     mov eax,u_NtCreateThreadEx
  302.     add eax,5
  303.     mov eax,[eax+1]
  304.     mov push_NtCreateThread,eax
  305.     pop eax
  306.   }
  307.   push_NtCreateThread=push_NtCreateThread-0x5010+0x2A98;
  308.   KdPrint(("NtCreateThread的第二个push地址为:%x\n",push_NtCreateThread));
  309.   ULONG u_NtCreateThread=GetSsdt_addr(in_NtCreateThread);
  310.   pbytecode_NtCreateThread=(pbytecode)u_NtCreateThread;
  311.   bytecode_NtCreateThread.push=pbytecode_NtCreateThread->push;
  312.   bytecode_NtCreateThread.addr=pbytecode_NtCreateThread->addr;
  313.   bytecode_NtCreateThread.push1=pbytecode_NtCreateThread->push1;
  314.   bytecode_NtCreateThread.addr1=pbytecode_NtCreateThread->addr1;
  315.   PAGED_Open();
  316.   pbytecode_NtCreateThread->push=0x68;
  317.   pbytecode_NtCreateThread->addr=0x308;
  318.   pbytecode_NtCreateThread->push1=0x68;
  319.   pbytecode_NtCreateThread->addr1=push_NtCreateThread;
  320.   PAGED_Exit();
  321. }

  322. bytecode1 bytecode_NtProtectVirtualMemory;
  323. pbytecode1 pbytecode_NtProtectVirtualMemory;
  324. #pragma PAGEDCODE
  325. VOID Get_NtProtectVirtualMemory()
  326. {
  327.   push_NtProtectVirtualMemory=push_NtCreateThread-0x2a98+0x6758;
  328.   ULONG u_NtProtectVirtualMemory=GetSsdt_addr(in_NtProtectVirtualMemory);
  329.   pbytecode_NtProtectVirtualMemory=(pbytecode1)u_NtProtectVirtualMemory;
  330.   bytecode_NtProtectVirtualMemory.push=pbytecode_NtProtectVirtualMemory->push;
  331.   bytecode_NtProtectVirtualMemory.pushaddr=pbytecode_NtProtectVirtualMemory->pushaddr;
  332.   bytecode_NtProtectVirtualMemory.push1=pbytecode_NtProtectVirtualMemory->push1;
  333.   bytecode_NtProtectVirtualMemory.pushaddr1=pbytecode_NtProtectVirtualMemory->pushaddr1;
  334.   PAGED_Open();
  335.   pbytecode_NtProtectVirtualMemory->push=0x6a;
  336.   pbytecode_NtProtectVirtualMemory->pushaddr=0x38;
  337.   pbytecode_NtProtectVirtualMemory->push1=0x68;
  338.   pbytecode_NtProtectVirtualMemory->pushaddr1=push_NtProtectVirtualMemory;
  339.   PAGED_Exit();
  340. }

  341. bytecode2 bytecode_NtQueueApcThread;
  342. pbytecode2 pbytecode_NtQueueApcThread;
  343. #pragma PAGEDCODE
  344. VOID Get_NtQueueAcpThread()
  345. {
  346.   ULONG u_NtQueueApcThread=GetSsdt_addr(in_NtQueueApcThread);
  347.   pbytecode_NtQueueApcThread=(pbytecode2)u_NtQueueApcThread;
  348.   bytecode_NtQueueApcThread.mov[0]=pbytecode_NtQueueApcThread->mov[0];
  349.   bytecode_NtQueueApcThread.mov[1]=pbytecode_NtQueueApcThread->mov[1];
  350.   bytecode_NtQueueApcThread.push=pbytecode_NtQueueApcThread->push;
  351.   bytecode_NtQueueApcThread.mov1[0]=pbytecode_NtQueueApcThread->mov1[0];
  352.   bytecode_NtQueueApcThread.mov1[1]=pbytecode_NtQueueApcThread->mov1[1];
  353.   bytecode_NtQueueApcThread.push1=pbytecode_NtQueueApcThread->push1;
  354.   PAGED_Open();
  355.   pbytecode_NtQueueApcThread->mov[0]=0x8B;
  356.   pbytecode_NtQueueApcThread->mov[1]=0xff;
  357.   pbytecode_NtQueueApcThread->push=0x55;
  358.   pbytecode_NtQueueApcThread->mov1[0]=0x8B;
  359.   pbytecode_NtQueueApcThread->mov1[1]=0xEC;
  360.   pbytecode_NtQueueApcThread->push1=0x51;
  361.   PAGED_Exit();
  362. }

  363. bytecode2 bytecode_NtTerminateProcess;
  364. pbytecode2 pbytecode_NtTerminteProcess;
  365. #pragma PAGEDCODE
  366. VOID Get_NtTerminateProcess()
  367. {
  368.   ULONG u_NtTerminateProcess=GetSsdt_addr(in_TerminateProcess);
  369.   pbytecode_NtTerminteProcess=(pbytecode2)u_NtTerminateProcess;
  370.   bytecode_NtTerminateProcess.mov[0]=pbytecode_NtTerminteProcess->mov[0];
  371.   bytecode_NtTerminateProcess.mov[1]=pbytecode_NtTerminteProcess->mov[1];
  372.   bytecode_NtTerminateProcess.push=pbytecode_NtTerminteProcess->push;
  373.   bytecode_NtTerminateProcess.mov1[0]=pbytecode_NtTerminteProcess->mov1[0];
  374.   bytecode_NtTerminateProcess.mov1[1]=pbytecode_NtTerminteProcess->mov1[1];
  375.   bytecode_NtTerminateProcess.push1=pbytecode_NtTerminteProcess->push1;
  376.   PAGED_Open();
  377.   pbytecode_NtTerminteProcess->mov[0]=0x8B;
  378.   pbytecode_NtTerminteProcess->mov[1]=0xff;
  379.   pbytecode_NtTerminteProcess->push=0x55;
  380.   pbytecode_NtTerminteProcess->mov1[0]=0x8B;
  381.   pbytecode_NtTerminteProcess->mov1[1]=0xEC;
  382.   pbytecode_NtTerminteProcess->push1=0x83;
  383.   PAGED_Exit();
  384. }

  385. bytecode1 bytecode_NtWriteVirtualMemory;
  386. pbytecode1 pbytecode_NtWriteVirtualMemory;
  387. #pragma PAGEDCODE
  388. VOID Get_NtWirteVirtualMemory()
  389. {
  390.   push_NtWriteVirtualMemory=push_NtProtectVirtualMemory-0x6758+0x5668;
  391.   ULONG u_NtWriteVirtualMemory=GetSsdt_addr(in_NtWriteVirtualMemory);
  392.   pbytecode_NtWriteVirtualMemory=(pbytecode1)u_NtWriteVirtualMemory;
  393.   bytecode_NtWriteVirtualMemory.push=pbytecode_NtWriteVirtualMemory->push;
  394.   bytecode_NtWriteVirtualMemory.pushaddr=pbytecode_NtWriteVirtualMemory->pushaddr;
  395.   bytecode_NtWriteVirtualMemory.push1=pbytecode_NtWriteVirtualMemory->push1;
  396.   bytecode_NtWriteVirtualMemory.pushaddr1=pbytecode_NtWriteVirtualMemory->pushaddr1;
  397.   PAGED_Open();
  398.   pbytecode_NtWriteVirtualMemory->push=0x6A;
  399.   pbytecode_NtWriteVirtualMemory->pushaddr=0x18;
  400.   pbytecode_NtWriteVirtualMemory->push1=0x68;
  401.   bytecode_NtWriteVirtualMemory.pushaddr1=push_NtWriteVirtualMemory;
  402.   PAGED_Exit();
  403. }

  404. bytecode2 bytecode_ObCheckObjectAccess;
  405. pbytecode2 pbytecode_ObCheckObjectAccess;
  406. #pragma PAGEDCODE
  407. VOID Get_ObCheckObjectAccess()
  408. {
  409.   ULONG u_NtWiteVirtualMemory=GetSsdt_addr(in_NtWriteVirtualMemory);
  410.   BYTE* _bp=(BYTE*)u_NtWiteVirtualMemory;
  411.   while(1)
  412.   {
  413.     if((*(_bp-11)==0xFF)&&(*(_bp-5)==0x6A)&&(*(_bp-3)==0xFF)&&(*(_bp)==0xE8)&&(*(_bp+5)==0x89)&&(*(_bp+8)==0x85))
  414.     {
  415.       break;
  416.     }
  417.     _bp++;
  418.   }
  419.   ULONG u_temp=(ULONG)_bp;
  420.   ULONG call_addr;
  421.   __asm
  422.   {
  423.     push eax
  424.     push ebx
  425.     mov eax,u_temp
  426.     mov ebx,[eax+1]
  427.     add eax,ebx
  428.     add eax,5
  429.     mov call_addr,eax
  430.     pop ebx
  431.     pop eax
  432.   }
  433.   _bp=(BYTE*)call_addr;
  434.   while(1)
  435.   {
  436.     if((*(_bp-9)==0x89)&&(*(_bp-6)==0x89)&&(*(_bp-3)==0x89)&&(*(_bp)==0xE8)&&(*(_bp+5)==0x3B)&&(*(_bp+7)==0x7D))
  437.     {
  438.       break;
  439.     }
  440.     _bp++;
  441.   }
  442.   ULONG u_ObCheckObjectAccess=(ULONG)_bp-0x27;
  443.   pbytecode_ObCheckObjectAccess=(pbytecode2)u_ObCheckObjectAccess;
  444.   bytecode_ObCheckObjectAccess.mov[0]=pbytecode_ObCheckObjectAccess->mov[0];
  445.   bytecode_ObCheckObjectAccess.mov[1]=pbytecode_ObCheckObjectAccess->mov[1];
  446.   bytecode_ObCheckObjectAccess.push=pbytecode_ObCheckObjectAccess->push;
  447.   bytecode_ObCheckObjectAccess.mov1[0]=pbytecode_ObCheckObjectAccess->mov1[0];
  448.   bytecode_ObCheckObjectAccess.mov1[1]=pbytecode_ObCheckObjectAccess->mov1[1];
  449.   bytecode_ObCheckObjectAccess.push1=pbytecode_ObCheckObjectAccess->push1;
  450.   PAGED_Open();
  451.   pbytecode_ObCheckObjectAccess->mov[0]=0x8B;
  452.   pbytecode_ObCheckObjectAccess->mov[1]=0xFF;
  453.   pbytecode_ObCheckObjectAccess->push=0x55;
  454.   pbytecode_ObCheckObjectAccess->mov1[0]=0x8B;
  455.   pbytecode_ObCheckObjectAccess->mov1[1]=0xEC;
  456.   pbytecode_ObCheckObjectAccess->push1=0x83;
  457.   PAGED_Exit();
  458. }

  459. extern "C"
  460. typedef
  461. NTSYSAPI
  462. NTSTATUS
  463. (__stdcall* nt_NtCreateMutant)(
  464.          OUT PHANDLE MutantHandle,
  465.          IN ACCESS_MASK DesiredAccess,
  466.          IN POBJECT_ATTRIBUTES ObjectAttributes,
  467.          IN BOOLEAN InitialOwner
  468.    );
  469. nt_NtCreateMutant* ntNtCreateMutant;

  470. #pragma PAGEDCODE
  471. extern "C"
  472. NTSTATUS
  473. __stdcall My_NtCreateMutant(
  474.                  OUT PHANDLE MutantHandle,
  475.                  IN ACCESS_MASK DesiredAccess,
  476.                  IN POBJECT_ATTRIBUTES ObjectAttributes,
  477.                  IN BOOLEAN InitialOwner)
  478. {
  479.   if(ObjectAttributes!=NULL && ObjectAttributes->ObjectName!=NULL && ObjectAttributes->ObjectName->Buffer!=NULL)
  480.   {
  481.     KdPrint(("互斥体名为:%wZ\r\n",ObjectAttributes->ObjectName));
  482.     UNICODE_STRING Mutant_name_Create;
  483.     RtlInitUnicodeString(&Mutant_name_Create,L"Global\\MutexDragonNest");
  484.     if(ObjectAttributes && RtlEqualUnicodeString(&Mutant_name_Create,ObjectAttributes->ObjectName,FALSE))
  485.     {
  486.       return STATUS_SUCCESS;
  487.     }
  488.   }
  489.   return ((NTSTATUS(NTAPI*)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,BOOLEAN))ntNtCreateMutant)(MutantHandle,DesiredAccess,ObjectAttributes,InitialOwner);
  490. }

  491. #pragma PAGEDCODE
  492. VOID Hook_NtCreateMutant()
  493. {
  494.   ULONG* un_NtOpenMutant;
  495.   un_NtOpenMutant=GetSSdt_this(in_NtCreateMutant);
  496.   addr_NtCreateMutant=GetSsdt_addr(in_NtCreateMutant);
  497.   KdPrint(("当前系统NtOpenMutant的地址为:%x\n",addr_NtCreateMutant));
  498.   ntNtCreateMutant=(nt_NtCreateMutant*)addr_NtCreateMutant;
  499.   PAGED_Open();
  500.   *un_NtOpenMutant=(ULONG)My_NtCreateMutant;
  501.   PAGED_Exit();
  502. }

  503. #pragma PAGEDCODE
  504. void UnHook_NtCreateMutant()
  505. {
  506.   ULONG ntcreatemutant;
  507.   ntcreatemutant=(ULONG)KeServiceDescriptorTable->ServiceTableBase+in_NtCreateMutant*4;
  508.   PAGED_Open();
  509.   *((ULONG*)ntcreatemutant)=(ULONG)addr_NtCreateMutant;
  510.   PAGED_Exit();
  511. }
复制代码

该用户从未签到

发表于 2012-10-19 22:04:07 | 显示全部楼层
3Q 谢谢分享

该用户从未签到

发表于 2013-9-23 12:18:36 | 显示全部楼层
够邪恶..不过我喜欢.嘿嘿
点击按钮快速添加回复内容: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

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

GMT+8, 2024-4-19 20:40

Powered by Kanliuxing X3.4

© 2010-2019 kanliuxing.com

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