26 Commits
Author SHA1 Message Date
Matthew CarrollandClaude Opus 5.5 7344c7d5bc lf: fall back to pm3_psk_demod for weak fc/2 PSK when the wave tracker isn't clean
At fc/2 the subcarrier is a one-sample alternation and pskRawDemod_ext finds
wave tops one sample at a time, unfiltered. On a weak tag, sample noise erases
tops; a wave then reads as four samples and counts as a phase shift, and the
bit stream fills with errors although every bit is still in the trace. A T5577
Indala at 22 mm gave the wrong card on 14 of 50 lf search reads.

PSKDemod keeps the tracker's result whenever it is clean, so nothing changes
where master already works. Otherwise, for fc/2, it tries the existing coherent
receiver pm3_psk_demod (now with an optional per-symbol magnitude output) and
keeps that only if it scores well above what level-step leakage can produce,
its bits aren't doubled or constant, and no symbol is weak. The receiver's
output is differential, so one bad decision would flip every later bit: a weak
symbol refuses the trace rather than risk a wrong card (absolute decisions with
weak symbols left to maxErr were tried and gave wrong IDs on dropouts). With no
usable clock from the caller, candidate clocks are tried largest first. Polarity is voted from the
raw level over each phase reversal, the cue pskFindFirstPhaseShift reads at the
first one. Client only; firmware is unchanged.

Base vs this change, same captures:
- T5577 Indala, live lf search: 22 mm 3 right / 14 wrong -> 50 / 0; 24 mm
  0 / 2 -> 50 / 0; 26 mm and 0-20 mm unchanged
- lf t55xx dump, live: 22 and 24 mm blocks 0-2 and page 1 correct 5/5 where
  master reads nothing; unchanged where master reads
- emulated Indala (Chameleon Ultra, clock drifting against the reader):
  lf search right / wrong 56 / 130 -> 91 / 95 of 200; every one of the 95 is
  master's own wrong ID on the same capture
- 27 PSK traces in traces/, weakened with Gaussian noise: correct 341 -> 636 of
  810, wrong IDs 83 -> 21; with recorded Proxmark noise 367 -> 553 of 648,
  33 -> 27. No lost reads and no new wrong IDs in either
- traces/lf_*.pm3 (99): lf search -1 and -1 -c output identical; 1,581
  non-PSK probes: lf search and lf t55xx detect identical
- 200 empty-field captures: no decode, either build

tools/pm3_tests.sh: a weak 24 mm Indala trace must read its ID (fails on
master), and a synthetic NRZ with an fc/2 ripple must not decode as a tag
(the level-step leakage the score check rejects).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 14:45:41 -07:00
iceman1001andClaude Opus 5 e648438306 hf 14b view: decode MyKey / COGES keys on SRIX4K
The SRIX4K block scrambler in cmdhf14b.c was a three entry lookup table with
its callers commented out, so `hf 14b valid` printed hard coded values and
nothing ever decoded. The scrambler is a 4x4 transpose of the block read as
sixteen crumbs. A transpose is its own inverse and it reproduces all three
entries of the old table, so the stub is replaced by a working parser.

client/src/parsers/parsemykey.c reads the application off a dump: key id,
production date, operations counter, vendor code, lock id, current and
previous credit, and the eight slot transaction ring. Every block carries a
checksum in its top byte and the parser reports how many hold up, which
catches a wrong UID or a torn write. The credit blocks are XORed with a
session key derived from the UID, the vendor code and the count down counter
in block 6, so the file name has to carry the UID.

`hf 14b valid` is removed. Checking that the maths holds is now
`hf 14b view --selftest`, following `hf mf view --selftest`, and it runs
against traces/hf-14b-D0021F673CB26556-dump.json, a dump of a real reset key.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 10:58:57 +02:00
iceman1001andClaude Opus 5 4dc412e403 hf mfdes sim: authentication, secure messaging, reads, writes and transactions
The DESFire simulation now plays the EV1 protocol rather than just the
activation and a handful of unauthenticated queries. A reader authenticates,
enumerates, reads and writes files, and commits or aborts transactions against
the card image `hf mfdes eload` put in emulator memory.

Authentication covers 0x0A, 0x1A and 0xAA with DES, 2TDEA, 3K3DES and AES keys
taken from the image. A key the image only holds a version for still refuses to
authenticate rather than authenticating with zeros.

Secure messaging follows the file's communication mode, with the rule that the
mode only applies when a key right matching the authenticated key granted the
operation -- access granted by the free-access right runs plain whatever the
file settings say. Responses are MACed or enciphered accordingly, and the
session CMAC is taken over every command and response in order so the two sides'
IVs stay together even where neither puts a MAC on the wire.

Reads cover ReadData, ReadRecords, GetValue and GetCardUID. Writes cover
WriteData, WriteRecord, UpdateRecord, Credit, Debit and LimitedCredit, plus
CommitTransaction, AbortTransaction and ClearRecordFile. Backup data, value and
record files write into their shadow region and only move across on commit, so
an abort really does discard.

