rapid7/metasploit-framework — pull request #3268 by jjarmoc (2014-04-16 15:32:38+00:00)
Title: Adds RSA key extraction via Heartbleed

This pull adds the ability to retrieve Private Keys from memory. There's also significant refactoring, mostly splitting things into functions to allow for better reuse.

msftidy comes back clean.

I've tested this against my own vulnerable nginx box (set up similar to https://news.ycombinator.com/item?id=7577659), and it works well with 1024 and 2048 bit keys. After restart it gets the key every time. Under light load it takes a little longer, as expected. I also used this on www.cloudflarechallenge.com successfully (see https://gist.github.com/jjarmoc/10890697)

Some new options are added. Notably;

MODE is an Enum that determines how the module operates. Choices are:
- SCAN - A generic scan for vulnerable hosts.
- DUMP - Stores retrieved memory (same as STOREDUMP true in the previous version)
- KEYS - Try to get private keys from memory (This is my new stuff)

In KEYS mode, two new options are used;
- MAX_KEYTRIES - This is the maximum number of times to try for a private key on each host
- STATUS_EVERY - status is reported modulo this may retries when trying for keys. Just lets us adjust how noisy reporting is/isn't.

Some caveats:
- STARTTLS isn't currently supported for KEYS mode. I need to work out how to parse the public key....
- Doesn't address non-RSA certs (but that's uncommon)
- I changed the heartbeat response read to use sock.get() instead of sock.get_once. The latter was badly truncating the response data; I'd see lots of data on the wire that never got read. See https://github.com/rapid7/metasploit-framework/issues/3261