Commit Graph
23947 Commits
Author SHA1 Message Date
iceman1001andClaude Opus 5 69ebbc8dca hf mf sen: faster default-key dictionary check
fm11_key_matches_nonce() runs once per dictionary key per unknown key slot,
up to 85442 * 34 times. For every one of them it malloc'd a cipher state,
clocked two full 32 bit keystream words and only then compared the first,
although nearly every key fails on the first byte.

Keep the state on the stack, compare a byte at a time and stop at the first
mismatch, and clock the second word only for a key that survives. Same keys
accepted, about 6x less time in that phase (2.9 s -> 0.5 s for a full 34 slot
scan of the 85k dictionary).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-11-13 12:23:43 +07:00
iceman1001andClaude Opus 5 c154f730c3 crapto1: much faster MIFARE Classic key recovery
Nested and static nested recovery ran lfsr_recovery32 once per nonce and
intersected two ~2^16 candidate lists. The cipher state is linear while the
nonce is fed in, so the states for one nonce are those for the other xored
with a known difference. Checking both keystreams inside a single recovery
leaves about one candidate instead of two large lists.

lfsr_recovery32_dual() does that: it skips the early bit times where the
difference prunes little (start chosen per call from an exact per bit match
probability, falling back to 0 on overflow), scans the first pass 64 states
at a time through a bit packed filter table, extends the tables branch free
in cache sized chunks, and replaces the 512 scattered sort buckets with one
contiguous counting sort.

lfsr_recovery32() is rebuilt on the same machinery, so hf mf sen, mfkey32,
mfkey64 and the nested tools all gain. It stays single threaded because
nested_util.c already calls it from four threads. recover() takes the second
keystream as optional extra state; the plain path is unchanged.

Both return the same key sets as before, verified against the old code under
ASan/UBSan over random and degenerate nonce pairs.

nested per key:            ~390 ms -> ~4 ms
lfsr_recovery32 per call:  ~270 ms -> ~165 ms
peak RSS, single nonce:    47.6 MB -> 27.6 MB

tools/mfc/protocol links pthread now, as the other two mfc tool dirs do.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-11-13 12:20:04 +07:00
Iceman 657cd08d45 Merge pull request #3815 from matrix/fix-hf15-reader-noise
hf 15: fix two defects of the tag answer decoders
2026-11-13 11:14:23 +08:00
Iceman 3983cd553d Merge branch 'master' into fix-hf15-reader-noise
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 11:12:28 +08:00
Iceman 7a0ae7e3f4 Merge pull request #3822 from matrix/fix-mf-ndefread-4k
hf mf ndefread: read the whole of 4K sectors 32-39
2026-11-13 11:11:35 +08:00
Iceman 18728cc970 Merge branch 'master' into fix-mf-ndefread-4k
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 11:11:13 +08:00
Iceman fbbafe3317 Merge pull request #3821 from matrix/fix-mf-ndefread-options
hf mf ndefread: try -k on the MAD sectors, check -k and --aid
2026-11-13 11:10:37 +08:00
Iceman 1c7bbf4730 Merge branch 'master' into fix-mf-ndefread-options
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 11:10:22 +08:00
Iceman 7452bfba9a Merge pull request #3823 from matrix/fix-external-sam-mfc
external_sam_read.py: add the mfc and desfire card families
2026-11-13 11:08:11 +08:00
Iceman 6dca4367a3 Merge branch 'master' into fix-external-sam-mfc
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 11:06:43 +08:00
Iceman 20f59381be Merge branch 'master' into fix-mf-ndefread-4k
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 11:04:55 +08:00
Iceman 2471ee133a Merge branch 'master' into fix-mf-ndefread-options
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 11:04:08 +08:00
Iceman e7fa43b8ec Merge pull request #3820 from matrix/fix-mf-mad-options
hf mf mad: accept --override, check -k and --aid, fix -f --aid
2026-11-13 11:03:17 +08:00
Iceman 4aa5dcb8ce Merge branch 'master' into fix-mf-mad-options
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 11:03:08 +08:00
Iceman 3ea9e6e7d4 Merge pull request #3819 from matrix/fix-mf-mad-4k
hf mf mad: read the whole of 4K sectors 32-39
2026-11-13 11:00:43 +08:00
Gabriele GristinaandClaude Mythos 5.2 742b1d1f17 external_sam_read.py: add the mfc and desfire card families
The script had no path for a HID MIFARE Classic credential, where the
SAM runs Crypto1 itself and sends frames with its own parity bits. A
HID DESFire credential was read only under the seos name.

