2020-05-12 13:12:21 -07:00
|
|
|
/**
|
|
|
|
|
* @file DebuggerEvents.c
|
2022-01-18 22:38:56 +03:30
|
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
2020-05-12 13:12:21 -07:00
|
|
|
* @brief Implementation of Debugger events (triggers and enable events)
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
2020-05-12 13:12:21 -07:00
|
|
|
* @version 0.1
|
|
|
|
|
* @date 2020-05-12
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
2020-05-12 13:12:21 -07:00
|
|
|
* @copyright This project is released under the GNU Public License v3.
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
2020-05-12 13:12:21 -07:00
|
|
|
*/
|
2022-05-04 16:38:21 -07:00
|
|
|
#include "pch.h"
|
2020-05-12 13:12:21 -07:00
|
|
|
|
|
|
|
|
/**
|
2020-08-28 04:03:12 -07:00
|
|
|
* @brief routines for !syscall command (enable syscall hook)
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
2020-05-12 13:12:21 -07:00
|
|
|
*/
|
|
|
|
|
VOID
|
2023-10-21 21:49:00 +09:00
|
|
|
DebuggerEventEnableEferOnAllProcessors()
|
2020-05-12 13:12:21 -07:00
|
|
|
{
|
2023-10-21 21:49:00 +09:00
|
|
|
ConfigureEnableEferSyscallEventsOnAllProcessors();
|
2020-05-12 13:12:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-28 04:03:12 -07:00
|
|
|
* @brief routines for !syscall command (disable syscall hook)
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
2020-05-12 13:12:21 -07:00
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
DebuggerEventDisableEferOnAllProcessors()
|
|
|
|
|
{
|
2023-01-26 21:24:12 +09:00
|
|
|
ConfigureDisableEferSyscallEventsOnAllProcessors();
|
2020-05-12 13:12:21 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-30 03:11:13 -07:00
|
|
|
/**
|
|
|
|
|
* @brief routines for debugging threads (enable mov-to-cr3 exiting)
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
2020-08-30 03:11:13 -07:00
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
DebuggerEventEnableMovToCr3ExitingOnAllProcessors()
|
|
|
|
|
{
|
2023-01-26 21:24:12 +09:00
|
|
|
ConfigureEnableMovToCr3ExitingOnAllProcessors();
|
2020-08-30 03:11:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief routines for debugging threads (disable mov-to-cr3 exiting)
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
2020-08-30 03:11:13 -07:00
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
DebuggerEventDisableMovToCr3ExitingOnAllProcessors()
|
|
|
|
|
{
|
2023-01-26 21:24:12 +09:00
|
|
|
ConfigureDisableMovToCr3ExitingOnAllProcessors();
|
2020-08-30 03:11:13 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-12 15:43:34 -07:00
|
|
|
/**
|
2024-01-31 18:42:58 +09:00
|
|
|
* @brief Apply monitor ept hook events for address
|
2022-09-23 17:21:42 +09:00
|
|
|
*
|
2024-01-31 18:01:51 +09:00
|
|
|
* @param HookingDetails
|
2023-07-07 01:21:07 +09:00
|
|
|
* @param ProcessId
|
2023-10-25 21:09:25 +09:00
|
|
|
* @param ApplyDirectlyFromVmxRoot
|
2023-07-07 01:21:07 +09:00
|
|
|
*
|
2022-09-23 17:21:42 +09:00
|
|
|
* @return VOID
|
2020-05-12 15:43:34 -07:00
|
|
|
*/
|
|
|
|
|
BOOLEAN
|
2024-01-31 18:01:51 +09:00
|
|
|
DebuggerEventEnableMonitorReadWriteExec(EPT_HOOKS_ADDRESS_DETAILS_FOR_MEMORY_MONITOR * HookingDetails,
|
|
|
|
|
UINT32 ProcessId,
|
|
|
|
|
BOOLEAN ApplyDirectlyFromVmxRoot)
|
2020-05-12 15:43:34 -07:00
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Check if the detail is ok for either read or write or both
|
|
|
|
|
//
|
2024-01-31 18:42:58 +09:00
|
|
|
if (!HookingDetails->SetHookForRead && !HookingDetails->SetHookForWrite && !HookingDetails->SetHookForExec)
|
2020-05-12 15:43:34 -07:00
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 05:35:04 -07:00
|
|
|
//
|
|
|
|
|
// If the read is FALSE and WRITE is TRUE, then the processor doesn't support
|
2021-11-13 02:10:12 +03:30
|
|
|
// such a thing, we will enable the Read silently here if, this problem will be
|
2020-05-13 05:35:04 -07:00
|
|
|
// solved when the trigger works, the trigger routines won't enable reads
|
|
|
|
|
//
|
2024-01-31 18:42:58 +09:00
|
|
|
if (HookingDetails->SetHookForWrite)
|
2020-05-13 05:35:04 -07:00
|
|
|
{
|
2024-01-31 18:42:58 +09:00
|
|
|
HookingDetails->SetHookForRead = TRUE;
|
2020-05-13 05:35:04 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-12 15:43:34 -07:00
|
|
|
//
|
|
|
|
|
// Perform the EPT Hook
|
|
|
|
|
//
|
2023-10-26 15:50:39 +09:00
|
|
|
if (ApplyDirectlyFromVmxRoot)
|
|
|
|
|
{
|
2024-01-31 18:42:58 +09:00
|
|
|
return ConfigureEptHookMonitorFromVmxRoot(KeGetCurrentProcessorNumberEx(NULL),
|
|
|
|
|
HookingDetails);
|
2023-10-26 15:50:39 +09:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-01-31 18:42:58 +09:00
|
|
|
return ConfigureEptHookMonitor(KeGetCurrentProcessorNumberEx(NULL),
|
|
|
|
|
HookingDetails,
|
|
|
|
|
ProcessId);
|
2023-10-26 15:50:39 +09:00
|
|
|
}
|
2020-05-12 15:43:34 -07:00
|
|
|
}
|
2023-01-08 04:34:41 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Handle process or thread switches
|
|
|
|
|
*
|
|
|
|
|
* @param CoreId
|
|
|
|
|
*
|
|
|
|
|
* @return BOOLEAN
|
|
|
|
|
*/
|
|
|
|
|
BOOLEAN
|
|
|
|
|
DebuggerCheckProcessOrThreadChange(_In_ UINT32 CoreId)
|
|
|
|
|
{
|
|
|
|
|
PROCESSOR_DEBUGGING_STATE * DbgState = &g_DbgState[CoreId];
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Check whether intercepting this process or thread is active or not
|
|
|
|
|
//
|
|
|
|
|
if (DbgState->ThreadOrProcessTracingDetails.InterceptClockInterruptsForThreadChange ||
|
|
|
|
|
DbgState->ThreadOrProcessTracingDetails.InterceptClockInterruptsForProcessChange)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// We only handle interrupts that are related to the clock-timer interrupt
|
|
|
|
|
//
|
|
|
|
|
if (DbgState->ThreadOrProcessTracingDetails.InterceptClockInterruptsForThreadChange)
|
|
|
|
|
{
|
|
|
|
|
return ThreadHandleThreadChange(DbgState);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return ProcessHandleProcessChange(DbgState);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Not handled here
|
|
|
|
|
//
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|