Skip to content

Commit 2ea116e

Browse files
authored
Land rapid7#19163, Allow setting the RPORT option for smb_version
2 parents 8c76143 + 0863700 commit 2ea116e

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

modules/auxiliary/scanner/smb/smb_enumusers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def run_host(_ip)
4343

4444
if datastore['RPORT'].blank? || datastore['RPORT'] == 0
4545
smb_services = [
46-
{ port: 139, direct: false },
47-
{ port: 445, direct: true }
46+
{ port: 445, direct: true },
47+
{ port: 139, direct: false }
4848
]
4949
else
5050
smb_services = [

modules/auxiliary/scanner/smb/smb_version.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,26 @@ def initialize
4040
'License' => MSF_LICENSE
4141
)
4242

43+
register_options([
44+
Msf::Opt::RPORT(nil, false)
45+
])
46+
4347
register_advanced_options(
4448
[
4549
*kerberos_storage_options(protocol: 'SMB'),
4650
*kerberos_auth_options(protocol: 'SMB', auth_methods: Msf::Exploit::Remote::AuthOption::SMB_OPTIONS),
4751
]
4852
)
4953

50-
deregister_options('RPORT', 'SMBDIRECT', 'SMB::ProtocolVersion')
54+
deregister_options('SMB::ProtocolVersion')
5155
end
5256

5357
def rport
54-
@smb_port
58+
@rport
5559
end
5660

57-
def smb_direct
58-
(@smb_port == 445)
61+
def connect(*args, **kwargs)
62+
super(*args, **kwargs, direct: @smb_direct)
5963
end
6064

6165
def seconds_to_timespan(seconds)
@@ -189,10 +193,21 @@ def smb_os_description(res, nd_smb_fingerprint)
189193
# Fingerprint a single host
190194
#
191195
def run_host(ip)
192-
smb_ports = [445, 139]
196+
if datastore['RPORT'].blank? || datastore['RPORT'] == 0
197+
smb_services = [
198+
{ port: 445, direct: true },
199+
{ port: 139, direct: false }
200+
]
201+
else
202+
smb_services = [
203+
{ port: datastore['RPORT'], direct: datastore['SMBDirect'] }
204+
]
205+
end
206+
193207
lines = [] # defer status output to the very end to group lines together by host
194-
smb_ports.each do |pnum|
195-
@smb_port = pnum
208+
smb_services.each do |smb_service|
209+
@rport = smb_service[:port]
210+
@smb_direct = smb_service[:direct]
196211
self.simple = nil
197212

198213
begin

0 commit comments

Comments
 (0)