Giter VIP home page Giter VIP logo

vmaware's Introduction

VMAware



VMAware (VM + Aware) is a cross-platform C++ library for virtual machine detection.

The library is:

  • Very easy to use, with only 5 functions in its public interface
  • Cross-platform (Windows + MacOS + Linux)
  • Compatible with x86 and ARM, with backwards compatibility for 32-bit systems
  • Features up to 100+ unique VM detection techniques [list]
  • Able to detect 40 VM brands including VMware, VirtualBox, QEMU, Hyper-V, Parallels, and much more
  • Very flexible, with total fine-grained control over which techniques get executed
  • Able to detect various semi-VM technologies like hypervisors, emulators, containers, and Wine
  • Able to guess the VM brand
  • Available with C++11 and above
  • Header-only
  • Memoized, meaning past results are cached and retrieved if ran again for performance benefits
  • Contains separate MIT and GPL-3.0 compliant library header files

Caution

DO NOT USE THIS LIBRARY FOR CRITICAL SOFTWARE (i.e. anti-cheats, proprietary software, paid software, etc...)

However, a solution is in development that will allow this in the next release which should be soon.

The full reason can be found here

Example 🧪

#include "vmaware.hpp"
#include <iostream>

int main() {
    if (VM::detect()) {
        std::cout << "Virtual machine detected!" << "\n";
        std::cout << "VM name: " << VM::brand() << "\n";
    } else {
        std::cout << "Running in baremetal" << "\n";
    }
    
    std::cout << "VM certainty: " << (int)VM::percentage() << "%" << "\n";
}

Structure ⚙️



CLI tool 🔧

This project also provides a tiny, but handy CLI tool utilising the full potential of what the library can do. It'll give you all sorts of details about the environment it's running under.


Installation 📥

To install the library, download the vmaware.hpp file in the latest release section to your project. No CMake or shared object linkages are necessary, it's literally that simple.

However, if you want the full project (globally accessible headers with <vmaware.hpp> and the CLI tool), follow these commands:

git clone https://github.com/kernelwernel/VMAware 
cd VMAware

FOR LINUX:

sudo dnf/apt/yum update -y # change this to whatever your distro is
mkdir build
cd build
cmake ..
sudo make install

FOR WINDOWS:

cmake -S . -B build/ -G "Visual Studio 16 2019"

If you just want the binaries, head over to the latest release section


Documentation 📒

You can view the full docs here. All the details such as functions, techniques, settings and examples are provided. Trust me, it's not too intimidating ;)


Q&A ❓

  • How does it work?

It utilises a comprehensive list of low-level and high-level anti-VM techniques that gets accounted in a scoring system. The scores (0-100) for each technique are arbitrarily given, and every technique that has detected a VM will have their score added to a single accumulative point, where a threshold point number will decide whether it's actually running in a VM.

  • Who is this library for?

It's designed for security researchers, VM engineers, gamer developers, and pretty much anybody who needs a practical and rock-solid VM detection mechanism in their project. For example, the library is suitable if you're making a VM and you're testing the effectiveness of concealing itself, or if you're a game developer or any proprietary software developer to thwart against reverse engineers, or if you're a malware analyst and you want to check if your VM environment is good enough to avoid detection.

  • Why another VM detection project?

There's already loads of projects that have the same goal such as InviZzzible, pafish and Al-Khaser. But the difference between the aforementioned projects is that they don't provide a programmable interface to interact with the detection mechanisms, on top of having little to no support for non-Windows systems. I wanted the core detection techniques to be accessible programmatically in a cross-platform way for everybody to get something useful out of it rather than providing just a CLI tool like those projects.

  • Is it possible to spoof the result?

Yes. There are some techniques that are trivially spoofable, and there's nothing the library can do about it whether it's a deliberate false positive or even a false negative. This is a problem that every VM detection project is facing, which is why the library is trying to test every technique possible to get the best result based on the environment it's running under.

  • What about using this for malware?

This project is not soliciting the development of malware for obvious reasons. Even if you intend to use it for concealment purposes, it'll most likely be flagged by antiviruses anyway and nothing is obfuscated to begin with.

  • Why GPL 3.0 and MIT?

I would've made it strictly MIT so proprietary software can make use of the library, but some of the techniques employed are from GPL 3.0 projects, and I have no choice but to use the same license for legal reasons. This gave me an idea to make an MIT version without all of the GPL code so it can also be used without forcing your code to be open-source. It should be noted that the MIT version removes 12 techniques out of 85 (as of 1.7 version), and the lesser the number of mechanisms, the less accurate the overall result might be.

  • I have linker errors when compiling

