Skip to content

Commit b41caa2

Browse files
authored
Merge pull request rapid7#19475 from NtAlexio2/smb_modules_rport
Allow setting the RPORT option for pipe_auditor
2 parents 97e50cc + 09ffbde commit b41caa2

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

modules/auxiliary/scanner/smb/pipe_auditor.rb

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ def initialize
2323
'Author' => 'hdm',
2424
'License' => MSF_LICENSE,
2525
)
26+
end
27+
28+
def connect(*args, **kwargs)
29+
super(*args, **kwargs, direct: @smb_direct)
30+
end
2631

27-
deregister_options('RPORT', 'SMBDirect')
32+
def rport
33+
@rport
2834
end
2935

3036
# Fingerprint a single host
@@ -35,29 +41,50 @@ def run_host(ip)
3541
if session
3642
print_status("Using existing session #{session.sid}")
3743
client = session.client
38-
datastore['RPORT'] = session.port
44+
@rport = datastore['RPORT'] = session.port
3945
self.simple = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client)
4046
self.simple.connect("\\\\#{session.address}\\IPC$")
41-
pipes += check_pipes
47+
report_pipes(ip, check_pipes)
4248
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
4459

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]
4763

4864
begin
4965
connect
5066
smb_login
5167
pipes += check_pipes
5268
disconnect
53-
break
69+
report_pipes(ip, pipes)
5470
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}")
5672
end
73+
5774
end
5875
end
5976

77+
end
6078

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)
6188
if(pipes.length > 0)
6289
print_good("Pipes: #{pipes.join(", ")}")
6390
# Add Report
@@ -72,11 +99,4 @@ def run_host(ip)
7299
end
73100
end
74101

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
82102
end

modules/auxiliary/scanner/smb/smb_enumusers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def initialize
2727
])
2828
end
2929

30+
def rport
31+
@rport
32+
end
33+
3034
def domain
3135
@smb_domain || super
3236
end

0 commit comments

Comments
 (0)