2009-10-26 15:12:05 +00:00
|
|
|
# $Id$
|
2011-10-23 11:56:13 +00:00
|
|
|
# $Revision$
|
2009-10-25 17:56:01 +00:00
|
|
|
# Meterpreter script for detecting if target host is a Virtual Machine
|
|
|
|
# Provided by Carlos Perez at carlos_perez[at]darkoperator.com
|
|
|
|
# Version: 0.2.0
|
2009-05-15 04:24:20 +00:00
|
|
|
session = client
|
2009-10-25 17:56:01 +00:00
|
|
|
|
2009-10-25 18:53:43 +00:00
|
|
|
@@exec_opts = Rex::Parser::Arguments.new(
|
|
|
|
"-h" => [ false,"Help menu." ]
|
|
|
|
)
|
|
|
|
|
|
|
|
@@exec_opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
print_line("CheckVM -- Check various attributes on the target for evidence that it is a virtual machine")
|
|
|
|
print_line("USAGE: run checkvm")
|
2009-11-04 16:35:51 +00:00
|
|
|
print_line(@@exec_opts.usage)
|
2009-10-25 20:57:23 +00:00
|
|
|
raise Rex::Script::Completed
|
2009-10-25 18:53:43 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2009-10-25 17:56:01 +00:00
|
|
|
# Function for detecting if it is a Hyper-V VM
|
2009-07-23 03:41:27 +00:00
|
|
|
def hypervchk(session)
|
2011-10-23 11:56:13 +00:00
|
|
|
begin
|
|
|
|
vm = false
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft', KEY_READ)
|
|
|
|
sfmsvals = key.enum_key
|
|
|
|
if sfmsvals.include?("Hyper-V")
|
2009-07-23 03:41:27 +00:00
|
|
|
print_status("This is a Hyper-V Virtual Machine")
|
2009-10-25 17:56:01 +00:00
|
|
|
vm = true
|
2011-10-23 11:56:13 +00:00
|
|
|
elsif sfmsvals.include?("VirtualMachine")
|
2009-07-23 03:41:27 +00:00
|
|
|
print_status("This is a Hyper-V Virtual Machine")
|
2009-10-25 17:56:01 +00:00
|
|
|
vm = true
|
2009-07-23 03:41:27 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
key.close
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SYSTEM\ControlSet001\Services', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("vmicheartbeat")
|
|
|
|
print_status("This is a Hyper-V Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("vmicvss")
|
|
|
|
print_status("This is a Hyper-V Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("vmicshutdown")
|
|
|
|
print_status("This is a Hyper-V Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("vmicexchange")
|
|
|
|
print_status("This is a Hyper-V Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
rescue
|
|
|
|
end
|
2010-05-03 17:13:09 +00:00
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
return vm
|
|
|
|
end
|
2009-10-25 17:56:01 +00:00
|
|
|
|
|
|
|
# Function for checking if it is a VMware VM
|
2009-07-23 03:41:27 +00:00
|
|
|
def vmwarechk(session)
|
|
|
|
vm = false
|
2009-05-15 04:24:20 +00:00
|
|
|
begin
|
2009-07-23 03:41:27 +00:00
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SYSTEM\ControlSet001\Services', KEY_READ)
|
2009-10-25 17:56:01 +00:00
|
|
|
srvvals = key.enum_key
|
2010-04-24 14:20:42 +00:00
|
|
|
if srvvals.include?("vmdebug")
|
2009-10-25 17:56:01 +00:00
|
|
|
print_status("This is a VMware Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("vmmouse")
|
|
|
|
print_status("This is a VMware Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("VMTools")
|
|
|
|
print_status("This is a VMware Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("VMMEMCTL")
|
|
|
|
print_status("This is a VMware Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
key.close
|
2009-05-15 04:24:20 +00:00
|
|
|
rescue
|
|
|
|
end
|
2009-10-25 17:56:01 +00:00
|
|
|
if not vm
|
2009-05-15 04:24:20 +00:00
|
|
|
begin
|
2011-10-23 11:56:13 +00:00
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0')
|
|
|
|
if key.query_value('Identifier').data.downcase =~ /vmware/
|
|
|
|
print_status("This is a VMware Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
rescue
|
|
|
|
end
|
2009-10-25 17:56:01 +00:00
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
if not vm
|
|
|
|
vmwareprocs = [
|
|
|
|
"vmwareuser.exe",
|
|
|
|
"vmwaretray.exe"
|
|
|
|
]
|
|
|
|
vmwareprocs.each do |p|
|
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
if p == (x['name'].downcase)
|
|
|
|
print_status("This is a VMware Virtual Machine") if not vm
|
2010-05-03 17:13:09 +00:00
|
|
|
vm = true
|
2009-07-23 03:41:27 +00:00
|
|
|
end
|
2009-05-15 04:24:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-10-25 17:56:01 +00:00
|
|
|
key.close
|
|
|
|
return vm
|
2009-07-23 03:41:27 +00:00
|
|
|
|
2009-05-15 04:24:20 +00:00
|
|
|
end
|
2009-10-25 17:56:01 +00:00
|
|
|
# Function for checking if it is a Virtual PC VM
|
2009-07-23 03:41:27 +00:00
|
|
|
def checkvrtlpc(session)
|
|
|
|
vm = false
|
|
|
|
vpcprocs = [
|
2009-10-25 17:56:01 +00:00
|
|
|
"vmusrvc.exe",
|
|
|
|
"vmsrvc.exe"
|
|
|
|
]
|
|
|
|
vpcprocs.each do |p|
|
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
if p == (x['name'].downcase)
|
|
|
|
print_status("This is a VirtualPC Virtual Machine") if not vm
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
if not vm
|
|
|
|
begin
|
2009-10-25 17:56:01 +00:00
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SYSTEM\ControlSet001\Services', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("vpcbus")
|
|
|
|
print_status("This is a VirtualPC Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("vpc-s3")
|
|
|
|
print_status("This is a VirtualPC Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("vpcuhub")
|
|
|
|
print_status("This is a VirtualPC Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("msvmmouf")
|
|
|
|
print_status("This is a VirtualPC Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
key.close
|
|
|
|
rescue
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
end
|
|
|
|
return vm
|
|
|
|
end
|
|
|
|
|
|
|
|
def vboxchk(session)
|
|
|
|
vm = false
|
|
|
|
vboxprocs = [
|
2009-10-25 17:56:01 +00:00
|
|
|
"vboxservice.exe",
|
|
|
|
"vboxtray.exe"
|
|
|
|
]
|
|
|
|
vboxprocs.each do |p|
|
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
if p == (x['name'].downcase)
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine") if not vm
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\ACPI\DSDT', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("VBOX__")
|
2009-10-25 17:56:01 +00:00
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
2009-07-23 03:41:27 +00:00
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
2009-10-25 17:56:01 +00:00
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\ACPI\FADT', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("VBOX__")
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\ACPI\RSDT', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("VBOX__")
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0')
|
|
|
|
if key.query_value('Identifier').data.downcase =~ /vbox/
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\DESCRIPTION\System')
|
|
|
|
if key.query_value('SystemBiosVersion').data.downcase =~ /vbox/
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SYSTEM\ControlSet001\Services', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("VBoxMouse")
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("VBoxGuest")
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("VBoxService")
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("VBoxSF")
|
|
|
|
print_status("This is a Sun VirtualBox Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
key.close
|
|
|
|
rescue
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
end
|
|
|
|
return vm
|
|
|
|
end
|
|
|
|
|
|
|
|
def xenchk(session)
|
2009-10-25 17:56:01 +00:00
|
|
|
vm = false
|
|
|
|
xenprocs = [
|
|
|
|
"xenservice.exe"
|
|
|
|
]
|
|
|
|
xenprocs.each do |p|
|
|
|
|
session.sys.process.get_processes().each do |x|
|
|
|
|
if p == (x['name'].downcase)
|
|
|
|
print_status("This is a Xen Virtual Machine") if not vm
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\ACPI\DSDT', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("Xen")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\ACPI\FADT', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("Xen")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\ACPI\RSDT', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("Xen")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
if not vm
|
|
|
|
begin
|
2009-10-25 17:56:01 +00:00
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SYSTEM\ControlSet001\Services', KEY_READ)
|
|
|
|
srvvals = key.enum_key
|
|
|
|
if srvvals.include?("xenevtchn")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("xennet")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("xennet6")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("xensvc")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
elsif srvvals.include?("xenvdb")
|
|
|
|
print_status("This is a Xen Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
key.close
|
|
|
|
rescue
|
|
|
|
end
|
2009-07-23 03:41:27 +00:00
|
|
|
end
|
|
|
|
return vm
|
|
|
|
end
|
2011-04-02 13:03:43 +00:00
|
|
|
|
|
|
|
def qemuchk(session)
|
|
|
|
vm = false
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0')
|
|
|
|
if key.query_value('Identifier').data.downcase =~ /qemu/
|
|
|
|
print_status("This is a QEMU/KVM Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not vm
|
|
|
|
begin
|
|
|
|
key = session.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'HARDWARE\DESCRIPTION\System\CentralProcessor\0')
|
|
|
|
if key.query_value('ProcessorNameString').data.downcase =~ /qemu/
|
|
|
|
print_status("This is a QEMU/KVM Virtual Machine")
|
|
|
|
vm = true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return vm
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-09-06 20:12:34 +00:00
|
|
|
if client.platform =~ /win32|win64/
|
|
|
|
print_status("Checking if target is a Virtual Machine .....")
|
|
|
|
found = hypervchk(session)
|
|
|
|
found = vmwarechk(session) if not found
|
|
|
|
found = checkvrtlpc(session) if not found
|
|
|
|
found = vboxchk(session) if not found
|
|
|
|
found = xenchk(session) if not found
|
2011-04-02 13:03:43 +00:00
|
|
|
found = qemuchk(session) if not found
|
2010-09-06 20:12:34 +00:00
|
|
|
print_status("It appears to be physical host.") if not found
|
|
|
|
else
|
|
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|