If you're compiling with gcc or clang, add the -lm and -lstdc++ flags, or use g++/clang++ compilers instead. If you're receiving linker errors from a brand new VM environment on Linux, update your system with sudo apt/dnf/yum update -y to install the necessary C++ components.


Issues and pull requests 📬

If you have any suggestions, ideas, or any sort of contribution, feel free to ask! I'll be more than happy to discuss in the issue section. If you want to personally ask something in private, my discord is kr.nl

And if you found this project useful, a star would be appreciated :)


Projects using VMAware

CrashLoggerSSE - SKSE/SKSEVR plugin that generates crash logs

If you know a project, or if you're working on a project that uses VMAware, let me know and I'll add it here.


Credits and contributors ✒️


Legal 📜

I am not responsible nor liable for any damage you cause through any malicious usage of this project.

License: GPL-3.0

vmaware's People

Contributors

alandtse avatar fameowner99 avatar greenozon avatar kernelwernel avatar marekknapek avatar notrequiem 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

vmaware's Issues

Not an issue, just needing assistance.

Trying to compile vmaware.hpp with MSVC 2019 16.7 on c++11 standard causes total of 30 issues.
7 out of 30 issues for example: inline variable asks for c++17.
How to compile vmaware.hpp on c++11?

question: VM directories false detect

