鱼C论坛

 找回密码
 立即注册
查看: 2418|回复: 1

[作品展示] -=最新双机=- 当前这个是看雪的资料

[复制链接]
发表于 2013-8-8 12:35:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. /***************************************************************************************
  2. * AUTHOR : pudge
  3. * DATE   : 2012-9-8
  4. * MODULE : PassKddisabledebugger.C
  5. *
  6. * Command:
  7. *  Source of IOCTRL Sample Driver
  8. *
  9. * Description:
  10. *    Demonstrates communications between USER and KERNEL.
  11. *
  12. ****************************************************************************************
  13. * Copyright (C) 2010 pudge.
  14. ****************************************************************************************/
  15. //#######################################################################################
  16. //# I N C L U D E S
  17. //#######################################################################################
  18. #ifndef CXX_PASSKDDISABLEDEBUGGER_H
  19. #include "PassKddisabledebugger.h"
  20. #endif
  21. #include <ntddk.h>
  22. #include "function.h"
  23. #include "myfunc.h"
  24. VOID LoadImageRoutine(
  25.   __in_opt PUNICODE_STRING  FullImageName,
  26.   __in HANDLE  ProcessId,
  27.   __in PIMAGE_INFO  ImageInfo
  28.   );
  29. void  SearchFeatureEx(int nAddr,char* pFeature,int ModuleSize,int nLeng);
  30. void PassGlobalStaticCrcEx();
  31. DWORD NTAPI MyVectoredExceptionHead(EXCEPTION_POINTERS * ExceptionInfo);
  32. ULONG fuckaddr1;
  33. DWORD pShutdown[10000]={0};
  34. BYTE _pMirror[1282048]={0};
  35. DWORD pMirror=(DWORD)_pMirror;
  36. DWORD TesSafeBase=0;
  37. BYTE mKdDisableDebugger[5]={0};
  38. DWORD kdRet=0;
  39. int n=0;
  40. PDRIVER_OBJECT g_pObj=NULL;
  41. //////////////////////////////////////////////////////////////////////////
  42. //#######################################################################################
  43. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  44. //@@@@@@@@        D R I V E R   E N T R Y   P O I N T             @@@@@@@@
  45. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  46. //#######################################################################################
  47. NTSTATUS
  48. DriverEntry(IN PDRIVER_OBJECT pDriverObj, IN PUNICODE_STRING pRegistryString)
  49. {
  50.   NTSTATUS    status = STATUS_SUCCESS;
  51.   UNICODE_STRING  ustrLinkName;
  52.   UNICODE_STRING  ustrDevName;  
  53.   PDEVICE_OBJECT  pDevObj;
  54.   int i = 0;
  55.     g_pObj=pDriverObj;
  56.     dprintf("EasySys Sample Driver\r\n"
  57.             "Compiled %s %s\r\nIn DriverEntry : %wZ\r\n",
  58.       __DATE__, __TIME__, pRegistryString);
  59.   // Register dispatch routines
  60. /*
  61.   for(i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
  62.   {
  63.     pDriverObj->MajorFunction[i] = DispatchCommon;  
  64.   }
  65. */
  66.   pDriverObj->MajorFunction[IRP_MJ_CREATE] = DispatchCreate;
  67.   pDriverObj->MajorFunction[IRP_MJ_CLOSE] = DispatchClose;
  68.   // Dispatch routine for communications
  69.   pDriverObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchDeviceControl;
  70.   // Unload routine
  71.   pDriverObj->DriverUnload = DriverUnload;
  72.   // Initialize the device name.
  73.   RtlInitUnicodeString(&ustrDevName, NT_DEVICE_NAME);
  74.   // Create the device object and device extension
  75.   status = IoCreateDevice(pDriverObj,
  76.         0,
  77.         &ustrDevName,
  78.         FILE_DEVICE_UNKNOWN,
  79.         0,
  80.         FALSE,
  81.         &pDevObj);
  82.   if(!NT_SUCCESS(status))
  83.   {
  84.     dprintf("Error, IoCreateDevice = 0x%x\r\n", status);
  85.     return status;
  86.   }
  87.     //// Get a pointer to our device extension
  88.     //deviceExtension = (PDEVICE_EXTENSION) deviceObject->DeviceExtension;
  89.     //// Save a pointer to the device object
  90.     //deviceExtension->DeviceObject = deviceObject;
  91.   if(IoIsWdmVersionAvailable(1,0x10))
  92.   {
  93.     //如果是支持符号链接用户相关性的系统
  94.     RtlInitUnicodeString(&ustrLinkName, SYMBOLIC_LINK_GLOBAL_NAME);
  95.   }
  96.   else
  97.   {
  98.     //不支持
  99.     RtlInitUnicodeString(&ustrLinkName, SYMBOLIC_LINK_NAME);
  100.   }
  101.   
  102.   // Create a symbolic link to allow USER applications to access it.
  103.   status = IoCreateSymbolicLink(&ustrLinkName, &ustrDevName);  
  104.   
  105.   if(!NT_SUCCESS(status))
  106.   {
  107.     dprintf("Error, IoCreateSymbolicLink = 0x%x\r\n", status);
  108.    
  109.     IoDeleteDevice(pDevObj);
  110.     return status;
  111.   }  
  112.   //
  113.   //  TODO: Add initialization code here.
  114.   //设备开始
  115.   
  116.   
  117.   PsSetLoadImageNotifyRoutine(LoadImageRoutine);
  118.   


  119.   //
  120.     //// Tell the I/O Manger to do BUFFERED IO
  121.     //deviceObject->Flags |= DO_BUFFERED_IO;
  122.     //// Save the DeviveObject
  123.     //deviceExtension->DeviceObject = deviceObject;
  124.   dprintf("DriverEntry Success\r\n");
  125.   DbgPrint("DriverEntry Success\r\n");
  126.   return STATUS_SUCCESS;
  127. }
  128. VOID
  129. DriverUnload(IN PDRIVER_OBJECT pDriverObj)
  130. {  
  131.    
  132.   UNICODE_STRING strLink;
  133.   // Unloading - no resources to free so just return.
  134.   dprintf("Unloading...\r\n");;  
  135.   DbgPrint("Unloading...\r\n");
  136.   //
  137.   // TODO: Add uninstall code here.
  138.   //关闭设备
  139.   
  140.   UnInLineHookEngine((int)KdDisableDebugger,(char *)mKdDisableDebugger,5);
  141.   PsRemoveLoadImageNotifyRoutine(LoadImageRoutine);
  142.   //NtFreeVirtualMemory((HANDLE)-1,pMirror,(PSIZE_T)0x139000,MEM_COMMIT);
  143.   DbgPrint("unNotifyRoutine is OK");

  144.   //
  145.   
  146.   // Delete the symbolic link
  147.   RtlInitUnicodeString(&strLink, SYMBOLIC_LINK_NAME);
  148.   IoDeleteSymbolicLink(&strLink);
  149.   // Delete the DeviceObject
  150.   IoDeleteDevice(pDriverObj->DeviceObject);
  151.   dprintf("Unloaded Success\r\n");
  152.   DbgPrint("Unloaded Success\r\n");
  153.   return;
  154. }
  155. NTSTATUS
  156. DispatchCreate(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
  157. {
  158.   pIrp->IoStatus.Status = STATUS_SUCCESS;
  159.   pIrp->IoStatus.Information = 0;
  160.   IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  161.   
  162.   return STATUS_SUCCESS;
  163. }

  164. NTSTATUS
  165. DispatchClose(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
  166. {
  167.   pIrp->IoStatus.Status = STATUS_SUCCESS;
  168.   pIrp->IoStatus.Information = 0;
  169.   IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  170.   
  171.   // Return success
  172.   return STATUS_SUCCESS;
  173. }
  174. NTSTATUS
  175. DispatchCommon(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
  176. {
  177.   pIrp->IoStatus.Status = STATUS_SUCCESS;
  178.   pIrp->IoStatus.Information = 0L;
  179.   IoCompleteRequest( pIrp, 0 );
  180.   // Return success
  181.   return STATUS_SUCCESS;
  182. }
  183. NTSTATUS
  184. DispatchDeviceControl(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
  185. {
  186.   NTSTATUS status               = STATUS_INVALID_DEVICE_REQUEST;   // STATUS_UNSUCCESSFUL
  187.   PIO_STACK_LOCATION pIrpStack  = IoGetCurrentIrpStackLocation(pIrp);
  188.   ULONG uIoControlCode          = 0;
  189.   PVOID pIoBuffer          = NULL;
  190.   ULONG uInSize                 = 0;
  191.   ULONG uOutSize                = 0;
  192.   // Get the IoCtrl Code
  193.   uIoControlCode = pIrpStack->Parameters.DeviceIoControl.IoControlCode;
  194.   pIoBuffer = pIrp->AssociatedIrp.SystemBuffer;
  195.   uInSize = pIrpStack->Parameters.DeviceIoControl.InputBufferLength;
  196.   uOutSize = pIrpStack->Parameters.DeviceIoControl.OutputBufferLength;
  197.   switch(uIoControlCode)
  198.   {
  199.     case IOCTL_HELLO_WORLD:
  200.       {      
  201.         dprintf("MY_CTL_CODE(0)=%d\r\n,MY_CTL_CODE");
  202.         // Return success
  203.         status = STATUS_SUCCESS;
  204.       }
  205.       break;
  206.     case IOCTRL_REC_FROM_APP:
  207.       {
  208.         // Receive data form Application
  209.         //dprintf("IOCTRL_REC_FROM_APP\r\n");
  210.         // Do we have any data?
  211.         if( uInSize > 0 )
  212.         {
  213.           dprintf("Get Data from App: %ws\r\n", pIoBuffer);
  214.         }
  215.         // Return success
  216.         status = STATUS_SUCCESS;
  217.       }
  218.       break;
  219.     case IOCTRL_SEND_TO_APP:
  220.       {
  221.         // Send data to Application
  222.         //dprintf("IOCTRL_SEND_TO_APP\r\n");
  223.       
  224.         // If we have enough room copy the data upto the App - note copy the terminating character as well...
  225.         if( uOutSize >= strlen( DATA_TO_APP ) + 1 )
  226.         {
  227.           RtlCopyMemory(  pIoBuffer,
  228.                   DATA_TO_APP,
  229.                   strlen( DATA_TO_APP ) + 1 );
  230.           // Update the length for the App
  231.           pIrp->IoStatus.Information = strlen( DATA_TO_APP ) + 1;
  232.           dprintf("Send Data to App: %s\r\n", pIoBuffer);
  233.          
  234.           // Return success
  235.           status = STATUS_SUCCESS;
  236.         }
  237.       }
  238.       break;
  239.       
  240.     //
  241.     // TODO: Add execute code here.执行
  242.       
  243.       
  244.     //
  245.     default:
  246.       {
  247.         // Invalid code sent
  248.         dprintf("Unknown IOCTL: 0x%X (%04X,%04X)\r\n",
  249.                                           uIoControlCode,
  250.                                           DEVICE_TYPE_FROM_CTL_CODE(uIoControlCode),
  251.                                           IoGetFunctionCodeFromCtlCode(uIoControlCode));
  252.         status = STATUS_INVALID_PARAMETER;  
  253.       }
  254.       break;
  255.   }
  256.   if(status == STATUS_SUCCESS)
  257.   {
  258.     pIrp->IoStatus.Information = uOutSize;
  259.   }
  260.   else
  261.   {
  262.     pIrp->IoStatus.Information = 0;
  263.   }
  264.   // Complete the I/O Request
  265.   pIrp->IoStatus.Status = status;
  266.   IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  267.   return status;
  268. }
  269. __declspec(naked) void MyKdDisableDebugger()
  270. {
  271.   __asm
  272.   {
  273.       push eax
  274.       mov eax,[esp+0x4]
  275.       sub eax,TesSafeBase
  276.       add eax,pMirror
  277.       mov [esp+0x4],eax
  278.       pop eax
  279.       jmp kdRet
  280.   }
  281.   
  282. }
  283. //
  284. // TODO: Add your module definitions here.
  285. //
  286. VOID LoadImageRoutine(
  287.   __in_opt PUNICODE_STRING  FullImageName,
  288.   __in HANDLE  ProcessId,
  289.   __in PIMAGE_INFO  ImageInfo
  290. )
  291. {
  292.   if(wcsstr(FullImageName->Buffer, L"TesSafe.sys")!=0)
  293.   {
  294.    
  295.     DbgPrint("TesSafe has been discovered");
  296.     ULONG uImageInfo=(ULONG)ImageInfo->ImageBase;
  297.     DbgPrint("TesSafeBase is %x",uImageInfo);
  298.     TesSafeBase=uImageInfo;
  299.    
  300.     PMDL pMdl;
  301.     pMdl = IoAllocateMdl(_pMirror,0x139000,FALSE,FALSE,NULL);
  302.     MmProtectMdlSystemAddress(pMdl,PAGE_EXECUTE_READWRITE);
  303.     IoFreeMdl(pMdl);
  304.     //NtAllocateVirtualMemory((HANDLE)-1,pMirror,0,(PSIZE_T)0x139000,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
  305.     UnInLineHookEngine((int)_pMirror,(char *)TesSafeBase,0x139000);
  306.     //PassGlobalStaticCrcEx();
  307.     kdRet=(DWORD)KdDisableDebugger+0x7;
  308.     UnInLineHookEngine((int)mKdDisableDebugger,(char *)KdDisableDebugger,5);
  309.     InLineHookEngine((ULONG)KdDisableDebugger,(int)MyKdDisableDebugger);
  310.     DbgPrint("MirrorBase is %x",(int)pMirror);
  311.     if(*(PUCHAR)(pMirror+0x92c1)==0x75)
  312.     {
  313.       
  314.       *(PUSHORT)(pMirror+0x92c1)=0x9090;
  315.       DbgPrint("TesSafeOffset1 is %x",pMirror+0x92c1);
  316.     }
  317.     if(*(PUCHAR)(pMirror+0x92c1+0x12e)==0x74)
  318.     {
  319.       *(PUCHAR)(pMirror+0x92c1+0x12e)=0xeb;
  320.       DbgPrint("TesSafeOffset2 is %x",pMirror+0x92c1+0x12e);
  321.     }
  322.    
  323.   }
  324.   return;
  325. }
  326. /* EOF */
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-10-7 17:16:26 | 显示全部楼层
谢谢楼主分享
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-20 01:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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