@@ -23,8 +23,14 @@ def initialize
23
23
'Author' => 'hdm' ,
24
24
'License' => MSF_LICENSE ,
25
25
)
26
+ end
27
+
28
+ def connect ( *args , **kwargs )
29
+ super ( *args , **kwargs , direct : @smb_direct )
30
+ end
26
31
27
- deregister_options ( 'RPORT' , 'SMBDirect' )
32
+ def rport
33
+ @rport
28
34
end
29
35
30
36
# Fingerprint a single host
@@ -35,29 +41,50 @@ def run_host(ip)
35
41
if session
36
42
print_status ( "Using existing session #{ session . sid } " )
37
43
client = session . client
38
- datastore [ 'RPORT' ] = session . port
44
+ @rport = datastore [ 'RPORT' ] = session . port
39
45
self . simple = ::Rex ::Proto ::SMB ::SimpleClient . new ( client . dispatcher . tcp_socket , client : client )
40
46
self . simple . connect ( "\\ \\ #{ session . address } \\ IPC$" )
41
- pipes += check_pipes
47
+ report_pipes ( ip , check_pipes )
42
48
else
43
- [ [ 139 , false ] , [ 445 , true ] ] . each do |info |
49
+ if datastore [ 'RPORT' ] . blank? || datastore [ 'RPORT' ] == 0
50
+ smb_services = [
51
+ { port : 445 , direct : true } ,
52
+ { port : 139 , direct : false }
53
+ ]
54
+ else
55
+ smb_services = [
56
+ { port : datastore [ 'RPORT' ] , direct : datastore [ 'SMBDirect' ] }
57
+ ]
58
+ end
44
59
45
- datastore [ 'RPORT' ] = info [ 0 ]
46
- datastore [ 'SMBDirect' ] = info [ 1 ]
60
+ smb_services . each do |smb_service |
61
+ @rport = smb_service [ :port ]
62
+ @smb_direct = smb_service [ :direct ]
47
63
48
64
begin
49
65
connect
50
66
smb_login
51
67
pipes += check_pipes
52
68
disconnect
53
- break
69
+ report_pipes ( ip , pipes )
54
70
rescue Rex ::Proto ::SMB ::Exceptions ::SimpleClientError , Rex ::ConnectionError => e
55
- vprint_error ( "SMB client Error with RPORT=#{ info [ 0 ] } SMBDirect=#{ info [ 1 ] } : #{ e . to_s } " )
71
+ vprint_error ( "SMB client Error with RPORT=#{ @rport } SMBDirect=#{ @smb_direct } : #{ e . to_s } " )
56
72
end
73
+
57
74
end
58
75
end
59
76
77
+ end
60
78
79
+ def check_pipes
80
+ pipes = [ ]
81
+ check_named_pipes . each do |pipe_name , _ |
82
+ pipes . push ( pipe_name )
83
+ end
84
+ pipes
85
+ end
86
+
87
+ def report_pipes ( ip , pipes )
61
88
if ( pipes . length > 0 )
62
89
print_good ( "Pipes: #{ pipes . join ( ", " ) } " )
63
90
# Add Report
@@ -72,11 +99,4 @@ def run_host(ip)
72
99
end
73
100
end
74
101
75
- def check_pipes
76
- pipes = [ ]
77
- check_named_pipes . each do |pipe_name , _ |
78
- pipes . push ( pipe_name )
79
- end
80
- pipes
81
- end
82
102
end
0 commit comments