mfc relays as hf mf sam does: select without RATS, UID and SAK to the
SAM, then each frame as plain bytes or as the SAM's bit stream with
ISO14A_NO_PARITY, and a timeout status when the card is silent.
desfire takes the seos relay.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-13 03:50:38 +01:00
Gabriele GristinaandClaude Opus 5.5 e6e5c56b36 hf mf ndefread: describe the MAD key fallback in the command help
Review of #3807: the -k description is back to its short text, and
the command description says that the MAD is read with -k when the
default MAD key fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 03:47:38 +01:00
Gabriele GristinaandClaude Opus 5.5 0c7f0b0429 hf mf ndefread: read the whole of 4K sectors 32-39
The command put the 256 bytes of a 4K sector 32-39 into a 64-byte
buffer, a stack buffer overflow, and kept 3 of its 15 data blocks.

Now the buffer holds 16 blocks, and the command keeps every data block
of the sector.

Split from #3807.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 03:41:35 +01:00
Gabriele GristinaandClaude Opus 5.5 f458b1ccb4 hf mf ndefread: try -k on the MAD sectors, check -k and --aid
When the MAD key failed on sector 0, the command told the user to retry
with -k, but it used -k only for the NDEF sectors. A -k or --aid of the
wrong length was ignored without a word.

Now the command tries -k on the MAD sectors when the MAD key fails,
and a -k that is not 12 hex digits or an --aid that is not 4 is
refused.

Split from #3807.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 03:41:12 +01:00
Gabriele GristinaandClaude Opus 5.5 cc30d200ae hf mf mad: accept --override, check -k and --aid, fix -f --aid
--override was refused: the code read it at index 9, which had no
argtable entry. A -k or --aid of the wrong length was ignored without
a word. With -f and --aid the command printed no block of the AID.

Now --override has its argtable entry, a -k that is not 12 hex digits
or an --aid that is not 4 is refused, and -f with --aid prints the
AID's blocks.

Split from #3806.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 03:18:34 +01:00
Gabriele GristinaandClaude Opus 5.5 b80b13f73c hf mf mad: read the whole of 4K sectors 32-39
With --aid or --dch, the card read put the 256 bytes of a 4K sector
32-39 into a 64-byte buffer, a stack buffer overflow. The command
printed only the first blocks of the sector, numbered wrong from
sector 33, and gave --dch 3 of its 15 data blocks.

Now both buffers hold 16 blocks, and the command prints and decodes
every block of the sector.

Split from #3806.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 03:18:06 +01:00
Iceman 98e01d8579 Merge pull request #3817 from matrix/fix-hf15-sniff
hf 15 sniff, hf iclass sniff: keep up with the samples
2026-11-13 09:55:00 +08:00
Iceman 04755173a6 Merge branch 'master' into fix-hf15-sniff
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 09:53:55 +08:00
Iceman 335a21890c Merge pull request #3816 from mfcarroll/fix/t55xx-st-stride
`lf t55xx detect` - find configurations that have the sequence terminator set, and report it correctly
2026-11-13 09:52:08 +08:00
Iceman 952e4effec Merge branch 'master' into fix/t55xx-st-stride
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 09:51:32 +08:00
Iceman 389b3ffe01 Merge pull request #3813 from matrix/fix-cli-str-terminator
cliparser: keep a string option's terminator inside its buffer
2026-11-13 09:46:04 +08:00
Iceman 3bfec259dc Merge branch 'master' into fix-cli-str-terminator
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 09:45:24 +08:00
Iceman 77bf793bfb Merge pull request #3812 from matrix/fix-legic-options
hf legic: fix the option checks of clone, migrate and wrbl
2026-11-13 09:43:57 +08:00
Iceman be3ab8099b Merge branch 'master' into fix-legic-options
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 09:43:46 +08:00
Iceman 7a01705be4 Merge pull request #3811 from matrix/fix-save-dump-return
client: report dump files that could not be written
2026-11-13 09:40:16 +08:00
Iceman a6d49da2bf Merge branch 'master' into fix-save-dump-return
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 09:40:05 +08:00
Iceman dd9764d2cc Merge pull request #3809 from matrix/fix-gallagher-test
hf gallagher test: fix the known vector and MES tests, run in make check
2026-11-13 09:36:34 +08:00
Iceman e51d140ce5 Merge branch 'master' into fix-gallagher-test
Signed-off-by: Iceman <iceman@iuse.se>
2026-11-13 09:36:22 +08:00
Iceman 373d561bce Merge pull request #3804 from matrix/fix-mf-sen
hf mf sen: field off and a message on Enter, fix options and saves
2026-11-13 09:22:03 +08:00
Gabriele GristinaandClaude Mythos 5.2 9414d316c4 hf 15 sniff, hf iclass sniff: keep up with the samples
SniffIso15693() ran from flash and could not keep up with the samples
of the FPGA. On an RDV2 sniffing an OMNIKEY 5427CK and an ICODE SLIX,
282 of 1256 reader frames had a good CRC and 87 of 432 SELECT commands
had their answer in the trace.

