Git Product home page Git Product logo

noirvisor's Introduction

NoirVisor

NoirVisor - The Grimoire Hypervisor solution for AMD64 Processors.

NoirVisor虚拟化交流群

Tips: if the link does not work, try to hover the shield icon and see text.

Introduction

NoirVisor is a hardware-accelerated hypervisor (a.k.a VMM, Virtual Machine Monitor) with support to complex functions and purposes. It is designed to support processors based on x86 architecture with hardware-accelerated virtualization feature. For example, Intel processors supporting Intel VT-x or AMD processors supporting AMD-V meet the requirement. By design, NoirVisor determines the processor manufacturer and selects the function core.

Namesake: NoirVisor is named after the Grimoire Noir in NieR:Gestalt/Replicant.

Processor Requirement

Intel Processors based on Intel 64 and IA-32 Architecture, with support to Intel VT-x. Intel EPT is prefered, but not required.
AMD Processors based on AMD64 Architecture, with support to AMD-V. Nested Paging is prefered, but not required.
Other processors based on x86 architecture may be supported in future.
Currently, it is discovered that x86 processors produced by VIA, Zhaoxin and Hygon supports Hardware-Accelerated Virtualization Technology. In summary, certain facts are observed that:

  • Processors produced by Intel Corporation may support Intel VT-x.
  • Processors produced by Advanced Micro Devices Inc. may support AMD-V.
  • Processors produced by VIA Technologies Inc. may support Intel VT-x.
  • Processors produced by Shanghai Zhaoxin Semiconductor Co, Ltd. may support Intel VT-x.
  • Processors produced by Tianjin Haiguang Advanced Technology Investment Co, Ltd. may support AMD-V.

Note that early Zhaoxin and VIA use Centaur as vendor.

Nested Virtualization

Algorithm regarding the Nested Virtualization was written in the readme files in both VT-Core and SVM-Core directories.
For Nested Intel VT-x Algorithm, visit here.
For Nested AMD-V Algorithm, visit here.

Nested AMD-V is now in debugging stage. NoirVisor currently can run a modified version of SimpleSvm as nested hypervisor where NPT is turned off.
Nested Intel VT-x is not supported yet.

Announcement to all contributors

NoirVisor is coded in the C programming language and the assembly since it is procedure-oriented designed.
Contributing Guidelines are available in repository. For details, see the markdown file in the root directory of repository.
DO NOT PROVIDE CODES WITH C++ WHICH INVOLVES THE NoirVisor Core IN YOUR PULL-REQUEST!

Build

To build NoirVisor, using batch is essential.
Note that you should execute the build_prep.bat to make directories for first-time compilation.
Once NoirVisor is updated, it is recommended to execute cleanup.bat script before building.

If you use terminal, you may add /s option in order to bypass the pause command. For example:

.\build\compchk_win7x64.bat /s

Windows Driver

To build a kernel-mode driver on Windows, you should download and mount Enterprise Windows Driver Kit 11 (Visual Studio Build Tools 16.9.2 and 17.1.5) ISO file to T: and V: drives. I recommend using WinCDEmu to mount the ISO on system startup if you are looking for a free virtual ISO Drive.
Then run the provided batch file to build it. You might have to mount the ISO file manually everytime on your machine startup in that I failed to find a script that mount an ISO to a specific drive letter. If you use WinCDEmu, however, you may order the system to mount EWDK10 and specify its drive letter during startup.
You may download the EWDK11 (with VS Build Tools 16.9.2) from Microsoft: https://docs.microsoft.com/en-us/legal/windows/hardware/enterprise-wdk-license-2019-New
You may download the EWDK11 (with VS Build Tools 17.1.5) from Microsoft: https://docs.microsoft.com/en-us/legal/windows/hardware/enterprise-wdk-license-2022
Make sure you have downloaded the correct version. NoirVisor would continue updating. If not using correct version, you might fail to compile the latest version of NoirVisor.
Note that EWDK11 with VS Build Tools newer than 16.9.2 has removed import library for Windows 7.
Presets for Free/Release build are available. Please note that the compiled binary under Free build does not come along with a digital signature. You might have to sign it yourself.

EFI Application and Runtime Driver

Due to different EFI firmware implementation, most modern computer firmware does not support booting an EFI Runtime Driver directly. Therefore, it is necessary to build a separate EFI Application. In this way, modern computer firmware will boot, and the application can load runtime driver into memory.
To build a EFI Runtime Driver and Application, you should NASM and TianoCore EDK II. To install TianoCore EDK II, you may download latest release source code and extract to path C:\UefiDKII. Also, you should mount EWDK11 with VS Build Tools 17.1.5 to V: drive.
You may download NASM from its official website: https://www.nasm.us/pub/nasm/stable/win64/. Make sure you have added the directory to the PATH environment variable.
You may download EDK II from GitHub: https://github.com/tianocore/edk2/releases. Download the source code.
NoirVisor also use EDK II Libraries. However, they should be pre-compiled. Visit EDK-II-Library on GitHub in order to build them.

Disassembler

Project NoirVisor chooses Zydis as NoirVisor's disassembler engine. You should pre-compile Zydis as a static library. Visit the documents for disassembler for further details.
In that Zydis is included as a submodule, and because Zydis itself has a submodule, you must clone this repository recursively.

Python script

Since January 2024, NoirVisor can be built using Python script. The minimum version required for building NoirVisor is 3.9 by virtue of the typing syntax. In other words, Windows 7 is not supported. There is no pip package requirements for compilation.
First of all, in the root directory of this repository, execute the following command to compile the third-party libraries:

