Chapters

15 BLE Attack Labs: PIN Brute-Force Timing

bluetooth-ble
bt
security
defense

15.1 Start With the Decision

A four-digit PIN can look safe until a script tries every value. Lockout time and retry limits decide how long the attack takes.

15.2 Route Overview

This is part 2 of 2. Review BLE Attack Labs: Security Review for the preceding evidence.

15.3 Learning Objectives

  • Calculate interactive: pin brute-force time calculator from stated measurements and limits.
  • Test 4. ignoring firmware update authentication against named attack, failure, and recovery cases.

15.4 Chapter Roadmap

  • Interactive: PIN Brute-Force Time Calculator
  • Defense-in-Depth Security Layers
  • BLE Attack Timeline Visualization
  • Visual Reference Gallery
  • Visual: Bluetooth Pairing Process
  • Visual: BLE State Machine
  • Visual: Bluetooth Power Classes
  • Visual: Bluetooth Protocol Stack Security
  • Knowledge Check
  • Auto-Gradable Quick Check
  • Common Mistake: Ignoring Bonded Key Storage Security
  • Checkpoint: Defense Stack
  • Concept Relationships
  • See Also
  • Practice Activities
  • Interactive Quiz: Match Defense Mechanisms
  • Interactive Quiz: Sequence the Security Hardening
  • Label the Diagram
  • Code Challenge
  • Start With the Story
  • Deep Dive: ATT Permissions and Write Validation
  • Summary
  • Common Pitfalls
  • 1. Testing Security Only at the BLE Protocol Layer
  • 2. Relying on Device Address as Authentication
  • 3. Not Revoking Bonding Keys After Security Incident
  • 4. Ignoring Firmware Update Authentication
  • What’s Next
  • Key Takeaway

Experiment with lockout parameters to see how rate limiting defends against brute-force attacks on BLE pairing PINs.

15.5 Defense-in-Depth Security Layers

Secure BLE deployments require protection at multiple layers. Inspect Figure 15.1 to ask what remains exposed when any single control fails; the aim is to avoid treating pairing or link encryption as the entire security architecture.

Five BLE layers run from physical security through radio exposure, pairing and link protection, application authorization, and device and data protection. No single layer is enough.
Figure 15.1: Defense-in-depth layers for BLE security showing how each layer blocks different attack vectors.

Read Figure 15.1 from the outside inward. Physical controls constrain access to the device, the radio perimeter limits exposure, link encryption protects over-the-air frames, application authentication decides who may invoke a function, and data protection limits damage to the underlying secret or record. The layers answer different threats, so the lab results should record which control stopped which attack rather than claiming one successful pairing test proves end-to-end security.

15.6 BLE Attack Timeline Visualization

Understanding when attacks can occur helps prioritize defenses. Follow Figure 15.2 across the whole device life so commissioning controls do not obscure supply-chain, operational, and retirement risks.

BLE security phases cover manufacturing, deployment, operation and retirement. Each hand-off needs an owner, a control and retained test evidence.
Figure 15.2: Attack timeline showing vulnerability windows throughout the BLE device lifecycle.

Read Figure 15.2 from manufacturing, where firmware and injected credentials establish the initial trust base, into deployment and its pairing window. Continue through operation, where eavesdropping, relay, authorization, and update risks persist, then finish at decommissioning, where retained bonds and data can outlive ownership. This sequence connects the hands-on lab to lifecycle policy: secure mode must include provenance, commissioning, maintenance, reset, and verified key destruction.

15.8 Knowledge Check

Knowledge Check: Defense-in-Depth for BLE
Knowledge Check: BLE Attack Surface
Common Mistake: Ignoring Bonded Key Storage Security

The Scenario: A smart lock manufacturer implements authenticated BLE pairing with Numeric Comparison but stores bonded LTK keys in unencrypted flash memory. After deployment, a security researcher extracts the keys through exposed debug access and demonstrates that cloned clients can reconnect as trusted devices.

What Went Wrong: Secure pairing means nothing if the resulting keys are not securely stored. Many developers focus on the pairing ceremony (Numeric Comparison, OOB) but neglect key storage, assuming the device’s physical security is sufficient.