SniffIso15693() now runs from RAM. While the reader decoder waits for
a SOF, the sniffer skips it on an unmodulated carrier. The tag decoder
accepts the falling edge of the SOF from posCount 11 (44 at low
speed), not only at 13 (52). After a slow rising edge the high phase
is short, and the old test started the bits one or two samples late.

With these changes the same sniff gave 985 of 985 reader frames with
a good CRC and 486 of 486 SELECT commands with their answer.

The code in RAM makes BigBuf 2008 bytes smaller on an RDV2.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-13 02:18:00 +01:00
iceman1001 9041810cdf style and textual changes 2026-11-13 07:57:33 +07:00
Matthew CarrollandClaude Opus 5.5 d83606a089 lf t55xx detect: report the sequence terminator on fsk hits
DetectST only runs on ask, and each fsk hit set its ST flag to false. An
fsk hit now reports ST if its block 0 word has the ST bit set and a copy
of the word sits 33 to 36 bits before or after it.

On a buffer of 92 bits or more, test() starts its scan at bit 28 and
often picks the second copy of block 0. On a short capture the copy
after that word may not fit, so the check also looks behind it. If
neither side has room for a copy, the ST bit decides. A Q5 word still
reports no ST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:42:16 -07:00
Matthew CarrollandClaude Opus 5.5 65802994b2 lf t55xx detect: report the sequence terminator only if DetectST found one
ASKDemod_ext sets its ST flag if DetectST cut terminators out, and never
clears it. The four ask attempts that call it preset the flag to true,
so every hit from them reported ST. Each of those hits now starts from
false and reports ST only if DetectST cut terminators out of that
demodulation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:41:50 -07:00
Matthew CarrollandClaude Opus 5.5 68d0106338 pm3_tests: lf t55xx detect on block 0 reads, with and without the sequence terminator
Each trace is the buffer 'lf t55xx detect --r0' leaves after reading block 0
of a T5577. info -1 decodes block 0 with the configuration detect found. A
test fails on a wrong polarity, a wrong offset or no answer.

detect -1 can't tell that a loaded buffer holds a block read, so
t55xx_fallback_try follows its strict fsk pass with a non-strict one.
The non-strict pass finds the fsk2a ST word even without the stride fix.
The fsk2a ST test therefore can't catch a fault in the strict pass's
stride check. Only a live detect can.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:41:49 -07:00
Matthew CarrollandClaude Opus 5.5 03bceddd50 lf t55xx detect: allow for the sequence terminator in a block read
On ask, DetectST cuts each sequence terminator out of the capture before
demodulation. A block read with ST set then demodulates to fewer bits
than t55xx_demod_yield_ok expects, and the yield check can reject it. If
DetectST cut anything, the yield check now expects fewer bits. This
covers the two ask demodulations in t55xxTryDetectModulationEx and the
two in t55xx_fallback_try.

On a block read, the strict fsk pass in t55xx_fallback_try accepts a
block 0 word only if the word repeats 32 bits later. After fsk
demodulation, a terminator adds about two bits between copies. If a
T5577 word has its ST bit set, the strict pass now also accepts a copy
33 to 36 bits later.

