-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathVM-CHECKER.ps1
More file actions
2303 lines (1933 loc) · 70.9 KB
/
VM-CHECKER.ps1
File metadata and controls
2303 lines (1933 loc) · 70.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$($PWD.Path)' ; & '$($myInvocation.InvocationName)'`"" -Verb RunAs
Exit
}
function Check-RegistryArtifacts {
$category = "Registry Keys"
$detected = @()
$paths = @(
"HKLM:\\SOFTWARE\\Oracle\\VirtualBox Guest Additions",
"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\VBoxGuest",
"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\VBoxMouse",
"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\VBoxService",
"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\VBoxSF",
"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\VBoxVideo",
"HKLM:\\SOFTWARE\\VMware, Inc.\\VMware Tools",
"HKLM:\\SOFTWARE\\Wine",
"HKLM:\\SOFTWARE\\Microsoft\\Virtual Machine\\Guest\\Parameters"
)
foreach ($p in $paths) {
if (Test-Path $p) { $detected += $p }
}
$acpi = @(
"HKLM:\\HARDWARE\\ACPI\\DSDT\\VBOX__",
"HKLM:\\HARDWARE\\ACPI\\FADT\\VBOX__",
"HKLM:\\HARDWARE\\ACPI\\RSDT\\VBOX__"
)
foreach ($p in $acpi) {
if (Test-Path $p) { $detected += $p }
}
try {
Get-ChildItem "HKLM:\\HARDWARE\\DEVICEMAP\\Scsi" -Recurse -ErrorAction Stop |
ForEach-Object {
$id = (Get-ItemProperty -Path $_.PSPath -Name Identifier -ErrorAction Stop).Identifier
if ($id -match "VBOX|VMWARE|QEMU") { $detected += "Scsi Identifier = $id" }
}
} catch { }
$diskKey = "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\Disk\\Enum"
if (Test-Path $diskKey) {
try {
(Get-ItemProperty $diskKey).PSObject.Properties |
Where-Object { $_.Name -match '^\d+$' } |
ForEach-Object {
if ($_.Value -match "VMware|VBOX|Virtual") {
$detected += "Disk Enum -> $($_.Value)"
}
}
} catch { }
}
$isBad = $detected.Count -gt 0
if ($isBad) {
$detail = "BAD: Detected virtualization registry artifacts:`n" +
($detected -join "`n")
} else {
$detail = "GOOD: No virtualization or sandbox registry artifacts found."
}
return [PSCustomObject]@{
Category = $category
IsBad = $isBad
Detail = $detail
}
}
function Check-SleepHook {
$category = "Timing Check"
$sw = [Diagnostics.Stopwatch]::StartNew()
Start-Sleep -Milliseconds 1000
$sw.Stop()
$actualMs = $sw.ElapsedMilliseconds
$expectedMs = 1000
$thresholdMs = 900
$suspicious = $actualMs -lt $thresholdMs
return [PSCustomObject]@{
Category = $category
IsBad = $suspicious
Detail = if ($suspicious) {
"Sleep(1000ms) returned too fast (actual ${actualMs}ms)"
} else {
"Sleep timing is normal (${actualMs}ms)"
}
}
}
function Check-Hypervisor {
$category = "HypervisorCheck"
$hypervisorFlag = $null
try {
$hypervisorFlag = (Get-CimInstance Win32_ComputerSystem).HypervisorPresent
} catch {
$hypervisorFlag = $false
}
$isHypervisor = ($hypervisorFlag -eq $true)
return [PSCustomObject]@{
Category = $category
IsBad = $isHypervisor
Detail = if ($isHypervisor) {
"Hypervisor is present (WMI HypervisorPresent = True)"
} else {
"No hypervisor flag detected (HypervisorPresent = False)"
}
}
}
function Check-CPUFeatures {
$category = "CPUFeatureCheck"
if (-not ([System.Management.Automation.PSTypeName]'Win32.NativeMethods').Type) {
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("kernel32.dll")]
public static extern bool IsProcessorFeaturePresent(uint feature);
"@ -PassThru | Out-Null
}
$nxSupported = [Win32.NativeMethods]::IsProcessorFeaturePresent(12)
$sse2Supported = [Win32.NativeMethods]::IsProcessorFeaturePresent(10)
$sse3Supported = [Win32.NativeMethods]::IsProcessorFeaturePresent(13)
$rdtscSupported= [Win32.NativeMethods]::IsProcessorFeaturePresent(8)
$missing = @()
if (-not $nxSupported) { $missing += "NX/DEP" }
if (-not $sse2Supported) { $missing += "SSE2" }
if (-not $sse3Supported) { $missing += "SSE3" }
if (-not $rdtscSupported) { $missing += "RDTSC" }
$isAnomalous = ($missing.Count -gt 0)
return [PSCustomObject]@{
Category = $category
IsBad = $isAnomalous
Detail = if ($isAnomalous) {
"Missing CPU features: " + ($missing -join ", ")
} else {
"All expected CPU features (NX, SSE2/3, RDTSC) are present"
}
}
}
function Check-VideoAdapter {
$category = "VideoAdapterCheck"
$virtualKeywords = @("VMWARE", "VirtualBox", "Virtual VGA", "Virtual",
"SVGA", "S3 Trio", "Basic Display", "Remote Display",
"Hyper-V", "Microsoft Hyper-V", "QXL", "Red Hat", "Parallels")
$virtualFound = @()
foreach ($gpu in Get-CimInstance Win32_VideoController) {
$name = $gpu.Name
$descr= $gpu.Description
$adapterText = ($name + " " + $descr).ToUpper()
foreach ($kw in $virtualKeywords) {
if ($adapterText -like "*$kw.ToUpper()*") {
$virtualFound += $gpu.Name
break
}
}
}
$isVirtualGPU = ($virtualFound.Count -gt 0)
return [PSCustomObject]@{
Category = $category
IsBad = $isVirtualGPU
Detail = if ($isVirtualGPU) {
"Unusual GPU driver detected: " + ($virtualFound -join "; ")
} else {
"Graphics adapters appear normal (no known virtual GPU drivers)"
}
}
}
function Check-OSArtifacts {
$category = "OSArtifactCheck"
$os = Get-CimInstance Win32_OperatingSystem
$regUser = $os.RegisteredUser
$org = $os.Organization
$caption = $os.Caption
$installDateStr = $os.InstallDate
$installDate = try {
[System.Management.ManagementDateTimeConverter]::ToDateTime($installDateStr)
} catch { $null }
$flags = @()
if ([string]::IsNullOrWhiteSpace($regUser) -or $regUser.ToLower() -match "user|admin|sandbox") {
$flags += "RegisteredUser='$regUser'"
}
if ($org -and ($org.ToLower() -match "organization|orgname|contoso" -or $org.Trim().Length -eq 0)) {
$flags += "Organization='$org'"
}
if ($caption -match "Evaluation") {
$flags += "OS Edition is Evaluation Copy"
}
if ($installDate) {
$daysSinceInstall = (Get-Date) - $installDate
if ($daysSinceInstall.TotalDays -lt 30) {
$flags += "OS installed ${[math]::Round($daysSinceInstall.TotalDays,1)} days ago"
}
}
$isSuspicious = ($flags.Count -gt 0)
return [PSCustomObject]@{
Category = $category
IsBad = $isSuspicious
Detail = if ($isSuspicious) {
"Suspicious OS info: " + ($flags -join "; ")
} else {
"No obvious sandbox artifacts in OS metadata (user, org, install date seem normal)"
}
}
}
function Check-Processes {
$category = "Processes"
$suspectNames = @(
"vboxservice",
"vboxtray",
"vmtoolsd",
"vmwaretray",
"vmwareuser",
"vgauthservice",
"vmacthlp",
"vmsrvc",
"vmusrvc",
"sbiectrl",
"sbiesvc"
)
$detected = Get-Process -ErrorAction SilentlyContinue |
Where-Object { $suspectNames -contains $_.Name.ToLower() } |
ForEach-Object { $_.Name + ".exe" }
$isBad = $detected.Count -gt 0
if ($isBad) {
$detail = "BAD: Detected the following VM/sandbox processes:`n" + ($detected -join "`n")
} else {
$detail = "GOOD: No known VM or sandbox processes are running."
}
return [PSCustomObject]@{
Category = $category
IsBad = $isBad
Detail = $detail
}
}
function Check-DriversFiles {
$systemDir = $Env:SystemRoot + "\\System32"
$filePaths = @(
"$systemDir\\drivers\\VBoxMouse.sys",
"$systemDir\\drivers\\VBoxWddm.sys",
"$systemDir\\drivers\\VBoxGuest.sys",
"$systemDir\\drivers\\VBoxSF.sys",
"$systemDir\\drivers\\VBoxVideo.sys",
"$systemDir\\drivers\\vmmouse.sys",
"$systemDir\\drivers\\vmhgfs.sys",
"$systemDir\\drivers\\vm3dmp.sys",
"$systemDir\\drivers\\vmci.sys",
"$systemDir\\drivers\\vmmemctl.sys",
"$systemDir\\drivers\\vmrawdsk.sys",
"$systemDir\\drivers\\vmusbmouse.sys",
"$systemDir\\vboxservice.exe",
"$systemDir\\vboxtray.exe"
)
$detected = @()
foreach ($file in $filePaths) {
if (Test-Path $file) {
$detected += ([System.IO.Path]::GetFileName($file))
}
}
$isBad = $detected.Count -gt 0
if ($isBad) {
$detail = "BAD: Detected the following VM driver files:`n" + ($detected -join "`n")
} else {
$detail = "GOOD: No virtualization driver files were found."
}
return [PSCustomObject]@{
Category = "System Files"
IsBad = $isBad
Detail = $detail
}
}
function Check-SystemManufacturer {
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
$manufacturer = $cs.Manufacturer
$model = $cs.Model
$detected = @()
$vmKeywords = @("VMware", "VirtualBox", "Virtual Machine", "Microsoft Corporation", "Xen", "QEMU", "Bochs", "Parallels", "KVM", "Innotek")
if ($manufacturer) {
foreach ($kw in $vmKeywords) {
if ($manufacturer -match $kw) {
$detected += "Manufacturer: $manufacturer"
break
}
}
}
if ($model) {
foreach ($kw in $vmKeywords) {
if ($model -match $kw) {
$detected += "Model: $model"
break
}
}
}
$csp = Get-CimInstance -ClassName Win32_ComputerSystemProduct -ErrorAction SilentlyContinue
if ($csp) {
if ($csp.Vendor) {
foreach ($kw in $vmKeywords) {
if ($csp.Vendor -match $kw) {
$detected += "System Vendor: $($csp.Vendor)"
break
}
}
}
if ($csp.Name) {
foreach ($kw in $vmKeywords) {
if ($csp.Name -match $kw) {
$detected += "Product Name: $($csp.Name)"
break
}
}
}
}
$isBad = $detected.Count -gt 0
if ($isBad) {
$detail = "BAD: Detected virtualization in hardware IDs:`n" + ($detected -join "`n")
} else {
$detail = "GOOD: No virtualization indicators in manufacturer/model/vendor/product."
}
return [PSCustomObject]@{
Category = "Hardware IDs"
IsBad = $isBad
Detail = $detail
}
}
function Check-BIOSInfo {
$bios = Get-CimInstance -ClassName Win32_BIOS
$biosVendor = $bios.Manufacturer
$biosVersion = ($bios.SMBIOSBIOSVersion -join " ")
$detected = @()
$vmKeywords = @("VMware", "VirtualBox", "VBox", "HVM", "Xen", "QEMU", "Virtual Machine", "Hyper-V", "Microsoft", "Bochs", "SeaBIOS", "Parallels")
if ($biosVendor) {
foreach ($kw in $vmKeywords) {
if ($biosVendor -match $kw) {
$detected += "BIOS Vendor: $biosVendor"
break
}
}
}
if ($biosVersion) {
foreach ($kw in $vmKeywords) {
if ($biosVersion -match $kw) {
$detected += "BIOS Version: $biosVersion"
break
}
}
}
if ($bios.SerialNumber -and ($bios.SerialNumber -match "0{4,}|Default|To be filled")) {
$detected += "BIOS Serial: $($bios.SerialNumber)"
}
$isBad = $detected.Count -gt 0
if ($isBad) {
$detail = "BAD: Detected virtualization in BIOS info:`n" + ($detected -join "`n")
} else {
$detail = "GOOD: No virtualization indicators in BIOS vendor, version, or serial."
}
return [PSCustomObject]@{
Category = "BIOS Info"
IsBad = $isBad
Detail = $detail
}
}
function Check-MAC {
$vmMACPrefixes = @{
"080027" = "VirtualBox"
"000569" = "VMware"
"000C29" = "VMware"
"001C14" = "VMware"
"005056" = "VMware"
"001C42" = "Parallels"
"00163E" = "Xen"
"0A0027" = "Sandbox"
"00155D" = "Hyper-V"
"525400" = "QEMU/KVM"
}
$detected = @()
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter "MACAddress IS NOT NULL" | ForEach-Object {
$mac = $_.MACAddress
if ($mac) {
$prefix = $mac.ToUpper() -replace "[:\-]", ""
if ($prefix.Length -ge 6) {
$prefix6 = $prefix.Substring(0,6)
if ($vmMACPrefixes.ContainsKey($prefix6)) {
$detected += ("MAC $mac (Vendor: $($vmMACPrefixes[$prefix6]))")
}
}
}
}
$isBad = $detected.Count -gt 0
if ($isBad) {
$detail = "BAD: Detected VM MAC prefixes:`n" + ($detected -join "`n")
} else {
$detail = "GOOD: No VM-related MAC address prefixes detected."
}
return [PSCustomObject]@{
Category = "MAC Address"
IsBad = $isBad
Detail = $detail
}
}
function Check-DeviceNames {
$detected = @()
$vmKeywords = @("VBOX", "VMware", "Virtual", "QEMU", "Hyper-V", "Xen", "Parallels")
Get-CimInstance -ClassName Win32_DiskDrive | ForEach-Object {
if ($_.Model -match "VBOX|Virtual|VMware|QEMU") {
$detected += "DiskDrive: $($_.Model)"
}
}
Get-CimInstance Win32_VideoController | ForEach-Object {
foreach ($kw in $vmKeywords) {
if ($_.Name -match $kw) {
$detected += "VideoController: $($_.Name)"
break
}
}
}
Get-CimInstance Win32_NetworkAdapter -Filter "MACAddress IS NOT NULL" | ForEach-Object {
foreach ($kw in $vmKeywords) {
if ($_.Name -match $kw) {
$detected += "NetworkAdapter: $($_.Name)"
break
}
}
}
$isBad = $detected.Count -gt 0
if ($isBad) {
$detail = "BAD: Detected virtualization in device names:`n" + ($detected -join "`n")
} else {
$detail = "GOOD: No virtualization indicators found in device names."
}
return [PSCustomObject]@{
Category = "Device Manager Names"
IsBad = $isBad
Detail = $detail
}
}
function Check-ACPI {
$detected = @()
$acpiRoot = "HKLM:\\HARDWARE\\ACPI"
$vmACPIKeywords = @("VBOX", "VMWARE", "VIRTUAL", "QEMU", "XEN", "HYPERV", "PARALLELS", "KVM", "BOCHS", "MICROSOFT")
if (Test-Path $acpiRoot) {
Get-ChildItem $acpiRoot -ErrorAction SilentlyContinue | ForEach-Object {
$keyName = $_.PSChildName
if ($vmACPIKeywords -contains $keyName.ToUpper()) {
$detected += "ACPI Root Table: $keyName matches known VM pattern."
}
Get-ChildItem -Path "$acpiRoot\\$keyName" -ErrorAction SilentlyContinue | ForEach-Object {
$subKeyName = $_.PSChildName
foreach ($kw in $vmACPIKeywords) {
if ($subKeyName.ToUpper() -like "*$kw*") {
$detected += "ACPI Subkey: $($keyName)\$($subKeyName) matches $kw"
break
}
}
}
}
}
function Get-OEMIDFromACPI {
param (
[string]$TableSignature
)
try {
$bufferSize = [System.Runtime.InteropServices.Marshal]::SizeOf([byte]) * 36
$buffer = New-Object byte[] $bufferSize
$bytesRead = [System.Runtime.InteropServices.Marshal]::SizeOf([byte]) * $bufferSize
$result = [System.Runtime.InteropServices.Marshal]::Copy(
[System.Runtime.InteropServices.Marshal]::AllocHGlobal($bufferSize),
$buffer,
0,
$bufferSize
)
$firmwareTableProviderSignature = [System.Text.Encoding]::ASCII.GetBytes("ACPI")
$tableSignature = [System.Text.Encoding]::ASCII.GetBytes($TableSignature)
$oemId = [System.Text.Encoding]::ASCII.GetString($buffer, 10, 6).Trim()
return $oemId
} catch {
return $null
}
}
$dsdtOemId = Get-OEMIDFromACPI -TableSignature "DSDT"
$facpOemId = Get-OEMIDFromACPI -TableSignature "FACP"
foreach ($oemId in @($dsdtOemId, $facpOemId)) {
if ($oemId) {
foreach ($kw in $vmACPIKeywords) {
if ($oemId.ToUpper() -like "*$kw*") {
$detected += "ACPI Table OEM ID: $oemId matches $kw"
break
}
}
}
}
$isBad = $detected.Count -gt 0
$detail = if ($isBad) {
"BAD: Detected ACPI VM indicators:`n" + ($detected -join "`n")
} else {
"GOOD: No virtualization indicators found in ACPI tables."
}
return [PSCustomObject]@{
Category = "ACPI Tables"
IsBad = $isBad
Detail = $detail
}
}
function Check-CPUIDHypervisorBit {
$category = "CPUID Hypervisor Bit"
try {
$proc = Get-CimInstance Win32_Processor | Select-Object -First 1
$hypervisorPresent = (Get-CimInstance Win32_ComputerSystem).HypervisorPresent
$cpuHints = $proc.Name -match "Virtual|Hypervisor|QEMU|KVM"
$isBad = $hypervisorPresent -or $cpuHints
return [PSCustomObject]@{
Category = $category
IsBad = $isBad
Detail = if ($isBad) {
"CPUID indicates hypervisor present or virtual CPU detected"
} else {
"CPUID shows no hypervisor presence"
}
}
}
catch {
return [PSCustomObject]@{
Category = $category
IsBad = $false
Detail = "Could not query CPUID information"
}
}
}
function Check-USBDevices {
$category = "USB Devices"
$usbDevices = Get-PnpDevice -Class USB -ErrorAction SilentlyContinue
$realDeviceCount = ($usbDevices | Where-Object {
$_.FriendlyName -notmatch "Root Hub|Generic|Composite"
}).Count
$isBad = $realDeviceCount -eq 0
return [PSCustomObject]@{
Category = $category
IsBad = $isBad
Detail = if ($isBad) {
"No real USB devices detected (typical of VMs)"
} else {
"Real USB devices detected ($realDeviceCount devices)"
}
}
}
function Check-BatteryPresence {
$category = "Battery Presence"
$battery = Get-CimInstance Win32_Battery -ErrorAction SilentlyContinue
$isDesktop = (Get-CimInstance Win32_SystemEnclosure).ChassisTypes -contains 3
$isSuspicious = ($null -eq $battery) -and -not $isDesktop
return [PSCustomObject]@{
Category = $category
IsBad = $isSuspicious
Detail = if ($battery) {
"Battery detected (laptop or hybrid)"
} elseif ($isDesktop) {
"No battery (desktop chassis)"
} else {
"No battery on non-desktop system (VM indicator)"
}
}
}
function Check-ScreenResolution {
$category = "Screen Resolution"
Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
$width = $screen.Bounds.Width
$height = $screen.Bounds.Height
# Common VM default resolutions
$vmResolutions = @(
"800x600", "1024x768", "1280x720", "1280x800", "1366x768"
)
$currentRes = "${width}x${height}"
$isSuspicious = $vmResolutions -contains $currentRes
return [PSCustomObject]@{
Category = $category
IsBad = $isSuspicious
Detail = if ($isSuspicious) {
"Resolution $currentRes matches common VM default"
} else {
"Resolution $currentRes appears normal"
}
}
}
function Check-UserActivity {
$category = "User Activity"
$chromeHistory = "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\History"
$edgeHistory = "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\History"
$hasHistory = (Test-Path $chromeHistory) -or (Test-Path $edgeHistory)
$recentFiles = Get-ChildItem "$env:APPDATA\Microsoft\Windows\Recent" -ErrorAction SilentlyContinue
$hasRecentActivity = $recentFiles.Count -gt 5
$isSuspicious = -not $hasHistory -and -not $hasRecentActivity
return [PSCustomObject]@{
Category = $category
IsBad = $isSuspicious
Detail = if ($isSuspicious) {
"No browser history or recent files (fresh VM indicator)"
} else {
"User activity detected (browser history or recent files exist)"
}
}
}
function Check-TemperatureSensors {
$category = "Temperature Sensors"
$wmi = Get-WmiObject -Namespace "root\wmi" -Class MSAcpi_ThermalZoneTemperature -ErrorAction SilentlyContinue
$hasSensors = $null -ne $wmi
return [PSCustomObject]@{
Category = $category
IsBad = -not $hasSensors
Detail = if ($hasSensors) {
"Temperature sensors detected (physical hardware)"
} else {
"No temperature sensors (VM indicator)"
}
}
}
function Check-ClipboardSharing {
$category = "Clipboard Sharing"
$clipboardProcesses = Get-Process | Where-Object {
$_.Name -match "VBoxClient|vmware-vmblock"
}
$isBad = $clipboardProcesses.Count -gt 0
return [PSCustomObject]@{
Category = $category
IsBad = $isBad
Detail = if ($isBad) {
"VM clipboard sharing detected"
} else {
"No VM clipboard sharing detected"
}
}
}
function Check-SystemUptime {
$category = "System Uptime"
$os = Get-CimInstance Win32_OperatingSystem
$uptime = (Get-Date) - $os.LastBootUpTime
$isSuspicious = $uptime.TotalMinutes -lt 30
return [PSCustomObject]@{
Category = $category
IsBad = $isSuspicious
Detail = if ($isSuspicious) {
"System uptime is only $([math]::Round($uptime.TotalMinutes, 1)) minutes (fresh boot)"
} else {
"System uptime: $([math]::Round($uptime.TotalHours, 1)) hours"
}
}
}
function Check-CPUCores {
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
$numCores = $cs.NumberOfLogicalProcessors
if (-not $numCores) {
$numCores = (Get-CimInstance -ClassName Win32_Processor).Count
}
$detected = @()
if ($numCores -le 2) {
$detected += "$numCores core(s) detected"
}
$isBad = $detected.Count -gt 0
$detail = if ($isBad) { $detected } else { @("Detected $numCores logical processor(s). This appears normal for a modern physical machine.") }
return [PSCustomObject]@{
Category = "CPU Cores"
IsBad = $isBad
Detail = $detail
}
}
function Check-RAM {
$cs = Get-CimInstance -ClassName Win32_ComputerSystem
$totalMemGB = [math]::Round($cs.TotalPhysicalMemory / 1GB, 2)
$detected = @()
$thresholdGB = 6
if ($totalMemGB -lt $thresholdGB) {
$detected += "$totalMemGB GB RAM detected, which is below the typical threshold of $thresholdGB GB."
} else {
$detected += "$totalMemGB GB RAM detected, which meets or exceeds the typical threshold of $thresholdGB GB."
}
$isBad = $totalMemGB -lt $thresholdGB
return [PSCustomObject]@{
Category = "RAM Size"
IsBad = $isBad
Detail = $detected
}
}
function Check-Disk {
$detected = @()
$cDrive = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'"
$thresholdGB = 80
if ($cDrive -and $cDrive.Size) {
$totalGB = [math]::Round($cDrive.Size / 1GB, 1)
if ($totalGB -lt $thresholdGB) {
$detected += "$totalGB GB disk size detected, which is below the threshold of $thresholdGB GB."
} else {
$detected += "$totalGB GB disk size detected, which exceeds the threshold of $thresholdGB GB."
}
} else {
$detected += "Unable to retrieve disk size information. This may indicate a restricted or abnormal system configuration."
}
$isBad = $cDrive -and $cDrive.Size -and ([math]::Round($cDrive.Size / 1GB, 1) -lt $thresholdGB)
$detail = $detected
return [PSCustomObject]@{
Category = "Disk Size"
IsBad = $isBad
Detail = $detail
}
}
function Check-MouseMovement {
Add-Type -AssemblyName System.Windows.Forms
$initialPos = [System.Windows.Forms.Cursor]::Position
Start-Sleep -Milliseconds 2000
$newPos = [System.Windows.Forms.Cursor]::Position
$detected = @()
if (($newPos.X -eq $initialPos.X) -and ($newPos.Y -eq $initialPos.Y)) {
$detected += "No mouse movement detected after 2 seconds."
} else {
$detected += "Mouse movement detected within 2 seconds."
}
$isBad = ($newPos.X -eq $initialPos.X) -and ($newPos.Y -eq $initialPos.Y)
$detail = $detected
return [PSCustomObject]@{
Category = "Mouse Movement"
IsBad = $isBad
Detail = $detail
}
}
function Check-CPUHypervisor {
$proc = Get-CimInstance -ClassName Win32_Processor | Select-Object -First 1
$cpuName = $proc.Name
$detected = @()
if ($cpuName -match "Virtual CPU|Microsoft Hyper-V|Virtualbox|vbox") {
$detected += "CPU Name indicates virtualization: '$cpuName'"
}
$isBad = $detected.Count -gt 0
$detail = if ($isBad) { $detected } else { "CPU Name appears normal: '$cpuName'. Typical of real hardware." }
return [PSCustomObject]@{
Category = "CPU IDs"
IsBad = $isBad
Detail = $detail
}
}
function Check-PciVendor {
$detected = @()
Get-CimInstance -ClassName Win32_PnPEntity | ForEach-Object {
if ($_.PNPDeviceID -match "VEN_80EE&DEV_CAFE") {
$detected += "Detected VirtualBox PCI device: $($_.PNPDeviceID)"
}
}
$isBad = $detected.Count -gt 0
$detail = if ($isBad) {
$detected
} else {
"No VirtualBox-specific PCI devices detected."
}
return [PSCustomObject]@{
Category = "PCI Vendor ID"
IsBad = $isBad
Detail = $detail
}
}
function Check-BaseBoard {
$detected = @()
$vmKeywords = @("VirtualBox", "Oracle Corporation", "Vbox")
$genericKeywords = @("OEM", "To Be Filled By OEM", "System Manufacturer", "System Product Name", "Default string")
$bb = Get-CimInstance -ClassName Win32_BaseBoard -ErrorAction SilentlyContinue
if ($bb) {
foreach ($prop in @($bb.Manufacturer, $bb.Product)) {
foreach ($kw in $vmKeywords + $genericKeywords) {
if ($prop -and ($prop -match [regex]::Escape($kw))) {
$detected += "Suspicious baseboard entry detected: $prop"
break
}
}
}
}
$isBad = $detected.Count -gt 0
$detail = if ($isBad) {
$detected
} else {
"No suspicious baseboard manufacturer or product names found."
}
return [PSCustomObject]@{
Category = "BaseBoard"
IsBad = $isBad
Detail = $detail
}
}
function Check-EventLogSources {
$targets = @("vboxvideo", "VBoxVideoW8", "VBoxWddm")
$detected = @()
try {
$events = Get-WinEvent -LogName System -ErrorAction SilentlyContinue
foreach ($event in $events) {
if ($targets -contains $event.ProviderName) {
$detected += "Detected VirtualBox-related event source: $($event.ProviderName)"
}
}
} catch {
$detected += "Error accessing System event log: $_"
}
$isBad = $detected.Count -gt 0
$detail = if ($isBad) {
$detected
} else {
"No VirtualBox-related event sources detected in the System event log."
}
return [PSCustomObject]@{
Category = "Event Log Sources"
IsBad = $isBad
Detail = $detail
}
}
function Check-NetworkProvider {
$dll = @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("mpr.dll", CharSet=CharSet.Auto)]
public static extern int WNetGetProviderName(int netType, System.Text.StringBuilder lpProviderName, ref int lpnLength);
}
"@
Add-Type -TypeDefinition $dll -PassThru | Out-Null
$sb = New-Object System.Text.StringBuilder 1024
$len = $sb.Capacity
$res = [Win32]::WNetGetProviderName(0x0000001A, $sb, [ref]$len)
$provider = if ($res -eq 0) { $sb.ToString() } else { "" }
$isBad = ($provider -eq "VirtualBox Shared Folders")
if ($isBad) {
$detail = @("Provider: `"$provider`" (VirtualBox shared-folders detected)")
} else {
$detail = @("No VirtualBox Shared Folders provider")
}
return [PSCustomObject]@{
Category = "NetProvider"
IsBad = $isBad
Detail = $detail
}
}
function Check-VBoxBiosData {
$category = "VirtualBox BIOS"
$findings = @()
$biosKey = "HKLM:\\HARDWARE\\DESCRIPTION\\System"
try {
$sysBiosVersion = (Get-ItemProperty -Path $biosKey -Name "SystemBiosVersion" -ErrorAction Stop)."SystemBiosVersion"
if ($sysBiosVersion) {
$sysBiosVersionText = if ($sysBiosVersion -is [System.Array]) { $sysBiosVersion -join " " } else { $sysBiosVersion }
if ($sysBiosVersionText -match "VBOX") {
$findings += "SystemBiosVersion contains 'VBOX'"
}
}
} catch { }
try {
$vidBiosVersion = (Get-ItemProperty -Path $biosKey -Name "VideoBiosVersion" -ErrorAction Stop)."VideoBiosVersion"
if ($vidBiosVersion) {
$vidBiosVersionText = if ($vidBiosVersion -is [System.Array]) { $vidBiosVersion -join " " } else { $vidBiosVersion }
if ($vidBiosVersionText -match "VIRTUALBOX") {
$findings += "VideoBiosVersion contains 'VIRTUALBOX'"
}
}
} catch { }
try {
$biosDate = (Get-ItemProperty -Path $biosKey -Name "SystemBiosDate" -ErrorAction Stop)."SystemBiosDate"
if ($biosDate) {
if ($biosDate -match "^06/2[3-9]/99$") {
$findings += "SystemBiosDate is $biosDate (matches VirtualBox default)"
}
}