Skip to content

Commit 5485b7a

Browse files
committed
fixed --all mechanism
1 parent 361f267 commit 5485b7a

2 files changed

Lines changed: 43 additions & 65 deletions

File tree

src/cli.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,28 @@ void general() {
478478
};
479479

480480
bool notes_enabled = false;
481-
VM::enum_flags spoofable_setting;
481+
const std::uint8_t max_bits = static_cast<std::uint8_t>(VM::MULTIPLE) + 1;
482+
483+
auto settings = [&]() -> std::bitset<max_bits> {
484+
std::bitset<max_bits> tmp;
485+
486+
if (arg_bitset.test(SPOOFABLE)) {
487+
tmp.set(VM::SPOOFABLE);
488+
}
489+
490+
if (arg_bitset.test(ALL)) {
491+
tmp |= VM::ALL;
492+
}
493+
494+
return tmp;
495+
};
482496

483497
if (arg_bitset.test(NOTES)) {
484498
notes_enabled = false;
485499
} else {
486500
notes_enabled = true;
487501
}
488502

489-
if (arg_bitset.test(SPOOFABLE)) {
490-
spoofable_setting = VM::SPOOFABLE;
491-
} else {
492-
spoofable_setting = VM::NULL_ARG;
493-
}
494-
495503
#if (LINUX)
496504
if (notes_enabled && !is_admin()) {
497505
std::cout << note << " Running under root might give better results\n";
@@ -521,7 +529,7 @@ void general() {
521529
checker(VM::DLL, "DLLs");
522530
checker(VM::REGISTRY, "registry");
523531
checker(VM::CWSANDBOX_VM, "Sunbelt CWSandbox directory");
524-
//checker(VM::WINE_CHECK, "Wine");
532+
checker(VM::WINE_CHECK, "Wine");
525533
checker(VM::VM_FILES, "VM files");
526534
checker(VM::HWMODEL, "hw.model");
527535
checker(VM::DISK_SIZE, "disk size");
@@ -532,7 +540,7 @@ void general() {
532540
checker(VM::MEMORY, "low memory space");
533541
checker(VM::VM_PROCESSES, "VM processes");
534542
checker(VM::LINUX_USER_HOST, "default Linux user/host");
535-
//checker(VM::VBOX_WINDOW_CLASS, "VBox window class");
543+
checker(VM::VBOX_WINDOW_CLASS, "VBox window class");
536544
checker(VM::GAMARUE, "gamarue ransomware technique");
537545
checker(VM::VMID_0X4, "0x4 leaf of VMID");
538546
checker(VM::PARALLELS_VM, "Parallels techniques");
@@ -621,7 +629,7 @@ void general() {
621629
std::cout << "[DEBUG] theoretical maximum points: " << VM::total_points << "\n";
622630
#endif
623631

624-
std::string brand = VM::brand(VM::MULTIPLE, spoofable_setting);
632+
std::string brand = VM::brand(VM::MULTIPLE, settings());
625633

626634
std::cout << "VM brand: " << ((brand == "Unknown") || (brand == "Hyper-V artifact (not an actual VM)") ? red : green) << brand << ansi_exit << "\n";
627635

@@ -643,7 +651,7 @@ void general() {
643651
}
644652

645653
const char* percent_color = "";
646-
const std::uint8_t percent = VM::percentage(spoofable_setting);
654+
const std::uint8_t percent = VM::percentage(settings());
647655

648656
if (percent == 0) { percent_color = red; }
649657
else if (percent < 25) { percent_color = red_orange; }
@@ -653,7 +661,7 @@ void general() {
653661

654662
std::cout << "VM likeliness: " << percent_color << static_cast<std::uint32_t>(percent) << "%" << ansi_exit << "\n";
655663

656-
const bool is_detected = VM::detect(spoofable_setting);
664+
const bool is_detected = VM::detect(settings());
657665

658666
std::cout << "VM confirmation: " << (is_detected ? green : red) << std::boolalpha << is_detected << std::noboolalpha << ansi_exit << "\n";
659667

@@ -818,6 +826,7 @@ int main(int argc, char* argv[]) {
818826
}
819827

820828
if (arg_bitset.test(ALL)) {
829+
std::cout << "\n\n\n\n\nALL SET\n\n\n\n";
821830
setting_bits |= VM::ALL;
822831
setting_bits.set(VM::SPOOFABLE);
823832
}

src/vmaware.hpp

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,6 @@ struct VM {
30393039
* @category Windows
30403040
*/
30413041
[[nodiscard]] static bool cursor_check() try {
3042-
return true;
30433042
#if (!MSVC)
30443043
return false;
30453044
#else
@@ -4352,8 +4351,7 @@ struct VM {
43524351
// this is added so no sanitizers can potentially cause unwanted delays while measuring rdtsc in a debug compilation
43534352
__attribute__((no_sanitize("address", "leak", "thread", "undefined")))
43544353
#endif
4355-
static bool rdtsc_vmexit() try {
4356-
4354+
static bool rdtsc_vmexit() try {
43574355
#if (!x86)
43584356
return false;
43594357
#else
@@ -4447,18 +4445,19 @@ struct VM {
44474445
}
44484446

44494447
// technique 3: Check for absence of AMD easter egg for K7 and K8 CPUs
4450-
/*
4448+
constexpr u32 AMD_EASTER_EGG = 0x8fffffff; // this is the CPUID leaf of the AMD easter egg
4449+
4450+
if (!cpu::is_leaf_supported(AMD_EASTER_EGG)) {
4451+
return false;
4452+
}
4453+
44514454
u32 unused, eax = 0;
44524455
cpu::cpuid(eax, unused, unused, unused, 1);
44534456

4454-
constexpr u8 AMD_K7 = 6;
4455-
constexpr u8 AMD_K8 = 15;
4456-
44574457
auto is_k7 = [](const u32 eax) -> bool {
44584458
const u32 family = (eax >> 8) & 0xF;
44594459
const u32 model = (eax >> 4) & 0xF;
44604460
const u32 extended_family = (eax >> 20) & 0xFF;
4461-
const u32 extended_model = (eax >> 16) & 0xF;
44624461

44634462
if (family == 6 && extended_family == 0) {
44644463
if (model == 1 || model == 2 || model == 3 || model == 4) {
@@ -4470,21 +4469,28 @@ struct VM {
44704469
};
44714470

44724471
auto is_k8 = [](const u32 eax) -> bool {
4473-
// TODO
4472+
const u32 family = (eax >> 8) & 0xF;
4473+
const u32 extended_family = (eax >> 20) & 0xFF;
4474+
4475+
if (family == 0xF) {
4476+
if (extended_family == 0x00 || extended_family == 0x01) {
4477+
return true;
4478+
}
4479+
}
4480+
4481+
return false;
44744482
};
44754483

4476-
if (family != AMD_K7 && family != AMD_K8) {
4484+
if (!(is_k7(eax) || is_k8(eax))) {
44774485
return false;
44784486
}
44794487

44804488
u32 ecx_bochs = 0;
4481-
cpu::cpuid(unused, unused, ecx_bochs, unused, cpu::leaf::amd_easter_egg);
4489+
cpu::cpuid(unused, unused, ecx_bochs, unused, AMD_EASTER_EGG);
44824490

44834491
if (ecx_bochs == 0) {
4484-
debug("BOCHS_CPU: technique 3 found");
4485-
return core::add(BOCHS);
4492+
return true;
44864493
}
4487-
*/
44884494
}
44894495

44904496
return false;
@@ -5035,13 +5041,13 @@ struct VM {
50355041
}
50365042

50375043
return false;
5038-
};
5044+
};
50395045

50405046
return (
50415047
check_usb() ||
50425048
check_general() ||
50435049
check_rom()
5044-
);
5050+
);
50455051
#endif
50465052
}
50475053
catch (...) {
@@ -9144,42 +9150,6 @@ struct VM {
91449150

91459151

91469152

9147-
9148-
9149-
9150-
9151-
// https://medium.com/@matterpreter/hypervisor-detection-with-systemhypervisordetailinformation-26e44a57f80e
9152-
9153-
// idea: maybe try to get the hyper-v version and check for those values in cpuid
9154-
9155-
/*
9156-
EAX=21h: Reserved for TDX enumerationWhen Intel TDX (Trust Domain Extensions) is active, attempts to execute the CPUID instruction by a TD (Trust Domain) guest will be intercepted by the TDX module. This module will, when CPUID is invoked with EAX=21h and ECX=0 (leaf 21h, sub-leaf 0), return the index of the highest supported sub-leaf for leaf 21h in EAX and a TDX module vendor ID string as a 12-byte ASCII string in EBX,EDX,ECX (in that order). Intel's own module implementation returns the vendor ID string "IntelTDX " (with four trailing spaces)[102] - for this module, additional feature information is not available through CPUID and must instead be obtained through the TDX-specific TDCALL instruction.
9157-
*/
9158-
9159-
9160-
// https://github.com/systemd/systemd/blob/main/src/basic/virt.c
9161-
9162-
9163-
/*
9164-
In the same way, a lot of these virtual files can provide information on the environment, including –
9165-
but not limited to – /proc/sysinfo (in which some distribution expose data about virtual machines),
9166-
/proc/device-tree (that lists the devices on the machine), /proc/xen (a file created by the Xen
9167-
Server) or /proc/modules (that contains information about the loaded kernel modules, modules
9168-
that are used by hypervisors to optimize the guests).
9169-
Like procfs (mounted in /proc), sysfs can be useful. Its role is to provide to the user an access to the
9170-
devices and their drivers. The file /sys/hypervisor/type, for instance, is sometimes used to store
9171-
information about the hypervisor Linux is running on
9172-
*/
9173-
9174-
9175-
// https://unprotect.it/technique/retrieve-hdd-information/
9176-
9177-
9178-
// https://github.com/torvalds/linux/blob/31cc088a4f5d83481c6f5041bd6eb06115b974af/arch/x86/kernel/cpu/vmware.c
9179-
9180-
9181-
9182-
91839153
struct core {
91849154
MSVC_DISABLE_WARNING(PADDING)
91859155
struct technique {
@@ -9323,7 +9293,6 @@ struct VM {
93239293
// run the technique
93249294
const bool result = tuple.run();
93259295

9326-
93279296
// accumulate the points if technique detected a VM
93289297
if (result) {
93299298
points += tuple.points;

0 commit comments

Comments
 (0)