forked from WKL-Sec/LayeredSyscall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuncWrappers.cpp
432 lines (396 loc) · 25.1 KB
/
FuncWrappers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#pragma once
#include <Windows.h>
#include <stdio.h>
#include "FuncWrappers.h"
#include "HookModule.h"
#include "imports.h"
FARPROC RetrieveSyscallAddress(const char* FuncName) {
return GetProcAddress(GetModuleHandleA("ntdll.dll"), FuncName);
}
///////////////////////////////////////////////
// Function Prototypes //
/////////////////////////////////////////////
typedef NTSTATUS(NTAPI* orgNtCreateProcess)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, HANDLE, BOOLEAN, HANDLE, HANDLE, HANDLE);
typedef NTSTATUS(NTAPI* orgNtCreateThreadEx)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, HANDLE, PVOID, PVOID, ULONG, SIZE_T, SIZE_T, SIZE_T, PPS_ATTRIBUTE_LIST);
typedef NTSTATUS(NTAPI* orgNtOpenProcess)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PCLIENT_ID);
typedef NTSTATUS(NTAPI* orgNtOpenProcessToken)(HANDLE, ACCESS_MASK, PHANDLE);
typedef NTSTATUS(NTAPI* orgNtOpenThread)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PCLIENT_ID);
typedef NTSTATUS(NTAPI* orgNtSuspendProcess)(HANDLE);
typedef NTSTATUS(NTAPI* orgNtSuspendThread)(HANDLE, PULONG);
typedef NTSTATUS(NTAPI* orgNtResumeProcess)(HANDLE);
typedef NTSTATUS(NTAPI* orgNtResumeThread)(HANDLE, PULONG);
typedef NTSTATUS(NTAPI* orgNtGetContextThread)(HANDLE, PCONTEXT);
typedef NTSTATUS(NTAPI* orgNtSetContextThread)(HANDLE, PCONTEXT);
typedef NTSTATUS(NTAPI* orgNtClose)(HANDLE);
typedef NTSTATUS(NTAPI* orgNtReadVirtualMemory)(HANDLE, PVOID, PVOID, SIZE_T, PSIZE_T);
typedef NTSTATUS(NTAPI* orgNtWriteVirtualMemory)(HANDLE, PVOID, PVOID, SIZE_T, PSIZE_T);
typedef NTSTATUS(NTAPI* orgNtAllocateVirtualMemory)(HANDLE, PVOID*, ULONG, PSIZE_T, ULONG, ULONG);
typedef NTSTATUS(NTAPI* orgNtProtectVirtualMemory)(HANDLE, PVOID*, PSIZE_T, ULONG, PULONG);
typedef NTSTATUS(NTAPI* orgNtFreeVirtualMemory)(HANDLE, PVOID*, PSIZE_T, ULONG);
typedef NTSTATUS(NTAPI* orgNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
typedef NTSTATUS(NTAPI* orgNtQueryDirectoryFile)(HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS, BOOLEAN, PUNICODE_STRING, BOOLEAN);
typedef NTSTATUS(NTAPI* orgNtQueryInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
typedef NTSTATUS(NTAPI* orgNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
typedef NTSTATUS(NTAPI* orgNtQueryInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG);
typedef NTSTATUS(NTAPI* orgNtCreateSection)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PLARGE_INTEGER, ULONG, ULONG, HANDLE);
typedef NTSTATUS(NTAPI* orgNtOpenSection)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
typedef NTSTATUS(NTAPI* orgNtMapViewOfSection)(HANDLE, HANDLE, PVOID, ULONG, SIZE_T, PLARGE_INTEGER, PSIZE_T, SECTION_INHERIT, ULONG, ULONG);
typedef NTSTATUS(NTAPI* orgNtUnmapViewOfSection)(HANDLE, PVOID);
typedef NTSTATUS(NTAPI* orgNtAdjustPrivilegesToken)(HANDLE, BOOLEAN, PTOKEN_PRIVILEGES, ULONG, PTOKEN_PRIVILEGES, PULONG);
typedef NTSTATUS(NTAPI* orgNtDeviceIoControlFile)(HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID, PIO_STATUS_BLOCK, ULONG, PVOID, ULONG, PVOID, ULONG);
typedef NTSTATUS(NTAPI* orgNtQueueApcThread)(HANDLE, PVOID, PVOID, PVOID, PVOID);
typedef NTSTATUS(NTAPI* orgNtWaitForMultipleObjects)(ULONG, PHANDLE, WAIT_TYPE, BOOLEAN, PLARGE_INTEGER);
typedef NTSTATUS(NTAPI* orgNtCreateUserProcess)(PHANDLE, PHANDLE, ACCESS_MASK, ACCESS_MASK, POBJECT_ATTRIBUTES, POBJECT_ATTRIBUTES, ULONG, ULONG, PRTL_USER_PROCESS_PARAMETERS, PPS_CREATE_INFO, PPS_ATTRIBUTE_LIST);
typedef NTSTATUS(NTAPI* orgNtAlertResumeThread)(HANDLE, PULONG);
ULONG wrpNtCreateProcess(PHANDLE ProcessHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, HANDLE ParentProcess, BOOLEAN InheritObjectTable, HANDLE SectionHandle, HANDLE DebugPort, HANDLE ExceptionPort) {
orgNtCreateProcess pNtCreateProcess = (orgNtCreateProcess)RetrieveSyscallAddress("NtCreateProcess");
if (pNtCreateProcess == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtCreateProcess\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtCreateProcess\n");
int ssn = GetSsnByName((PCHAR)"NtCreateProcess");
SetHwBp((ULONG_PTR)pNtCreateProcess, TRUE, ssn);
return pNtCreateProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ParentProcess, InheritObjectTable, SectionHandle, DebugPort, ExceptionPort);
}
ULONG wrpNtCreateThreadEx(PHANDLE ThreadHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, HANDLE ProcessHandle, PVOID StartRoutine, PVOID Argument, ULONG CreateFlags, SIZE_T ZeroBits, SIZE_T StackSize, SIZE_T MaximumStackSize, PPS_ATTRIBUTE_LIST AttributeList) {
orgNtCreateThreadEx pNtCreateThreadEx = (orgNtCreateThreadEx)RetrieveSyscallAddress("NtCreateThreadEx");
if (pNtCreateThreadEx == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtCreateThreadEx\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtCreateThreadEx\n");
int ssn = GetSsnByName((PCHAR)"NtCreateThreadEx");
SetHwBp((ULONG_PTR)pNtCreateThreadEx, TRUE, ssn);
return pNtCreateThreadEx(ThreadHandle, DesiredAccess, ObjectAttributes, ProcessHandle, StartRoutine, Argument, CreateFlags, ZeroBits, StackSize, MaximumStackSize, AttributeList);
}
ULONG wrpNtOpenProcess(PHANDLE ProcessHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PCLIENT_ID ClientId) {
orgNtOpenProcess pNtOpenProcess = (orgNtOpenProcess)RetrieveSyscallAddress("NtOpenProcess");
if (pNtOpenProcess == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtOpenProcess\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtOpenProcess\n");
int ssn = GetSsnByName((PCHAR)"NtOpenProcess");
SetHwBp((ULONG_PTR)pNtOpenProcess, TRUE, ssn);
return pNtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId);
}
ULONG wrpNtOpenProcessToken(HANDLE ProcessHandle, ACCESS_MASK DesiredAccess, PHANDLE TokenHandle) {
orgNtOpenProcessToken pNtOpenProcessToken = (orgNtOpenProcessToken)RetrieveSyscallAddress("NtOpenProcessToken");
if (pNtOpenProcessToken == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtOpenProcessToken\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtOpenProcessToken\n");
int ssn = GetSsnByName((PCHAR)"NtOpenProcessToken");
SetHwBp((ULONG_PTR)pNtOpenProcessToken, TRUE, ssn);
return pNtOpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle);
}
ULONG wrpNtOpenThread(PHANDLE ThreadHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PCLIENT_ID ClientId) {
orgNtOpenThread pNtOpenThread = (orgNtOpenThread)RetrieveSyscallAddress("NtOpenThread");
if (pNtOpenThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtOpenThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtOpenThread\n");
int ssn = GetSsnByName((PCHAR)"NtOpenThread");
SetHwBp((ULONG_PTR)pNtOpenThread, TRUE, ssn);
return pNtOpenThread(ThreadHandle, DesiredAccess, ObjectAttributes, ClientId);
}
ULONG wrpNtSuspendProcess(HANDLE ProcessHandle) {
orgNtSuspendProcess pNtSuspendProcess = (orgNtSuspendProcess)RetrieveSyscallAddress("NtSuspendProcess");
if (pNtSuspendProcess == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtSuspendProcess\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtSuspendProcess\n");
int ssn = GetSsnByName((PCHAR)"NtSuspendProcess");
SetHwBp((ULONG_PTR)pNtSuspendProcess, TRUE, ssn);
return pNtSuspendProcess(ProcessHandle);
}
ULONG wrpNtSuspendThread(HANDLE ThreadHandle, PULONG PreviousSuspendCount) {
orgNtSuspendThread pNtSuspendThread = (orgNtSuspendThread)RetrieveSyscallAddress("NtSuspendThread");
if (pNtSuspendThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtSuspendThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtSuspendThread\n");
int ssn = GetSsnByName((PCHAR)"NtSuspendThread");
SetHwBp((ULONG_PTR)pNtSuspendThread, TRUE, ssn);
return pNtSuspendThread(ThreadHandle, PreviousSuspendCount);
}
ULONG wrpNtResumeProcess(HANDLE ProcessHandle) {
orgNtResumeProcess pNtResumeProcess = (orgNtResumeProcess)RetrieveSyscallAddress("NtResumeProcess");
if (pNtResumeProcess == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtResumeProcess\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtResumeProcess\n");
int ssn = GetSsnByName((PCHAR)"NtResumeProcess");
SetHwBp((ULONG_PTR)pNtResumeProcess, TRUE, ssn);
return pNtResumeProcess(ProcessHandle);
}
ULONG wrpNtResumeThread(HANDLE ThreadHandle, PULONG PreviousSuspendCount) {
orgNtResumeThread pNtResumeThread = (orgNtResumeThread)RetrieveSyscallAddress("NtResumeThread");
if (pNtResumeThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtResumeThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtResumeThread\n");
int ssn = GetSsnByName((PCHAR)"NtResumeThread");
SetHwBp((ULONG_PTR)pNtResumeThread, TRUE, ssn);
return pNtResumeThread(ThreadHandle, PreviousSuspendCount);
}
ULONG wrpNtGetContextThread(HANDLE ThreadHandle, PCONTEXT ThreadContext) {
orgNtGetContextThread pNtGetContextThread = (orgNtGetContextThread)RetrieveSyscallAddress("NtGetContextThread");
if (pNtGetContextThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtGetContextThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtGetContextThread\n");
int ssn = GetSsnByName((PCHAR)"NtGetContextThread");
SetHwBp((ULONG_PTR)pNtGetContextThread, TRUE, ssn);
return pNtGetContextThread(ThreadHandle, ThreadContext);
}
ULONG wrpNtSetContextThread(HANDLE ThreadHandle, PCONTEXT Context) {
orgNtSetContextThread pNtSetContextThread = (orgNtSetContextThread)RetrieveSyscallAddress("NtSetContextThread");
if (pNtSetContextThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtSetContextThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtSetContextThread\n");
int ssn = GetSsnByName((PCHAR)"NtSetContextThread");
SetHwBp((ULONG_PTR)pNtSetContextThread, TRUE, ssn);
return pNtSetContextThread(ThreadHandle, Context);
}
ULONG wrpNtClose(HANDLE Handle) {
orgNtClose pNtClose = (orgNtClose)RetrieveSyscallAddress("NtClose");
if (pNtClose == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtClose\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtClose\n");
int ssn = GetSsnByName((PCHAR)"NtClose");
SetHwBp((ULONG_PTR)pNtClose, TRUE, ssn);
return pNtClose(Handle);
}
ULONG wrpNtReadVirtualMemory(HANDLE ProcessHandle, PVOID BaseAddress, PVOID Buffer, SIZE_T BufferSize, PSIZE_T NumberOfBytesRead) {
orgNtReadVirtualMemory pNtReadVirtualMemory = (orgNtReadVirtualMemory)RetrieveSyscallAddress("NtReadVirtualMemory");
if (pNtReadVirtualMemory == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtReadVirtualMemory\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtReadVirtualMemory\n");
int ssn = GetSsnByName((PCHAR)"NtReadVirtualMemory");
SetHwBp((ULONG_PTR)pNtReadVirtualMemory, TRUE, ssn);
return pNtReadVirtualMemory(ProcessHandle, BaseAddress, Buffer, BufferSize, NumberOfBytesRead);
}
ULONG wrpNtWriteVirtualMemory(HANDLE ProcessHandle, PVOID BaseAddress, PVOID Buffer, SIZE_T NumberOfBytesToWrite, PSIZE_T NumberOfBytesWritten) {
orgNtWriteVirtualMemory pNtWriteVirtualMemory = (orgNtWriteVirtualMemory)RetrieveSyscallAddress("NtWriteVirtualMemory");
if (pNtWriteVirtualMemory == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtWriteVirtualMemory\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtWriteVirtualMemory\n");
int ssn = GetSsnByName((PCHAR)"NtWriteVirtualMemory");
SetHwBp((ULONG_PTR)pNtWriteVirtualMemory, TRUE, ssn);
return pNtWriteVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten);
}
ULONG wrpNtAllocateVirtualMemory(HANDLE ProcessHandle, PVOID* BaseAddress, ULONG ZeroBits, PSIZE_T RegionSize, ULONG AllocationType, ULONG Protect) {
orgNtAllocateVirtualMemory pNtAllocateVirtualMemory = (orgNtAllocateVirtualMemory)RetrieveSyscallAddress("NtAllocateVirtualMemory");
if (pNtAllocateVirtualMemory == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtAllocateVirtualMemory\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtAllocateVirtualMemory\n");
int ssn = GetSsnByName((PCHAR)"NtAllocateVirtualMemory");
SetHwBp((ULONG_PTR)pNtAllocateVirtualMemory, TRUE, ssn);
return pNtAllocateVirtualMemory(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect);
}
ULONG wrpNtProtectVirtualMemory(HANDLE ProcessHandle, PVOID* BaseAddress, PSIZE_T RegionSize, ULONG NewProtect, PULONG OldProtect) {
orgNtProtectVirtualMemory pNtProtectVirtualMemory = (orgNtProtectVirtualMemory)RetrieveSyscallAddress("NtProtectVirtualMemory");
if (pNtProtectVirtualMemory == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtProtectVirtualMemory\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtProtectVirtualMemory\n");
int ssn = GetSsnByName((PCHAR)"NtProtectVirtualMemory");
SetHwBp((ULONG_PTR)pNtProtectVirtualMemory, TRUE, ssn);
return pNtProtectVirtualMemory(ProcessHandle, BaseAddress, RegionSize, NewProtect, OldProtect);
}
ULONG wrpNtFreeVirtualMemory(HANDLE ProcessHandle, PVOID* BaseAddress, PSIZE_T RegionSize, ULONG FreeType) {
orgNtFreeVirtualMemory pNtFreeVirtualMemory = (orgNtFreeVirtualMemory)RetrieveSyscallAddress("NtFreeVirtualMemory");
if (pNtFreeVirtualMemory == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtFreeVirtualMemory\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtFreeVirtualMemory\n");
int ssn = GetSsnByName((PCHAR)"NtFreeVirtualMemory");
SetHwBp((ULONG_PTR)pNtFreeVirtualMemory, TRUE, ssn);
return pNtFreeVirtualMemory(ProcessHandle, BaseAddress, RegionSize, FreeType);
}
ULONG wrpNtQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength) {
orgNtQuerySystemInformation pNtQuerySystemInformation = (orgNtQuerySystemInformation)RetrieveSyscallAddress("NtQuerySystemInformation");
if (pNtQuerySystemInformation == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtQuerySystemInformation\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtQuerySystemInformation\n");
int ssn = GetSsnByName((PCHAR)"NtQuerySystemInformation");
SetHwBp((ULONG_PTR)pNtQuerySystemInformation, TRUE, ssn);
return pNtQuerySystemInformation(SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength);
}
ULONG wrpNtQueryDirectoryFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass, BOOLEAN ReturnSingleEntry, PUNICODE_STRING FileName, BOOLEAN RestartScan) {
orgNtQueryDirectoryFile pNtQueryDirectoryFile = (orgNtQueryDirectoryFile)RetrieveSyscallAddress("NtQueryDirectoryFile");
if (pNtQueryDirectoryFile == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtQueryDirectoryFile\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtQueryDirectoryFile\n");
int ssn = GetSsnByName((PCHAR)"NtQueryDirectoryFile");
SetHwBp((ULONG_PTR)pNtQueryDirectoryFile, TRUE, ssn);
return pNtQueryDirectoryFile(FileHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, FileInformation, Length, FileInformationClass, ReturnSingleEntry, FileName, RestartScan);
}
ULONG wrpNtQueryInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass) {
orgNtQueryInformationFile pNtQueryInformationFile = (orgNtQueryInformationFile)RetrieveSyscallAddress("NtQueryInformationFile");
if (pNtQueryInformationFile == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtQueryInformationFile\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtQueryInformationFile\n");
int ssn = GetSsnByName((PCHAR)"NtQueryInformationFile");
SetHwBp((ULONG_PTR)pNtQueryInformationFile, TRUE, ssn);
return pNtQueryInformationFile(FileHandle, IoStatusBlock, FileInformation, Length, FileInformationClass);
}
ULONG wrpNtQueryInformationProcess(HANDLE ProcessHandle, PROCESSINFOCLASS ProcessInformationClass, PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG ReturnLength) {
orgNtQueryInformationProcess pNtQueryInformationProcess = (orgNtQueryInformationProcess)RetrieveSyscallAddress("NtQueryInformationProcess");
if (pNtQueryInformationProcess == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtQueryInformationProcess\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtQueryInformationProcess\n");
int ssn = GetSsnByName((PCHAR)"NtQueryInformationProcess");
SetHwBp((ULONG_PTR)pNtQueryInformationProcess, TRUE, ssn);
return pNtQueryInformationProcess(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength, ReturnLength);
}
ULONG wrpNtQueryInformationThread(HANDLE ThreadHandle, THREADINFOCLASS ThreadInformationClass, PVOID ThreadInformation, ULONG ThreadInformationLength, PULONG ReturnLength) {
orgNtQueryInformationThread pNtQueryInformationThread = (orgNtQueryInformationThread)RetrieveSyscallAddress("NtQueryInformationThread");
if (pNtQueryInformationThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtQueryInformationThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtQueryInformationThread\n");
int ssn = GetSsnByName((PCHAR)"NtQueryInformationThread");
SetHwBp((ULONG_PTR)pNtQueryInformationThread, TRUE, ssn);
return pNtQueryInformationThread(ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength, ReturnLength);
}
ULONG wrpNtCreateSection(PHANDLE SectionHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PLARGE_INTEGER MaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, HANDLE FileHandle) {
orgNtCreateSection pNtCreateSection = (orgNtCreateSection)RetrieveSyscallAddress("NtCreateSection");
if (pNtCreateSection == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtCreateSection\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtCreateSection\n");
int ssn = GetSsnByName((PCHAR)"NtCreateSection");
SetHwBp((ULONG_PTR)pNtCreateSection, TRUE, ssn);
return pNtCreateSection(SectionHandle, DesiredAccess, ObjectAttributes, MaximumSize, SectionPageProtection, AllocationAttributes, FileHandle);
}
ULONG wrpNtOpenSection(PHANDLE SectionHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes) {
orgNtOpenSection pNtOpenSection = (orgNtOpenSection)RetrieveSyscallAddress("NtOpenSection");
if (pNtOpenSection == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtOpenSection\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtOpenSection\n");
int ssn = GetSsnByName((PCHAR)"NtOpenSection");
SetHwBp((ULONG_PTR)pNtOpenSection, TRUE, ssn);
return pNtOpenSection(SectionHandle, DesiredAccess, ObjectAttributes);
}
ULONG wrpNtMapViewOfSection(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID BaseAddress, ULONG ZeroBits, SIZE_T CommitSize, PLARGE_INTEGER SectionOffset, PSIZE_T ViewSize, SECTION_INHERIT InheritDisposition, ULONG AllocationType, ULONG Win32Protect) {
orgNtMapViewOfSection pNtMapViewOfSection = (orgNtMapViewOfSection)RetrieveSyscallAddress("NtMapViewOfSection");
if (pNtMapViewOfSection == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtMapViewOfSection\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtMapViewOfSection\n");
int ssn = GetSsnByName((PCHAR)"NtMapViewOfSection");
SetHwBp((ULONG_PTR)pNtMapViewOfSection, TRUE, ssn);
return pNtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect);
}
ULONG wrpNtUnmapViewOfSection(HANDLE ProcessHandle, PVOID BaseAddress) {
orgNtUnmapViewOfSection pNtUnmapViewOfSection = (orgNtUnmapViewOfSection)RetrieveSyscallAddress("NtUnmapViewOfSection");
if (pNtUnmapViewOfSection == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtUnmapViewOfSection\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtUnmapViewOfSection\n");
int ssn = GetSsnByName((PCHAR)"NtUnmapViewOfSection");
SetHwBp((ULONG_PTR)pNtUnmapViewOfSection, TRUE, ssn);
return pNtUnmapViewOfSection(ProcessHandle, BaseAddress);
}
ULONG wrpNtAdjustPrivilegesToken(HANDLE TokenHandle, BOOLEAN DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, ULONG BufferLength, PTOKEN_PRIVILEGES PreviousState, PULONG ReturnLength) {
orgNtAdjustPrivilegesToken pNtAdjustPrivilegesToken = (orgNtAdjustPrivilegesToken)RetrieveSyscallAddress("NtAdjustPrivilegesToken");
if (pNtAdjustPrivilegesToken == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtAdjustPrivilegesToken\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtAdjustPrivilegesToken\n");
int ssn = GetSsnByName((PCHAR)"NtAdjustPrivilegesToken");
SetHwBp((ULONG_PTR)pNtAdjustPrivilegesToken, TRUE, ssn);
return pNtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength);
}
ULONG wrpNtDeviceIoControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG IoControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength) {
orgNtDeviceIoControlFile pNtDeviceIoControlFile = (orgNtDeviceIoControlFile)RetrieveSyscallAddress("NtDeviceIoControlFile");
if (pNtDeviceIoControlFile == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtDeviceIoControlFile\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtDeviceIoControlFile\n");
int ssn = GetSsnByName((PCHAR)"NtDeviceIoControlFile");
SetHwBp((ULONG_PTR)pNtDeviceIoControlFile, TRUE, ssn);
return pNtDeviceIoControlFile(FileHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, IoControlCode, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength);
}
ULONG wrpNtQueueApcThread(HANDLE ThreadHandle, PVOID ApcRoutine, PVOID ApcArgument1, PVOID ApcArgument2, PVOID ApcArgument3) {
orgNtQueueApcThread pNtQueueApcThread = (orgNtQueueApcThread)RetrieveSyscallAddress("NtQueueApcThread");
if (pNtQueueApcThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtQueueApcThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtQueueApcThread\n");
int ssn = GetSsnByName((PCHAR)"NtQueueApcThread");
SetHwBp((ULONG_PTR)pNtQueueApcThread, TRUE, ssn);
return pNtQueueApcThread(ThreadHandle, ApcRoutine, ApcArgument1, ApcArgument2, ApcArgument3);
}
ULONG wrpNtWaitForMultipleObjects(ULONG Count, PHANDLE Handles, WAIT_TYPE WaitType, BOOLEAN Alertable, PLARGE_INTEGER Timeout) {
orgNtWaitForMultipleObjects pNtWaitForMultipleObjects = (orgNtWaitForMultipleObjects)RetrieveSyscallAddress("NtWaitForMultipleObjects");
if (pNtWaitForMultipleObjects == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtWaitForMultipleObjects\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtWaitForMultipleObjects\n");
int ssn = GetSsnByName((PCHAR)"NtWaitForMultipleObjects");
SetHwBp((ULONG_PTR)pNtWaitForMultipleObjects, TRUE, ssn);
return pNtWaitForMultipleObjects(Count, Handles, WaitType, Alertable, Timeout);
}
ULONG wrpNtCreateUserProcess(PHANDLE ProcessHandle, PHANDLE ThreadHandle, ACCESS_MASK ProcessDesiredAccess, ACCESS_MASK ThreadDesiredAccess, POBJECT_ATTRIBUTES ProcessObjectAttributes, POBJECT_ATTRIBUTES ThreadObjectAttributes, ULONG ProcessFlags, ULONG ThreadFlags, PRTL_USER_PROCESS_PARAMETERS ProcessParameters, PPS_CREATE_INFO CreateInfo, PPS_ATTRIBUTE_LIST AttributeList) {
orgNtCreateUserProcess pNtCreateUserProcess = (orgNtCreateUserProcess)RetrieveSyscallAddress("NtCreateUserProcess");
if (pNtCreateUserProcess == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtCreateUserProcess\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtCreateUserProcess\n");
int ssn = GetSsnByName((PCHAR)"NtCreateUserProcess");
SetHwBp((ULONG_PTR)pNtCreateUserProcess, TRUE, ssn);
return pNtCreateUserProcess(ProcessHandle, ThreadHandle, ProcessDesiredAccess, ThreadDesiredAccess, ProcessObjectAttributes, ThreadObjectAttributes, ProcessFlags, ThreadFlags, ProcessParameters, CreateInfo, AttributeList);
}
ULONG wrpNtAlertResumeThread(HANDLE ThreadHandle, PULONG PreviousSuspendCount) {
orgNtAlertResumeThread pNtAlertResumeThread = (orgNtAlertResumeThread)RetrieveSyscallAddress("NtAlertResumeThread");
if (pNtAlertResumeThread == NULL) {
printf("[!] Unable to resolve ntdll.dll!NtAlertResumeThread\n");
return -1;
}
printf("[*] Calling function ntdll.dll!NtAlertResumeThread\n");
int ssn = GetSsnByName((PCHAR)"NtAlertResumeThread");
SetHwBp((ULONG_PTR)pNtAlertResumeThread, TRUE, ssn);
return pNtAlertResumeThread(ThreadHandle, PreviousSuspendCount);
}