@@ -24,13 +24,20 @@ def initialize
2424 'License' => MSF_LICENSE ,
2525 )
2626
27- deregister_options ( 'RPORT' )
2827 register_options (
2928 [
3029 OptString . new ( 'SMBPIPE' , [ true , "The pipe name to use (BROWSER)" , 'BROWSER' ] ) ,
3130 ] )
3231 end
3332
33+ def connect ( *args , **kwargs )
34+ super ( *args , **kwargs , direct : @smb_direct )
35+ end
36+
37+ def rport
38+ @rport
39+ end
40+
3441 @@target_uuids = [
3542 [ '00000131-0000-0000-c000-000000000046' , '0.0' ] ,
3643 [ '00000134-0000-0000-c000-000000000046' , '0.0' ] ,
@@ -253,59 +260,69 @@ def initialize
253260
254261 # Fingerprint a single host
255262 def run_host ( ip )
256- ports = [ 139 , 445 ]
257-
258263 if session
259264 print_status ( "Using existing session #{ session . sid } " )
260265 client = session . client
266+ @rport = datastore [ 'RPORT' ] = session . port
261267 self . simple = ::Rex ::Proto ::SMB ::SimpleClient . new ( client . dispatcher . tcp_socket , client : client )
262- ports = [ simple . port ]
263268 self . simple . connect ( "\\ \\ #{ simple . address } \\ IPC$" ) # smb_login connects to this share for some reason and it doesn't work unless we do too
264- end
265-
266- ports . each do |port |
267- datastore [ 'RPORT' ] = port
269+ check_uuids ( ip )
270+ else
271+ if datastore [ 'RPORT' ] . blank? || datastore [ 'RPORT' ] == 0
272+ smb_services = [
273+ { port : 445 , direct : true } ,
274+ { port : 139 , direct : false }
275+ ]
276+ else
277+ smb_services = [
278+ { port : datastore [ 'RPORT' ] , direct : datastore [ 'SMBDirect' ] }
279+ ]
280+ end
268281
269- begin
270- unless session
271- connect ( )
272- smb_login ( )
282+ smb_services . each do |smb_service |
283+ @rport = smb_service [ :port ]
284+ @smb_direct = smb_service [ :direct ]
285+
286+ begin
287+ connect
288+ smb_login
289+ check_uuids ( ip )
290+ disconnect
291+ rescue ::Exception
292+ print_line ( $!. to_s )
273293 end
274294
275- @@target_uuids . each do |uuid |
276-
277- handle = dcerpc_handle_target (
278- uuid [ 0 ] , uuid [ 1 ] ,
279- 'ncacn_np' , [ "\\ #{ datastore [ 'SMBPIPE' ] } " ] , self . simple . address
280- )
295+ end
296+ end
281297
282- begin
283- dcerpc_bind ( handle )
284- print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } OPEN VIA #{ datastore [ 'SMBPIPE' ] } " )
285- # Add Report
286- report_note (
287- :host => ip ,
288- :proto => 'tcp' ,
289- :sname => 'smb' ,
290- :port => rport ,
291- :type => "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } " ,
292- :data => "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } OPEN VIA #{ datastore [ 'SMBPIPE' ] } "
293- )
294- rescue ::Rex ::Proto ::SMB ::Exceptions ::ErrorCode => e
295- print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } ERROR 0x%.8x" % e . error_code )
296- rescue StandardError => e
297- print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } ERROR #{ $!} " )
298- end
299- end
298+ end
300299
301- disconnect ( )
300+ def check_uuids ( ip )
301+ @@target_uuids . each do |uuid |
302+
303+ handle = dcerpc_handle_target (
304+ uuid [ 0 ] , uuid [ 1 ] ,
305+ 'ncacn_np' , [ "\\ #{ datastore [ 'SMBPIPE' ] } " ] , self . simple . address
306+ )
302307
303- return
304- rescue ::Exception
305- print_line ( $!. to_s )
308+ begin
309+ dcerpc_bind ( handle )
310+ print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } OPEN VIA #{ datastore [ 'SMBPIPE' ] } " )
311+ # Add Report
312+ report_note (
313+ :host => ip ,
314+ :proto => 'tcp' ,
315+ :sname => 'smb' ,
316+ :port => rport ,
317+ :type => "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } " ,
318+ :data => "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } OPEN VIA #{ datastore [ 'SMBPIPE' ] } "
319+ )
320+ rescue ::Rex ::Proto ::SMB ::Exceptions ::ErrorCode => e
321+ print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } ERROR 0x%.8x" % e . error_code )
322+ rescue StandardError => e
323+ print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } ERROR #{ $!} " )
306324 end
307325 end
308326 end
309327
310-
311328end
0 commit comments