@@ -46,7 +46,7 @@ def initialize(info={})
46
46
register_options (
47
47
[
48
48
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 ] ) ,
50
50
OptBool . new ( 'SpiderProfiles' , [ false , 'Spider only user profiles when share = C$' , true ] ) ,
51
51
OptEnum . new ( 'LogSpider' , [ false , '0 = disabled, 1 = CSV, 2 = table (txt), 3 = one liner (txt)' , 3 , [ 0 , 1 , 2 , 3 ] ] ) ,
52
52
OptInt . new ( 'MaxDepth' , [ true , 'Max number of subdirectories to spider' , 999 ] ) ,
@@ -188,7 +188,7 @@ def lanman_netshareenum(ip, rport, info)
188
188
rescue ::Rex ::Proto ::SMB ::Exceptions ::ErrorCode => e
189
189
if e . error_code == 0xC00000BB
190
190
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
192
192
return srvsvc_netshareenum ( ip )
193
193
end
194
194
end
@@ -287,6 +287,8 @@ def get_user_dirs(ip, share, base, sub_dirs)
287
287
288
288
begin
289
289
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?
290
292
files . each do |f |
291
293
if f [ 0 ] != "." and f [ 0 ] != ".."
292
294
usernames . push ( f [ 0 ] )
@@ -299,7 +301,6 @@ def get_user_dirs(ip, share, base, sub_dirs)
299
301
end
300
302
return dirs
301
303
rescue
302
- dirs = nil
303
304
return dirs
304
305
end
305
306
end
@@ -309,7 +310,7 @@ def profile_options(ip, share)
309
310
new_dirs = [ 'Desktop' , 'Documents' , 'Downloads' , 'Music' , 'Pictures' , 'Videos' ]
310
311
311
312
dirs = get_user_dirs ( ip , share , "Documents and Settings" , old_dirs )
312
- if dirs == nil
313
+ if dirs . blank?
313
314
dirs = get_user_dirs ( ip , share , "Users" , new_dirs )
314
315
end
315
316
return dirs
@@ -334,7 +335,7 @@ def get_files_info(ip, rport, shares, info)
334
335
if x == "ADMIN$" or x == "IPC$"
335
336
next
336
337
end
337
- if not datastore [ 'VERBOSE ' ]
338
+ if not datastore [ 'ShowFiles ' ]
338
339
print_status ( "#{ ip } :#{ rport } - Spidering #{ x } ." )
339
340
end
340
341
subdirs = [ "" ]
@@ -403,11 +404,11 @@ def get_files_info(ip, rport, shares, info)
403
404
404
405
end
405
406
end
406
- vprint_good ( pretty_tbl . to_s )
407
+ print_good ( pretty_tbl . to_s ) if datastore [ 'ShowFiles' ]
407
408
end
408
409
subdirs . shift
409
410
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
411
412
end
412
413
unless detailed_tbl . rows . empty?
413
414
if datastore [ 'LogSpider' ] == '1'
@@ -423,12 +424,14 @@ def get_files_info(ip, rport, shares, info)
423
424
end
424
425
end
425
426
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' ]
430
429
end
431
430
431
+ # Overrides the one in smb.rb
432
+ def smb_direct
433
+ @smb_redirect || datastore [ 'SMBDirect' ]
434
+ end
432
435
433
436
def run_host ( ip )
434
437
@rport = datastore [ 'RPORT' ]
@@ -437,13 +440,13 @@ def run_host(ip)
437
440
shares = [ ]
438
441
439
442
[ [ 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 ]
442
445
443
446
begin
444
447
connect
445
448
smb_login
446
- if datastore [ 'USE_SRVSVC_ONLY' ]
449
+ if @srvsvc
447
450
shares = srvsvc_netshareenum ( ip )
448
451
else
449
452
shares = lanman_netshareenum ( ip , rport , info )
@@ -506,3 +509,4 @@ def run_host(ip)
506
509
end
507
510
end
508
511
end
512
+
0 commit comments