Skip to content

Commit f520616

Browse files
committed
This fixes a few things, see commit message for more info
This commit fixes the following: 1. Not handling eval_host()'s nil file return value, which can causes a NoMethodError at runtime due to various conditions. 2. Renames datastore option VERBOSE to ShowFiles to pass msftidy 3. Avoids overwriting datastore options directly to pass msftidy
1 parent da845c7 commit f520616

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

modules/auxiliary/scanner/smb/smb_enumshares.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def initialize(info={})
4646
register_options(
4747
[
4848
OptBool.new('SpiderShares', [false, 'Spider shares recursively', false]),
49-
OptBool.new('VERBOSE', [true, 'Show detailed information when spidering', false]),
49+
OptBool.new('ShowFiles', [true, 'Show detailed information when spidering', false]),
5050
OptBool.new('SpiderProfiles', [false, 'Spider only user profiles when share = C$', true]),
5151
OptEnum.new('LogSpider', [false, '0 = disabled, 1 = CSV, 2 = table (txt), 3 = one liner (txt)', 3, [0,1,2,3]]),
5252
OptInt.new('MaxDepth', [true, 'Max number of subdirectories to spider', 999]),
@@ -188,7 +188,7 @@ def lanman_netshareenum(ip, rport, info)
188188
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
189189
if e.error_code == 0xC00000BB
190190
vprint_error("#{ip}:#{rport} - Got 0xC00000BB while enumerating shares, switching to srvsvc...")
191-
datastore['USE_SRVSVC_ONLY'] = true # Make sure the module is aware of this state
191+
@srvsvc = true # Make sure the module is aware of this state
192192
return srvsvc_netshareenum(ip)
193193
end
194194
end
@@ -287,6 +287,8 @@ def get_user_dirs(ip, share, base, sub_dirs)
287287

288288
begin
289289
read,write,type,files = eval_host(ip, share, base)
290+
# files or type could return nil due to various conditions
291+
return dirs if files.nil?
290292
files.each do |f|
291293
if f[0] != "." and f[0] != ".."
292294
usernames.push(f[0])
@@ -299,7 +301,6 @@ def get_user_dirs(ip, share, base, sub_dirs)
299301
end
300302
return dirs
301303
rescue
302-
dirs = nil
303304
return dirs
304305
end
305306
end
@@ -309,7 +310,7 @@ def profile_options(ip, share)
309310
new_dirs = ['Desktop','Documents','Downloads','Music','Pictures','Videos']
310311

311312
dirs = get_user_dirs(ip, share, "Documents and Settings", old_dirs)
312-
if dirs == nil
313+
if dirs.blank?
313314
dirs = get_user_dirs(ip, share, "Users", new_dirs)
314315
end
315316
return dirs
@@ -334,7 +335,7 @@ def get_files_info(ip, rport, shares, info)
334335
if x == "ADMIN$" or x == "IPC$"
335336
next
336337
end
337-
if not datastore['VERBOSE']
338+
if not datastore['ShowFiles']
338339
print_status("#{ip}:#{rport} - Spidering #{x}.")
339340
end
340341
subdirs = [""]
@@ -403,11 +404,11 @@ def get_files_info(ip, rport, shares, info)
403404

404405
end
405406
end
406-
vprint_good(pretty_tbl.to_s)
407+
print_good(pretty_tbl.to_s) if datastore['ShowFiles']
407408
end
408409
subdirs.shift
409410
end
410-
print_status("#{ip}:#{rport} - Spider #{x} complete.") unless datastore['VERBOSE'] == true
411+
print_status("#{ip}:#{rport} - Spider #{x} complete.") unless datastore['ShowFiles'] == true
411412
end
412413
unless detailed_tbl.rows.empty?
413414
if datastore['LogSpider'] == '1'
@@ -423,12 +424,14 @@ def get_files_info(ip, rport, shares, info)
423424
end
424425
end
425426

426-
def cleanup
427-
datastore['RPORT'] = @rport
428-
datastore['SMBDirect'] = @smb_redirect
429-
datastore['USE_SRVSVC_ONLY'] = @srvsvc
427+
def rport
428+
@rport || datastore['RPORT']
430429
end
431430

431+
# Overrides the one in smb.rb
432+
def smb_direct
433+
@smb_redirect || datastore['SMBDirect']
434+
end
432435

433436
def run_host(ip)
434437
@rport = datastore['RPORT']
@@ -437,13 +440,13 @@ def run_host(ip)
437440
shares = []
438441

439442
[[139, false], [445, true]].each do |info|
440-
datastore['RPORT'] = info[0]
441-
datastore['SMBDirect'] = info[1]
443+
@rport = info[0]
444+
@smb_redirect = info[1]
442445

443446
begin
444447
connect
445448
smb_login
446-
if datastore['USE_SRVSVC_ONLY']
449+
if @srvsvc
447450
shares = srvsvc_netshareenum(ip)
448451
else
449452
shares = lanman_netshareenum(ip, rport, info)
@@ -506,3 +509,4 @@ def run_host(ip)
506509
end
507510
end
508511
end
512+

0 commit comments

Comments
 (0)