Hi, My Name Is Keyboard
The Bluetooth stacks in Android, Linux, macOS, iOS and Windows allow an attacker to pair an emulated Bluetooth keyboard without authentication or user confirmation, and then inject keystrokes. Additionally, the Magic Keyboard can be exploited to extract its Bluetooth link key via the Lightning port or unauthenticated Bluetooth.
github.com
Published on github.com
Blog post part 2, adding CVE-2024-0230 and CVE-2024-21306
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This write-up covers a family of Bluetooth vulnerabilities affecting the way hosts and peripherals handle Human Interface Device (HID) pairing. The headline issue is that the Bluetooth stacks in Android, Linux, macOS, iOS and Windows can be made to pair an emulated Bluetooth keyboard and accept injected keystrokes without user confirmation. A second, related issue is that the Apple Magic Keyboard can be made to give up its Bluetooth link key, either over the Lightning port or over unauthenticated Bluetooth, and, when Lockdown Mode is not enabled, from the paired Mac over USB.
The report is published in the skysafe/reblog repository under a directory named cve-2024-0230, with the README titled "Hi, My Name is Keyboard". The keystroke-injection issues are tracked as CVE-2023-45866 (Android, Linux/BlueZ, macOS, iOS) and CVE-2024-21306 (Windows). The Magic Keyboard link key extraction is tracked as CVE-2024-0230. Proof-of-concept scripts were to be released following the author's ShmooCon talk at roughly 3pm ET on January 13th.
A short primer on the relevant HID concepts is useful before the details. HID devices exchange messages called reports: input reports carry keypresses and mouse movement or clicks, output reports carry commands and state changes, and feature reports let the host read and write device settings. Reports are transport agnostic and can arrive over USB or Bluetooth. Bluetooth HID devices communicate over Bluetooth Classic L2CAP sockets, where L2CAP port 17 is the HID Control channel (feature reports, high latency) and L2CAP port 19 is the HID Interrupt channel (input and output reports, low latency). A Bluetooth HID link is considered established when both L2CAP ports are connected, so in general, if you can connect to L2CAP 17 and 19 on a host, you can inject keystrokes.
For a keyboard to reach those ports it has to pair with the host. The link key encrypts data between two Bluetooth devices; pairing establishes the link key; bonding saves it to the device; out-of-band pairing performs pairing and bonding over a non-Bluetooth channel such as NFC or USB; and pairing capability defines the authentication mechanisms a host or peripheral supports.
Setup
The report does not describe a lab setup, tooling versions or test accounts. What it does state are the preconditions under which each attack works, and those are the practical setup requirements.
For forced pairing and keystroke injection, the criteria are:
- the host is connectable/discoverable;
- the host supports pairing without authentication via the
NoInputNoOutputpairing capability; - the attacker can connect to L2CAP ports 17 and 19 on the host.
On Linux and Android, L2CAP 17 and 19 are available whenever the host is discoverable. On macOS, iOS and Windows, those ports are only available to known peripherals, identified by Bluetooth address. The Linux and Android attacks can be performed with almost any Bluetooth adapter, while the macOS, iOS and Windows attacks require a Broadcom-based Bluetooth adapter.
For the Magic Keyboard attacks, the relevant preconditions are physical or radio proximity: access to the Lightning port, the ability to connect to the keyboard's unauthenticated Bluetooth HID services at the right moment, or knowledge of the keyboard's Bluetooth address and serial number for the USB attack against the paired Mac.
Finding it
The reasoning starts from the normal pairing flow. Pairing is normally initiated when the user selects a device from a list of Bluetooth devices displayed on the host:
sequenceDiagram
User->>Host: please pair with this keyboard
Host->>Keyboard: I want to pair
Keyboard-->>Host: okay, I require authentication
Host-->>Keyboard: I also require authentication
Host->>User: please type this passkey on the keyboard
Keyboard-->>Host: here is the passkey
Host-->>Keyboard: looks good, let's establish a link key
Keyboard-->Host: <key exchange>
Keyboard->>Host: here are some keystrokes
Pairing can also be initiated by the keyboard. If the keyboard declares that it does not support authentication, the expectation is that the host rejects the pairing attempt:
sequenceDiagram
Keyboard->>Host: I want to pair
Host-->>Keyboard: okay
Keyboard-->>Host: I don't require authentication
Host-->>Keyboard: I require authentication
Host-->Keyboard: <pairing failed>
If a host instead accepted a pairing request without authentication, an attacker could pair a keyboard without the user's consent. That is the design gap the report exploits: vulnerable devices support keyboard-initiated pairing and do not require authenticated pairing, so a keyboard, or an emulated keyboard, can pair with a vulnerable device without user confirmation.
On the Magic Keyboard side, the observation is that the keyboard exposes an unauthenticated Bluetooth HID service while its radio is powered on, and that the out-of-band pairing data it holds over USB includes the link key. Both are places where the key can leak.
Exploitation
Step 1: Forced pairing and keystroke injection
The keystroke injection flow is the keyboard-initiated flow with the authentication requirement removed on both sides:
The emulated keyboard declares the NoInputNoOutput capability, the host accepts pairing without authentication, a link key is established, and the attacker then sends input reports over L2CAP 19. The injected keystrokes perform actions as the user, so long as those actions do not require password or biometric authentication.
The exposure differs per platform:
- Android is vulnerable when Bluetooth is enabled. The vulnerability is zero-click, and unpatched devices can be exploited whenever Bluetooth is enabled.
- Linux/BlueZ is vulnerable when Bluetooth is discoverable and connectable, typically when a "Bluetooth settings" dialog is open. It is zero-click, and unpatched hosts can be exploited when they are discoverable and connectable over Bluetooth.
- macOS and iOS are vulnerable when the host is connecting to a paired Magic Keyboard. Both are zero-click, but can only be exploited when the Mac or iPhone is attempting to connect to a paired Magic Keyboard. In practice, a Mac is exploitable when the user unplugs their Magic Keyboard after pairing or charging, and an iPhone is exploitable when the user is connecting to their paired Magic Keyboard.
- Windows is vulnerable when a Bluetooth keyboard has been paired with the computer and the keyboard is powered off or out of range. The user has to interact with a malicious pairing request in any way: clicking accept, reject or close.
Step 2: Understand the out-of-band pairing of the Magic Keyboard
Out-of-band pairing occurs over USB HID when the Magic Keyboard is plugged into the Mac, and the connection is accepted if the Mac is in Lockdown Mode. The sequence is:
- The Mac generates a random link key and stores it in the Keychain.
- The Mac sends the link key to the keyboard over USB, along with the Bluetooth address of the Mac.
- The keyboard stores the link key and Bluetooth address in memory.
- When the keyboard is unplugged from the Mac, it uses the address and link key to connect to the Mac over Bluetooth.
Step 3: Extract the link key from the Lightning port
After out-of-band pairing is performed, the link key remains in memory until the keyboard is switched off. An attacker with physical access to the keyboard can therefore extract the link key by connecting to the Lightning port and reading the appropriate HID report. This works if the keyboard has not been powered off since the last time it was plugged into the Mac.
Step 4: Extract the link key over unauthenticated Bluetooth
An unauthenticated Bluetooth HID service is available on the Magic Keyboard when the Bluetooth radio is powered on, persisting until the keyboard connects to the Mac via Bluetooth or Lightning/USB. This occurs when the Magic Keyboard is switched on, and again when it is unplugged from the Mac.
An unauthenticated attacker can connect to the keyboard and send and receive HID messages as if they were the paired Mac. That includes receiving keystrokes and reading and writing HID feature reports. When the Magic Keyboard is unplugged from the Mac, the attacker can connect to these services and extract the link key by reading the appropriate HID report.
This attack depends on a race condition: the attacker must connect to the Bluetooth HID services on the Magic Keyboard before the keyboard connects to the Mac. In testing, the attacker wins the race approximately 50% of the time.
Step 5: Extract the link key from the USB port on the Mac
The first time the Magic Keyboard is plugged into the Mac, the Bluetooth daemon generates a random link key and sends it to the keyboard over USB. The next time the keyboard is plugged into the Mac, the Bluetooth daemon recognises the keyboard using its serial number and Bluetooth address, and resends the original link key.
If an attacker knows the Bluetooth address and serial number of a Magic Keyboard paired with a Mac, they can spoof the Magic Keyboard and read the link key from the USB port on the Mac, which can be screen locked. This attack is mitigated by Lockdown Mode on macOS.
Step 6: Pair the Magic Keyboard to a different host
An attacker can pair the Magic Keyboard with a different computer by writing out-of-band pairing data over Lightning/USB or unauthenticated Bluetooth. After the OOB pairing data is written, the Magic Keyboard will connect to the attacker-configured host.
Root cause
The keystroke-injection issue is a design mistake in the pairing state machine: the host accepts a keyboard-initiated pairing where the peripheral declares NoInputNoOutput and the host itself does not require authenticated pairing. The expected behaviour, rejecting a pairing request that does not support authentication, is not enforced. Because a HID link is established once L2CAP 17 and 19 are connected, accepting the pairing is enough to allow input reports to be injected. The per-platform differences in exposure come from when those L2CAP ports are reachable: always when discoverable on Linux and Android, and only to known peripherals on macOS, iOS and Windows.
The Magic Keyboard issue is that the link key, which is the long-term secret protecting the Bluetooth link, is held in memory and exposed through channels that do not authenticate the caller: the Lightning port while the keyboard stays powered, and the unauthenticated Bluetooth HID service that is up until the keyboard connects to its Mac. The USB attack against the Mac relies on the daemon resending the stored link key to anything that presents the keyboard's serial number and Bluetooth address, which are not secrets. Lockdown Mode is the control that blocks that last path.
Impact
For the keystroke-injection issues, an attacker can pair an emulated keyboard and inject keystrokes to perform actions as the user, so long as those actions do not require password or biometric authentication. The affected versions listed in the report are:
| Product | Versions | CVE | Status | Notes |
|---|---|---|---|---|
| Android | 4.2, 5, 6, 7, 8, 9, 10 | CVE-2023-45866 | no fix available | Android 3 and earlier were not tested |
| Android | 11, 12, 13, 14 | CVE-2023-45866 | fixed in 2023-12-05 security patch level | |
| Linux (BlueZ) | affected distros | CVE-2023-45866 | BlueZ patch available | |
| macOS | 12, 13 | CVE-2023-45866 | no fix available | macOS 11 and earlier were not tested |
| macOS | 14 | CVE-2023-45866 | fixed in macOS 14.2 | |
| iOS | 16 | CVE-2023-45866 | no fix available | iOS 15 and earlier were not tested |
| iOS | 17 | CVE-2023-45866 | fixed in iOS 17.2 | |
| Windows | 10, 11, Server 2022 | CVE-2024-21306 | fixed in January 2024 Patch Tuesday | earlier versions of Windows were not tested |
For CVE-2024-0230, the Magic Keyboard link key can be read via the Lightning port if the keyboard has not been powered off since the last time it was plugged into the Mac, via unauthenticated Bluetooth when the keyboard gets unplugged from its Mac, and via the USB port on the paired Mac if Lockdown Mode is not enabled. The affected versions listed are:
| Product | Model | CVE | Vector | Status |
|---|---|---|---|---|
| macOS | 12, 13, 14 | CVE-2024-0230 | USB | fix details pending |
| Magic Keyboard | A2449 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Keyboard | A2450 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Keyboard | A2520 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Keyboard | A1843 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Mouse | A1657 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
With the link key, an attacker can spoof the Magic Keyboard to the paired Mac and can also re-pair the keyboard to an attacker-controlled host.
Fix
For the keystroke-injection issues, the report records the following fixes: Android 11 through 14 fixed in the 2023-12-05 security patch level; a BlueZ patch available in the kernel tree; macOS 14.2 and iOS 17.2 fixed; and Windows 10, 11 and Server 2022 fixed in the January 2024 Patch Tuesday. Android 4.2 through 10, macOS 12 and 13, and iOS 16 had no fix available at the time of writing. The report also lists patch information published by Linux distributions, which it notes is not intended to be a complete list of vulnerable distributions:
| Distribution | Patch information |
|---|---|
| Ubuntu | https://ubuntu.com/security/CVE-2023-45866 |
| Debian | https://security-tracker.debian.org/tracker/CVE-2023-45866 |
| Redhat | https://access.redhat.com/security/cve/cve-2023-45866 |
| Amazon Linux | https://explore.alas.aws.amazon.com/CVE-2023-45866.html |
| Fedora | https://lists.fedoraproject.org/archives/list/[redacted]/message/[redacted]/ |
| Gentoo | https://bugs.gentoo.org/919383 |
| Arch | https://gitlab.archlinux.org/archlinux/packaging/packages/bluez/-/commit/[redacted] |
| OpenEmbedded | https://git.openembedded.org/openembedded-core/commit/?h=kirkstone&id=[redacted] |
| Yocto | https://patchwork.yoctoproject.org/project/oe-core/patch/[redacted]/ |
| NixOS | https://github.com/NixOS/nixpkgs/blob/[redacted]/pkgs/os-specific/linux/bluez/default.nix#L45-L50 |
For CVE-2024-0230, the report notes that firmware updates for the Magic Keyboard were observed rolling out on 2023-01-09, and that a cursory evaluation suggests Apple has mitigated the attacks that exploit the Magic Keyboard over Lightning and Bluetooth. The Apple security release referenced is Magic Keyboard Firmware Update 2.0.6. The report says that section will be updated when more details are available, and the fix details for the affected models are listed as pending. Lockdown Mode on macOS mitigates the USB attack against the paired Mac.
Variants to test
- Keyboard-initiated pairing on other Bluetooth HID hosts. Try pairing an emulated keyboard that declares
NoInputNoOutputagainst a host that is discoverable and connectable. A positive result is a completed pairing with no user confirmation followed by a successful connection to L2CAP 17 and 19, which is the point at which keystroke injection becomes possible. - Discoverability windows. On Linux and Android, check whether L2CAP 17 and 19 are reachable whenever the host is discoverable, for example while a Bluetooth settings panel is open. A positive result is a successful connection to both ports without prior bonding.
- Known-peripheral gating. On macOS, iOS and Windows, test whether the ports are restricted to known peripherals by Bluetooth address, and whether a Broadcom-based adapter changes what is reachable. A positive result is reaching L2CAP 17 and 19 from an address the host does not know.
- Peripheral-side unauthenticated HID services. Look for peripherals that expose HID services while powered on and before they connect to their host, as the Magic Keyboard does. A positive result is the ability to read and write feature reports, and to receive keystrokes, as if you were the paired host.
- Race against reconnection. Reproduce the unplug scenario: connect to the peripheral's HID services before it reconnects to its host. A positive result is winning the race and reading the link key report; the report's own testing won roughly half the time.
- USB re-provisioning by identity. Check whether a host daemon resends a stored link key to a device that presents a known serial number and Bluetooth address. A positive result is receiving the link key over USB while the host is screen locked, and Lockdown Mode should block it.
- Re-pairing to an attacker host. Write out-of-band pairing data over the wired or unauthenticated Bluetooth channel and observe whether the peripheral then connects to the configured host. A positive result is the peripheral associating with the attacker-controlled machine.
What happened, in plain words
A security researcher found a family of problems in how Bluetooth keyboards talk to computers and phones. The short version: on several operating systems, an attacker can pretend to be a Bluetooth keyboard, get the computer to accept it without asking the user, and then type things on the victim's machine. Separately, an Apple Magic Keyboard can be made to hand over the secret code it uses to talk securely to its paired Mac, either through the charging port or over Bluetooth, and in some cases through the Mac's own USB port.
The report lives in a GitHub repository called skysafe/reblog, in a folder named cve-2024-0230, and the README is titled "Hi, My Name is Keyboard". The keystroke-injection problems are tracked as CVE-2023-45866 (Android, Linux/BlueZ, macOS, iOS) and CVE-2024-21306 (Windows). The Magic Keyboard key-extraction problem is tracked as CVE-2024-0230. Proof-of-concept scripts were to be released after the author's ShmooCon talk at roughly 3pm ET on January 13th.
A few words before we start, because the rest of this article leans on them.
Bluetooth is the short-range radio technology that lets a keyboard, mouse, headphones or phone talk to a computer without a cable. When two Bluetooth devices want to talk privately, they first pair: they agree on a shared secret code, called a link key, and use it to scramble everything they send each other. Think of pairing as two people agreeing on a password in person, and the link key as that password. Anyone who learns the password can join the conversation.
A CVE is a public catalogue number for a known security flaw. When you see CVE-2024-0230, read it as "the flaw registered under this identifier in 2024". It is just a name, like a case number.
A proof of concept (PoC) is a small program that demonstrates a flaw works, so other people can check it. It is not a weapon; it is evidence.
The background you need: how keyboards talk to computers
Before the flaws make sense, you need to know how a keyboard actually sends a keypress. The report gives a short primer, and it is worth going through slowly.
HID stands for Human Interface Device. It is the standard that covers keyboards, mice, game controllers and similar gadgets. HID devices do not send free-form text; they send small structured messages called reports. There are three kinds:
- Input reports carry things the device is telling the computer: a key was pressed, the mouse moved, a button was clicked.
- Output reports carry things the computer is telling the device: a command, a change of state, like turning on a Caps Lock light.
- Feature reports are used by the computer to read and write the device's settings. Think of them as a settings panel the computer can open on the device.
Reports do not care whether they travel over a cable or over the air. The same report can arrive over USB or over Bluetooth. That matters later: if you can send the right reports over Bluetooth, the computer cannot easily tell you apart from a real keyboard.
Bluetooth HID devices use a part of Bluetooth called Bluetooth Classic L2CAP. L2CAP is best imagined as a set of numbered doors on a device. Each door leads to a different service. Two doors matter here:
- L2CAP port 17 is the HID Control channel. Feature reports go through it. It is slower (high latency).
- L2CAP port 19 is the HID Interrupt channel. Input and output reports go through it. It is faster (low latency), because keypresses need to arrive quickly.
A Bluetooth HID link is considered established when both doors are connected. So, in plain terms: if you can get through doors 17 and 19 on a computer, you can send it keystrokes. That single sentence is the heart of the whole keystroke-injection story.
To reach those doors, a keyboard has to pair with the computer first. A few pairing terms:
- Link key: the shared secret that encrypts data between two Bluetooth devices.
- Pairing: the process that establishes the link key.
- Bonding: saving the link key to the device so you do not have to pair again next time.
- Out of band pairing: doing the pairing and bonding over a channel that is not Bluetooth, such as NFC (the tap-to-pay radio) or USB. "Out of band" just means "through a different route than the main one".
- Pairing capability: a declaration of which authentication methods a device supports. One specific value,
NoInputNoOutput, means "I have no screen and no keyboard, so I cannot show or type a code". A device that declaresNoInputNoOutputis saying it cannot take part in a code-based check.
The normal pairing flow, and what it should prevent
Normally the user starts pairing by picking a device from a list on the computer. The report draws that flow as a sequence diagram:
sequenceDiagram
User->>Host: please pair with this keyboard
Host->>Keyboard: I want to pair
Keyboard-->>Host: okay, I require authentication
Host-->>Keyboard: I also require authentication
Host->>User: please type this passkey on the keyboard
Keyboard-->>Host: here is the passkey
Host-->>Keyboard: looks good, let's establish a link key
Keyboard-->Host: <key exchange>
Keyboard->>Host: here are some keystrokes
Line by line, in plain words:
User->>Host: please pair with this keyboardmeans the person tells the computer (the host) to pair with a specific keyboard.Host->>Keyboard: I want to pairmeans the computer asks the keyboard to pair.Keyboard-->>Host: okay, I require authenticationmeans the keyboard agrees but says a check is needed.Host-->>Keyboard: I also require authenticationmeans the computer agrees to that check.Host->>User: please type this passkey on the keyboardmeans the computer shows a number on screen and asks the person to type it on the keyboard.Keyboard-->>Host: here is the passkeymeans the keyboard sends the number back.Host-->>Keyboard: looks good, let's establish a link keymeans the numbers matched, so the computer accepts and both sides set up the shared secret.Keyboard-->Host: <key exchange>is the actual exchange that produces the link key.Keyboard->>Host: here are some keystrokesmeans the keyboard is now trusted and can send keypresses.
The point of steps 5 and 6 is to prove that the person holding the keyboard is the same person looking at the screen. If the numbers match, both sides know they are talking to the right device.
Pairing can also start from the keyboard side. The report shows what should happen if a keyboard says it cannot do authentication:
sequenceDiagram
Keyboard->>Host: I want to pair
Host-->>Keyboard: okay
Keyboard-->>Host: I don't require authentication
Host-->>Keyboard: I require authentication
Host-->Keyboard: <pairing failed>
Line by line:
Keyboard->>Host: I want to pairmeans the keyboard asks the computer to pair.Host-->>Keyboard: okaymeans the computer is willing to try.Keyboard-->>Host: I don't require authenticationmeans the keyboard declares it cannot or will not do the code check.Host-->>Keyboard: I require authenticationmeans the computer says a check is required.Host-->Keyboard: <pairing failed>means the computer refuses, because the two sides cannot agree on a secure check.
That refusal is the correct behaviour. If the computer instead accepted a pairing request without authentication, an attacker could pair a keyboard without the user's consent. That is exactly the gap the report exploits: vulnerable devices support keyboard-initiated pairing and do not require authenticated pairing, so a keyboard, or a fake keyboard, can pair with them without the user confirming anything.
On the Magic Keyboard side, the observation is different. The keyboard exposes an unauthenticated Bluetooth HID service while its radio is on, and the out-of-band pairing data it holds over USB includes the link key. Both are places where the secret can leak.
Step 1: Forced pairing and keystroke injection
The attack flow is the keyboard-initiated flow with the authentication requirement removed on both sides:
Line by line:
Evil Keyboard->>Host: I want to pairmeans the attacker's device (a fake keyboard, often a small radio adapter driven by a laptop) asks the computer to pair.Host-->>Evil Keyboard: okaymeans the computer agrees to try.Evil Keyboard-->>Host: I don't require authenticationmeans the fake keyboard declaresNoInputNoOutput, i.e. it cannot do the code check.Host-->>Host: I also don't require authenticationmeans the computer, wrongly, decides it does not need the check either. This is the flaw.Evil Keyboard-->>Host: let's establish a link keymeans both sides set up the shared secret.Evil Keyboard-->Host: <key exchange>is the exchange that produces the link key.Evil Keyboard->>Host: here are some keystrokesmeans the fake keyboard now sends input reports over L2CAP port 19.User->>Host: WTF?is the person at the computer noticing that text is appearing on its own.
The emulated keyboard declares NoInputNoOutput, the host accepts pairing without authentication, a link key is established, and the attacker then sends input reports over L2CAP 19. The injected keystrokes perform actions as the user, so long as those actions do not require password or biometric authentication. In other words, the attacker can perform actions as the user, so long as those actions do not require password or biometric authentication.
The exposure differs per platform:
- Android is vulnerable when Bluetooth is enabled. The vulnerability is zero-click, and unpatched devices can be exploited whenever Bluetooth is enabled. "Zero-click" means the victim does not have to click or tap anything.
- Linux/BlueZ is vulnerable when Bluetooth is discoverable and connectable, typically when a "Bluetooth settings" dialog is open. It is zero-click, and unpatched hosts can be exploited when they are discoverable and connectable over Bluetooth. BlueZ is the standard Bluetooth software on Linux.
- macOS and iOS are vulnerable when the host is connecting to a paired Magic Keyboard. Both are zero-click, but can only be exploited when the Mac or iPhone is attempting to connect to a paired Magic Keyboard. In practice, a Mac is exploitable when the user unplugs their Magic Keyboard after pairing or charging, and an iPhone is exploitable when the user is connecting to their paired Magic Keyboard.
- Windows is vulnerable when a Bluetooth keyboard has been paired with the computer and the keyboard is powered off or out of range. The user has to interact with a malicious pairing request in any way: clicking accept, reject or close.
Why does the platform matter so much? Because of when the two doors (L2CAP 17 and 19) are reachable. On Linux and Android, they are open whenever the host is discoverable. On macOS, iOS and Windows, they are only open to known peripherals, identified by Bluetooth address. A Bluetooth address is a device's radio identifier. The Linux and Android attacks can be performed with almost any Bluetooth adapter, while the macOS, iOS and Windows attacks require a Broadcom-based Bluetooth adapter, a specific chip family.
Step 2: Understand the out-of-band pairing of the Magic Keyboard
Apple's Magic Keyboard can pair with a Mac over the charging cable instead of over the air. The report calls this out-of-band pairing, and it happens over USB HID when the keyboard is plugged into the Mac. The connection is accepted if the Mac is in Lockdown Mode, a stricter security setting on Apple devices. The sequence is:
- The Mac generates a random link key and stores it in the Keychain. The Keychain is Apple's encrypted store for passwords and secrets.
- The Mac sends the link key to the keyboard over USB, along with the Bluetooth address of the Mac.
- The keyboard stores the link key and Bluetooth address in memory.
- When the keyboard is unplugged from the Mac, it uses the address and link key to connect to the Mac over Bluetooth.
Why does this matter? Because the secret is now sitting in the keyboard's memory, and the report shows it can be read over the Lightning port or unauthenticated Bluetooth.
Step 3: Extract the link key from the Lightning port
After out-of-band pairing is performed, the link key remains in memory until the keyboard is switched off. An attacker with physical access to the keyboard can therefore extract the link key by connecting to the Lightning port and reading the appropriate HID report. This works if the keyboard has not been powered off since the last time it was plugged into the Mac.
In plain words: if you can get your hands on the keyboard while it is still on, and plug something into its charging port, you can ask it for the secret through the same HID feature-report mechanism a computer would use. The Lightning port exposes the link key through an unauthenticated HID report.
Step 4: Extract the link key over unauthenticated Bluetooth
An unauthenticated Bluetooth HID service is available on the Magic Keyboard when the Bluetooth radio is powered on, persisting until the keyboard connects to the Mac via Bluetooth or Lightning/USB. This occurs when the Magic Keyboard is switched on, and again when it is unplugged from the Mac.
An unauthenticated attacker can connect to the keyboard and send and receive HID messages as if they were the paired Mac. That includes receiving keystrokes and reading and writing HID feature reports. When the Magic Keyboard is unplugged from the Mac, the attacker can connect to these services and extract the link key by reading the appropriate HID report.
This attack depends on a race condition: the attacker must connect to the Bluetooth HID services on the Magic Keyboard before the keyboard connects to the Mac. A race condition is when two things are trying to happen at the same time and the outcome depends on who gets there first. In testing, the attacker wins the race approximately 50% of the time, roughly a coin flip.
Step 5: Extract the link key from the USB port on the Mac
The first time the Magic Keyboard is plugged into the Mac, the Bluetooth daemon generates a random link key and sends it to the keyboard over USB. A daemon is a background program that runs without a visible window. The next time the keyboard is plugged into the Mac, the Bluetooth daemon recognises the keyboard using its serial number and Bluetooth address, and resends the original link key.
If an attacker knows the Bluetooth address and serial number of a Magic Keyboard paired with a Mac, they can spoof the Magic Keyboard and read the link key from the USB port on the Mac, which can be screen locked. To spoof means to pretend to be something you are not. The serial number and Bluetooth address are not secrets. This attack is mitigated by Lockdown Mode on macOS.
Step 6: Pair the Magic Keyboard to a different host
An attacker can pair the Magic Keyboard with a different computer by writing out-of-band pairing data over Lightning/USB or unauthenticated Bluetooth. After the OOB pairing data is written, the Magic Keyboard will connect to the attacker-configured host. In plain words: the attacker writes new pairing data to the keyboard, and it connects to the attacker's computer.
Why it works: the root cause
The keystroke-injection issue is a design mistake in the pairing state machine. A state machine is the set of rules a device follows to move from one situation to another, like a traffic light moving from red to green. The host accepts a keyboard-initiated pairing where the peripheral declares NoInputNoOutput and the host itself does not require authenticated pairing. The expected behaviour, rejecting a pairing request that does not support authentication, is not enforced. Because a HID link is established once L2CAP 17 and 19 are connected, accepting the pairing is enough to allow input reports to be injected. The per-platform differences in exposure come from when those L2CAP ports are reachable: always when discoverable on Linux and Android, and only to known peripherals on macOS, iOS and Windows.
The Magic Keyboard issue is that the link key, which is the long-term secret protecting the Bluetooth link, is held in memory and exposed through channels that do not authenticate the caller: the Lightning port while the keyboard stays powered, and the unauthenticated Bluetooth HID service that is up until the keyboard connects to its Mac. The USB attack against the Mac relies on the daemon resending the stored link key to anything that presents the keyboard's serial number and Bluetooth address, which are not secrets. Lockdown Mode is the control that blocks that last path.
What an attacker can do with it
For the keystroke-injection issues, an attacker can pair an emulated keyboard and inject keystrokes to perform actions as the user, so long as those actions do not require password or biometric authentication. The affected versions listed in the report are:
| Product | Versions | CVE | Status | Notes |
|---|---|---|---|---|
| Android | 4.2, 5, 6, 7, 8, 9, 10 | CVE-2023-45866 | no fix available | Android 3 and earlier were not tested |
| Android | 11, 12, 13, 14 | CVE-2023-45866 | fixed in 2023-12-05 security patch level | |
| Linux (BlueZ) | affected distros | CVE-2023-45866 | BlueZ patch available | |
| macOS | 12, 13 | CVE-2023-45866 | no fix available | macOS 11 and earlier were not tested |
| macOS | 14 | CVE-2023-45866 | fixed in macOS 14.2 | |
| iOS | 16 | CVE-2023-45866 | no fix available | iOS 15 and earlier were not tested |
| iOS | 17 | CVE-2023-45866 | fixed in iOS 17.2 | |
| Windows | 10, 11, Server 2022 | CVE-2024-21306 | fixed in January 2024 Patch Tuesday | earlier versions of Windows were not tested |
A security patch level is the date of the last set of security fixes a phone has received. "Patch Tuesday" is Microsoft's monthly day for releasing fixes, the second Tuesday of each month.
For CVE-2024-0230, the Magic Keyboard link key can be read via the Lightning port if the keyboard has not been powered off since the last time it was plugged into the Mac, via unauthenticated Bluetooth when the keyboard gets unplugged from its Mac, and via the USB port on the paired Mac if Lockdown Mode is not enabled. The affected versions listed are:
| Product | Model | CVE | Vector | Status |
|---|---|---|---|---|
| macOS | 12, 13, 14 | CVE-2024-0230 | USB | fix details pending |
| Magic Keyboard | A2449 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Keyboard | A2450 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Keyboard | A2520 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Keyboard | A1843 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
| Magic Mouse | A1657 | CVE-2024-0230 | Lightning, Bluetooth | fix details pending |
"Vector" here just means the route the attack takes: the cable, the radio, or the Mac's USB port. With the link key, an attacker can spoof the Magic Keyboard to the paired Mac and can also re-pair the keyboard to an attacker-controlled host.
What was fixed, and when
For the keystroke-injection issues, the report records the following fixes: Android 11 through 14 fixed in the 2023-12-05 security patch level; a BlueZ patch available in the kernel tree; macOS 14.2 and iOS 17.2 fixed; and Windows 10, 11 and Server 2022 fixed in the January 2024 Patch Tuesday. Android 4.2 through 10, macOS 12 and 13, and iOS 16 had no fix available at the time of writing. The report also lists patch information published by Linux distributions, which it notes is not intended to be a complete list of vulnerable distributions:
| Distribution | Patch information |
|---|---|
| Ubuntu | https://ubuntu.com/security/CVE-2023-45866 |
| Debian | https://security-tracker.debian.org/tracker/CVE-2023-45866 |
| Redhat | https://access.redhat.com/security/cve/cve-2023-45866 |
| Amazon Linux | https://explore.alas.aws.amazon.com/CVE-2023-45866.html |
| Fedora | https://lists.fedoraproject.org/archives/list/[redacted]/message/[redacted]/ |
| Gentoo | https://bugs.gentoo.org/919383 |
| Arch | https://gitlab.archlinux.org/archlinux/packaging/packages/bluez/-/commit/[redacted] |
| OpenEmbedded | https://git.openembedded.org/openembedded-core/commit/?h=kirkstone&id=[redacted] |
| Yocto | https://patchwork.yoctoproject.org/project/oe-core/patch/[redacted]/ |
| NixOS | https://github.com/NixOS/nixpkgs/blob/[redacted]/pkgs/os-specific/linux/bluez/default.nix#L45-L50 |
A distribution is a packaged version of Linux, like Ubuntu or Fedora. Each one ships its own copy of BlueZ and publishes its own fix.
For CVE-2024-0230, the report notes that firmware updates for the Magic Keyboard were observed rolling out on 2023-01-09, and that a cursory evaluation suggests Apple has mitigated the attacks that exploit the Magic Keyboard over Lightning and Bluetooth. Firmware is the small program built into a device, which can be updated separately from the operating system. The Apple security release referenced is Magic Keyboard Firmware Update 2.0.6. The report says that section will be updated when more details are available, and the fix details for the affected models are listed as pending. Lockdown Mode on macOS mitigates the USB attack against the paired Mac.
Things worth testing if you want to explore further
The report lists variants to test. These are ideas for other researchers, not instructions for the public.
- Keyboard-initiated pairing on other Bluetooth HID hosts. Try pairing an emulated keyboard that declares
NoInputNoOutputagainst a host that is discoverable and connectable. A positive result is a completed pairing with no user confirmation followed by a successful connection to L2CAP 17 and 19, which is the point at which keystroke injection becomes possible. - Discoverability windows. On Linux and Android, check whether L2CAP 17 and 19 are reachable whenever the host is discoverable, for example while a Bluetooth settings panel is open. A positive result is a successful connection to both ports without prior bonding.
- Known-peripheral gating. On macOS, iOS and Windows, test whether the ports are restricted to known peripherals by Bluetooth address, and whether a Broadcom-based adapter changes what is reachable. A positive result is reaching L2CAP 17 and 19 from an address the host does not know.
- Peripheral-side unauthenticated HID services. Look for peripherals that expose HID services while powered on and before they connect to their host, as the Magic Keyboard does. A positive result is the ability to read and write feature reports, and to receive keystrokes, as if you were the paired host.
- Race against reconnection. Reproduce the unplug scenario: connect to the peripheral's HID services before it reconnects to its host. A positive result is winning the race and reading the link key report; the report's own testing won roughly half the time.
- USB re-provisioning by identity. Check whether a host daemon resends a stored link key to a device that presents a known serial number and Bluetooth address. A positive result is receiving the link key over USB while the host is screen locked, and Lockdown Mode should block it.
- Re-pairing to an attacker host. Write out-of-band pairing data over the wired or unauthenticated Bluetooth channel and observe whether the peripheral then connects to the configured host. A positive result is the peripheral associating with the attacker-controlled machine.
Glossary
- Bluetooth: a short-range radio technology for connecting nearby devices without cables.
- Link key: the shared secret code two Bluetooth devices use to encrypt their traffic.
- Pairing: the process of two Bluetooth devices agreeing on a link key.
- Bonding: saving the link key so the devices do not have to pair again.
- Out-of-band pairing: pairing and bonding done over a channel other than Bluetooth, such as USB or NFC.
NoInputNoOutput: a pairing capability meaning the device has no screen and no keyboard, so it cannot show or type a code.- HID: Human Interface Device, the standard for keyboards, mice and similar gadgets.
- Report: a small structured message a HID device sends or receives.
- Input report: a report carrying keypresses or mouse movement to the computer.
- Output report: a report carrying commands or state changes to the device.
- Feature report: a report the computer uses to read or write device settings.
- L2CAP: a part of Bluetooth that provides numbered channels, like doors, to different services.
- L2CAP port 17: the HID Control channel, used for feature reports, slower.
- L2CAP port 19: the HID Interrupt channel, used for input and output reports, faster.
- Host: the computer or phone that a peripheral connects to.
- Peripheral: the device that connects to a host, such as a keyboard or mouse.
- Bluetooth address: a device's radio identifier, similar to a hardware serial number; not a secret.
- CVE: a public catalogue number for a known security flaw.
- Zero-click: an attack that needs no action from the victim.
- Proof of concept (PoC): a small program that demonstrates a flaw works.
- BlueZ: the standard Bluetooth software on Linux.
- Daemon: a background program that runs without a visible window.
- Keychain: Apple's encrypted store for passwords and secrets.
- Lockdown Mode: a stricter security setting on Apple devices.
- Spoof: to pretend to be a device or person you are not.
- Race condition: a situation where the outcome depends on which of two things happens first.
- State machine: the set of rules a device follows to move from one situation to another.
- Firmware: the small program built into a device, updatable separately from the operating system.
- Security patch level: the date of the last set of security fixes a phone has received.
- Patch Tuesday: Microsoft's monthly day for releasing security fixes.
- Distribution: a packaged version of Linux, such as Ubuntu or Fedora.
- Broadcom-based adapter: a Bluetooth adapter built on chips from Broadcom, a specific chip family.
- Vector: the route an attack takes, such as a cable, the radio, or a USB port.