make /target disassembler /j
make /target snprintf /j

The first command will build the zydis disassembler engine.
The second command will build the snprintf library.

Then you can compile NoirVisor itself:

make /j

Python-based compilation is parallel. It will achieve a great performance in building NoirVisor.

Current implementation only supports building NoirVisor as Windows Driver.

See documentation for more information using python script to build NoirVisor.

Test

Windows Driver

There is a .NET Framework 4.0 based GUI loader available on GitHub now: https://github.com/Zero-Tang/NoirVisorLoader
If you are using operating systems older than Windows 8, you are supposed to manually install .NET Framework 4.0 or higher.
If you use the digital signature provided in NoirVisor's repository, then you should enable the test-signing on your machine.
You may enable Stealth SSDT Hook by setting up registry. Please note that since hooking is a very dangerous behavior, NoirVisor disables them on default.
Caveat: The stealth hook functionalities are deprecated in that I'm tired of doing this. They are disabled by default. Future updates of NoirVisor will rarely address issues from them. If you encountered issues from stealth hook features, expect no fixes will be applied. This project has no interest in fixing them.

reg add "HKLM\SOFTWARE\Zero-Tang\NoirVisor" /v "StealthMsrHook" /t REG_DWORD /d 1 /f

You may enable Stealth Inline Hook by setting up registry:

reg add "HKLM\SOFTWARE\Zero-Tang\NoirVisor" /v "StealthInlineHook" /t REG_DWORD /d 1 /f

You may set the values to 0, or remove the value key, in order to disable these features again.

You may load NoirVisor by using command-line or batch script:

reg add "HKLM\SOFTWARE\Zero-Tang\NoirVisor" /v "SubvertOnDriverLoad" /t REG_DWORD /d 1 /f
sc create NoirVisor type= kernel binPath= <Path to NoirVisor driver file>
sc start NoirVisor

You may unload NoirVisor by using command-line or batch script as well:

sc stop NoirVisor
sc delete NoirVisor
reg add "HKLM\SOFTWARE\Zero-Tang\NoirVisor" /v "SubvertOnDriverLoad" /t REG_DWORD /d 0 /f

The SubvertOnDriverLoad registry key value specifies whether the driver should subvert the system or not on the entry. This key value conflicts with NoirVisor Loader. You must delete or disable this key value in order to use NoirVisor Loader.

EFI Application and Runtime Driver

There are two methods to test NoirVisor.

Running on a physical machine

This method can also be used on VMware.
Use a USB flash stick and setup with GUID Partition Table (GPT). Construct a partition and format it info FAT32 file system. After you successfully build the image, you should see two images: bootx64.efi and NoirVisor.efi
Those two files are EFI Application and Runtime Driver respectively.
Copy EFI Application to \EFI\BOOT\bootx64.efi
Copy EFI Runtime Driver to \NoirVisor.efi
As the USB flash stick is ready, enter your firmware settings and set it prior to the operating system. Disable Secure Boot feature unless you can sign the executable.
NoirVisor has defined its own vendor GUID {2B1F2A1E-DBDF-44AC-DABCC7A130E2E71E}. Developments regarding Layered Hypervisor would require accessing NoirVisor's UEFI variables.

Running on a virtual machine

The point of this method is to build a virtual disk image.
You may use mtools in order to make a virtual disk image. The pre-built mtools executables are provided here. Put them into directories listed in PATH environment variable.

Build script for NoirVisor on UEFI includes above commands. Add NoirVisor-Uefi.img as a floppy image in your virtual machine.

Documents

This repository provides additional documents which help new developers to join development.

Detection of NoirVisor

As specified in AMD64 Architecture Programming Manual, CPUID.EAX=1.ECX[bit 31] indicates hypervisor presence. So NoirVisor will set this bit. For CPUID instruction, since AMD defines that function leaves 0x40000000-0x400000FF are reserved for hypervisor use, we will use them. Most hypervisors defines leaf 0x40000000 is used to identify hypervisor vendor. The string constructed by register sequence EBX-ECX-EDX is used to identify vendor of hypervisor. For example, VMware hypervisor vendor string is VMwareVMware. In NoirVisor, hypervisor vendor string is defined as NoirVisor ZT.

You may disable the detection for NoirVisor in Windows via setting up the registry.
Locate the registry key: HKLM\Software\Zero-Tang\NoirVisor. If this key does not exist then create it.
Edit the CpuidPresence Key Value to 0. Feel free to execute the following command if you find it less taxing to do:

reg add "HKLM\SOFTWARE\Zero-Tang\NoirVisor" /v "CpuidPresence" /t REG_DWORD /d 0 /f

NoirVisor as a Nested Hypervisor

If NoirVisor is subverting a system under a virtualized environment with exposed detection (e.g: VMware virtual machines with hypervisor.cpuid.v0 = TRUE configuration) as a Type-II hypervisor, the operating system may have already been using functionalities provided by the hypervisor. In this regard, NoirVisor should pass-through the access to hypervisor functionalities (e.g: cpuid instructions, accesses to Microsoft Synthetic MSRs, hypercalls, etc.)

TSC-Omission

Since the end of 2020, NoirVisor implemented a simple Time-Profiler Countermeasure. According to the half-year test, this technique is deemed unstable with multiprocessing systems. For example, TSC-omission may cause external hardwares to trigger drivers resetting themselves. Everything could be messed up: Timer, Graphics Card, NIC, etc. In a nutshell, system may go haywire.
By virtue of this unexpected and unpleasant side-effect, this feature is now obsolete. Codes addressing this feature are now removed.

Customizable VM

