Skip to content

Commit 68d8afc

Browse files
committed
Land rapid7#3604, @hmoore-r7's [FixRM rapid7#8838] smb_lookupsid nil class dereference
2 parents 159ce3f + 3bc8d1f commit 68d8afc

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

modules/auxiliary/scanner/smb/smb_lookupsid.rb

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ class Metasploit3 < Msf::Auxiliary
2121

2222
def initialize
2323
super(
24-
'Name' => 'SMB Local User Enumeration (LookupSid)',
24+
'Name' => 'SMB SID User Enumeration (LookupSid)',
2525
'Description' => 'Determine what users exist via brute force SID lookups.
2626
This module can enumerate both local and domain accounts by setting
2727
ACTION to either LOCAL or DOMAIN',
2828
'Author' => 'hdm',
2929
'License' => MSF_LICENSE,
3030
'DefaultOptions' =>
3131
{
32+
# Samba doesn't like this option, so we disable so we are compatible with
33+
# both Windows and Samba for enumeration.
3234
'DCERPC::fake_bind_multi' => false
3335
},
3436
'Actions' =>
@@ -49,6 +51,10 @@ def initialize
4951
deregister_options('RPORT', 'RHOST')
5052
end
5153

54+
# Constants used by this module
55+
LSA_UUID = '12345778-1234-abcd-ef00-0123456789ab'
56+
LSA_VERS = '0.0'
57+
LSA_PIPES = %W{ LSARPC NETLOGON SAMR BROWSER SRVSVC }
5258

5359
# Locate an available SMB PIPE for the specified service
5460
def smb_find_dcerpc_pipe(uuid, vers, pipes)
@@ -128,11 +134,6 @@ def smb_parse_sid_lookup(data)
128134
[ uinfo[3], name ]
129135
end
130136

131-
132-
@@lsa_uuid = '12345778-1234-abcd-ef00-0123456789ab'
133-
@@lsa_vers = '0.0'
134-
@@lsa_pipes = %W{ LSARPC NETLOGON SAMR BROWSER SRVSVC }
135-
136137
# Fingerprint a single host
137138
def run_host(ip)
138139

@@ -145,7 +146,7 @@ def run_host(ip)
145146
lsa_handle = nil
146147
begin
147148
# find the lsarpc pipe
148-
lsa_pipe = smb_find_dcerpc_pipe(@@lsa_uuid, @@lsa_vers, @@lsa_pipes)
149+
lsa_pipe = smb_find_dcerpc_pipe(LSA_UUID, LSA_VERS, LSA_PIPES)
149150
break if not lsa_pipe
150151

151152
# OpenPolicy2()
@@ -201,20 +202,27 @@ def run_host(ip)
201202
resp = dcerpc.last_response ? dcerpc.last_response.stub_data : nil
202203
domain_sid, domain_name = smb_parse_sid(resp)
203204

204-
205205
# Store SID, local domain name, joined domain name
206206
print_status("#{ip} PIPE(#{lsa_pipe}) LOCAL(#{host_name} - #{host_sid}) DOMAIN(#{domain_name} - #{domain_sid})")
207207

208-
209208
domain = {
210209
:name => host_name,
211210
:txt_sid => host_sid,
212211
:users => {},
213212
:groups => {}
214213
}
215214

216-
target_sid = host_sid if action.name =~ /LOCAL/i
217-
target_sid = domain_sid if action.name =~ /DOMAIN/i
215+
target_sid = case action.name.upcase
216+
when 'LOCAL'
217+
host_sid
218+
when 'DOMAIN'
219+
# Fallthrough to the host SID if no domain SID was returned
220+
unless domain_sid
221+
print_error("#{ip} No domain SID identified, falling back to the local SID...")
222+
end
223+
domain_sid || host_sid
224+
end
225+
218226
# Brute force through a common RID range
219227
500.upto(datastore['MaxRID'].to_i) do |rid|
220228

@@ -269,10 +277,9 @@ def run_host(ip)
269277
)
270278

271279
print_status("#{ip} #{domain[:name].upcase} [#{domain[:users].keys.map{|k| domain[:users][k]}.join(", ")} ]")
272-
273-
# cleanup
274280
disconnect
275281
return
282+
276283
rescue ::Timeout::Error
277284
rescue ::Interrupt
278285
raise $!

0 commit comments

Comments
 (0)