Heartbleed

Heartbleed

One-liner: A critical OpenSSL vulnerability that allowed attackers to read sensitive memory contents including private keys, passwords, and session tokens.

🎯 What Is It?

Heartbleed (CVE-2014-0160) was a catastrophic buffer over-read vulnerability in the OpenSSL cryptographic library discovered in 2014. It affected the TLS/SSL heartbeat extension, allowing attackers to read up to 64KB of server memory per request without authentication or leaving traces in logs.

The vulnerability exposed:

Affected Versions: OpenSSL 1.0.1 through 1.0.1f

πŸ€” Why It Matters

Impact Scale

Historical Significance

πŸ”¬ How It Works

TLS Heartbeat Extension

The heartbeat is a "keep-alive" mechanism for TLS connections:

Client β†’ "Hey, I'm still here!" (sends data)
Server β†’ "Got it!" (echoes data back)

The Vulnerability

OpenSSL failed to validate the length field in heartbeat requests:

Normal Heartbeat:
Client: "Send back this 4-byte message: 'test'"
Server: Returns 4 bytes: "test"

Heartbleed Attack:
Client: "Send back this 4-byte message: 'test'" BUT LENGTH=65535
Server: Returns 65535 bytes β€” INCLUDING ADJACENT MEMORY!

Attack Visualization

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Heartbeat Request Payload          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Type: 1 (request)                   β”‚
β”‚ Length: 65535 (LIE!)                β”‚
β”‚ Actual Data: "test" (4 bytes)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Server Memory Returned             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ "test"                              β”‚  ← Your 4 bytes
β”‚ "admin:SuperSecretP@ssw0rd!"        β”‚  ← Memory leak!
β”‚ "SESSION_ID=a3f8c92..."             β”‚  ← Stolen session
β”‚ "-----BEGIN PRIVATE KEY-----..."    β”‚  ← SSL private key!
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Exploitation Process

# Using Metasploit
use auxiliary/scanner/ssl/openssl_heartbleed
set RHOSTS target.com
set RPORT 443
run

# Manual exploitation
# Send malformed heartbeat with length=65535
# Server returns 64KB of memory content
# Repeat to collect more data

πŸ“Š Technical Details

Vulnerable Code (Simplified)

// OpenSSL heartbeat handler (vulnerable)
int tls1_process_heartbeat(SSL *s) {
    unsigned char *p = &s->s3->rrec.data[0];
    unsigned short payload_length;
    
    payload_length = (p[0] << 8) | p[1]; // Client-controlled!
    
    // VULNERABLE: No bounds check!
    memcpy(bp, p, payload_length);
    return 0;
}

The bug: payload_length is user-controlled and never validated against actual data size.

πŸ›‘οΈ Detection & Prevention

How to Detect

For Servers:

nmap --script ssl-heartbleed target.com

# Or Metasploit
msf> use auxiliary/scanner/ssl/openssl_heartbleed

For Defenders:

How to Prevent / Mitigate

Immediate Actions (2014)

  1. Patch OpenSSL β†’ Upgrade to 1.0.1g or later
  2. Reissue SSL certificates β†’ Private keys may be compromised
  3. Revoke old certificates β†’ Invalidate potentially leaked keys
  4. Reset user passwords β€” Credentials may have been exposed
  5. Invalidate session tokens β€” Force re-authentication

Long-Term Solutions

# Compile OpenSSL without heartbeat
./config -DOPENSSL_NO_HEARTBEATS

Testing for Heartbleed

# Using nmap
nmap -p 443 --script ssl-heartbleed <target>

# Using sslscan
sslscan --heartbleed <target>:443

# Online tester
https://filippo.io/Heartbleed/

🎀 Interview Angles

Common Questions

STAR Example

Situation: During a 2014 incident response engagement, a financial client discovered their servers were running vulnerable OpenSSL versions post-disclosure.
Task: Determine scope of compromise and restore security posture.
Action: Patched all OpenSSL instances, revoked and reissued 47 SSL certificates, forced company-wide password reset, invalidated all active sessions. Analyzed network traffic for heartbeat anomalies (found none, but couldn't rule out prior exploitation).
Result: Restored secure communications within 72 hours. Implemented continuous vulnerability scanning to prevent future delays in patching critical CVEs.

βœ… Best Practices

❌ Common Misconceptions

πŸ“š References