Heartbleed: length of heatbeat message?

What is the right length of heartbeat message between 2^14 and 2^16 ?

The RFC https://www.rfc-editor.org/rfc/rfc6520 says that

The total length of a HeartbeatMessage MUST NOT exceed 2^14 or
max_fragment_length when negotiated as defined in [RFC6066].

In this Heartbleed PoC the size is `40 00` in hex so 16 384 -> 2^14

But if I check these explanations (two from many):

Then the maximum length is 65 535 -> 2^16

EDIT SOLVED ?

I test Heartbleed PoC code, the hb code is :

``````hb = h2bin('''
18 03 02 00 03
01 40 00
''')
``````

`40 00` -> 16 384 -> 2^14

If i print the length received, it show 16 384

If i replace `40 00` by `FF FF` -> 2^16, the length of the data received is still 16 384 four time.

``````16 384
16 384
16 384
16 384
``````

=> 2^16

Interesting

So the max is 2^16 but it will be divided on packets length 2^14

• The designed message length is 2^14, but there is overhead added to it (padding, etc)? Message is supposed to be one size, but to exploit it, you need the extra length. Commented Mar 8, 2015 at 18:39

The maximum size of a HeartbeatMessage (including padding, etc.) is 2^14 per RFC 6520 sect. 4 as you pointed out.

OpenSSL however had an implementation issue that did not properly check for this bound (and allowing values up to the maximum size of an 16-bit integer, that is about 2^16). The result is known as the "Heartbleed" bug. See this OpenSSL commit for the fix which adds the missing boundary check.

If you are wondering why setting the payload length to 0xFFFF does not result in a single response of about 2^16 bytes, this is because the maximum size for a TLSPlainText must not exceed 2^14 which is also enforced in OpenSSL. (For a detailed explanation on the exact format for a crafted Heartbeat message, see these comments of the pacemaker PoC.)

• you mean 2^14 at the first line no ? rfc say `The total length of a HeartbeatMessage MUST NOT exceed 2^14`
– mpgn
Commented Mar 9, 2015 at 6:46
• @mpgn Yes you are right, amended the answer for that. Note that if you chose exactly `0xFFFF` as Heartbeat message length, you will not receive the last 19 bytes as these are being buffered. Commented Mar 9, 2015 at 9:39
• the "pacemaker Poc" you wrote is really well explain ! i recommend to everyone to read it to understand the attack
– mpgn
Commented Mar 15, 2015 at 14:08