metasploit-framework/modules/auxiliary/scanner/smb/smb_enumusers_domain.rb

207 lines
5.3 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Auxiliary
2013-08-30 21:28:54 +00:00
# Exploit mixins should be called first
include Msf::Exploit::Remote::SMB::Client
include Msf::Exploit::Remote::SMB::Client::Authenticated
2013-08-30 21:28:54 +00:00
include Msf::Exploit::Remote::DCERPC
# Scanner mixin should be near last
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::Report
def initialize
super(
'Name' => 'SMB Domain User Enumeration',
'Description' => 'Determine what domain users are logged into a remote system via a DCERPC to NetWkstaUserEnum.',
'Author' =>
[
2015-06-13 21:02:43 +00:00
'natron', # original module
'Joshua D. Abraham <jabra[at]praetorian.com>', # database storage
],
2013-08-30 21:28:54 +00:00
'References' =>
[
[ 'URL', 'http://msdn.microsoft.com/en-us/library/aa370669%28VS.85%29.aspx' ]
],
'License' => MSF_LICENSE
)
deregister_options('RPORT', 'RHOST')
end
def parse_value(resp, idx)
#val_length = resp[idx,4].unpack("V")[0]
idx += 4
#val_offset = resp[idx,4].unpack("V")[0]
idx += 4
val_actual = resp[idx,4].unpack("V")[0]
idx += 4
2015-07-20 23:40:48 +00:00
value = resp[idx,val_actual*2]
2013-08-30 21:28:54 +00:00
idx += val_actual * 2
idx += val_actual % 2 * 2 # alignment
return value,idx
end
2015-07-20 23:40:48 +00:00
def parse_net_wksta_enum_users_info(resp)
2013-08-30 21:28:54 +00:00
accounts = [ Hash.new() ]
idx = 20
count = resp[idx,4].unpack("V")[0] # wkssvc_NetWkstaEnumUsersInfo -> Info -> PtrCt0 -> User() -> Ptr -> Max Count
idx += 4
1.upto(count) do
# wkssvc_NetWkstaEnumUsersInfo -> Info -> PtrCt0 -> User() -> Ptr -> Ref ID
idx += 4 # ref id name
idx += 4 # ref id logon domain
idx += 4 # ref id other domains
idx += 4 # ref id logon server
end
1.upto(count) do
# wkssvc_NetWkstaEnumUsersInfo -> Info -> PtrCt0 -> User() -> Ptr -> ID1 max count
2015-07-20 23:40:48 +00:00
account_name,idx = parse_value(resp, idx)
logon_domain,idx = parse_value(resp, idx)
other_domains,idx = parse_value(resp, idx)
logon_server,idx = parse_value(resp, idx)
2013-08-30 21:28:54 +00:00
accounts << {
:account_name => account_name,
:logon_domain => logon_domain,
:other_domains => other_domains,
:logon_server => logon_server
}
end
accounts
end
2014-08-07 22:59:40 +00:00
def rport
@rport || datastore['RPORT']
end
2014-08-07 23:47:33 +00:00
def smb_direct
2014-08-07 22:59:40 +00:00
@smbdirect || datastore['SMBDirect']
end
2015-07-20 23:40:48 +00:00
def store_username(username, res, ip, rport)
service_data = {
address: ip,
port: rport,
service_name: 'smb',
protocol: 'tcp',
workspace_id: myworkspace_id,
proof: res
}
credential_data = {
origin_type: :service,
module_fullname: fullname,
username: username
}
credential_data.merge!(service_data)
credential_core = create_credential(credential_data)
login_data = {
core: credential_core,
status: Metasploit::Model::Login::Status::UNTRIED
}
login_data.merge!(service_data)
create_credential_login(login_data)
end
2013-08-30 21:28:54 +00:00
def run_host(ip)
[[139, false], [445, true]].each do |info|
2014-08-07 22:59:40 +00:00
@rport = info[0]
@smbdirect = info[1]
2013-08-30 21:28:54 +00:00
begin
connect()
smb_login()
uuid = [ '6bffd098-a112-3610-9833-46c3f87e345a', '1.0' ]
handle = dcerpc_handle(
uuid[0], uuid[1], 'ncacn_np', ["\\wkssvc"]
)
begin
dcerpc_bind(handle)
stub =
2015-07-20 23:40:48 +00:00
NDR.uwstring("\\\\" + ip) + # Server Name
NDR.long(1) + # Level
NDR.long(1) + # Ctr
NDR.long(rand(0xffffffff)) + # ref id
NDR.long(0) + # entries read
NDR.long(0) + # null ptr to user0
2013-08-30 21:28:54 +00:00
2015-07-20 23:40:48 +00:00
NDR.long(0xffffffff) + # Prefmaxlen
NDR.long(rand(0xffffffff)) + # ref id
NDR.long(0) # null ptr to resume handle
2013-08-30 21:28:54 +00:00
dcerpc.call(2,stub)
resp = dcerpc.last_response ? dcerpc.last_response.stub_data : nil
2015-07-20 23:40:48 +00:00
accounts = parse_net_wksta_enum_users_info(resp)
2013-08-30 21:28:54 +00:00
accounts.shift
if datastore['VERBOSE']
accounts.each do |x|
print_status x[:logon_domain] + "\\" + x[:account_name] +
2013-08-30 21:28:54 +00:00
"\t(logon_server: #{x[:logon_server]}, other_domains: #{x[:other_domains]})"
end
else
print_status "#{accounts.collect{|x| x[:logon_domain] + "\\" + x[:account_name]}.join(", ")}"
2013-08-30 21:28:54 +00:00
end
found_accounts = []
accounts.each do |x|
comp_user = x[:logon_domain] + "\\" + x[:account_name]
found_accounts.push(comp_user.scan(/[[:print:]]/).join) unless found_accounts.include?(comp_user.scan(/[[:print:]]/).join)
end
found_accounts.each do |comp_user|
if comp_user.to_s =~ /\$$/
next
end
print_good("Found user: #{comp_user}")
2015-07-20 23:40:48 +00:00
store_username(comp_user, resp, ip, rport)
end
2013-08-30 21:28:54 +00:00
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
2016-06-08 19:22:36 +00:00
print_error("UUID #{uuid[0]} #{uuid[1]} ERROR 0x%.8x" % e.error_code)
2013-08-30 21:28:54 +00:00
#puts e
#return
rescue ::Exception => e
2016-06-08 19:22:36 +00:00
print_error("UUID #{uuid[0]} #{uuid[1]} ERROR #{$!}")
2013-08-30 21:28:54 +00:00
#puts e
#return
end
disconnect()
return
rescue ::Exception
print_line($!.to_s)
end
end
end
end