diff --git a/src/vmaware.hpp b/src/vmaware.hpp index 5f81052..29e91be 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -103,6 +103,7 @@ #pragma comment(lib, "wbemuuid.lib") #pragma comment(lib, "iphlpapi.lib") + #pragma comment(lib,"MPR") #elif (LINUX) #include #include @@ -858,6 +859,8 @@ struct VM { HYPERV_WMI = 1ULL << 49, HYPERV_REG = 1ULL << 50, BIOS_SERIAL = 1ULL << 51, + VBOX_FOLDERS = 1ULL << 52, + VBOX_MSSMBIOS = 1ULL << 53, // __UNIQUE_LABEL, ADD YOUR UNIQUE FUNCTION FLAG VALUE ABOVE HERE @@ -3088,12 +3091,16 @@ struct VM { /** * @brief Check if the BIOS serial is valid * @category Windows + * @todo FIX THE FUCKING SEGFAULT */ [[nodiscard]] static bool bios_serial() try { if (disabled(BIOS_SERIAL)) { return false; } + return false; // temporary + + /* #if (!MSVC) return false; #else @@ -3148,6 +3155,7 @@ struct VM { return false; #endif + */ } catch (...) { #ifdef __VMAWARE_DEBUG__ debug("BIOS_SERIAL: catched error, returned false"); @@ -3876,6 +3884,142 @@ struct VM { } + /** + * @brief Check for VirtualBox-specific string for shared folder ID + * @category Windows + * @note slightly modified code from original + * @author @waleedassar + * @link https://pastebin.com/xhFABpPL + */ + [[nodiscard]] static bool vbox_shared_folders() try { + if (disabled(VBOX_FOLDERS)) { + return false; + } + + #if (!MSVC) + return false; + #else + constexpr u32 pnsize = 0x1000; + char* provider = static_cast(LocalAlloc(LMEM_ZEROINIT,pnsize)); + int retv = WNetGetProviderName(WNNC_NET_RDR2SAMPLE,provider,&pnsize); + if (retv == NO_ERROR) { + if (lstrcmpi(provider,"VirtualBox Shared Folders") == 0) { + return add(VBOX) + } + } + + return false; + #endif + } catch (...) { + #ifdef __VMAWARE_DEBUG__ + debug("VBOX_FOLDERS: ", "catched error, returned false"); + #endif + return false; + } + + + /** + * @brief Check VirtualBox MSSMBIOS registry for VM-specific strings + * + */ + [[nodiscard]] static bool vbox_mssmbios() try { + if (disabled(VBOX_MSSMBIOS)) { + return false; + } + + #if (!MSVC) + return false; + #else + HKEY hk = 0; + int ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\mssmbios\\data", 0, KEY_ALL_ACCESS, &hk); + if (ret != ERROR_SUCCESS) { + return false; + } + + bool is_vm = false; + unsigned long type = 0; + unsigned long length = 0; + ret = RegQueryValueEx(hk, "SMBiosData", 0, &type, 0, &length); + + if (ret != ERROR_SUCCESS) { + RegCloseKey(hk); + return false; + } + + if (length == 0) { + RegCloseKey(hk); + return false; + } + + char* p = static_cast(LocalAlloc(LMEM_ZEROINIT, length)); + + if (p == nullptr) { + RegCloseKey(hk); + return false; + } + + ret = RegQueryValueEx(hk, "SMBiosData", 0, &type, (unsigned char*)p, &length); + + if (ret != ERROR_SUCCESS) { + LocalFree(p); + RegCloseKey(hk); + return false; + } + + auto ScanDataForString = [](unsigned char* data, u32 data_length, unsigned char* string2) -> unsigned char* { + std::size_t string_length = strlen(reinterpret_cast(string2)); + + for (std::size_t i = 0; i <= (data_length-string_length); i++) { + if (strncmp(reinterpret_cast(&data[i]), reinterpret_cast(string2), string_length) == 0) { + return &data[i]; + } + } + return 0; + }; + + std::transform(p, p + length, p, [](unsigned char c) { + return std::toupper(c); + }); + + // cleaner and better shortcut than typing reinterpret_cast a million times + auto cast = [](char* p) -> unsigned char* { + return reinterpret_cast(p); + }; + + unsigned char* x1 = ScanDataForString(cast(p), length, cast("INNOTEK GMBH")); + unsigned char* x2 = ScanDataForString(cast(p), length, cast("VIRTUALBOX")); + unsigned char* x3 = ScanDataForString(cast(p), length, cast("SUN MICROSYSTEMS")); + unsigned char* x4 = ScanDataForString(cast(p), length, cast("VIRTUAL MACHINE")); + unsigned char* x5 = ScanDataForString(cast(p), length, cast("VBOXVER")); + + if (x1 || x2 || x3 || x4 || x5) { + is_vm = true; + #ifdef __VMAWARE_DEBUG__ + if (x1) { debug("VBOX_MSSMBIOS: ", x1); } + if (x2) { debug("VBOX_MSSMBIOS: ", x2); } + if (x3) { debug("VBOX_MSSMBIOS: ", x3); } + if (x4) { debug("VBOX_MSSMBIOS: ", x4); } + if (x5) { debug("VBOX_MSSMBIOS: ", x5); } + #endif + } + + LocalFree(p); + RegCloseKey(hk); + + if (is_vm) { + return add(VBOX); + } + + return false; + #endif + } catch (...) { + #ifdef __VMAWARE_DEBUG__ + debug("VBOX_INNOTEK: ", "catched error, returned false"); + #endif + return false; + } + + // __TECHNIQUE_LABEL, label for adding techniques above this point @@ -4269,6 +4413,8 @@ const std::map VM::table = { { VM::HYPERV_WMI, { 80, VM::hyperv_wmi }}, { VM::HYPERV_REG, { 80, VM::hyperv_registry }}, { VM::BIOS_SERIAL, { 60, VM::bios_serial }}, + { VM::VBOX_FOLDERS, { 45, VM::vbox_shared_folders }}, + { VM::VBOX_MSSMBIOS, { 75, VM::vbox_mssmbios }} // __TABLE_LABEL, add your technique above // { VM::YOUR_FUNCTION, { POINTS, FUNCTION POINTER }}