Customizable VM is the true explanation of "complex functions and purposes". As the project creator and director, Zero's true intention to create this project is for studying Hardware-Acclerated Virtualization Technology. Therefore, any features which is related to virtualization and which Zero has ideas to implement will be added in the project.
Customizable VM is the feature that Zero researches about Virtualization: to run an arbitrary guest, instead of to just subvert the host system. In a word, it is aimed to be a competitor of the Windows Hypervisor Platform (WHP).
For CVM Algorithm on AMD-V, visit here.
For CVM Algorithm on Intel VT-x, visit here.

APIs to invoke Customizable VMs are available in the NoirCvmApi repository. The documentation of the APIs is available in the wiki page.

NoirVisor Secure Virtualization

NSV (a.k.a NoirVisor Secure Virtualization) is a security extension to NoirVisor CVM. This extension is a crossover project with Columbia University's Operating Systems II course project. Read this document for further details.

NPIEP

NPIEP (a.k.a Non-Privileged Instruction Execution Prevention) is an important security feature in Microsoft Virtualization-based Security. As a hypervisor project in conformance to Microsoft Hv#1 interface, NoirVisor would provide this feature to the guest. This feature is similar to UMIP provided by later models of x86 processors. The differences are:

  • NPIEP does not raise an exception even if the instruction is executed in user mode.
  • NPIEP would prevent the guest from reading the real values of descriptor tables.
  • NPIEP does not intercept smsw instruction, probably in that Intel VT-x does not support intercepting this instruction.

For further details of NPIEP, visit here.

Security Advisories

You should not report security vulnerabilities through the GitHub issue. You should read this document to check out the steps to report security vulnerability.

Supported Platforms

NoirVisor is designed to be cross-platform. It can be built to a kernel-mode component of an operating system, or even as a software with bootstrap running on bare-metal.
Currently, NoirVisor supports the Windows Operating System newer than or same as Windows XP, running as a kernel-mode driver.
Porting to Unified Extensible Firmware Interface (UEFI) is in progress.
If there is already a hypervisor running in the system, make sure it supports native virtualization nesting.

Development Status

Project NoirVisor has six future development plans:

  • Develop Customizable VM engine for complex purposes.
  • Develop Nested Virtualization.
  • Develop IOMMU Core on Intel VT-d and AMD-Vi.
  • Port NoirVisor to the Rust Programming Language.
  • Port NoirVisor to Linux.
  • Port NoirVisor to UEFI and corresponding layered hypervisor.

For more information, check out the NoirVisor 2020+ Project.

Publications

Here lists some informal publications (blogs) regarding hypervisor development:

Completed Features

  • Minimal Microsoft Hv#1 Hypervisor Functionalities.
  • Stealth SSDT Hook (NtOpenProcess Hook) on 64-bit Windows, both Intel VT-x and AMD-V. (Compatible with the KiErrata420Present mitigation and KVA Shadow mechanism.)
  • Stealth Inline Hook (NtSetInformationFile Hook) on 64-bit Windows, both Intel VT-x/EPT and AMD-V/NPT.
  • Non-Privileged Instruction Execution Prevention (NPIEP) on AMD-V.
  • Customizable VM engine on AMD-V.
  • Tagged Translation Lookaside Buffer by ASID/VPID feature.
  • Critical Hypervisor Protection.
  • Software-Level Code Integrity Enforcement.
  • Hardware-Level Code Integrity Enforcement, both Intel EPT and AMD NPT.

License

This repository is under MIT license.

Code of Conduct

The Code of Conduct is added to NoirVisor Project since May.5th, 2019. Please follow the rules when contributing.

noirvisor's People

Contributors

zero-tang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

noirvisor's Issues

Windows 10 1809 - DRIVER_IRQL_NOT_LESS_OR_EQUAL after call NoirBuildHypervisor()

Hello, i got BSOD with code DRIVER_IRQL_NOT_LESS_OR_EQUAL after call NoirBuildHypervisor(), cause by this block code :

void inline noir_cpuid(u32 ia,u32 ic,u32* a,u32* b,u32* c,u32* d)
{
u32 info[4];
#if defined(_msvc)
__cpuidex(info,ia,ic);
#endif

if(a)*a=info[0]; // BSOD
if(b)*b=info[1];
if(c)*c=info[2];
if(d)*d=info[3];
}

here my crash dump log :


  •                                                                         *
    
  •                    Bugcheck Analysis                                    *
    
  •                                                                         *
    

DRIVER_IRQL_NOT_LESS_OR_EQUAL (d1)
An attempt was made to access a pageable (or completely invalid) address at an
interrupt request level (IRQL) that is too high. This is usually
caused by drivers using improper addresses.
If kernel debugger is available get stack backtrace.
Arguments:
Arg1: ffffd38e8d360ee0, memory referenced
Arg2: 0000000000000002, IRQL
Arg3: 0000000000000001, value 0 = read operation, 1 = write operation
Arg4: fffff80749142e58, address which referenced memory

Debugging Details:

KEY_VALUES_STRING: 1

STACKHASH_ANALYSIS: 1

TIMELINE_ANALYSIS: 1

DUMP_CLASS: 1

DUMP_QUALIFIER: 401

BUILD_VERSION_STRING: 17763.1.amd64fre.rs5_release.180914-1434

SYSTEM_MANUFACTURER: Micro-Star International Co., Ltd.

SYSTEM_PRODUCT_NAME: GT72 2QD

SYSTEM_SKU: To be filled by O.E.M.

SYSTEM_VERSION: REV:0.C

BIOS_VENDOR: American Megatrends Inc.

BIOS_VERSION: E1781IMS.316

