RFID and NFC cards open doors, pay fares, and unlock devices, yet many deployments still trust a static identifier or a card type that was never designed to resist cloning. Low frequency cards often carry nothing but an ID number. MIFARE Classic cards use a cipher with well known weaknesses. Even stronger cards fail when the reader accepts replayed responses, when keys are shared across a fleet, or when the system never checks that the card is physically present. This skill covers authorized lab analysis: identifying card types, reading what a card actually discloses, testing cloning, replay, and relay concepts on lab cards, reviewing reader behavior, and writing mitigations. Work only on cards and readers you own or have written permission to test. Never clone, emulate, or replay a credential that belongs to someone else, and never use lab findings against a live access control system.
Quick Workflow
- Confirm scope in writing: which cards, readers, and test credentials are yours to use, and which live systems are off limits.
- Identify the card technology: frequency, chip type, and protocol family, before attempting any read.
- Read the card with a lab reader and record exactly what it discloses without authentication: UID, card type, and any readable blocks.
- Test authentication: default keys, diversified keys, and whether the reader challenges the card or just trusts its UID.
- Test cloning analysis on lab cards you own: copy the disclosed data to a blank lab card and see which readers accept it.
- Test replay and relay concepts in the lab: capture a session, replay it to a lab reader, and measure reader timing and distance checks.
- Review card emulation behavior: what a phone or lab device presents to a reader, and what the reader verifies.
- Document findings per card type and write mitigations that fit the deployment: challenge response, key diversification, and revocation.
1. Identifying the card
Start by identifying the card before running attacks against it. Frequency and chip type decide which tools and techniques apply, and guessing wrong wastes time and can corrupt writable cards.
# List NFC readers visible to the lab host
nfc-list
# Poll for any tag in the field and show its type
nfc-poll
# Show low level details for a MIFARE style card in the field
nfc-mfclassic --help 2>&1 | head -20
# Record the UID and card type for your lab notes
nfc-poll 2>&1 | tee lab_card_identification.txt
Note the UID length, the chip family if the tool reports it, and whether the card answers as low frequency (125 kHz) or high frequency (13.56 MHz). Low frequency cards with a static ID need no further protocol analysis to assess: the ID is the credential, and any compatible reader will accept a copy of it.
2. Reading what a card discloses
Read the card the way an attacker would: first without keys, then with default or lab supplied keys, and record the difference. This separates cards that leak data from cards that protect it.
# Read a MIFARE Classic lab card with default keys (lab cards only)
nfc-mfclassic r lab_dump.mfd 2>&1 | tee lab_read_log.txt
# Dump sector contents in a readable form for analysis
xxd lab_dump.mfd | head -40
# Check which sectors the default keys opened, by reading the log
grep -i "fail\|success\|auth" lab_read_log.txt | head -30
# Parse a lab card dump: list UIDs, sector keys, and readable blocks
import sys
def parse_dump(path):
with open(path, "rb") as fh:
data = fh.read()
print("dump size:", len(data), "bytes")
print("UID bytes:", data[0:4].hex())
for sector in range(len(data) // 64):
block = data[sector * 64:(sector + 1) * 64]
trailer = block[48:64]
key_a = trailer[0:6].hex()
key_b = trailer[10:16].hex()
print(f"sector {sector}: key A {key_a}, key B {key_b}")
if __name__ == "__main__":
parse_dump(sys.argv[1])
If default keys open sectors on a production style card in your lab, that is a finding: the deployment never changed the factory keys. If only the UID is readable and all sectors need unknown keys, the card itself is resisting casual reads, and the next test is whether the reader still trusts the UID alone.
3. Cloning analysis on lab cards
Cloning analysis answers one question: does the system verify something the card knows, or does it trust something the card says? Copy lab card data to a blank lab card and present both to a lab reader, then compare the results.
# Write the lab dump to a blank writable lab card (magic card, lab only)
nfc-mfclassic w lab_dump.mfd 2>&1 | tee lab_write_log.txt
# Confirm the copy reads back identically
nfc-mfclassic r lab_copy_check.mfd 2>&1 | head -10
cmp lab_dump.mfd lab_copy_check.mfd && echo "copy matches original"
# Present original and copy to the lab reader in turn and log outcomes
# Record: reader response, access decision, and any log entry per card
A reader that accepts the copy has no card authentication: it trusts the UID or the static data. A reader that rejects the copy while accepting the original is doing something stronger, such as a challenge response or a diversified key check. Report which behavior you observed, with the card type and reader model, not a general claim about the technology.
4. Replay and relay review
Replay tests whether a captured response stays valid. Relay tests whether the reader checks that the card is actually nearby. Both are lab exercises with lab readers and lab cards, and both need careful measurement, not just a success or failure note.
# Capture an NFC session with a lab sniffer for offline review
# Save the capture, then inspect APDU exchanges frame by frame
tshark -i usbmon0 -Y "usb" -w nfc_session.pcapng -a duration:60 2>&1 | head -5
# List APDU-like exchanges from the capture for manual review
tshark -r nfc_session.pcapng -T fields -e frame.number \
-e usb.capdata 2>/dev/null | head -40
# Replay analysis helper: compare two captured sessions for static fields
# Usage: python3 replay_compare.py session_a.txt session_b.txt
import sys
def load_fields(path):
fields = {}
with open(path) as fh:
for line in fh:
line = line.strip()
if "=" in line:
key, value = line.split("=", 1)
fields[key.strip()] = value.strip()
return fields
a = load_fields(sys.argv[1])
b = load_fields(sys.argv[2])
for key in sorted(set(a) | set(b)):
status = "SAME" if a.get(key) == b.get(key) else "CHANGED"
print(f"{status} {key}: {a.get(key)} -> {b.get(key)}")
Fields that stay identical across sessions are replay candidates. Fields that change per session, such as a reader nonce or a card challenge response, show replay resistance. For relay, measure round trip time: a relayed session adds latency, so check whether the reader enforces a timing bound or a distance bounding check, and record the measured times rather than asserting a pass or fail.
5. Card emulation review
Card emulation is when a phone or lab device presents itself as a card to a reader. Review what the emulated card discloses and what the reader verifies, using a lab reader and a test credential you control.
# Check what the host sees when an emulated card is presented
nfc-list 2>&1 | tee emulation_probe.txt
# Poll repeatedly while presenting the emulated card
for i in 1 2 3; do
echo "=== probe $i ==="
nfc-poll 2>&1 | grep -iE "UID|ATQA|SAK|type" | head -10
sleep 2
done
Compare the emulated presentation against the real lab card: UID format, random versus static UID, and which applications the reader selects. A reader that accepts a static emulated UID with no further check has the same weakness as a reader that accepts a cloned card. A reader that selects a secure application and runs a challenge response is testing something the emulator must actually know. Note the difference in the report, and never test emulation against a live reader you do not own.
6. Mitigations that fit the deployment
Write mitigations for the specific weakness you confirmed, not a generic list. Match each finding to a control the operator can actually deploy.
# Evidence checklist before writing mitigations
# 1. Card type and UID behavior: static or random UID
# 2. Keys: factory default, shared fleet key, or diversified per card
# 3. Reader check: UID only, or challenge response
# 4. Replay: static fields present, or per session challenge
# 5. Relay: timing bound present, or no distance check
# 6. Revocation: can a lost card be blocked, and how fast
ls -la lab_*.txt lab_*.mfd 2>/dev/null
Strong mitigations include: diversified keys derived per card so one leaked key does not compromise the fleet, challenge response authentication so a copied UID alone is worthless, secure element backed credentials on phones, short validity and revocation lists for lost cards, reader timing bounds against relay, and audit logs that record every grant and denial. For low frequency systems with no cryptography at all, the honest mitigation is migration to a high frequency system with authentication, plus compensating controls such as cameras and supervised entry in the meantime.
Edge cases
- Writable lab cards differ from real cards: a magic card that accepts a copied UID proves the reader trusts the UID, but it does not prove a real issued card can be cloned the same way.
- Random UIDs change every tap: some phones and modern cards randomize the UID, so a reader that worked once may fail the next tap for reasons unrelated to your test.
- Default key lists are long: try the documented defaults for the card family first, then stop and report partial access rather than brute forcing keys against a card you do not own.
- Relay timing varies with hardware: measure latency on the lab setup several times and report the range, not a single sample.
- Payment and transit cards carry legal and safety limits: use test cards and lab readers only, and never test against a live payment terminal or transit gate.
- Some readers cache decisions: after a denied tap, wait and retest before concluding a card is rejected, since caching can mask the real behavior.
- Card data can include personal data: redact names, IDs, and balances from dumps before sharing evidence outside the lab.
Key references
- ISO/IEC 14443, covering proximity card radio interface, initialization, and anti-collision for high frequency cards.
- ISO/IEC 15693, covering vicinity card behavior for longer range high frequency deployments.
- ISO/IEC 18092, covering NFC interface and protocol for peer to peer and card emulation modes.
- MIFARE Classic and MIFARE DESFire product documentation from NXP, covering authentication, key diversification, and secure messaging concepts.
- NIST SP 800-63B, covering authenticator types and the limits of static identifiers as credentials.
- libnfc documentation and examples, covering reader setup, polling, and MIFARE operations on lab hardware.
- OWASP guidance on broken access control and insecure authentication, applied to physical credential verification.
