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

hide the debugger from anti-debugging and anti-hypervisor methods (headers) More...

Go to the source code of this file.

Classes

struct  _TRANSPARENCY_MEASUREMENTS
 The measurements from user-mode and kernel-mode. More...
 
struct  _TRANSPARENCY_PROCESS
 The ProcessList of TRANSPARENCY_MEASUREMENTS is from this architecture. More...
 

Macros

#define MSR_IA32_TIME_STAMP_COUNTER   0x10
 IA32_TIME_STAMP_COUNTER MSR (rcx)
 
#define RAND_MAX   0x7fff
 Maximum value that can be returned by the rand function.
 

Typedefs

typedef struct _TRANSPARENCY_MEASUREMENTS TRANSPARENCY_MEASUREMENTS
 The measurements from user-mode and kernel-mode.
 
typedef struct _TRANSPARENCY_MEASUREMENTSPTRANSPARENCY_MEASUREMENTS
 
typedef struct _TRANSPARENCY_PROCESS TRANSPARENCY_PROCESS
 The ProcessList of TRANSPARENCY_MEASUREMENTS is from this architecture.
 
typedef struct _TRANSPARENCY_PROCESSPTRANSPARENCY_PROCESS
 

Functions

BOOLEAN TransparentModeStart (VIRTUAL_MACHINE_STATE *VCpu, UINT32 ExitReason)
 VM-Exit handler for different exit reasons.
 

Detailed Description

hide the debugger from anti-debugging and anti-hypervisor methods (headers)

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

Macro Definition Documentation

◆ MSR_IA32_TIME_STAMP_COUNTER

#define MSR_IA32_TIME_STAMP_COUNTER   0x10

IA32_TIME_STAMP_COUNTER MSR (rcx)

◆ RAND_MAX

#define RAND_MAX   0x7fff

Maximum value that can be returned by the rand function.

Typedef Documentation

◆ PTRANSPARENCY_MEASUREMENTS

◆ PTRANSPARENCY_PROCESS

◆ TRANSPARENCY_MEASUREMENTS

The measurements from user-mode and kernel-mode.

◆ TRANSPARENCY_PROCESS

The ProcessList of TRANSPARENCY_MEASUREMENTS is from this architecture.

Function Documentation

◆ TransparentModeStart()

BOOLEAN TransparentModeStart ( VIRTUAL_MACHINE_STATE * VCpu,
UINT32 ExitReason )

VM-Exit handler for different exit reasons.

Should be called from vmx-root