Vulnerable implementation pattern:

  • Bonding keys are saved to ordinary flash without flash encryption.
  • JTAG or SWD debug access remains enabled in production.
  • The enclosure allows simple access to programming pads.
  • There is no process to revoke bonds after a suspected key leak.

Attack Vector:

  1. Attacker removes smart lock cover (2 screws)
  2. Connects USB debugger (ST-Link, J-Link) to exposed JTAG/SWD pins
  3. Dumps flash memory contents (5 minutes)
  4. Extracts bonded keys from known NVS partition offsets
  5. Creates spoofed central device using extracted keys
  6. Locks now accept attacker’s device as trusted

Secure implementation pattern:

  • Enable flash encryption before production release.
  • Disable debug interfaces or lock them behind an authenticated service process.
  • Store long-lived secrets in protected flash or a secure element when the risk justifies the cost.
  • Add a bond-revocation path so extracted or lost credentials can be invalidated.

Defense Checklist:

  • Enable flash encryption (ESP32/nRF52: burns eFuses, permanent)
  • Disable debug interfaces (JTAG/SWD) in production firmware
  • Use tamper-evident enclosures (security screws, ultrasonic welds)
  • Implement key rotation (refresh LTK every N days)
  • Add intrusion detection (accelerometer detects case opening)

Deployment cost lesson: Retrofitting hardware security after release is usually more expensive than designing for protected storage and debug-port lockdown before manufacturing.

Radio RemiCheckpoint: Defense Stack

You now know:

  • BLE link encryption uses AES-CCM with 128-bit keys, but link encryption only protects traffic in transit.
  • Defense-in-depth adds application-layer authorization, signed firmware, flash encryption, protected bonded-key storage, and a revocation path.
  • Physical access matters: the chapter’s bonded-key scenario needs only two screws, a debugger, and about 5 minutes when production debug access is left open.
  • The final lab record should prove both denial paths and allowed paths: unauthenticated writes fail, malformed authorized writes fail, and valid authorized commands still work.

The remaining sections consolidate those layers into a study map, practice checks, and common deployment mistakes.

Concept Relationships
  • Defense-in-depth and security layers: Link encryption protects traffic in transit, but production devices also need application authorization, secure boot, and protected key storage.
  • Attack timeline and lifecycle security: Vulnerabilities can appear during manufacturing, pairing, normal operation, firmware update, resale, and decommissioning.
  • Secure boot and firmware integrity: Signed boot prevents malicious firmware from disabling encryption or leaking bonded keys.
  • LE Secure Connections and key agreement: ECDH-based pairing improves key establishment and prevents passive recovery of past session keys.
  • Key storage protection and bonding security: Flash encryption, secure elements, and debug-port lockdown reduce the risk of LTK extraction.

15.9 See Also

15.10 Practice Activities

15.11 Start With the Story

Picture a smart lock that opens after a nearby phone asks. The phone and lock may have made a protected link. That does not prove the person may open this door. It also does not prove the lock will reject a changed or repeated command.

A security lab turns these hidden questions into visible tests. Start with one action. State who should be allowed to request it. State what the device should reject. Then try the wrong person, wrong message, and wrong time. Save the evidence from each result.

Use several layers of defense. The wireless link can hide data from a nearby listener. The product must still check permission. The device must limit repeated guesses. New software must come from a trusted source. Lost phones and old keys need a removal path. Physical access also changes the risk.

Run the weak case first. Capture what an attacker can see or change. Apply one protection. Repeat the same test. A passing result should name the exact action and setup. It should not claim that the whole product is safe.

This first view uses a small door command. Real attacks can cross the phone, device, cloud service, and recovery process. The Practitioner layer builds repeatable lab records and fixes. Under the Hood examines data permissions, write checks, key storage, and the cases that a simple pairing test cannot cover.

A security lab should make invisible trust visible. If a setup is vulnerable to weak pairing, passive capture, relay assumptions, or bad recovery, the lab needs to produce evidence before the field deployment does.

Use this chapter as a small defense review. Run the attack or failure pattern, capture the trace, apply the mitigation, and leave a record that says exactly what changed and what still needs retesting.

15.12 Deep Dive: ATT Permissions and Write Validation

