Skip to content

Commit 6b0e103

Browse files
authored
Merge pull request #29 from kernelwernel/dev
1.0
2 parents a436fba + 8d266a8 commit 6b0e103

File tree

4 files changed

+32
-78
lines changed

4 files changed

+32
-78
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
**VMAware** (not to be confused with VMware) is a cross-platform C++ library for virtual machine detection.
1111

12-
It utilises a comprehensive list of low-level and high-level anti-VM techniques that gets accounted in a scoring system. The library is meant to be stupidly easy to use, designed for anybody wanting to integrate the library to their project without a hassle.
13-
1412
The library is:
1513
- Very easy to use, with only 4 functions in its public interface
1614
- Very flexible, with total fine-grained control over what gets executed
@@ -25,9 +23,9 @@ The library is:
2523

2624
- - -
2725

28-
**IMPORTANT:** The library is currently in the alpha stage, so more improvements and cross-compatibility fixes are planned (especially for MacOS and Windows which I'm currently working on improving). I don't recommend using this for any serious projects for now.
26+
**IMPORTANT:** The library is currently in the alpha stage, so more improvements are planned. I don't recommend using this for any serious projects for now.
2927

30-
Also, this library doesn't guarantee it'll be accurate. If you found a false negative then please create an issue with information on what your VM is, what OS you're using, and other relevant details.
28+
Also, this library doesn't guarantee it'll be accurate. If you found a false positive or a false negative then please create an issue with information on what your VM is, what OS you're using, and other relevant details.
3129

3230
- - -
3331

@@ -91,6 +89,9 @@ You can view the full docs [here](docs/documentation.md). Trust me, it's not too
9189
<br>
9290

9391
## Q&A ❓
92+
- How does it work?
93+
> It utilises a comprehensive list of low-level and high-level anti-VM techniques that gets accounted in a scoring system. The given scores for each technique given are arbitrarily given.
94+
9495
- Who is this library for?
9596
> It's designed for security researchers, VM engineers, and pretty much anybody who needs a practical and rock-solid VM detection mechanism in their project. For example, if you're making a VM and you're testing the effectiveness of concealing itself, or if you're a malware analyst and you want to check if your VM environment is good enough.
9697

docs/documentation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ VMAware provides a convenient way to not only check for VMs, but also have the f
207207
| `VM::REGISTRY` | Look throughout the registry for all sorts of VMs | Windows | 75% | |
208208
| `VM::SUNBELT_VM` | Detect for Sunbelt technology | Windows | 10% | |
209209
| `VM::WINE_CHECK` | Find for a Wine-specific file | Windows | 85% | |
210-
| `VM::BOOT` | Analyse the OS uptime | Yes | 5% | |
211210
| `VM::VM_FILES` | Find if any VM-specific files exists | Windows | 20% | |
212211
| `VM::HWMODEL` | Check if the sysctl for the hwmodel does not contain the "Mac" string | MacOS | 75% | |
213212
| `VM::DISK_SIZE` | Check if disk size is under or equal to 50GB | Linux | 60% | |

src/cli.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ int main(int argc, char* argv[]) {
9090
checker(VM::REGISTRY, "registry");
9191
checker(VM::SUNBELT_VM, "Sunbelt");
9292
checker(VM::WINE_CHECK, "Wine");
93-
checker(VM::BOOT, "boot uptime");
9493
checker(VM::VM_FILES, "VM files");
9594
checker(VM::HWMODEL, "hw.model");
9695
checker(VM::DISK_SIZE, "disk size");

src/vmaware.hpp

Lines changed: 27 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ struct VM {
164164
using i32 = std::int32_t;
165165
using i64 = std::int64_t;
166166

167+
static constexpr auto enum_line_start = __LINE__; // hacky way to fetch enum size
167168
public:
168169
enum enum_flags : u8 {
169170
VMID = 1,
@@ -191,7 +192,6 @@ struct VM {
191192
REGISTRY,
192193
SUNBELT_VM,
193194
WINE_CHECK,
194-
BOOT,
195195
VM_FILES,
196196
HWMODEL,
197197
DISK_SIZE,
@@ -228,7 +228,10 @@ struct VM {
228228
EXTREME,
229229
NO_MEMO
230230
};
231+
private:
232+
static constexpr u8 enum_size = __LINE__ - enum_line_start - 4; // get enum size
231233

234+
public:
232235
// this will allow the enum to be used in the public interface as "VM::TECHNIQUE"
233236
enum enum_flags tmp_ignore_this = NO_MEMO;
234237

@@ -239,8 +242,7 @@ struct VM {
239242

240243
private:
241244
// for the bitset
242-
static constexpr u8 flag_size = 65;
243-
using flagset = std::bitset<flag_size>;
245+
using flagset = std::bitset<enum_size>;
244246

245247
// global values
246248
static flagset DEFAULT; // default bitset that will be run if no parameters are specified
@@ -302,6 +304,7 @@ struct VM {
302304
#define VMAWARE_LIKELY
303305
#endif
304306

307+
// various cpu operation stuff
305308
struct cpu {
306309
// cpuid leaf values
307310
struct leaf {
@@ -607,10 +610,7 @@ struct VM {
607610
}
608611
};
609612

610-
611-
612-
613-
613+
// miscellaneous functionalities
614614
struct util {
615615
#if (LINUX)
616616
// fetch file data
@@ -662,7 +662,7 @@ struct VM {
662662
return (base_str.find(keyword) != std::string::npos);
663663
};
664664

665-
// for debug output
665+
// for debug output
666666
#ifdef __VMAWARE_DEBUG__
667667
template <typename... Args>
668668
static inline void debug(Args... message) noexcept {
@@ -680,7 +680,7 @@ struct VM {
680680
}
681681
#endif
682682

683-
// directly return when adding a brand to the scoreboard for a more succint expression
683+
// directly return when adding a brand to the scoreboard for a more succint expression
684684
#if (MSVC)
685685
__declspec(noalias)
686686
#elif (LINUX)
@@ -2268,7 +2268,6 @@ struct VM {
22682268

22692269
/**
22702270
* @brief Find VMware tools presence
2271-
* @todo FIX THIS SHIT
22722271
* @category Windows
22732272
*/
22742273
[[nodiscard]] static bool vmware_registry() try {
@@ -2380,43 +2379,6 @@ struct VM {
23802379
}
23812380

23822381

2383-
/**
2384-
* @brief Check boot-time
2385-
* @todo: finish the linux part tomorrow
2386-
* @category All systems
2387-
*/
2388-
[[nodiscard]] static bool boot_time() try {
2389-
if (util::disabled(BOOT)) {
2390-
return false;
2391-
}
2392-
2393-
#if (MSVC)
2394-
// doesn't work for some reason, fix this whenever i have time
2395-
/*
2396-
SYSTEM_TIME_OF_DAY_INFORMATION SysTimeInfo;
2397-
LARGE_INTEGER LastBootTime;
2398-
2399-
NtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
2400-
LastBootTime = wmi_Get_LastBootTime();
2401-
return ((wmi_LastBootTime.QuadPart - SysTimeInfo.BootTime.QuadPart) / 10000000 != 0); // 0 seconds
2402-
*/
2403-
#elif (LINUX)
2404-
// TODO: finish this shit tomorrow
2405-
//https://stackoverflow.com/questions/349889/how-do-you-determine-the-amount-of-linux-system-ram-in-c
2406-
#else
2407-
return false;
2408-
#endif
2409-
2410-
return false; // tmp
2411-
}
2412-
catch (...) {
2413-
#ifdef __VMAWARE_DEBUG__
2414-
debug("BOOT: catched error, returned false");
2415-
#endif
2416-
return false;
2417-
}
2418-
2419-
24202382
/**
24212383
* @brief Find for VMware and VBox specific files
24222384
* @category Windows
@@ -2513,7 +2475,6 @@ struct VM {
25132475
/**
25142476
* @brief Check for sysctl hardware model
25152477
* @author MacRansom ransomware
2516-
* @todo TEST IF THIS WORKS
25172478
* @category MacOS
25182479
*/
25192480
[[nodiscard]] static bool hwmodel() try {
@@ -2760,28 +2721,24 @@ struct VM {
27602721
* @todo fix WNetGetProviderName linker error
27612722
*/
27622723
[[nodiscard]] static bool vbox_network_share() try {
2763-
return false;
2764-
/*
2765-
2766-
if (util::disabled(VBOX_NETWORK)) {
2767-
return false;
2768-
}
2724+
if (util::disabled(VBOX_NETWORK)) {
2725+
return false;
2726+
}
27692727

2770-
#if (!MSVC)
2771-
return false;
2772-
#else
2773-
u32 pnsize = 0x1000;
2774-
char* provider = new char[pnsize];
2728+
#if (!MSVC)
2729+
return false;
2730+
#else
2731+
u32 pnsize = 0x1000;
2732+
char* provider = new char[pnsize];
27752733

2776-
int32_t retv = WNetGetProviderName(WNNC_NET_RDR2SAMPLE, provider, &pnsize);
2734+
u32 retv = WNetGetProviderName(WNNC_NET_RDR2SAMPLE, provider, reinterpret_cast<LPDWORD>(&pnsize));
27772735

2778-
if (retv == NO_ERROR) {
2779-
return (lstrcmpi(provider, "VirtualBox Shared Folders") == 0);
2780-
}
2736+
if (retv == NO_ERROR) {
2737+
return (lstrcmpi(provider, "VirtualBox Shared Folders") == 0);
2738+
}
27812739

2782-
return FALSE;
2783-
#endif
2784-
*/
2740+
return false;
2741+
#endif
27852742
}
27862743
catch (...) {
27872744
#ifdef __VMAWARE_DEBUG__
@@ -3212,8 +3169,7 @@ struct VM {
32123169

32133170
/**
32143171
* @brief Check if the BIOS serial is valid
3215-
* @category Windows
3216-
* @todo FIX THE SEGFAULT
3172+
* @category Linux
32173173
*/
32183174
[[nodiscard]] static bool bios_serial() try {
32193175
if (util::disabled(BIOS_SERIAL)) {
@@ -4453,7 +4409,7 @@ struct VM {
44534409
throw std::invalid_argument(std::string(text) + ss.str());
44544410
};
44554411

4456-
if (p_flag > flag_size) {
4412+
if (p_flag > enum_size) {
44574413
throw_error("Flag argument must be a valid");
44584414
}
44594415

@@ -4720,8 +4676,8 @@ MSVC_ENABLE_WARNING(4626 4514)
47204676

47214677

47224678
std::map<bool, VM::memo::memo_struct> VM::memo::cache;
4723-
std::bitset<VM::flag_size> VM::flags = 0;
4724-
std::bitset<VM::flag_size> VM::DEFAULT = []() -> flagset {
4679+
VM::flagset VM::flags = 0;
4680+
VM::flagset VM::DEFAULT = []() -> flagset {
47254681
flagset tmp;
47264682
tmp.set(); // set all bits to 1
47274683
tmp.flip(EXTREME);
@@ -4773,7 +4729,6 @@ const std::map<VM::u8, VM::technique> VM::table = {
47734729
{ VM::REGISTRY, { 75, VM::registry_key }},
47744730
{ VM::SUNBELT_VM, { 10, VM::sunbelt_check }},
47754731
{ VM::WINE_CHECK, { 85, VM::wine }},
4776-
{ VM::BOOT, { 5, VM::boot_time }},
47774732
{ VM::VM_FILES, { 20, VM::vm_files }},
47784733
{ VM::HWMODEL, { 75, VM::hwmodel }},
47794734
{ VM::DISK_SIZE, { 60, VM::disk_size }},

0 commit comments

Comments
 (0)