remove user-mode debugger trap flag ignorance

This commit is contained in:
Sinaei 2023-07-26 17:34:43 +09:00
parent 44b68442f7
commit 68ce21bda0
3 changed files with 18 additions and 42 deletions

View file

@ -1,5 +1,5 @@
/**
* @file remoteconnection.cpp
* @file remote-connection.cpp
* @author Sina Karvandi (sina@hyperdbg.org)
* @brief handle remote connections command
* @details
@ -210,7 +210,7 @@ RemoteConnectionListen(PCSTR Port)
DWORD WINAPI
RemoteConnectionThreadListeningToDebuggee(LPVOID lpParam)
{
char recvbuf[COMMUNICATION_BUFFER_SIZE + TCP_END_OF_BUFFER_CHARS_COUNT] = {0};
char RecvBuf[COMMUNICATION_BUFFER_SIZE + TCP_END_OF_BUFFER_CHARS_COUNT] = {0};
UINT32 BuffLenReceived = 0;
while (g_IsConnectedToRemoteDebuggee)
@ -218,7 +218,7 @@ RemoteConnectionThreadListeningToDebuggee(LPVOID lpParam)
//
// Receive message
//
if (CommunicationClientReceiveMessage(g_ClientConnectSocket, recvbuf, COMMUNICATION_BUFFER_SIZE, &BuffLenReceived) != 0)
if (CommunicationClientReceiveMessage(g_ClientConnectSocket, RecvBuf, COMMUNICATION_BUFFER_SIZE, &BuffLenReceived) != 0)
{
//
// Failed, break
@ -231,18 +231,18 @@ RemoteConnectionThreadListeningToDebuggee(LPVOID lpParam)
//
for (size_t i = 0; i < BuffLenReceived; i++)
{
if (recvbuf[i] == g_EndOfBufferCheckTcp[0] &&
recvbuf[i + 1] == g_EndOfBufferCheckTcp[1] &&
recvbuf[i + 2] == g_EndOfBufferCheckTcp[2] &&
recvbuf[i + 3] == g_EndOfBufferCheckTcp[3])
if (RecvBuf[i] == g_EndOfBufferCheckTcp[0] &&
RecvBuf[i + 1] == g_EndOfBufferCheckTcp[1] &&
RecvBuf[i + 2] == g_EndOfBufferCheckTcp[2] &&
RecvBuf[i + 3] == g_EndOfBufferCheckTcp[3])
{
g_IsEndOfMessageReceived = TRUE;
//
// Cut the last string using \x00 \x00
//
recvbuf[i] = '\x00';
recvbuf[i + 1] = '\x00';
RecvBuf[i] = '\x00';
RecvBuf[i + 1] = '\x00';
break;
}
}
@ -255,7 +255,7 @@ RemoteConnectionThreadListeningToDebuggee(LPVOID lpParam)
//
// Show message from remote debuggee
//
ShowMessages("%s", recvbuf);
ShowMessages("%s", RecvBuf);
}
//
@ -277,7 +277,7 @@ RemoteConnectionThreadListeningToDebuggee(LPVOID lpParam)
//
// Clear the buffer
//
RtlZeroMemory(recvbuf, COMMUNICATION_BUFFER_SIZE);
RtlZeroMemory(RecvBuf, COMMUNICATION_BUFFER_SIZE);
}
//

View file

@ -159,9 +159,14 @@ UdStepInstructions(PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadDebuggingDetails,
VmFuncSetRflagTrapFlag(TRUE);
//
// Rflags' trap flag is set
// Indicate that we should set the trap flag to the FALSE next time on
// the same process/thread
//
ThreadDebuggingDetails->IsRflagsTrapFlagsSet = TRUE;
if (!BreakpointRestoreTheTrapFlagOnceTriggered(PsGetCurrentProcessId(), PsGetCurrentThreadId()))
{
LogWarning("Warning, it is currently not possible to add the current process/thread to the list of processes "
"where the trap flag should be masked. Please ensure that you manually unset the trap flag");
}
break;
@ -386,29 +391,6 @@ UdSpinThreadOnNop(PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadDebuggingDetails,
ThreadDebuggingDetails->IsPaused = TRUE;
}
/**
* @brief Handle after we hit the stepping
* @details This function can be used in vmx-root
*
* @param DbgState The state of the debugger on the current core
* @param ThreadDebuggingDetails
* @return VOID
*/
VOID
UdHandleAfterSteppingReason(PROCESSOR_DEBUGGING_STATE * DbgState,
PUSERMODE_DEBUGGING_THREAD_DETAILS ThreadDebuggingDetails)
{
//
// Unset the trap-flag
//
VmFuncSetRflagTrapFlag(FALSE);
//
// Rflags' trap flag is not set anymore
//
ThreadDebuggingDetails->IsRflagsTrapFlagsSet = FALSE;
}
/**
* @brief Handle special reasons pre-pausings
* @details This function can be used in vmx-root
@ -433,11 +415,6 @@ UdPrePausingReasons(PROCESSOR_DEBUGGING_STATE * DbgState,
{
case DEBUGGEE_PAUSING_REASON_DEBUGGEE_GENERAL_DEBUG_BREAK:
if (ThreadDebuggingDetails->IsRflagsTrapFlagsSet)
{
UdHandleAfterSteppingReason(DbgState, ThreadDebuggingDetails);
}
break;
default:

View file

@ -34,7 +34,6 @@ typedef struct _USERMODE_DEBUGGING_THREAD_DETAILS
UINT32 ThreadId;
UINT64 ThreadRip; // if IsPaused is TRUE
BOOLEAN IsPaused;
BOOLEAN IsRflagsTrapFlagsSet;
DEBUGGER_UD_COMMAND_ACTION UdAction[MAX_USER_ACTIONS_FOR_THREADS];
} USERMODE_DEBUGGING_THREAD_DETAILS, *PUSERMODE_DEBUGGING_THREAD_DETAILS;