BIOS_DATE: 09/23/2015

BASEBOARD_MANUFACTURER: Micro-Star International Co., Ltd.

BASEBOARD_PRODUCT: MS-1781

BASEBOARD_VERSION: REV:0.C

DUMP_TYPE: 1

BUGCHECK_P1: ffffd38e8d360ee0

BUGCHECK_P2: 2

BUGCHECK_P3: 1

BUGCHECK_P4: fffff80749142e58

WRITE_ADDRESS: ffffd38e8d360ee0 Nonpaged pool

CURRENT_IRQL: 2

FAULTING_IP:
NoirVisor!noir_cpuid+48 [e:\source\noirvisor\src\include\intrin.h @ 119]
fffff807`49142e58 8901 mov dword ptr [rcx],eax

CPU_COUNT: 8

CPU_MHZ: a86

CPU_VENDOR: GenuineIntel

CPU_FAMILY: 6

CPU_MODEL: 47

CPU_STEPPING: 1

CPU_MICROCODE: 6,47,1,0 (F,M,S,R) SIG: 1D'00000000 (cache) 1D'00000000 (init)

BLACKBOXBSD: 1 (!blackboxbsd)

DEFAULT_BUCKET_ID: WIN8_DRIVER_FAULT

BUGCHECK_STR: AV

PROCESS_NAME: System

ANALYSIS_SESSION_HOST: DESKTOP-6P18NJQ

ANALYSIS_SESSION_TIME: 05-05-2019 22:32:52.0722

ANALYSIS_VERSION: 10.0.17763.132 amd64fre

DPC_STACK_BASE: FFFFF8074BFDDFB0

TRAP_FRAME: fffff8074bfdd730 -- (.trap 0xfffff8074bfdd730)
NOTE: The trap frame does not contain all registers.
Some register values may be zeroed or incorrect.
rax=0000000000000000 rbx=0000000000000000 rcx=ffffd38e8d360ee0
rdx=0000000000000121 rsi=0000000000000000 rdi=0000000000000000
rip=fffff80749142e58 rsp=fffff8074bfdd8c0 rbp=fffff8074bfddd60
r8=000000002c100800 r9=ffffd38e8d360ee4 r10=ffffd38e8d360eec
r11=0000000080000021 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
iopl=0 nv up ei ng nz na pe nc
NoirVisor!noir_cpuid+0x48:
fffff80749142e58 8901 mov dword ptr [rcx],eax ds:ffffd38e8d360ee0=????????
Resetting default scope

LAST_CONTROL_TRANSFER: from fffff807497c5d69 to fffff807497b45e0

STACK_TEXT:
fffff8074bfdd5e8 fffff807497c5d69 : 000000000000000a ffffd38e8d360ee0 0000000000000002 0000000000000001 : nt!KeBugCheckEx
fffff8074bfdd5f0 fffff807497c218e : 0000000000000000 0000000000000000 0000000000000000 0000000000000000 : nt!KiBugCheckDispatch+0x69
fffff8074bfdd730 fffff80749142e58 : 0000000000000000 2c10080000000121 fffff8074829af80 fffff8074914241d : nt!KiPageFault+0x44e
fffff8074bfdd8c0 fffff8074914241d : 0000ffff80000001 007fffff00000000 ffffd38e8d360ee0 ffffd38e8d360ee4 : NoirVisor!noir_cpuid+0x48 [e:\source\noirvisor\src\include\intrin.h @ 119]
fffff8074bfdd8e0 fffff80749141774 : ffffd3868d362090 fffff8074bfdd960 fffff8074918de02 0000000000000000 : NoirVisor!nvc_vt_setup_cpuid_cache+0x13d [e:\source\noirvisor\src\vt_core\vt_main.c @ 406]
fffff8074bfdd930 fffff8074918ddfa : ffffd3868d362090 0000000000000036 fffff8074bfddb00 fffff8074918de02 : NoirVisor!nvc_vt_subvert_processor_i+0xa4 [e:\source\noirvisor\src\vt_core\vt_main.c @ 423]
fffff8074bfddae0 ffffd3868d362090 : 0000000000000036 fffff8074bfddb00 fffff8074918de02 0000000000000001 : NoirVisor!nvc_vt_subvert_processor_a+0x32 [E:\Source\NoirVisor\src\xpf_core\windows\vt_hv64.asm @ 130]
fffff8074bfddae8 0000000000000036 : fffff8074bfddb00 fffff8074918de02 0000000000000001 ffffd3868d362090 : 0xffffd3868d362090 fffff8074bfddaf0 fffff8074bfddb00 : fffff8074918de02 0000000000000001 ffffd3868d362090 0000000000000036 : 0x36 fffff8074bfddaf8 fffff8074918de02 : 0000000000000001 ffffd3868d362090 0000000000000036 fffff8074829af80 : 0xfffff8074bfddb00
fffff8074bfddb00 0000000000000001 : ffffd3868d362090 0000000000000036 fffff8074829af80 fffff8074bfddb98 : NoirVisor!nvc_vt_subvert_processor_a+0x3a [E:\Source\NoirVisor\src\xpf_core\windows\vt_hv64.asm @ 138]
fffff8074bfddb08 ffffd3868d362090 : 0000000000000036 fffff8074829af80 fffff8074bfddb98 fffff8074bfddd60 : 0x1
fffff8074bfddb10 0000000000000036 : fffff8074829af80 fffff8074bfddb98 fffff8074bfddd60 ffffd3868d302280 : 0xffffd3868d362090 fffff8074bfddb18 fffff8074829af80 : fffff8074bfddb98 fffff8074bfddd60 ffffd3868d302280 fffff80748298180 : 0x36 fffff8074bfddb20 fffff8074bfddb98 : fffff8074bfddd60 ffffd3868d302280 fffff80748298180 000000000000004d : 0xfffff8074829af80
fffff8074bfddb28 fffff8074bfddd60 : ffffd3868d302280 fffff80748298180 000000000000004d 0000000000000003 : 0xfffff8074bfddb98 fffff8074bfddb30 ffffd3868d302280 : fffff80748298180 000000000000004d 0000000000000003 206f742064656461 : 0xfffff8074bfddd60
fffff8074bfddb38 fffff80748298180 : 000000000000004d 0000000000000003 206f742064656461 ffffd3868d36a0bc : 0xffffd3868d302280 fffff8074bfddb40 000000000000004d : 0000000000000003 206f742064656461 ffffd3868d36a0bc 0000000000000000 : 0xfffff80748298180
fffff8074bfddb48 0000000000000003 : 206f742064656461 ffffd3868d36a0bc 0000000000000000 0000000000000000 : 0x4d
fffff8074bfddb50 206f742064656461 : ffffd3868d36a0bc 0000000000000000 0000000000000000 fffff8074bfdde70 : 0x3
fffff8074bfddb58 ffffd3868d36a0bc : 0000000000000000 0000000000000000 fffff8074bfdde70 0000000000000001 : 0x206f742064656461 fffff8074bfddb60 0000000000000000 : 0000000000000000 fffff8074bfdde70 0000000000000001 0000000000000286 : 0xffffd3868d36a0bc

THREAD_SHA1_HASH_MOD_FUNC: 039ca5da31788169faa44ab725c95ded1c1d2e73

THREAD_SHA1_HASH_MOD_FUNC_OFFSET: 7b9d839b2926641b9096942e6d1e56703dcbfcab

THREAD_SHA1_HASH_MOD: 3f7d06bd15643dd3e18ca1ae0c3560f55b1b63f3

FOLLOWUP_IP:
NoirVisor!noir_cpuid+48 [e:\source\noirvisor\src\include\intrin.h @ 119]
fffff807`49142e58 8901 mov dword ptr [rcx],eax

