29 if (NULL == Hook->GpaHook)
36 if (Hook->IsIntegrityOn)
39 Hook->GpaHook->GpaPage + Hook->Offset,
44 ERROR(
"[ERROR] IntMemClkHashPage failed: 0x%08x\n", status);
51 ERROR(
"[ERROR] IntHookGpaRemoveHook failed: 0x%08x\n", status);
81 Hook->Header.EptHookType,
82 Hook->Callback.Access,
89 ERROR(
"[ERROR] IntHookGpaSetHook failed: 0x%08x\n", status);
93 if (Hook->IsIntegrityOn)
98 NewGpaPage + Hook->Offset,
103 ERROR(
"[ERROR] IntMemClkHashPage failed: 0x%08x\n", status);
111 else if (crc != Hook->Hash)
115 WARNING(
"[WARNING] Integrity validation failed on page 0x%016llx/0x%016llx (length: %x, offset: %x), " 116 "computed hash is 0x%08x, stored hash is 0x%08x!\n",
124 memzero(pTrViol,
sizeof(*pTrViol));
150 memzero(&originator,
sizeof(originator));
157 WARNING(
"[WARNING] Failed to get originator on translation violation, RIP: %llx\n",
174 WARNING(
"[WARNING] IntNotifyIntroEvent failed: 0x%08x\n", status);
210 if (NULL != Hook->GpaHook)
215 ERROR(
"[ERROR] IntHookGpaRemoveHook failed: 0x%08x\n", status);
221 if (NULL != Hook->PtsHook)
226 ERROR(
"[ERROR] IntHookPtsRemoveHook failed: 0x%08x\n", status);
276 QWORD newValue, oldValue, newGpaPage;
277 BOOLEAN disableHook, enableHook;
292 disableHook = enableHook =
FALSE;
295 if ((((oldValue & 1) == 1)) && (((newValue & 1) == 0)))
301 else if ((((oldValue & 1) == 0)) && (((newValue & 1) == 1)))
307 else if (((oldValue & 1) == 1) && ((newValue & 1) == 1) &&
313 disableHook = enableHook =
TRUE;
321 ERROR(
"[ERROR] IntHookGvaDisableHooks failed: 0x%08x\n", status);
325 if (!!(newValue &
PT_P))
327 newGpaPage = (
CLEAN_PHYS_ADDRESS64(newValue) & (~(NewPageSize - 1))) + (Hook->GvaPage & (NewPageSize - 1));
328 Hook->IsPageWritable = !!(newValue &
PT_RW);
336 ERROR(
"[ERROR] IntHookGvaEnableHooks failed: 0x%08x\n", status);
403 if ((Gva &
PAGE_MASK) != ((Gva + Length - 1) & PAGE_MASK))
416 if (NULL == pGvaHook)
449 ERROR(
"[ERROR] IntHookPtsSetHook failed: 0x%08x\n", status);
451 goto cleanup_and_exit;
465 ERROR(
"[ERROR] IntHookGvaHandleSwap failed: 0x%08x\n", status);
466 goto cleanup_and_exit;
477 ERROR(
"[ERROR] IntHookPtsSetHook failed: 0x%08x\n", status);
479 goto cleanup_and_exit;
496 ERROR(
"[ERROR] IntHookGvaRemoveHookInternal failed: 0x%08x\n", status2);
542 ERROR(
"[ERROR] IntHookGvaRemoveHookInternal failed: 0x%08x\n", status);
577 ERROR(
"[ERROR] Trying to delete a non-removed hook!\n");
583 if (NULL != Hook->GpaHook)
588 ERROR(
"[ERROR] IntHookGpaDeleteHook failed: 0x%08x\n", status);
592 if (NULL != Hook->PtsHook)
597 ERROR(
"[ERROR] IntHookPtsDeleteHook failed: 0x%08x\n", status);
647 ERROR(
"[ERROR] IntHookGvaDeleteHookInternal failed: 0x%08x\n", status);
696 ERROR(
"[ERROR] IntHookGvaDeleteHookInternal failed: 0x%08x\n", status);
701 ERROR(
"[ERROR] Invalid hook state: %x for hook at GVA 0x%016llx\n",
#define CONTAINING_RECORD(List, Type, Member)
BOOLEAN Valid
Set to True if the information in the structure is valid, False otherwise.
BOOLEAN Dirty
Set whenever hooks are added or removed.
void * Context
User-defined data that will be supplied to the callback.
QWORD IntAlertCoreGetFlags(QWORD ProtectionFlag, INTRO_ACTION_REASON Reason)
Returns the flags for an alert.
DWORD Size
The size of the access.
BOOLEAN IsPageWritable
True if the page is writable, false otherwise.
HOOK_GVA_STATE GvaHooks
GVA hooks state.
MITRE_ID MitreID
The Mitre ID that corresponds to this attack.
INTSTATUS IntHookGpaRemoveHook(HOOK_GPA **Hook, DWORD Flags)
Remove a GPA hook.
LIST_ENTRY Link
List entry element.
#define CLEAN_PHYS_ADDRESS64(x)
QWORD SystemCr3
The Cr3 used to map the kernel.
#define INT_STATUS_SUCCESS
QWORD NewValue[8]
The written value. Only the first Size bytes are valid.
static INTSTATUS IntHookGvaEnableHooks(HOOK_GVA *Hook, QWORD NewGpaPage)
Enable a GVA hook.
#define IntEnterDebugger()
struct _LIST_ENTRY * Flink
static INTSTATUS IntHookGvaDisableHooks(HOOK_GVA *Hook)
Deactivates a GVA hook.
#define INT_SUCCESS(Status)
#define HOOK_FLG_DISABLED
If flag is set, the hook is disabled, therefore ignored on EPT violations.
BOOLEAN IsIntegrityOn
True if integrity checks are enabled for this page. Integrity checks are enabled if the this is a wri...
QWORD Flags
A combination of ALERT_FLAG_* values describing the alert.
WORD Offset
Offset inside the 4K page, interval [0, 4095].
LIST_HEAD RemovedHooksList
IntHookGvaCommitHooks function is called.
static INTSTATUS IntHookGvaDeleteHookInternal(HOOK_GVA *Hook, DWORD Flags)
Completely delete a GVA hook.
BOOLEAN KernelBetaDetections
True if the kernel protection is in beta (log-only) mode.
INTRO_VIOLATION_HEADER Header
The alert header.
BYTE EptHookType
The type of the hook in EPT (see IG_EPT_HOOK_TYPE)
struct _EVENT_TRANSLATION_VIOLATION::@301 Victim
#define INT_STATUS_NOT_NEEDED_HINT
KERNEL_DRIVER * Driver
The driver that's modifying the memory.
#define HpAllocWithTag(Len, Tag)
int INTSTATUS
The status data type.
QWORD GvaPage
Guest virtual page base address, aligned to 4K.
HOOK_STATE * gHooks
Global hooks state.
QWORD VirtualAddress
The Virtual Address whose translation is being modified.
Event structure for illegal paging-structures modifications.
QWORD Rip
The value of the guest RIP register when the event was generated.
Describes a kernel-mode originator.
union _HOOK_GVA::@85 Callback
EVENT_TRANSLATION_VIOLATION Translation
INTRO_GUEST_TYPE OSType
The type of the guest.
void IntAlertFillCpuContext(BOOLEAN CopyInstruction, INTRO_CPUCTX *CpuContext)
Fills the current CPU context for an alert.
struct _EXCEPTION_KM_ORIGINATOR::@63 Return
INTSTATUS IntHookGvaDeleteHook(HOOK_GVA **Hook, DWORD Flags)
Completely delete a GVA hook.
INTSTATUS IntHookGpaSetHook(QWORD Gpa, DWORD Length, BYTE Type, PFUNC_EptViolationCallback Callback, void *Context, void *ParentHook, DWORD Flags, HOOK_GPA **Hook)
Places an EPT hook on the indicated memory range.
QWORD CurPageSize
Current page size.
INTSTATUS IntHookPtsSetHook(QWORD Cr3, QWORD VirtualAddress, PFUNC_SwapCallback Callback, void *Context, void *Parent, DWORD Flags, PHOOK_PTS *Hook)
Start monitoring translation modifications for the given VirtualAddress.
void IntAlertFillVersionInfo(INTRO_VIOLATION_HEADER *Header)
Fills version information for an alert.
INTSTATUS IntHookGvaInit(void)
Initialize the GVA hooks system.
TRANS_VIOLATION_TYPE ViolationType
INTRO_ACTION_REASON Reason
The reason for which Action was taken.
BOOLEAN HooksRemoved
True if at least one hook has been removed since the last commit.
BYTE HookType
The type of the hook structure (see _HOOK_TYPE)
#define ALERT_FLAG_BETA
If set, the alert is a BETA alert. No action was taken.
GENERIC_ALERT gAlert
Global alert buffer.
#define HOOK_FLG_GLOBAL_MASK
Global flags must be defined here and must be handled by each hooks layer (even if it ignores them...
#define INT_STATUS_NOT_INITIALIZED
INTRO_CPUCTX CpuContext
The context of the CPU that triggered the alert.
INTSTATUS IntNotifyIntroEvent(INTRO_EVENT_TYPE EventClass, void *Param, size_t EventSize)
Notifies the integrator about an introspection alert.
static BOOLEAN RemoveEntryList(LIST_ENTRY *Entry)
QWORD CurEntry
Current page-table entry.
void * ParentHook
The parent hook. For a GPA hook, for example, a GVA hook or a PagedHook will be the parent hook...
#define HOOK_FLG_CHAIN_DELETE
If flag is set, then we won't remove the hook on commit phase; we'll let the parent hook handle the d...
HOOK_HEADER Header
The hook header.
INTRO_WRITE_INFO WriteInfo
The original and new address to which VirtualAddress translates.
#define HpFreeAndNullWithTag(Add, Tag)
INTSTATUS IntHookPtsRemoveHook(HOOK_PTS **Hook, DWORD Flags)
Remove a PTS hook.
#define INT_STATUS_INVALID_INTERNAL_STATE
Sent for virtual address translation alerts. See EVENT_TRANSLATION_VIOLATION.
INTSTATUS IntHookGpaDeleteHook(HOOK_GPA **Hook, DWORD Flags)
Permanently delete a GPA hook.
LIST_HEAD GvaHooks
The list of GVA hooks.
void IntAlertFillWinProcessCurrent(INTRO_PROCESS *EventProcess)
Saves information about the current Windows process inside an alert.
static void InsertTailList(LIST_ENTRY *ListHead, LIST_ENTRY *Entry)
static void InitializeListHead(LIST_ENTRY *ListHead)
#define UNREFERENCED_PARAMETER(P)
INTSTATUS IntHookPtsDeleteHook(HOOK_PTS **Hook, DWORD Flags)
Permanently delete the PTS hook.
static INTSTATUS IntHookGvaHandleSwap(HOOK_GVA *Hook, QWORD VirtualAddress, QWORD OldEntry, QWORD NewEntry, QWORD OldPageSize, QWORD NewPageSize)
Handle a swap event on a hooked guest virtual page.
QWORD OldValue[8]
The original value. Only the first Size bytes are valid.
No access type. This can be used for swap hooks.
MM Mm
Guest memory information, such as paging mode, system Cr3 value, etc.
INTRO_MODULE Module
The module that modified the translation.
GUEST_STATE gGuest
The current guest state.
PFUNC_EptViolationCallback Access
The read/write/execute access callback. Valid if Type != IG_EPT_HOOK_NONE.
INTRO_MODULE ReturnModule
The module to which the current code return to.
struct _EXCEPTION_KM_ORIGINATOR::@64 Original
INTRO_ACTION Action
The action that was taken as the result of this alert.
PHOOK_PTS PtsHook
The page tables hook.
struct _EVENT_TRANSLATION_VIOLATION::@300 Originator
#define INT_STATUS_INVALID_PARAMETER_1
#define INT_STATUS_NOT_SUPPORTED
INTRO_PROCESS CurrentProcess
The current process.
INTSTATUS IntHookGvaRemoveHook(HOOK_GVA **Hook, DWORD Flags)
Remove a GVA hook.
The action was blocked because there was no exception for it.
After a page was swapped-in, its hash no longer matches the one it had when it was swapped-out...
DWORD Flags
Generic flags. Check out EPT Hook flags.
void IntAlertFillWinKmModule(const KERNEL_DRIVER *Driver, INTRO_MODULE *EventModule)
Saves kernel module information inside an alert.
INTSTATUS IntHookGvaCommitHooks(void)
Commit all the modified GVA hooks.
INTSTATUS IntExceptKernelGetOriginator(EXCEPTION_KM_ORIGINATOR *Originator, DWORD Options)
This function is used to get the information about the kernel-mode originator.
INTSTATUS IntHookGvaSetHook(QWORD Cr3, QWORD Gva, DWORD Length, BYTE Type, void *Callback, void *Context, void *ParentHook, DWORD Flags, HOOK_GVA **GvaHook)
Set a read, write, execute or swap hook on a guest virtual address.
static INTSTATUS IntHookGvaRemoveHookInternal(HOOK_GVA *Hook, DWORD Flags)
Remove a GVA hook.
Measures the deletion of HOOK_GVA objects.
INTSTATUS IntMemClkHashRegion(QWORD VirtualAddress, QWORD PhysicalAddress, DWORD Size, DWORD *Crc32)
Hashes the contents of a cloaked memory page.
#define HOOK_FLG_REMOVE
If flag is set, the hook has been removed, and waits the next commit to be actually deleted...
PFUNC_SwapCallback Swap
The swap callback. Valid if Type == IG_EPT_HOOK_NONE.
#define INT_STATUS_INSUFFICIENT_RESOURCES