Skip to content
Info disclosure Write-up Advanced

fastboot oem sha1sum

The Pixel bootloader's fastboot oem sha1sum command allowed an attacker with physical access or ADB to compute SHA1 hashes of arbitrary partition ranges, leaking sensitive data via preimage attacks. Google patched it to prevent running the command on arbitrary partitions.

Roee Hay Follow

Published on securityresear.ch

In the January 2017 Android Security Bulletin, Google provided a patch to CVE-2016-8462, an interesting vulnerabiltiy in the Pixels’ bootloader. I reported this issue to Google last December, but unfortunately got beat by Jon Sawyer (@jcase) and Sean Beaupre (@firewaterdevs), who reported it in October, so kudos to…

Roee Hay, on securityresear.ch

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 3 min read.

Context

In the January 2017 Android Security Bulletin, Google published a patch for CVE-2016-8462, a vulnerability in the bootloader of the Pixel devices. The issue concerns a proprietary fastboot oem command named sha1sum that the Pixel bootloader exposes. The command takes three arguments: a partition name, a size and an offset, with the constraint that size must be greater than or equal to offset. The command computes a SHA-1 digest over a range of bytes of a partition, and it could be run against an arbitrary partition.

The researcher reported the issue to Google in December 2016. Jon Sawyer (@jcase) and Sean Beaupre (@firewaterdevs) had reported the same issue in October 2016, so the credit for the discovery goes to them.

Setup

It requires physical access to the device, or a malicious charger, or a malicious host with ADB access that can reboot the device into the bootloader. From there the attacker can issue fastboot oem sha1sum commands against partitions of their choosing. The researcher built a proof of concept, published at github.com/roeeh/PoC/tree/master/CVE-2016-8462, and ran it against the board_info partition.

Finding it

The bootloader contains a proprietary fastboot oem command, sha1sum, which accepts a partition name, a size and an offset, with the constraint that size >= offset. Because the command lets the caller name any partition and any range, an attacker can compute the preimage of the first bytes of any partition, which may allow the attacker to leak sensitive information out of the device. Beyond the first bytes, a preimage attack on higher offsets is possible when a specific pattern is approximately known, such as a known suffix or a known prefix.

Exploitation

Step 1: Reach the bootloader

The attacker needs the device in fastboot mode. This can be achieved with physical access, with a malicious charger, or from a malicious host that has ADB access and can reboot the device into the bootloader.

Step 2: Run the PoC against board_info

The researcher ran the PoC twice against the board_info partition. The first run leaked bytes 0 to 7, which read HTC-BOAR. The second run leaked bytes 158 to 161, which read \xA2\x80\x00\x00. The exact command lines are not reproduced in the report; the PoC itself is linked above.

Step 3: Recover the plaintext from the digest

Because the command returns a SHA-1 digest of the requested range, the attacker guesses candidate plaintext for that range and hashes it until the digest matches. For higher offsets, the attack works when a pattern is approximately known, such as a known suffix or prefix, which narrows the candidate space enough to brute force the unknown bytes.

Root cause

The sha1sum command could be run against an arbitrary partition, and Google's patch now prevents that.: an attacker who can issue the command can obtain a digest of any range of any partition and use it to test guesses about the underlying bytes.

Impact

An attacker with physical access, a malicious charger, or a malicious host with ADB access can compute the preimage of the first bytes of any partition and leak sensitive information out of the device. The same technique can be extended to higher offsets when a specific pattern is approximately known, such as a known suffix or a known prefix. The report does not state which kinds of sensitive data were recovered beyond the board_info example.

Fix

Google's patch prevents running the command on an arbitrary partition. The report does not describe the exact mechanism of the restriction.

Variants to test

  1. A positive result is a command that returns data derived from an arbitrary partition without an unlock or authorisation check.
  2. A positive result is a digest that matches a guessed plaintext for a partition the attacker should not be able to read.
  3. Higher offsets on the same partition when a known prefix or suffix is present. A positive result is a digest that matches a candidate built from the known pattern plus brute-forced unknown bytes.
  4. A positive result is reaching the bootloader and issuing the command without physical interaction beyond plugging in the cable or rebooting over ADB.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

Every phone has a small piece of software that runs before the main operating system starts. It is called the bootloader, and its job is to wake up the hardware and then hand control to Android.