t55xx_ask_coherent keeps the 32 bit check. It decodes an ST word with
the wrong polarity and no ST, and the check rejects that word. The
fallback's ask attempts decode it correctly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:41:49 -07:00
Matthew CarrollandClaude Opus 5.5 1713b389ce traces: replace the weak Indala capture with an FC 123 card 1337 tag
Same setup as before: a T5577 written as Indala PSK1 RF/32, 24 mm off a
Proxmark3 Easy antenna, 4096 samples. The tracker fails on it and the fc/2
fallback reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:32:45 -07:00
Gabriele GristinaandClaude Mythos 5.2 f11efa88ff hf 15: fix two defects of the tag answer decoders
Handle15693SamplesFromTag() started the SOF detection on any step
above NOISE_THRESHOLD after 10 quiet samples, so a noise step in the
samples before a tag answer started it too. The false high phase
then either ended too short, and the decoder asked for 10 quiet
samples again and dropped the real edge, or ran into the real edge
and was too long. On an RDV2 the reader lost 3 of 78 answers of an
ICODE SLIX in hf 15 info, and hf 15 dump ended incomplete 7 times
in 10. Now a high phase that ends too short keeps the quiet time it
started from, and after a noise-sized edge an edge more than twice
the level taken as high restarts the SOF timing there.

The ASK and FSK decoders stored a byte before checking the buffer,
so an answer longer than max_len wrote one byte past it, and the ASK
decoder did not report the overflow when that byte ended with a 0
bit. They check first and mark the overflow with len = max_len + 1.
SniffIso15693() logs at most max_len bytes.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-13 01:18:37 +01:00
Gabriele GristinaandClaude Opus 5.5 5d447cd1a6 cliparser: keep a string option's terminator inside its buffer
CLIParamStrToBuf() refused only strings longer than maxdatalen, then
copied the string with its terminator. Most direct callers pass the
buffer size, so a string that fills the buffer gets its terminator
written one byte past it, e.g. hf mf view -f with a 1000-char name.
The check was ibuf + 1 > maxdatalen in aa3d29e6a and became
ibuf > maxdatalen in c2d5a7d74.

CLIParamStrToBuf() takes the buffer size again and refuses a string
that leaves no byte for the terminator. CLIGetStrWithReturn passes
*datalen + 1, since its callers give the maximum number of chars.
The direct calls that passed the buffer size - 1 or the field length
pass the buffer size. The uid buffers of hf mf restore and hf mf
hardnested get one more byte, so the 20 hex chars of a 10-byte UID
and the 14 of a 7-byte UID are still accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:45:08 +01:00
Gabriele GristinaandClaude Opus 5.5 6394622cf4 hf legic: fix the option checks of clone, migrate and wrbl
hf legic clone read --mcc <hex> with CLIParamStrToBuf() into a 1-byte
buffer. It refused --mcc 39 as a string too long, and with --mcc 9 it
wrote the character and its terminator into the buffer, a stack
buffer overflow that ASan reports. arg_get_str() never returns NULL,
so without --write clone printed "Output filename is invalid" for a
missing -o and "Target MCC must be exactly one byte" for a missing
--mcc, instead of the messages meant for those cases. With --write
the code read neither --mcc nor -o, so --write --mcc 39 looked for a
tag. The first clone help example used -c, an invalid option.

hf legic migrate had the same NULL check on --dcf, so it stopped with
"DCF must be exactly two bytes" whenever --dcf was missing. After
"parameter too large", migrate took --dcf 60EAFF as two bytes and
wrbl took --fill FFFF as one byte.

--mcc is now read as hex, as hf legic crc reads it. Clone's --mcc and
-o and migrate's --dcf are checked by their count, and clone reads
--mcc and -o with --write too. --mcc, --dcf and --fill are accepted
only when CLIParamHexToBuf() succeeds with the expected length. The
first clone help example uses --mcc, and the second einfo one uses
einfo instead of eview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:01:16 +01:00
Gabriele GristinaandClaude Opus 5.5 cd9cee29c0 client: report dump files that could not be written
pm3_save_dump(), pm3_save_dump_cb() and pm3_save_dump_json() returned
PM3_SUCCESS whatever their saveFile() and saveFileJSON() calls
returned, so hf mfu esave and hf st25ta esave exited 0 after a failed
save, and hid_sam_output() printed hints for a dump it had not saved.
saveFileEx() checked neither fwrite() nor fclose(), so after a failed
write, for example on a full disk, it printed
"Saved N bytes to binary file" and returned PM3_SUCCESS.

