Files
proxmark3/armsrc
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
..
…
2026-08-19 15:32:39 +02:00
2026-09-05 18:09:46 +02:00
2026-08-28 13:10:24 +02:00
2026-08-28 13:10:24 +02:00
2026-09-04 06:21:20 +02:00
2025-12-21 02:58:56 -07:00
2025-12-21 00:34:11 -07:00
2026-03-24 14:21:54 +07:00
2026-09-15 18:50:57 +02:00
2026-09-01 17:57:31 +02:00
2024-05-14 12:32:57 +02:00
2026-09-15 08:36:13 +02:00
2023-08-08 23:03:34 -07:00
2025-03-16 01:05:55 -07:00
2026-08-19 15:32:39 +02:00
2025-03-21 11:25:31 +01:00
2026-03-29 09:38:09 +07:00
2026-09-15 08:10:09 +02:00
2023-08-08 23:38:26 -07:00
2026-08-28 22:35:08 +02:00
2026-06-12 18:31:57 +03:00
2026-08-19 15:32:39 +02:00
2026-06-12 18:31:57 +03:00
2026-07-15 16:39:15 +02:00
…
2026-09-15 08:36:13 +02:00
2023-08-09 00:03:48 -07:00
2026-09-15 08:36:13 +02:00
…
2026-09-15 08:21:25 +02:00
2026-09-15 08:36:13 +02:00
2024-11-21 19:23:03 +00:00
2026-09-15 16:02:46 +08:00
2026-09-15 08:03:54 +02:00
2026-08-29 15:00:03 +02:00
2026-09-15 08:10:09 +02:00
2026-09-15 08:10:09 +02:00
2026-09-15 08:21:25 +02:00
2026-08-19 15:32:39 +02:00
2026-08-19 15:32:39 +02:00
2026-09-15 08:17:05 +02:00
2026-09-15 08:36:13 +02:00
2026-09-14 19:56:57 +02:00
…
2026-09-15 08:29:06 +02:00
2026-08-29 16:03:00 +02:00
2026-08-19 15:32:39 +02:00
…
…
2024-05-14 10:10:44 +02:00
2025-03-18 08:11:06 +01:00
2025-03-25 10:12:16 +01:00
…
2026-08-28 13:10:24 +02:00
2026-09-15 08:21:25 +02:00
2026-09-01 13:34:02 +02:00
2026-09-08 16:04:45 +08:00
2026-09-05 22:31:52 +08:00
2026-09-15 08:17:05 +02:00
2026-04-13 09:35:02 +02:00
2026-08-19 15:32:39 +02:00
2025-12-21 04:26:44 -07:00
2025-01-14 18:01:09 -08:00
2025-01-14 18:01:09 -08:00
2026-09-15 08:17:05 +02:00
2026-08-19 15:32:39 +02:00
…
2026-09-15 08:36:13 +02:00
2026-09-01 13:34:23 +02:00
2025-04-21 23:17:47 +10:00
2026-09-01 13:32:49 +02:00
…
…
…
…