Skip to content

Commit 24e473f

Browse files
authored
Merge pull request #335 from kernelwernel/dev
Improved timing attacks
2 parents 86aca7e + 54b2c39 commit 24e473f

8 files changed

Lines changed: 349 additions & 426 deletions

File tree

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
For a report on a false positive, please make sure that you include:
1+
For a report on a false positive/bug, please make sure that you include:
22
- which OS and VM you are using
33
- which technique(s) have given a false positive
44
- a screenshot or copy pasted message of the CLI's output
5+
- if necessary, running the [debug binary](https://github.com/kernelwernel/VMAware/releases/download/v2.2.0/vmaware_debug.exe) and copy pasting the output would be immensely useful for us to diagnose your issue.
56

67
> [!NOTE]
78
> Specific versions or in-depth system info is not required, just the bare basics is what we're looking for.
89
9-
If your issue is not a false positive, please make sure to write as much information as needed.
10+
If your issue is not a false positive, please make sure to write the necessary information needed.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ You can view the full docs [here](docs/documentation.md). All the details such a
239239

240240
> 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 projects, and I have no choice but to use the same license for legal reasons.
241241
>
242-
> 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 <b>7</b> techniques out of 117 (as of 2.0 version), and the lesser the number of techniques, the less accurate the overall result might be.
242+
> 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 <b>7</b> techniques out of 116 (as of 2.0 version), and the lesser the number of techniques, the less accurate the overall result might be.
243243
244244
</details>
245245

auxiliary/benchmark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
class VMAwareBenchmark {
3737
public:
38-
static uint64_t get_timestamp() {
38+
static inline uint64_t get_timestamp() {
3939
#if defined(_WIN32)
4040
LARGE_INTEGER counter;
4141
QueryPerformanceCounter(&counter);
@@ -51,7 +51,7 @@ class VMAwareBenchmark {
5151
#endif
5252
}
5353

54-
static double get_elapsed(uint64_t start, uint64_t end) {
54+
static inline double get_elapsed(uint64_t start, uint64_t end) {
5555
#if defined(_WIN32)
5656
static LARGE_INTEGER freq;
5757
QueryPerformanceFrequency(&freq);

docs/documentation.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [`VM::conclusion()`](#vmconclusion)
1111
- [`VM::detected_count()`](#vmdetected_count)
1212
- [`VM::vmaware struct`](#vmaware-struct)
13+
- [Overall things to avoid](#overall-things-to-avoid)
1314
- [Flag table](#flag-table)
1415
- [Brand table](#brand-table)
1516
- [Setting flags](#setting-flags)
@@ -411,6 +412,12 @@ int main() {
411412

412413
<br>
413414

415+
# Overall things to avoid
416+
❌ 1. Do NOT rely on the percentage to determine whether you're in a VM. The lib is not designed for this way, and you're potentially increasing false positives. Use VM::detect() instead for that job.
417+
❌ 2. Do NOT depend your whole program on whether a specific brand was found. VM::brand() will not guarantee it'll give you the result you're looking for even if the environment is in fact that specific VM brand.
418+
❌ 3. Do NOT use VM::NO_MEMO flag if you're not sure what you're doing, this can potentially hamper the performance significantly.
419+
420+
<br>
414421

415422
# Flag table
416423
VMAware provides a convenient way to not only check for VMs, but also have the flexibility and freedom for the end-user to choose what techniques are used with complete control over what gets executed or not. This is handled with a flag system.
@@ -515,15 +522,13 @@ VMAware provides a convenient way to not only check for VMs, but also have the f
515522
| `VM::PROCESSOR_NUMBER` | Check for number of processors | Windows | 50% | | | | |
516523
| `VM::NUMBER_OF_CORES` | Check for number of cores | Windows | 50% | | | | |
517524
| `VM::ACPI_TEMPERATURE` | Check for device's temperature | Windows | 25% | | | | |
518-
| `VM::PROCESSOR_ID` | Check if any processor has an empty Processor ID using SMBIOS data | Windows | 25% | | | | |
519525
| `VM::SYS_QEMU` | Check for existence of "qemu_fw_cfg" directories within /sys/module and /sys/firmware | Linux | 70% | | | | |
520526
| `VM::LSHW_QEMU` | Check for QEMU string instances with lshw command | Linux | 80% | | | | |
521527
| `VM::VIRTUAL_PROCESSORS` | Check if the number of virtual and logical processors are reported correctly by the system | Windows | 50% | | | | |
522528
| `VM::HYPERV_QUERY` | Check if a call to NtQuerySystemInformation with the 0x9f leaf fills a _SYSTEM_HYPERVISOR_DETAIL_INFORMATION structure | Windows | 100% | | | | |
523529
| `VM::BAD_POOLS` | Check for system pools allocated by hypervisors | Windows | 80% | | | | |
524530
| `VM::AMD_SEV` | Check for AMD-SEV MSR running on the system | Linux and MacOS | 50% | Admin | | | |
525531
| `VM::AMD_THREAD_MISMATCH` | Check for AMD CPU thread count database if it matches the system's thread count | | 95% | | | | |
526-
| `VM::NATIVE_VHD` | Checks if the OS was booted from a VHD container | | 100% | | | | |
527532
| `VM::NATIVE_VHD` | Check for OS being booted from a VHD container | Windows | 100% | | | | |
528533
| `VM::VIRTUAL_REGISTRY` | Check for particular object directory which is present in Sandboxie virtual environment but not in usual host systems | Windows | 65% | | | | Admin only needed for Linux |
529534
| `VM::FIRMWARE` | Check for VM signatures and patched strings by hardeners in firmware, while ensuring the BIOS serial is valid | Windows and Linux | 100% | | | | |

src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
|------|---------|
33
| `cli.cpp` | Entire CLI tool code |
44
| `vmaware.hpp` | Official and original library header in GPL-3.0, most likely what you're looking for. |
5-
| `vmaware_MIT.hpp` | Same as above but in MIT. But this removes 7 techniques out of 117 |
5+
| `vmaware_MIT.hpp` | Same as above but in MIT. But this removes 7 techniques out of 116 |
66

77
<br>
88

src/cli.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ bool is_unsupported(VM::enum_flags flag) {
458458
case VM::PROCESSOR_NUMBER:
459459
case VM::NUMBER_OF_CORES:
460460
case VM::ACPI_TEMPERATURE:
461-
case VM::PROCESSOR_ID:
462461
case VM::POWER_CAPABILITIES:
463462
case VM::SETUPAPI_DISK:
464463
case VM::VIRTUAL_PROCESSORS:
@@ -807,36 +806,27 @@ void checker(const VM::enum_flags flag, const char* message) {
807806
// overload for std::function, this is specific for any.run techniques
808807
// that are embedded in the CLI because it was removed in the lib as of 2.0
809808
void checker(const std::function<bool()>& func, const char* message) {
810-
#if __cplusplus >= 201703L
811-
if constexpr (!CLI_WINDOWS) {
812-
if (arg_bitset.test(VERBOSE)) {
813-
unsupported_count++;
814-
}
815-
else {
816-
supported_count++;
817-
}
818-
}
819-
else {
820-
supported_count++;
821-
}
822-
#else
823-
#if !CLI_WINDOWS
809+
#if (!CLI_WINDOWS)
824810
if (arg_bitset.test(VERBOSE)) {
825811
unsupported_count++;
826-
}
827-
else {
812+
} else {
828813
supported_count++;
829814
}
830815
#else
831816
supported_count++;
832817
#endif
833-
#endif
818+
819+
const bool result = func();
834820

835821
std::cout <<
836-
(func() ? detected : not_detected) <<
822+
(result ? detected : not_detected) <<
823+
(result ? bold : "") <<
837824
" Checking " <<
838825
message <<
839-
"...\n";
826+
"..." <<
827+
(result ? ansi_exit : "") <<
828+
"\n";
829+
840830
}
841831

842832

@@ -974,7 +964,6 @@ void general() {
974964
checker(VM::PROCESSOR_NUMBER, "processor count");
975965
checker(VM::NUMBER_OF_CORES, "CPU core count");
976966
checker(VM::ACPI_TEMPERATURE, "thermal devices");
977-
checker(VM::PROCESSOR_ID, "processor ID");
978967
checker(VM::POWER_CAPABILITIES, "Power capabilities");
979968
checker(VM::SETUPAPI_DISK, "SETUPDI diskdrive");
980969
checker(VM::SYS_QEMU, "QEMU in /sys");
@@ -1159,11 +1148,20 @@ void general() {
11591148
{
11601149
const char* conclusion_color = color(vm.percentage);
11611150

1151+
std::string conclusion = vm.conclusion;
1152+
1153+
if (is_anyrun && VM::brand() == brands::NULL_BRAND) {
1154+
const std::string original = "unknown";
1155+
const std::string new_brand = "ANY.RUN";
1156+
1157+
replace(conclusion, original, new_brand);
1158+
}
1159+
11621160
std::cout
11631161
<< bold
11641162
<< "====== CONCLUSION: "
11651163
<< ansi_exit
1166-
<< conclusion_color << vm.conclusion << " " << ansi_exit
1164+
<< conclusion_color << conclusion << " " << ansi_exit
11671165
<< bold
11681166
<< "======"
11691167
<< ansi_exit

0 commit comments

Comments
 (0)