Code Monkey home page Code Monkey logo

hyperdbg's Introduction

HyperDBG

hyper dbg system

빌드

  1. https://docs.hyperdbg.org/getting-started/build-and-install 순서대로 visual studio > windows sdk > wdk 설치

build 폴더에서 MAKE 실행

  1. 원격 연결 ( 시리얼 포트 설정 : \.\pipe\HyperDbgPipe) VM 내부 > .debug prepare serial 115200 com1 호스트 > .debug remote namedpipe \.\pipe\HyperDbgPipe

Unique Features

First Release (v0.1.0.0)

  • Advanced Hypervisor-based Kernel Mode Debugger [link][link][link]
  • Classic EPT Hook (Hidden Breakpoint) [link][link][link]
  • Inline EPT Hook (Inline Hook) [link][link]
  • Monitor Memory For R/W (Emulating Hardware Debug Registers Without Limitation) [link][link][link]
  • SYSCALL Hook (Disable EFER & Handle #UD) [link][link][link]
  • SYSRET Hook (Disable EFER & Handle #UD) [link][link]
  • CPUID Hook & Monitor [link][link]
  • RDMSR Hook & Monitor [link][link]
  • WRMSR Hook & Monitor [link][link]
  • RDTSC/RDTSCP Hook & Monitor [link]
  • RDPMC Hook & Monitor [link]
  • VMCALL Hook & Monitor [link]
  • Debug Registers Hook & Monitor [link]
  • I/O Port (In Instruction) Hook & Monitor [link][link]
  • I/O Port (Out Instruction) Hook & Monitor [link][link]
  • MMIO Monitor [link]
  • Exception (IDT < 32) Monitor [link][link][link]
  • External-Interrupt (IDT > 32) Monitor [link][link][link]
  • Running Automated Scripts [link]
  • Transparent-mode (Anti-debugging and Anti-hypervisor Resistance) [link][link]
  • Running Custom Assembly In Both VMX-root, VMX non-root (Kernel & User) [link]
  • Checking For Custom Conditions [link][link]
  • Process-specific & Thread-specific Debugging [link][link][link]
  • VMX-root Compatible Message Tracing [link]
  • Powerful Kernel Side Scripting Engine [link][link]
  • Support To Symbols (Parsing PDB Files) [link][link]
  • Mapping Data To Symbols & Create Structures, Enums From PDB Files [link][link][link]
  • Event Forwarding (#DFIR) [link][link]
  • Transparent Breakpoint Handler [link][link]
  • Various Custom Scripts [link]

Second Release (v0.2.0.0)

  • HyperDbg Software Development Kit (SDK) [link]

Third Release (v0.3.0.0)

  • Event Short-circuiting [link][link]
  • Tracking records of function calls and return addresses [link]
  • Kernel-level Length Disassembler Engine (LDE) [link][link]

Fourth Release (v0.4.0.0)

  • Memory Execution Monitor & Execution Blocking [link]
  • Custom Page-fault Injection [link]

Fifth Release (v0.5.0.0)

  • Different Event Calling Stages [link]

Sixth Release (v0.6.0.0)

  • Injecting Custom Interrupts/Exceptions/Faults [link][link]

Seventh Release (v0.7.0.0)

  • Instant events in the Debugger Mode [link]

Eighth Release (v0.8.0.0)

  • Detect kernel-to-user and user-to-kernel transitions [link]

Analyze Features

Advanced Hypervisor-based Kernel Mode Debugger

windbg, gdb 같은 커널 디버거는 크게 바뀌지 않음 -> 커널 모드를 디버깅하려는 디버거는 하드웨어 계층(링) 측면에 더 많은 권한을 가져야 함 -> 운영 체제를 방해하지 않고 별도의 레이어 -> hypervisor

hyperDbg는 하이퍼바이저 기술을 이용하여 디버깅 기술을 구현 + Anti-디버깅 & Anti-하이퍼바이저 우회

VMI - Virtual Machine Interface 모드 -> 가상 머신의 메모리 덤프를 생성 & 프로세스 상태 등을 실시간으로 분석하고 모니터링 하기 위 해사용 [r2vmi github]

Classic EPT Hook [ Hidden Breakpoint ]

..

Code Analyze

VM EXIT - EPT_VIOLATION

[vm exit]

  1. VM EXIT > EPT_VIOLATION 흐름

EPT Violation 발생 VM EXIT > VM EXIT Handler 호출 이때 인자로 guest의 레지스터 정보들이 인자로 들어옴

guest로 넘어올때 기본적으로 cpu의 레지스트리에 저장됨 > 이를 함수로 호출하기 위해 스택에 넣는 asm 코드 작업이 필요함 [asm 코드</>]

** VM EXIT가 발생하면 VMM은 guest의 eip를 조정해줘야함 > 안그럼 무한 루프에 빠짐 **

typedef struct GUEST_REGS
{
    //
    // DO NOT FUCKING TOUCH THIS STRUCTURE WITHOUT COORDINATION WITH SINA
    //

    UINT64 rax; // 0x00
    UINT64 rcx; // 0x08
    UINT64 rdx; // 0x10
    UINT64 rbx; // 0x18
    UINT64 rsp; // 0x20
    UINT64 rbp; // 0x28
    UINT64 rsi; // 0x30
    UINT64 rdi; // 0x38
    UINT64 r8;  // 0x40
    UINT64 r9;  // 0x48
    UINT64 r10; // 0x50
    UINT64 r11; // 0x58
    UINT64 r12; // 0x60
    UINT64 r13; // 0x68
    UINT64 r14; // 0x70
    UINT64 r15; // 0x78

    //
    // DO NOT FUCKING TOUCH THIS STRUCTURE WITHOUT COORDINATION WITH SINA
    //

} GUEST_REGS, *PGUEST_REGS;

switch 문을 통해 EPT_VIOLATION 인지 확인함

VCpu = Virtual Machine State 구조체 (==? VMCS) https://github1s.com/nks0005/HyperDbg/blob/master/_hyperdbg/hyperdbg/hprdbghv/header/common/State.h#L285-L339

VmxVmexitHandler(_Inout_ PGUEST_REGS GuestRegs)
    ...

    case VMX_EXIT_REASON_EPT_VIOLATION:
    {
        if (EptHandleEptViolation(VCpu) == FALSE)
        {
            LogError("Err, there were errors in handling EPT violation");
        }

        break;
    }

EptHandleEptViolation > TRUE의 경우 의도한 EPT Violation ( ept 훅 등... )

VCpu의 ExitQualification 값을 이용하여 무슨 violation 종류인지 값을 담음] VMX_EXIT_QUALIFICATION_EPT_VIOLATION 구조체 https://github1s.com/nks0005/HyperDbg/blob/master/_hyperdbg/hyperdbg/dependencies/ia32-doc/out/ia32.h#L18596-L18790

총 17개 종류가 있음 - 각 1비트로 계산됨 ReadAccess: 데이터 읽기 액세스가 EPT 위반의 원인인 경우 설정됩니다. WriteAccess: 데이터 쓰기 액세스가 EPT 위반의 원인인 경우 설정됩니다. ExecuteAccess: 명령어 실행이 EPT 위반의 원인인 경우 설정됩니다. EptReadable: EPT 위반의 원인이 된 가상 주소가 읽기 가능한지 여부를 나타냅니다. EptWriteable: EPT 위반의 원인이 된 가상 주소가 쓰기 가능한지 여부를 나타냅니다. EptExecutable: EPT 위반의 원인이 된 가상 주소가 실행 가능한지 여부를 나타냅니다. EptExecutableForUserMode: 사용자 모드 선형 주소에서 실행 가능한지 여부를 나타냅니다. ValidGuestLinearAddress: 게스트 선형 주소 필드가 유효한지 여부를 나타냅니다. CausedByTranslation: 주소 변환에 의해 EPT 위반이 발생한 경우 설정됩니다. UserModeLinearAddress: 사용자 모드 선형 주소 여부를 나타냅니다. ReadableWritablePage: 읽기/쓰기 가능한 페이지인지 여부를 나타냅니다. ExecuteDisablePage: 실행 비활성 페이지 여부를 나타냅니다. NmiUnblocking: IRET으로 인한 NMI 언블로킹 여부를 나타냅니다. ShadowStackAccess: 쉐도우 스택 액세스 여부를 나타냅니다. SupervisorShadowStack: 슈퍼바이저 쉐도우 스택 여부를 나타냅니다. GuestPagingVerification: 게스트 페이징 확인 여부를 나타냅니다. AsynchronousToInstruction: 명령어 실행과 비동기적으로 관련된 액세스 여부를 나타냅니다.

BOOLEAN
EptHandleEptViolation(VIRTUAL_MACHINE_STATE * VCpu)
{
    UINT64                               GuestPhysicalAddr;
    VMX_EXIT_QUALIFICATION_EPT_VIOLATION ViolationQualification = {.AsUInt = VCpu->ExitQualification};

    //
    // Reading guest physical address
    //
    __vmx_vmread(VMCS_GUEST_PHYSICAL_ADDRESS, &GuestPhysicalAddr);
   

https://ocw.snu.ac.kr/sites/default/files/NOTE/2566.pdf

ExecTrapHandleEptViolationVmexit > MBEC (Monitor Mode Execution Control) 후킹과 관련된 EPT (Extended Page Tables) 위반을 처리하는 데 사용

MBEC -> 실제 물리 메모리를 등록해서 해당 물리 메모리를 모니터링 -> 트랩 발생 ( EPT VIOLATION ? ) epthook2 기능이 아닐지?

    if (ExecTrapHandleEptViolationVmexit(VCpu, &ViolationQualification))
    {
        return TRUE;
    }
    else if (EptHandlePageHookExit(VCpu, ViolationQualification, GuestPhysicalAddr))
    {
        //
        // Handled by page hook code
        //
        return TRUE;
    }
    else if (VmmCallbackUnhandledEptViolation(VCpu->CoreId, (UINT64)ViolationQualification.AsUInt, GuestPhysicalAddr))
    {
        //
        // Check whether this violation is meaningful for the application or not
        //
        return TRUE;
    }

    LogError("Err, unexpected EPT violation at RIP: %llx", VCpu->LastVmexitRip);
    DbgBreakPoint();
    //
    // Redo the instruction that caused the exception
    //
    return FALSE;
}

VM EXIT - VM CALL?

hyperdbg

    case VMX_EXIT_REASON_EXECUTE_VMCALL:
    {
        //
        // Handle vm-exits of VMCALLs
        //
        DispatchEventVmcall(VCpu);

        break;
    }

cheat_engine

hyperdbg's People

Contributors

air14 avatar aleeamini avatar behroozabbassi avatar cutecatsandvirtualmachines avatar germanaizek avatar gmh5225 avatar hyperdbgbot avatar jianxq avatar l1b0 avatar mattiwatti avatar mhgholamrezaei avatar momo5502 avatar mrezn avatar nitr0-g avatar nks0005 avatar rwkeith avatar sal3h avatar sariaki avatar sinakarvandi avatar thiagoalexsander avatar velocityra avatar vxcute avatar wxwywz avatar xmaple555 avatar xorrsp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.