Replay Attacking a Car’s Remote Keyless Entry

In this guide, we will take a look at a few exploits that target remote keyless entry (RKE) systems in modern vehicles. We will learn the theory behind the generic rolljam attack and also implement a specific attack on Subaru vehicles.

SubaruFobRob

SubaruFobRob is an exploit for certain remote keyless entry (RKE) systems in Subaru vehicles developed by Tom Wimmenhove. It allows an attacker to issue unlock, lock, trunk, and panic commands without possession of the original key fob. This type of attack is far from new, but SubaruFobRob was a great way to get myself oriented into the growing field of car hacking. I was able to conveniently test the exploit on my 2007 Subaru Legacy.

How do RKEs Work?

A remote keyless entry system uses your familiar, battery-powered vehicle keys to communicate with your car over radio frequencies. A typical key fob contains a chip capable of generating pseudo-random keys (called rolling codes), a unique hard coded identifier, and an antenna to transmit the final packet over 433MHz radio frequency. The receiver in your car contains an identically seeded pseudo-random number generator that yields the same sequence of random keys and knows the hard-coded identifier.

Because of the possibility that a key fob may be "rolled" while out of range of the vehicle, the receiver pre-generates the next 256 possible keys and accepts any one of them. If an attacker sends a rolling code that is sufficiently farther in the pseudo-random sequence than the last code on the key fob's chip, the key fob is rendered useless (I elected not to test this additional attack on my car).

Due to the fact that most RKEs are single packets and not challenge-response, they can be replay attacked.

The Exploit

While a traditional key fob will be using a pseudo-random sequence of rolling codes, the list of affected Subaru vehicles below opted to use an incremental sequence instead. This is a major security weakness when combined with the fact that the packet that contains the code does not receive any additional encryption before transmission. Lets take a look at a sample packet sent with Subaru RKEs:

The preamble is the location of the identifier unique to each key and receiver combination. This prevents a brute force attack on rolling codes (with the unique key, you could exploit the 256 padding that the receiver gives to iterate through the 20 bit rolling codes with only 4096 attempts). But since the only way to pursue that attack vector is to capture a packet, we might as well use the incremental weakness instead for instant control.

With a captured packet, we simply need to increment the embedded rolling code by a value of 1 to get the next code, modify the command bits to suit our need, and recalculate the checksum.

The following commands are available:
0x81 - Lock
0x82 - Unlock
0x8A - Panic
0x8B - Trunk

The Checksum Algorithm:

public static byte calcChecksum(byte[] packet) {
    byte sum = 0;
    for(int i = 0; i < 10 - 1; i++) {
        sum = (byte)(Byte.toUnsignedInt(sum) ^ Byte.toUnsignedInt(packet[i]) & 0xf);
        sum = (byte)(Byte.toUnsignedInt(sum) ^ Byte.toUnsignedInt(packet[i]) >> 4 & 0xf);
    }
    sum = (byte)(Byte.toUnsignedInt(sum) ^ Byte.toUnsignedInt(packet[9]) >> 4 & 0xf);
    sum = (byte)(Byte.toUnsignedInt(sum) + 1);
    sum = (byte)(Byte.toUnsignedInt(sum) & 0xf);
    return sum;
}

Affected Vehicles

2006 Subaru Baja
2005 - 2010 Subaru Forester
2004 - 2011 Subaru Impreza
2005 - 2010 Subaru Legacy
2005 - 2010 Subaru Outback

Replay Attacking

The most common and versatile replay attack for a key fob consists of the following steps:

  1. The attacker starts jamming the receiver in the vehicle
  2. The owner sends a valid packet to the vehicle via their key
  3. The attacker records this packet
  4. The owner, likely unfazed, sends another packet with the next rolling code
  5. The attacker records this code as well
  6. The attacker stops jamming the receiver
  7. The attacker relays the first packet they recorded (still valid) and holds on to the next packet
  8. The attacker uses their second packet the next time the owner leaves the vehicle unattended

However because of Subaru's poor implementation of rolling codes, they are afflicted with a much more dangerous replay attack:

  1. The attacker begins listening without jamming
  2. The owner sends a packet with a valid rolling code
  3. The attacker records this packet and can manipulate it via the subarufobrob exploit
  4. The attacker sends a crafted packet at any time in the future

Putting it All Together

To start this project we need the following hardware:

I configured a raspberry pi 3 to run hostapd to allow easy ssh from my phone. The drivers for the USB dongle can be installed via the debian package librtlsdr-dev. To transmit, I soldered the wire to GPIO18 and compiled rpitx.

Then I set up subarufobrob to handle the exploitation. After tucking it all into a small box, the working package looks like this:

It worked immediately out of the box on my test vehicle. Unfortunately, this type of vulnerability is unlikely to be retroactively fixed. RKEs have improved their security in recent years but not enough attention is given to these old exploitable systems.

Leave a Reply

Your email address will not be published. Required fields are marked *