On Google's Pixel phones, the bootloader included a special maintenance command called sha1sum. The command lets the caller ask the bootloader for a short fingerprint of bytes in a named area of storage. The fingerprint is a hash, a fixed-length value computed from data so that any change to the data changes the fingerprint.

That command accepted a partition name, a size and an offset, with the constraint that size must be greater than or equal to offset. Anyone who could get the phone into the bootloader's maintenance mode, called fastboot, could ask for fingerprints of areas they were never meant to see. By guessing what those areas contain and comparing guesses against the returned fingerprint, an attacker can work out the real contents, a little at a time. That is the vulnerability: a legitimate feature that leaks information because it was not restricted.

Google fixed it in the January 2017 Android Security Bulletin, under the identifier CVE-2016-8462. The researcher reported the issue to Google in December 2016, but Jon Sawyer (@jcase) and Sean Beaupre (@firewaterdevs) had reported the same problem in October 2016, so the credit for finding it goes to them.

The pieces you need to know

Before the steps make sense, here are the ideas involved, each with a plain comparison.

  • Bootloader: the first program that runs when a phone powers on. Think of it as the building's caretaker who unlocks the doors and switches on the lights before the tenants (Android) arrive. The caretaker has keys to rooms the tenants never enter.
  • Fastboot: a mode and a protocol for talking to the bootloader from a computer over a USB cable. Think of it as the service hatch on the side of the building, used by technicians with a laptop.
  • Partition: a named, separate region of the phone's storage. Think of the phone's storage as a filing cabinet with labelled drawers: one drawer for the system, one for user data, one for radio firmware, and so on. board_info is the name of one such drawer.
  • fastboot oem command: oem means the phone maker added its own commands on top of the standard fastboot ones. Think of standard fastboot as the public list of buttons in the service hatch, and oem commands as extra buttons the manufacturer installed for its own use.
  • Hash (SHA-1 digest): a mathematical fingerprint of some data. Feed in bytes, get back a short fixed-length value. The same bytes always give the same fingerprint, and different bytes almost always give a different one. Think of it as a wax seal pressed onto a document: it tells you whether the document is the one you expected, without showing you the document.
  • Preimage attack: working backwards from a fingerprint to the data that produced it. Because a hash cannot practically be reversed by maths, the attacker instead guesses candidate data, hashes each guess, and checks whether the result matches the fingerprint. Think of a locked briefcase with a three-digit combination: you do not pick the lock, you try 000, 001, 002 and so on until it opens. This only works when the number of plausible guesses is small.
  • Offset and size: an offset is a starting position counted in bytes from the beginning of a partition; a size is how many bytes to cover. Think of a book: offset is the page you start on, size is how many pages you read.
  • ADB: the Android Debug Bridge, a standard tool that lets a computer send commands to an Android device, including a command to reboot it. Think of it as a remote control for the phone.
  • Malicious charger or malicious host: a USB device that looks harmless, such as a charger, but actually sends commands to the phone. Think of a fake key-cutting machine that, while pretending to sharpen your key, also copies it.
  • CVE: a public catalogue number for a known security flaw, so that everyone can refer to the same issue unambiguously.

Setup

What is required is one of three things:

  1. Physical access to the phone, so you can hold the right buttons at power-on and enter fastboot.
  2. A malicious charger, which plugs into the USB port and issues fastboot commands instead of merely supplying power.
  3. A malicious host with ADB access, which can send the reboot command that restarts the phone into the bootloader.

Once the phone is in fastboot mode, the attacker can send fastboot oem sha1sum commands naming partitions of their choosing. The researcher wrote a proof of concept, a small program that demonstrates the attack, and published it at github.com/roeeh/PoC/tree/master/CVE-2016-8462. The runs described below were made against the board_info partition.

Finding it

The bootloader contains a proprietary fastboot oem command, sha1sum. It accepts three arguments: a partition name, a size and an offset, with the constraint that size must be greater than or equal to offset.

Why does that matter? Because the command lets the caller name any partition and any range inside it. The command was presumably intended to check a known area, for example to verify that firmware had been written correctly. But nothing in the interface stopped a caller from naming a partition the caller should not be able to read.

The result is that an attacker can compute the SHA-1 preimage of the first bytes of any partition. In other words, the attacker can recover the actual first bytes, not just their fingerprint, by guessing and checking. That is enough to leak sensitive information out of the device.

The same idea extends beyond the first bytes. A preimage attack on higher offsets is possible when a specific pattern is approximately known, such as a known suffix or a known prefix. If you already know most of the bytes in a range, you only have to guess the few unknown ones, and the number of guesses becomes small enough to try them all.