im on vmware and I can sure those dirs in source codes does not exist.
{ CWSANDBOX, "c:\analysis" },
{ VBOX, "%PROGRAMFILES%\oracle\virtualbox guest additions\" },
{ VMWARE, "%PROGRAMFILES%\VMware\" }

but util::exists keeps return true when testing the VBOX dir and report me on a virtualbox.
is this a bug or some deep trick inside?

Windows vm detect vis 'port connector'

In windows you can use powershell/wmi to get 'ports'

On bare metal:

--- CODE -- (as is not formatting very well)
PS C:\Users\admin> powershell -Command "Get-WmiObject Win32_PortConnector"

Tag : Port Connector 0
ConnectorType : {61}
SerialNumber :
ExternalReferenceDesignator : PS2Mouse
PortType : 14
--- CODE --

On VM this return empty value

RDTSC_VMEXIT test is not accurate

I have slow windows PC and this test say that I am running VM but it's not true.

line 3271 | return (avg >= 1000 || avg == 0);

wrong because I have avg = ~1500.

windows sandbox

does not detect windows sandbox. might be something you want to look into! cool project otherwise though!

Defining debug mode leads to compiler errors

If all of a sudden you decided to see the matrix deep sea :)
by defining

#define __VMAWARE_DEBUG__ 

you'll hit something interesting ,eg:

image

that's cause currently the debug() routine is living inside the VM::util space, but used outside...
what was the original intention - to keep it inside util or inside VM scope?

99% Detection rate on bare metal Windows

Using Acer Laptop running Windows 10 22H2 and I get the following output:

`C:\Users\Lion\Downloads>vm --disable-hyperv-host
[NOT DETECTED] Checking VMID...
[NOT DETECTED] Checking CPU brand...
[NOT DETECTED] Checking CPUID hypervisor bit...
[NOT DETECTED] Checking CPUID 0x4 leaf...
[NOT DETECTED] Checking hypervisor brand...
[NOT DETECTED] Checking RDTSC...
[NOT DETECTED] Checking sidt null byte...
[NOT DETECTED] Checking processor count...
[ DETECTED ] Checking MAC address...
[NOT DETECTED] Checking temperature...
[NOT DETECTED] Checking systemd virtualisation...
[NOT DETECTED] Checking chassis vendor...
[NOT DETECTED] Checking chassis type...
[NOT DETECTED] Checking Dockerenv...
[NOT DETECTED] Checking dmidecode output...
[NOT DETECTED] Checking dmesg output...
[NOT DETECTED] Checking hwmon presence...
[NOT DETECTED] Checking cursor...
[NOT DETECTED] Checking VMware registry...
[NOT DETECTED] Checking VBox registry...
[NOT DETECTED] Checking users...
[NOT DETECTED] Checking DLLs...
[NOT DETECTED] Checking registry...
[NOT DETECTED] Checking Sunbelt CWSandbox directory...
[NOT DETECTED] Checking Wine...
[NOT DETECTED] Checking VM files...
[NOT DETECTED] Checking hw.model...
[NOT DETECTED] Checking disk size...
[NOT DETECTED] Checking VBox default specs...
[NOT DETECTED] Checking VBox network provider match...
[NOT DETECTED] Checking computer name...
[NOT DETECTED] Checking hostname...
[NOT DETECTED] Checking low memory space...
[NOT DETECTED] Checking VM processes...
[NOT DETECTED] Checking default Linux user/host...
[NOT DETECTED] Checking VBox window class...
[NOT DETECTED] Checking gamarue ransomware technique...
[NOT DETECTED] Checking 0x4 leaf of VMID...
[NOT DETECTED] Checking Parallels techniques...
[NOT DETECTED] Checking RDTSC VMEXIT...
[NOT DETECTED] Checking loaded DLLs...
[NOT DETECTED] Checking QEMU CPU brand...
[NOT DETECTED] Checking BOCHS CPU techniques...
[NOT DETECTED] Checking VirtualPC motherboard...
[NOT DETECTED] Checking BIOS serial number...
[NOT DETECTED] Checking Hyper-V registry...
[NOT DETECTED] Checking Hyper-V WMI output...
[NOT DETECTED] Checking VirtualBox shared folders...
[NOT DETECTED] Checking MSSMBIOS...
[NOT DETECTED] Checking MacOS hw.memsize...
[NOT DETECTED] Checking MacOS registry IO-kit...
[NOT DETECTED] Checking IO registry grep...
[NOT DETECTED] Checking MacOS SIP...
[NOT DETECTED] Checking KVM registries...
[NOT DETECTED] Checking KVM drivers...
[NOT DETECTED] Checking KVM directories...
[NOT DETECTED] Checking HKLM registries...
[NOT DETECTED] Checking Audio device...
[NOT DETECTED] Checking qemu-ga process...
[NOT DETECTED] Checking MSR validity...
[NOT DETECTED] Checking QEMU processes...
[NOT DETECTED] Checking QEMU directories...
[NOT DETECTED] Checking VPC processes...
[NOT DETECTED] Checking VPC invalid instructions...
[NOT DETECTED] Checking SIDT...
[NOT DETECTED] Checking SGDT...
[NOT DETECTED] Checking SLDT...
[NOT DETECTED] Checking Offensive Security SIDT...
[NOT DETECTED] Checking Offensive Security SGDT...
[NOT DETECTED] Checking Offensive Security SLDT...
[NOT DETECTED] Checking VirtualPC SIDT...
[NOT DETECTED] Checking Hyper-V motherboard...
[NOT DETECTED] Checking Extra VM files...
[NOT DETECTED] Checking /proc/iomem file...
[NOT DETECTED] Checking /proc/ioports file...
[NOT DETECTED] Checking /proc/scsi/scsi file...
[NOT DETECTED] Checking VMware dmesg...
[NOT DETECTED] Checking STR instruction...
[NOT DETECTED] Checking VMware IO port backdoor...
[NOT DETECTED] Checking VMware port memory...
[NOT DETECTED] Checking SMSW instruction...
[NOT DETECTED] Checking mutex strings...
[NOT DETECTED] Checking uptime...
[NOT DETECTED] Checking unusual thread count...
[NOT DETECTED] Checking Intel thread count mismatch...
[NOT DETECTED] Checking Intel Xeon thread count mismatch...
[NOT DETECTED] Checking VM memory regions...
[ DETECTED ] Checking VMware devices...
[NOT DETECTED] Checking Hyper-V CPUID...
[NOT DETECTED] Checking Cuckoo directory...
[NOT DETECTED] Checking Cuckoo pipe...
[NOT DETECTED] Checking Hyper-V Azure hostname...
[NOT DETECTED] Checking general VM hostnames...
[NOT DETECTED] Checking screen resolution...
[NOT DETECTED] Checking bogus device string...
[NOT DETECTED] Checking mouse device...
[NOT DETECTED] Checking BlueStacks folders...

VM brand: Hybrid Analysis
VM likeliness: 99%
VM confirmation: true
VM detections: 2/97

====== CONCLUSION: Very likely a Hybrid Analysis VM ======`

Is there a way we can just have detections base on VM detections only? Seems to be much more reliable in my case.

Wrong flag given.

After running VMAware in terminal i got this output along with a positive result due to what is ebing said below as a result of this i decided to copy paste the flag --discard-hyperv-host but upon running i was given Unknown argument provided, consult the help menu with --help which is what i had copy and pasted from below upon checking the help menu with --help i relasied you had run with the flag --disable-hyperv-host so all in all small typo to be chnaged in commits thanks for the work outside of this works a charm.

[    NOTE    ] If you know you are running on host, Hyper-V virtualises all applications by default within the host system. This result is in fact correct and NOT a false positive. If you do not want Hyper-V's default virtualisation enabled, run with the "--discard-hyperv-host" argument. See here https://github.com/kernelwernel/VMAware/issues/75
====== CONCLUSION: Running inside a Microsoft Hyper-V VM ======

wcstombs: This function or variable may be unsafe

When attempting to compile using VS, I receive the following error:

'wcstombs': This function or variable may be unsafe. Consider using wcsombs_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

While using this option does disable it, it'd be great to have this fixed.

Windows/MSVC/C++17 update

All of a sudden was iterating over different C++ standards and hit this case when selected MSVC C++17:

The contents of <bit> are available only with C++20 or later.

inspecting the header in my system I've found the following:

image

as well as some official docs stating that header is indeed part of C++20 standard

Here is a small PR #34

also if you don't mind I've added some printouts to end user showing the currently selected compiler standard as well as added support for C++23 standard which was already settled down:

__cplusplus 202302L

Do yo have some plans to start using features/headers from C++23?

Does not detect KVM Windows.

My computer is Windows Server 2022 x64 running on virtual computer in Hetzner data center using the KVM technology. Your tool provides inconsistent report.

[NOT DETECTED] Checking VMID...
[NOT DETECTED] Checking CPU brand...
[  DETECTED  ] Checking CPUID hypervisor bit...
[  DETECTED  ] Checking CPUID 0x4 leaf...
[  DETECTED  ] Checking hypervisor brand...
[NOT DETECTED] Checking RDTSC...
[NOT DETECTED] Checking sidt null byte...
[NOT DETECTED] Checking processor count...
[NOT DETECTED] Checking MAC address...
[NOT DETECTED] Checking temperature...
[NOT DETECTED] Checking systemd virtualisation...
[NOT DETECTED] Checking chassis vendor...
[NOT DETECTED] Checking chassis type...
[NOT DETECTED] Checking Dockerenv...
[NOT DETECTED] Checking dmidecode output...
[NOT DETECTED] Checking dmesg output...
[NOT DETECTED] Checking hwmon presence...
[  DETECTED  ] Checking cursor...
[NOT DETECTED] Checking VMware registry...
[NOT DETECTED] Checking VBox registry...
[NOT DETECTED] Checking users...
[NOT DETECTED] Checking DLLs...
[NOT DETECTED] Checking registry...
[NOT DETECTED] Checking Sunbelt...
[NOT DETECTED] Checking Wine...
[  DETECTED  ] Checking VM files...
[NOT DETECTED] Checking hw.model...
[NOT DETECTED] Checking disk size...
[NOT DETECTED] Checking VBox default specs...
[NOT DETECTED] Checking VBox network provider match...
[NOT DETECTED] Checking computer name...
[NOT DETECTED] Checking hostname...
[NOT DETECTED] Checking low memory space...
[NOT DETECTED] Checking VM processes...
[NOT DETECTED] Checking default Linux user/host...
[NOT DETECTED] Checking VBox window class...
[NOT DETECTED] Checking gamarue ransomware technique...
[NOT DETECTED] Checking WMIC outputs...
[  DETECTED  ] Checking 0x4 leaf of VMID...
[NOT DETECTED] Checking Parallels techniques...
[  DETECTED  ] Checking RDTSC VMEXIT...
[NOT DETECTED] Checking loaded DLLs...
[NOT DETECTED] Checking QEMU CPU brand...
[NOT DETECTED] Checking BOCHS CPU techniques...
[NOT DETECTED] Checking VirtualPC motherboard...
[NOT DETECTED] Checking BIOS serial number...
[NOT DETECTED] Checking Hyper-V registry...
[NOT DETECTED] Checking Hyper-V WMI output...
[NOT DETECTED] Checking VirtualBox shared folders...
[NOT DETECTED] Checking VirtualBox MSSMBIOS...
[NOT DETECTED] Checking MacOS hyperthreading...
[NOT DETECTED] Checking MacOS hw.memsize...
[NOT DETECTED] Checking MacOS registry IO-kit...
[NOT DETECTED] Checking IO registry grep...
[NOT DETECTED] Checking MacOS SIP...
[  DETECTED  ] Checking KVM registries...
[  DETECTED  ] Checking KVM drivers...
[NOT DETECTED] Checking KVM directories...

VM brand: KVM
VM certainty: 0%
VM confirmation: true

====== CONCLUSION: Running in baremetal ======

cpuz1
cpuz2
cpuz3
cpuz4
cpuz5
cpuz6
cpuz7

Windows BareMetal detected 100%

Hello.
I just compiled and tested VMAware. On my baremetal Windows11 machine, it detects "Microsoft Virtual PC/Hyper-V" with a 100% certainty.

Here are the checks, that flagged "detected":
• Checking 0x4 leaf of VMID...
• Checking RDTSC VMEXIT...
• Checking VM directories...
• Checking MMX instruction set...

I have HyperV, VM-Platform, Windows-Sandbox and WSL enabled. I also have docker desktop installed, if that helps.

MSVC: not possible to build code from cmdline as some windows libs are missing

for some (tricky) cases one might need to build hes/her code from the VC++ command line
in this case the linker is not happy, eg:

c:\Users\user\source\repos\vm_tester>cl cli.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30153 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cli.cpp
c:\Users\user\source\repos\vm_tester\vmaware.hpp(754): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
Microsoft (R) Incremental Linker Version 14.29.30153.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:cli.exe
cli.obj
cli.obj : error LNK2019: unresolved external symbol __imp__GetUserNameA@8 referenced in function "private: static bool __cdecl VM::user_check(void)" (?user_check@VM@@CA_NXZ)
cli.obj : error LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function "public: bool __thiscall <lambda_f49e2cc4151d968a45b56bd5552f53de>::operator()(char const *)const " (??R
<lambda_f49e2cc4151d968a45b56bd5552f53de>@@QBE_NPBD@Z)
cli.obj : error LNK2019: unresolved external symbol __imp__RegEnumKeyExW@32 referenced in function "private: static bool __cdecl VM::hyperv_registry(void)" (?hyperv_registry@VM@@CA_NXZ)
cli.obj : error LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20 referenced in function "public: bool __thiscall <lambda_f49e2cc4151d968a45b56bd5552f53de>::operator()(char const *)const " (
??R<lambda_f49e2cc4151d968a45b56bd5552f53de>@@QBE_NPBD@Z)
cli.obj : error LNK2019: unresolved external symbol __imp__RegOpenKeyExW@20 referenced in function "public: void __thiscall <lambda_fabddcdefc99831fc201e2118c777bd6>::operator()(char const *,char cons
t *)const " (??R<lambda_fabddcdefc99831fc201e2118c777bd6>@@QBEXPBD0@Z)
cli.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExW@24 referenced in function "private: static bool __cdecl VM::gamarue(void)" (?gamarue@VM@@CA_NXZ)
cli.obj : error LNK2019: unresolved external symbol __imp__SHGetSpecialFolderPathA@16 referenced in function "private: static bool __cdecl VM::kvm_directories(void)" (?kvm_directories@VM@@CA_NXZ)
cli.exe : fatal error LNK1120: 7 unresolved externals