The three functions now return the save error, as pm3_save_mf_dump()
does. saveFileEx() returns PM3_EFILE after a failed fwrite() or
fclose() and reports the failure as saveFileJSON() reports a failed
save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 19:59:50 +01:00
Gabriele GristinaandClaude Opus 5.5 2bbaf340f4 hf gallagher test: fix the known vector and MES tests, run in make check
Two of the five tests failed on master. gallagher_decode_creds()
descrambled the caller's buffer in place, so test_known_vector_creds()
compared the encoding with its own input after the decode had changed
it. gallagher_construct_credential() never set csn_len, so test_MES()
encoded with an uninitialised CSN length and got 9C24CC5C instead of
4F36B74E, the formats/mes.md vector. The command printed no overall
result and make check did not run it, so no automated run showed the
failures.

gallagher_decode_creds() now decodes a copy, the constructor sets
csn_len, GallagherTest() prints "Tests ( ok )" or "Tests ( fail )" as
DesfireTest() does, and pm3_tests.sh runs hf gallagher test with the
other hf self-tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 18:49:27 +01:00
Gabriele GristinaandClaude Opus 5.5 98b3e86e9c hf mf sen: field off and a message on Enter, fix options and saves
Enter or a timeout in a chunked key check left the field on, Enter gave
no message and was lost in a single-key probe. Every --parity-mask
value was refused, over the --max-online-candidates limit the keys
found were dropped, after a failed --keep-nonces save the command
printed "Saved" and returned success, and the dictionary fallback said
no key authenticated when one had.

After a stop the field is now dropped and the progress table closed,
Enter prints "aborted via keyboard!" and also stops the probes,
--parity-mask takes 1..F, the keys found are kept over the limit,
pm3_save_fm11rf08s_nonces() returns the save result and the fallback
line is printed only when no key authenticated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:28:09 +01:00
iceman1001andClaude Opus 5.5 3bfa83b92f aidlist: add two HID configuration card AIDs
`hf gp aids` found A0000003820013000101 and A0000003820017000101 on two
physical HID reader configuration cards and could not name either.
They sit in the same HID Global range as the Reader Manager admin card
AIDs already listed (A00000038200xx000101).

Added as "HID configuration card", type configuration. No Sources entry:
these come from physical cards, not from the Reader Manager app the
neighbouring entries cite.

Verified A0000003820017000101 on its card: `hf gp aids` now prints
"HID configuration card | HID Global". A0000003820013000101 is taken from
a scan of the other card. JSON valid, tools/check_json_uniq.py passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:59:10 +07:00
iceman1001andClaude Opus 5.5 419e83bde4 hf ntag424 getfs: list every file when no file number is given
Finding out which files an NTAG 424 has meant running getfs once per
file number and reading past "91 F0 Specified file number does not
exist" for the gaps. The card can't be asked: it answers GetFileIDs
with 91 1C, command not supported.

`--fileno` is now optional. Without it getfs asks GetFileSettings for
file numbers 0-31, prints the settings of every file that exists the
same way as for a single file, and ends with "Found 3 files: 1, 2, 3".
"No such file" is the expected answer for most numbers and stays quiet;
any other status is reported against its file number. A number the
card never answered is not taken to mean there is no file there: the
list then says it is incomplete and the command returns PM3_EPARTIAL.

The probe uses its own exchange rather than ntag424_get_file_settings(),
since ntag424_exchange_apdu() reports every unexpected status as an
error and returns PM3_ESOFT both for a card error and for no response.

Behaviour change: `hf ntag424 getfs` without arguments lists all files
instead of failing on the missing `--fileno`. `--fileno N` is unchanged.

Tested on an NTAG 424 DNA: files 1, 2 and 3 found in 0.59 s, settings
identical to querying each file on its own, file 2's SDM block included;
`--fileno 3` and `--fileno 4` behave as before. The incomplete-list path
was not exercised on hardware. Builds clean with gcc and clang.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 21:54:40 +07:00
Iceman d08ed4fc68 Merge pull request #3803 from matrix/fix-mfu-chk-abort
hf mfu chk: stop on Enter in a chunk, fix the speed and progress lines
2026-11-12 22:25:09 +08:00