16 _In_ PANSI_STRING ExportName
27 LONG Low = 0, Mid = 0, High, Ret;
51 NameTable = (PULONG)((ULONG_PTR)DllBase + ExportDirectory->
AddressOfNames);
65 Mid = (Low + High) >> 1;
71 Ret = strcmp(ExportName->Buffer, (PCHAR)DllBase + NameTable[Mid]);
108 Ordinal = OrdinalTable[Mid];
124 Function = (PVOID)((ULONG_PTR)DllBase + ExportTable[Ordinal]);
131 (Function < (PVOID)ExportDirectory) ||
132 (Function > (PVOID)((ULONG_PTR)ExportDirectory + ExportSize))
153OB_PREOP_CALLBACK_STATUS
PreOperationCallback(PVOID RegistrationContext, POB_PRE_OPERATION_INFORMATION OperationInformation)
156 UNREFERENCED_PARAMETER(RegistrationContext);
157 UNREFERENCED_PARAMETER(OperationInformation);
198 return OB_PREOP_SUCCESS;
214 if (processInfo->
ProcessId == ProcessId) {
217 entry = entry->Flink;
228 if (processInfo->
ProcessId == ProcessId) {
229 RemoveEntryList(entry);
232 entry = entry->Flink;
239 UNREFERENCED_PARAMETER(NormalRoutine);
240 UNREFERENCED_PARAMETER(NormalContext);
241 UNREFERENCED_PARAMETER(SystemArgument1);
242 UNREFERENCED_PARAMETER(SystemArgument2);
264 DbgPrint(
"InjectDll Entered");
265 HANDLE pProcessId = (HANDLE)NormalContext;
266 UNREFERENCED_PARAMETER(SystemArgument1);
267 UNREFERENCED_PARAMETER(SystemArgument2);
269 if (
nullptr == pProcessId)
271 DbgPrint(
"InjectDll - pProcessId is null");
275 ANSI_STRING loadDllRoutineName = RTL_CONSTANT_STRING(
"LoadLibraryExW");
280 UNICODE_STRING dllToInject;
281 UNICODE_STRING dllFullPathx64;
282 UNICODE_STRING dllFullPathx86;
283 RtlInitUnicodeString(&dllFullPathx64, L
"C:\\Program Files\\Panoptes\\PanoptesDLLx64.dll");
284 RtlInitUnicodeString(&dllFullPathx86, L
"C:\\Program Files\\Panoptes\\PanoptesDLLx86.dll");
285 PVOID allocatedAddressContainingDllFullPath =
nullptr;
289 dllToInject = dllFullPathx64;
293 dllToInject = dllFullPathx86;
296 NTSTATUS status = ZwAllocateVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, 0, (PSIZE_T)&dllToInject.Length, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
297 if (!NT_SUCCESS(status))
299 DbgPrint(
"Error: Unable to allocate memory in the target process.");
302 RtlCopyMemory(allocatedAddressContainingDllFullPath, dllToInject.Buffer, dllToInject.Length);
304 PKAPC pKapc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(KAPC),
'tikt');
307 DbgPrint(
"Error: Unable to allocate the APC object.");
308 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, (PSIZE_T)&dllToInject.Length, MEM_RELEASE);
314 DbgPrint(
"Inserting APC to target thread");
317 DbgPrint(
"Error: Unable to insert APC to target thread.");
318 ZwFreeVirtualMemory(NtCurrentProcess(), &allocatedAddressContainingDllFullPath, (PSIZE_T)&dllToInject.Length, MEM_RELEASE);
325 DbgPrint(
"InjectDllKernelApc exiting");
330 PRKAPC pKapc =
nullptr;
331 PETHREAD pThread =
nullptr;
333 pKapc = (PKAPC)ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(KAPC),
'tiky');
334 if (
nullptr == pKapc)
336 DbgPrint(
"InstallKernelModeApcToInjectDll Failed to allocate memory for the APC");
337 return STATUS_INSUFFICIENT_RESOURCES;
340 pThread = KeGetCurrentThread();
345 KernelMode, (PVOID)ProcessId);
348 DbgPrint(
"InstallKernelModeApcToInjectDll Failed to insert APC");
350 return STATUS_UNSUCCESSFUL;
354 DbgPrint(
"InstallKernelModeApcToInjectDll APC delivered");
357 return STATUS_SUCCESS;
361 UINT64* processAsUint64 =
reinterpret_cast<UINT64*
>(targetProcess);
362 PVOID* wow64ProcessPtr =
reinterpret_cast<PVOID*
>(processAsUint64 + 0x580 /
sizeof(UINT64));
363 if (*wow64ProcessPtr == NULL)
373 UNREFERENCED_PARAMETER(ImageInfo);
376 if (!processInfo || processInfo->
Injected)
383 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Skipping protected process %llu", (ULONG64)ProcessId);
390 UNICODE_STRING ntdllLoadImage;
391 RtlInitUnicodeString(&ntdllLoadImage, L
"ntdll.dll");
392 if (wcsstr(FullImageName->Buffer, ntdllLoadImage.Buffer) != NULL) {
398 UNICODE_STRING kernel32LoadImage;
399 RtlInitUnicodeString(&kernel32LoadImage, L
"kernel32.dll");
400 if (wcsstr(FullImageName->Buffer, kernel32LoadImage.Buffer) != NULL) {
407 UNICODE_STRING kernelbaseLoadImage;
408 RtlInitUnicodeString(&kernelbaseLoadImage, L
"KernelBase.dll");
409 if (wcsstr(FullImageName->Buffer, kernelbaseLoadImage.Buffer) != NULL) {
417 PEPROCESS targetProcess = NULL;
418 NTSTATUS status = PsLookupProcessByProcessId(ProcessId, &targetProcess);
419 if (!NT_SUCCESS(status)) {
423 PUNICODE_STRING processPath{};
424 status = SeLocateProcessImageName(targetProcess, &processPath);
425 if (!NT_SUCCESS(status)) {
426 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to get process name, status: 0x%X\n", status);
432 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Injecting into x64: (%llu) %wZ\n", (ULONG64)ProcessId, processPath);
435 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Injecting Into x86: (%llu) %wZ\n", (ULONG64)ProcessId, processPath);
520 UNREFERENCED_PARAMETER(Process);
522 if (CreateInfo != NULL) {
523 UNICODE_STRING onlyProc;
524 RtlInitUnicodeString(&onlyProc, L
"die.exe");
525 if (wcsstr(CreateInfo->ImageFileName->Buffer, onlyProc.Buffer) != NULL) {
539 if (!NT_SUCCESS(status)) {
540 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to get process mitigation policy, status: 0x%X\n", status);
592 if (!NT_SUCCESS(status)) {
594 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");
597 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Set Process Creation Notify Callbacks\n");
600 if (!NT_SUCCESS(status)) {
602 if (!NT_SUCCESS(removeStatus)) {
603 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[!] Panoptes: Driver Failed to remove callback for Set Process Creation Notify Routine Notify Routine\n");
606 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");
609 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[+] Panoptes: Set Image Load Notify Callbacks\n");
611 return STATUS_SUCCESS;
PPANO_PROCESS_INFO GetProcessInfo(HANDLE ProcessId)
VOID LoadImageNotifyRoutine(PUNICODE_STRING FullImageName, HANDLE ProcessId, PIMAGE_INFO ImageInfo)
NTSTATUS InitializeKernelCallbacks()
BOOLEAN Is64BitProcess(PEPROCESS targetProcess)
VOID ProcessCreateCallback(PEPROCESS Process, HANDLE ProcessId, PPS_CREATE_NOTIFY_INFO CreateInfo)
KSPIN_LOCK g_ProcessListLock
OB_PREOP_CALLBACK_STATUS PreOperationCallback(PVOID RegistrationContext, POB_PRE_OPERATION_INFORMATION OperationInformation)
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)
PVOID g_ObRegistrationHandle
PVOID NTAPI RtlxFindExportedRoutineByName(_In_ PVOID DllBase, _In_ PANSI_STRING ExportName)
VOID InjectDllKernelApc(PVOID NormalContext, PVOID SystemArgument1, PVOID SystemArgument2)
BOOLEAN NTAPI KeTestAlertThread(IN KPROCESSOR_MODE AlertMode)
PVOID NTAPI RtlImageDirectoryEntryToData(_In_ PVOID BaseOfImage, _In_ BOOLEAN MappedAsImage, _In_ USHORT DirectoryEntry, _Out_ PULONG Size)
BOOLEAN NTAPI PsIsProtectedProcess(_In_ PEPROCESS Process)
#define IMAGE_DIRECTORY_ENTRY_EXPORT
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)
struct _IMAGE_EXPORT_DIRECTORY * PIMAGE_EXPORT_DIRECTORY
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)
NTSTATUS QueryProcessMitigationPolicy(HANDLE ProcessId, PROCESS_MITIGATION_POLICY_INFORMATION *policyInfo)
ULONG AddressOfNameOrdinals
PVOID kernel32BaseAddress
struct _PANO_PROCESS_INFO * PPANO_PROCESS_INFO