Skip to content

Commit d81d50b

Browse files
committed
Land rapid7#9430, Improve Hyper-V checkvm checks
2 parents fdefa4b + 9328374 commit d81d50b

File tree

2 files changed

+92
-18
lines changed

2 files changed

+92
-18
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
This is a post-exploitation module that checks several known registry keys and process names, as a simple way to determine if your target is running inside of a virtual machine. While many of these are easy to change, triggering a false negative, this script services as a simple pre-check.
2+
3+
The script has been tested on a variety of Windows 10 targets, but changes to hypervisors and VM-related drivers are common. If you identify misleading output from this tool, please [file an issue](https://github.com/rapid7/metasploit-framework/issues/new) or, even better, [submit a pull request](https://github.com/rapid7/metasploit-framework/blob/master/CONTRIBUTING.md#contributing-to-metasploit).
4+
5+
The script can be run from within a Meterpreter session or from the Metasploit shell:
6+
7+
### Within Meterpreter
8+
```
9+
meterpreter > run post/windows/gather/checkvm
10+
```
11+
12+
### From the Metasploit console
13+
```
14+
msf > use post/windows/gather/checkvm
15+
msf post(windows/gather/checkvm) > set SESSION 1
16+
SESSION => 1
17+
msf post(windows/gather/checkvm) > run
18+
19+
[*] Checking if DESKTOP-Q05UKIU is a Virtual Machine .....
20+
[+] This is a VMware Virtual Machine
21+
[*] Post module execution completed
22+
```
23+
24+
# Example Output
25+
26+
### On a Windows 10 x64 physical machine
27+
```
28+
[*] Checking if DESKTOP-Q05UKIU is a Virtual Machine .....
29+
[*] DESKTOP-Q05UKIU appears to be a Physical Machine
30+
```
31+
32+
### On a Windows 10 x64 VMware VM
33+
```
34+
[*] Checking if DESKTOP-Q05UKIU is a Virtual Machine .....
35+
[+] This is a VMware Virtual Machine
36+
```
37+
38+
### On a Windows 10 x64 Hyper-V VM
39+
```
40+
[*] Checking if DESKTOP-Q05UKIU is a Virtual Machine .....
41+
[+] This is a Hyper-V Virtual Machine running on physical host ASOTO-HYPERV-SERVER
42+
43+
msf > notes
44+
45+
[*] Time: 2018-01-17 18:31:24 UTC Note: host=192.168.77.2 type=host.hypervisor data={:hypervisor=>"MS Hyper-V"}
46+
[*] Time: 2018-01-17 18:31:24 UTC Note: host=192.168.77.2 type=host.physicalHost data={:hypervisor=>"ASOTO-HYPERV-SERVER"}
47+
```

modules/post/windows/gather/checkvm.rb

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ module supports detection of Hyper-V, VMWare, Virtual PC,
1919
VirtualBox, Xen, and QEMU.
2020
},
2121
'License' => MSF_LICENSE,
22-
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
22+
'Author' => [
23+
'Carlos Perez <carlos_perez[at]darkoperator.com>',
24+
'Aaron Soto <aaron_soto[at]rapid7.com>'
25+
],
2326
'Platform' => [ 'win' ],
2427
'SessionTypes' => [ 'meterpreter' ]
2528
))
@@ -28,49 +31,73 @@ module supports detection of Hyper-V, VMWare, Virtual PC,
2831
# Method for detecting if it is a Hyper-V VM
2932
def hypervchk(session)
3033
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
34+
35+
physicalHost = registry_getvaldata('HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters','PhysicalHostNameFullyQualified')
36+
if physicalHost
37+
vm=true
38+
report_note(
39+
:host => session,
40+
:type => 'host.physicalHost',
41+
:data => { :physicalHost => physicalHost },
42+
:update => :unique_data
43+
)
3644
end
45+
3746
if not vm
38-
if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System','SystemBiosVersion') =~ /vrtual/i
47+
sfmsvals = registry_enumkeys('HKLM\SOFTWARE\Microsoft')
48+
if sfmsvals and sfmsvals.include?("Hyper-V")
49+
vm = true
50+
elsif sfmsvals and sfmsvals.include?("VirtualMachine")
51+
vm = true
52+
elsif registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System','SystemBiosVersion') =~ /vrtual/i
3953
vm = true
4054
end
4155
end
56+
4257
if not vm
4358
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\FADT')
4459
if srvvals and srvvals.include?("VRTUAL")
4560
vm = true
61+
else
62+
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\RSDT')
63+
if srvvals and srvvals.include?("VRTUAL")
64+
vm = true
65+
end
4666
end
4767
end
68+
4869
if not vm
49-
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\RSDT')
50-
if srvvals and srvvals.include?("VRTUAL")
70+
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
71+
if srvvals and srvvals.include?("vmicexchange")
5172
vm = true
73+
else
74+
key_path = 'HKLM\HARDWARE\DESCRIPTION\System'
75+
systemBiosVersion = registry_getvaldata(key_path,'SystemBiosVersion')
76+
if systemBiosVersion.unpack("s<*").reduce('', :<<).include? "Hyper-V"
77+
vm = true
78+
end
5279
end
5380
end
81+
5482
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")
83+
key_path = 'HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0'
84+
if registry_getvaldata(key_path,'Identifier') =~ /Msft Virtual Disk 1.0/i
6385
vm = true
6486
end
6587
end
88+
6689
if vm
6790
report_note(
6891
:host => session,
6992
:type => 'host.hypervisor',
7093
:data => { :hypervisor => "MS Hyper-V" },
7194
:update => :unique_data
7295
)
73-
print_good("This is a Hyper-V Virtual Machine")
96+
if physicalHost
97+
print_good("This is a Hyper-V Virtual Machine running on physical host #{physicalHost}")
98+
else
99+
print_good("This is a Hyper-V Virtual Machine")
100+
end
74101
return "MS Hyper-V"
75102
end
76103
end

0 commit comments

Comments
 (0)