FAULT_INSTR_CODE: 83480189

FAULTING_SOURCE_LINE: e:\source\noirvisor\src\include\intrin.h

FAULTING_SOURCE_FILE: e:\source\noirvisor\src\include\intrin.h

FAULTING_SOURCE_LINE_NUMBER: 119

FAULTING_SOURCE_CODE:
115: u32 info[4];
116: #if defined(_msvc)
117: __cpuidex(info,ia,ic);
118: #endif

119: if(a)*a=info[0];
120: if(b)*b=info[1];
121: if(c)*c=info[2];
122: if(d)*d=info[3];
123: }
124:

SYMBOL_STACK_INDEX: 3

SYMBOL_NAME: NoirVisor!noir_cpuid+48

FOLLOWUP_NAME: MachineOwner

MODULE_NAME: NoirVisor

IMAGE_NAME: NoirVisor.sys

DEBUG_FLR_IMAGE_TIMESTAMP: 5ccf0170

STACK_COMMAND: .thread ; .cxr ; kb

BUCKET_ID_FUNC_OFFSET: 48

FAILURE_BUCKET_ID: AV_NoirVisor!noir_cpuid

BUCKET_ID: AV_NoirVisor!noir_cpuid

PRIMARY_PROBLEM_CLASS: AV_NoirVisor!noir_cpuid

TARGET_TIME: 2019-05-05T15:30:42.000Z

OSBUILD: 17763

OSSERVICEPACK: 0

SERVICEPACK_NUMBER: 0

OS_REVISION: 0

SUITE_MASK: 272

PRODUCT_TYPE: 1

OSPLATFORM_TYPE: x64

OSNAME: Windows 10

OSEDITION: Windows 10 WinNt TerminalServer SingleUserTS

OS_LOCALE:

USER_LCID: 0

OSBUILD_TIMESTAMP: unknown_date

BUILDDATESTAMP_STR: 180914-1434

BUILDLAB_STR: rs5_release

BUILDOSVER_STR: 10.0.17763.1.amd64fre.rs5_release.180914-1434

ANALYSIS_SESSION_ELAPSED_TIME: 1b33

ANALYSIS_SOURCE: KM

FAILURE_ID_HASH_STRING: km:av_noirvisor!noir_cpuid

FAILURE_ID_HASH: {449b3ed9-2691-d0c3-01e9-01134c18e54c}

Followup: MachineOwner

Im tried to fix something but not working, please help me check it.
if you need my binary and pdb, here they are :
NoirVisor.zip
thank you for the good the project.

NoirConstructHook 里面的 MmProbeAndLockPages 函数异常

我在最新的(Win11_Chinese(Simplified)_x64.iso) 测试 NtSetInformationFile 函数 MmProbeAndLockPages(Mdl, KernelMode, IoWriteAccess); 会产生0xC0000005的异常 ,锁定失败 , 所以开启VT的时候会产生蓝屏,暂时去掉了 return GetExceptionCode(); 可以正常运行

Exit vt :Init

您好前辈,之前向您请教过Exit vt退出时,触发了Init这个信号。(那个时候是在 tandasat 的项目中遇到的)
最近在学习您写的代码时 依然遇到了此问题。(我没有修改您的代码,直接编译运行的)
后来我尝试在msr 定义 0x40000071 尝试拦截 Interrupt Command Register 想通过观察 msr 看看是谁在发送INIT
但是在 msr处理中并没有拦截到 Interrupt Command Register 信号,这让我感到困惑。
因为您之前说过 触发 INIT 信号以后 guest context 已经不可信。
我尝试在 win10 win11,i5-9400f i7-13000k 上运行,但是依然会init 这个来说应该不是处理器的问题?
但是我在Win7上运行,就不会遇到此问题。不知道是否是系统问题?

