15 _In_ PANSI_STRING ExportName)
24 PIMAGE_EXPORT_DIRECTORY ExportDirectory;
25 LONG Low = 0, Mid = 0, High, Ret;
37 IMAGE_DIRECTORY_ENTRY_EXPORT,
49 NameTable = (PULONG)((ULONG_PTR)DllBase + ExportDirectory->AddressOfNames);
50 OrdinalTable = (PUSHORT)((ULONG_PTR)DllBase + ExportDirectory->AddressOfNameOrdinals);
56 High = ExportDirectory->NumberOfNames - 1;
63 Mid = (Low + High) >> 1;
69 Ret = strcmp(ExportName->Buffer, (PCHAR)DllBase + NameTable[Mid]);
106 Ordinal = OrdinalTable[Mid];
112 if (Ordinal >= ExportDirectory->NumberOfFunctions)
121 ExportTable = (PULONG)((ULONG_PTR)DllBase + ExportDirectory->AddressOfFunctions);
122 Function = (PVOID)((ULONG_PTR)DllBase + ExportTable[Ordinal]);
129 (Function < (PVOID)ExportDirectory) ||
130 (Function > (PVOID)((ULONG_PTR)ExportDirectory + ExportSize)));
143static BOOLEAN RequiresMicrosoftSignedImages(PEPROCESS Process)
147 HANDLE processHandle = NULL;
148 NTSTATUS status = ObOpenObjectByPointer(
156 if (!NT_SUCCESS(status))
158 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to open process to query its signature policy, status: 0x%X\n", status);
163 policyInfo.
Policy = ProcessSignaturePolicy;
165 ZwClose(processHandle);
166 if (!NT_SUCCESS(status))
168 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to query process signature policy, status: 0x%X\n", status);
173 const PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY &signaturePolicy = policyInfo.
Data.
SignaturePolicy;
174 return signaturePolicy.MicrosoftSignedOnly || signaturePolicy.StoreSignedOnly || signaturePolicy.MitigationOptIn;
179 UNREFERENCED_PARAMETER(Table);
185 return GenericLessThan;
189 return GenericGreaterThan;
196 UNREFERENCED_PARAMETER(Table);
197 return ExAllocatePool2(POOL_FLAG_NON_PAGED, ByteSize,
'corP');
202 UNREFERENCED_PARAMETER(Table);
203 ExFreePoolWithTag(Buffer,
'corP');
222 UNREFERENCED_PARAMETER(NormalRoutine);
223 UNREFERENCED_PARAMETER(NormalContext);
224 UNREFERENCED_PARAMETER(SystemArgument1);
225 UNREFERENCED_PARAMETER(SystemArgument2);
248 DbgPrint(
"InjectDll Entered");
249 HANDLE pProcessId = (HANDLE)NormalContext;
250 UNREFERENCED_PARAMETER(SystemArgument1);
251 UNREFERENCED_PARAMETER(SystemArgument2);
253 if (
nullptr == pProcessId)
255 DbgPrint(
"InjectDll - pProcessId is null");
262 DbgPrint(
"InjectDll - process is not tracked");
266 ANSI_STRING loadDllRoutineName = RTL_CONSTANT_STRING(
"LoadLibraryExW");
268 if (shellcodeAddress ==
nullptr)
271 DbgPrint(
"Error: LoadLibraryExW was not found in kernel32.");
275 UNICODE_STRING dllToInject;
276 PVOID allocatedAddressContainingDllFullPath =
nullptr;
280 RtlInitUnicodeString(&dllToInject, L
"C:\\Program Files\\Panoptes\\PanoptesDLLx64.dll");
284 RtlInitUnicodeString(&dllToInject, L
"C:\\Program Files\\Panoptes\\PanoptesDLLx86.dll");
290 SIZE_T regionSize = dllToInject.Length +
sizeof(WCHAR);
294 ULONG_PTR zeroBits = pi->
is64Bit ? 0 : 0x7FFFFFFF;
295 NTSTATUS status = ZwAllocateVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, zeroBits, ®ionSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
296 if (!NT_SUCCESS(status))
298 DbgPrint(
"Error: Unable to allocate memory in the target process.");
301 RtlCopyMemory(allocatedAddressContainingDllFullPath, dllToInject.Buffer, dllToInject.Length);
304 SIZE_T releaseSize = 0;
306 PKAPC pKapc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(KAPC),
'tikt');
309 DbgPrint(
"Error: Unable to allocate the APC object.");
310 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, &releaseSize, MEM_RELEASE);
318 PVOID apcRoutine = shellcodeAddress;
319 PVOID apcContext = allocatedAddressContainingDllFullPath;
322 status = PsWrapApcWow64Thread(&apcContext, &apcRoutine);
323 if (!NT_SUCCESS(status))
325 DbgPrint(
"Error: Unable to wrap the APC for a WOW64 process.");
326 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, &releaseSize, MEM_RELEASE);
334 DbgPrint(
"Inserting APC to target thread");
337 DbgPrint(
"Error: Unable to insert APC to target thread.");
338 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, &releaseSize, MEM_RELEASE);
345 DbgPrint(
"InjectDllKernelApc exiting");
350 PRKAPC pKapc =
nullptr;
351 PETHREAD pThread =
nullptr;
353 pKapc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(KAPC),
'tiky');
354 if (
nullptr == pKapc)
356 DbgPrint(
"InstallKernelModeApcToInjectDll Failed to allocate memory for the APC");
357 return STATUS_INSUFFICIENT_RESOURCES;
360 pThread = KeGetCurrentThread();
365 KernelMode, (PVOID)ProcessId);
368 DbgPrint(
"InstallKernelModeApcToInjectDll Failed to insert APC");
370 return STATUS_UNSUCCESSFUL;
374 DbgPrint(
"InstallKernelModeApcToInjectDll APC delivered");
377 return STATUS_SUCCESS;
387#pragma region Registry Events
389#define PANO_REGISTRY_POOL_TAG 'gRoP'
393static BOOLEAN BeginRegistryEvent(UINT64* ProcessId, UINT64* ThreadId, UINT32* Flags)
395 *ProcessId = (UINT64)PsGetCurrentProcessId();
401 *ThreadId = (UINT64)PsGetCurrentThreadId();
408static PCUNICODE_STRING GetRegistryKeyName(PVOID KeyObject)
410 PCUNICODE_STRING name = NULL;
411 if (KeyObject == NULL || !NT_SUCCESS(CmCallbackGetKeyObjectIDEx(&
g_RegistryCookie, KeyObject, NULL, &name, 0)))
422static PVOID CaptureRegistryBuffer(
const void* Buffer, SIZE_T Length, UINT32* Flags)
424 if (Buffer == NULL || Length == 0)
438 RtlCopyMemory(copy, Buffer, Length);
440 __except (EXCEPTION_EXECUTE_HANDLER)
452static PWCH CaptureRegistryString(PCUNICODE_STRING String, UINT32* Length, UINT32* Flags)
460 UNICODE_STRING string;
465 __except (EXCEPTION_EXECUTE_HANDLER)
471 UINT32 length =
string.Length /
sizeof(WCHAR);
472 PWCH copy = (PWCH)CaptureRegistryBuffer(
string.Buffer, length *
sizeof(WCHAR), Flags);
480static void FreeRegistryBuffer(PVOID Buffer)
488static void ReleaseRegistryKeyName(PCUNICODE_STRING KeyName)
492 CmCallbackReleaseKeyObjectIDEx(KeyName);
497static void ReportRegistryKeyEvent(
PANO_EVENT_TYPE Type, PVOID KeyObject)
499 UINT64 processId, threadId;
501 if (!BeginRegistryEvent(&processId, &threadId, &flags))
506 PCUNICODE_STRING keyName = GetRegistryKeyName(KeyObject);
519 keyName ? keyName->Buffer : NULL,
520 keyName ? keyName->Length /
sizeof(WCHAR) : 0,
526 ReleaseRegistryKeyName(keyName);
531static void ReportSetValueKey(PREG_SET_VALUE_KEY_INFORMATION Info)
533 UINT64 processId, threadId;
535 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
540 UINT32 valueNameLength;
541 PWCH valueName = CaptureRegistryString(Info->ValueName, &valueNameLength, &flags);
548 PVOID data = CaptureRegistryBuffer(Info->Data, dataLength, &flags);
554 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
567 keyName ? keyName->Buffer : NULL,
568 keyName ? keyName->Length /
sizeof(WCHAR) : 0,
574 ReleaseRegistryKeyName(keyName);
575 FreeRegistryBuffer(valueName);
576 FreeRegistryBuffer(data);
581static void ReportSaveKey(PREG_SAVE_KEY_INFORMATION Info)
583 UINT64 processId, threadId;
585 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
592 POBJECT_NAME_INFORMATION fileName = NULL;
593 PFILE_OBJECT fileObject = NULL;
594 if (NT_SUCCESS(ObReferenceObjectByHandle(Info->FileHandle, 0, *IoFileObjectType, ExGetPreviousMode(), (PVOID*)&fileObject, NULL)))
596 if (!NT_SUCCESS(IoQueryFileDosDeviceName(fileObject, &fileName)))
600 ObDereferenceObject(fileObject);
603 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
604 if (keyName == NULL || fileName == NULL)
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,
625 CmCallbackReleaseKeyObjectIDEx(keyName);
627 if (fileName != NULL)
629 ExFreePool(fileName);
635static void ReportSetKeySecurity(PREG_SET_KEY_SECURITY_INFORMATION Info)
637 UINT64 processId, threadId;
639 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
644 SECURITY_INFORMATION securityInformation = 0;
647 if (Info->SecurityInformation != NULL)
649 securityInformation = *Info->SecurityInformation;
652 __except (EXCEPTION_EXECUTE_HANDLER)
657 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
670 keyName ? keyName->Buffer : NULL,
671 keyName ? keyName->Length /
sizeof(WCHAR) : 0,
679 CmCallbackReleaseKeyObjectIDEx(keyName);
685static void ReportCreateKey(PREG_POST_OPERATION_INFORMATION Info)
687 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->Object == NULL)
692 PREG_CREATE_KEY_INFORMATION pre = (PREG_CREATE_KEY_INFORMATION)Info->PreInformation;
699 ULONG disposition = 0;
702 if (pre->Disposition != NULL)
704 disposition = *pre->Disposition;
707 __except (EXCEPTION_EXECUTE_HANDLER)
712 if (disposition == REG_CREATED_NEW_KEY)
719static PWCH JoinRegistryPath(PCUNICODE_STRING Parent,
const WCHAR* Child, UINT32 ChildLength, UINT32* Length)
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);
729 RtlCopyMemory(path, Parent->Buffer, parentLength *
sizeof(WCHAR));
730 path[parentLength] = L
'\\';
731 RtlCopyMemory(path + parentLength + 1, Child, ChildLength *
sizeof(WCHAR));
738static void ReportLoadKey(PREG_POST_OPERATION_INFORMATION Info)
740 UINT64 processId, threadId;
742 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->PreInformation == NULL ||
743 !BeginRegistryEvent(&processId, &threadId, &flags))
748 PREG_LOAD_KEY_INFORMATION pre = (PREG_LOAD_KEY_INFORMATION)Info->PreInformation;
750 UINT32 keyNameLength;
751 PWCH keyName = CaptureRegistryString(pre->KeyName, &keyNameLength, &flags);
755 if (keyName != NULL && keyName[0] != L
'\\' && pre->Object != NULL)
757 PCUNICODE_STRING rootName = GetRegistryKeyName(pre->Object);
758 if (rootName != NULL)
761 PWCH fullName = JoinRegistryPath(rootName, keyName, keyNameLength, &fullLength);
762 if (fullName != NULL)
764 FreeRegistryBuffer(keyName);
766 keyNameLength = fullLength;
768 ReleaseRegistryKeyName(rootName);
772 UINT32 fileNameLength;
773 PWCH fileName = CaptureRegistryString(pre->SourceFile, &fileNameLength, &flags);
774 if (keyName == NULL || fileName == NULL)
793 FreeRegistryBuffer(keyName);
794 FreeRegistryBuffer(fileName);
799static void ReportReplaceKey(PREG_POST_OPERATION_INFORMATION Info)
801 UINT64 processId, threadId;
803 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->PreInformation == NULL ||
804 !BeginRegistryEvent(&processId, &threadId, &flags))
809 PREG_REPLACE_KEY_INFORMATION pre = (PREG_REPLACE_KEY_INFORMATION)Info->PreInformation;
811 UINT32 newFileLength;
812 PWCH newFile = CaptureRegistryString(pre->NewFileName, &newFileLength, &flags);
815 UINT32 oldFileLength;
816 PWCH oldFile = CaptureRegistryString(pre->OldFileName, &oldFileLength, &flags);
817 UINT32 oldFileBytes = oldFileLength *
sizeof(WCHAR);
824 PCUNICODE_STRING keyName = GetRegistryKeyName(pre->Object);
825 if (keyName == NULL || newFile == NULL || oldFile == NULL)
837 keyName ? keyName->Buffer : NULL,
838 keyName ? keyName->Length /
sizeof(WCHAR) : 0,
844 ReleaseRegistryKeyName(keyName);
845 FreeRegistryBuffer(newFile);
846 FreeRegistryBuffer(oldFile);
860static void BeginRenameKey(PREG_RENAME_KEY_INFORMATION Info)
862 UINT64 processId, threadId;
864 if (Info == NULL || !BeginRegistryEvent(&processId, &threadId, &flags))
869 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
875 UINT32 length = keyName->Length /
sizeof(WCHAR);
883 RtlCopyMemory(context->
Name, keyName->Buffer, length *
sizeof(WCHAR));
884 Info->CallContext = context;
887 ReleaseRegistryKeyName(keyName);
891static void ReportRenameKey(PREG_POST_OPERATION_INFORMATION Info)
893 if (Info == NULL || Info->CallContext == NULL)
899 UINT64 processId, threadId;
901 if (NT_SUCCESS(Info->Status) && BeginRegistryEvent(&processId, &threadId, &flags))
903 PCUNICODE_STRING newName = GetRegistryKeyName(Info->Object);
918 newName ? newName->Buffer : NULL,
919 newName ? newName->Length /
sizeof(WCHAR) : 0,
923 ReleaseRegistryKeyName(newName);
931static BOOLEAN IsCredentialKey(PCUNICODE_STRING KeyName)
933 static const UNICODE_STRING roots[] = {
934 RTL_CONSTANT_STRING(L
"\\REGISTRY\\MACHINE\\SAM"),
935 RTL_CONSTANT_STRING(L
"\\REGISTRY\\MACHINE\\SECURITY"),
938 for (
const UNICODE_STRING& root : roots)
940 if (RtlPrefixUnicodeString(&root, KeyName, TRUE) &&
941 (KeyName->Length == root.Length || KeyName->Buffer[root.Length /
sizeof(WCHAR)] == L
'\\'))
952static void ReportQueryValueKey(PREG_POST_OPERATION_INFORMATION Info)
954 UINT64 processId, threadId;
956 if (Info == NULL || !NT_SUCCESS(Info->Status) || Info->PreInformation == NULL ||
957 !BeginRegistryEvent(&processId, &threadId, &flags))
962 PCUNICODE_STRING keyName = GetRegistryKeyName(Info->Object);
967 if (!IsCredentialKey(keyName))
969 ReleaseRegistryKeyName(keyName);
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);
982 (UINT32)pre->KeyValueInformationClass,
985 keyName->Length /
sizeof(WCHAR),
991 ReleaseRegistryKeyName(keyName);
992 FreeRegistryBuffer(valueName);
999 UNREFERENCED_PARAMETER(CallbackContext);
1002 REG_NOTIFY_CLASS regClass = (REG_NOTIFY_CLASS)(ULONG_PTR)Argument1;
1005 case RegNtPreSetValueKey:
1006 ReportSetValueKey((PREG_SET_VALUE_KEY_INFORMATION)Argument2);
1008 case RegNtPreSaveKey:
1009 ReportSaveKey((PREG_SAVE_KEY_INFORMATION)Argument2);
1011 case RegNtPreSetKeySecurity:
1012 ReportSetKeySecurity((PREG_SET_KEY_SECURITY_INFORMATION)Argument2);
1014 case RegNtPreDeleteKey:
1016 PREG_DELETE_KEY_INFORMATION deleteInfo = (PREG_DELETE_KEY_INFORMATION)Argument2;
1017 if (deleteInfo != NULL)
1023 case RegNtPostCreateKeyEx:
1024 ReportCreateKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1026 case RegNtPostLoadKey:
1027 ReportLoadKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1029 case RegNtPostReplaceKey:
1030 ReportReplaceKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1032 case RegNtPreRenameKey:
1033 BeginRenameKey((PREG_RENAME_KEY_INFORMATION)Argument2);
1035 case RegNtPostRenameKey:
1036 ReportRenameKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1038 case RegNtPostQueryValueKey:
1039 ReportQueryValueKey((PREG_POST_OPERATION_INFORMATION)Argument2);
1046 return STATUS_SUCCESS;
1061 UNICODE_STRING ntdllLoadImage;
1062 RtlInitUnicodeString(&ntdllLoadImage, L
"ntdll.dll");
1063 if (wcsstr(FullImageName->Buffer, ntdllLoadImage.Buffer) != NULL)
1069 UNICODE_STRING kernel32LoadImage;
1070 RtlInitUnicodeString(&kernel32LoadImage, L
"kernel32.dll");
1071 if (wcsstr(FullImageName->Buffer, kernel32LoadImage.Buffer) != NULL)
1078 UNICODE_STRING kernelbaseLoadImage;
1079 RtlInitUnicodeString(&kernelbaseLoadImage, L
"KernelBase.dll");
1080 if (wcsstr(FullImageName->Buffer, kernelbaseLoadImage.Buffer) != NULL)
1088 PEPROCESS targetProcess = NULL;
1089 NTSTATUS status = PsLookupProcessByProcessId(ProcessId, &targetProcess);
1090 if (!NT_SUCCESS(status))
1095 PUNICODE_STRING processPath{};
1096 status = SeLocateProcessImageName(targetProcess, &processPath);
1097 if (!NT_SUCCESS(status))
1099 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to get process name, status: 0x%X\n", status);
1100 ObDereferenceObject(targetProcess);
1108 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[*] Panoptes: Not injecting into (%llu) %wZ: it is in the DontInject list\n", (ULONG64)ProcessId, processPath);
1110 ExFreePool(processPath);
1111 ObDereferenceObject(targetProcess);
1118 if (RequiresMicrosoftSignedImages(targetProcess))
1120 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[*] Panoptes: Not injecting into (%llu) %wZ: it only loads Microsoft-signed images\n", (ULONG64)ProcessId, processPath);
1122 ExFreePool(processPath);
1123 ObDereferenceObject(targetProcess);
1129 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Injecting into x64: (%llu) %wZ\n", (ULONG64)ProcessId, processPath);
1133 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Injecting Into x86: (%llu) %wZ\n", (ULONG64)ProcessId, processPath);
1136 ExFreePool(processPath);
1137 ObDereferenceObject(targetProcess);
1147 if (CreateInfo != NULL)
1157 if (!RtlInsertElementGenericTableAvl(&
g_ProcessList, &processInfo,
sizeof(processInfo), NULL))
1159 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to track process %llu\n", (ULONG64)ProcessId);
1163 PCUNICODE_STRING imageName = CreateInfo->FileOpenNameAvailable ? CreateInfo->ImageFileName : NULL;
1165 PCUNICODE_STRING commandLine = CreateInfo->CommandLine;
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);
1192 if (!NT_SUCCESS(status))
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");
1197 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Set Process Creation Notify Callbacks\n");
1200 if (!NT_SUCCESS(status))
1203 if (!NT_SUCCESS(removeStatus))
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;
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");
1211 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Set Image Load Notify Callbacks\n");
1213 PVOID RegistryContext =
nullptr;
1215 if (!NT_SUCCESS(status))
1218 if (!NT_SUCCESS(removeStatus))
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;
1225 if (!NT_SUCCESS(removeStatus))
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;
1230 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[!] Panoptes: Driver Failed to Register Registry Callback, status: 0x%X\n", status);
1233 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Set Registry Callbacks\n");
1236 return STATUS_SUCCESS;
1246 while ((entry = RtlGetElementGenericTableAvl(&
g_ProcessList, 0)) != NULL)
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
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
NTSTATUS InstallKernelModeApcToInjectDll(HANDLE ProcessId)
void NTAPI KernelRoutine(PKAPC apc, PKNORMAL_ROUTINE *NormalRoutine, PVOID *NormalContext, PVOID *SystemArgument1, PVOID *SystemArgument2)
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)
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)
BOOLEAN NTAPI KeInsertQueueApc(_Inout_ PRKAPC Apc, _In_opt_ PVOID SystemArgument1, _In_opt_ PVOID SystemArgument2, _In_ KPRIORITY Increment)
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.
@ 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).
@ PANO_EVENT_PROCESS_CREATED
A process was created (a PANO_PROCESS_EVENT_DATA).
@ 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...
PVOID kernel32BaseAddress
BOOLEAN InjectionExcluded
struct _PANO_PROCESS_INFO * PPANO_PROCESS_INFO
struct _PANO_PROCESS_INFO PANO_PROCESS_INFO