Parameters
VCpuThe virtual processor's state
ExitReasonExit Reason
Returns
BOOLEAN Return True we should emulate RDTSCP or return false if we should not emulate RDTSCP
494{
495 UINT32 Aux = 0;
496 PLIST_ENTRY TempList = 0;
497 PCHAR CurrentProcessName = 0;
498 UINT32 CurrentProcessId;
499 UINT64 CurrrentTime;
500 HANDLE CurrentThreadId;
501 BOOLEAN Result = TRUE;
502 BOOLEAN IsProcessOnTransparencyList = FALSE;
503
504 //
505 // Save the current time
506 //
507 CurrrentTime = __rdtscp(&Aux);
508
509 //
510 // Save time of vm-exit on each logical processor separately
511 //
512 VCpu->TransparencyState.PreviousTimeStampCounter = CurrrentTime;
513
514 //
515 // Find the current process id and name
516 //
517 CurrentProcessId = HANDLE_TO_UINT32(PsGetCurrentProcessId());
518 CurrentProcessName = CommonGetProcessNameFromProcessControlBlock(PsGetCurrentProcess());
519
520 //
521 // Check for process id and process name, if not match then we don't emulate it
522 //
524 while (&g_TransparentModeMeasurements->ProcessList != TempList->Flink)
525 {
526 TempList = TempList->Flink;
527 PTRANSPARENCY_PROCESS ProcessDetails = (PTRANSPARENCY_PROCESS)CONTAINING_RECORD(TempList, TRANSPARENCY_PROCESS, OtherProcesses);
528 if (ProcessDetails->TrueIfProcessIdAndFalseIfProcessName)
529 {
530 //
531 // This entry is process id
532 //
533 if (ProcessDetails->ProcessId == CurrentProcessId)
534 {
535 //
536 // Let the transparency handler to handle it
537 //
538 IsProcessOnTransparencyList = TRUE;
539 break;
540 }
541 }
542 else
543 {
544 //
545 // This entry is a process name
546 //
547 if (CurrentProcessName != NULL && CommonIsStringStartsWith(CurrentProcessName, ProcessDetails->ProcessName))
548 {
549 //
550 // Let the transparency handler to handle it
551 //
552 IsProcessOnTransparencyList = TRUE;
553 break;
554 }
555 }
556 }
557
558 //
559 // Check whether we find this process on transparency list or not
560 //
561 if (!IsProcessOnTransparencyList)
562 {
563 //
564 // No, we didn't let's do the normal tasks
565 //
566 return TRUE;
567 }
568
569 //
570 // Get current thread Id
571 //
572 CurrentThreadId = PsGetCurrentThreadId();
573
574 //
575 // Check whether we are in new thread or in previous thread
576 //
577 if (VCpu->TransparencyState.ThreadId != CurrentThreadId)
578 {
579 //
580 // It's a new thread Id reset everything
581 //
582 VCpu->TransparencyState.ThreadId = CurrentThreadId;
585 }
586
587 //
588 // Now, it's time to check and play with RDTSC/P and CPUID
589 //
590
591 if (ExitReason == VMX_EXIT_REASON_EXECUTE_RDTSC || ExitReason == VMX_EXIT_REASON_EXECUTE_RDTSCP)
592 {
594 {
595 //
596 // It's a timing and the previous time for the thread is null
597 // so we need to save the time (maybe) for future use
598 //
600 }
602 {
603 //
604 // Someone tries to know about the hypervisor
605 // let's play with them
606 //
607
608 // LogInfo("Possible RDTSC+CPUID+RDTSC");
609 }
612 {
613 //
614 // It's a new rdtscp, let's save the new value
615 //
619 ;
620 }
621
622 //
623 // Adjust the rdtsc based on RevealedTimeStampCounterByRdtsc
624 //
625 VCpu->Regs->rax = 0x00000000ffffffff &
627
628 VCpu->Regs->rdx = 0x00000000ffffffff &
630
631 //
632 // Check if we need to adjust rcx as a result of rdtscp
633 //
634 if (ExitReason == VMX_EXIT_REASON_EXECUTE_RDTSCP)
635 {
636 VCpu->Regs->rcx = 0x00000000ffffffff & Aux;
637 }
638 //
639 // Shows that vm-exit handler should not emulate the RDTSC/P
640 //
641 Result = FALSE;
642 }
643 else if (ExitReason == VMX_EXIT_REASON_EXECUTE_CPUID &&
645 {
646 //
647 // The guy executed one or more CPUIDs after an rdtscp so we
648 // need to add new cpuid value to previous timer and also
649 // we need to store it somewhere to remember this behavior
650 //
654
656 }
657
658 return Result;
659}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define NULL64_ZERO
Definition BasicTypes.h:52
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
TRANSPARENCY_MEASUREMENTS * g_TransparentModeMeasurements
holds the measurements from the user-mode and kernel-mode
Definition GlobalVariables.h:56
#define HANDLE_TO_UINT32(_var)
Definition MetaMacros.h:39
int TransparentRandn(int Average, int Sigma)
Integer Gaussian Random Number Generator(GRNG) based on Box-Muller method. A Float to Integer mapping...
Definition Transparency.c:232
BOOLEAN CommonIsStringStartsWith(const char *pre, const char *str)
Detects whether the string starts with another string.
Definition Common.c:69
PCHAR CommonGetProcessNameFromProcessControlBlock(PEPROCESS Eprocess)
Get process name by eprocess.
Definition Common.c:48
struct _TRANSPARENCY_PROCESS * PTRANSPARENCY_PROCESS
UINT64 CpuidStandardDeviation
Definition Transparency.h:48
UINT64 CpuidAverage
Definition Transparency.h:47
LIST_ENTRY ProcessList
Definition Transparency.h:55
The ProcessList of TRANSPARENCY_MEASUREMENTS is from this architecture.
Definition Transparency.h:64
UINT32 ProcessId
Definition Transparency.h:65
BOOLEAN TrueIfProcessIdAndFalseIfProcessName
Definition Transparency.h:68
PVOID ProcessName
Definition Transparency.h:66
GUEST_REGS * Regs
Definition State.h:305
VM_EXIT_TRANSPARENCY TransparencyState
Definition State.h:330
UINT64 RevealedTimeStampCounterByRdtsc
Definition State.h:141
UINT64 PreviousTimeStampCounter
Definition State.h:138
HANDLE ThreadId
Definition State.h:140
BOOLEAN CpuidAfterRdtscDetected
Definition State.h:142
UINT64 rax
Definition BasicTypes.h:75
UINT64 rcx
Definition BasicTypes.h:76
UINT64 rdx
Definition BasicTypes.h:77