Unknown reason of shutdown in UEFI-based SVM-Core

As the hypervisor subverts the system, it would shutdown after a very short amount of time. After a few attempts of debugging, some facts are observed:

  1. According to a test, the cpuid instruction can be intercepted properly.
  2. If the processor enters a dead loop after the subversion, the system will not shutdown.
  3. VMware does not treat this shutdown as a crash.
  4. The shutdown seems to occur when the processor enters halted state. (e.g: waiting for keyboard input, etc.)

Note that there is no chance for me to boot an OS at this time, so I assume possible bugs in APIC virtualization is utterly irrelevant.
The shutdown does not seem be a triple fault in that VMware Workstation would dump the VM and report it otherwise. This shutdown is without any notice: the VM just quit as if the shutdown is done in a gentle way.
I tried intercepting exceptions in both setting IDTR and VMCB, but nothing went manifested.

If you know what's behind the bug, feel free to post your thoughts.

Win7 x64 测试蓝屏的原因

经过调试 发现 vcpu->ept_manager=(void*)nvc_ept_build_identity_map(); 获取到的值为NULL 所以跳到了alloc_failure
这个时候nvc_vt_cleanup里面的rhvm 为NULL ,然后执行了下面的代码if(rhvm->msr_bitmap.virt)
所以蓝屏了

The specified procedure could not be found.

Win10 21H2
wdk 10.0.22621.0 (not ewdk)

C:\Windows\system32>sc start noir
[SC] StartService FAILED 127:

The specified procedure could not be found.

I'm confused with that error.
Maybe because that I was not using EWDK?

Use a build system or VS projects instead of batch scripts

First of all, I'm amazed by your project. It's probably the only hypervisor that currently supports both intel and amd and a great learning resource for a person like me trying to learn more about hypervisors.

Why do you use .bat scripts to build the windows driver? Don't you use visual studio to develop? Other than that it would maybe be better to use some build system like CMake or premake. And it should be possible to build using WDK downloaded with Vistual Studio Installer. What do you think about it?

Clion

请教下不安装vs2019的情况下,使用clion
ewdk最新版,clion始终无法构建项目的原因,
如果不安装vs的情况下可以通过ewdk生成exe dll
sys,那很给力啊,vs 60gb巨坑

随机MSR导致的崩溃问题

我发现在windows版本 1909 以后 系统会随机的写和读一些奇奇怪怪的msr
比如:读 0x40000105
错误信息如下:
Unexpected rdmsr is intercepted! Index=0x40000105
谷歌了一下发现
KVM Hyper-V based guests can notify hypervisor about
occurred guest crash by writing into Hyper-V crash MSR's.
This patch does handling and migration of HV_X64_MSR_CRASH_P0-P4,
HV_X64_MSR_CRASH_CTL msrs. User can enable these MSR's by
'hv-crash' option.
不是很懂,这个是指自己crash了 还是这个windows上其他的hv crash了?

您好,前辈再一次打扰到您了。

您好前辈,再次打扰到您实在不好意思。我是前两天向您请教 INIT信号的人。
我通过您的指点 对 INIT 信号陷入VT 的Dmp进行了分析,但是我实在找不到是什么原因。希望前辈可以指点一二。
堆栈
guest context
通过堆栈 可以看到是MwaitIdle 触发了INIT,我看到堆栈有APIC的符号,具体猜测是不是因为 映射了APIC的基
// Initialize an EPT entry for APIC_BASE. It is required to allocated it now for some reasons, or else, system hangs.
const Ia32ApicBaseMsr apic_msr = {UtilReadMsr64(Msr::kIa32ApicBase)};
// 这里是把APIC物理页的 read,write ,exe 置1
if (!EptpConstructTables(ept_pml4, 4, apic_msr.fields.apic_base * PAGE_SIZE, nullptr))
自己的能力不足,希望前辈可以指点一下 谢谢。

cpuid

是否可以添加 虚拟

cpuid std_leaf_index

wmic CPU get ProcessorID
ProcessorId
BFEBFBFF000306C3


{0x80000002, handle_ext_pname},
{0x80000003, handle_ext_pname},

Processor Name: Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz

Windows 10 1809 - nvc_vt_build_cpuid_cache() Allocation Failure

Hello, i got Allocation Failure when im trying to start NoirVisor, for what i can trace is because nvc_vt_build_cpuid_cache return false by this block (vt_main.c line 491) :

  cache->ext_leaf=noir_alloc_nonpg_memory((hvm->relative_hvm->ext_leaftotal+1)*sizeof(noir_vt_cpuid_info));
  if(cache->ext_leaf==null)
  	*cache->ext_leaf=viext;
  else
   	return false;

how to fix it?, thank you so much.

win7x64 代码修复

发现Win7x64 msrhook 无效了 找了好久
在 nvc_vt_subvert_system 添加了 就好了
if (hvm_p->options.stealth_msr_hook)vcpu->enabled_feature |= noir_vt_syscall_hook;
if (hvm_p->options.stealth_inline_hook)vcpu->enabled_feature |= noir_vt_ept_with_hooks;

但是 WIN10 1909下测试 msrhook epthook 都蓝屏,因为现在机器很多都是WIN10。。。
因为不是很懂这个 所以 接下来 我自己没法修复这些问题了。。。