Exploitation

Step 1: Reach the bootloader

The attacker first needs the phone in fastboot mode. This can be achieved in three ways:

  1. With physical access to the device.
  2. With a malicious charger that speaks the fastboot protocol over USB.
  3. From a malicious host that has ADB access and can reboot the phone into the bootloader.

Step 2: Run the PoC against board_info

The researcher ran the PoC twice against the board_info partition.

  • The first run leaked bytes 0 to 7, which read HTC-BOAR.
  • The second run leaked bytes 158 to 161, which read \xA2\x80\x00\x00.

The exact command lines are not reproduced in the report; the PoC itself is linked above. The notation \xA2 means a single byte whose value is written in hexadecimal, so the second result is four bytes: A2, 80, 00, 00.

Step 3: Recover the plaintext from the digest

Because the command returns a SHA-1 digest of the requested range, the attacker guesses candidate plaintext for that range and hashes it until the digest matches.

For the first bytes of a partition, the candidate space is often small enough to enumerate.

For higher offsets, the attack works when a pattern is approximately known, such as a known suffix or prefix. Knowing part of the content narrows the candidate space enough to brute force the unknown bytes. Brute force here means trying every possibility in a small set, one after another, as with the briefcase combination.

Root cause

The design mistake is that the sha1sum command was allowed to run against an arbitrary partition. The sha1sum command could be run against an arbitrary partition, and Google's patch now prevents that.: a service that answers questions. An attacker who can issue the command can obtain a digest of any range of any partition and use it to test guesses about the underlying bytes.

Think of a librarian who will not show you a sealed letter but will happily answer yes or no to "does this letter start with these words?". Ask enough yes or no questions and you can reconstruct the letter.

Impact

An attacker with physical access, a malicious charger, or a malicious host with ADB access can compute the preimage of the first bytes of any partition and leak sensitive information out of the device. The same technique can be extended to higher offsets when a specific pattern is approximately known, such as a known suffix or a known prefix.

The report does not state which kinds of sensitive data were recovered beyond the board_info example.

Fix

Google's patch prevents running the command on an arbitrary partition. The report does not describe the exact mechanism of the restriction.

Variants to test

  1. A positive result is a command that returns data derived from an arbitrary partition without an unlock or authorisation check.
  2. A positive result is a digest that matches a guessed plaintext for a partition the attacker should not be able to read.
  3. Higher offsets on the same partition when a known prefix or suffix is present. A positive result is a digest that matches a candidate built from the known pattern plus brute-forced unknown bytes.
  4. A positive result is reaching the bootloader and issuing the command without physical interaction beyond plugging in the cable or rebooting over ADB.

Glossary

  • ADB (Android Debug Bridge): a standard tool that lets a computer send commands to an Android device, including rebooting it.
  • Bootloader: the first program that runs when a phone powers on, which prepares the hardware and then starts Android.
  • Brute force: trying every possibility in a set, one after another, until the right one is found.
  • CVE: a public catalogue number for a known security flaw.
  • Digest: the short fixed-length output of a hash function, used as a fingerprint of data.
  • Fastboot: a mode and protocol for sending commands to a phone's bootloader over USB.
  • Hash (SHA-1): a mathematical function that turns data into a short fixed-length fingerprint; the same data always gives the same fingerprint.
  • Malicious charger: a USB device that looks like a charger but sends commands to the phone.
  • Malicious host: a computer that connects to the phone and sends commands the owner did not intend.
  • Offset: a starting position counted in bytes from the beginning of a partition.
  • Oracle: a service that answers questions about data the questioner cannot see, which can be used to reconstruct that data.
  • oem command: a command added by the phone manufacturer on top of the standard fastboot commands.
  • Partition: a named, separate region of a phone's storage, such as the system, user data or board_info.
  • Preimage attack: recovering the data behind a hash by guessing candidates and hashing them until one matches.
  • Proof of concept (PoC): a small program that demonstrates that an attack works.
  • Rooted: having full administrator rights inside Android.
  • SHA-1: the specific hash function used by the sha1sum command.
  • Unlocked bootloader: a bootloader whose manufacturer restriction on what it will accept has been removed.
  • Vulnerability: a weakness in software that allows someone to do something the designer did not intend.

More by Roee Hay

View all

1 more disclosed report, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.