HyperDbg Debugger
Loading...
Searching...
No Matches
Transparency.c File Reference

Try to hide the debugger from anti-debugging and anti-hypervisor methods. More...

#include "pch.h"

Functions

BOOLEAN TransparentHideDebugger (HYPEREVADE_CALLBACKS *HyperevadeCallbacks, DEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE *TransparentModeRequest)
 Hide debugger on transparent-mode (activate transparent-mode).
BOOLEAN TransparentUnhideDebugger ()
 Deactivate transparent-mode.
UINT32 TransparentGetRand ()
 Generate a random number by utilizing RDTSC instruction.
BOOLEAN TransparentAddNameOrProcessIdToTheList (PDEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE Measurements)
 Add name or process id of the target process to the list of processes that HyperDbg should apply transparent-mode on them.

Detailed Description

Try to hide the debugger from anti-debugging and anti-hypervisor methods.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
jtaw5649
Version
0.1
Date
2020-07-07

Function Documentation

◆ TransparentAddNameOrProcessIdToTheList()

BOOLEAN TransparentAddNameOrProcessIdToTheList ( PDEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE Measurements)

Add name or process id of the target process to the list of processes that HyperDbg should apply transparent-mode on them.

Parameters
MeasurementsPointer to the debugger hide and transparent mode request structure
Returns
BOOLEAN
150{
151 SIZE_T SizeOfBuffer;
152 PTRANSPARENCY_PROCESS PidAndNameBuffer;
153
154 //
155 // Check whether it's a process id or it's a process name
156 //
157 if (Measurements->TrueIfProcessIdAndFalseIfProcessName)
158 {
159 //
160 // It's a process Id
161 //
162 SizeOfBuffer = sizeof(TRANSPARENCY_PROCESS);
163 }
164 else
165 {
166 //
167 // It's a process name
168 //
169 SizeOfBuffer = sizeof(TRANSPARENCY_PROCESS) + Measurements->LengthOfProcessName;
170 }
171
172 //
173 // Allocate the Buffer
174 //
175 PidAndNameBuffer = PlatformMemAllocateZeroedNonPagedPool(SizeOfBuffer);
176
177 if (PidAndNameBuffer == NULL)
178 {
179 return FALSE;
180 }
181
182 //
183 // Save the address of the buffer for future de-allocation
184 //
185 PidAndNameBuffer->BufferAddress = PidAndNameBuffer;
186
187 //
188 // Check again whether it's a process id or it's a process name
189 // then fill the structure
190 //
191 if (Measurements->TrueIfProcessIdAndFalseIfProcessName)
192 {
193 //
194 // It's a process Id
195 //
196 PidAndNameBuffer->ProcessId = Measurements->ProcId;
197 PidAndNameBuffer->TrueIfProcessIdAndFalseIfProcessName = TRUE;
198 }
199 else
200 {
201 //
202 // It's a process name
203 //
205
206 //
207 // Move the process name string to the end of the buffer
208 //
209 RtlCopyBytes((VOID *)((UINT64)PidAndNameBuffer + sizeof(TRANSPARENCY_PROCESS)),
210 (CONST VOID *)((UINT64)Measurements + sizeof(DEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE)),
211 Measurements->LengthOfProcessName);
212
213 //
214 // Set the process name location
215 //
216 PidAndNameBuffer->ProcessName = (PVOID)((UINT64)PidAndNameBuffer + sizeof(TRANSPARENCY_PROCESS));
217 }
218
219 //
220 // Link it to the list of process that we need to transparent
221 // vm-exits for them
222 //
223 // InsertHeadList(&g_TransparentModeMeasurements->ProcessList, &(PidAndNameBuffer->OtherProcesses));
224
225 return TRUE;
226}
PVOID PlatformMemAllocateZeroedNonPagedPool(SIZE_T NumberOfBytes)
Allocates zeroed non-paged pool memory.
Definition PlatformMem.c:248
void * PVOID
Definition BasicTypes.h:56
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
struct _DEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE DEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE
request for enable or disable transparent-mode
struct _TRANSPARENCY_PROCESS TRANSPARENCY_PROCESS
The ProcessList of TRANSPARENCY_MEASUREMENTS is from this architecture.
struct _TRANSPARENCY_PROCESS * PTRANSPARENCY_PROCESS
UINT32 LengthOfProcessName
Definition RequestStructures.h:609
BOOLEAN TrueIfProcessIdAndFalseIfProcessName
Definition RequestStructures.h:607
UINT32 ProcId
Definition RequestStructures.h:608
PVOID BufferAddress
Definition Transparency.h:51
UINT32 ProcessId
Definition Transparency.h:49
BOOLEAN TrueIfProcessIdAndFalseIfProcessName
Definition Transparency.h:52
PVOID ProcessName
Definition Transparency.h:50

◆ TransparentGetRand()

UINT32 TransparentGetRand ( )

Generate a random number by utilizing RDTSC instruction.

Masking 16 LSB of the measured clock time.

