@@ -18,19 +18,25 @@ class MetasploitModule < Msf::Auxiliary
1818
1919 def initialize
2020 super (
21- 'Name' => 'SMB Session Pipe DCERPC Auditor' ,
21+ 'Name' => 'SMB Session Pipe DCERPC Auditor' ,
2222 'Description' => 'Determine what DCERPC services are accessible over a SMB pipe' ,
23- 'Author' => 'hdm' ,
24- 'License' => MSF_LICENSE ,
23+ 'Author' => 'hdm' ,
24+ 'License' => MSF_LICENSE ,
2525 )
2626
27- deregister_options ( 'RPORT' )
2827 register_options (
2928 [
30- OptString . new ( 'SMBPIPE' , [ true , "The pipe name to use (BROWSER)" , 'BROWSER' ] ) ,
31- ] )
29+ OptString . new ( 'SMBPIPE' , [ true , 'The pipe name to use (BROWSER)' , 'BROWSER' ] ) ,
30+ ]
31+ )
32+ end
33+
34+ def connect ( *args , **kwargs )
35+ super ( *args , **kwargs , direct : @smb_direct )
3236 end
3337
38+ attr_reader :rport
39+
3440 @@target_uuids = [
3541 [ '00000131-0000-0000-c000-000000000046' , '0.0' ] ,
3642 [ '00000134-0000-0000-c000-000000000046' , '0.0' ] ,
@@ -248,64 +254,70 @@ def initialize
248254 [ 'fdb3a030-065f-11d1-bb9b-00a024ea5525' , '1.0' ] ,
249255 [ 'ffe561b8-bf15-11cf-8c5e-08002bb49649' , '2.0' ]
250256
251-
252- ]
257+ ]
253258
254259 # Fingerprint a single host
255260 def run_host ( ip )
256- ports = [ 139 , 445 ]
257-
258261 if session
259262 print_status ( "Using existing session #{ session . sid } " )
260263 client = session . client
264+ @rport = datastore [ 'RPORT' ] = session . port
261265 self . simple = ::Rex ::Proto ::SMB ::SimpleClient . new ( client . dispatcher . tcp_socket , client : client )
262- ports = [ simple . port ]
263- 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
268-
269- begin
270- unless session
271- connect ( )
272- smb_login ( )
273- end
274-
275- @@target_uuids . each do |uuid |
266+ simple . connect ( "\\ \\ #{ simple . address } \\ IPC$" ) # smb_login connects to this share for some reason and it doesn't work unless we do too
267+ check_uuids ( ip )
268+ else
269+ if datastore [ 'RPORT' ] . blank? || datastore [ 'RPORT' ] == 0
270+ smb_services = [
271+ { port : 445 , direct : true } ,
272+ { port : 139 , direct : false }
273+ ]
274+ else
275+ smb_services = [
276+ { port : datastore [ 'RPORT' ] , direct : datastore [ 'SMBDirect' ] }
277+ ]
278+ end
276279
277- handle = dcerpc_handle_target (
278- uuid [ 0 ] , uuid [ 1 ] ,
279- 'ncacn_np' , [ "\\ #{ datastore [ 'SMBPIPE' ] } " ] , self . simple . address
280- )
280+ smb_services . each do |smb_service |
281+ @rport = smb_service [ :port ]
282+ @smb_direct = smb_service [ :direct ]
281283
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
284+ begin
285+ connect
286+ smb_login
287+ check_uuids ( ip )
288+ disconnect
289+ rescue ::Exception
290+ print_line ( $!. to_s )
299291 end
292+ end
293+ end
294+ end
300295
301- disconnect ( )
296+ def check_uuids ( ip )
297+ @@target_uuids . each do |uuid |
298+ handle = dcerpc_handle_target (
299+ uuid [ 0 ] , uuid [ 1 ] ,
300+ 'ncacn_np' , [ "\\ #{ datastore [ 'SMBPIPE' ] } " ] , simple . address
301+ )
302302
303- return
304- rescue ::Exception
305- print_line ( $!. to_s )
303+ begin
304+ dcerpc_bind ( handle )
305+ print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } OPEN VIA #{ datastore [ 'SMBPIPE' ] } " )
306+ # Add Report
307+ report_note (
308+ host : ip ,
309+ proto : 'tcp' ,
310+ sname : 'smb' ,
311+ port : rport ,
312+ type : "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } " ,
313+ data : "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } OPEN VIA #{ datastore [ 'SMBPIPE' ] } "
314+ )
315+ rescue ::Rex ::Proto ::SMB ::Exceptions ::ErrorCode => e
316+ print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } ERROR 0x%.8x" % e . error_code )
317+ rescue StandardError => e
318+ print_line ( "UUID #{ uuid [ 0 ] } #{ uuid [ 1 ] } ERROR #{ $!} " )
306319 end
307320 end
308321 end
309322
310-
311323end
0 commit comments