hf mfdes: dump a whole card to json, and view it back
'hf mfdes dump' walked one application and printed it. It now walks every application on the PICC, keeps what it reads, and saves a 'hf-mfdes-<UID>-dump.json' card image. '--aid' / '--isoid' / '--dfname' still narrow it to one application, '--ns' skips the save. The format is 'mfdes v1', written and read in fileutils.c and documented in doc/mfdes_dump_format.md. Two decisions worth stating: - The PICC level is application 000000, so every key in the file says which AID it opens. Key version and key value are separate: a version with no key is the normal shape for a key that was found but never recovered, and a missing key never means the key is zero. - Every file carries a 'Read' flag. A file whose contents could not be fetched is recorded as unread with no data at all, rather than as a run of zeros. A simulator built on this must not confuse '8 bytes of 00' with 'we could not read 8 bytes'. 'hf mfdes view -f <fn>' prints such a file with no device attached. With no '--keys', the dump looks for 'hf-mfdes-<UID>-keys.json' by itself, so a 'hf mfdes chk -j' run is picked up on the next dump without naming the file again. Two fixes fell out of testing against a DESFire EV2: - DesfireSetKey() calls DesfireClearContext(), which wipes command set, comm mode, KDF and UID, not just the key. Swapping in a per-application key that way left the context at 'Communication mode: n/a' and DesfireFillFileList() then returned junk file ids. Use DesfireSetKeyNoClear(). - GetVersion and the originality signature are answered unauthenticated. Asking for them from inside the authenticated session produced a 'Wrong communication mode' warning and a run of MAC mismatches. hex_to_buffer() treats hex_max_len as a byte count while every sprint_hex* caller passes sizeof(buf) - 1, a character count, so it writes two or three times the buffer size. Measured, sprint_hex_inrow overflowed at 4098 input bytes. Doubling UTIL_BUFFER_SIZE_SPRINT to 16384 moves that to 8192; the mixed semantics still need auditing across ~30 call sites. Co-Authored-By: Claude Opus 5 (1M context)
This commit is contained in:
1 parent
66dbf6ac5c
commit
8fd9bcbebc
8 files changed
+1578
-68
No files matched your search
+36
-13
@@ -5996,9 +5996,10 @@
|
||||
"--2k MIFARE Classic/Plus 2k",
|
||||
"--4k MIFARE Classic 4k / S70",
|
||||
"--ns no save to file",
|
||||
"-v, --verbose verbose output"
|
||||
"-v, --verbose verbose output",
|
||||
"--sk Save extracted keys to binary file"
|
||||
],
|
||||
"usage": "hf mf dump [-hv] [-f <fn>] [-k <fn>] [--mini] [--1k] [--2k] [--4k] [--ns]"
|
||||
"usage": "hf mf dump [-hv] [-f <fn>] [-k <fn>] [--mini] [--1k] [--2k] [--4k] [--ns] [--sk]"
|
||||
},
|
||||
"hf mf ecfill": {
|
||||
"command": "hf mf ecfill",
|
||||
@@ -7145,16 +7146,18 @@
|
||||
"command": "hf mf view",
|
||||
"description": "Print a MIFARE Classic dump file (bin/eml/json)",
|
||||
"notes": [
|
||||
"hf mf view -f hf-mf-01020304-dump.bin"
|
||||
"hf mf view -f hf-mf-01020304-dump.bin",
|
||||
"hf mf view --selftest"
|
||||
],
|
||||
"offline": true,
|
||||
"options": [
|
||||
"-h, --help This help",
|
||||
"-f, --file <fn> Specify a filename for dump file",
|
||||
"-v, --verbose verbose output",
|
||||
"--sk Save extracted keys to binary file"
|
||||
"--sk Save extracted keys to binary file",
|
||||
"--selftest Run the dump parsers self tests and exit"
|
||||
],
|
||||
"usage": "hf mf view [-hv] -f <fn> [--sk]"
|
||||
"usage": "hf mf view [-hv] [-f <fn>] [--sk] [--selftest]"
|
||||
},
|
||||
"hf mf wipe": {
|
||||
"command": "hf mf wipe",
|
||||
@@ -7853,9 +7856,12 @@
|
||||
},
|
||||
"hf mfdes dump": {
|
||||
"command": "hf mfdes dump",
|
||||
"description": "For each application show fil list and then file content. Key needs to be provided for authentication or flag --no-auth set (depend on cards settings).",
|
||||
"description": "Dump a DESFire card to a json file. Walks every application and every file unless an application is named with --aid / --isoid / --dfname. Key needs to be provided for authentication or flag --no-auth set (depend on cards settings).",
|
||||
"notes": [
|
||||
"hf mfdes dump --aid 123456 -> show file dump for: app=123456 with channel defaults from `default` command/nhf mfdes dump --isoid df01 --schann lrp -t aes --length 000090 -> lrp default settings with length limit"
|
||||
"hf mfdes dump -> dump the whole PICC with channel defaults from `default` command",
|
||||
"hf mfdes dump --aid 123456 -> dump only application 123456",
|
||||
"hf mfdes dump --keys hf-mfdes-0102030405-keys.json -> use recovered keys per application",
|
||||
"hf mfdes dump --isoid df01 --schann lrp -t aes --length 000090 -> lrp default settings with length limit"
|
||||
],
|
||||
"offline": false,
|
||||
"options": [
|
||||
@@ -7874,9 +7880,12 @@
|
||||
"--isoid <hex> Application ISO ID (ISO DF ID) (2 hex bytes, big endian)",
|
||||
"--dfname <hex> Application ISO DF Name (5-16 hex bytes, big endian)",
|
||||
"-l, --length <hex> Maximum length for read data files (3 hex bytes, big endian)",
|
||||
"--no-auth Execute without authentication"
|
||||
"--no-auth Execute without authentication",
|
||||
"-f, --file <fn> Save dump to file, if no <fn> UID will be used as filename",
|
||||
"--keys <fn> Load application keys from a `hf mfdes chk` key file",
|
||||
"--ns No save to file"
|
||||
],
|
||||
"usage": "hf mfdes dump [-hav] [-n <dec>] [-t <DES|2TDEA|3TDEA|AES>] [-k <hex>] [--kdf <none|AN10922|gallagher>] [-i <hex>] [-m <plain|mac|encrypt>] [-c <native|niso|iso>] [--schann <d40|ev1|ev2|lrp>] [--aid <hex>] [--isoid <hex>] [--dfname <hex>] [-l <hex>] [--no-auth]"
|
||||
"usage": "hf mfdes dump [-hav] [-n <dec>] [-t <DES|2TDEA|3TDEA|AES>] [-k <hex>] [--kdf <none|AN10922|gallagher>] [-i <hex>] [-m <plain|mac|encrypt>] [-c <native|niso|iso>] [--schann <d40|ev1|ev2|lrp>] [--aid <hex>] [--isoid <hex>] [--dfname <hex>] [-l <hex>] [--no-auth] [-f <fn>] [--keys <fn>] [--ns]"
|
||||
},
|
||||
"hf mfdes formatpicc": {
|
||||
"command": "hf mfdes formatpicc",
|
||||
@@ -8189,7 +8198,7 @@
|
||||
},
|
||||
"hf mfdes help": {
|
||||
"command": "hf mfdes help",
|
||||
"description": "help This help list List DESFire (ISO 14443A) history makemfclicense Generate a Mifare Classic license for DESFire EV3C test Regression crypto tests --------------------------------------------------------------------------------------- hf mfdes list available offline: yes Alias of `trace list -t des -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol",
|
||||
"description": "help This help list List DESFire (ISO 14443A) history view Display content from tag dump file makemfclicense Generate a Mifare Classic license for DESFire EV3C test Regression crypto tests --------------------------------------------------------------------------------------- hf mfdes list available offline: yes Alias of `trace list -t des -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol",
|
||||
"notes": [
|
||||
"hf mfdes list --frame -> show frame delay times",
|
||||
"hf mfdes list -1 -> use trace buffer"
|
||||
@@ -8630,6 +8639,20 @@
|
||||
],
|
||||
"usage": "hf mfdes verifycert [-hav] [<profile>] [-n <dec>] [-t <DES|2TDEA|3TDEA|AES>] [-k <hex>] [--kdf <none|AN10922|gallagher>] [-i <hex>] [-m <plain|mac|encrypt>] [-c <native|niso|iso>] [--schann <ev2>] [--aid <hex>] [--isoid <hex>] [--dfname <hex>] [--fid <hex>] [--no-auth] [--ca <name|cert|pubkey|path|skip>]... [--keyaid <hex>] [--keyisoid <hex>] [--keydfname <hex>] [--keyidx <dec>] [--validatemethod <auto|intauth|vde|skip>] [--readmethod <auto|desfire>]"
|
||||
},
|
||||
"hf mfdes view": {
|
||||
"command": "hf mfdes view",
|
||||
"description": "Print a DESFire card dump file (json)",
|
||||
"notes": [
|
||||
"hf mfdes view -f hf-mfdes-01020304050607-dump.json"
|
||||
],
|
||||
"offline": true,
|
||||
"options": [
|
||||
"-h, --help This help",
|
||||
"-f, --file <fn> Filename of dump",
|
||||
"-v, --verbose Verbose output"
|
||||
],
|
||||
"usage": "hf mfdes view [-hv] -f <fn>"
|
||||
},
|
||||
"hf mfdes write": {
|
||||
"command": "hf mfdes write",
|
||||
"description": "Write data from file. Key needs to be provided or flag --no-auth set (depend on file settings).",
|
||||
@@ -16221,7 +16244,7 @@
|
||||
"command": "smart raw",
|
||||
"description": "Sends raw bytes to card",
|
||||
"notes": [
|
||||
"smart raw -s -0 -d 00a404000e315041592e5359532e4444463031 -> `1PAY.SYS.DDF01` PPSE directory with get ATR",
|
||||
"smart raw --t0 -s -d 00a404000e315041592e5359532e4444463031 -> `1PAY.SYS.DDF01` PPSE directory with get ATR",
|
||||
"smart raw --t0 -d 00a404000e325041592e5359532e4444463031 -> `2PAY.SYS.DDF01` PPSE directory",
|
||||
"smart raw --t0 -t -d 00a4040007a0000000041010 -> Mastercard",
|
||||
"smart raw --t0 -t -d 00a4040007a0000000031010 -> Visa",
|
||||
@@ -16538,8 +16561,8 @@
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"commands_extracted": 920,
|
||||
"commands_extracted": 921,
|
||||
"extracted_by": "PM3Help2JSON v1.00",
|
||||
"extracted_on": "2026-09-12T19:49:38+00:00"
|
||||
"extracted_on": "2026-09-14T06:50:14+00:00"
|
||||
}
|
||||
}
|
||||
@@ -817,6 +817,7 @@ Check column "offline" for their availability.
|
||||
|`hf mfdes getfileisoids `|N |`Get File ISO IDs list`
|
||||
|`hf mfdes lsfiles `|N |`Show all files list`
|
||||
|`hf mfdes dump `|N |`Dump all files`
|
||||
|`hf mfdes view `|Y |`Display content from tag dump file`
|
||||
|`hf mfdes createfile `|N |`Create Standard/Backup File`
|
||||
|`hf mfdes createvaluefile`|N |`Create Value File`
|
||||
|`hf mfdes createrecordfile`|N |`Create Linear/Cyclic Record File`
|
||||
|
||||
@@ -342,6 +342,9 @@ hf mfdes chk -k 00000000000000000000000000000000 -j hf-mfdes-043240CAE45380-keys
|
||||
|
||||
# and dump it
|
||||
hf mfdes dump -t 2tdea -k 00000000000000000000000000000000
|
||||
|
||||
# to put the card back the way it was
|
||||
hf mfdes formatpicc -t 2tdea -k 00000000000000000000000000000000
|
||||
```
|
||||
|
||||
Without that `chk` run, application `112233` cannot be opened with the 2TDEA
|
||||
@@ -525,8 +528,11 @@ The dump picks this file up without `--keys` because its name follows the same
|
||||
|
||||
Things to read out of it:
|
||||
|
||||
* **`FreeMem` is 896**, not the 2080 a blank card reports. The applications and
|
||||
files took the rest.
|
||||
* **`FreeMem` is 896** with the two applications in place. Measured on this same
|
||||
card: 2080 free before the example was built, 896 with it, and 2560 after
|
||||
`hf mfdes formatpicc`. A format therefore reclaims space that creating and
|
||||
deleting applications leaves behind -- 0 applications on its own does not mean
|
||||
a fully free card.
|
||||
* **`NumKeysRaw` `83`** decodes to `KeyType: aes` (top bits 10), ISO file ids
|
||||
enabled (bit 5) and `NumKeys: 3`.
|
||||
* **Keys 1 and 2 of `112233` have a `Version` but no `Key`.** They exist, we
|
||||
|
||||
Reference in new issue
Block a user