Returns
UINT32
131{
132 UINT64 Tsc;
133 UINT32 Rand;
134
135 Tsc = CpuReadTsc();
136 Rand = Tsc & 0xffff;
137
138 return Rand;
139}
UINT64 CpuReadTsc(VOID)
Read Time-Stamp Counter.
Definition PlatformIntrinsics.c:295
unsigned int UINT32
Definition BasicTypes.h:54

◆ TransparentHideDebugger()

BOOLEAN TransparentHideDebugger ( HYPEREVADE_CALLBACKS * HyperevadeCallbacks,
DEBUGGER_HIDE_AND_TRANSPARENT_DEBUGGER_MODE * TransparentModeRequest )

Hide debugger on transparent-mode (activate transparent-mode).

Parameters
HyperevadeCallbacksPointer to the HyperEvade callbacks structure
TransparentModeRequestPointer to the transparent debugger mode request
Returns
BOOLEAN
26{
27 UINT32 EvadeMask = TransparentModeRequest->EvadeMask;
28
29 if (EvadeMask == 0)
30 {
32 }
33
34 if ((EvadeMask & ~TRANSPARENT_EVADE_MASK_ALL) != 0)
35 {
37 return FALSE;
38 }
39
40 //
41 // Check if any of the required callbacks are NULL
42 //
43 for (UINT32 i = 0; i < sizeof(HYPEREVADE_CALLBACKS) / sizeof(UINT64); i++)
44 {
45 if (((PVOID *)HyperevadeCallbacks)[i] == NULL)
46 {
47 //
48 // The callback has null entry, so we cannot proceed
49 //
51 return FALSE;
52 }
53 }
54
55 //
56 // Save the callbacks
57 //
58 RtlCopyMemory(&g_Callbacks, HyperevadeCallbacks, sizeof(HYPEREVADE_CALLBACKS));
59
60 //
61 // Check whether the transparent-mode was already initialized or not
62 //
64 {
65 //
66 // Store the system-call numbers information
67 //
69 &TransparentModeRequest->SystemCallNumbersInformation,
71#if ActivateHyperEvadeProject == TRUE
72 //
73 // Choose a random genuine vendor string to replace hypervisor vendor data
74 //
75 g_TransparentGenuineVendorStringIndex = TransparentGetRand() %
76 (sizeof(TRANSPARENT_LEGIT_VENDOR_STRINGS_WCHAR) / sizeof(TRANSPARENT_LEGIT_VENDOR_STRINGS_WCHAR[0]));
77#endif
78
79 //
80 // Enable the transparent mode
81 //
83 g_TransparentEvadeMask = EvadeMask;
84 TransparentModeRequest->EvadeMask = EvadeMask;
85 TransparentModeRequest->KernelStatus = DEBUGGER_OPERATION_WAS_SUCCESSFUL;
86
87 //
88 // Successfully enabled the transparent-mode
89 //
90 return TRUE;
91 }
92 else
93 {
94 TransparentModeRequest->KernelStatus = DEBUGGER_ERROR_DEBUGGER_ALREADY_HIDE;
95 return FALSE;
96 }
97}
SYSTEM_CALL_NUMBERS_INFORMATION g_SystemCallNumbersInformation
System call numbers information.
Definition SyscallFootprints.h:158
UINT32 TransparentGetRand()
Generate a random number by utilizing RDTSC instruction.
Definition Transparency.c:130
#define TRANSPARENT_EVADE_MASK_DEFAULT
Definition Constants.h:689
#define TRANSPARENT_EVADE_MASK_ALL
Definition Constants.h:687
#define DEBUGGER_ERROR_DEBUGGER_ALREADY_HIDE
error, the debugger is already in transparent-mode
Definition ErrorCodes.h:93
#define DEBUGGER_ERROR_UNABLE_TO_HIDE_OR_UNHIDE_DEBUGGER
error, unable to hide the debugger and enter to transparent-mode
Definition ErrorCodes.h:87
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
struct _SYSTEM_CALL_NUMBERS_INFORMATION SYSTEM_CALL_NUMBERS_INFORMATION
Windows System call values that are intercepted by transparency mode.
struct _HYPEREVADE_CALLBACKS HYPEREVADE_CALLBACKS
Prototype of each function needed by hyperevade module.
UINT32 g_TransparentEvadeMask
The enabled transparent-mode feature mask.
Definition Transparency.h:72
HYPEREVADE_CALLBACKS g_Callbacks
List of callbacks.
Definition Transparency.h:23
BOOLEAN g_TransparentMode
Shows whether the debugger transparent mode is enabled (true) or not (false).
Definition Transparency.h:66
SYSTEM_CALL_NUMBERS_INFORMATION SystemCallNumbersInformation
Definition RequestStructures.h:611
UINT32 KernelStatus
Definition RequestStructures.h:613
UINT32 EvadeMask
Definition RequestStructures.h:617

◆ TransparentUnhideDebugger()

BOOLEAN TransparentUnhideDebugger ( )

Deactivate transparent-mode.

Returns
BOOLEAN
106{
108 {
109 //
110 // Disable the transparent-mode
111 //
114
115 return TRUE;
116 }
117 else
118 {
119 return FALSE;
120 }
121}