
Python simulation of the Bluetooth Classic KNOB attack, showing encryption key-size downgrade and brute-force decryption of intercepted Bluetooth traffic.
# knob_attack_sim.py - Simulates negotiation of encryption key size to 1 byte
import random, hashlib
class BluetoothDevice:
def negotiate_key_size(self, proposed_size):
# Vulnerable: accepts any key size down to 1 byte
return max(1, proposed_size) # should enforce minimum 7
def attack():
bob = BluetoothDevice()
# Attacker proposes 1 byte key size
agreed = bob.negotiate_key_size(1)
print(f"Key size negotiated: {agreed} byte")
# Now brute-force 1-byte key (256 possibilities) in seconds
for k in range(256):
# Simulate successful decryption
print(f"Key {k} decrypted traffic.")
attack()
A Bluetooth device accepts encryption key sizes as small as 1 byte during the pairing negotiation. An attacker can force the connection to use an extremely weak key, then brute‑force it in real time and eavesdrop on the communication.
Run the simulation:
python knob_attack_sim.py
It outputs that a 1‑byte key was agreed upon and can be brute‑forced instantly.