Hacking Boston Transit Cards

Reverse engineering the MBTA's MIFARE Classic cards

2020Security ResearchRFID
Responsible Disclosure

This research was conducted for educational purposes in 2020. The vulnerabilities discussed here were disclosed to the MBTA in 2023 by a group of students who presented their findings at DEFCON 31. The MBTA has since begun transitioning to more secure card technologies as part of their AFC 2.0 program. The findings discussed here only apply to the original MIFARE Classic cards, and should be used for educational purposes only.

Overview

The Massachusetts Bay Transportation Authority (MBTA) operates transit services in the Greater Boston area. The MBTA's RFID card, called the Charlie Card, uses MIFARE Classic, a widely deployed contactless smart card technology. MIFARE Classic is known to be vulnerable to bruteforce cryptanalysis. Through security research in 2020, I discovered that all Charlie Cards use a common set of keys that can be recovered through a bruteforce attack.

Additionally, the MBTA does not use a server to store card balance, opting to store card balance directly on the card itself. I reverse engineered the common set of Charlie Card encryption keys, the card's data structure, and the checksum algorithm, allowing one to modify the card's balance.

MIFARE Classic Charlie Card

Background

MIFARE is a family of high-frequency (13.56 MHz) RFID technology created by Dutch semiconductor company NXP. MIFARE cards differ from traditional RFID cards in that they store some amount of data, ranging from 1 KB to 8 KB, and allow for read and write operations on this data. While newer MIFARE versions use AES and DES, the original version of MIFARE, called MIFARE Classic, used a lightweight proprietary encryption algorithm created by NXP, called Crypto-1.

MIFARE Classic cards have been the backbone of transit and hotel systems worldwide since the 1990s. Instead of authenticating a card's ID to a server, these systems opted instead to trust the data on the card itself, which contains information like the card's balance, room number, etc. This allows reader systems to operate entirely offline.

Some other popular cards that use MIFARE Classic:

In March of 2008, researchers from Radboud University in the Netherlands published this paper revealing fundamental weaknesses in Crypto-1, effectively breaking the security model that thousands of transit and hotel systems relied upon. That same year, three MIT undergrads, Zack Anderson, RJ Ryan, and Alessandro Chiesa, reverse engineered the CharlieCard and CharlieTicket systems for a class project and prepared a DEF CON talk on what they found. The MBTA sued them days before the talk and got a temporary restraining order blocking it, but a judge lifted the order about a week later, ruling the MBTA was unlikely to win on the merits. It's a good reminder that this kind of research has a long, occasionally litigious history in Boston specifically.

MIFARE Classic Memory Structure

A MIFARE Classic 1K card contains 1024 bytes of EEPROM memory, organized into 16 sectors. Each sector consists of 4 blocks, with each block holding 16 bytes of data. That is 64 blocks total (numbered 0-63).

The memory layout follows a specific structure:

MIFARE Classic 1K memory map
  • Block 0 (Sector 0, Block 0): The manufacturer block, containing the card's unique 4-byte UID, manufacturer data, and check bytes. This block is read-only and set at the factory.
  • Blocks 1-2 (Sector 0): Available for data storage.
  • Block 3 (Sector 0): The sector trailer, containing Key A (6 bytes), access bits (4 bytes), and Key B (6 bytes).

This pattern repeats for all 16 sectors. The last block of each sector (blocks 3, 7, 11, 15, etc.) is always the sector trailer that controls access permissions. The access bits define what operations (read, write, increment, decrement) are allowed with Key A versus Key B.

The access bits are stored with redundant inverted copies so the card can detect corruption. If they become corrupted, the entire sector becomes permanently inaccessible, which is a security feature that can also brick cards if manipulated incorrectly.

The Proxmark

The Proxmark3 is an open source RFID research platform that can read, write, sniff, and emulate both low and high frequency cards, including MIFARE Classic. Unlike a cheap USB NFC reader, it runs its own firmware on an onboard ARM processor, so attacks like the Darkside and nested authentication attacks described below execute locally instead of round-tripping every command over USB. I flashed mine with the community RRG/Iceman firmware, which layers a large set of MIFARE-specific attack scripts on top of the stock firmware.

Its eavesdrop mode ended up being the most useful feature for this project: held near a legitimate reader, the Proxmark can passively record the authentication exchange between the reader and a card without the card or reader ever knowing it's there.

Proxmark3 Device

The Attack

Key Recovery

The first step was recovering the sector keys. MIFARE Classic's Crypto-1 cipher has well-documented cryptographic weaknesses, and several attack vectors exist for key recovery.

The most reliable approach is a two-stage attack. First, recover at least one sector key with a Darkside attack (implemented by mfcuk), which exploits flaws in the card's PRNG and how it responds to failed authentication attempts. By analyzing error responses and timing, this attack can recover a single key without any prior knowledge, though it can take several minutes to hours depending on the card.

Alternatively, if you have access to a legitimate reader, you can sniff the authentication exchange between the reader and card using a Proxmark in eavesdrop mode. The captured nonces and encrypted responses can then be analyzed offline to recover the key.

