2011-01-12 18:29:56 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2011-01-12 02:16:06 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-01-12 18:29:56 +00:00
|
|
|
##
|
2011-01-12 02:16:06 +00:00
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/core/post/windows/registry'
|
2012-01-30 06:44:45 +00:00
|
|
|
require 'msf/core/post/common'
|
2012-12-22 14:27:54 +00:00
|
|
|
require 'msf/core/auxiliary/report'
|
2011-01-12 02:16:06 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2011-06-21 00:38:04 +00:00
|
|
|
include Msf::Post::Windows::Registry
|
2012-01-30 06:44:45 +00:00
|
|
|
include Msf::Post::Common
|
2012-12-22 14:27:54 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2011-01-12 02:16:06 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2012-12-22 19:10:44 +00:00
|
|
|
'Name' => 'Windows Gather Virtual Environment Detection',
|
|
|
|
'Description' => %q{
|
|
|
|
This module attempts to determine whether the system is running
|
|
|
|
inside of a virtual environment and if so, which one. This
|
|
|
|
module supports detectoin of Hyper-V, VMWare, Virtual PC,
|
|
|
|
VirtualBox, Xen, and QEMU.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
'Platform' => [ 'win' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Method for detecting if it is a Hyper-V VM
|
|
|
|
def hypervchk(session)
|
2012-12-22 19:10:44 +00:00
|
|
|
vm = false
|
|
|
|
sfmsvals = registry_enumkeys('HKLM\SOFTWARE\Microsoft')
|
|
|
|
if sfmsvals and sfmsvals.include?("Hyper-V")
|
|
|
|
vm = true
|
|
|
|
elsif sfmsvals and sfmsvals.include?("VirtualMachine")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
2012-12-22 02:11:57 +00:00
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System','SystemBiosVersion') =~ /vrtual/i
|
|
|
|
vm = true
|
2012-12-22 02:11:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\FADT')
|
|
|
|
if srvvals and srvvals.include?("VRTUAL")
|
|
|
|
vm = true
|
2012-12-22 02:11:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\RSDT')
|
|
|
|
if srvvals and srvvals.include?("VRTUAL")
|
|
|
|
vm = true
|
2012-12-22 02:11:57 +00:00
|
|
|
end
|
|
|
|
end
|
2011-01-12 02:16:06 +00:00
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
|
|
|
|
if srvvals and srvvals.include?("vmicheartbeat")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("vmicvss")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("vmicshutdown")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("vmicexchange")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-26 19:02:39 +00:00
|
|
|
if vm
|
2012-12-22 14:27:54 +00:00
|
|
|
report_note(
|
2012-12-22 14:42:43 +00:00
|
|
|
:host => session,
|
|
|
|
:type => 'host.hypervisor',
|
|
|
|
:data => { :hypervisor => "MS Hyper-V" },
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2012-01-26 19:02:39 +00:00
|
|
|
print_status("This is a Hyper-V Virtual Machine")
|
|
|
|
return "MS Hyper-V"
|
|
|
|
end
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Method for checking if it is a VMware VM
|
|
|
|
def vmwarechk(session)
|
|
|
|
vm = false
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
|
|
|
|
if srvvals and srvvals.include?("vmdebug")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("vmmouse")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("VMTools")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("VMMEMCTL")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System\BIOS','SystemManufacturer') =~ /vmware/i
|
|
|
|
vm = true
|
2012-12-22 02:11:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
key_path = 'HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0'
|
|
|
|
if registry_getvaldata(key_path,'Identifier') =~ /vmware/i
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
vmwareprocs = [
|
|
|
|
"vmwareuser.exe",
|
|
|
|
"vmwaretray.exe"
|
|
|
|
]
|
2011-01-29 01:55:47 +00:00
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
vmwareprocs.each do |p|
|
2011-01-12 02:16:06 +00:00
|
|
|
if p == (x['name'].downcase)
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-22 02:11:57 +00:00
|
|
|
|
2012-01-26 19:02:39 +00:00
|
|
|
if vm
|
2012-12-22 14:27:54 +00:00
|
|
|
report_note(
|
2012-12-22 14:42:43 +00:00
|
|
|
:host => session,
|
|
|
|
:type => 'host.hypervisor',
|
|
|
|
:data => { :hypervisor => "VMware" },
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2012-01-26 19:02:39 +00:00
|
|
|
print_status("This is a VMware Virtual Machine")
|
|
|
|
return "VMWare"
|
|
|
|
end
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Method for checking if it is a Virtual PC VM
|
|
|
|
def checkvrtlpc(session)
|
|
|
|
vm = false
|
|
|
|
vpcprocs = [
|
|
|
|
"vmusrvc.exe",
|
|
|
|
"vmsrvc.exe"
|
|
|
|
]
|
2011-01-29 01:55:47 +00:00
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
vpcprocs.each do |p|
|
2011-01-12 02:16:06 +00:00
|
|
|
if p == (x['name'].downcase)
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
|
|
|
|
if srvvals and srvvals.include?("vpc-s3")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("vpcuhub")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("msvmmouf")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-26 19:02:39 +00:00
|
|
|
if vm
|
2012-12-22 14:27:54 +00:00
|
|
|
report_note(
|
2012-12-22 14:42:43 +00:00
|
|
|
:host => session,
|
|
|
|
:type => 'host.hypervisor',
|
|
|
|
:data => { :hypervisor => "VirtualPC" },
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2012-01-26 19:02:39 +00:00
|
|
|
print_status("This is a VirtualPC Virtual Machine")
|
|
|
|
return "VirtualPC"
|
|
|
|
end
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Method for checking if it is a VirtualBox VM
|
|
|
|
def vboxchk(session)
|
|
|
|
vm = false
|
|
|
|
vboxprocs = [
|
|
|
|
"vboxservice.exe",
|
|
|
|
"vboxtray.exe"
|
|
|
|
]
|
2011-01-29 01:55:47 +00:00
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
vboxprocs.each do |p|
|
2011-01-12 02:16:06 +00:00
|
|
|
if p == (x['name'].downcase)
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\DSDT')
|
|
|
|
if srvvals and srvvals.include?("VBOX__")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\FADT')
|
|
|
|
if srvvals and srvvals.include?("VBOX__")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\RSDT')
|
|
|
|
if srvvals and srvvals.include?("VBOX__")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
key_path = 'HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0'
|
|
|
|
if registry_getvaldata(key_path,'Identifier') =~ /vbox/i
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
if registry_getvaldata('HKLM\HARDWARE\DESCRIPTION\System','SystemBiosVersion') =~ /vbox/i
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
|
|
|
|
if srvvals and srvvals.include?("VBoxMouse")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("VBoxGuest")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("VBoxService")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("VBoxSF")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-26 19:02:39 +00:00
|
|
|
if vm
|
2012-12-22 14:27:54 +00:00
|
|
|
report_note(
|
2012-12-22 14:42:43 +00:00
|
|
|
:host => session,
|
|
|
|
:type => 'host.hypervisor',
|
|
|
|
:data => { :hypervisor => "VirtualBox" },
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2012-06-06 05:36:17 +00:00
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
2012-01-26 19:02:39 +00:00
|
|
|
return "VirtualBox"
|
|
|
|
end
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Method for checking if it is a Xen VM
|
|
|
|
def xenchk(session)
|
|
|
|
vm = false
|
|
|
|
xenprocs = [
|
|
|
|
"xenservice.exe"
|
|
|
|
]
|
2011-01-29 01:55:47 +00:00
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
xenprocs.each do |p|
|
2011-01-12 02:16:06 +00:00
|
|
|
if p == (x['name'].downcase)
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\DSDT')
|
|
|
|
if srvvals and srvvals.include?("Xen")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HARDWARE\ACPI\FADT')
|
|
|
|
if srvvals and srvvals.include?("Xen")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\HARDWARE\ACPI\RSDT')
|
|
|
|
if srvvals and srvvals.include?("Xen")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
srvvals = registry_enumkeys('HKLM\SYSTEM\ControlSet001\Services')
|
|
|
|
if srvvals and srvvals.include?("xenevtchn")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("xennet")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("xennet6")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("xensvc")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals and srvvals.include?("xenvdb")
|
|
|
|
vm = true
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-26 19:02:39 +00:00
|
|
|
if vm
|
2012-12-22 14:27:54 +00:00
|
|
|
report_note(
|
2012-12-22 14:42:43 +00:00
|
|
|
:host => session,
|
|
|
|
:type => 'host.hypervisor',
|
|
|
|
:data => { :hypervisor => "Xen" },
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2012-01-26 19:02:39 +00:00
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
return "Xen"
|
|
|
|
end
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
|
|
|
|
2011-04-02 13:03:43 +00:00
|
|
|
def qemuchk(session)
|
|
|
|
vm = false
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
key_path = 'HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0'
|
|
|
|
if registry_getvaldata(key_path,'Identifier') =~ /qemu/i
|
|
|
|
print_status("This is a QEMU/KVM Virtual Machine")
|
|
|
|
vm = true
|
2011-04-02 13:03:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2012-12-22 19:10:44 +00:00
|
|
|
key_path = 'HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0'
|
|
|
|
if registry_getvaldata(key_path,'ProcessorNameString') =~ /qemu/i
|
|
|
|
print_status("This is a QEMU/KVM Virtual Machine")
|
|
|
|
vm = true
|
2011-04-02 13:03:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-26 19:02:39 +00:00
|
|
|
if vm
|
2012-12-22 14:27:54 +00:00
|
|
|
report_note(
|
2012-12-22 14:42:43 +00:00
|
|
|
:host => session,
|
|
|
|
:type => 'host.hypervisor',
|
|
|
|
:data => { :hypervisor => "Qemu/KVM" },
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2012-01-26 19:02:39 +00:00
|
|
|
return "Qemu/KVM"
|
|
|
|
end
|
2011-04-02 13:03:43 +00:00
|
|
|
end
|
|
|
|
|
2011-01-12 02:16:06 +00:00
|
|
|
# run Method
|
|
|
|
def run
|
|
|
|
print_status("Checking if #{sysinfo['Computer']} is a Virtual Machine .....")
|
|
|
|
found = hypervchk(session)
|
2012-01-26 19:02:39 +00:00
|
|
|
found ||= vmwarechk(session)
|
|
|
|
found ||= checkvrtlpc(session)
|
|
|
|
found ||= vboxchk(session)
|
|
|
|
found ||= xenchk(session)
|
|
|
|
found ||= qemuchk(session)
|
|
|
|
if found
|
|
|
|
report_vm(found)
|
|
|
|
else
|
|
|
|
print_status("#{sysinfo['Computer']} appears to be a Physical Machine")
|
|
|
|
end
|
2011-01-12 02:16:06 +00:00
|
|
|
end
|
2012-01-26 19:02:39 +00:00
|
|
|
|
2011-01-12 18:29:56 +00:00
|
|
|
end
|