x86

支持 期待 x86 版本

Expected Intercept Code: 0x400

Hello, my elder. Please consult you

Expected Intercept Code: 0x400

Using NVC_ svm_ nested_ pf_ Handler to switch the pages of inline hook,

However, page switching is not found in the function, but primary CR3 and secondary CR3 are used

Do you use switching CR3 to hide the page in the design of this function?

Triple Fault in SVM-Core when CPUID-interception is set.

If CPUID-interception is set, system will crash in a random amount of time after subversion. It seems to be specific to SVM-Core. I didn't meet this problem with VT-Core, albeit I can't choose not to intercept CPUID in VT-Core.

In case NoirVisor runs in VMware, debug log will indicate a triple fault. I will further analyze the problem. I, currently, have no idea what the problem is, though, in that I am learning to analyze VMware dump file.

Processors Tested: AMD Ryzen 7 1700, AMD Ryzen Threadripper 2950X.

Microsoft Hypervisor TLFS Conformance

Introduction

Since the issue #2, I realized that Microsoft Windows 10 is utilizing virtualization features from the hosting VMM.

Request of Issue

Implement conformance to Microsoft Hypervisor Top-Level Functional Specification.

Relevant Reference

Microsoft Hypervisor Specifications:
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
XenProject Relevant Source Code regarding TLFS (viridian):
https://github.com/xen-project/xen/tree/master/xen/arch/x86/hvm/viridian

EFI App/Driver doesn't seem to subvert the system

I'm testing out Noir by using the UEFI bootloader route with EDK2, everything seems to work fine, I see the NoirVisor initialization at boot, and it says everything is successful and requests enter key to be pressed.

Upon clicking enter key, it goes back to boot select screen where I boot Win10. OS boots fine, but upon checking cpuid leaf vendor, it reports back the same as non virtualized OS. Does not show "NoirVisor ZT".

I assume this means the HV isn't present.

I figured my machine might be soft rebooting itself when returning to boot manager screen where I boot to Win10 after Noir init, so I modified the EFI app to find the bootmgr for Win10 using Simple File System in EDK2, and call load image on bootmgr to auto boot Win10 to prevent a soft reboot by my bios.

Same results though, no cpuid vendor shift to NoirVisor VT. System appears to be devirtualized.

Any thoughts? I am posting this issue early just to see if you know anything regarding, but I'll take a look tomorrow to see if I can figure it out.

Thanks! I love the code and simplicity of Noir.

I have a question about NCR3 switching (AMD)

Hello, thank you for the awesome idea of swapping CR3 on vmexit as opposed to switching permissions of each individual page. I am currently trying to implement this in my own AMD hypervisor, for windows. I have a very strange issue when I do that,

I have two tables:
1 primary table, with all pages set to allow RWX, except for 1 hooked page which is RW only
1 secondary table, with all pages set to RW only, except for 1 hooked page, which is RWX and points to my modified copy of the original page

The guest RIP seems to be "stuck" when I swap to secondary table, and strangely this doesn't happen when I allow all pages to be RWX in the secondary table. By being "stuck", I mean that the guest RIP constantly switches back and forth between hooked page and non hooked page, in an infinite loop without even executing anything. I know this doesn't have anything to do with instructions being split across pages, I flushed TLB properly, and I also cleaned VMCB cache bits.

image

My question: Have you had any similar problems when you implemented NCR3 switching?

Here is a snippet of my code, in vmexit handler:

        NPTHOOK_ENTRY* nptHook = GetHookByPhysicalPage(g_HvData, FailAddress);

        if (nptHook) {
            VpData->GuestVmcb.ControlArea.NCr3 = g_HvData->SecondaryNCr3;
        }
        else {
            VpData->GuestVmcb.ControlArea.NCr3 = g_HvData->PrimaryNCr3;
        }

        KeInvalidateAllCaches();

        VpData->GuestVmcb.ControlArea.VmcbClean &= 0xFFFFFFEF;
        VpData->GuestVmcb.ControlArea.TlbControl = 1;

Thanks in advance

这个版本的一点小问题

测试了一点小问题
这个版本 msrhook 无法开启
我的WIN7X64虚拟机内存是8GB的调成1GB后 再去加载会蓝屏

System freezes on some Intel laptops

As noted in follow-ups in issue #24, it is confirmed that system might freeze on some Intel laptops. The i5-6200U and i5-5200U are confirmed to have this issue. The i7-7500U, nevertheless, does not have this issue.
As a part of investigation, the system does not seem to freeze if EPT is disabled.
I suspect there is a bug in MTRR emulation.

Feature: Detection vectors / Stealth mode

https://github.com/Zero-Tang/NoirVisor#detection-of-noirvisor

It would be a great feature to completely disable the detection with some flags(preprocessor definitions) aka stealth mode if possible. Different software(malware, anti cheats etc.) may detect the usage/presence of hypervisor and disallow further execution. This might require some additional work to circumvent time based detection like emulating rdtsc instruction too https://secret.club/2020/01/12/battleye-hypervisor-detection.html

https://github.com/bi-zone/rdtsc-checkvirt-poc

(Question) wpm / rpm

I was reading through the readme and saw that one of the features was "NtOpenProcess Hook", I simply wanted to know if the returned struct:

__kernel_entry NTSYSCALLAPI NTSTATUS NtOpenProcess(
  PHANDLE            ProcessHandle,
  ACCESS_MASK        DesiredAccess,
  POBJECT_ATTRIBUTES ObjectAttributes,
  PCLIENT_ID         ClientId
);

could be used for stealthily reading & writing to process memory.

