|
45 | 45 | #include <wintrust.h> |
46 | 46 | #include <softpub.h> |
47 | 47 | #include <cwctype> |
| 48 | +#include <intrin.h> |
48 | 49 | #include <stdexcept> |
49 | 50 | #include <string> |
50 | 51 | #include <array> |
@@ -90,6 +91,7 @@ bool duplicate_system_modules_present(); |
90 | 91 | bool user_writable_module_present(); |
91 | 92 | bool module_has_rwx_section(HMODULE mod); |
92 | 93 | bool core_modules_signed(); |
| 94 | +bool hypervisor_present(); |
93 | 95 | std::string seed; |
94 | 96 | void cleanUpSeedData(const std::string& seed); |
95 | 97 | std::string signature; |
@@ -1937,6 +1939,56 @@ bool user_writable_module_present() |
1937 | 1939 | return false; |
1938 | 1940 | } |
1939 | 1941 |
|
| 1942 | +static bool reg_key_exists(HKEY root, const wchar_t* path) |
| 1943 | +{ |
| 1944 | + HKEY h = nullptr; |
| 1945 | + const LONG res = RegOpenKeyExW(root, path, 0, KEY_READ, &h); |
| 1946 | + if (res == ERROR_SUCCESS) { |
| 1947 | + RegCloseKey(h); |
| 1948 | + return true; |
| 1949 | + } |
| 1950 | + return false; |
| 1951 | +} |
| 1952 | + |
| 1953 | +static bool file_exists(const std::wstring& path) |
| 1954 | +{ |
| 1955 | + const DWORD attr = GetFileAttributesW(path.c_str()); |
| 1956 | + return (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY); |
| 1957 | +} |
| 1958 | + |
| 1959 | +bool hypervisor_present() |
| 1960 | +{ |
| 1961 | + int cpu_info[4] = {}; |
| 1962 | + __cpuid(cpu_info, 1); |
| 1963 | + const bool hv_bit = (cpu_info[2] & (1 << 31)) != 0; |
| 1964 | + if (hv_bit) { |
| 1965 | + return true; |
| 1966 | + } |
| 1967 | + |
| 1968 | + // registry artifacts (conservative) |
| 1969 | + if (reg_key_exists(HKEY_LOCAL_MACHINE, L"HARDWARE\\ACPI\\DSDT\\VBOX__") || |
| 1970 | + reg_key_exists(HKEY_LOCAL_MACHINE, L"HARDWARE\\ACPI\\DSDT\\VMWARE") || |
| 1971 | + reg_key_exists(HKEY_LOCAL_MACHINE, L"HARDWARE\\ACPI\\DSDT\\XEN") || |
| 1972 | + reg_key_exists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\VMware, Inc.\\VMware Tools") || |
| 1973 | + reg_key_exists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Oracle\\VirtualBox Guest Additions")) { |
| 1974 | + return true; |
| 1975 | + } |
| 1976 | + |
| 1977 | + // file artifacts (drivers/tools) |
| 1978 | + if (file_exists(L"C:\\Windows\\System32\\drivers\\VBoxGuest.sys") || |
| 1979 | + file_exists(L"C:\\Windows\\System32\\drivers\\VBoxMouse.sys") || |
| 1980 | + file_exists(L"C:\\Windows\\System32\\drivers\\VBoxSF.sys") || |
| 1981 | + file_exists(L"C:\\Windows\\System32\\drivers\\VBoxVideo.sys") || |
| 1982 | + file_exists(L"C:\\Windows\\System32\\drivers\\vmhgfs.sys") || |
| 1983 | + file_exists(L"C:\\Windows\\System32\\drivers\\vmmouse.sys") || |
| 1984 | + file_exists(L"C:\\Windows\\System32\\drivers\\vm3dmp.sys") || |
| 1985 | + file_exists(L"C:\\Windows\\System32\\drivers\\xen.sys")) { |
| 1986 | + return true; |
| 1987 | + } |
| 1988 | + |
| 1989 | + return false; |
| 1990 | +} |
| 1991 | + |
1940 | 1992 | void KeyAuth::api::setDebug(bool value) { |
1941 | 1993 | KeyAuth::api::debug = value; |
1942 | 1994 | } |
@@ -2323,7 +2375,7 @@ void checkInit() { |
2323 | 2375 | const auto last_mod = last_module_check.load(); |
2324 | 2376 | if (now - last_mod > 60) { |
2325 | 2377 | last_module_check.store(now); |
2326 | | - if (!module_paths_ok() || duplicate_system_modules_present() || user_writable_module_present() || !core_modules_signed()) { |
| 2378 | + if (!module_paths_ok() || duplicate_system_modules_present() || user_writable_module_present() || !core_modules_signed() || hypervisor_present()) { |
2327 | 2379 | error(XorStr("module path check failed, possible side-load detected.")); |
2328 | 2380 | } |
2329 | 2381 | } |
@@ -2355,7 +2407,7 @@ void integrity_watchdog() { |
2355 | 2407 | const auto last_mod = last_module_check.load(); |
2356 | 2408 | if (now - last_mod > 120) { |
2357 | 2409 | last_module_check.store(now); |
2358 | | - if (!module_paths_ok() || duplicate_system_modules_present() || user_writable_module_present() || !core_modules_signed()) { |
| 2410 | + if (!module_paths_ok() || duplicate_system_modules_present() || user_writable_module_present() || !core_modules_signed() || hypervisor_present()) { |
2359 | 2411 | error(XorStr("module path check failed, possible side-load detected.")); |
2360 | 2412 | } |
2361 | 2413 | } |
|
0 commit comments