Once I had a single valid key, I used mfoc (MIFARE Classic Offline Cracker) to perform the nested authentication attack. That recovers all remaining sector keys in under a minute by authenticating to the known sector, then initiating authentication to unknown sectors. Predictable nonce generation lets the unknown keys be derived mathematically.

What I found was alarming: the MBTA uses an identical set of keys across their entire CharlieCard fleet. There is no key diversification. Once you recover the keys from a single card, you have the keys to read and write every CharlieCard in circulation.

Card Layout

These are the sectors of a MIFARE Classic Charlie Card, and what each one holds. I'm leaving the recovered key values themselves out of this table; they're already well documented elsewhere, and reproducing them here doesn't add anything beyond what a search turns up.

SectorContents
0Manufacturer block, card magic
1Magic / mostly unused
2Fare balance: current and previous value registers, timestamp, checksum
3Unknown; possibly unused
4Unknown; mostly static zeros
5Unknown; mostly static zeros
6Transaction log
7Transaction log
8Secondary serial (rest unused)
9-15Unused (0xff filled)

Sectors 6 and 7 hold the rotating trip history: timestamps, station/location codes, transaction type, and fare amounts. Sector 8 stores the secondary serial printed in small text on the card. Sectors 9 through 15 are blank filler, each with its own unique key pair for no obvious reason.

Analyzing Card Data

With the keys recovered, I dumped the card's memory and reverse engineered the data format by hand. Transit card formats are proprietary and undocumented, so the only path forward was comparing dumps.

I started by comparing hex dumps from multiple cards and from the same card at different fare values. By adding $5 to my card and comparing before/after dumps, I could identify which bytes changed. I originally assumed this meant the balance was duplicated across sectors 2 and 3, rotating between them, but that's not quite right: the live balance sits in a single block inside sector 2, which stores two 16-bit fields side by side, the current balance and the previous balance, immediately followed by a checksum. Both values are recorded in half-cents rather than cents, so a $1.25 balance shows up as the raw number 250, not 125.

One interesting mechanism was the rotating transaction log in sectors 6/7. Rather than writing transaction data to a fixed location, the card cycles through multiple blocks to record trip history. Each entry includes a sequence number, and the system reads all entries to find the most recent valid one. That makes simple replay attacks harder, since restoring an old block without matching sequence numbers reveals the tampering.

Cracking the Checksum

Every data block ends with a 2-byte checksum, and it clearly wasn't a static value: changing a single byte anywhere in the block also changed the checksum. Rather than reversing the algorithm itself, the trick is to find two blocks with identical contents on two different cards. Even though the data matches byte for byte, the checksum comes out different on each card, but that difference is constant for that pair of cards. XOR the two checksums together and you get a "checksum modifier" for that pair. Copy a block from card A onto card B, XOR its checksum with that modifier, and card B accepts it as valid.

That alone is enough to copy a good balance from one card onto another, but it also generalizes into editing a single card without needing a second one at all. XOR an existing value with the value you want it to become and you get a "data modifier." Look up that data modifier alongside the byte position ("column") it lives in against a table built the same way, and you get a matching "checksum modifier" to apply to the existing checksum. The fact that the same position and data modifier always produce the same checksum modifier, no matter what else is in the block, is consistent with a linear, CRC-style checksum: for a fixed-length block, XORing two blocks together and checksumming the result gives the same answer as XORing their two individual checksums together. Nobody needs to know the actual generator polynomial to exploit that property, just enough sample data to fill in a lookup table of checksum deltas.

Findings

  1. No Key Diversification: The MBTA uses identical keys across all CharlieCards. Recovering keys from one card compromises the entire system.
  2. No Backend Validation: The system relies on card-side data validation. Fare readers trust whatever value the card reports without cross-checking a central database.
  3. Crackable Checksum: The per-block checksum behaves linearly under XOR, so edits can be validated with a lookup table instead of ever reversing the actual algorithm.
  4. Predictable Structure: Once the data format is understood, arbitrary fare values can be written to any card.

Tools Used

  • Proxmark3: RFID research platform for sniffing, emulating, and cloning cards
  • libnfc: Open source NFC library for low-level card communication
  • mfoc: MIFARE Classic offline cracker implementing the nested authentication attack
  • Hex editor: Manual analysis of card dumps and pattern identification

Lessons Learned

This project reinforced a critical security principle: never trust the client. The MBTA's system placed all trust in the card itself, with no server-side validation of fare values. A properly designed system would treat the card as untrusted storage and validate transactions against a backend database.

The lack of key diversification was equally problematic. Modern transit systems derive unique keys for each card using a master key and the card's UID. Even if one card is compromised, those keys are useless for any other card in the system.

The checksum has the same underlying flaw as the encryption: it's an integrity check with no secret behind it that the card owner doesn't also have. A checksum only protects data from tampering if computing a valid one requires information the attacker doesn't have. Here, all it took was two cards and some patience.