VM-Entry failed due to invalid control fields

[NoirVisor] Launching vCPU...
[NoirVisor] Error while launching the Guest! VMX Status: 1
[NoirVisor] Failed at VM-Entry, Code=7  Reason: VM-Entry failed due to invalid control fields!
[NoirVisor] -----------
[NoirVisor] Dumping VMCS Guest State Area...
[NoirVisor] Guest CS Segment - Selector: 0x10  Access-Rights: 0x209B  Limit: 0x0  Base: 0x0000000000000000
[NoirVisor] Guest DS Segment - Selector: 0x2B  Access-Rights: 0xC0F3  Limit: 0xFFFFFFFF  Base: 0x0000000000000000
[NoirVisor] Guest ES Segment - Selector: 0x2B  Access-Rights: 0xC0F3  Limit: 0xFFFFFFFF  Base: 0x0000000000000000
[NoirVisor] Guest FS Segment - Selector: 0x53  Access-Rights: 0x40F3  Limit: 0xBC00  Base: 0x0000000000000000
[NoirVisor] Guest GS Segment - Selector: 0x2B  Access-Rights: 0xC0F3  Limit: 0xFFFFFFFF  Base: 0xFFFF94001CC40000
[NoirVisor] Guest SS Segment - Selector: 0x18  Access-Rights: 0x4093  Limit: 0x0  Base: 0x0000000000000000
[NoirVisor] Guest Task Register - Selector: 0x40  Access-Rights: 0x8B  Limit: 0x67  Base: 0xFFFF94001CC50000
[NoirVisor] Guest LDT Register - Selector: 0x0  Access-Rights: 0x10000  Limit: 0x0  Base: 0x0000000000000000
[NoirVisor] Guest GDTR Limit: 0x57  Base: 0xFFFF94001CC51FB0  Guest IDTR Limit: 0xFFF  Base: 0xFFFF94001CC4F000
[NoirVisor] Guest Control & Debug Registers - CR0: 0x80050033  CR3: 0x00000004154F0000  CR4: 0xB52EF8  DR7: 0x400
[NoirVisor] Guest Special GPRs: Rsp: 0xFFFFFA0C7E047A10  Rip: 0xFFFFF803B8285330  RFlags:0x2  Ssp: 0x0000000000000000
[NoirVisor] Guest Activity State: 0  Interruptibility State: 0x0  Pending Debug Exceptions: 0x0
[NoirVisor] Guest EFER: 0xD01  PAT: 0x0  Debug Control: 0x0
[NoirVisor] Guest VMCS Link Pointer: 0xFFFFFFFFFFFFFFFF
[NoirVisor] Guest PDPTE0: 0x0  PDPTE1: 0x0  PDPTE2: 0x0  PDPTE3: 0x0
[NoirVisor] Pin-Based Controls: 0x16  Primary Controls: 0x96006172  Secondary Controls: 0x11010AA  Exception Bitmap: 0x0
[NoirVisor] VM-Exit Controls: 0x336FFB  VM-Entry Controls: 0x93FB
[NoirVisor] EPT Pointer: 0x6D9BC01E
[NoirVisor] Event Injection: 0x0
[NoirVisor] -----------

tested on Microsoft Windows [Version 10.0.22000.556] with Intel i5-8400 (VT-x & EPT are supported)

抱歉前辈,再次打扰到您了。

您好前辈,我尝试编译您开源的 https://github.com/Zero-Tang/NoirVisor 项目。
disasm\build 在目录中 我尝试通过EWDK 17.1.5 来运行编译 compchk_win11x64/compfre_win11x64。
但是错误提示:
disasm.c
ZYDIS_STATIC_DEFINE was renamed to ZYDIS_STATIC_BUILD.
..\disasm.c(24): error C2065: 'ZYDIS_ADDRESS_WIDTH_64': undeclared identifier
..\disasm.c(25): error C2065: 'ZYDIS_ADDRESS_WIDTH_32': undeclared identifier
..\disasm.c(26): error C2065: 'ZYDIS_ADDRESS_WIDTH_16': undeclared identifier
..\disasm.c(34): warning C4013: 'ZydisDecoderDecodeBuffer' undefined; assuming extern returning int
..\disasm.c(35): warning C4133: 'function': incompatible types - from 'char *' to 'const ZydisDecodedOperand *'
..\disasm.c(35): warning C4244: 'function': conversion from 'ZyanUSize' to 'ZyanU8', possible loss of data
..............................
我尝试在源代码中寻找 ZYDIS_ADDRESS_WIDTH_64,ZYDIS_ADDRESS_WIDTH_32,ZYDIS_ADDRESS_WIDTH_16,并没有找到,
Zydis项目中虽然有ZydisDecoderDecodeBuffer函数的定义,但是提示确说没有定义此函数。。
打扰到前辈非常抱歉,希望您可以在百忙之中可以看到我的来信 谢谢

CPU 过高的问题

我在E5 CPU测试 (WIN10)会产生CPU过高的问题 WIN7 不会(没有开启StealthMsrHook 和 StealthInlineHook),vmexit 好像频繁的进入 nvc_vt_rdmsr_handler (不太确定是不是这个原因)
00000
1111

您好前辈,向您请教一个问题。

在intel处理器处理vt时,我发现有时候会因为 Expected Exit Reason: 3,INIT signal 初始化信号而陷入VT
我翻阅了intel手册,对比了自己的代码,我的代码里 没有明确的标记要接管这个INIT signal 信号,
但是他确实无时间规律的陷入VT,请问我怎样可以关闭这个 INIT事件的陷入?

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.