Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
hook_trace.hpp
Go to the documentation of this file.
1#pragma once
2#include <Windows.h>
3#include <winternl.h> // NTSTATUS
4
5// ETW TraceLogging provider for the hook DLL, "Panoptes.Hook". It is separate from the driver's
6// "Panoptes" provider: each injected process registers its own instance of this provider, and a
7// consumer (the Panoptes service) tells the two sources apart by provider GUID. Detections are
8// written at warning level with the HOOK_KEYWORD_DETECTION keyword.
9//
10// Every event carries TargetProcessId (the process acted on, 0 if the handle lacks query
11// access) and Remote (whether that is another process). The process the hook ran in is the
12// ProcessId the kernel stamps in the event header, which the writer cannot change.
13//
14// Writing an event is a single NtTraceEvent syscall, which is not hooked, so logging from inside
15// a hook cannot recurse. When no trace session has enabled the provider the write is skipped.
16//
17// In Debug builds each event is also sent to OutputDebugString as a "[Panoptes] " message,
18// which the hook tests capture.
19
20// {D9AA2FDD-2853-4A97-A42F-E77E42921704}
21#define HOOK_PROVIDER_NAME "Panoptes.Hook"
22
23#define HOOK_KEYWORD_DETECTION 0x1
24
26VOID HookTraceInit();
27
29VOID HookTraceUninit();
30
35
41VOID Log_PEWritten(HANDLE ProcessHandle, BOOL CurrentProcess, PVOID BaseAddress, BOOL Executable);
42
48VOID Log_PEBWritten(HANDLE ProcessHandle, BOOL CurrentProcess, SIZE_T Size, ULONG_PTR PebOffset);
49
60VOID Log_EntryPointWritten(HANDLE ProcessHandle, BOOL CurrentProcess, PVOID BaseAddress, SIZE_T Size,
61 PVOID EntryPoint, BOOL CodeWritten, BOOL FieldWritten);
62
68VOID Log_PEBRead(HANDLE ProcessHandle, BOOL CurrentProcess, SIZE_T Size, ULONG_PTR PebOffset);
69
76VOID Log_ProtectionSetAttempt(HANDLE ProcessHandle, BOOL CurrentProcess, NTSTATUS Status);
77
88VOID Log_ApcQueued(HANDLE ThreadHandle, BOOL CurrentProcess, const char* Api, PVOID ApcRoutine, ULONG ApcFlags);
89
94VOID Log_RemoteThreadCreated(HANDLE ProcessHandle, PVOID StartRoutine, ULONG CreateFlags);
95
105VOID Log_ExecutableAllocated(HANDLE ProcessHandle, BOOL CurrentProcess, const char* Api,
106 PVOID BaseAddress, SIZE_T RegionSize, ULONG AllocationType, ULONG Protection);
107
117VOID Log_ExecutableUnmapped(HANDLE ProcessHandle, BOOL CurrentProcess, const char* Api,
118 PVOID BaseAddress, BOOL IsImage);
119
130VOID Log_RemoteViewMapped(HANDLE ProcessHandle, const char* Api, PVOID BaseAddress, SIZE_T ViewSize,
131 ULONG Protection, BOOL Executable, BOOL IsImage);
132
140VOID Log_PEMadeExecutable(HANDLE ProcessHandle, BOOL CurrentProcess, PVOID BaseAddress,
141 ULONG OldProtection, ULONG NewProtection);
VOID Log_ProtectionSetAttempt(HANDLE ProcessHandle, BOOL CurrentProcess, NTSTATUS Status)
NtSetInformationProcess was called to set a process's protection level (ProcessProtectionInformation)...
VOID Log_ApcQueued(HANDLE ThreadHandle, BOOL CurrentProcess, const char *Api, PVOID ApcRoutine, ULONG ApcFlags)
NtQueueApcThread or NtQueueApcThreadEx2 queued an APC to a thread. Event "ApcQueued"....
VOID Log_RemoteViewMapped(HANDLE ProcessHandle, const char *Api, PVOID BaseAddress, SIZE_T ViewSize, ULONG Protection, BOOL Executable, BOOL IsImage)
NtMapViewOfSection or NtMapViewOfSectionEx mapped a view into another process. Mapping a shared secti...
VOID Log_PEMadeExecutable(HANDLE ProcessHandle, BOOL CurrentProcess, PVOID BaseAddress, ULONG OldProtection, ULONG NewProtection)
NtProtectVirtualMemory made a region starting with a PE image executable. Event "PEMadeExecutable".
VOID HookTraceInit()
Registers the provider. Call before placing the hooks.
VOID Log_ExecutableAllocated(HANDLE ProcessHandle, BOOL CurrentProcess, const char *Api, PVOID BaseAddress, SIZE_T RegionSize, ULONG AllocationType, ULONG Protection)
NtAllocateVirtualMemory or NtAllocateVirtualMemoryEx allocated executable memory. Event "ExecutableAl...
VOID Log_RemoteThreadCreated(HANDLE ProcessHandle, PVOID StartRoutine, ULONG CreateFlags)
NtCreateThreadEx created a thread in another process. Event "RemoteThreadCreated".
VOID Log_EntryPointWritten(HANDLE ProcessHandle, BOOL CurrentProcess, PVOID BaseAddress, SIZE_T Size, PVOID EntryPoint, BOOL CodeWritten, BOOL FieldWritten)
NtWriteVirtualMemory wrote over the entry point of a process's main image (the image PEB....
VOID Log_PEBWritten(HANDLE ProcessHandle, BOOL CurrentProcess, SIZE_T Size, ULONG_PTR PebOffset)
NtWriteVirtualMemory wrote to a process's PEB. Event "PEBWritten".
VOID HookTraceUninit()
Unregisters the provider. Call after removing the hooks.
VOID Log_PEWritten(HANDLE ProcessHandle, BOOL CurrentProcess, PVOID BaseAddress, BOOL Executable)
NtWriteVirtualMemory wrote a PE image. Event "PEWritten".
VOID Log_ExecutableUnmapped(HANDLE ProcessHandle, BOOL CurrentProcess, const char *Api, PVOID BaseAddress, BOOL IsImage)
NtUnmapViewOfSection or NtUnmapViewOfSectionEx unmapped a view with executable pages....
BOOL HookLoggingEnabled()
Whether the Log_* functions should write. FALSE on the thread running a Detours transaction (so the h...
Definition hook.cpp:860
VOID Log_PEBRead(HANDLE ProcessHandle, BOOL CurrentProcess, SIZE_T Size, ULONG_PTR PebOffset)
NtReadVirtualMemory read from a process's PEB. Event "PEBRead".