Skip to content

Commit 2e4bc2c

Browse files
committed
Add a check method to the smb_relay module
1 parent 85f62a8 commit 2e4bc2c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

docs/metasploit-framework.wiki/ad-certificates/Attacking-AD-CS-ESC-Vulnerabilities.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ In the following example the AUTO mode is used to issue a certificate for the MS
892892
authenticated.
893893

894894
```msf
895-
msf6 auxiliary(server/relay/esc8) > set RELAY_TARGETS 172.30.239.85
895+
msf6 auxiliary(server/relay/esc8) > set RHOSTS 172.30.239.85
896896
msf6 auxiliary(server/relay/esc8) > run
897897
[*] Auxiliary module running as background job 1.
898898
msf6 auxiliary(server/relay/esc8) >

modules/exploits/windows/smb/smb_relay.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def run_psexec(relay_connection)
201201
framework.threads.spawn(thread_name, false, new_mod_instance) do |mod_instance|
202202
mod_instance.exploit_smb_target
203203
rescue StandardError => e
204-
print_error("Failed running psexec against target #{datastore['RHOST']} - #{e.class} #{e.message}")
204+
print_error("Failed running psexec against target #{relay_connection.target.ip} - #{e.class} #{e.message}")
205205
elog(e)
206206
# ensure
207207
# # Note: Don't cleanup explicitly, as the shared replicant state leads to payload handlers etc getting closed.
@@ -213,12 +213,31 @@ def run_psexec(relay_connection)
213213
def relay_targets
214214
Msf::Exploit::Remote::SMB::Relay::TargetList.new(
215215
:smb,
216-
445,
216+
rport,
217217
datastore['RHOSTS'],
218218
randomize_targets: datastore['RANDOMIZE_TARGETS']
219219
)
220220
end
221221

222+
def check_host(target_ip)
223+
generic_message = 'Failed to connect and negotiate an SMB connection.'
224+
begin
225+
simple = connect(false, direct: true)
226+
protocol = simple.client.negotiate
227+
rescue Rex::Proto::SMB::Exceptions::Error, RubySMB::Error::RubySMBError, Errno::ECONNRESET
228+
return Exploit::CheckCode::Unknown(generic_message)
229+
rescue ::Exception => e # rubocop:disable Lint/RescueException
230+
elog(generic_message, error: e)
231+
return Exploit::CheckCode::Unknown(generic_message)
232+
end
233+
234+
if simple.signing_required
235+
return Exploit::CheckCode::Safe('Signing is required by the target server.')
236+
end
237+
238+
Exploit::CheckCode::Vulnerable('Signing is not required by the target server.')
239+
end
240+
222241
# Called after a successful connection to a relayed host is opened
223242
def exploit_smb_target
224243
# automatically select an SMB share unless one is explicitly specified
@@ -283,4 +302,7 @@ def session_setup(client)
283302
s
284303
end
285304

305+
def rport
306+
445
307+
end
286308
end

0 commit comments

Comments
 (0)