Skip to content

Commit 10cf327

Browse files
committed
Improve Hyper-V tests in checkvm
All Win10 machines, physical and virtual, were being reported as 'Hyper-V' (false positives) Added functionality to extract hostname of physical hypervisor from VM registry
1 parent d6e966b commit 10cf327

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

modules/post/windows/gather/checkvm.rb

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,73 @@ module supports detection of Hyper-V, VMWare, Virtual PC,
2828
# Method for detecting if it is a Hyper-V VM
2929
def hypervchk(session)
3030
vm = false
31-
sfmsvals = registry_enumkeys('HKLM\SOFTWARE\Microsoft')
32-
if sfmsvals and sfmsvals.include?("Hyper-V")
33-
vm = true
34-
elsif sfmsvals and sfmsvals.include?("VirtualMachine")
35-
vm = true
31+
32+
physicalHost = registry_getvaldata('HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters','PhysicalHostNameFullyQualified')
33+
if physicalHost
34+
vm=true
35+
report_note(
36+
:host => session,
37+
:type => 'host.physicalHost',
38+
:data => { :physicalHost => physicalHost },
39+
:update => :unique_data
40+
)
3641
end
42+
3743
if not vm
38-
if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System','SystemBiosVersion') =~ /vrtual/i
44+
sfmsvals = registry_enumkeys('HKLM\SOFTWARE\Microsoft')
45+
if sfmsvals and sfmsvals.include?("Hyper-V")
46+
vm = true
47+
elsif sfmsvals and sfmsvals.include?("VirtualMachine")
48+
vm = true
49+
elsif registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System','SystemBiosVersion') =~ /vrtual/i
3950
vm = true
4051
end
4152
end
53+
4254
if not vm
4355
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\FADT')
4456
if srvvals and srvvals.include?("VRTUAL")
4557
vm = true
58+
else
59+
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\RSDT')
60+
if srvvals and srvvals.include?("VRTUAL")
61+
vm = true
62+
end
4663
end
4764
end
65+
4866
if not vm
49-
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\RSDT')
50-
if srvvals and srvvals.include?("VRTUAL")
67+
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
68+
if srvvals and srvvals.include?("vmicexchange")
5169
vm = true
70+
else
71+
key_path = 'HKLM\HARDWARE\DESCRIPTION\System'
72+
systemBiosVersion = registry_getvaldata(key_path,'SystemBiosVersion')
73+
if systemBiosVersion.unpack("s<*").reduce('', :<<).include? "Hyper-V"
74+
vm = true
75+
end
5276
end
5377
end
78+
5479
if not vm
55-
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
56-
if srvvals and srvvals.include?("vmicheartbeat")
57-
vm = true
58-
elsif srvvals and srvvals.include?("vmicvss")
59-
vm = true
60-
elsif srvvals and srvvals.include?("vmicshutdown")
61-
vm = true
62-
elsif srvvals and srvvals.include?("vmicexchange")
80+
key_path = 'HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0'
81+
if registry_getvaldata(key_path,'Identifier') =~ /Msft Virtual Disk 1.0/i
6382
vm = true
6483
end
6584
end
85+
6686
if vm
6787
report_note(
6888
:host => session,
6989
:type => 'host.hypervisor',
7090
:data => { :hypervisor => "MS Hyper-V" },
7191
:update => :unique_data
7292
)
73-
print_good("This is a Hyper-V Virtual Machine")
93+
if physicalHost
94+
print_good("This is a Hyper-V Virtual Machine running on physical host #{physicalHost}")
95+
else
96+
print_good("This is a Hyper-V Virtual Machine")
97+
end
7498
return "MS Hyper-V"
7599
end
76100
end

0 commit comments

Comments
 (0)