Three fixes were needed to interoperate with the client, and all three share a
shape worth naming: the authentication handshake still succeeded, because it
runs on the original key, and only the traffic afterwards was wrong.

1. A DES or 2TDEA key is stored as 16 bytes and the key itself decides which
   cipher the PICC uses -- if the second half equals the first it is a single
   DES key, and that governs session key generation too (M134034 8.1). The
   all-zero default key is the common case. Deriving a 2K3DES session key from
   it left the card MACing under a key the reader did not have. Confirmed by
   decrypting a captured GetCardUID response offline: under the session key the
   reader derives it yields the UID and a valid CRC32, under the other it does
   not.

2. Session keys are built here rather than through Desfire_session_key_new(),
   whose 3K3DES branch clears the low bit of the first eight bytes. Those bits
   are key version, which a session key does not have, and the reader keeps them.

3. The reader's 0xAF continuation is not a command, it continues one. Giving it
   its own CMAC restarted the running calculation halfway through a chained
   answer, so every chained response longer than one frame carried a wrong MAC
   while single-frame answers verified fine.

The sample card in traces/mifare is rekeyed from all zeros to the sequence
01 02 .. 10, extended to .. 18 for 3TDEA. An all-zero key has matching halves,
so it exercises only the degenerate path of fix 1 above and hides the bug;
distinct halves surface a wrong derivation on the first MACed frame.

tools/desfire_sim_test.sh loads an image, simulates it, drives the second
Proxmark3 at it and reports. It stops the simulation the way the client does, a
newline on its stdin, through a fifo held open for the run rather than a fixed
timer -- a run that outlives its timer leaves the device simulating. A command
counts as passing only if it prints something that says it worked: card errors,
client side argument rejections and MAC or CRC complaints all fail, because
several of those print a plausible result line as well and matching on the
result alone reports passes that never happened.

Tested on two RDV4s, one simulating and one reading: activation, info,
application and file enumeration, all three key types, enciphered GetCardUID,
plain and MACed reads up to 256 bytes over chained frames, and writes verified
by reading the image back out with `hf mfdes esave`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 20:40:32 +02:00
iceman1001 6755b96323 added a couple of desfire test files for easy simmulation 2026-09-15 14:49:32 +02:00
iceman1001 c91993acc8 text 2026-09-12 21:48:46 +02:00
iceman1001 50c1c72136 added some sample dump files and trace file for hitag2 2026-09-03 19:35:58 +02:00
iceman1001 32a4e622d2 added two trace files for UL-AES in order for people to more easily understand secure messaging and authentication 2025-10-17 18:08:15 +02:00
iceman1001 641b8f3f57 added a trace file for looking at a genuine Hitag2 read out when card is configured in Crypto mode 2024-04-25 07:37:26 +02:00
iceman1001 bfa912952e added a trace of xerox info execution 2024-01-26 21:25:45 +01:00
iceman1001 c97f003b2f added a pm3 simulating trace of MIFARE HID SIO 1K card 2022-07-04 17:21:36 +02:00
iceman1001 54ddd8176f added iclass sniff 2022-01-30 21:25:02 +01:00
iceman1001 7dcaf59cdd added a sniffed desfire trace 2022-01-30 21:23:17 +01:00
iceman1001 0330234aea Added sniffed traces of Visa Apple ECP transactions. Thanks to @a66at for them! 2021-10-14 19:49:57 +02:00
iceman1001 fe75de7440 added a trace of reading a MIFARE UL-C with 3DES authentication, thanks @rad1game! 2021-10-13 19:10:17 +02:00
iceman1001 710c612a2c text 2021-09-03 19:14:04 +02:00
Matthew Saunier 26227e1d7b Added trace 2021-06-08 12:20:46 -06:00
STRSHR 1280912589 Add an IDTECK sample 2021-04-25 09:45:29 +03:00
iceman1001 89d2e4fe8f text 2021-03-05 10:49:00 +01:00
Philippe Teuwen 34a56fae9a blue cloner trace 2020-10-17 00:46:10 +02:00
Philippe Teuwen fc6492288c add trace 2020-10-02 02:20:45 +02:00
Philippe Teuwen b3a3828c3f add 14b* traces 2020-10-02 01:18:49 +02:00
Philippe Teuwen d1bb16f862 text 2020-09-29 18:19:23 +02:00
Philippe Teuwen 1abdbf3369 text 2020-09-29 18:09:29 +02:00
Philippe Teuwen c79e50b8f7 remove useless lf_Q5_mod-data.bin 2020-09-29 17:50:01 +02:00
Philippe Teuwen 58efbaeefd typo 2020-09-29 17:48:50 +02:00
Philippe Teuwen b4058bc72c reorg traces 2020-09-29 17:35:48 +02:00