Skip to content

Commit

Permalink
Merge pull request ayoubfaouzi#197 from Mattiwatti/debugobjecthandle
Browse files Browse the repository at this point in the history
DebugObjectHandle improvements
  • Loading branch information
gsuberland authored Jan 7, 2020
2 parents 7a6c54d + 0b2627d commit 8ff90a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ the process isn't being debugged

BOOL NtQueryInformationProcess_ProcessDebugObject()
{
// ProcessDebugFlags
// ProcessDebugObjectHandle
const int ProcessDebugObjectHandle = 0x1e;

auto NtQueryInfoProcess = static_cast<pNtQueryInformationProcess>(API::GetAPI(API_IDENTIFIER::API_NtQueryInformationProcess));

// Other Vars
NTSTATUS Status;
HANDLE hDebugObject = NULL;
HANDLE hDebugObject = NULL;

#if defined (ENV64BIT)
DWORD dProcessInformationLength = sizeof(ULONG) * 2;
Expand All @@ -28,10 +28,22 @@ BOOL NtQueryInformationProcess_ProcessDebugObject()
DWORD32 IsRemotePresent = 0;
#endif

// Regular check
Status = NtQueryInfoProcess(GetCurrentProcess(), ProcessDebugObjectHandle, &hDebugObject, dProcessInformationLength, NULL);

if (Status == 0x00000000 && hDebugObject)
return TRUE;
else
return FALSE;

if (Status != STATUS_PORT_NOT_SET)
return TRUE;
if (hDebugObject != NULL)
return TRUE;

// Check with overlapping return length and debug object handle buffers to find anti-anti-debuggers
Status = NtQueryInfoProcess(GetCurrentProcess(), ProcessDebugObjectHandle, &hDebugObject, dProcessInformationLength, (PULONG)&hDebugObject);
if (Status != STATUS_PORT_NOT_SET)
return TRUE;
if (hDebugObject == NULL)
return TRUE; // Handle incorrectly zeroed
if ((ULONG)(ULONG_PTR)hDebugObject != dProcessInformationLength)
return TRUE; // Return length incorrectly overwritten

return FALSE;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

BOOL NtQueryInformationProcess_ProcessDebugObject();
BOOL NtQueryInformationProcess_ProcessDebugObject();

#define STATUS_PORT_NOT_SET ((NTSTATUS)0xC0000353L)

0 comments on commit 8ff90a3

Please sign in to comment.