There is an easy mitigation - instruct the linker using pragma, so all become happy

Please consider this PR: #37

VM::Default inaccessible

Under VS2022 Version 17.8.3 this example results in an inaccessible member error for VM::DEFAULT

bool is_vm6 = VM::detect(VM::DEFAULT & ~(VM::RDTSC));

image

I'm on main (so not a release) so let me know if that's the issue. I tried moving

    // global values
    static flagset DEFAULT; // default bitset that will be run if no parameters are specified

From private: to public: but then Default isn't an enum so the & fails. I didn't have much time to play with it so may figure something out.

ucrtbase.dll not found when running application

This isn't necessarily an issue with the binary itself, but with the Windows system that doesn't have the file for whatever reason.

error:

The code execution cannot proceed because ucrtbase.dll was not found. Reinstalling the program may fix this problem.

FIX:

step 1: download the dll from here: https://www.dll-files.com/ucrtbase.dll.html
step 2: add the dll to the same file location as the vmaware.exe binary

if you're running a debug binary and the error is referring to ucrtbased.dll and not ucrtbase.dll, follow the same steps except the dll to download should be this instead:
https://www.dll-files.com/ucrtbased.dll.html

how do you run the cli tool

As far as I know a .cpp can't run on windows
Your readme makes it seem like it can, and you just need to DL it and run it?
If so how to do that? I'm unfamiliar with windows.

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.