Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
callbacks.cpp
Go to the documentation of this file.
1#include "callbacks.h"
2#include <ntstrsafe.h>
3#include "shellcode.h"
4#include "event_queue.h"
5#include "inject_exclusions.h"
6
7RTL_AVL_TABLE g_ProcessList;
8LARGE_INTEGER g_RegistryCookie;
9
10// https://github.com/wbenny/injdrv/blob/a8dadf43a09f33c33a3957a250cb7ee05a986608/src/injlib/injlib.c#L404
11PVOID
12NTAPI
14 _In_ PVOID DllBase,
15 _In_ PANSI_STRING ExportName)
16{
17 //
18 // RtlFindExportedRoutineByName is not exported by ntoskrnl until Win10.
19 // Following code is borrowed from ReactOS.
20 //
21
22 PULONG NameTable;
23 PUSHORT OrdinalTable;
24 PIMAGE_EXPORT_DIRECTORY ExportDirectory;
25 LONG Low = 0, Mid = 0, High, Ret;
26 USHORT Ordinal;
27 PVOID Function;
28 ULONG ExportSize;
29 PULONG ExportTable;
30
31 //
32 // Get the export directory.
33 //
34
35 ExportDirectory = (PIMAGE_EXPORT_DIRECTORY)RtlImageDirectoryEntryToData(DllBase,
36 TRUE,
37 IMAGE_DIRECTORY_ENTRY_EXPORT,
38 &ExportSize);
39
40 if (!ExportDirectory)
41 {
42 return NULL;
43 }
44
45 //
46 // Setup name tables.
47 //
48
49 NameTable = (PULONG)((ULONG_PTR)DllBase + ExportDirectory->AddressOfNames);
50 OrdinalTable = (PUSHORT)((ULONG_PTR)DllBase + ExportDirectory->AddressOfNameOrdinals);
51
52 //
53 // Do a binary search.
54 //
55
56 High = ExportDirectory->NumberOfNames - 1;
57 while (High >= Low)
58 {
59 //
60 // Get new middle value.
61 //
62
63 Mid = (Low + High) >> 1;
64
65 //
66 // Compare name.
67 //
68
69 Ret = strcmp(ExportName->Buffer, (PCHAR)DllBase + NameTable[Mid]);
70 if (Ret < 0)
71 {
72 //
73 // Update high.
74 //
75 High = Mid - 1;
76 }
77 else if (Ret > 0)
78 {
79 //
80 // Update low.
81 //
82 Low = Mid + 1;
83 }
84 else
85 {
86 //
87 // We got it.
88 //
89 break;
90 }
91 }
92
93 //
94 // Check if we couldn't find it.
95 //
96
97 if (High < Low)
98 {
99 return NULL;
100 }
101
102 //
103 // Otherwise, this is the ordinal.
104 //
105
106 Ordinal = OrdinalTable[Mid];
107
108 //
109 // Validate the ordinal.
110 //
111
112 if (Ordinal >= ExportDirectory->NumberOfFunctions)
113 {
114 return NULL;
115 }
116
117 //
118 // Resolve the address and write it.
119 //
120
121 ExportTable = (PULONG)((ULONG_PTR)DllBase + ExportDirectory->AddressOfFunctions);
122 Function = (PVOID)((ULONG_PTR)DllBase + ExportTable[Ordinal]);
123
124 //
125 // We found it!
126 //
127
128 NT_ASSERT(
129 (Function < (PVOID)ExportDirectory) ||
130 (Function > (PVOID)((ULONG_PTR)ExportDirectory + ExportSize)));
131
132 return Function;
133}
134
143static BOOLEAN RequiresMicrosoftSignedImages(PEPROCESS Process)
144{
145 // A kernel handle opened with KernelMode access skips the access check, so this works
146 // from any process context
147 HANDLE processHandle = NULL;
148 NTSTATUS status = ObOpenObjectByPointer(
149 Process,
150 OBJ_KERNEL_HANDLE,
151 NULL,
152 0x1000, // PROCESS_QUERY_LIMITED_INFORMATION
153 *PsProcessType,
154 KernelMode,
155 &processHandle);
156 if (!NT_SUCCESS(status))
157 {
158 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[-] Panoptes: Failed to open process to query its signature policy, status: 0x%X\n", status);
159 return FALSE;
160 }
161
163 policyInfo.Policy = ProcessSignaturePolicy;
164 status = ZwQueryInformationProcess(processHandle, ProcessMitigationPolicy, &policyInfo, sizeof(policyInfo), NULL);
165 ZwClose(processHandle);
166 if (!NT_SUCCESS(status))
167 {
168 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[-] Panoptes: Failed to query process signature policy, status: 0x%X\n", status);
169 return FALSE;
170 }
171
172 // The Audit* flags only log, so the DLL still loads with them
173 const PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY &signaturePolicy = policyInfo.Data.SignaturePolicy;
174 return signaturePolicy.MicrosoftSignedOnly || signaturePolicy.StoreSignedOnly || signaturePolicy.MitigationOptIn;
175}
176
177RTL_GENERIC_COMPARE_RESULTS NTAPI ProcessInfoCompareRoutine(PRTL_AVL_TABLE Table, PVOID FirstStruct, PVOID SecondStruct)
178{
179 UNREFERENCED_PARAMETER(Table);
180 ULONG_PTR first = (ULONG_PTR)((PPANO_PROCESS_INFO)FirstStruct)->ProcessId;
181 ULONG_PTR second = (ULONG_PTR)((PPANO_PROCESS_INFO)SecondStruct)->ProcessId;
182
183 if (first < second)
184 {
185 return GenericLessThan;
186 }
187 if (first > second)
188 {
189 return GenericGreaterThan;
190 }
191 return GenericEqual;
192}
193
194PVOID NTAPI ProcessInfoAllocateRoutine(PRTL_AVL_TABLE Table, CLONG ByteSize)
195{
196 UNREFERENCED_PARAMETER(Table);
197 return ExAllocatePool2(POOL_FLAG_NON_PAGED, ByteSize, 'corP');
198}
199
200VOID NTAPI ProcessInfoFreeRoutine(PRTL_AVL_TABLE Table, PVOID Buffer)
201{
202 UNREFERENCED_PARAMETER(Table);
203 ExFreePoolWithTag(Buffer, 'corP');
204}
205
207{
208 PANO_PROCESS_INFO key{};
209 key.ProcessId = ProcessId;
210 return (PPANO_PROCESS_INFO)RtlLookupElementGenericTableAvl(&g_ProcessList, &key);
211}
212
213VOID RemoveProcessInfo(HANDLE ProcessId)
214{
215 PANO_PROCESS_INFO key{};
216 key.ProcessId = ProcessId;
217 RtlDeleteElementGenericTableAvl(&g_ProcessList, &key);
218}
219
220void NTAPI KernelRoutine(PKAPC apc, PKNORMAL_ROUTINE *NormalRoutine, PVOID *NormalContext, PVOID *SystemArgument1, PVOID *SystemArgument2)
221{
222 UNREFERENCED_PARAMETER(NormalRoutine);
223 UNREFERENCED_PARAMETER(NormalContext);
224 UNREFERENCED_PARAMETER(SystemArgument1);
225 UNREFERENCED_PARAMETER(SystemArgument2);
226
227 ExFreePool(apc);
228}
229
231{
232 PUNICODE_STRING DLLPath;
233 PUNICODE_STRING DllName;
235};
236
237BOOLEAN CanInject(PPANO_PROCESS_INFO processInfo)
238{
239 if (processInfo->ntdllLoaded && processInfo->kernel32Loaded && processInfo->kernelBaseLoaded)
240 {
241 return TRUE;
242 }
243 return FALSE;
244}
245
246VOID InjectDllKernelApc(PVOID NormalContext, PVOID SystemArgument1, PVOID SystemArgument2)
247{
248 DbgPrint("InjectDll Entered");
249 HANDLE pProcessId = (HANDLE)NormalContext;
250 UNREFERENCED_PARAMETER(SystemArgument1);
251 UNREFERENCED_PARAMETER(SystemArgument2);
252
253 if (nullptr == pProcessId)
254 {
255 DbgPrint("InjectDll - pProcessId is null");
256 return;
257 }
258
259 PPANO_PROCESS_INFO pi = GetProcessInfo(pProcessId);
260 if (pi == nullptr)
261 {
262 DbgPrint("InjectDll - process is not tracked");
263 return;
264 }
265
266 ANSI_STRING loadDllRoutineName = RTL_CONSTANT_STRING("LoadLibraryExW");
267 PVOID shellcodeAddress = RtlxFindExportedRoutineByName(pi->kernel32BaseAddress, &loadDllRoutineName);
268 if (shellcodeAddress == nullptr)
269 {
270 // Queuing an APC to a NULL routine would crash the process
271 DbgPrint("Error: LoadLibraryExW was not found in kernel32.");
272 return;
273 }
274
275 UNICODE_STRING dllToInject;
276 PVOID allocatedAddressContainingDllFullPath = nullptr;
277
278 if (pi->is64Bit)
279 {
280 RtlInitUnicodeString(&dllToInject, L"C:\\Program Files\\Panoptes\\PanoptesDLLx64.dll");
281 }
282 else
283 {
284 RtlInitUnicodeString(&dllToInject, L"C:\\Program Files\\Panoptes\\PanoptesDLLx86.dll");
285 }
286
287 // Room for the path and its terminator. ZwAllocateVirtualMemory takes and returns a SIZE_T,
288 // so it gets its own variable rather than a pointer to the USHORT dllToInject.Length.
289 // The allocation is rounded up to whole pages, which are zero-filled
290 SIZE_T regionSize = dllToInject.Length + sizeof(WCHAR);
291
292 // A 32-bit process's LoadLibraryExW takes a 32-bit pointer, so its copy of the path must be
293 // below 2 GB. A ZeroBits value above 32 is a mask the allocation's address must fit in
294 ULONG_PTR zeroBits = pi->is64Bit ? 0 : 0x7FFFFFFF;
295 NTSTATUS status = ZwAllocateVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, zeroBits, &regionSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
296 if (!NT_SUCCESS(status))
297 {
298 DbgPrint("Error: Unable to allocate memory in the target process.");
299 return;
300 }
301 RtlCopyMemory(allocatedAddressContainingDllFullPath, dllToInject.Buffer, dllToInject.Length);
302
303 // MEM_RELEASE frees the whole allocation and requires a size of 0
304 SIZE_T releaseSize = 0;
305
306 PKAPC pKapc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(KAPC), 'tikt'); // Allocate the APC object
307 if (!pKapc)
308 {
309 DbgPrint("Error: Unable to allocate the APC object.");
310 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, &releaseSize, MEM_RELEASE); // Free the allocated memory
311 return;
312 }
313
314 // User-mode APCs are delivered by the native 64-bit dispatcher. For a 32-bit process the
315 // routine is the 32-bit kernel32's LoadLibraryExW, which must run in 32-bit mode: wrapping
316 // the APC makes WOW64 switch modes and call it. Without this the dispatcher runs 32-bit
317 // code as 64-bit code and the process crashes
318 PVOID apcRoutine = shellcodeAddress;
319 PVOID apcContext = allocatedAddressContainingDllFullPath;
320 if (!pi->is64Bit)
321 {
322 status = PsWrapApcWow64Thread(&apcContext, &apcRoutine);
323 if (!NT_SUCCESS(status))
324 {
325 DbgPrint("Error: Unable to wrap the APC for a WOW64 process.");
326 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, &releaseSize, MEM_RELEASE);
327 ExFreePool(pKapc);
328 return;
329 }
330 }
331
332 KeInitializeApc(pKapc, KeGetCurrentThread(), OriginalApcEnvironment, KernelRoutine, NULL, (PKNORMAL_ROUTINE)apcRoutine, UserMode, apcContext); // Initialize the APC
333
334 DbgPrint("Inserting APC to target thread");
335 if (!KeInsertQueueApc(pKapc, NULL, NULL, IO_NO_INCREMENT))
336 {
337 DbgPrint("Error: Unable to insert APC to target thread.");
338 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, &releaseSize, MEM_RELEASE); // Free the allocated memory
339 ExFreePool(pKapc); // Free the APC object
340 return;
341 }
342
343 KeTestAlertThread(UserMode);
344
345 DbgPrint("InjectDllKernelApc exiting");
346}
347
348NTSTATUS InstallKernelModeApcToInjectDll(HANDLE ProcessId)
349{
350 PRKAPC pKapc = nullptr;
351 PETHREAD pThread = nullptr;
352
353 pKapc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(KAPC), 'tiky'); // Allocate the APC object
354 if (nullptr == pKapc)
355 {
356 DbgPrint("InstallKernelModeApcToInjectDll Failed to allocate memory for the APC");
357 return STATUS_INSUFFICIENT_RESOURCES;
358 }
359
360 pThread = KeGetCurrentThread();
361 KeInitializeApc(pKapc, pThread,
363 KernelRoutine, NULL,
365 KernelMode, (PVOID)ProcessId);
366 if (!KeInsertQueueApc(pKapc, NULL, NULL, IO_NO_INCREMENT))
367 {
368 DbgPrint("InstallKernelModeApcToInjectDll Failed to insert APC");
369 ExFreePool(pKapc); // Free the APC object
370 return STATUS_UNSUCCESSFUL;
371 }
372 else
373 {
374 DbgPrint("InstallKernelModeApcToInjectDll APC delivered");
375 }
376
377 return STATUS_SUCCESS;
378}
379
380BOOLEAN Is64BitProcess(PEPROCESS targetProcess)
381{
382 // Rather than reading EPROCESS.WoW64Process at a fixed offset, which differs between
383 // Windows builds
384 return PsGetProcessWow64Process(targetProcess) == NULL;
385}
386
387#pragma region Registry Events
388
389#define PANO_REGISTRY_POOL_TAG 'gRoP' // "PoRg"
390
391// Decides whether a registry operation on the current thread is reported, and fills in who made
392// it. The service's own registry activity is not reported, as with its file activity
393static BOOLEAN BeginRegistryEvent(UINT64* ProcessId, UINT64* ThreadId, UINT32* Flags)
394{
395 *ProcessId = (UINT64)PsGetCurrentProcessId();
396 if (EventQueueIsConsumerProcess(*ProcessId))
397 {
398 return FALSE;
399 }
400
401 *ThreadId = (UINT64)PsGetCurrentThreadId();
402 *Flags = (ExGetPreviousMode() == KernelMode) ? PANO_FLAG_KERNEL_MODE_CALLER : 0;
403 return TRUE;
404}
405
406// Gets the full name (\REGISTRY\MACHINE\...) of a key object. Release a non-NULL result with
407// CmCallbackReleaseKeyObjectIDEx
408static PCUNICODE_STRING GetRegistryKeyName(PVOID KeyObject)
409{
410 PCUNICODE_STRING name = NULL;
411 if (KeyObject == NULL || !NT_SUCCESS(CmCallbackGetKeyObjectIDEx(&g_RegistryCookie, KeyObject, NULL, &name, 0)))
412 {
413 return NULL;
414 }
415 return name;
416}
417
418// Copies a buffer passed with a registry operation into pool. For a call from user mode the
419// buffer can be the caller's own memory: the system call has checked that it is user memory, but
420// the caller can still change or free it at any time, so it is only read under __try. Returns
421// NULL and sets *Failed if it could not be copied. Free a non-NULL result with ExFreePoolWithTag
422static PVOID CaptureRegistryBuffer(const void* Buffer, SIZE_T Length, UINT32* Flags)
423{
424 if (Buffer == NULL || Length == 0)
425 {
426 return NULL;
427 }
428
429 PVOID copy = ExAllocatePool2(POOL_FLAG_PAGED, Length, PANO_REGISTRY_POOL_TAG);
430 if (copy == NULL)
431 {
432 *Flags |= PANO_FLAG_CAPTURE_FAILED;
433 return NULL;
434 }
435
436 __try
437 {
438 RtlCopyMemory(copy, Buffer, Length);
439 }
440 __except (EXCEPTION_EXECUTE_HANDLER)
441 {
442 ExFreePoolWithTag(copy, PANO_REGISTRY_POOL_TAG);
443 *Flags |= PANO_FLAG_CAPTURE_FAILED;
444 return NULL;
445 }
446 return copy;
447}
448
449// Copies a UNICODE_STRING passed with a registry operation into pool, under the same rules as
450// CaptureRegistryBuffer (the UNICODE_STRING itself is read under __try too). Returns NULL with
451// *Length 0 for a missing or empty string. Free a non-NULL result with ExFreePoolWithTag
452static PWCH CaptureRegistryString(PCUNICODE_STRING String, UINT32* Length, UINT32* Flags)
453{
454 *Length = 0;
455 if (String == NULL)
456 {
457 return NULL;
458 }
459
460 UNICODE_STRING string;
461 __try
462 {
463 string = *String;
464 }
465 __except (EXCEPTION_EXECUTE_HANDLER)
466 {
467 *Flags |= PANO_FLAG_CAPTURE_FAILED;
468 return NULL;
469 }
470
471 UINT32 length = string.Length / sizeof(WCHAR);
472 PWCH copy = (PWCH)CaptureRegistryBuffer(string.Buffer, length * sizeof(WCHAR), Flags);
473 if (copy != NULL)
474 {
475 *Length = length;
476 }
477 return copy;
478}
479
480static void FreeRegistryBuffer(PVOID Buffer)
481{
482 if (Buffer != NULL)
483 {
484 ExFreePoolWithTag(Buffer, PANO_REGISTRY_POOL_TAG);
485 }
486}
487
488static void ReleaseRegistryKeyName(PCUNICODE_STRING KeyName)
489{
490 if (KeyName != NULL)
491 {
492 CmCallbackReleaseKeyObjectIDEx(KeyName);
493 }
494}
495
496// Reports an event that carries only a key name: the full name of KeyObject
497static void ReportRegistryKeyEvent(PANO_EVENT_TYPE Type, PVOID KeyObject)
498{
499 UINT64 processId, threadId;
500 UINT32 flags;
501 if (!BeginRegistryEvent(&processId, &threadId, &flags))
502 {
503 return;
504 }
505
506 PCUNICODE_STRING keyName = GetRegistryKeyName(KeyObject);
507 if (keyName == NULL)
508 {
510 }
511
513 Type,
514 processId,
515 threadId,
516 flags,
517 0,
518 0,
519 keyName ? keyName->Buffer : NULL,
520 keyName ? keyName->Length / sizeof(WCHAR) : 0,
521 NULL,
522 0,
523 NULL,
524 0);
525
526 ReleaseRegistryKeyName(keyName);
527}
528
529// Reports a value about to be written. Persistence (Run keys, services, IFEO, COM hijacks) and
530// defence tampering are mostly value writes, so the value name and the start of its data are sent
531static void ReportSetValueKey(PREG_SET_VALUE_KEY_INFORMATION Info)
532{
533 UINT64 processId, threadId;
534 UINT32 flags;
535 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
536 {
537 return;
538 }
539
540 UINT32 valueNameLength;
541 PWCH valueName = CaptureRegistryString(Info->ValueName, &valueNameLength, &flags);
542
543 UINT32 dataLength = min(Info->DataSize, (ULONG)PANO_MAX_REGISTRY_DATA_SIZE);
544 if (Info->DataSize > PANO_MAX_REGISTRY_DATA_SIZE)
545 {
547 }
548 PVOID data = CaptureRegistryBuffer(Info->Data, dataLength, &flags);
549 if (data == NULL)
550 {
551 dataLength = 0;
552 }
553
554 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
555 if (keyName == NULL)
556 {
558 }
559
562 processId,
563 threadId,
564 flags,
565 Info->Type,
566 Info->DataSize,
567 keyName ? keyName->Buffer : NULL,
568 keyName ? keyName->Length / sizeof(WCHAR) : 0,
569 valueName,
570 valueNameLength,
571 data,
572 dataLength);
573
574 ReleaseRegistryKeyName(keyName);
575 FreeRegistryBuffer(valueName);
576 FreeRegistryBuffer(data);
577}
578
579// Reports a key about to be saved to a file. Saving HKLM\SAM, SECURITY or SYSTEM is how
580// credentials are dumped with reg save, so the destination file is sent too
581static void ReportSaveKey(PREG_SAVE_KEY_INFORMATION Info)
582{
583 UINT64 processId, threadId;
584 UINT32 flags;
585 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
586 {
587 return;
588 }
589
590 // The handle belongs to the caller, and pre callbacks run on the caller's thread. It is
591 // looked up with the caller's mode so a user mode caller cannot name a kernel handle
592 POBJECT_NAME_INFORMATION fileName = NULL;
593 PFILE_OBJECT fileObject = NULL;
594 if (NT_SUCCESS(ObReferenceObjectByHandle(Info->FileHandle, 0, *IoFileObjectType, ExGetPreviousMode(), (PVOID*)&fileObject, NULL)))
595 {
596 if (!NT_SUCCESS(IoQueryFileDosDeviceName(fileObject, &fileName)))
597 {
598 fileName = NULL;
599 }
600 ObDereferenceObject(fileObject);
601 }
602
603 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
604 if (keyName == NULL || fileName == NULL)
605 {
607 }
608
611 processId,
612 threadId,
613 flags,
614 Info->Format,
615 0,
616 keyName ? keyName->Buffer : NULL,
617 keyName ? keyName->Length / sizeof(WCHAR) : 0,
618 fileName ? fileName->Name.Buffer : NULL,
619 fileName ? fileName->Name.Length / sizeof(WCHAR) : 0,
620 NULL,
621 0);
622
623 if (keyName != NULL)
624 {
625 CmCallbackReleaseKeyObjectIDEx(keyName);
626 }
627 if (fileName != NULL)
628 {
629 ExFreePool(fileName);
630 }
631}
632
633// Reports a key's security descriptor about to be changed, e.g. to stop defenders from reading
634// or removing a persistence key
635static void ReportSetKeySecurity(PREG_SET_KEY_SECURITY_INFORMATION Info)
636{
637 UINT64 processId, threadId;
638 UINT32 flags;
639 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
640 {
641 return;
642 }
643
644 SECURITY_INFORMATION securityInformation = 0;
645 __try
646 {
647 if (Info->SecurityInformation != NULL)
648 {
649 securityInformation = *Info->SecurityInformation;
650 }
651 }
652 __except (EXCEPTION_EXECUTE_HANDLER)
653 {
655 }
656
657 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
658 if (keyName == NULL)
659 {
661 }
662
665 processId,
666 threadId,
667 flags,
668 securityInformation,
669 0,
670 keyName ? keyName->Buffer : NULL,
671 keyName ? keyName->Length / sizeof(WCHAR) : 0,
672 NULL,
673 0,
674 NULL,
675 0);
676
677 if (keyName != NULL)
678 {
679 CmCallbackReleaseKeyObjectIDEx(keyName);
680 }
681}
682
683// Reports a key that was created. A create call on a key that already exists just opens it,
684// which happens constantly, so only keys that are new are reported
685static void ReportCreateKey(PREG_POST_OPERATION_INFORMATION Info)
686{
687 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->Object == NULL)
688 {
689 return;
690 }
691
692 PREG_CREATE_KEY_INFORMATION pre = (PREG_CREATE_KEY_INFORMATION)Info->PreInformation;
693 if (pre == NULL)
694 {
695 return;
696 }
697
698 // Disposition can point at the caller's memory
699 ULONG disposition = 0;
700 __try
701 {
702 if (pre->Disposition != NULL)
703 {
704 disposition = *pre->Disposition;
705 }
706 }
707 __except (EXCEPTION_EXECUTE_HANDLER)
708 {
709 return;
710 }
711
712 if (disposition == REG_CREATED_NEW_KEY)
713 {
714 ReportRegistryKeyEvent(PANO_EVENT_REGISTRY_CREATE_KEY, Info->Object);
715 }
716}
717
718// Builds "<Parent><Child>" in pool. Free a non-NULL result with ExFreePoolWithTag
719static PWCH JoinRegistryPath(PCUNICODE_STRING Parent, const WCHAR* Child, UINT32 ChildLength, UINT32* Length)
720{
721 UINT32 parentLength = Parent->Length / sizeof(WCHAR);
722 UINT32 length = parentLength + 1 + ChildLength;
723 PWCH path = (PWCH)ExAllocatePool2(POOL_FLAG_PAGED, (SIZE_T)length * sizeof(WCHAR), PANO_REGISTRY_POOL_TAG);
724 if (path == NULL)
725 {
726 return NULL;
727 }
728
729 RtlCopyMemory(path, Parent->Buffer, parentLength * sizeof(WCHAR));
730 path[parentLength] = L'\\';
731 RtlCopyMemory(path + parentLength + 1, Child, ChildLength * sizeof(WCHAR));
732 *Length = length;
733 return path;
734}
735
736// Reports a hive file that was loaded into the registry. Attackers load a hive to edit an offline
737// user's settings, or a copied SAM or SECURITY hive to read it
738static void ReportLoadKey(PREG_POST_OPERATION_INFORMATION Info)
739{
740 UINT64 processId, threadId;
741 UINT32 flags;
742 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->PreInformation == NULL ||
743 !BeginRegistryEvent(&processId, &threadId, &flags))
744 {
745 return;
746 }
747
748 PREG_LOAD_KEY_INFORMATION pre = (PREG_LOAD_KEY_INFORMATION)Info->PreInformation;
749
750 UINT32 keyNameLength;
751 PWCH keyName = CaptureRegistryString(pre->KeyName, &keyNameLength, &flags);
752
753 // The name is relative to the root key in Object when the caller passed one (e.g. HKLM),
754 // so the root's name is put in front of it
755 if (keyName != NULL && keyName[0] != L'\\' && pre->Object != NULL)
756 {
757 PCUNICODE_STRING rootName = GetRegistryKeyName(pre->Object);
758 if (rootName != NULL)
759 {
760 UINT32 fullLength;
761 PWCH fullName = JoinRegistryPath(rootName, keyName, keyNameLength, &fullLength);
762 if (fullName != NULL)
763 {
764 FreeRegistryBuffer(keyName);
765 keyName = fullName;
766 keyNameLength = fullLength;
767 }
768 ReleaseRegistryKeyName(rootName);
769 }
770 }
771
772 UINT32 fileNameLength;
773 PWCH fileName = CaptureRegistryString(pre->SourceFile, &fileNameLength, &flags);
774 if (keyName == NULL || fileName == NULL)
775 {
777 }
778
781 processId,
782 threadId,
783 flags,
784 pre->Flags,
785 0,
786 keyName,
787 keyNameLength,
788 fileName,
789 fileNameLength,
790 NULL,
791 0);
792
793 FreeRegistryBuffer(keyName);
794 FreeRegistryBuffer(fileName);
795}
796
797// Reports a key's hive file being replaced at the next boot, which swaps in a hive the
798// attacker prepared offline
799static void ReportReplaceKey(PREG_POST_OPERATION_INFORMATION Info)
800{
801 UINT64 processId, threadId;
802 UINT32 flags;
803 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->PreInformation == NULL ||
804 !BeginRegistryEvent(&processId, &threadId, &flags))
805 {
806 return;
807 }
808
809 PREG_REPLACE_KEY_INFORMATION pre = (PREG_REPLACE_KEY_INFORMATION)Info->PreInformation;
810
811 UINT32 newFileLength;
812 PWCH newFile = CaptureRegistryString(pre->NewFileName, &newFileLength, &flags);
813
814 // The old file name goes in Data, as the event has room for only two names
815 UINT32 oldFileLength;
816 PWCH oldFile = CaptureRegistryString(pre->OldFileName, &oldFileLength, &flags);
817 UINT32 oldFileBytes = oldFileLength * sizeof(WCHAR);
818 UINT32 oldFileDataLength = min(oldFileBytes, (UINT32)PANO_MAX_REGISTRY_DATA_SIZE);
819 if (oldFileBytes > PANO_MAX_REGISTRY_DATA_SIZE)
820 {
822 }
823
824 PCUNICODE_STRING keyName = GetRegistryKeyName(pre->Object);
825 if (keyName == NULL || newFile == NULL || oldFile == NULL)
826 {
828 }
829
832 processId,
833 threadId,
834 flags,
835 0,
836 oldFileBytes,
837 keyName ? keyName->Buffer : NULL,
838 keyName ? keyName->Length / sizeof(WCHAR) : 0,
839 newFile,
840 newFileLength,
841 oldFile,
842 oldFileDataLength);
843
844 ReleaseRegistryKeyName(keyName);
845 FreeRegistryBuffer(newFile);
846 FreeRegistryBuffer(oldFile);
847}
848
849// A key's old name, kept from its pre-rename notification to its post-rename one. Once the key
850// is renamed, its object only gives the new name
856
857// Saves the key's name before it is renamed. The registry hands CallContext to the matching
858// post notification, which reports the rename and frees it. If the driver unloads between the
859// two, that post notification never comes and the context is leaked
860static void BeginRenameKey(PREG_RENAME_KEY_INFORMATION Info)
861{
862 UINT64 processId, threadId;
863 UINT32 flags;
864 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
865 {
866 return;
867 }
868
869 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
870 if (keyName == NULL)
871 {
872 return;
873 }
874
875 UINT32 length = keyName->Length / sizeof(WCHAR);
876 PPANO_RENAME_KEY_CONTEXT context = (PPANO_RENAME_KEY_CONTEXT)ExAllocatePool2(
877 POOL_FLAG_PAGED,
878 FIELD_OFFSET(PANO_RENAME_KEY_CONTEXT, Name) + (SIZE_T)length * sizeof(WCHAR),
880 if (context != NULL)
881 {
882 context->Length = length;
883 RtlCopyMemory(context->Name, keyName->Buffer, length * sizeof(WCHAR));
884 Info->CallContext = context;
885 }
886
887 ReleaseRegistryKeyName(keyName);
888}
889
890// Reports a renamed key with its old and new full names
891static void ReportRenameKey(PREG_POST_OPERATION_INFORMATION Info)
892{
893 if (Info == NULL || Info->CallContext == NULL)
894 {
895 return;
896 }
897
898 PPANO_RENAME_KEY_CONTEXT context = (PPANO_RENAME_KEY_CONTEXT)Info->CallContext;
899 UINT64 processId, threadId;
900 UINT32 flags;
901 if (NT_SUCCESS(Info->Status) && BeginRegistryEvent(&processId, &threadId, &flags))
902 {
903 PCUNICODE_STRING newName = GetRegistryKeyName(Info->Object);
904 if (newName == NULL)
905 {
907 }
908
911 processId,
912 threadId,
913 flags,
914 0,
915 0,
916 context->Name,
917 context->Length,
918 newName ? newName->Buffer : NULL,
919 newName ? newName->Length / sizeof(WCHAR) : 0,
920 NULL,
921 0);
922
923 ReleaseRegistryKeyName(newName);
924 }
925
926 ExFreePoolWithTag(context, PANO_REGISTRY_POOL_TAG);
927}
928
929// True if a key is in a hive that holds credentials: HKLM\SAM (local account hashes) or
930// HKLM\SECURITY (LSA secrets, cached domain logons)
931static BOOLEAN IsCredentialKey(PCUNICODE_STRING KeyName)
932{
933 static const UNICODE_STRING roots[] = {
934 RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SAM"),
935 RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SECURITY"),
936 };
937
938 for (const UNICODE_STRING& root : roots)
939 {
940 if (RtlPrefixUnicodeString(&root, KeyName, TRUE) &&
941 (KeyName->Length == root.Length || KeyName->Buffer[root.Length / sizeof(WCHAR)] == L'\\'))
942 {
943 return TRUE;
944 }
945 }
946 return FALSE;
947}
948
949// Reports a value read from a key holding credentials. Value reads happen constantly across the
950// system, so reads of any other key are dropped. The value's data is never sent: it would put
951// password hashes and secrets in the log
952static void ReportQueryValueKey(PREG_POST_OPERATION_INFORMATION Info)
953{
954 UINT64 processId, threadId;
955 UINT32 flags;
956 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->PreInformation == NULL ||
957 !BeginRegistryEvent(&processId, &threadId, &flags))
958 {
959 return;
960 }
961
962 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
963 if (keyName == NULL)
964 {
965 return;
966 }
967 if (!IsCredentialKey(keyName))
968 {
969 ReleaseRegistryKeyName(keyName);
970 return;
971 }
972
973 PREG_QUERY_VALUE_KEY_INFORMATION pre = (PREG_QUERY_VALUE_KEY_INFORMATION)Info->PreInformation;
974 UINT32 valueNameLength;
975 PWCH valueName = CaptureRegistryString(pre->ValueName, &valueNameLength, &flags);
976
979 processId,
980 threadId,
981 flags,
982 (UINT32)pre->KeyValueInformationClass,
983 0,
984 keyName->Buffer,
985 keyName->Length / sizeof(WCHAR),
986 valueName,
987 valueNameLength,
988 NULL,
989 0);
990
991 ReleaseRegistryKeyName(keyName);
992 FreeRegistryBuffer(valueName);
993}
994
995#pragma endregion
996
997NTSTATUS RegistryCallbackFunction(PVOID CallbackContext, PVOID Argument1, PVOID Argument2)
998{
999 UNREFERENCED_PARAMETER(CallbackContext);
1000
1001 // Argument1 holds the REG_NOTIFY_CLASS value itself, not a pointer to it
1002 REG_NOTIFY_CLASS regClass = (REG_NOTIFY_CLASS)(ULONG_PTR)Argument1;
1003 switch (regClass)
1004 {
1005 case RegNtPreSetValueKey:
1006 ReportSetValueKey((PREG_SET_VALUE_KEY_INFORMATION)Argument2);
1007 break;
1008 case RegNtPreSaveKey:
1009 ReportSaveKey((PREG_SAVE_KEY_INFORMATION)Argument2);
1010 break;
1011 case RegNtPreSetKeySecurity:
1012 ReportSetKeySecurity((PREG_SET_KEY_SECURITY_INFORMATION)Argument2);
1013 break;
1014 case RegNtPreDeleteKey:
1015 {
1016 PREG_DELETE_KEY_INFORMATION deleteInfo = (PREG_DELETE_KEY_INFORMATION)Argument2;
1017 if (deleteInfo != NULL)
1018 {
1019 ReportRegistryKeyEvent(PANO_EVENT_REGISTRY_DELETE_KEY, deleteInfo->Object);
1020 }
1021 break;
1022 }
1023 case RegNtPostCreateKeyEx:
1024 ReportCreateKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1025 break;
1026 case RegNtPostLoadKey:
1027 ReportLoadKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1028 break;
1029 case RegNtPostReplaceKey:
1030 ReportReplaceKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1031 break;
1032 case RegNtPreRenameKey:
1033 BeginRenameKey((PREG_RENAME_KEY_INFORMATION)Argument2);
1034 break;
1035 case RegNtPostRenameKey:
1036 ReportRenameKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1037 break;
1038 case RegNtPostQueryValueKey:
1039 ReportQueryValueKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1040 break;
1041 default:
1042 break;
1043 }
1044
1045 // STATUS_SUCCESS lets the registry operation proceed
1046 return STATUS_SUCCESS;
1047}
1048
1049VOID LoadImageNotifyRoutine(PUNICODE_STRING FullImageName, HANDLE ProcessId, PIMAGE_INFO ImageInfo)
1050{
1051 PAGED_CODE();
1052
1053 PPANO_PROCESS_INFO processInfo = GetProcessInfo(ProcessId);
1054 if (!processInfo || processInfo->Injected || processInfo->ProtectedProcess || processInfo->SignedImagesOnly || processInfo->InjectionExcluded)
1055 {
1056 return;
1057 }
1058
1059 if (!CanInject(processInfo))
1060 {
1061 UNICODE_STRING ntdllLoadImage;
1062 RtlInitUnicodeString(&ntdllLoadImage, L"ntdll.dll");
1063 if (wcsstr(FullImageName->Buffer, ntdllLoadImage.Buffer) != NULL)
1064 {
1065 processInfo->ntdllLoaded = TRUE;
1066 return;
1067 }
1068
1069 UNICODE_STRING kernel32LoadImage;
1070 RtlInitUnicodeString(&kernel32LoadImage, L"kernel32.dll");
1071 if (wcsstr(FullImageName->Buffer, kernel32LoadImage.Buffer) != NULL)
1072 {
1073 processInfo->kernel32Loaded = TRUE;
1074 processInfo->kernel32BaseAddress = ImageInfo->ImageBase;
1075 return;
1076 }
1077
1078 UNICODE_STRING kernelbaseLoadImage;
1079 RtlInitUnicodeString(&kernelbaseLoadImage, L"KernelBase.dll");
1080 if (wcsstr(FullImageName->Buffer, kernelbaseLoadImage.Buffer) != NULL)
1081 {
1082 processInfo->kernelBaseLoaded = TRUE;
1083 return;
1084 }
1085 }
1086 else
1087 {
1088 PEPROCESS targetProcess = NULL;
1089 NTSTATUS status = PsLookupProcessByProcessId(ProcessId, &targetProcess);
1090 if (!NT_SUCCESS(status))
1091 {
1092 return;
1093 }
1094
1095 PUNICODE_STRING processPath{};
1096 status = SeLocateProcessImageName(targetProcess, &processPath);
1097 if (!NT_SUCCESS(status))
1098 {
1099 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[-] Panoptes: Failed to get process name, status: 0x%X\n", status);
1100 ObDereferenceObject(targetProcess);
1101 return;
1102 }
1103
1104 // Checked just before injecting, so a list the service sent after the process started
1105 // still applies. The result is kept so later image loads skip the process
1106 if (IsInjectionExcluded(processPath))
1107 {
1108 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[*] Panoptes: Not injecting into (%llu) %wZ: it is in the DontInject list\n", (ULONG64)ProcessId, processPath);
1109 processInfo->InjectionExcluded = TRUE;
1110 ExFreePool(processPath);
1111 ObDereferenceObject(targetProcess);
1112 return;
1113 }
1114
1115 // Checked here rather than at creation, so a policy turned on after creation but
1116 // before kernel32 loads is also seen. The result is kept so later image loads skip
1117 // the process without querying again
1118 if (RequiresMicrosoftSignedImages(targetProcess))
1119 {
1120 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[*] Panoptes: Not injecting into (%llu) %wZ: it only loads Microsoft-signed images\n", (ULONG64)ProcessId, processPath);
1121 processInfo->SignedImagesOnly = TRUE;
1122 ExFreePool(processPath);
1123 ObDereferenceObject(targetProcess);
1124 return;
1125 }
1126
1127 if (processInfo->is64Bit)
1128 {
1129 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[+] Panoptes: Injecting into x64: (%llu) %wZ\n", (ULONG64)ProcessId, processPath);
1130 }
1131 else
1132 {
1133 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[+] Panoptes: Injecting Into x86: (%llu) %wZ\n", (ULONG64)ProcessId, processPath);
1134 }
1135
1136 ExFreePool(processPath);
1137 ObDereferenceObject(targetProcess);
1138
1140 processInfo->Injected = TRUE;
1141 }
1142 return;
1143}
1144
1145VOID ProcessCreateCallback(PEPROCESS Process, HANDLE ProcessId, PPS_CREATE_NOTIFY_INFO CreateInfo)
1146{
1147 if (CreateInfo != NULL)
1148 {
1149 // Protected processes are still tracked and reported; ProtectedProcess makes
1150 // LoadImageNotifyRoutine skip injecting into them
1151 PANO_PROCESS_INFO processInfo{};
1152 processInfo.ProcessId = ProcessId;
1153 processInfo.is64Bit = Is64BitProcess(Process);
1154 processInfo.ProtectedProcess = PsIsProtectedProcess(Process);
1155 // The signature policy is checked in LoadImageNotifyRoutine just before injecting
1156
1157 if (!RtlInsertElementGenericTableAvl(&g_ProcessList, &processInfo, sizeof(processInfo), NULL))
1158 {
1159 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[-] Panoptes: Failed to track process %llu\n", (ULONG64)ProcessId);
1160 }
1161
1162 // ImageFileName is only valid when FileOpenNameAvailable is set
1163 PCUNICODE_STRING imageName = CreateInfo->FileOpenNameAvailable ? CreateInfo->ImageFileName : NULL;
1164 // CommandLine can be NULL (e.g. minimal/pico processes)
1165 PCUNICODE_STRING commandLine = CreateInfo->CommandLine;
1168 (UINT64)ProcessId,
1169 (UINT64)CreateInfo->ParentProcessId,
1170 (UINT64)CreateInfo->CreatingThreadId.UniqueProcess,
1171 (UINT64)CreateInfo->CreatingThreadId.UniqueThread,
1172 imageName ? imageName->Buffer : NULL,
1173 imageName ? imageName->Length / sizeof(WCHAR) : 0,
1174 commandLine ? commandLine->Buffer : NULL,
1175 commandLine ? commandLine->Length / sizeof(WCHAR) : 0);
1176
1177
1178 }
1179 else
1180 {
1181 RemoveProcessInfo(ProcessId);
1182 PanoReportProcessEvent(PANO_EVENT_PROCESS_TERMINATED, (UINT64)ProcessId, 0, 0, 0, NULL, 0, NULL, 0);
1183 }
1184}
1185
1187{
1188 PAGED_CODE();
1189
1191 NTSTATUS status = PsSetCreateProcessNotifyRoutineEx(ProcessCreateCallback, FALSE);
1192 if (!NT_SUCCESS(status))
1193 {
1194 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[!] Panoptes: Driver Failed to Set Process Creation Notify Routine Notify Routine - Ensure /INTEGRITYCHECK is added to the linker options\n");
1195 return status;
1196 }
1197 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[+] Panoptes: Set Process Creation Notify Callbacks\n");
1198
1199 status = PsSetLoadImageNotifyRoutine(LoadImageNotifyRoutine);
1200 if (!NT_SUCCESS(status))
1201 {
1202 NTSTATUS removeStatus = PsSetCreateProcessNotifyRoutineEx(ProcessCreateCallback, TRUE);
1203 if (!NT_SUCCESS(removeStatus))
1204 {
1205 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[!] Panoptes: Driver Failed to remove callback for Set Process Creation Notify Routine Notify Routine\n");
1206 return removeStatus;
1207 }
1208 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[!] Panoptes: Driver Failed to Set Process Load Image Notify Routine - Ensure /INTEGRITYCHECK is added to the linker options\n");
1209 return status;
1210 }
1211 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[+] Panoptes: Set Image Load Notify Callbacks\n");
1212
1213 PVOID RegistryContext = nullptr;
1214 status = CmRegisterCallback(RegistryCallbackFunction, RegistryContext, &g_RegistryCookie);
1215 if (!NT_SUCCESS(status))
1216 {
1217 NTSTATUS removeStatus = PsRemoveLoadImageNotifyRoutine(LoadImageNotifyRoutine);
1218 if (!NT_SUCCESS(removeStatus))
1219 {
1220 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[!] Panoptes: Driver Failed to remove callback for Set Image Load Notify Routine Notify Routine\n");
1221 return removeStatus;
1222 }
1223
1224 removeStatus = PsSetCreateProcessNotifyRoutineEx(ProcessCreateCallback, TRUE);
1225 if (!NT_SUCCESS(removeStatus))
1226 {
1227 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[!] Panoptes: Driver Failed to remove callback for Set Process Creation Notify Routine Notify Routine\n");
1228 return removeStatus;
1229 }
1230 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[!] Panoptes: Driver Failed to Register Registry Callback, status: 0x%X\n", status);
1231 return status;
1232 }
1233 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "[+] Panoptes: Set Registry Callbacks\n");
1234
1235
1236 return STATUS_SUCCESS;
1237}
1238
1240{
1241 PsSetCreateProcessNotifyRoutineEx(ProcessCreateCallback, TRUE);
1242 PsRemoveLoadImageNotifyRoutine(LoadImageNotifyRoutine);
1243 CmUnRegisterCallback(g_RegistryCookie);
1244
1245 PVOID entry;
1246 while ((entry = RtlGetElementGenericTableAvl(&g_ProcessList, 0)) != NULL)
1247 {
1248 RtlDeleteElementGenericTableAvl(&g_ProcessList, entry);
1249 }
1250 return;
1251}
PVOID NTAPI ProcessInfoAllocateRoutine(PRTL_AVL_TABLE Table, CLONG ByteSize)
RTL_GENERIC_COMPARE_RESULTS NTAPI ProcessInfoCompareRoutine(PRTL_AVL_TABLE Table, PVOID FirstStruct, PVOID SecondStruct)
#define PANO_REGISTRY_POOL_TAG
PPANO_PROCESS_INFO GetProcessInfo(HANDLE ProcessId)
NTSTATUS RegistryCallbackFunction(PVOID CallbackContext, PVOID Argument1, PVOID Argument2)
VOID LoadImageNotifyRoutine(PUNICODE_STRING FullImageName, HANDLE ProcessId, PIMAGE_INFO ImageInfo)
NTSTATUS InitializeKernelCallbacks()
RTL_AVL_TABLE g_ProcessList
Definition callbacks.cpp:7
BOOLEAN Is64BitProcess(PEPROCESS targetProcess)
VOID ProcessCreateCallback(PEPROCESS Process, HANDLE ProcessId, PPS_CREATE_NOTIFY_INFO CreateInfo)
struct _PANO_RENAME_KEY_CONTEXT * PPANO_RENAME_KEY_CONTEXT
LARGE_INTEGER g_RegistryCookie
Definition callbacks.cpp:8
NTSTATUS InstallKernelModeApcToInjectDll(HANDLE ProcessId)
void NTAPI KernelRoutine(PKAPC apc, PKNORMAL_ROUTINE *NormalRoutine, PVOID *NormalContext, PVOID *SystemArgument1, PVOID *SystemArgument2)
VOID RemoveCallbacks()
VOID RemoveProcessInfo(HANDLE ProcessId)
BOOLEAN CanInject(PPANO_PROCESS_INFO processInfo)
VOID NTAPI ProcessInfoFreeRoutine(PRTL_AVL_TABLE Table, PVOID Buffer)
PVOID NTAPI RtlxFindExportedRoutineByName(_In_ PVOID DllBase, _In_ PANSI_STRING ExportName)
Definition callbacks.cpp:13
struct _PANO_RENAME_KEY_CONTEXT PANO_RENAME_KEY_CONTEXT
VOID InjectDllKernelApc(PVOID NormalContext, PVOID SystemArgument1, PVOID SystemArgument2)
NTKERNELAPI PVOID NTAPI PsGetProcessWow64Process(_In_ PEPROCESS Process)
Exported by ntoskrnl but not declared in the WDK. Returns the process's WOW64 PEB (non-NULL) for a 32...
VOID(NTAPI * PKNORMAL_ROUTINE)(_In_ PVOID NormalContext, _In_ PVOID SystemArgument1, _In_ PVOID SystemArgument2)
Definition callbacks.h:59
BOOLEAN NTAPI KeInsertQueueApc(_Inout_ PRKAPC Apc, _In_opt_ PVOID SystemArgument1, _In_opt_ PVOID SystemArgument2, _In_ KPRIORITY Increment)
@ OriginalApcEnvironment
Definition callbacks.h:53
BOOLEAN NTAPI KeTestAlertThread(IN KPROCESSOR_MODE AlertMode)
struct _PROCESS_MITIGATION_POLICY_INFORMATION PROCESS_MITIGATION_POLICY_INFORMATION
NTSTATUS NTAPI ZwQueryInformationProcess(HANDLE hProcess, PROCESSINFOCLASS infoType, PVOID pBuf, ULONG lenBuf, SIZE_T *returnLength)
PVOID NTAPI RtlImageDirectoryEntryToData(_In_ PVOID BaseOfImage, _In_ BOOLEAN MappedAsImage, _In_ USHORT DirectoryEntry, _Out_ PULONG Size)
VOID NTAPI KeInitializeApc(_Out_ PRKAPC Apc, _In_ PRKTHREAD Thread, _In_ KAPC_ENVIRONMENT Environment, _In_ PKKERNEL_ROUTINE KernelRoutine, _In_opt_ PKRUNDOWN_ROUTINE RundownRoutine, _In_opt_ PKNORMAL_ROUTINE NormalRoutine, _In_opt_ KPROCESSOR_MODE ProcessorMode, _In_opt_ PVOID NormalContext)
BOOLEAN NTAPI PsIsProtectedProcess(_In_ PEPROCESS Process)
BOOLEAN EventQueueIsConsumerProcess(UINT64 ProcessId)
Checks whether a process is the one reading events (the service). The filter does not report that pro...
NTSTATUS PanoReportProcessEvent(PANO_EVENT_TYPE Type, UINT64 ProcessId, UINT64 ParentProcessId, UINT64 CreatingProcessId, UINT64 CreatingThreadId, _In_reads_opt_(ImageNameLength) const WCHAR *ImageName, UINT32 ImageNameLength, _In_reads_opt_(CommandLineLength) const WCHAR *CommandLine, UINT32 CommandLineLength)
Convenience wrapper that builds a PANO_PROCESS_EVENT_DATA event. If the image name and command line t...
NTSTATUS PanoReportRegistryEvent(PANO_EVENT_TYPE Type, UINT64 ProcessId, UINT64 ThreadId, UINT32 Flags, UINT32 Detail, UINT32 DataSize, _In_reads_opt_(KeyNameLength) const WCHAR *KeyName, UINT32 KeyNameLength, _In_reads_opt_(SecondNameLength) const WCHAR *SecondName, UINT32 SecondNameLength, _In_reads_bytes_opt_(DataLength) const void *Data, UINT32 DataLength)
Convenience wrapper that builds a PANO_REGISTRY_EVENT_DATA event. Every buffer must be kernel memory:...
BOOLEAN IsInjectionExcluded(_In_ PCUNICODE_STRING ProcessImagePath)
Checks whether a process's image is in the list. PASSIVE_LEVEL only.
#define PANO_FLAG_KERNEL_MODE_CALLER
Registry events: the operation came from kernel mode (a driver or the system) rather than from a user...
#define PANO_FLAG_CAPTURE_FAILED
Registry events: a name or the data could not be read, so the event is incomplete....
PANO_EVENT_TYPE
The type of event, which determines the data that follows the header.
Definition pano_events.h:65
@ PANO_EVENT_REGISTRY_SET_KEY_SECURITY
A registry key's security descriptor is about to be changed (a PANO_REGISTRY_EVENT_DATA)....
@ PANO_EVENT_REGISTRY_SAVE_KEY
A registry key is about to be saved to a file, e.g. reg save HKLM\SAM (a PANO_REGISTRY_EVENT_DATA)....
@ PANO_EVENT_REGISTRY_REPLACE_KEY
A key's hive file was replaced, taking effect at the next boot, e.g. reg replace (a PANO_REGISTRY_EVE...
@ PANO_EVENT_REGISTRY_RENAME_KEY
A registry key was renamed (a PANO_REGISTRY_EVENT_DATA). The key name is the old full name and Second...
@ PANO_EVENT_REGISTRY_SET_VALUE
A registry value is about to be written (a PANO_REGISTRY_EVENT_DATA). SecondName is the value name,...
@ PANO_EVENT_REGISTRY_CREATE_KEY
A new registry key was created (a PANO_REGISTRY_EVENT_DATA with only the key name)....
@ PANO_EVENT_PROCESS_TERMINATED
A process exited (a PANO_PROCESS_EVENT_DATA with only ProcessId set).
Definition pano_events.h:89
@ PANO_EVENT_PROCESS_CREATED
A process was created (a PANO_PROCESS_EVENT_DATA).
Definition pano_events.h:87
@ PANO_EVENT_REGISTRY_LOAD_KEY
A hive file was loaded into the registry, e.g. reg load (a PANO_REGISTRY_EVENT_DATA)....
@ PANO_EVENT_REGISTRY_DELETE_KEY
A registry key is about to be deleted (a PANO_REGISTRY_EVENT_DATA with only the key name)....
@ PANO_EVENT_REGISTRY_QUERY_VALUE
A value was read from a key holding credentials (under HKLM\SAM or HKLM\SECURITY) (a PANO_REGISTRY_EV...
#define PANO_MAX_REGISTRY_DATA_SIZE
The most bytes of a value's data a PANO_EVENT_REGISTRY_SET_VALUE carries. Enough for the paths and co...
#define PANO_FLAG_DATA_TRUNCATED
PANO_EVENT_REGISTRY_SET_VALUE / _REPLACE_KEY: Data holds only the first PANO_MAX_REGISTRY_DATA_SIZE b...
PUNICODE_STRING DLLPath
PUNICODE_STRING DllName
PVOID DllHandle
BOOLEAN ntdllLoaded
Definition structs.h:12
PVOID kernel32BaseAddress
Definition structs.h:15
BOOLEAN Injected
Definition structs.h:8
HANDLE ProcessId
Definition structs.h:7
BOOLEAN SignedImagesOnly
Definition structs.h:10
BOOLEAN kernel32Loaded
Definition structs.h:13
BOOLEAN InjectionExcluded
Definition structs.h:11
BOOLEAN ProtectedProcess
Definition structs.h:9
BOOLEAN kernelBaseLoaded
Definition structs.h:14
BOOLEAN is64Bit
Definition structs.h:6
PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY SignaturePolicy
Definition callbacks.h:20
union _PROCESS_MITIGATION_POLICY_INFORMATION::@141134034226020126354051231043252166210044025227 Data
PROCESS_MITIGATION_POLICY Policy
Definition callbacks.h:11
struct _PANO_PROCESS_INFO * PPANO_PROCESS_INFO
struct _PANO_PROCESS_INFO PANO_PROCESS_INFO