BLE MITM Prevention: Securing Against Man-in-the-Middle Attacks

<\/script>\n
'; }, get iframeSnippet() { const domain = '{ SITE_DOMAIN }'; const type = '{ embed_type }'; const slug = '{ embed_slug }'; return ''; }, get activeSnippet() { return this.method === 'script' ? this.scriptSnippet : this.iframeSnippet; }, copySnippet() { navigator.clipboard.writeText(this.activeSnippet).then(() => { this.copied = true; setTimeout(() => { this.copied = false; }, 2000); }); } }" @keydown.escape.window="open = false" @click.outside="open = false">

Embed This Widget

Theme


      
    

Widget powered by . Free, no account required.

Protecting BLE connections from eavesdropping and relay attacks

| 4 분 읽기

BLE MITM Prevention: Securing Against Man-in-the-Middle Attacks

A Bluetooth Low Energy MITM attack intercepts the pairing exchange and substitutes the attacker's public key for the legitimate device's key. Once established, the attacker decrypts all traffic in both directions while relaying it transparently. Preventing MITM attacks requires authenticated key exchange — something Just Works pairing explicitly does not provide.

MITM Attack Anatomy

Legitimate flow:
  Phone ←────────── LTK encrypted ──────────→ Sensor

MITM attack:
  Phone ←── LTK1 ──→ Attacker ←── LTK2 ──→ Sensor
              |                        |
         Phone thinks             Sensor thinks
         attacker is sensor       attacker is phone

The attacker needs to be present during the initial pairing handshake. After bonding, re-connecting with the stored LTK is secure (the LTK is never retransmitted). MITM attacks target the first pairing or forced re-pairing (via bonding removal).

LE Secure Connections ECDH

LE Secure Connections (LESC) uses P-256 Elliptic Curve Diffie-Hellman (ECDH) for key exchange. The DHKey derived from ECDH is used to generate all session keys:

Phase 1: Feature exchange
  → Both devices share IO capabilities (determines association model)

Phase 2: ECDH key exchange + authentication
  A: generates ephemeral keypair (PrivA, PubA)
  B: generates ephemeral keypair (PrivB, PubB)
  A → B: PubA
  B → A: PubB
  DHKey = ECDH(PrivA, PubB) = ECDH(PrivB, PubA)

Phase 2: Nonce exchange (for Numeric Comparison / Passkey)
  → 20 commitment-reveal rounds confirm passkey bits
  → Displayed 6-digit number derived from:
     g2(PubA, PubB, Na, Nb) mod 10^6

Phase 3: Key distribution
  → LTK, IRK, CSRK exchanged over encrypted link

Why ECDH prevents MITM: If an attacker M substitutes PubM for PubA, then: - Phone computes DHKey_AM = ECDH(PrivA, PubM) - Sensor computes DHKey_MB = ECDH(PrivM, PubB) - DHKey_AM ≠ DHKey_MB → derived nonces differ → Numeric Comparison shows different numbers

Channel Sounding for Relay Prevention

Bluetooth 6.0 (October 2024) introduced Channel Sounding (also called Bluetooth Ranging), enabling sub-meter distance measurement between peers using RTT (Round-Trip Time) and HADM (High Accuracy Distance Measurement).

Channel Sounding prevents relay attacks (Bluetooth distance bounding):

Relay attack (e.g., car key relay):
  Attacker A near car ←→ Attacker B near legitimate key (100m away)
  Car sees key at "1m" (relayed)

Channel Sounding defense:
  Car measures ToF to key: RTT/2 = 0.33 µs → distance 50m (100m round trip)
  Car threshold: 5m → REJECT connection (key not physically present)

Channel Sounding uses Coded Tone Extension (CTE) signals on multiple frequencies with precise timestamp correlation:

Method Accuracy Range Use Case
RTT (Round-Trip Time) 20–50 cm 30 m Entry controls, payment
HADM Phase-based 5–20 cm 10 m Ultra-precise proximity
Hybrid RTT+HADM 10–30 cm 20 m Recommended default

Implementation Checklist

Control Implementation
Enforce LESC Reject legacy pairing requests (SMP Pairing Failed 0x03)
Require MITM flag Set auth_req.mitm = 1 in pairing request
Use Numeric Comparison where possible IO capability: KeyboardDisplay
Re-authenticate on reconnect Verify LTK encryption on every reconnect
Enable LE Privacy Rotating addresses prevent attacker address resolution
Implement Channel Sounding (BT 6.0) Distance-bound for physical access controls
Reject Just Works for sensitive ops Write to lock characteristic requires MITM-protected session
// Nordic nRF Connect SDK: enforce MITM protection
static const struct bt_conn_auth_cb auth_callbacks = {
    .passkey_display = auth_passkey_display,
    .passkey_confirm = auth_passkey_confirm,
    .cancel = auth_cancel,
    // No .passkey_entry = NULL means no keyboard → Numeric Comparison
};

// Reject Just Works (no MITM):
static void security_changed(struct bt_conn *conn, bt_security_t level,
                              enum bt_security_err err) {
    if (level < BT_SECURITY_L3) { // L3 = LESC with MITM
        bt_conn_disconnect(conn, BT_HCI_ERR_AUTH_FAIL);
    }
}

Security Levels Reference

Level Description MITM? LESC?
BT_SECURITY_L1 No security No No
BT_SECURITY_L2 Unauthenticated encryption (Just Works) No Optional
BT_SECURITY_L3 Authenticated encryption (Passkey/OOB) Yes Optional
BT_SECURITY_L4 Authenticated LESC + 128-bit key Yes Yes

For medical devices, always require L4. For smart locks, L3 minimum. See BLE Pairing Methods for IO capability selection and BLE Vulnerabilities for known attacks against pairing.

자주 묻는 질문

Yes, our guides range from beginner introductions to advanced topics. Each guide indicates its difficulty level and prerequisites so you can find the right starting point.