A useful BLE security lab starts by inventorying the ATT operations before testing pairing or packet capture. Write down every characteristic, the operations it permits, and the minimum security level expected for each operation. That map often exposes the real defect faster than radio analysis: a command characteristic left writable by any nearby phone.

ATT operationSecurity questionFailure if left open
ReadWho may pull the current value?A nearby client can read state, identity, or sensor values.
Write / Write CommandWho may change the value?A nearby client can change configuration or actuate hardware.
NotifyWho may subscribe through the CCCD?A nearby client can receive a continuing telemetry stream.
IndicateWho may receive acknowledged updates?Reliability improves delivery, but does not add authorization.

A GATT server assigns each attribute a security level for its operations. This permission setting, not the secrecy of the UUID, is what protects the device:

Permission levelWho can perform the operation
Open (no security)Any device in radio range, no pairing
Encryption requiredOnly a paired device on an encrypted link using the LTK
Authentication requiredOnly a device paired with MITM protection such as Numeric Comparison or Passkey Entry

The classic vulnerability is a writable command characteristic left at Open. A smart lock whose unlock characteristic accepts a Write Command with no security lets anyone within range enumerate the UUID, send 0x01, and open the door. Changing from Write Command to Write Request only adds an ATT response; changing the UUID only delays discovery. The meaningful test result changes only when the write permission becomes authentication-required and the unauthenticated write fails before the latch callback runs.

Permissions are still only one layer. A bonded, authorized client can send malformed or malicious data through a legitimate Write, so the application must validate every written value. For a lock command, validate the opcode, door identifier, requested open time, nonce, and message authentication value before the latch moves. Reject unexpected lengths, unknown opcodes, replayed nonces, and unsafe durations such as 255 seconds, then log and rate-limit failures. In the lab, prove both sides: one unauthorized write fails at ATT permission checks, and one malformed authorized write fails in the application parser.

15.13 Summary

This chapter provided hands-on experience with BLE security:

  • Interactive Lab: ESP32-based demonstration comparing secure and insecure BLE modes
  • Security Challenges: PIN brute-force protection, packet interception analysis, secure boot implementation
  • Defense-in-Depth: Multi-layer security architecture from physical to data protection
  • Attack Timeline: Vulnerability windows across device lifecycle (manufacturing, deployment, operation, decommissioning)
  • Visual Gallery: Reference diagrams for pairing, encryption, and protocol stack security

Common Pitfalls

BLE security testing that focuses only on pairing and encryption misses vulnerabilities at other layers: unvalidated GATT write values causing buffer overflows, unauthenticated command execution (e.g., factory reset via GATT Write without security), or insecure bootloader allowing unsigned firmware. Test the complete attack surface including: physical access, JTAG/debug interfaces, UART console, GATT command handling, and OTA update integrity.

Using the BLE device MAC address as an authentication factor is insecure — MAC addresses are transmitted in cleartext in advertising packets and can be spoofed in software. An attacker can clone a trusted device’s MAC address to impersonate it. Authentication must use cryptographic methods: LESC pairing, application-layer token exchange, or certificate-based authentication, never MAC address matching.

When a bonded device is lost, stolen, or suspected compromised, the LTK stored in the remaining device’s NVS must be immediately deleted to prevent unauthorized reconnection. IoT devices without a mechanism to remotely revoke bonding keys (via cloud command + BLE or local physical trigger) remain permanently open to the lost device reconnecting with the stolen key. Always implement a key revocation path in production firmware.

An OTA DFU implementation that accepts unsigned firmware images allows an attacker within BLE range to flash arbitrary malicious firmware. All production BLE OTA implementations must verify firmware image signatures (ECDSA or RSA) before applying updates. The public key for signature verification should be stored in a protected flash region that cannot be overwritten by OTA updates themselves.

15.14 What’s Next

Prioritize these follow-up chapters based on the security question you need to answer next:

15.15 Key Takeaway

Security labs should prove both allowed and denied paths. Test pairing, encryption, authorization, key reuse, and failed access attempts so defensive behavior is visible rather than assumed.

15.16 Continue Your Route

This final part closes the route from Interactive: PIN Brute-Force Time Calculator through Key Takeaway. Return to BLE Attack Labs: Security Review or continue from the bluetooth-ble module index.