Compare commits

...
248 Commits
Author SHA1 Message Date
iceman1001 aceed281e8 Release v4.18589 - Aurora 2024-05-28 10:36:32 +02:00
iceman1001 efcfd3e126 text 2024-05-28 10:36:23 +02:00
iceman1001 4a4e7bc27f wrong lib 2024-05-28 10:32:50 +02:00
iceman1001 d6356bd3f4 wrong file 2024-05-28 10:30:40 +02:00
iceman1001 9cc8f6a10b Merge branch 'master' of github.com:RfidResearchGroup/proxmark3 2024-05-28 10:27:33 +02:00
iceman1001 54644c6113 update cmakefile with changes from client cmake 2024-05-28 10:27:23 +02:00
iceman1001 adfbcbc193 miscchecks white space 2024-05-28 10:14:02 +02:00
iceman1001 6bdfe11c1a minor fixes 2024-05-28 10:00:11 +02:00
iceman1001 98acac3fc2 fix unused warning 2024-05-28 09:52:27 +02:00
Iceman 0562ff6723 Merge pull request #2394 from ikarus23/master
add keys from MCT project
2024-05-27 21:23:32 +02:00
ikarus 897643f4cc add keys from MCT project 2024-05-27 21:19:13 +02:00
iceman1001 369db7c9d7 style 2024-05-27 20:29:02 +02:00
iceman1001 8d1e9c1f5d adapt response struct for hitag2 so be large enough to handle 256bytes for cryptostream 2024-05-27 15:19:22 +02:00
iceman1001 d3d701f538 the generation of NrAr is used in the regression tests. I readded the old way and if you call the hitag2_gen_nRaR.py with five params, you get the nice commands instead 2024-05-27 15:08:49 +02:00
Iceman 1e6915fcd7 Merge pull request #2393 from uhei/fix-legic-clone
fix: hf_legic_clone.lua script
2024-05-25 16:41:59 +02:00
Uli Heilmeier 4babe8f012 fix: hf_legic_clone.lua script
Fixes: #2236
2024-05-25 16:14:01 +02:00
Iceman 2b8ae4079c Merge pull request #2391 from ry4000/master
Added Jett's 24 Hour Fitness
2024-05-22 17:44:56 +02:00
ry4000 5a133e39bd Added Jett's 24 Hour Fitness
Updated gym list; made some minor spelling corrections.

Jett's 24 Hour Fitness might also access Zap Fitness gym tags; however, I am unable to test that just yet as I have been unable to buy any of their cancelled credentials on second-hand marketplaces.

Signed-off-by: ry4000 <154689120+ry4000@users.noreply.github.com>
2024-05-22 10:05:43 +10:00
Iceman 36d93395e5 Merge pull request #2390 from kormax/new-aid-ecp
Add new AID & ECP definitions
2024-05-21 21:57:57 +02:00
kormax 7570f4a87c add new AID & ECP definitions 2024-05-21 22:49:06 +03:00
iceman1001 b9a583cdb5 swapped out to use bigbuff memory allocation and also show an empty message 2024-05-21 18:31:51 +02:00
iceman1001 1b387ae90e some simple identification tests, will need to expand on the idea later 2024-05-20 21:26:12 +02:00
iceman1001 968bfcd591 added "lf hitag reader" command 2024-05-20 17:47:44 +02:00
iceman1001 00407383fe hitag2 crack1,2 fixes. The error response I never seen, the fct to hex2bin prone to overflows. This should make both attack vectors more stable 2024-05-20 14:22:55 +02:00
Iceman d2003b7b65 Merge pull request #2387 from shoganaich/master
Inside Wash Membership Card in Portugal
2024-05-18 10:50:13 +02:00
Victor Cardoso 9787821a53 Inside Wash Membership Card in Portugal
Just one key is used. The rest of the card is blank.

I tested on 3 different cards and got through a hardnested attack.

Signed-off-by: Victor Cardoso <shoganaich@tutanota.com>
2024-05-17 14:57:37 +01:00
Philippe Teuwen 676c91baaf pk st25tn 2024-05-16 23:50:35 +02:00
iceman1001 7dfcc47975 Merge branch 'master' of github.com:RfidResearchGroup/proxmark3 2024-05-16 22:51:06 +02:00
iceman1001 d9ec99f903 found the bug in a call to hex2binarray() fct which overwrote first 16 bytes of keystream. Fixed loops. Crack2 now generates same data as RFIDLer impl. 2024-05-16 22:49:24 +02:00
Iceman a0eeb00132 Merge pull request #2386 from mifa-om/master
fixed em4x50_sim_read_bit
2024-05-15 12:09:35 +02:00
mifa-om 12f9ac5275 fixed em4x50_sim_read_bit 2024-05-15 11:34:44 +02:00
Iceman 3d4b5fc413 Merge pull request #2369 from jlitewski/loud-nightingale
Another fix to the Buffer SaveStates
2024-05-15 09:41:56 +02:00
Iceman 184393ee41 Merge branch 'master' into loud-nightingale
Signed-off-by: Iceman <iceman@iuse.se>
2024-05-15 09:41:50 +02:00
iceman1001 e5d5510b61 text 2024-05-15 09:37:44 +02:00
iceman1001 498af46fbf fix #2384 the use of free() is completely wrong as we use bigbuff allocations. Converted the old style to new and removed the dynamic allocation. 2024-05-15 09:36:31 +02:00
Iceman 2b276cae1a Merge pull request #2385 from henrygab/em4x70_add_tests
add `lf em 4x70 calc` and self-tests
2024-05-15 09:19:41 +02:00
Henry Gabryjelski f9dbe3fb6e Update CHANGELOG.md
Signed-off-by: Henry Gabryjelski <henrygab@users.noreply.github.com>
2024-05-14 21:34:43 -07:00
Henry Gabryjelski 20711e7037 Add em4x70 tests 2024-05-14 21:06:35 -07:00
Henry Gabryjelski f58992922d limit freen color to calculated values 2024-05-14 20:35:27 -07:00
Henry Gabryjelski 2757881945 functions should be static where possible 2024-05-14 20:22:30 -07:00
Henry Gabryjelski 2952d55904 Add lf em 4x70 calc 2024-05-14 20:21:42 -07:00
Henry Gabryjelski b7fff95b7c Improve editor folding (some editors use indentation as cue) 2024-05-14 19:16:37 -07:00
Henry Gabryjelski d27c084819 Internal code cleanup.
Reduce ambiguity in function and parameter names.
2024-05-14 19:16:05 -07:00
iceman1001 cacc1c1445 unused 2024-05-14 16:12:42 +02:00
iceman1001 cd1f935846 fix missing 2024-05-14 15:20:01 +02:00
iceman1001 b696c498b7 scope, const 2024-05-14 14:37:08 +02:00
iceman1001 5fd4d7e774 fix const param, bitwiseboolean 2024-05-14 14:29:30 +02:00
iceman1001 4bbfc944f3 fix const params, logic, casting 2024-05-14 14:13:13 +02:00
iceman1001 2d3e71d556 fix fct names, const params 2024-05-14 12:52:44 +02:00
iceman1001 bae6f5196f fix fct name mismatch 2024-05-14 12:42:08 +02:00
iceman1001 9535bd5a11 fix fct name mismatch 2024-05-14 12:41:22 +02:00
iceman1001 6f23b7f3eb fix fct name mismatch, const params, 2024-05-14 12:40:26 +02:00
iceman1001 f63ba3f31a fix fct name mismatch 2024-05-14 12:32:57 +02:00
iceman1001 5107b7ce04 fix fct names mismatch, const params, 2024-05-14 12:29:33 +02:00
iceman1001 2e2fa850bb const params, vars, scope, bad if statements 2024-05-14 12:25:00 +02:00
iceman1001 f3f647e6af fix const params, unused set vars 2024-05-14 12:04:03 +02:00
iceman1001 4aa8645a33 fixed order of checking 2024-05-14 12:00:19 +02:00
iceman1001 0096672d38 fix fct names and consts and bad if statement 2024-05-14 11:57:47 +02:00
iceman1001 a9a3c0bea9 const params 2024-05-14 11:45:36 +02:00
iceman1001 480d5a3241 array init 2024-05-14 11:26:16 +02:00
iceman1001 bf24c2b01f const params and init arrays 2024-05-14 11:23:33 +02:00
iceman1001 2c1f45f3aa fix const params and if statements 2024-05-14 11:20:36 +02:00
iceman1001 5ee9014e02 const 2024-05-14 11:10:50 +02:00
iceman1001 3430e20459 fix const params, lessen variable scope and fixing func arguments names 2024-05-14 11:10:12 +02:00
iceman1001 0963f51318 fix const params, lessen variable scope and fixing func arguments names 2024-05-14 11:04:41 +02:00
iceman1001 cb937a3f57 fix overwriting return value in one case 2024-05-14 10:59:10 +02:00
iceman1001 e3ceb2ffe4 const param 2024-05-14 10:10:44 +02:00
iceman1001 6abb217a18 fix shadowed variable 2024-05-14 10:10:12 +02:00
iceman1001 42f0699c78 style 2024-05-14 10:04:28 +02:00
iceman1001 72a11cfd89 Merge branch 'master' of github.com:RfidResearchGroup/proxmark3 2024-05-14 10:03:58 +02:00
iceman1001 dd94207ee8 fix bad compare 2024-05-14 10:02:10 +02:00
Iceman 6e938fa0c5 Merge pull request #2381 from Akury83/patch-1
Update to include USCUID-UL
2024-05-14 09:15:30 +02:00
Henry Gabryjelski 483b192d40 rename parameter for em4x70_receive
Avoid generic "length" parameters, as they are often ambiguous.

Prefer `byte_count`, `element_count`, `bit_count` or more explicit names to reduce misunderstandings and thus reduce bugs.
2024-05-13 10:19:00 -07:00
iceman1001 77db65a590 there were several memory leaks in hf 15 dump. Fixed by @jlitewski 2024-05-13 14:29:27 +02:00
iceman1001 11a298dc42 changed hf search to look for topaz first and commented out ICT code path 2024-05-13 11:12:27 +02:00
iceman1001 bbbe985111 when changing to 50 loops on device side, the felica reader code on client side timedout and it wasnt handled good enough so the return code was PM3_SUCCESS giving a false positive. Increase timeout, decrease loops to 25, and better loop handling of return value 2024-05-12 20:17:50 +02:00
iceman1001 3502da17df assert its smaller than 5 2024-05-12 19:36:28 +02:00
iceman1001 c50f109f05 the failed compiling on MINGW/proxspace warns over a overflow in buffer[5], the return value in utf8_check_first() can be 0 - 4, which used later in loop as index with 1 as start offset. a 4 will overflow the buffer[5]. Increased buffer with to just in case to support the zero terminator. Another option where this code will bail out is, 0 is goto out, 1 will trigger the assert and break client. A bit ruff I say. 2024-05-12 19:14:17 +02:00
Iceman d714902fc0 Merge pull request #2373 from jlitewski/marker-oob-fix
Fix OOB segfault with markers
2024-05-12 17:15:29 +02:00
Iceman fd445c7af1 Merge pull request #2378 from henrygab/em4x70_parity_break
Prevent sending corrupt data to em4x70 w/`--par` option
2024-05-12 17:14:20 +02:00
Iceman a627e6cc82 Merge branch 'master' into em4x70_parity_break
Signed-off-by: Iceman <iceman@iuse.se>
2024-05-12 17:13:24 +02:00
Iceman f9929be99a Merge pull request #2380 from henrygab/macos_action_python_install_fix
Fix Github Action builds
2024-05-12 17:04:46 +02:00
Iceman b72a44f5d1 Merge pull request #2375 from RunTheBot/patch-1
Added Presto Transit Card to aid_desfire.json
2024-05-12 17:03:25 +02:00
Henry Gabryjelski 0de99805cd Fix broken test 2024-05-06 09:09:46 -07:00
Henry Gabryjelski c40f4be3e6 re-enable broken hitag2 test 2024-05-06 07:59:41 -07:00
Akury83 541bb31143 Update to include USCUID-UL
Update to include USCUID-UL chips
Removed hidden block reading and writing from UFUID chips, as these do not have hidden blocks.

Signed-off-by: Akury83 <87064827+Akury83@users.noreply.github.com>
2024-05-06 23:30:57 +10:00
Henry Gabryjelski 7712acff64 Use actions/setup-python for Ubuntu also 2024-05-05 18:35:38 -07:00
Henry Gabryjelski 9d33646b80 Disable broken hitag2 test so github actions work 2024-05-05 18:27:35 -07:00
Henry Gabryjelski 3d824425d2 Use actions/setup-python for MacOS 2024-05-05 18:23:45 -07:00
Henry Gabryjelski 18cbc7259c prevent sending corrupt data to em4x70 tags 2024-05-05 16:00:16 -07:00
Henry Gabryjelski b0b9f4fa42 Add key that tests autorecovery more quickly
This autorecovery test key also has three potential matches
for the last phase, thus ensuring authentication test is
required to determine which of those keys was actually used.
2024-05-05 15:57:26 -07:00
Henry Gabryjelski 569d57719d Fix firmware return value for em4x70 to always be of type PM3_* 2024-05-05 15:54:00 -07:00
RunTheBot 8bf57b2094 Update CHANGELOG.md
Signed-off-by: RunTheBot <58890327+RunTheBot@users.noreply.github.com>
2024-05-02 18:46:09 -04:00
RunTheBot f1adb30a9c Added Presto Transit Card to aid_desfire.json
Signed-off-by: RunTheBot <58890327+RunTheBot@users.noreply.github.com>
2024-05-02 18:40:13 -04:00
jlitewski b20d3f44ad Fix OOB segfault with markers 2024-04-27 09:06:40 -04:00
iceman1001 2bc7c50302 changed fct names 2024-04-26 22:52:49 +02:00
iceman1001 097dfba5c8 simplified loop 2024-04-26 16:25:40 +02:00
iceman1001 05df50678c missing header 2024-04-26 16:18:10 +02:00
iceman1001 dee84b5b6f added "lf hitag crack2" to support the second attack vector against Hitag2, based on all work from @kevsecurity Kev Sheldrake in the RFIDler repo. This is WIP, not working at the moment 2024-04-26 15:38:06 +02:00
Iceman f71c9a5e59 Merge pull request #2370 from jlitewski/qt-fix
Fix the issue of SKIPQT builds not working
2024-04-26 14:50:49 +02:00
jlitewski 8789991f9a Fixed compile issues I missed 2024-04-26 08:29:17 -04:00
jlitewski d820153a61 Fix the issue of SKIPQT builds not working 2024-04-26 07:23:38 -04:00
iceman1001 eac3774189 changed to 50 polls, not sure if its good. Maybe looking at timeout 1060ms value instead? also cleaned out debug statements 2024-04-26 12:15:38 +02:00
jlitewski f1340495b3 Another fix to the Graph SaveStates 2024-04-25 22:06:12 -04:00
iceman1001 5396524dc4 the change to download the anticollision signal trace to "hf 14b reader" made it slow. Making it optional instead improves performance in "hf search" 2024-04-25 08:02:11 +02:00
Iceman 6e6fa4270b Merge pull request #2367 from kitsunehunter/update_elite_helptext
update iclass elite key chk helptext
2024-04-25 07:42:21 +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 36603818d1 fixed a valgrind memory usage of uninitialised array 2024-04-25 07:29:22 +02:00
Xavier 99a2a37e82 update iclass elite key chk helptext
Signed-off-by: Xavier <90627943+kitsunehunter@users.noreply.github.com>
2024-04-24 21:55:24 -04:00
iceman1001 d635f39048 fix when length is not even dividable with four. 2024-04-24 21:33:56 +02:00
iceman1001 4dc1f9c62d clean up 2024-04-24 21:32:51 +02:00
iceman1001 b754f09d24 fix valgrind memory bug 2024-04-24 21:24:52 +02:00
iceman1001 4b2c42aff8 update checkout to v4 2024-04-24 11:10:05 +02:00
iceman1001 aa504ace00 update codeql version to v3 2024-04-24 11:02:14 +02:00
iceman1001 f6e0b8c330 style 2024-04-24 09:13:32 +02:00
Iceman 8f73520173 Merge pull request #2365 from gentilkiwi/patch-1
Update intertic.py to support Saint-Malo (MAT / RATP)
2024-04-24 00:24:32 +02:00
iceman1001 59c07f911a - now are able to verify signature. Thanks @doegox! 2024-04-24 00:23:16 +02:00
Benjamin DELPY c3ad45d84c Update intertic.py to support Saint-Malo (MAT / RATP)
Signed-off-by: Benjamin DELPY <benjamin@gentilkiwi.com>
2024-04-24 00:15:54 +02:00
iceman1001 b84fa69f39 ... checks 2024-04-23 23:13:22 +02:00
Philippe Teuwen 455d4a9a74 key id 01? 2024-04-23 22:58:18 +02:00
Philippe Teuwen 5ca6d5c493 Update recover_pk.py 2024-04-23 22:51:47 +02:00
Iceman 8550cf0e85 Merge pull request #2364 from xueliu/delete-duplicate-header-file
Delete a duplicate header file fpga.h in armsrc/appmain.c
2024-04-23 21:12:39 +02:00
iceman1001 6aded8a3b5 textual 2024-04-23 19:57:32 +02:00
Xue Liu 4216900694 - delete a duplicate header file in armsrc/appmain.c
Signed-off-by: Xue Liu <liuxuenetmail@gmail.com>
2024-04-23 16:34:26 +02:00
iceman1001 1a3613901e since I messed up the calypso and mobib lua script, I made a native implentatin instead. I leave the decoding of the extracted data for people to come to have some sort of challenge 2024-04-23 10:09:46 +02:00
iceman1001 2d36efe821 updated type identifications. Will need a better way to detect size of those 15693 ones 2024-04-23 08:43:55 +02:00
iceman1001 3ef3e3a63d update signature data 2024-04-23 02:16:01 +02:00
Iceman 399b85919a Merge pull request #2362 from gentilkiwi/patch-1
Update recover_pk.py with first TruST25 (ST) key
2024-04-23 01:35:20 +02:00
Benjamin DELPY e6ad06a2c8 Update recover_pk.py with first TruST25 (ST) key
TruST25 (ST) - KeyID 0x04?
`curve=secp128r1, hash=sha256` - from block 63 in ST25TV, starting with KeyID?

Tested on multiple `ST25TV02KC` - `K04S` at block 63, signature in ... ASCII...

Signed-off-by: Benjamin DELPY <benjamin@gentilkiwi.com>
2024-04-23 01:11:05 +02:00
iceman1001 b4ba36c1ff adaptations 2024-04-22 19:58:52 +02:00
iceman1001 934a969d41 adapt some detection of fudan 2024-04-22 19:52:24 +02:00
Iceman a65fd6e1fa Merge pull request #2361 from jlitewski/purring-basilisk
Implemented Buffer SaveStates
2024-04-22 17:41:09 +02:00
Iceman 9343014b68 Merge branch 'master' into purring-basilisk
Signed-off-by: Iceman <iceman@iuse.se>
2024-04-22 17:41:01 +02:00
iceman1001 8edf45a6c9 darn it 2024-04-22 17:36:22 +02:00
iceman1001 5f65b5a19e fix order 2024-04-22 17:30:52 +02:00
iceman1001 cad63e7162 fix missing crc calcs 2024-04-22 16:55:54 +02:00
iceman1001 3f6ea0f0fc style 2024-04-22 16:35:22 +02:00
iceman1001 4762f5f33b fix error from goto ... 2024-04-22 16:30:09 +02:00
iceman1001 1016108694 comment out pwm code 2024-04-22 16:23:45 +02:00
iceman1001 c8849af5e0 This is the major changes made to the HITAG2 commands. Its heavly based on RFIDLers implementation and its been converted to work with Proxmark3. Special thanks to @kevsecurity for his amazing implementations of the Gone in 360 Seconds paper by Roel, Flavio & Balasch. Thanks to @adamlaurie for his RFIDler project. It wouldnt been doable without it. 2024-04-22 16:20:24 +02:00
JLitewski 97d5c4e50c Merge branch 'master' into purring-basilisk
Signed-off-by: JLitewski <hackhalotwo@gmail.com>
2024-04-22 09:49:31 -04:00
iceman1001 fc2a3dd2c5 Updated the command according to @whywilson's findings. and fixed the wrong byte aswell 2024-04-22 15:41:59 +02:00
JLitewski 6097c531c8 Merge branch 'master' into purring-basilisk
Signed-off-by: JLitewski <hackhalotwo@gmail.com>
2024-04-22 06:42:45 -04:00
iceman1001 4304372858 tweaking felica timings to see if it gets better results 2024-04-22 10:41:28 +02:00
iceman1001 5025a18722 pushed update to use latest setup script 2024-04-22 09:51:42 +02:00
iceman1001 cc5998a153 adapt awid 2024-04-22 09:47:40 +02:00
iceman1001 362cfff60a fix ref name 2024-04-22 09:44:07 +02:00
iceman1001 d3f8323a3f @mwalker33 psk tests, maybe one day its good enough to merge in 2024-04-22 09:42:46 +02:00
iceman1001 1b45112ad0 style 2024-04-22 09:40:50 +02:00
iceman1001 042ba20d58 style 2024-04-22 09:36:42 +02:00
iceman1001 12e38cdfff text 2024-04-22 09:34:46 +02:00
iceman1001 ac809c4a9f support function 2024-04-22 09:29:38 +02:00
iceman1001 47262433e8 missing header 2024-04-22 09:27:54 +02:00
iceman1001 02872796aa should wait for a reply from device that sniffing is done 2024-04-22 09:26:25 +02:00
iceman1001 d340de388d textual 2024-04-22 09:23:22 +02:00
iceman1001 67c14c5314 adapt regression tests 2024-04-22 09:21:55 +02:00
iceman1001 365454bb3c fixing buffer overflow when reading large files 2024-04-22 09:17:58 +02:00
iceman1001 d1e921171b removed old unused rfidler code. Added modified code to work with proxmark3. Thanks to @kevsecurity and @AdamLaurie! 2024-04-22 09:10:09 +02:00
iceman1001 87c6633de1 add support for generation 2 magic command when setting UID on ISO15693 cards. ref:: https://github.com/RfidResearchGroup/proxmark3/issues/1604#issuecomment-2068444071 2024-04-22 09:04:01 +02:00
jlitewski 2d0bc5100a Forgot about resetting the grid offsets 2024-04-20 22:47:42 -04:00
jlitewski 791f02209d Implemented Buffer SaveStates 2024-04-20 14:14:15 -04:00
iceman1001 508a4ed064 missing update 2024-04-20 11:53:55 +02:00
iceman1001 543f8df8c0 fixes to when thing gets wrongly identified 2024-04-20 11:32:51 +02:00
iceman1001 c860bd252a textual detection 2024-04-20 09:38:04 +02:00
iceman1001 b09c0e0d5f textual 2024-04-20 08:47:49 +02:00
Iceman 591795a8fc Merge pull request #2359 from jlitewski/marker_v2
Graph Markers, Version 2
2024-04-19 17:17:22 +02:00
Jacob Litewski 560b6f9dc2 Marker V2 fixes 2024-04-19 07:53:20 -04:00
Iceman fbe101791a Merge pull request #2360 from Thechamp669/patch-1
Update lf_ioprox_bulkclone.lua Spelling
2024-04-19 09:45:07 +02:00
Thechamp669 28bcedbc4c Update lf_ioprox_bulkclone.lua Spelling
Typo

Signed-off-by: Thechamp669 <mjpdobbs@gmail.com>
2024-04-18 20:44:28 -07:00
Jacob Litewski bb1c662af0 Graph Markers, Version 2 2024-04-18 23:08:33 -04:00
Iceman fc584b348a Merge pull request #2358 from jlitewski/opbuffer
Disable Rendering the Operation Buffer
2024-04-19 00:15:08 +02:00
Jacob Litewski dadd6ee65d Disable Rendering the Operation Buffer
For now, at least until I can fully and correctly implement it.
2024-04-18 17:37:06 -04:00
iceman1001 5a524a2ec9 renamed and since there is already another same styled script, this became v2. also applied prefered coding style 2024-04-18 12:03:27 +02:00
iceman1001 bc9f406dc0 renamed the scripts to fit current naming convention and applied same code style 2024-04-18 11:58:31 +02:00
Iceman acfda59ff2 Merge pull request #2356 from JakaBac/time-include
fix implicit use of time()
2024-04-18 10:30:28 +02:00
Iceman 6d7769ca88 Merge pull request #2355 from Thechamp669/master
Add files via upload
2024-04-18 10:30:03 +02:00
Jaka c871e435e4 fix implicit use of time() 2024-04-18 09:40:00 +02:00
Thechamp669 83e346005c Add files via upload
Signed-off-by: Thechamp669 <mjpdobbs@gmail.com>
2024-04-17 21:16:59 -07:00
Iceman 42d0cc04b1 Merge pull request #2354 from philicious/fix-typo-qt5-cmake
Fix typo in cmake for qt5 detection
2024-04-17 15:51:26 +02:00
iceman1001 45bf8801fd Merge branch 'master' of github.com:RfidResearchGroup/proxmark3 2024-04-17 12:37:12 +02:00
iceman1001 a6dfe052bd missmatching name 2024-04-17 12:36:33 +02:00
philicious c9a83b0222 missed in #2351 2024-04-16 23:07:22 +02:00
philicious c44992232e Update gitignore for CMake artifacts 2024-04-16 23:04:14 +02:00
Iceman 7857baa5f4 Merge pull request #2352 from philicious/fix-macosx-make-python312
Fix building against Python3.12 on MacOS
2024-04-16 22:39:11 +02:00
Iceman 9ebc753dd9 Merge pull request #2351 from philicious/fix-macosx-qt5-detection-cmake
Fix homebrew Qt5 detection on MacOS also for cmake
2024-04-16 22:37:13 +02:00
iceman1001 6cc9c435e0 fix #2350 updated the swig wrappers to swig version 4.2.1. Lets hope it solves the OSX issues 2024-04-16 22:35:10 +02:00
philicious bfaf440fb2 Fix building against Python3.12 on MacOS with make by prefering python3-embed over python3 (as CMakeLists.txt does) 2024-04-16 22:34:47 +02:00
philicious 41d808bf69 Fix homebrew Qt5 detection on MacOS also for cmake 2024-04-16 22:22:41 +02:00
Iceman 628ed5c96b Merge pull request #2349 from philicious/fix-macosx-qt5-detection
Fix homebrew Qt5 detection on MacOS
2024-04-16 21:23:28 +02:00
philicious 87597835e6 Fix homebrew Qt5 detection on MacOS 2024-04-16 20:51:47 +02:00
Iceman ce61d94040 Merge pull request #2348 from jlitewski/plot_cursor_improvements
Marker code cleanup
2024-04-15 01:51:10 +02:00
Jacob Litewski 31bfa16b76 Marker code cleanup 2024-04-14 14:58:52 -04:00
Iceman 197baa4623 Merge pull request #2347 from jlitewski/plot_refactor
Refactored Plot Annotations and some cleanup
2024-04-14 12:19:16 +02:00
Jacob Litewski f2afbca6ec Refactored Plot Annotations and some cleanup 2024-04-13 23:03:35 -04:00
iceman1001 3c8b1317c2 deprecated hex2bin and bin2hex. Use data num instead 2024-04-13 11:30:26 +02:00
Iceman de7579ab00 Merge pull request #2345 from jlitewski/plot_gui_improvements
Plot Improvements, Round 1
2024-04-13 11:01:32 +02:00
iceman1001 500e10f3a5 text 2024-04-13 10:59:55 +02:00
iceman1001 6bc6ec23ce fix #2346 refactored the write loop before it assumed a full t55xx memory layout. Now handles block writes to individual parts 2024-04-13 10:59:07 +02:00
Jacob Litewski 0608a7c530 Minor Changes to the Operation Buffer Implementation
Instead of being initialized as all zeros and showing changes if those values are not zero, it now has a copy of the Graph Buffer data, and will show changes if it's different from what's stored in the Graph Buffer.
2024-04-12 08:34:05 -04:00
Jacob Litewski 6b72e39f51 Command Organization in cmddata.c
Getting ready to do some refactoring!
2024-04-11 20:06:36 -04:00
iceman1001 9a73e77d72 style 2024-04-11 22:08:25 +02:00
Iceman 2612b87f41 Merge pull request #2343 from p51d78th/master_mine
Fix compile error from variable type declaration
2024-04-11 19:20:29 +02:00
Jacob Litewski c2e43c3f46 Rough Implementation of the Operations Buffer
The Operations Buffer is basically a buffer of changes to the Graph Buffer. Instead of writing all the changes to the Graph Buffer directly, I plan to have those changes written to the Operation Buffer, so you can visually see what would be changed before it's applied.
2024-04-11 08:57:26 -04:00
Jacob Litewski 8e3efec3e2 Rename s_Buff to s_OverlayBuff 2024-04-11 08:46:46 -04:00
Jacob Litewski 3d2169b833 Cursor A graph scrolling implementation
If Cursor A goes off the screen, it will reposition the window to place the cursor in the middle of it.
2024-04-10 21:01:05 -04:00
David Driscoll f3d9423f70 Fix compile error from variable type declaration 2024-04-10 11:52:11 -04:00
iceman1001 6a7e70ad26 style 2024-04-10 14:26:05 +02:00
Iceman 8426beb173 Merge pull request #2342 from jlitewski/plot_point_mods
Plot improvements
2024-04-10 08:29:17 +02:00
jlitewski ad01195a04 Plot improvements
- Added hotkeys to move the yellow/purple cursor around
- Added hotkeys to manually increment/decrement a value from a plot point
-- This is currently the point where the yellow cursor is at
2024-04-09 22:47:40 -04:00
iceman1001 befb2644d2 dont hook signal in MINGW environments like proxspace 2024-04-09 15:30:34 +02:00
iceman1001 9b8cf1e323 the waitforResponseTimeoutW fct will lock the client in situations like sniffing and if the device locks up there is no way to exit nice. This fix will look for life signs from the device. if lost, we will break. Allowing for the client to handle it better 2024-04-07 23:50:58 +02:00
iceman1001 4e540053e9 style 2024-04-07 11:38:51 +02:00
iceman1001 9ba8937f3c text 2024-04-07 11:32:25 +02:00
iceman1001 ab984c5fdf minor style 2024-04-06 21:11:07 +02:00
iceman1001 a68a5a8825 if using readline , the CTRL-C should now handle it a bit more nicer. Especially the pm3 history file should be flushed with the upside you dont loose all your commands you issued and mistakingly pressed CTRL-C. for the linenoice and Win32, you still have this issue. 2024-04-06 20:57:54 +02:00
iceman1001 7c755e20bc parentheses miss 2024-04-06 18:53:04 +02:00
iceman1001 27735355cd initial text changes 2024-04-06 15:48:41 +02:00
Iceman 2110af617a Merge pull request #2340 from gentilkiwi/patch-1
Update intertic.py to support Lyon (TCL / Keolis)
2024-04-05 00:41:04 +02:00
iceman1001 82a809887c hf mf ginfo -now supports decoding of a user supplied configuration block and improved textual output 2024-04-05 00:40:13 +02:00
iceman1001 39984c400a make Ev1 keys stick out and with an explaination making it a bit more clear for user 2024-04-05 00:37:02 +02:00
Benjamin DELPY 10c4679f1e Update intertic.py to support Lyon (TCL / Keolis)
Signed-off-by: Benjamin DELPY <benjamin@gentilkiwi.com>
2024-04-05 00:20:55 +02:00
iceman1001 263180377a sixth time is the charm 2024-04-04 00:40:42 +02:00
iceman1001 77c549acad test5... cleaning 2024-04-04 00:26:16 +02:00
iceman1001 d22b57008a test4 2024-04-04 00:18:56 +02:00
iceman1001 d882cb9b90 test3 2024-04-04 00:15:51 +02:00
iceman1001 32d08c9db9 test2 2024-04-04 00:07:53 +02:00
iceman1001 720a518b53 seems to be python3.so that the linker CLANG on OSX which alerts for it cant do dynamic lookups 2024-04-03 23:55:54 +02:00
iceman1001 a4c94ffd3b textual 2024-04-03 17:22:45 +02:00
iceman1001 679f2d4feb remove comments 2024-04-03 17:15:12 +02:00
iceman1001 3ea2cb0eda faster return 2024-04-03 17:14:44 +02:00
iceman1001 9bbdb747c8 Merge branch 'master' of github.com:RfidResearchGroup/proxmark3 2024-04-03 17:07:19 +02:00
iceman1001 21f25ccd1f the data load for long file since we got the extended sniff possibility is hard to see. This commit now shows a comma printed version. It helps me :) 2024-04-03 17:05:34 +02:00
Philippe Teuwen c183894cb4 fix doc and add similar to 2024-03-27 16:41:44 +01:00
iceman1001 700d558432 move hitag2 crypto parts to the common folder in order to be able to use it on the client side. Some textual and minor adaptations across the bord 2024-03-27 09:32:00 +01:00
iceman1001 cdc46d5d2b textual and some layouts 2024-03-27 09:16:37 +01:00
iceman1001 371e7e5ebe forgot the header file 2024-03-26 15:21:15 +01:00
iceman1001 d5e33fb209 added some support functions 2024-03-26 15:13:23 +01:00
iceman1001 64a5b048e5 text 2024-03-26 15:11:12 +01:00
iceman1001 ab2e3d5179 updated the OpenCL Headers from https://github.com/KhronosGroup/OpenCL-Headers/tree/main/CL. 2024-03-26 15:08:34 +01:00
iceman1001 c66e781a9c annotation of the hitag2 protocol now properly identifies different parts without shifting of whole hex arrays. Took the idea from RFIdler (@adamLLaurie) where he treats it like a binary string instead. It works. Problem: We use whole bytes in our logging protocol and Hitag2 uses 5, 10, 32, 64 bits commands. START_AUTH is 11000, which as a MSB aligned byte is 0xC0. Now we shift it down to LSB centered and 11000 becomes 0x18. This reduces all issues with handing the rest of the array. \n\nTake note that our protocol uses whole bytes. I had to print out number of actually captured bits in the trace log now. Otherwise 65 or 71 bits would not look any different but will not work when used with other tools. This also means we abuse the logging protocol by using the parity byte arry to store number of "left over bits" in the par[0] position. 2024-03-26 15:04:39 +01:00
iceman1001 529d57a181 style 2024-03-25 23:34:53 +01:00
iceman1001 140cc1d957 style 2024-03-25 23:33:44 +01:00
Iceman 1a7b2856ef Merge pull request #2337 from craftbyte/desfire-deleteapp-fix
Fix MIFARE DESfire DeleteApp command
2024-03-21 14:13:26 +01:00
Iceman 9889228b50 Merge pull request #2338 from craftbyte/desfire-aid-update
Update Slovenian DESfire AIDs
2024-03-21 14:12:52 +01:00
Anže Jenšterle 0cde19e7c1 Update Slovenian DESfire AIDs 2024-03-21 13:46:48 +01:00
Anže Jenšterle 9b765b488c Fix MIFARE DESfire DeleteApp command
Closes #2336
2024-03-21 13:35:26 +01:00
iceman1001 dd62dc9275 changelog 2024-03-20 23:33:02 +01:00
iceman1001 5a8917c1d0 Revert "Release v4.18341 - Zenith"
This reverts commit 70582c6828.
2024-03-20 23:31:54 +01:00
207 changed files with 17330 additions and 8261 deletions

No files matched your search

+3 -3
View File
@@ -51,11 +51,11 @@ jobs:
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -73,4 +73,4 @@ jobs:
run: make -j$((`nproc` + 1))
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
+15 -12
View File
@@ -21,6 +21,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set Git http.postBuffer to something high
run: git config --global http.postBuffer 524288000
@@ -39,10 +43,7 @@ jobs:
continue-on-error: true
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools ansicolors sslcrypto
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
run: pip install -r tools/requirements.txt
- name: make clean
run: make clean
@@ -61,6 +62,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set Git http.postBuffer to something high
run: git config --global http.postBuffer 524288000
@@ -79,10 +84,7 @@ jobs:
continue-on-error: true
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools ansicolors sslcrypto
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
run: pip install -r tools/requirements.txt
- name: make clean
run: make clean
@@ -102,6 +104,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set Git http.postBuffer to something high
run: git config --global http.postBuffer 524288000
@@ -120,10 +126,7 @@ jobs:
continue-on-error: true
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools ansicolors sslcrypto
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
run: pip install -r tools/requirements.txt
- name: Prepare Build Folders
run: |
+15 -15
View File
@@ -22,6 +22,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Update apt repos
run: sudo apt-get update
@@ -29,11 +33,7 @@ jobs:
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev libgd-dev
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools
python3 -m pip install ansicolors sslcrypto
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
run: pip install -r tools/requirements.txt
- name: make clean
run: make clean
@@ -52,6 +52,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Update apt repos
run: sudo apt-get update
@@ -59,11 +63,7 @@ jobs:
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev libgd-dev
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools
python3 -m pip install ansicolors sslcrypto
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
run: pip install -r tools/requirements.txt
- name: make clean
run: make clean
@@ -83,6 +83,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Update apt repos
run: sudo apt-get update
@@ -90,11 +94,7 @@ jobs:
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev libgd-dev
- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools
python3 -m pip install ansicolors sslcrypto
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
run: pip install -r tools/requirements.txt
- name: Prepare Build Folders
run: |
+1 -1
View File
@@ -98,7 +98,7 @@ jobs:
steps:
- name: WSL setup
uses: Vampire/setup-wsl@v2
uses: Vampire/setup-wsl@v3
with:
distribution: Ubuntu-22.04
update: "true"
+10 -1
View File
@@ -44,9 +44,14 @@ Makefile.platform.*
.Makefile.options.cache
# cmake
CMakeFiles/
deps/
client/CMakeFiles/
client/deps/
client/build/
client/android/build/
client/deps/bzip2/
CMakeCache.txt
*.cmake
# Coverity
cov-int/
@@ -117,3 +122,7 @@ fpga_version_info.c
# docs
!doc/*.json
# local codeql
_codeql*
/codeql
+48 -5
View File
@@ -4,7 +4,50 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
## [unreleased][unreleased]
## [Zenith][2024-03-20]
## [Aurora][2024-05-28]
- Fixed the pm3 regressiontests for Hitag2Crack (@iceman1001)
- Changed `mem spiffs tree` - adapted to bigbuff and show if empty (@iceman1001)
- Changed `lf hitag info` - now tries to identify different key fob emulators (@iceman1001)
- Added `lf hitag reader` - act as a Hitag2 reader (@iceman1001)
- Fixed `lf hitag crack2` - now works. (@iceman1001)
- Fixed wrong use of free() in desfire crypto on arm src, thanks @jlitewski! (@iceman1001)
- Added `lf em 4x70 calc` - calculate `frn`/`grn` for a given `key` + `rnd`
- Fixed `hf 15 dump` memory leaks (@jlitewski)
- Changed `hf search` - topaz is detect before ISO14443a and commented out WIP ICT code path (@iceman1001)
- Fixed `hf search` - where felica reader now doesnt timeout and give wrong response (@iceman1001)
- Fixed overflow in deps/jansson library (@iceman1001)
- Added `lf hitag crack2` - WIP. Trying to add the second attack vector against Hitag2 (@iceman1001)
- Changed `hf 14b reader --plot` - made the anticollision signal trace download optional (@iceman1001)
- Added `lf_hitag_crypto.trace` - trace file of a complete read out of a Hitag2 in crypto mode (@iceman1001)
- Fix `lf cmdread` - uninitialised memory usage (@iceman1001)
- Changed `hf st info` - now tries to check signature if available (@iceman1001)
- Added `hf 14b mobib` - try to read out all data from a MOBIB card (@iceman1001)
- Added `hf 14b calyso` - try to read out all data from a Calypso card (@iceman1001)
- Changed the graphbuffer handling implementation (@HACKhalo2)
- Changed `lf hitag dump --nrar` - now supports attack 1 from "gone in 360 seconds" paper. Thanks @kevsecurity! (@iceman1001)
- Added `lf hitag selftest` - converted from RFIDLers selftest (@iceman1001)
- Added `lf hitag chk` - dictionary attack against card (@iceman1001)
- Added `lf hitag lookup` - verify collected challenges aginst dictionary (@iceman1001)
- Updated windows workflow to use latest setup-wsl script (@iceman1001)
- Added a micro second clock in the client (@iceman1001)
- Fix `hf mfdes read` - buffer overflow when reading large files (@iceman1001)
- Changed `hf 15 csetuid` - now supports gen2 command. Thanks @whywilson! (@iceman1001)
- Changed `hf mfp info` - to identify Ev2 (@iceman1001)
- Updated Graph Markers implementation to include temporary markers and marker labels (@HACKhalo2)
- Updated to SWIG 4.2.1 (@iceman1001)
- Removed `data bin2hex` - replaced by `data num` (@iceman1001)
- Removed `data hex2bin` - replaced by `data num` (@iceman1001)
- Fixed `lf em 410x clone --electra` - now writes properly (@iceman1001)
- Changed waiting for device loops. More stable experience (@iceman1001)
- Changed client now handles CTRL-C and saves history if using READLINE (@iceman1001)
- Changed `hf mf *` - printing of keys if MFC EV1 added extra explaination (@iceman1001)
- Changed `hf mf ginfo` - now supports decoding of user supplied configuration block (@iceman1001)
- Changed `data load` - now shows loaded number as comma printed. (@iceman1001)
- Updated `/tools/hitag2crack/common/OpenCL-Headers/CL` with latest from KhronosGroup github page (@iceman1001)
- Fixed `lf hitag list` - improved HITAG2 protocol annotation (@iceman1001)
- Added AIDs `002000` and `FF30FF` from Metrolinx Presto Card (@RunTheBot)
## [Zenith.4.18340][2024-03-20]
- Changed `hf mf info` - some detections (@iceman1001)
- Changed `hf mf autopwn` - minor fix (@iceman1001)
- Fixed `lf em 4x70 recover` - no more compiler warning (@iceman1001)
@@ -401,9 +444,9 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
- Changed `hf 15 sim` - now supports reader writes (@markus-oehme-pg40)
- Added `hf 15 eload` - specify memory image for ISO15693 simulation (@markus-oehme-pg40)
- Added `hf 15 sim --blocksize` - configure block size for simulation (@markus-oehme-pg40)
- Fixed buffer overflow in mfu ndef decode (@mwalker)
- Changed spiffs write/append to send in 8192 chunks to ensure its eraised (@mwalker)
- Fixed spiffs dump to ensure to fails correctly if no big_buff was allocated (@mwalker)
- Fixed buffer overflow in mfu ndef decode (@mwalker33)
- Changed spiffs write/append to send in 8192 chunks to ensure its eraised (@mwalker33)
- Fixed spiffs dump to ensure to fails correctly if no big_buff was allocated (@mwalker33)
- Change Client Makefile to respect global flags (@blshkv)
- Change Makefile, honors global CC values (@blshkv)
- Fixed bad memory handling in MifareSim device side (@iceman1001)
@@ -609,7 +652,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
- Fixed `hf fido` commands now works correctly (@merlokk)
- Moved / renamed `client/resource/fido2_defparams.json` -> `client/resource/hf_fido2_defparams.json` (@merlokk)
- Added `hf cipurse` commands to work with cipurse transport cards (@merlokk)
- Added `--gap` option to lf em 410x sim for more control over sim data (@mwalker)
- Added `--gap` option to lf em 410x sim for more control over sim data (@mwalker33)
- Changed `hf fido` - refactored load/save json objects (@iceman1001)
- Moved / renamed `fido2.json` -> `client/resource/fido2_defparams.json` (@iceman1001)
- Added openocd shikra support based on @ninjastyle82 patch to deprecated iceman fork (@iceman1001)
+6
View File
@@ -308,8 +308,14 @@ bool LogTrace_ISO15693(const uint8_t *bytes, uint16_t len, uint32_t ts_start, ui
// specific LogTrace function for bitstreams: the partial byte size is stored in first parity byte. E.g. bitstream "1100 00100010" -> partial byte: 4 bits
bool RAMFUNC LogTraceBits(const uint8_t *btBytes, uint16_t bitLen, uint32_t timestamp_start, uint32_t timestamp_end, bool reader2tag) {
if (bitLen == 0) {
return false;
}
uint8_t parity[(nbytes(bitLen) - 1) / 8 + 1];
memset(parity, 0x00, sizeof(parity));
// parity has amount of leftover bits.
parity[0] = bitLen % 8;
return LogTrace(btBytes, nbytes(bitLen), timestamp_start, timestamp_end, parity, reader2tag);
}
+2 -1
View File
@@ -71,7 +71,8 @@ else
endif
ifneq (,$(findstring WITH_HITAG,$(APP_CFLAGS)))
SRC_HITAG = hitag2_crypto.c hitag2.c hitagS.c
SRC_HITAG = hitag2_crypto.c hitag2.c hitagS.c hitag2_crack.c
APP_CFLAGS += -I../common/hitag2
else
SRC_HITAG =
endif
+1 -2
View File
@@ -48,7 +48,6 @@ void RunMod(void) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
const uint32_t high = 0x20; // LF high value is always 0x20 here
uint32_t low = 0;
uint32_t fac = FACILITY_CODE, cardnum = 0;
@@ -80,7 +79,7 @@ void RunMod(void) {
if (BUTTON_HELD(1000) == BUTTON_HOLD) break; // long button press (>=1sec) exit
// calculate the new LF low value including Card number, Facility code and checksum
low = (cardnum << 1) | (fac << 17);
uint32_t low = (cardnum << 1) | (fac << 17);
low |= oddparity32((low >> 1) & 0xFFF);
low |= evenparity32((low >> 13) & 0xFFF) << 25;
+45 -13
View File
@@ -26,7 +26,6 @@
#include "dbprint.h"
#include "pmflash.h"
#include "fpga.h"
#include "fpga.h"
#include "fpgaloader.h"
#include "string.h"
#include "printf.h"
@@ -40,6 +39,7 @@
#include "thinfilm.h"
#include "felica.h"
#include "hitag2.h"
#include "hitag2_crack.h"
#include "hitagS.h"
#include "em4x50.h"
#include "em4x70.h"
@@ -1131,7 +1131,7 @@ static void PacketReceived(PacketCommandNG *packet) {
#ifdef WITH_HITAG
case CMD_LF_HITAG_SNIFF: { // Eavesdrop Hitag tag, args = type
SniffHitag2(true);
// SniffHitag2(packet->oldarg[0]);
//hitag_sniff();
reply_ng(CMD_LF_HITAG_SNIFF, PM3_SUCCESS, NULL, 0);
break;
}
@@ -1139,8 +1139,29 @@ static void PacketReceived(PacketCommandNG *packet) {
SimulateHitag2(true);
break;
}
case CMD_LF_HITAG2_CRACK: {
lf_hitag_data_t *payload = (lf_hitag_data_t *) packet->data.asBytes;
ht2_crack1(payload->NrAr);
break;
}
case CMD_LF_HITAG2_CRACK_2: {
lf_hitag_data_t *payload = (lf_hitag_data_t *) packet->data.asBytes;
ht2_crack2(payload->NrAr);
break;
}
case CMD_LF_HITAG_READER: { // Reader for Hitag tags, args = type and function
ReaderHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, true);
lf_hitag_data_t *payload = (lf_hitag_data_t *) packet->data.asBytes;
switch (payload->cmd) {
case RHT2F_UID_ONLY: {
ht2_read_uid(NULL, true, true, false);
break;
}
default: {
ReaderHitag(payload, true);
break;
}
}
break;
}
case CMD_LF_HITAGS_SIMULATE: { // Simulate Hitag s tag, args = memory content
@@ -1148,25 +1169,28 @@ static void PacketReceived(PacketCommandNG *packet) {
break;
}
case CMD_LF_HITAGS_TEST_TRACES: { // Tests every challenge within the given file
Hitag_check_challenges(packet->data.asBytes, packet->oldarg[0], true);
Hitag_check_challenges(packet->data.asBytes, packet->length, true);
break;
}
case CMD_LF_HITAGS_READ: { //Reader for only Hitag S tags, args = key or challenge
ReadHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, true);
case CMD_LF_HITAGS_READ: { // Reader for only Hitag S tags, args = key or challenge
lf_hitag_data_t *payload = (lf_hitag_data_t *) packet->data.asBytes;
ReadHitagS(payload, true);
break;
}
case CMD_LF_HITAGS_WRITE: { //writer for Hitag tags args=data to write,page and key or challenge
if ((hitag_function)packet->oldarg[0] < 10) {
WritePageHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2], true);
} else {
WriterHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2], true);
}
case CMD_LF_HITAGS_WRITE: {
lf_hitag_data_t *payload = (lf_hitag_data_t *) packet->data.asBytes;
WritePageHitagS(payload, true);
break;
}
case CMD_LF_HITAG2_WRITE: {
lf_hitag_data_t *payload = (lf_hitag_data_t *) packet->data.asBytes;
WriterHitag(payload, true);
break;
}
case CMD_LF_HITAG_ELOAD: {
lf_hitag_t *payload = (lf_hitag_t *) packet->data.asBytes;
uint8_t *mem = BigBuf_get_EM_addr();
memcpy((uint8_t *)mem, payload->data, payload->len);
memcpy(mem, payload->data, payload->len);
break;
}
#endif
@@ -1364,6 +1388,14 @@ static void PacketReceived(PacketCommandNG *packet) {
SetTag15693Uid(payload->uid);
break;
}
case CMD_HF_ISO15693_CSETUID_V2: {
struct p {
uint8_t uid[8];
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
SetTag15693Uid_v2(payload->uid);
break;
}
case CMD_HF_ISO15693_SLIX_DISABLE_EAS: {
struct p {
uint8_t pwd[4];
+3 -2
View File
@@ -102,8 +102,9 @@ void Dbhexdump(int len, const uint8_t *d, bool bAsci) {
}
#endif
}
void print_result(const char *name, const uint8_t *d, size_t
void print_result(const char *name, const uint8_t *d, size_t n) {
n) {
const uint8_t *p = d;
uint16_t tmp = n & 0xFFF0;
@@ -129,7 +130,7 @@ void print_result(const char *name, const uint8_t *d, size_t n) {
}
// Prints message and hexdump
void print_dbg(char *msg, uint8_t *d, uint16_t n) {
void print_dbg(const char *msg, const uint8_t *d, uint16_t n) {
if (g_dbglevel == DBG_DEBUG) {
print_result(msg, d, n);
}
+2 -2
View File
@@ -27,8 +27,8 @@ void DbpStringEx(uint32_t flags, const char *src, size_t srclen);
void Dbprintf(const char *fmt, ...);
void DbprintfEx(uint32_t flags, const char *fmt, ...);
void Dbhexdump(int len, const uint8_t *d, bool bAsci);
void print_result(const char *name, const uint8_t *buf, size_t len);
void print_dbg(char *msg, uint8_t *d, uint16_t n);
void print_result(const char *name, const uint8_t *d, size_t n);
void print_dbg(const char *msg, const uint8_t *d, uint16_t n);
//void PrintToSendBuffer(void);
#endif
+67 -44
View File
@@ -543,30 +543,35 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes,
void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings) {
void *res = data;
void *edata = NULL;
uint8_t first_cmac_byte = 0x00;
desfirekey_t key = DESFIRE(tag)->session_key;
if (!key)
if (!key) {
return data;
}
// Return directly if we just have a status code.
if (1 == *nbytes)
if (1 == *nbytes) {
return res;
}
switch (communication_settings & MDCM_MASK) {
case MDCM_PLAIN:
case MDCM_PLAIN: {
if (AS_LEGACY == DESFIRE(tag)->authentication_scheme)
if (AS_LEGACY == DESFIRE(tag)->authentication_scheme) {
break;
}
}
/* pass through */
case MDCM_MACED:
case MDCM_MACED: {
switch (DESFIRE(tag)->authentication_scheme) {
case AS_LEGACY:
if (communication_settings & MAC_VERIFY) {
case AS_LEGACY: {
if ((communication_settings & MAC_VERIFY) == MAC_VERIFY) {
*nbytes -= key_macing_length(key);
if (*nbytes == 0) {
*nbytes = -1;
res = NULL;
@@ -577,18 +582,17 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
}
size_t edl = enciphered_data_length(tag, *nbytes - 1, communication_settings);
edata = BigBuf_malloc(edl);
uint8_t edata[edl];
memset(edata, 0, sizeof(edata));
memcpy(edata, data, *nbytes - 1);
memset((uint8_t *)edata + *nbytes - 1, 0, edl - *nbytes + 1);
mifare_cypher_blocks_chained(tag, NULL, NULL, edata, edl, MCD_SEND, MCO_ENCYPHER);
if (0 != memcmp((uint8_t *)data + *nbytes - 1, (uint8_t *)edata + edl - 8, 4)) {
if (0 != memcmp((uint8_t *)data + *nbytes - 1, edata + edl - 8, 4)) {
#ifdef WITH_DEBUG
Dbprintf("MACing not verified");
hexdump((uint8_t *)data + *nbytes - 1, key_macing_length(key), "Expect ", 0);
hexdump((uint8_t *)edata + edl - 8, key_macing_length(key), "Actual ", 0);
hexdump(edata + edl - 8, key_macing_length(key), "Actual ", 0);
#endif
DESFIRE(tag)->last_pcd_error = CRYPTO_ERROR;
*nbytes = -1;
@@ -596,10 +600,16 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
}
}
break;
case AS_NEW:
if (!(communication_settings & CMAC_COMMAND))
}
case AS_NEW: {
if ((communication_settings & CMAC_COMMAND) != CMAC_COMMAND) {
break;
if (communication_settings & CMAC_VERIFY) {
}
int n = 0;
if ((communication_settings & CMAC_VERIFY) == CMAC_VERIFY) {
if (*nbytes < 9) {
*nbytes = -1;
res = NULL;
@@ -607,13 +617,16 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
}
first_cmac_byte = ((uint8_t *)data)[*nbytes - 9];
((uint8_t *)data)[*nbytes - 9] = ((uint8_t *)data)[*nbytes - 1];
n = 8;
}
int n = (communication_settings & CMAC_VERIFY) ? 8 : 0;
cmac(key, DESFIRE(tag)->ivect, ((uint8_t *)data), *nbytes - n, DESFIRE(tag)->cmac);
if (communication_settings & CMAC_VERIFY) {
if ((communication_settings & CMAC_VERIFY) == CMAC_VERIFY) {
((uint8_t *)data)[*nbytes - 9] = first_cmac_byte;
if (0 != memcmp(DESFIRE(tag)->cmac, (uint8_t *)data + *nbytes - 9, 8)) {
#ifdef WITH_DEBUG
Dbprintf("CMAC NOT verified :-(");
@@ -628,12 +641,11 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
}
}
break;
}
}
free(edata);
break;
case MDCM_ENCIPHERED:
}
case MDCM_ENCIPHERED: {
(*nbytes)--;
bool verified = false;
int crc_pos = 0x00;
@@ -670,48 +682,50 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
* verified, and accumulating 0's in it should not change it.
*/
switch (DESFIRE(tag)->authentication_scheme) {
case AS_LEGACY:
case AS_LEGACY: {
crc_pos = *nbytes - 8 - 1; // The CRC can be over two blocks
if (crc_pos < 0) {
/* Single block */
crc_pos = 0;
crc_pos = 0; // Single block
}
break;
case AS_NEW:
}
case AS_NEW: {
/* Move status between payload and CRC */
res = DESFIRE(tag)->crypto_buffer;
memcpy(res, data, *nbytes);
crc_pos = (*nbytes) - 16 - 3;
if (crc_pos < 0) {
/* Single block */
crc_pos = 0;
crc_pos = 0; // Single block
}
memcpy((uint8_t *)res + crc_pos + 1, (uint8_t *)res + crc_pos, *nbytes - crc_pos);
((uint8_t *)res)[crc_pos] = 0x00;
crc_pos++;
*nbytes += 1;
break;
}
}
do {
uint16_t crc_16 = 0x00;
uint32_t crc = 0x00;
switch (DESFIRE(tag)->authentication_scheme) {
case AS_LEGACY:
case AS_LEGACY: {
AddCrc14A((uint8_t *)res, end_crc_pos);
end_crc_pos = crc_pos + 2;
//
crc = crc_16;
break;
case AS_NEW:
}
case AS_NEW: {
end_crc_pos = crc_pos + 4;
crc32_ex(res, end_crc_pos, (uint8_t *)&crc);
break;
}
}
if (!crc) {
if (crc == 0) {
verified = true;
for (int n = end_crc_pos; n < *nbytes - 1; n++) {
uint8_t byte = ((uint8_t *)res)[n];
@@ -719,31 +733,40 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
verified = false;
}
}
if (verified) {
*nbytes = crc_pos;
switch (DESFIRE(tag)->authentication_scheme) {
case AS_LEGACY:
case AS_LEGACY: {
((uint8_t *)data)[(*nbytes)++] = 0x00;
break;
case AS_NEW:
}
case AS_NEW: {
/* The status byte was already before the CRC */
break;
}
}
} else {
switch (DESFIRE(tag)->authentication_scheme) {
case AS_LEGACY:
case AS_LEGACY: {
break;
case AS_NEW:
}
case AS_NEW: {
x = ((uint8_t *)res)[crc_pos - 1];
((uint8_t *)res)[crc_pos - 1] = ((uint8_t *)res)[crc_pos];
((uint8_t *)res)[crc_pos] = x;
break;
}
}
crc_pos++;
}
} while (!verified && (end_crc_pos < *nbytes));
if (!verified) {
} while (verified == false && (end_crc_pos < *nbytes));
if (verified == false) {
#ifdef WITH_DEBUG
/* FIXME In some configurations, the file is transmitted PLAIN */
Dbprintf("CRC not verified in decyphered stream");
@@ -752,14 +775,14 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
*nbytes = -1;
res = NULL;
}
break;
default:
}
default: {
Dbprintf("Unknown communication settings");
*nbytes = -1;
res = NULL;
break;
}
}
return res;
}
+5 -1
View File
@@ -1255,7 +1255,11 @@ static int em4x50_sim_read_bit(void) {
int cycles = 0;
int timeout = EM4X50_T_SIMULATION_TIMEOUT_READ;
while (cycles < EM4X50_T_TAG_FULL_PERIOD) {
// wait 16 cycles to make sure there is no field when reading a "0" bit
uint32_t waitval = GetTicks();
while (GetTicks() - waitval < EM4X50_T_TAG_QUARTER_PERIOD * CYCLES2TICKS);
while (cycles < EM4X50_T_TAG_THREE_QUARTER_PERIOD) {
// wait until reader field disappears
while ((timeout--) && !(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK));
+109 -64
View File
@@ -30,6 +30,8 @@ static em4x70_tag_t tag = { 0 };
// EM4170 requires a parity bit on commands, other variants do not.
static bool command_parity = true;
#if 1 // Calculation of ticks for timing functions
// Conversion from Ticks to RF periods
// 1 us = 1.5 ticks
// 1RF Period = 8us = 12 Ticks
@@ -55,11 +57,15 @@ static bool command_parity = true;
#define EM4X70_COMMAND_RETRIES 5 // Attempts to send/read command
#define EM4X70_MAX_RECEIVE_LENGTH 96 // Maximum bits to expect from any command
#endif // Calculation of ticks for timing functions
#if 1 // EM4x70 Command IDs
/**
* These IDs are from the EM4170 datasheet
* These IDs are from the EM4170 datasheet.
* Some versions of the chip require a
* (even) parity bit, others do not
* (even) parity bit, others do not.
* The command is thus stored only in the
* three least significant bits (mask 0x07).
*/
#define EM4X70_COMMAND_ID 0x01
#define EM4X70_COMMAND_UM1 0x02
@@ -67,6 +73,7 @@ static bool command_parity = true;
#define EM4X70_COMMAND_PIN 0x04
#define EM4X70_COMMAND_WRITE 0x05
#define EM4X70_COMMAND_UM2 0x07
#endif // EM4x70 Command IDs
// Constants used to determine high/low state of signal
#define EM4X70_NOISE_THRESHOLD 13 // May depend on noise in environment
@@ -80,9 +87,9 @@ static bool command_parity = true;
#define IS_TIMEOUT(timeout_ticks) (GetTicks() > timeout_ticks)
#define TICKS_ELAPSED(start_ticks) (GetTicks() - start_ticks)
static uint8_t bits2byte(const uint8_t *bits, int length);
static void bits2bytes(const uint8_t *bits, int length, uint8_t *out);
static int em4x70_receive(uint8_t *bits, size_t length);
static uint8_t encoded_bit_array_to_byte(const uint8_t *bits, int count_of_bits);
static void encoded_bit_array_to_bytes(const uint8_t *bits, int count_of_bits, uint8_t *out);
static int em4x70_receive(uint8_t *bits, size_t maximum_bits_to_read);
static bool find_listen_window(bool command);
static void init_tag(void) {
@@ -207,9 +214,10 @@ static uint32_t get_pulse_length(edge_detection_t edge) {
return 0;
}
static bool check_pulse_length(uint32_t pl, uint32_t length) {
// check if pulse length <pl> corresponds to given length <length>
return ((pl >= (length - EM4X70_T_TAG_TOLERANCE)) && (pl <= (length + EM4X70_T_TAG_TOLERANCE)));
static bool check_pulse_length(uint32_t pulse_tick_length, uint32_t target_tick_length) {
// check if pulse tick length corresponds to target length (+/- tolerance)
return ((pulse_tick_length >= (target_tick_length - EM4X70_T_TAG_TOLERANCE)) &&
(pulse_tick_length <= (target_tick_length + EM4X70_T_TAG_TOLERANCE)));
}
static void em4x70_send_bit(bool bit) {
@@ -344,7 +352,11 @@ static int authenticate(const uint8_t *rnd, const uint8_t *frnd, uint8_t *respon
if (g_dbglevel >= DBG_EXTENDED) Dbprintf("Auth failed");
return PM3_ESOFT;
}
bits2bytes(grnd, 24, response);
// although only received 20 bits
// ask for 24 bits converted because
// this utility function requires
// decoding in multiples of 8 bits
encoded_bit_array_to_bytes(grnd, 24, response);
return PM3_SUCCESS;
}
@@ -455,12 +467,12 @@ static int send_pin(const uint32_t pin) {
WaitTicks(EM4X70_T_TAG_WEE);
// <-- Receive header + ID
uint8_t tag_id[EM4X70_MAX_RECEIVE_LENGTH];
int num = em4x70_receive(tag_id, 32);
if (num < 32) {
int count_of_bits_received = em4x70_receive(tag_id, 32);
if (count_of_bits_received < 32) {
Dbprintf("Invalid ID Received");
return PM3_ESOFT;
}
bits2bytes(tag_id, num, &tag.data[4]);
encoded_bit_array_to_bytes(tag_id, count_of_bits_received, &tag.data[4]);
return PM3_SUCCESS;
}
}
@@ -537,36 +549,38 @@ static bool find_listen_window(bool command) {
return false;
}
static void bits2bytes(const uint8_t *bits, int length, uint8_t *out) {
// *bits == array of bytes, each byte storing a single bit.
// *out == array of bytes, storing converted bits --> bytes.
//
// [in, bcount(count_of_bits) ] const uint8_t *bits
// [out, bcount(count_of_bits/8)] uint8_t *out
static void encoded_bit_array_to_bytes(const uint8_t *bits, int count_of_bits, uint8_t *out) {
if (length % 8 != 0) {
Dbprintf("Should have a multiple of 8 bits, was sent %d", length);
if (count_of_bits % 8 != 0) {
Dbprintf("Should have a multiple of 8 bits, was sent %d", count_of_bits);
}
int num_bytes = length / 8; // We should have a multiple of 8 here
int num_bytes = count_of_bits / 8; // We should have a multiple of 8 here
for (int i = 1; i <= num_bytes; i++) {
out[num_bytes - i] = bits2byte(bits, 8);
out[num_bytes - i] = encoded_bit_array_to_byte(bits, 8);
bits += 8;
}
}
static uint8_t bits2byte(const uint8_t *bits, int length) {
static uint8_t encoded_bit_array_to_byte(const uint8_t *bits, int count_of_bits) {
// converts <length> separate bits into a single "byte"
// converts <count_of_bits> separate bits into a single "byte"
uint8_t byte = 0;
for (int i = 0; i < length; i++) {
for (int i = 0; i < count_of_bits; i++) {
byte <<= 1;
byte |= bits[i];
if (i != length - 1)
byte <<= 1;
}
return byte;
}
static bool send_command_and_read(uint8_t command, uint8_t *bytes, size_t length) {
static bool send_command_and_read(uint8_t command, uint8_t *bytes, size_t expected_byte_count) {
int retries = EM4X70_COMMAND_RETRIES;
while (retries) {
@@ -574,19 +588,14 @@ static bool send_command_and_read(uint8_t command, uint8_t *bytes, size_t length
if (find_listen_window(true)) {
uint8_t bits[EM4X70_MAX_RECEIVE_LENGTH] = {0};
size_t out_length_bits = length * 8;
size_t out_length_bits = expected_byte_count * 8;
em4x70_send_nibble(command, command_parity);
int len = em4x70_receive(bits, out_length_bits);
if (len < out_length_bits) {
Dbprintf("Invalid data received length: %d, expected %d", len, out_length_bits);
return false;
}
// TODO: Figure out why getting an extra bit (quite often) here
// e.g., write block and info commands both reach here and output:
// [#] Should have a multiple of 8 bits, was sent 33
// [#] Should have a multiple of 8 bits, was sent 65
// Extra bits are currently just dropped, with no ill effect noticed.
bits2bytes(bits, len, bytes);
encoded_bit_array_to_bytes(bits, len, bytes);
return true;
}
}
@@ -617,7 +626,6 @@ static bool em4x70_read_um1(void) {
}
/**
* em4x70_read_um2
*
@@ -635,7 +643,7 @@ static bool find_em4x70_tag(void) {
return find_listen_window(false);
}
static int em4x70_receive(uint8_t *bits, size_t length) {
static int em4x70_receive(uint8_t *bits, size_t maximum_bits_to_read) {
uint32_t pl;
int bit_pos = 0;
@@ -673,7 +681,7 @@ static int em4x70_receive(uint8_t *bits, size_t length) {
// identify remaining bits based on pulse lengths
// between listen windows only pulse lengths of 1, 1.5 and 2 are possible
while (bit_pos < length) {
while (bit_pos < maximum_bits_to_read) {
pl = get_pulse_length(edge);
@@ -687,13 +695,13 @@ static int em4x70_receive(uint8_t *bits, size_t length) {
// pulse length 1.5 -> 2 bits + flip edge detection
if (edge == FALLING_EDGE) {
bits[bit_pos++] = 0;
if (bit_pos < length) {
if (bit_pos < maximum_bits_to_read) {
bits[bit_pos++] = 0;
}
edge = RISING_EDGE;
} else {
bits[bit_pos++] = 1;
if (bit_pos < length) {
if (bit_pos < maximum_bits_to_read) {
bits[bit_pos++] = 1;
}
edge = FALLING_EDGE;
@@ -704,12 +712,12 @@ static int em4x70_receive(uint8_t *bits, size_t length) {
// pulse length of 2 -> two bits
if (edge == FALLING_EDGE) {
bits[bit_pos++] = 0;
if (bit_pos < length) {
if (bit_pos < maximum_bits_to_read) {
bits[bit_pos++] = 1;
}
} else {
bits[bit_pos++] = 1;
if (bit_pos < length) {
if (bit_pos < maximum_bits_to_read) {
bits[bit_pos++] = 0;
}
}
@@ -725,7 +733,7 @@ static int em4x70_receive(uint8_t *bits, size_t length) {
void em4x70_info(const em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
bool success = false;
// Support tags with and without command parity bits
command_parity = etd->parity;
@@ -736,20 +744,27 @@ void em4x70_info(const em4x70_data_t *etd, bool ledcontrol) {
// Find the Tag
if (get_signalproperties() && find_em4x70_tag()) {
// Read ID, UM1 and UM2
status = em4x70_read_id() && em4x70_read_um1() && em4x70_read_um2();
success = em4x70_read_id() && em4x70_read_um1() && em4x70_read_um2();
}
StopTicks();
lf_finalize(ledcontrol);
int status = success ? PM3_SUCCESS : PM3_ESOFT;
reply_ng(CMD_LF_EM4X70_INFO, status, tag.data, sizeof(tag.data));
}
void em4x70_write(const em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
int status = PM3_ESOFT;
command_parity = etd->parity;
// Disable to prevent sending corrupted data to the tag.
if (command_parity) {
Dbprintf("Use of `--par` option with `lf em 4x70 write` is disabled to prevent corrupting tag data");
reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
return;
}
init_tag();
em4x70_setup_read();
@@ -757,16 +772,15 @@ void em4x70_write(const em4x70_data_t *etd, bool ledcontrol) {
if (get_signalproperties() && find_em4x70_tag()) {
// Write
status = write(etd->word, etd->address) == PM3_SUCCESS;
status = write(etd->word, etd->address);
if (status) {
if (status == PM3_SUCCESS) {
// Read Tag after writing
if (em4x70_read_id()) {
em4x70_read_um1();
em4x70_read_um2();
}
}
}
StopTicks();
@@ -776,7 +790,7 @@ void em4x70_write(const em4x70_data_t *etd, bool ledcontrol) {
void em4x70_unlock(const em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
int status = PM3_ESOFT;
command_parity = etd->parity;
@@ -790,10 +804,10 @@ void em4x70_unlock(const em4x70_data_t *etd, bool ledcontrol) {
if (em4x70_read_id()) {
// Send PIN
status = send_pin(etd->pin) == PM3_SUCCESS;
status = send_pin(etd->pin);
// If the write succeeded, read the rest of the tag
if (status) {
if (status == PM3_SUCCESS) {
// Read Tag
// ID doesn't change
em4x70_read_um1();
@@ -809,11 +823,19 @@ void em4x70_unlock(const em4x70_data_t *etd, bool ledcontrol) {
void em4x70_auth(const em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
int status = PM3_ESOFT;
uint8_t response[3] = {0};
command_parity = etd->parity;
// Disable to prevent sending corrupted data to the tag.
if (command_parity) {
Dbprintf("Use of `--par` option with `lf em 4x70 auth` is disabled to prevent corrupting tag data");
reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
return;
}
init_tag();
em4x70_setup_read();
@@ -821,7 +843,7 @@ void em4x70_auth(const em4x70_data_t *etd, bool ledcontrol) {
if (get_signalproperties() && find_em4x70_tag()) {
// Authenticate and get tag response
status = authenticate(etd->rnd, etd->frnd, response) == PM3_SUCCESS;
status = authenticate(etd->rnd, etd->frnd, response);
}
StopTicks();
@@ -830,11 +852,18 @@ void em4x70_auth(const em4x70_data_t *etd, bool ledcontrol) {
}
void em4x70_brute(const em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
int status = PM3_ESOFT;
uint8_t response[2] = {0};
command_parity = etd->parity;
// Disable to prevent sending corrupted data to the tag.
if (command_parity) {
Dbprintf("Use of `--par` option with `lf em 4x70 brute` is disabled to prevent corrupting tag data");
reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
return;
}
init_tag();
em4x70_setup_read();
@@ -842,7 +871,7 @@ void em4x70_brute(const em4x70_data_t *etd, bool ledcontrol) {
if (get_signalproperties() && find_em4x70_tag()) {
// Bruteforce partial key
status = bruteforce(etd->address, etd->rnd, etd->frnd, etd->start_key, response) == PM3_SUCCESS;
status = bruteforce(etd->address, etd->rnd, etd->frnd, etd->start_key, response);
}
StopTicks();
@@ -852,10 +881,17 @@ void em4x70_brute(const em4x70_data_t *etd, bool ledcontrol) {
void em4x70_write_pin(const em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
int status = PM3_ESOFT;
command_parity = etd->parity;
// Disable to prevent sending corrupted data to the tag.
if (command_parity) {
Dbprintf("Use of `--par` option with `lf em 4x70 setpin` is disabled to prevent corrupting tag data");
reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
return;
}
init_tag();
em4x70_setup_read();
@@ -865,17 +901,19 @@ void em4x70_write_pin(const em4x70_data_t *etd, bool ledcontrol) {
// Read ID (required for send_pin command)
if (em4x70_read_id()) {
// Write new PIN
if ((write((etd->pin) & 0xFFFF, EM4X70_PIN_WORD_UPPER) == PM3_SUCCESS) &&
(write((etd->pin >> 16) & 0xFFFF, EM4X70_PIN_WORD_LOWER) == PM3_SUCCESS)) {
// Write the pin
status = write((etd->pin) & 0xFFFF, EM4X70_PIN_WORD_UPPER);
if (status == PM3_SUCCESS) {
status = write((etd->pin >> 16) & 0xFFFF, EM4X70_PIN_WORD_LOWER);
}
if (status == PM3_SUCCESS) {
// Now Try to authenticate using the new PIN
// Send PIN
status = send_pin(etd->pin) == PM3_SUCCESS;
status = send_pin(etd->pin);
// If the write succeeded, read the rest of the tag
if (status) {
if (status == PM3_SUCCESS) {
// Read Tag
// ID doesn't change
em4x70_read_um1();
@@ -892,10 +930,17 @@ void em4x70_write_pin(const em4x70_data_t *etd, bool ledcontrol) {
void em4x70_write_key(const em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
int status = PM3_ESOFT;
command_parity = etd->parity;
// Disable to prevent sending corrupted data to the tag.
if (command_parity) {
Dbprintf("Use of `--par` option with `lf em 4x70 setkey` is disabled to prevent corrupting tag data");
reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
return;
}
init_tag();
em4x70_setup_read();
@@ -904,15 +949,15 @@ void em4x70_write_key(const em4x70_data_t *etd, bool ledcontrol) {
// Read ID to ensure we can write to card
if (em4x70_read_id()) {
status = 1;
status = PM3_SUCCESS;
// Write each crypto block
for (int i = 0; i < 6; i++) {
uint16_t key_word = (etd->crypt_key[(i * 2) + 1] << 8) + etd->crypt_key[i * 2];
// Write each word, abort if any failure occurs
if (write(key_word, 9 - i) != PM3_SUCCESS) {
status = 0;
status = write(key_word, 9 - i);
if (status != PM3_SUCCESS) {
break;
}
}
+96 -73
View File
@@ -29,7 +29,8 @@
// FeliCa timings
// minimum time between the start bits of consecutive transfers from reader to tag: 6800 carrier (13.56MHz) cycles
#ifndef FELICA_REQUEST_GUARD_TIME
# define FELICA_REQUEST_GUARD_TIME (6800/16 + 1) // 426
//# define FELICA_REQUEST_GUARD_TIME (6800 / 16 + 1) // 426
# define FELICA_REQUEST_GUARD_TIME ((512 + 0 * 256) * 64 / 16 + 1)
#endif
// FRAME DELAY TIME 2672 carrier cycles
#ifndef FELICA_FRAME_DELAY_TIME
@@ -64,6 +65,11 @@ static uint32_t iso18092_get_timeout(void) {
#define FELICA_MAX_FRAME_SIZE 260
#endif
//structure to hold outgoing NFC frame
static uint8_t frameSpace[FELICA_MAX_FRAME_SIZE + 4];
@@ -122,38 +128,45 @@ static void shiftInByte(uint8_t bt) {
}
static void Process18092Byte(uint8_t bt) {
switch (FelicaFrame.state) {
case STATE_UNSYNCD: {
//almost any nonzero byte can be start of SYNC. SYNC should be preceded by zeros, but that is not always the case
// almost any nonzero byte can be start of SYNC. SYNC should be preceded by zeros, but that is not always the case
if (bt > 0) {
FelicaFrame.shiftReg = reflect8(bt);
FelicaFrame.state = STATE_TRYING_SYNC;
}
break;
}
case STATE_TRYING_SYNC: {
if (bt == 0) {
//desync
// desync
FelicaFrame.shiftReg = bt;
FelicaFrame.state = STATE_UNSYNCD;
} else {
for (uint8_t i = 0; i < 8; i++) {
if (FelicaFrame.shiftReg == SYNC_16BIT) {
//SYNC done!
// SYNC done!
FelicaFrame.state = STATE_GET_LENGTH;
FelicaFrame.framebytes[0] = 0xb2;
FelicaFrame.framebytes[1] = 0x4d;
FelicaFrame.byte_offset = i;
//shift in remaining byte, slowly...
// shift in remaining byte, slowly...
for (uint8_t j = i; j < 8; j++) {
FelicaFrame.framebytes[2] = (FelicaFrame.framebytes[2] << 1) + (bt & 1);
bt >>= 1;
}
FelicaFrame.posCnt = 2;
if (i == 0)
if (i == 0) {
break;
}
}
FelicaFrame.shiftReg = (FelicaFrame.shiftReg << 1) + (bt & 1);
bt >>= 1;
@@ -223,9 +236,10 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
// 0x00 = timeslot
// 0x09 0x21 = crc
static uint8_t poll[10] = {0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xFF, 0xFF, 0x00, 0x00, 0x09, 0x21};
int len = 10;
// We try 10 times, or if answer was received.
int len = 25;
do {
// end-of-reception response packet data, wait approx. 501μs
// end-of-transmission command packet data, wait approx. 197μs
@@ -233,45 +247,40 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
TransmitFor18092_AsReader(poll, sizeof(poll), NULL, 1, 0);
// polling card, break if success
if (WaitForFelicaReply(1024) && FelicaFrame.framebytes[3] == FELICA_POLL_ACK)
if (WaitForFelicaReply(1024) && FelicaFrame.framebytes[3] == FELICA_POLL_ACK) {
break;
}
WDT_HIT();
} while (--len);
// timed-out
// 1. timed-out
if (len == 0) {
if (g_dbglevel >= DBG_DEBUG)
Dbprintf("Error: Time out card selection!");
return 1;
}
// wrong answer
// 2. wrong answer
if (FelicaFrame.framebytes[3] != FELICA_POLL_ACK) {
if (g_dbglevel >= DBG_DEBUG)
Dbprintf("Error: Wrong answer selecting card!");
return 2;
}
// VALIDATE CRC residue is 0, hence if crc is a value it failed.
if (!check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2)) {
// 3. wrong crc. residue is 0, hence if crc is a value it failed.
if (check_crc(CRC_FELICA, FelicaFrame.framebytes + 2, FelicaFrame.len - 2) == false) {
if (g_dbglevel >= DBG_DEBUG) {
Dbprintf("Error: CRC check failed!");
Dbprintf("CRC check was done on Frame: ");
Dbhexdump(FelicaFrame.len - 2, FelicaFrame.framebytes + 2, 0);
}
return 3;
}
if (g_dbglevel >= DBG_DEBUG)
Dbprintf("Card selection successful!");
// copy UID
// idm 8
if (card) {
memcpy(card->IDm, FelicaFrame.framebytes + 4, 8);
memcpy(card->PMm, FelicaFrame.framebytes + 4 + 8, 8);
//memcpy(card->servicecode, FelicaFrame.framebytes + 4 + 8 + 8, 2);
// memcpy(card->servicecode, FelicaFrame.framebytes + 4 + 8 + 8, 2);
memcpy(card->code, card->IDm, 2);
memcpy(card->uid, card->IDm + 2, 6);
memcpy(card->iccode, card->PMm, 2);
@@ -281,7 +290,7 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
}
}
// more status bytes?
// 0. OK
return 0;
}
@@ -298,8 +307,10 @@ static uint8_t felica_select_card(felica_card_select_t *card) {
// 8-byte IDm, number of blocks, blocks numbers
// number of blocks limited to 4 for FelicaLite(S)
static void BuildFliteRdblk(const uint8_t *idm, uint8_t blocknum, const uint16_t *blocks) {
if (blocknum > 4 || blocknum == 0)
if (blocknum > 4 || blocknum == 0) {
Dbprintf("Invalid number of blocks, %d != 4", blocknum);
}
uint8_t c = 0, i = 0;
@@ -307,11 +318,11 @@ static void BuildFliteRdblk(const uint8_t *idm, uint8_t blocknum, const uint16_t
frameSpace[c++] = 0xb2;
frameSpace[c++] = 0x4d;
c++; //set length later
c++; // set length later
frameSpace[c++] = FELICA_RDBLK_REQ; //command number
frameSpace[c++] = FELICA_RDBLK_REQ; // command number
//card IDm, from poll
// card IDm, from poll
frameSpace[c++] = idm[0];
frameSpace[c++] = idm[1];
frameSpace[c++] = idm[2];
@@ -321,22 +332,22 @@ static void BuildFliteRdblk(const uint8_t *idm, uint8_t blocknum, const uint16_t
frameSpace[c++] = idm[6];
frameSpace[c++] = idm[7];
//number of services
// number of services
frameSpace[c++] = 0x01;
//service code
// service code
frameSpace[c++] = (SERVICE_FELICA_LITE_READONLY >> 8);
frameSpace[c++] = SERVICE_FELICA_LITE_READONLY & 0xFF;
//number of blocks
// number of blocks
frameSpace[c++] = blocknum;
for (i = 0; i < blocknum; i++) {
//3-byte block
// 3-byte block
if (blocks[i] >= 256) {
frameSpace[c++] = 0x00;
frameSpace[c++] = (blocks[i] >> 8); //block number, little endian....
frameSpace[c++] = (blocks[i] >> 8); // block number, little endian....
frameSpace[c++] = (blocks[i] & 0xff);
} else {
frameSpace[c++] = 0x80;
@@ -344,23 +355,28 @@ static void BuildFliteRdblk(const uint8_t *idm, uint8_t blocknum, const uint16_t
}
}
//set length
// set length
frameSpace[2] = c - 2;
//Add CRC
// Add CRC
AddCrc(frameSpace + 2, c - 2);
}
static void TransmitFor18092_AsReader(const uint8_t *frame, uint16_t len, const uint32_t *NYI_timing_NYI, uint8_t power, uint8_t highspeed) {
if (NYI_timing_NYI != NULL) {
Dbprintf("Error: TransmitFor18092_AsReader does not check or set parameter NYI_timing_NYI");
DbpString("Error: TransmitFor18092_AsReader does not check or set parameter NYI_timing_NYI");
return;
}
uint16_t flags = FPGA_MAJOR_MODE_HF_ISO18092;
if (power)
if (power) {
flags |= FPGA_HF_ISO18092_FLAG_READER;
if (highspeed)
}
if (highspeed) {
flags |= FPGA_HF_ISO18092_FLAG_424K;
}
FpgaWriteConfWord(flags);
@@ -382,10 +398,6 @@ static void TransmitFor18092_AsReader(const uint8_t *frame, uint16_t len, const
}
// sending data with sync bytes
c = 0;
if (g_dbglevel >= DBG_DEBUG) {
Dbprintf("Sending frame:");
Dbhexdump(len, frame, 0);
}
while (c < len) {
// Put byte into tx holding register as soon as it is ready
@@ -419,9 +431,11 @@ static void TransmitFor18092_AsReader(const uint8_t *frame, uint16_t len, const
// stop when button is pressed
// or return TRUE when command is captured
bool WaitForFelicaReply(uint16_t maxbytes) {
if (g_dbglevel >= DBG_DEBUG)
Dbprintf("WaitForFelicaReply Start");
// if (g_dbglevel >= DBG_DEBUG) { Dbprintf("WaitForFelicaReply Start"); }
uint32_t c = 0;
// power, no modulation
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO18092 | FPGA_HF_ISO18092_FLAG_READER | FPGA_HF_ISO18092_FLAG_NOMOD);
FelicaFrameReset();
@@ -433,12 +447,19 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
uint32_t timeout = iso18092_get_timeout();
for (;;) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
b = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
Process18092Byte(b);
if (FelicaFrame.state == STATE_FULL) {
felica_nexttransfertime = MAX(felica_nexttransfertime,
felica_nexttransfertime = MAX(
felica_nexttransfertime,
(GetCountSspClk() & 0xfffffff8) - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / 16 + FELICA_FRAME_DELAY_TIME);
LogTrace(
@@ -449,10 +470,12 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
NULL,
false
);
if (g_dbglevel >= DBG_DEBUG) Dbprintf("All bytes received! STATE_FULL");
return true;
} else if (c++ > timeout && (FelicaFrame.state == STATE_UNSYNCD || FelicaFrame.state == STATE_TRYING_SYNC)) {
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Error: Timeout! STATE_UNSYNCD");
// if (g_dbglevel >= DBG_DEBUG) Dbprintf("Error: Timeout! STATE_UNSYNCD");
return false;
}
}
@@ -462,7 +485,6 @@ bool WaitForFelicaReply(uint16_t maxbytes) {
// Set up FeliCa communication (similar to iso14443a_setup)
// field is setup for "Sending as Reader"
static void iso18092_setup(uint8_t fpga_minor_mode) {
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Start iso18092_setup");
LEDsoff();
#if defined XC3
@@ -476,10 +498,11 @@ static void iso18092_setup(uint8_t fpga_minor_mode) {
// Initialize Demod and Uart structs
// DemodInit(BigBuf_malloc(MAX_FRAME_SIZE));
FelicaFrameinit(BigBuf_malloc(FELICA_MAX_FRAME_SIZE));
FelicaFrameinit(BigBuf_calloc(FELICA_MAX_FRAME_SIZE));
felica_nexttransfertime = 2 * DELAY_ARM2AIR_AS_READER;
iso18092_set_timeout(2120); // 106 * 20ms maximum start-up time of card
felica_nexttransfertime = 2 * DELAY_ARM2AIR_AS_READER; // 418
// iso18092_set_timeout(2120); // 106 * 20ms maximum start-up time of card
iso18092_set_timeout(1060); // 106 * 10ms maximum start-up time of card
init_table(CRC_FELICA);
@@ -518,63 +541,63 @@ static void felica_reset_frame_mode(void) {
// arg1 len of commandbytes
// d.asBytes command bytes to send
void felica_sendraw(const PacketCommandNG *c) {
if (g_dbglevel >= DBG_DEBUG) Dbprintf("FeliCa_sendraw Enter");
felica_command_t param = c->oldarg[0];
size_t len = c->oldarg[1] & 0xffff;
const uint8_t *cmd = c->data.asBytes;
uint32_t arg0;
felica_card_select_t card;
if ((param & FELICA_CONNECT))
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Clear trace");
clear_trace();
if ((param & FELICA_CONNECT) == FELICA_CONNECT) {
clear_trace();
}
set_tracing(true);
iso18092_setup(FPGA_HF_ISO18092_FLAG_READER | FPGA_HF_ISO18092_FLAG_NOMOD);
if ((param & FELICA_CONNECT)) {
if ((param & FELICA_CONNECT) == FELICA_CONNECT) {
// notify client selecting status.
// if failed selecting, turn off antenna and quite.
if (!(param & FELICA_NO_SELECT)) {
if ((param & FELICA_NO_SELECT) != FELICA_NO_SELECT) {
felica_card_select_t card;
arg0 = felica_select_card(&card);
reply_mix(CMD_ACK, arg0, sizeof(card.uid), 0, &card, sizeof(felica_card_select_t));
if (arg0 > 0) {
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Error: Failed selecting card! ");
if (arg0) {
felica_reset_frame_mode();
return;
}
}
} else {
if (g_dbglevel >= DBG_DEBUG) Dbprintf("No card selection");
}
if ((param & FELICA_RAW)) {
if ((param & FELICA_RAW) == FELICA_RAW) {
// 2 sync, 1 len, 2crc == 5
uint8_t *buf = BigBuf_malloc(len + 5);
uint8_t *buf = BigBuf_calloc(len + 5);
// add sync bits
buf[0] = 0xb2;
buf[1] = 0x4d;
buf[2] = len;
// copy command
memcpy(buf + 2, cmd, len);
memcpy(buf + 2, c->data.asBytes, len);
if ((param & FELICA_APPEND_CRC)) {
if ((param & FELICA_APPEND_CRC) == FELICA_APPEND_CRC) {
// Don't append crc on empty bytearray...
if (len > 0) {
AddCrc(buf + 2, len);
}
}
if (g_dbglevel >= DBG_DEBUG) {
Dbprintf("Transmit Frame (no CRC shown):");
Dbhexdump(len, buf, 0);
Dbprintf("Buffer Length: %i", buf[2] + 4);
};
TransmitFor18092_AsReader(buf, buf[2] + 4, NULL, 1, 0);
arg0 = WaitForFelicaReply(1024);
if (g_dbglevel >= DBG_DEBUG) {
Dbprintf("Received Frame Code: %d", arg0);
Dbhexdump(FelicaFrame.len, FelicaFrame.framebytes, 0);
@@ -585,11 +608,11 @@ void felica_sendraw(const PacketCommandNG *c) {
Dbprintf("Reply to Client Error Code: %i", result);
}
}
if ((param & FELICA_NO_DISCONNECT)) {
Dbprintf("Disconnect");
if ((param & FELICA_NO_DISCONNECT) == FELICA_NO_DISCONNECT) {
return;
}
if (g_dbglevel >= DBG_DEBUG)
Dbprintf("FeliCa_sendraw Exit");
felica_reset_frame_mode();
return;
}
@@ -606,7 +629,7 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
int remFrames = (samplesToSkip) ? samplesToSkip : 0;
int trigger_cnt = 0;
uint32_t timeout = iso18092_get_timeout();
bool isReaderFrame = true;
bool isReaderFrame;
uint8_t flip = 0;
uint16_t checker = 0;
@@ -709,7 +732,7 @@ void felica_sim_lite(const uint8_t *uid) {
int retval = PM3_SUCCESS;
int curlen = 0;
uint8_t *curresp = NULL;
const uint8_t *curresp = NULL;
bool listenmode = true;
// uint32_t frtm = GetCountSspClk();
@@ -859,7 +882,7 @@ void felica_dump_lite_s(void) {
dest[cnt++] = liteblks[blknum];
uint8_t *fb = FelicaFrame.framebytes;
const uint8_t *fb = FelicaFrame.framebytes;
dest[cnt++] = fb[12];
dest[cnt++] = fb[13];
+784 -311
View File
File diff suppressed because it is too large. Load diff
+7 -3
View File
@@ -23,8 +23,12 @@
#include "hitag.h"
void SniffHitag2(bool ledcontrol);
void hitag_sniff(void);
void SimulateHitag2(bool ledcontrol);
void ReaderHitag(hitag_function htf, const hitag_data *htd, bool ledcontrol);
void WriterHitag(hitag_function htf, const hitag_data *htd, int page, bool ledcontrol);
void EloadHitag(const uint8_t *data, uint16_t len);
void ReaderHitag(const lf_hitag_data_t *payload, bool ledcontrol);
void WriterHitag(const lf_hitag_data_t *payload, bool ledcontrol);
bool ht2_packbits(uint8_t *nrz_samples, size_t nrzs, uint8_t *rx, size_t *rxlen);
int ht2_read_uid(uint8_t *uid, bool ledcontrol, bool send_answer, bool keep_field_up);
int ht2_tx_rx(uint8_t *tx, size_t txlen, uint8_t *rx, size_t *rxlen, bool ledcontrol, bool keep_field_up);
#endif
+441
View File
@@ -0,0 +1,441 @@
//-----------------------------------------------------------------------------
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// This coode has been converted from RFIDler source code to work with Proxmark3.
// https://github.com/AdamLaurie/RFIDler/blob/master/firmware/Pic32/RFIDler.X/src/hitag2crack.c
#include "hitag2_crack.h"
#include "hitag2/hitag2_crypto.h"
#include "hitag2.h"
#include "proxmark3_arm.h"
#include "commonutil.h"
#include "dbprint.h"
#include "util.h"
#include "string.h"
#include "BigBuf.h"
#include "cmd.h"
#include "lfadc.h"
// #define READP0CMD "1100000111"
const static uint8_t read_p0_cmd[] = {1, 1, 0, 0, 0, 0, 0, 1, 1, 1};
// hitag2crack_xor XORs the source with the pad to produce the target.
// source, target and pad are binarrays of length len.
static void hitag2crack_xor(uint8_t *target, const uint8_t *source, const uint8_t *pad, size_t len) {
for (size_t i = 0; i < len; i++) {
target[i] = source[i] ^ pad[i];
}
}
// hitag2crack_send_e_cmd replays the auth and sends the given encrypted
// command.
// responsestr is the hexstring of the response to the command;
// nrar is the 64 bit binarray of the nR aR pair;
// cmd is the binarray of the encrypted command to send;
// len is the length of the encrypted command.
static bool hitag2crack_send_e_cmd(uint8_t *resp, uint8_t *nrar, uint8_t *cmd, size_t len) {
memset(resp, 0, 4);
// Get UID
if (ht2_read_uid(NULL, true, false, true) != PM3_SUCCESS) {
return false;
}
// send nrar and receive (useless) encrypted page 3 value
size_t n = 0;
if (ht2_tx_rx(nrar, 64, NULL, &n, true, true) != PM3_SUCCESS) {
return false;
}
// send encrypted command
n = 0;
ht2_tx_rx(cmd, len, resp, &n, true, false);
if (n == 32) {
return true;
}
return false;
}
// hitag2crack_read_page uses the supplied key stream and nrar pair to read the
// given page, returning the response as a hexstring.
// responsestr is the returned hexstring;
// pagenum is the page number to read;
// nrar is the 64 bit binarray of the nR aR pair;
// keybits is the binarray of the key stream.
static bool hitag2crack_read_page(uint8_t *resp, uint8_t pagenum, uint8_t *nrar, uint8_t *keybits) {
if (pagenum > 7) {
return false;
}
// create cmd
uint8_t cmd[10];
memcpy(cmd, read_p0_cmd, sizeof(read_p0_cmd));
if (pagenum & 0x1) {
cmd[9] = !cmd[9];
cmd[4] = !cmd[4];
}
if (pagenum & 0x2) {
cmd[8] = !cmd[8];
cmd[3] = !cmd[3];
}
if (pagenum & 0x4) {
cmd[7] = !cmd[7];
cmd[2] = !cmd[2];
}
// encrypt command
uint8_t e_cmd[10] = {0};
hitag2crack_xor(e_cmd, cmd, keybits, 10);
// send encrypted command
uint8_t e_resp[4];
if (hitag2crack_send_e_cmd(e_resp, nrar, e_cmd, 10)) {
uint8_t e_response[32] = {0};
uint8_t response[32] = {0};
// convert to binarray
hex2binarray_n((char *)e_response, (char *)e_resp, 4);
// decrypt response
hitag2crack_xor(response, e_response, keybits + 10, 32);
// convert to hexstring
binarray2hex(response, 32, resp);
return true;
}
return false;
}
// hitag2crack_test_e_p0cmd XORs the message (command + response) with the
// encrypted version to retrieve the key stream. It then uses this key stream
// to encrypt an extended version of the READP0CMD and tests if the response
// is valid.
// keybits is the returned binarray of the key stream;
// nrar is the 64 bit binarray of nR aR pair;
// e_cmd is the binarray of the encrypted command;
// uid is the binarray of the card UID;
// e_uid is the binarray of the encrypted version of the UID.
static bool hitag2crack_test_e_p0cmd(uint8_t *keybits, uint8_t *nrar, uint8_t *e_cmd, uint8_t *uid, uint8_t *e_uid) {
uint8_t cipherbits[42] = {0};
memcpy(cipherbits, e_cmd, 10); // copy encrypted cmd to cipherbits
memcpy(cipherbits + 10, e_uid, 32); // copy encrypted uid to cipherbits
uint8_t plainbits[42] = {0};
memcpy(plainbits, read_p0_cmd, sizeof(read_p0_cmd)); // copy cmd to plainbits
memcpy(plainbits + 10, uid, 32); // copy uid to plainbits
// xor the plainbits with the cipherbits to get keybits
hitag2crack_xor(keybits, plainbits, cipherbits, 42);
// create extended cmd -> 4 * READP0CMD = 40 bits
// xor extended cmd with keybits
uint8_t e_ext_cmd[40] = {0};
hitag2crack_xor(e_ext_cmd, read_p0_cmd, keybits, 10);
hitag2crack_xor(e_ext_cmd + 10, read_p0_cmd, keybits + 10, 10);
hitag2crack_xor(e_ext_cmd + 20, read_p0_cmd, keybits + 20, 10);
hitag2crack_xor(e_ext_cmd + 30, read_p0_cmd, keybits + 30, 10);
// send extended encrypted cmd
uint8_t resp[4] = {0};
if (hitag2crack_send_e_cmd(resp, nrar, e_ext_cmd, 40)) {
return true;
}
return false;
}
// hitag2crack_find_e_page0_cmd tries all bit-flipped combinations of the
// valid encrypted command and tests the results by attempting an extended
// command version of the command to see if that produces a valid response.
// keybits is the returned binarray of the recovered key stream;
// e_page0cmd is the returned binarray of the encrypted 'read page 0' command;
// e_firstcmd is the binarray of the first valid encrypted command found;
// nrar is the binarray of the 64 bit nR aR pair;
// uid is the binarray of the 32 bit UID.
static bool hitag2crack_find_e_page0_cmd(uint8_t *keybits, uint8_t *e_firstcmd, uint8_t *nrar, uint8_t *uid) {
// we're going to brute the missing 4 bits of the valid encrypted command
for (uint8_t a = 0; a < 2; a++) {
for (uint8_t b = 0; b < 2; b++) {
for (uint8_t c = 0; c < 2; c++) {
for (uint8_t d = 0; d < 2; d++) {
// create our guess by bit flipping the pattern of bits
// representing the inverted bit and the 3 page bits
// in both the non-inverted and inverted parts of the
// encrypted command.
uint8_t guess[10];
memcpy(guess, e_firstcmd, 10);
if (a) {
guess[5] = !guess[5];
guess[0] = !guess[0];
}
if (b) {
guess[7] = !guess[7];
guess[2] = !guess[2];
}
if (c) {
guess[8] = !guess[8];
guess[3] = !guess[3];
}
if (d) {
guess[9] = !guess[9];
guess[4] = !guess[4];
}
// try the guess
uint8_t resp[4] = {0};
if (hitag2crack_send_e_cmd(resp, nrar, guess, 10)) {
// convert response to binarray
// response should been encrypted UID
uint8_t e_uid[32] = {0};
hex2binarray_n((char *)e_uid, (char *)resp, 4);
// test if the guess was 'read page 0' command
if (hitag2crack_test_e_p0cmd(keybits, nrar, guess, uid, e_uid)) {
return true;
}
}
}
}
}
}
return false;
}
// hitag2crack_find_valid_e_cmd repeatedly replays the auth protocol each
// with a different sequential encrypted command value in order to find one
// that returns a valid response.
// e_cmd is the returned binarray of the valid encrypted command;
// nrar is the binarray of the 64 bit nR aR pair.
static bool hitag2crack_find_valid_e_cmd(uint8_t *e_cmd, uint8_t *nrar) {
// we're going to hold bits 5, 7, 8 and 9 and brute force the rest
// e.g. x x x x x 0 x 0 0 0
for (uint8_t a = 0; a < 2; a++) {
for (uint8_t b = 0; b < 2; b++) {
for (uint8_t c = 0; c < 2; c++) {
for (uint8_t d = 0; d < 2; d++) {
for (uint8_t e = 0; e < 2; e++) {
for (uint8_t g = 0; g < 2; g++) {
// build binarray
uint8_t guess[10] = { a, b, c, d, e, 0, g, 0, 0, 0 };
// send guess
uint8_t resp[4] = {0};
if (hitag2crack_send_e_cmd(resp, nrar, guess, sizeof(guess))) {
// return the guess as the encrypted command
memcpy(e_cmd, guess, 10);
return true;
}
}
}
}
}
}
}
return false;
}
typedef struct {
uint8_t keybits[2080];
uint8_t uid[32];
uint8_t nrar[64];
uint8_t e_ext_cmd[2080];
} PACKED lf_hitag_crack2_t;
// hitag2_crack implements the first crack algorithm described in the paper,
// Gone In 360 Seconds by Verdult, Garcia and Balasch.
// response is a multi-line text response containing the 8 pages of the cracked tag
// nrarhex is a string containing hex representations of the 32 bit nR and aR values
void ht2_crack1(uint8_t *nrar_hex) {
clear_trace();
lf_hitag_crack_response_t packet;
memset((uint8_t *)&packet, 0x00, sizeof(lf_hitag_crack_response_t));
int res = PM3_SUCCESS;
// get uid as hexstring
uint8_t uid_hex[4];
if (ht2_read_uid(uid_hex, false, false, false) != PM3_SUCCESS) {
packet.status = -1;
res = PM3_EFAILED;
goto out;
}
// convert to binarray
uint8_t nrar[64] = {0};
hex2binarray_n((char *)nrar, (char *)nrar_hex, 8);
// find a valid encrypted command
uint8_t e_firstcmd[10];
if (hitag2crack_find_valid_e_cmd(e_firstcmd, nrar) == false) {
packet.status = -2;
res = PM3_EFAILED;
goto out;
}
// now we got a first encrypted command inside e_firstcmd
uint8_t uid[32];
hex2binarray_n((char *)uid, (char *)uid_hex, 4);
// find the 'read page 0' command and recover key stream
uint8_t keybits[42];
if (hitag2crack_find_e_page0_cmd(keybits, e_firstcmd, nrar, uid) == false) {
packet.status = -3;
res = PM3_EFAILED;
goto out;
}
// read all pages using key stream
for (uint8_t i = 1; i < 8; i++) {
hitag2crack_read_page(packet.data + (i * 4), i, nrar, keybits);
}
// copy UID since we already have it...
memcpy(packet.data, uid_hex, 4);
packet.status = 1;
out:
reply_ng(CMD_LF_HITAG2_CRACK, res, (uint8_t *)&packet, sizeof(lf_hitag_crack_response_t));
}
// hitag2_keystream uses the first crack algorithm described in the paper,
// Gone In 360 Seconds by Verdult, Garcia and Balasch, to retrieve 2048 bits of keystream.
// response is a multi-line text response containing the hex of the keystream;
// nrar_hex is the 32 bit nR and aR in hex
void ht2_crack2(uint8_t *nrar_hex) {
BigBuf_free();
uint8_t *e_response = BigBuf_calloc(32);
lf_hitag_crack2_t *c2 = (lf_hitag_crack2_t *)BigBuf_calloc(sizeof(lf_hitag_crack2_t));
g_logging = false;
LEDsoff();
set_tracing(false);
clear_trace();
// find the 'read page 0' command and recover key stream
// get uid as hexstring
uint8_t uid_hex[4] = {0};
if (ht2_read_uid(uid_hex, false, false, false) != PM3_SUCCESS) {
BigBuf_free();
reply_ng(CMD_LF_HITAG2_CRACK_2, PM3_EFAILED, NULL, 0);
return;
}
hex2binarray_n((char *)c2->uid, (char *)uid_hex, 4);
hex2binarray_n((char *)c2->nrar, (char *)nrar_hex, 8);
DbpString("looking for encrypted command");
// find a valid encrypted command
uint8_t e_firstcmd[10] = {0};
if (hitag2crack_find_valid_e_cmd(e_firstcmd, c2->nrar) == false) {
BigBuf_free();
reply_ng(CMD_LF_HITAG2_CRACK_2, PM3_EFAILED, NULL, 0);
return;
}
DbpString("looking for encrypted page 0");
// find encrypted page0 commnd
if (hitag2crack_find_e_page0_cmd(c2->keybits, e_firstcmd, c2->nrar, c2->uid) == false) {
BigBuf_free();
reply_ng(CMD_LF_HITAG2_CRACK_2, PM3_EFAILED, NULL, 0);
return;
}
// We got 42 bits of keystream in c2->keybits.
// using the 40 bits of keystream in keybits, sending commands with ever
// increasing lengths to acquire 2048 bits of key stream.
int kslen = 40;
int res = PM3_SUCCESS;
while (kslen < 2048 && BUTTON_PRESS() == false) {
hitag2crack_xor(c2->e_ext_cmd, read_p0_cmd, c2->keybits, 10);
hitag2crack_xor(c2->e_ext_cmd + 10, read_p0_cmd, c2->keybits + 10, 10);
hitag2crack_xor(c2->e_ext_cmd + 20, read_p0_cmd, c2->keybits + 20, 10);
hitag2crack_xor(c2->e_ext_cmd + 30, read_p0_cmd, c2->keybits + 30, 10);
Dbprintf("Recovered " _YELLOW_("%4i") " bits of keystream", kslen);
// Get UID
if (ht2_read_uid(NULL, true, false, true) != PM3_SUCCESS) {
res = PM3_EFAILED;
break;
}
// send nrar and receive (useless) encrypted page 3 value
size_t n = 0;
if (ht2_tx_rx(c2->nrar, 64, NULL, &n, true, true) != PM3_SUCCESS) {
res = PM3_EFAILED;
break;
}
uint8_t resp[4] = {0};
res = ht2_tx_rx(c2->e_ext_cmd, kslen, resp, &n, true, false);
if (res != PM3_SUCCESS) {
Dbprintf("tx/rx failed, got %zu (res... %i)", n, res);
break;
}
// convert response to binarray
hex2binarray_n((char *)e_response, (char *)resp, 4);
// recover keystream from encrypted response
hitag2crack_xor(c2->keybits + kslen, e_response, c2->uid, 32);
// extented with 30 bits or 3 * 10 read_p0_cmds
hitag2crack_xor(c2->e_ext_cmd + kslen, read_p0_cmd, c2->keybits + kslen, 10);
kslen += 10;
hitag2crack_xor(c2->e_ext_cmd + kslen, read_p0_cmd, c2->keybits + kslen, 10);
kslen += 10;
hitag2crack_xor(c2->e_ext_cmd + kslen, read_p0_cmd, c2->keybits + kslen, 10);
kslen += 10;
}
Dbprintf("Recovered " _YELLOW_("%4i") " bits of keystream", kslen);
lf_hitag_crack_response_t *packet = (lf_hitag_crack_response_t *)BigBuf_calloc(sizeof(lf_hitag_crack_response_t));
packet->status = 1;
binarray2hex(c2->keybits, kslen, packet->data);
reply_ng(CMD_LF_HITAG2_CRACK_2, res, (uint8_t *)packet, sizeof(lf_hitag_crack_response_t));
BigBuf_free();
return;
}
+27
View File
@@ -0,0 +1,27 @@
//-----------------------------------------------------------------------------
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// Hitag2 crack implementeation
//-----------------------------------------------------------------------------
#ifndef _HITAG2_CRACK__H_
#define _HITAG2_CRACK__H_
#include <stdbool.h>
#include "common.h"
void ht2_crack1(uint8_t *nrar_hex);
void ht2_crack2(uint8_t *nrar_hex);
#endif
-125
View File
@@ -1,125 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// Hitag2 Crypto
//-----------------------------------------------------------------------------
#include "hitag2_crypto.h"
#include "util.h"
#include "string.h"
/* Following is a modified version of cryptolib.com/ciphers/hitag2/ */
// Software optimized 48-bit Philips/NXP Mifare Hitag2 PCF7936/46/47/52 stream cipher algorithm by I.C. Wiener 2006-2007.
// For educational purposes only.
// No warranties or guarantees of any kind.
// This code is released into the public domain by its author.
// Single bit Hitag2 functions:
#ifndef i4
#define i4(x,a,b,c,d) ((uint32_t)((((x)>>(a))&1)+(((x)>>(b))&1)*2+(((x)>>(c))&1)*4+(((x)>>(d))&1)*8))
#endif
static const uint32_t ht2_f4a = 0x2C79; // 0010 1100 0111 1001
static const uint32_t ht2_f4b = 0x6671; // 0110 0110 0111 0001
static const uint32_t ht2_f5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0111 1011
uint32_t _f20(const uint64_t x) {
uint32_t i5;
i5 = ((ht2_f4a >> i4(x, 1, 2, 4, 5)) & 1) * 1
+ ((ht2_f4b >> i4(x, 7, 11, 13, 14)) & 1) * 2
+ ((ht2_f4b >> i4(x, 16, 20, 22, 25)) & 1) * 4
+ ((ht2_f4b >> i4(x, 27, 28, 30, 32)) & 1) * 8
+ ((ht2_f4a >> i4(x, 33, 42, 43, 45)) & 1) * 16;
return (ht2_f5c >> i5) & 1;
}
uint64_t _hitag2_init(const uint64_t key, const uint32_t serial, const uint32_t IV) {
uint32_t i;
uint64_t x = ((key & 0xFFFF) << 32) + serial;
for (i = 0; i < 32; i++) {
x >>= 1;
x += (uint64_t)(_f20(x) ^ (((IV >> i) ^ (key >> (i + 16))) & 1)) << 47;
}
return x;
}
uint64_t _hitag2_round(uint64_t *state) {
uint64_t x = *state;
x = (x >> 1) +
((((x >> 0) ^ (x >> 2) ^ (x >> 3) ^ (x >> 6)
^ (x >> 7) ^ (x >> 8) ^ (x >> 16) ^ (x >> 22)
^ (x >> 23) ^ (x >> 26) ^ (x >> 30) ^ (x >> 41)
^ (x >> 42) ^ (x >> 43) ^ (x >> 46) ^ (x >> 47)) & 1) << 47);
*state = x;
return _f20(x);
}
// "MIKRON" = O N M I K R
// Key = 4F 4E 4D 49 4B 52 - Secret 48-bit key
// Serial = 49 43 57 69 - Serial number of the tag, transmitted in clear
// Random = 65 6E 45 72 - Random IV, transmitted in clear
//~28~DC~80~31 = D7 23 7F CE - Authenticator value = inverted first 4 bytes of the keystream
// The code below must print out "D7 23 7F CE 8C D0 37 A9 57 49 C1 E6 48 00 8A B6".
// The inverse of the first 4 bytes is sent to the tag to authenticate.
// The rest is encrypted by XORing it with the subsequent keystream.
uint32_t _hitag2_byte(uint64_t *x) {
uint32_t i, c;
for (i = 0, c = 0; i < 8; i++) {
c += (uint32_t) _hitag2_round(x) << (i ^ 7);
}
return c;
}
void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv) {
uint64_t key = ((uint64_t)tag->sectors[2][2]) |
((uint64_t)tag->sectors[2][3] << 8) |
((uint64_t)tag->sectors[1][0] << 16) |
((uint64_t)tag->sectors[1][1] << 24) |
((uint64_t)tag->sectors[1][2] << 32) |
((uint64_t)tag->sectors[1][3] << 40);
uint32_t uid = ((uint32_t)tag->sectors[0][0]) |
((uint32_t)tag->sectors[0][1] << 8) |
((uint32_t)tag->sectors[0][2] << 16) |
((uint32_t)tag->sectors[0][3] << 24);
uint32_t iv_ = (((uint32_t)(iv[0]))) |
(((uint32_t)(iv[1])) << 8) |
(((uint32_t)(iv[2])) << 16) |
(((uint32_t)(iv[3])) << 24);
tag->cs = _hitag2_init(REV64(key), REV32(uid), REV32(iv_));
}
int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator_is) {
uint8_t authenticator_should[4];
authenticator_should[0] = ~_hitag2_byte(cs);
authenticator_should[1] = ~_hitag2_byte(cs);
authenticator_should[2] = ~_hitag2_byte(cs);
authenticator_should[3] = ~_hitag2_byte(cs);
return (memcmp(authenticator_should, authenticator_is, 4) == 0);
}
int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, uint16_t bytes, uint16_t bits) {
int i;
for (i = 0; i < bytes; i++) data[i] ^= _hitag2_byte(cs);
for (i = 0; i < bits; i++) data[bytes] ^= _hitag2_round(cs) << (7 - i);
return 0;
}
-840
View File
@@ -1,840 +0,0 @@
//-----------------------------------------------------------------------------
// Borrowed initially from https://github.com/factoritbv/hitag2hell
// and https://github.com/AdamLaurie/RFIDler/blob/master/firmware/Pic32/RFIDler.X/src/hitag2crack.c
// Copyright (C) Kevin Sheldrake <kev@headhacking.com>, Aug 2018
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// hitag2 attack functions
//-----------------------------------------------------------------------------
#include "hitag2_crypto.h"
#include "hitag2crack.h"
#define READP0CMD "1100000111"
#define ERROR_RESPONSE "F402889C"
static const uint8_t Hitag2Sync[5];
static bool CryptoActive;
static Hitag_State Hitag_Crypto_State;
// hitag2_crack implements the first crack algorithm described in the paper,
// Gone In 360 Seconds by Verdult, Garcia and Balasch.
// response is a multi-line text response containing the 8 pages of the
// cracked tag;
// nrarhex is a string containing hex representations of the 32 bit nR and aR
// values (separated by a space) snooped using SNIFF-PWM.
bool hitag2_crack(uint8_t *response, uint8_t *nrarhex) {
uint8_t uidhex[9];
uint8_t uid[32];
uint8_t nrar[64];
uint8_t e_firstcmd[10];
// uint8_t e_page0cmd[10];
uint8_t keybits[42];
uint8_t pagehex[9];
uint8_t temp[20];
int i;
uint8_t *spaceptr = NULL;
// get uid as hexstring
if (!hitag2_get_uid(uidhex)) {
UserMessage("Cannot get UID\r\n");
return false;
}
// convert uid hexstring to binarray
hextobinarray(uid, uidhex);
// convert nR and aR hexstrings to binarray
spaceptr = strchr(nrarhex, ' ');
if (!spaceptr) {
UserMessage("Please supply a valid nR aR pair\r\n");
return false;
}
*spaceptr = 0x00;
if (hextobinarray(nrar, nrarhex) != 32) {
UserMessage("nR is not 32 bits long\r\n");
return false;
}
if (hextobinarray(nrar + 32, spaceptr + 1) != 32) {
UserMessage("aR is not 32 bits long\r\n");
return false;
}
// find a valid encrypted command
if (!hitag2crack_find_valid_e_cmd(e_firstcmd, nrar)) {
UserMessage("Cannot find a valid encrypted command\r\n");
return false;
}
// find the 'read page 0' command and recover key stream
if (!hitag2crack_find_e_page0_cmd(keybits, e_firstcmd, nrar, uid)) {
UserMessage("Cannot find encrypted 'read page0' command\r\n");
return false;
}
// empty the response string
response[0] = 0x00;
// read all pages using key stream
for (i = 0; i < 8; i++) {
if (hitag2crack_read_page(pagehex, i, nrar, keybits)) {
sprintf(temp, "%1d: %s\r\n", i, pagehex);
} else {
sprintf(temp, "%1d:\r\n", i);
}
// add page string to response
strcat(response, temp);
}
return true;
}
// hitag2crack_find_valid_e_cmd repeatedly replays the auth protocol each
// with a different sequential encrypted command value in order to find one
// that returns a valid response.
// e_cmd is the returned binarray of the valid encrypted command;
// nrar is the binarray of the 64 bit nR aR pair.
bool hitag2crack_find_valid_e_cmd(uint8_t e_cmd[], uint8_t nrar[]) {
uint8_t guess[10];
uint8_t responsestr[9];
// UserMessage("Finding valid encrypted command:");
// we're going to hold bits 5, 7, 8 and 9 and brute force the rest
// e.g. x x x x x 0 x 0 0 0
for (uint8_t a = 0; a < 2; a++) {
for (uint8_t b = 0; b < 2; b++) {
for (uint8_t c = 0; c < 2; c++) {
for (uint8_t d = 0; d < 2; d++) {
for (uint8_t e = 0; e < 2; e++) {
for (uint8_t g = 0; g < 2; g++) {
// build binarray
guess[0] = a;
guess[1] = b;
guess[2] = c;
guess[3] = d;
guess[4] = e;
guess[5] = 0;
guess[6] = g;
guess[7] = 0;
guess[8] = 0;
guess[9] = 0;
// send guess
if (hitag2crack_send_e_cmd(responsestr, nrar, guess, 10)) {
// check if it was valid
if (strcmp(responsestr, ERROR_RESPONSE) != 0) {
// return the guess as the encrypted command
memcpy(e_cmd, guess, 10);
return true;
}
} else {
#ifdef RFIDLER_DEBUG
UserMessage("hitag2crack_find_valid_e_cmd:\r\n hitag2crack_send_e_cmd failed\r\n");
#endif
}
UserMessage(".");
}
}
}
}
}
}
// UserMessage("hitag2crack_find_valid_e_cmd:\r\n no valid encrypted command found\r\n");
return false;
}
// hitag2crack_find_e_page0_cmd tries all bit-flipped combinations of the
// valid encrypted command and tests the results by attempting an extended
// command version of the command to see if that produces a valid response.
// keybits is the returned binarray of the recovered key stream;
// e_page0cmd is the returned binarray of the encrypted 'read page 0' command;
// e_firstcmd is the binarray of the first valid encrypted command found;
// nrar is the binarray of the 64 bit nR aR pair;
// uid is the binarray of the 32 bit UID.
bool hitag2crack_find_e_page0_cmd(uint8_t keybits[], uint8_t e_firstcmd[], uint8_t nrar[], uint8_t uid[]) {
uint8_t a, b, c, d;
uint8_t guess[10];
uint8_t responsestr[9];
uint8_t e_uid[32];
UserMessage("Finding 'read page 0' command:");
// we're going to brute the missing 4 bits of the valid encrypted command
for (a = 0; a < 2; a++) {
for (b = 0; b < 2; b++) {
for (c = 0; c < 2; c++) {
for (d = 0; d < 2; d++) {
// create our guess by bit flipping the pattern of bits
// representing the inverted bit and the 3 page bits
// in both the non-inverted and inverted parts of the
// encrypted command.
memcpy(guess, e_firstcmd, 10);
if (a) {
guess[5] = !guess[5];
guess[0] = !guess[0];
}
if (b) {
guess[7] = !guess[7];
guess[2] = !guess[2];
}
if (c) {
guess[8] = !guess[8];
guess[3] = !guess[3];
}
if (d) {
guess[9] = !guess[9];
guess[4] = !guess[4];
}
// try the guess
if (hitag2crack_send_e_cmd(responsestr, nrar, guess, 10)) {
// check if it was valid
if (strcmp(responsestr, ERROR_RESPONSE) != 0) {
// convert response to binarray
hextobinarray(e_uid, responsestr);
// test if the guess was 'read page 0' command
if (hitag2crack_test_e_p0cmd(keybits, nrar, guess, uid, e_uid)) {
return true;
}
} else {
#ifdef RFIDLER_DEBUG
UserMessage("hitag2crack_find_e_page0_cmd:\r\n hitag2crack_send_e_cmd returned ERROR_RESPONSE\r\n");
#endif
}
} else {
#ifdef RFIDLER_DEBUG
UserMessage("hitag2crack_find_e_page0_cmd:\r\n hitag2crack_send_e_cmd failed\r\n");
#endif
}
UserMessage(".");
}
}
}
}
UserMessage("hitag2crack_find_e_page0_cmd:\r\n could not find encrypted 'read page 0' command\r\n");
return false;
}
// hitag2crack_test_e_p0cmd XORs the message (command + response) with the
// encrypted version to retrieve the key stream. It then uses this key stream
// to encrypt an extended version of the READP0CMD and tests if the response
// is valid.
// keybits is the returned binarray of the key stream;
// nrar is the 64 bit binarray of nR aR pair;
// e_cmd is the binarray of the encrypted command;
// uid is the binarray of the card UID;
// e_uid is the binarray of the encrypted version of the UID.
bool hitag2crack_test_e_p0cmd(uint8_t *keybits, uint8_t *nrar, uint8_t *e_cmd, uint8_t *uid, uint8_t *e_uid) {
uint8_t cipherbits[42];
uint8_t plainbits[42];
uint8_t ext_cmd[40];
uint8_t e_ext_cmd[40];
uint8_t responsestr[9];
int i;
// copy encrypted cmd to cipherbits
memcpy(cipherbits, e_cmd, 10);
// copy encrypted uid to cipherbits
memcpy(cipherbits + 10, e_uid, 32);
// copy cmd to plainbits
binstringtobinarray(plainbits, READP0CMD);
// copy uid to plainbits
memcpy(plainbits + 10, uid, 32);
// xor the plainbits with the cipherbits to get keybits
hitag2crack_xor(keybits, plainbits, cipherbits, 42);
// create extended cmd -> 4 * READP0CMD = 40 bits
for (i = 0; i < 4; i++) {
binstringtobinarray(ext_cmd + (i * 10), READP0CMD);
}
// xor extended cmd with keybits
hitag2crack_xor(e_ext_cmd, ext_cmd, keybits, 40);
// send extended encrypted cmd
if (hitag2crack_send_e_cmd(responsestr, nrar, e_ext_cmd, 40)) {
// test if it was valid
if (strcmp(responsestr, ERROR_RESPONSE) != 0) {
return true;
}
} else {
#ifdef RFIDLER_DEBUG
UserMessage("hitag2crack_test_e_p0cmd:\r\n hitag2crack_send_e_cmd failed\r\n");
#endif
}
return false;
}
// hitag2crack_xor XORs the source with the pad to produce the target.
// source, target and pad are binarrays of length len.
void hitag2crack_xor(uint8_t *target, const uint8_t *source, const uint8_t *pad, unsigned int len) {
for (int i = 0; i < len; i++) {
target[i] = source[i] ^ pad[i];
}
}
// hitag2crack_read_page uses the supplied key stream and nrar pair to read the
// given page, returning the response as a hexstring.
// responsestr is the returned hexstring;
// pagenum is the page number to read;
// nrar is the 64 bit binarray of the nR aR pair;
// keybits is the binarray of the key stream.
bool hitag2crack_read_page(uint8_t *responsestr, uint8_t pagenum, uint8_t *nrar, uint8_t *keybits) {
uint8_t cmd[10];
uint8_t e_cmd[10];
uint8_t e_responsestr[9];
if (pagenum > 7) {
UserMessage("hitag2crack_read_page:\r\n invalid pagenum\r\n");
return false;
}
// create cmd
binstringtobinarray(cmd, READP0CMD);
if (pagenum & 0x1) {
cmd[9] = !cmd[9];
cmd[4] = !cmd[4];
}
if (pagenum & 0x2) {
cmd[8] = !cmd[8];
cmd[3] = !cmd[3];
}
if (pagenum & 0x4) {
cmd[7] = !cmd[7];
cmd[2] = !cmd[2];
}
// encrypt command
hitag2crack_xor(e_cmd, cmd, keybits, 10);
// send encrypted command
if (hitag2crack_send_e_cmd(e_responsestr, nrar, e_cmd, 10)) {
// check if it is valid
if (strcmp(e_responsestr, ERROR_RESPONSE) != 0) {
uint8_t e_response[32];
uint8_t response[32];
// convert to binarray
hextobinarray(e_response, e_responsestr);
// decrypt response
hitag2crack_xor(response, e_response, keybits + 10, 32);
// convert to hexstring
binarray_2_hex(responsestr, response, 32);
return true;
} else {
UserMessage("hitag2crack_read_page:\r\n hitag2crack_send_e_cmd returned ERROR_RESPONSE\r\n");
}
} else {
UserMessage("hitag2crack_read_page:\r\n hitag2crack_send_e_cmd failed\r\n");
}
return false;
}
// hitag2crack_send_e_cmd replays the auth and sends the given encrypted
// command.
// responsestr is the hexstring of the response to the command;
// nrar is the 64 bit binarray of the nR aR pair;
// cmd is the binarray of the encrypted command to send;
// len is the length of the encrypted command.
bool hitag2crack_send_e_cmd(uint8_t *responsestr, uint8_t *nrar, uint8_t *cmd, int len) {
// uint8_t tmp[37];
uint8_t uid[9];
uint8_t e_page3str[9];
// get the UID
if (!hitag2_get_uid(uid)) {
UserMessage("hitag2crack_send_e_cmd:\r\n cannot get UID\r\n");
return false;
}
// START_AUTH kills active crypto session
CryptoActive = false;
// get the UID again
if (!hitag2_get_uid(uid)) {
UserMessage("hitag2crack_send_e_cmd:\r\n cannot get UID (2nd time)\r\n");
return false;
}
// send nrar and receive (useless) encrypted page 3 value
if (!hitag2crack_tx_rx(e_page3str, nrar, 64, RWD_STATE_WAKING, false)) {
UserMessage("hitag2crack_send_e_cmd:\r\n tx/rx nrar failed\r\n");
return false;
}
// send encrypted command
if (!hitag2crack_tx_rx(responsestr, cmd, len, RWD_STATE_WAKING, false)) {
#ifdef RFIDLER_DEBUG
UserMessage("hitag2crack_send_e_cmd:\r\n tx/rx cmd failed\r\n");
#endif
return false;
}
return true;
}
// hitag2crack_tx_rx transmits a message and receives a response.
// responsestr is the hexstring of the response;
// msg is the binarray of the message to send;
// state is the RWD state;
// reset indicates whether to reset RWD state after.
bool hitag2crack_tx_rx(uint8_t *responsestr, uint8_t *msg, int len, int state, bool reset) {
uint8_t tmp[37];
int ret = 0;
// START_AUTH kills active crypto session
CryptoActive = false;
if (!rwd_send(msg, len, reset, BLOCK, state, RFIDlerConfig.FrameClock, 0, RFIDlerConfig.RWD_Wait_Switch_RX_TX, RFIDlerConfig.RWD_Zero_Period, RFIDlerConfig.RWD_One_Period, RFIDlerConfig.RWD_Gap_Period, RFIDlerConfig.RWD_Wait_Switch_TX_RX)) {
UserMessage("hitag2crack_tx_rx: rwd_send failed\r\n");
return false;
}
// skip 1/2 bit to synchronise manchester
HW_Skip_Bits = 1;
ret = read_ask_data(RFIDlerConfig.FrameClock, RFIDlerConfig.DataRate, tmp, 37, RFIDlerConfig.Sync, RFIDlerConfig.SyncBits, RFIDlerConfig.Timeout, ONESHOT_READ, BINARY);
// check if response was a valid length (5 sync bits + 32 bits response)
if (ret == 37) {
// check sync bits
if (memcmp(tmp, Hitag2Sync, 5) != 0) {
UserMessage("hitag2crack_tx_rx: no sync\r\n");
return false;
}
// convert response to hexstring
binarray_2_hex(responsestr, tmp + 5, 32);
return true;
} else {
#ifdef RFIDLER_DEBUG
UserMessage("hitag2crack_tx_rx: wrong rx len\r\n");
#endif
return false;
}
return false;
}
bool hitag2crack_rng_init(uint8_t *response, uint8_t *input) {
uint64_t sharedkey;
uint32_t serialnum;
uint32_t initvector;
uint8_t *spaceptr;
uint8_t *dataptr;
// extract vals from input
dataptr = input;
spaceptr = strchr(dataptr, ' ');
if (!spaceptr) {
UserMessage("/r/nformat is 'sharedkey UID nR' in hex\r\n");
return false;
}
*spaceptr = 0x00;
if (strlen(dataptr) != 12) {
UserMessage("/r/nsharedkey should be 48 bits long (12 hexchars)\r\n");
return false;
}
sharedkey = rev64(hexreversetoulonglong(dataptr));
dataptr = spaceptr + 1;
spaceptr = strchr(dataptr, ' ');
if (!spaceptr) {
UserMessage("/r/nno UID\r\n");
return false;
}
*spaceptr = 0x00;
if (strlen(dataptr) != 8) {
UserMessage("/r/nUID should be 32 bits long (8 hexchars)\r\n");
return false;
}
serialnum = rev32(hexreversetoulong(dataptr));
dataptr = spaceptr + 1;
if (strlen(dataptr) != 8) {
UserMessage("/r/nnR should be 32 bits long (8 hexchars)\r\n");
return false;
}
initvector = rev32(hexreversetoulong(dataptr));
// start up crypto engine
hitag2_init(&Hitag_Crypto_State, sharedkey, serialnum, initvector);
strcpy(response, "Success\r\n");
return true;
}
bool hitag2crack_decrypt_hex(uint8_t *response, uint8_t *hex) {
uint8_t bin[32];
uint8_t binhex[9];
uint8_t binstr[33];
uint32_t binulong;
if (strlen(hex) != 8) {
UserMessage("/r/nhex must be 32bits (8 hex chars)\r\n");
return false;
}
binulong = hextoulong(hex);
ulongtobinarray(bin, hitag2_crypt(binulong, 32), 32);
binarray_2_binstr(binstr, bin, 32);
binarray_2_hex(binhex, bin, 32);
// UserMessage("ar = %s\r\n", binstr);
// UserMessage("arhex = %s\r\n", binhex);
strcpy(response, binhex);
return true;
}
bool hitag2crack_decrypt_bin(uint8_t *response, uint8_t *e_binstr) {
uint8_t bin[32];
uint8_t e_bin[32];
uint8_t binstr[33];
uint32_t binulong;
int len;
len = strlen(e_binstr);
if (len > 32) {
UserMessage("\r\nbinary string must be <= 32 bits\r\n");
return false;
}
binstringtobinarray(e_bin, e_binstr);
binulong = binarraytoulong(e_bin, len);
ulongtobinarray(bin, hitag2_crypt(binulong, len), len);
binarray_2_binstr(binstr, bin, len);
strcpy(response, binstr);
return true;
}
bool hitag2crack_encrypt_hex(uint8_t *response, uint8_t *hex) {
// XOR pad so encrypt == decrypt :)
return hitag2crack_decrypt_hex(response, hex);
}
bool hitag2crack_encrypt_bin(uint8_t *response, uint8_t *e_binstr) {
return hitag2crack_decrypt_bin(response, e_binstr);
}
// hitag2_keystream uses the first crack algorithm described in the paper,
// Gone In 360 Seconds by Verdult, Garcia and Balasch, to retrieve 2048 bits
// of keystream.
// response is a multi-line text response containing the hex of the keystream;
// nrarhex is a string containing hex representations of the 32 bit nR and aR
// values (separated by a space) snooped using SNIFF-PWM.
bool hitag2_keystream(uint8_t *response, uint8_t *nrarhex) {
uint8_t uidhex[9];
uint8_t uid[32];
uint8_t nrar[64];
uint8_t e_firstcmd[10];
// uint8_t e_page0cmd[10];
// uint8_t keybits[2080];
uint8_t *keybits = DataBuff;
uint8_t keybitshex[67];
int kslen;
int ksoffset;
// uint8_t pagehex[9];
// uint8_t temp[20];
int i;
uint8_t *spaceptr = NULL;
/*
keybits = calloc(2080, sizeof(uint8_t));
if (!keybits) {
UserMessage("cannot malloc keybits\r\n");
return false;
}
*/
// get uid as hexstring
if (!hitag2_get_uid(uidhex)) {
UserMessage("Cannot get UID\r\n");
return false;
}
// convert uid hexstring to binarray
hextobinarray(uid, uidhex);
// convert nR and aR hexstrings to binarray
spaceptr = strchr(nrarhex, ' ');
if (!spaceptr) {
UserMessage("Please supply a valid nR aR pair\r\n");
return false;
}
*spaceptr = 0x00;
if (hextobinarray(nrar, nrarhex) != 32) {
UserMessage("nR is not 32 bits long\r\n");
return false;
}
if (hextobinarray(nrar + 32, spaceptr + 1) != 32) {
UserMessage("aR is not 32 bits long\r\n");
return false;
}
// find a valid encrypted command
if (!hitag2crack_find_valid_e_cmd(e_firstcmd, nrar)) {
UserMessage("Cannot find a valid encrypted command\r\n");
return false;
}
// find the 'read page 0' command and recover key stream
if (!hitag2crack_find_e_page0_cmd(keybits, e_firstcmd, nrar, uid)) {
UserMessage("Cannot find encrypted 'read page0' command\r\n");
return false;
}
// using the 40 bits of keystream in keybits, sending commands with ever
// increasing lengths to acquire 2048 bits of key stream.
kslen = 40;
while (kslen < 2048) {
ksoffset = 0;
if (!hitag2crack_send_auth(nrar)) {
UserMessage("hitag2crack_send_auth failed\r\n");
return false;
}
// while we have at least 52 bits of keystream, consume it with
// extended read page 0 commands. 52 = 10 (min command len) +
// 32 (response) + 10 (min command len we'll send)
while ((kslen - ksoffset) >= 52) {
// consume the keystream, updating ksoffset as we go
if (!hitag2crack_consume_keystream(keybits, kslen, &ksoffset, nrar)) {
UserMessage("hitag2crack_consume_keystream failed\r\n");
return false;
}
}
// send an extended command to retrieve more keystream, updating kslen
// as we go
if (!hitag2crack_extend_keystream(keybits, &kslen, ksoffset, nrar, uid)) {
UserMessage("hitag2crack_extend_keystream failed\r\n");
return false;
}
UserMessage("Recovered %d bits of keystream\r\n", kslen);
}
for (i = 0; i < 2048; i += 256) {
binarray_2_hex(keybitshex, keybits + i, 256);
UserMessage("%s\r\n", keybitshex);
}
response[0] = 0x00;
return true;
}
// hitag2crack_send_auth replays the auth and returns.
// nrar is the 64 bit binarray of the nR aR pair;
bool hitag2crack_send_auth(uint8_t *nrar) {
uint8_t uid[9];
uint8_t e_page3str[9];
// get the UID
if (!hitag2_get_uid(uid)) {
UserMessage("hitag2crack_send_auth:\r\n cannot get UID\r\n");
return false;
}
// START_AUTH kills active crypto session
CryptoActive = false;
// get the UID again
if (!hitag2_get_uid(uid)) {
UserMessage("hitag2crack_send_auth:\r\n cannot get UID (2nd time)\r\n");
return false;
}
// send nrar and receive (useless) encrypted page 3 value
if (!hitag2crack_tx_rx(e_page3str, nrar, 64, RWD_STATE_WAKING, false)) {
UserMessage("hitag2crack_send_auth:\r\n tx/rx nrar failed\r\n");
return false;
}
return true;
}
// hitag2crack_consume_keystream sends an extended command (up to 510 bits in
// length) to consume keystream.
// keybits is the binarray of keystream bits;
// kslen is the length of keystream;
// ksoffset is a pointer to the current keystream offset (updated by this fn);
// nrar is the 64 bit binarray of the nR aR pair.
bool hitag2crack_consume_keystream(uint8_t *keybits, int kslen, int *ksoffset, uint8_t *nrar) {
int conlen;
int numcmds;
int i;
uint8_t ext_cmd[510];
uint8_t e_ext_cmd[510];
uint8_t responsestr[9];
// calculate the length of keybits to consume with the extended command.
// 42 = 32 bit response + 10 bit command reserved for next command. conlen
// cannot be longer than 510 bits to fit into the small RWD buffer.
conlen = kslen - *ksoffset - 42;
if (conlen < 10) {
UserMessage("hitag2crack_consume_keystream:\r\n conlen < 10\r\n");
return false;
}
// sanitise conlen
if (conlen > 510) {
conlen = 510;
}
// calculate how many repeated commands to send in this extended command.
numcmds = conlen / 10;
// build extended command
for (i = 0; i < numcmds; i++) {
binstringtobinarray(ext_cmd + (i * 10), READP0CMD);
}
// xor extended cmd with keybits
hitag2crack_xor(e_ext_cmd, ext_cmd, keybits + *ksoffset, numcmds * 10);
// send encrypted command
if (!hitag2crack_tx_rx(responsestr, e_ext_cmd, numcmds * 10, RWD_STATE_WAKING, false)) {
UserMessage("hitag2crack_consume_keystream:\r\n tx/rx cmd failed\r\n");
return false;
}
// test response
if (strcmp(responsestr, ERROR_RESPONSE) == 0) {
UserMessage("hitag2crack_consume_keystream:\r\n got error response from card\r\n");
return false;
}
// don't bother decrypting the response - we already know the keybits
// update ksoffset with command length and response
*ksoffset += (numcmds * 10) + 32;
return true;
}
// hitag2crack_extend_keystream sends an extended command to retrieve more keybits.
// keybits is the binarray of the keystream bits;
// kslen is a pointer to the current keybits length;
// ksoffset is the offset into the keybits array;
// nrar is the 64 bit binarray of the nR aR pair;
// uid is the 32 bit binarray of the UID.
bool hitag2crack_extend_keystream(uint8_t *keybits, int *kslen, int ksoffset, uint8_t *nrar, uint8_t *uid) {
int cmdlen;
int numcmds;
uint8_t ext_cmd[510];
uint8_t e_ext_cmd[510];
uint8_t responsestr[9];
uint8_t e_response[32];
int i;
// calc number of command iterations to send
cmdlen = *kslen - ksoffset;
if (cmdlen < 10) {
UserMessage("hitag2crack_extend_keystream:\r\n cmdlen < 10\r\n");
return false;
}
numcmds = cmdlen / 10;
// build extended command
for (i = 0; i < numcmds; i++) {
binstringtobinarray(ext_cmd + (i * 10), READP0CMD);
}
// xor extended cmd with keybits
hitag2crack_xor(e_ext_cmd, ext_cmd, keybits + ksoffset, numcmds * 10);
// send extended encrypted cmd
if (!hitag2crack_tx_rx(responsestr, e_ext_cmd, numcmds * 10, RWD_STATE_WAKING, false)) {
UserMessage("hitag2crack_extend_keystream:\r\n tx/rx cmd failed\r\n");
return false;
}
// test response
if (strcmp(responsestr, ERROR_RESPONSE) == 0) {
UserMessage("hitag2crack_extend_keystream:\r\n got error response from card\r\n");
return false;
}
// convert response to binarray
hextobinarray(e_response, responsestr);
// recover keystream from encrypted response
hitag2crack_xor(keybits + ksoffset + (numcmds * 10), e_response, uid, 32);
// update kslen
*kslen = ksoffset + (numcmds * 10) + 32;
return true;
}
bool hitag2_reader(uint8_t *response, uint8_t *key, bool interactive) {
uint8_t tmp[9];
response[0] = '\0';
// auth to tag
if (hitag2_crypto_auth(tmp, key)) {
// read tag, one page at a time
for (int i = 0; i <= 7; ++i) {
if (!read_tag(tmp, i, i)) {
// if read fails, it could be because of auth,
// so try to reauth
if (!hitag2_crypto_auth(tmp, key)) {
// if we can't reauth, it's a real failure
return false;
}
// temp failure (probably due to page protections)
strcpy(tmp, "XXXXXXXX");
}
// page contents are in tmp
strcat(response, tmp);
}
if (interactive) {
tmp[8] = '\0';
for (i = 0; i <= 7 ; ++i) {
UserMessageNum("%d: ", i);
memcpy(tmp, response + (i * 8), 8);
UserMessage("%s\r\n", tmp);
}
UserMessage("%s", "\r\n");
} else {
hitag2_nvm_store_tag(response);
}
return true;
} else {
return false;
}
}
-42
View File
@@ -1,42 +0,0 @@
//-----------------------------------------------------------------------------
// Borrowed initially from https://github.com/factoritbv/hitag2hell
// and https://github.com/AdamLaurie/RFIDler/blob/master/firmware/Pic32/RFIDler.X/src/hitag2crack.c
// Copyright (C) Kevin Sheldrake <kev@headhacking.com>, Aug 2018
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// Definitions hitag2 attack functions
//-----------------------------------------------------------------------------
bool hitag2_crack(uint8_t *response, uint8_t *nrarhex);
bool hitag2crack_find_valid_e_cmd(uint8_t e_cmd[], uint8_t nrar[]);
bool hitag2crack_find_e_page0_cmd(uint8_t keybits[], uint8_t e_firstcmd[], uint8_t nrar[], uint8_t uid[]);
bool hitag2crack_test_e_p0cmd(uint8_t *keybits, uint8_t *nrar, uint8_t *e_cmd, uint8_t *uid, uint8_t *e_uid);
void hitag2crack_xor(uint8_t *target, const uint8_t *source, const uint8_t *pad, unsigned int len);
bool hitag2crack_read_page(uint8_t *responsestr, uint8_t pagenum, uint8_t *nrar, uint8_t *keybits);
bool hitag2crack_send_e_cmd(uint8_t *responsestr, uint8_t *nrar, uint8_t *cmd, int len);
bool hitag2crack_tx_rx(uint8_t *responsestr, uint8_t *msg, int len, int state, bool reset);
bool hitag2crack_rng_init(uint8_t *response, uint8_t *input);
bool hitag2crack_decrypt_hex(uint8_t *response, uint8_t *hex);
bool hitag2crack_decrypt_bin(uint8_t *response, uint8_t *e_binstr);
bool hitag2crack_encrypt_hex(uint8_t *response, uint8_t *hex);
bool hitag2crack_encrypt_bin(uint8_t *response, uint8_t *e_binstr);
bool hitag2_keystream(uint8_t *response, uint8_t *nrarhex);
bool hitag2crack_send_auth(uint8_t *nrar);
bool hitag2crack_consume_keystream(uint8_t *keybits, int kslen, int *ksoffset, uint8_t *nrar);
bool hitag2crack_extend_keystream(uint8_t *keybits, int *kslen, int ksoffset, uint8_t *nrar, uint8_t *uid);
bool hitag2_reader(uint8_t *response, uint8_t *key, bool interactive);
+330 -180
View File
File diff suppressed because it is too large. Load diff
+2 -3
View File
@@ -22,11 +22,10 @@
#define _HITAGS_H_
#include "common.h"
#include "hitag.h"
void SimulateHitagSTag(bool tag_mem_supplied, const uint8_t *data, bool ledcontrol);
void ReadHitagS(hitag_function htf, const hitag_data *htd, bool ledcontrol);
void WritePageHitagS(hitag_function htf, const hitag_data *htd, int page, bool ledcontrol);
void ReadHitagS(const lf_hitag_data_t *payload, bool ledcontrol);
void WritePageHitagS(const lf_hitag_data_t *payload, bool ledcontrol);
void Hitag_check_challenges(const uint8_t *data, uint32_t datalen, bool ledcontrol);
#endif
+2 -2
View File
@@ -764,7 +764,7 @@ bool sc_rx_bytes(uint8_t *dest, uint16_t *destlen, uint32_t wait) {
break;
} else if (len == 1) {
continue;
} else if (len <= 0) {
} else {
return false;
}
}
@@ -937,7 +937,7 @@ void SmartCardUpgrade(uint64_t arg0) {
bool isOK = true;
uint16_t length = arg0, pos = 0;
uint8_t *fwdata = BigBuf_get_addr();
const uint8_t *fwdata = BigBuf_get_addr();
uint8_t *verfiydata = BigBuf_malloc(I2C_BLOCK_SIZE);
while (length) {
+1 -1
View File
@@ -68,6 +68,6 @@ void SmartCardUpgrade(uint64_t arg0);
void SmartCardSetBaud(uint64_t arg0);
void SmartCardSetClock(uint64_t arg0);
void I2C_print_status(void);
int I2C_get_version(uint8_t *maj, uint8_t *min);
int I2C_get_version(uint8_t *major, uint8_t *minor);
#endif
+5 -5
View File
@@ -774,7 +774,7 @@ void SimulateIso14443bTag(const uint8_t *pupi) {
int cardSTATE = SIM_NOFIELD;
int vHf = 0; // in mV
tosend_t *ts = get_tosend();
const tosend_t *ts = get_tosend();
uint8_t *receivedCmd = BigBuf_calloc(MAX_FRAME_SIZE);
@@ -1566,7 +1566,7 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len, bool framing) {
* Convenience function to encode, transmit and trace iso 14443b comms
*/
static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len, uint32_t *start_time, uint32_t *eof_time, bool framing) {
tosend_t *ts = get_tosend();
const tosend_t *ts = get_tosend();
CodeIso14443bAsReader(cmd, len, framing);
TransmitFor14443b_AsReader(start_time);
if (g_trigger) LED_A_ON();
@@ -1582,7 +1582,7 @@ static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len, uint32_t
/* Sends an APDU to the tag
* TODO: check CRC and preamble
*/
int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void *rxdata, uint16_t rxmaxlen, uint8_t *response_byte, uint16_t *reponselen) {
int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void *rxdata, uint16_t rxmaxlen, uint8_t *response_byte, uint16_t *responselen) {
uint8_t real_cmd[msg_len + 4];
@@ -1693,8 +1693,8 @@ int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void
}
}
if (reponselen) {
*reponselen = len;
if (responselen) {
*responselen = len;
}
return PM3_SUCCESS;
}
+1 -1
View File
@@ -39,7 +39,7 @@
#endif
void iso14443b_setup(void);
int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void *rxdata, uint16_t rxmaxlen, uint8_t *res, uint16_t *responselen);
int iso14443b_apdu(uint8_t const *msg, size_t msg_len, bool send_chaining, void *rxdata, uint16_t rxmaxlen, uint8_t *response_byte, uint16_t *responselen);
int iso14443b_select_card(iso14b_card_select_t *card);
+67 -27
View File
@@ -1009,7 +1009,7 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
}
uint32_t dma_start_time = 0;
uint16_t *upTo = dma->buf;
const uint16_t *upTo = dma->buf;
for (;;) {
@@ -1502,7 +1502,7 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo
if (g_dbglevel > DBG_ERROR) Dbprintf("FpgaSetupSscDma failed. Exiting");
return -4;
}
uint8_t *upTo = dma->buf;
const uint8_t *upTo = dma->buf;
uint32_t dma_start_time = GetCountSspClk() & 0xfffffff8;
@@ -1603,7 +1603,7 @@ void AcquireRawAdcSamplesIso15693(void) {
SpinDelay(250);
// Now send the command
tosend_t *ts = get_tosend();
const tosend_t *ts = get_tosend();
uint32_t start_time = 0;
TransmitTo15693Tag(ts->buf, ts->max, &start_time, false);
@@ -1681,7 +1681,7 @@ void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string, bool icla
// Count of samples received so far, so that we can include timing
int samples = 0;
uint16_t *upTo = dma->buf;
const uint16_t *upTo = dma->buf;
for (;;) {
@@ -1902,7 +1902,7 @@ static void BuildIdentifyRequest(uint8_t *cmd) {
// If you do not need the answer use NULL for *recv[]
// return: length of received data
// logging enabled
int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
int SendDataTag(const uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time, uint16_t *resp_len) {
if (init) {
@@ -1918,7 +1918,7 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t
CodeIso15693AsReader256(send, sendlen);
}
tosend_t *ts = get_tosend();
const tosend_t *ts = get_tosend();
TransmitTo15693Tag(ts->buf, ts->max, &start_time, false);
if (tearoff_hook() == PM3_ETEAROFF) { // tearoff occurred
@@ -1941,7 +1941,7 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t
int SendDataTagEOF(uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time, bool fsk, bool recv_speed, uint16_t *resp_len) {
CodeIso15693AsReaderEOF();
tosend_t *ts = get_tosend();
const tosend_t *ts = get_tosend();
TransmitTo15693Tag(ts->buf, ts->max, &start_time, false);
uint32_t end_time = start_time + 32 * (8 * ts->max - 4); // subtract the 4 padding bits after EOF
LogTrace_ISO15693(NULL, 0, (start_time * 4), (end_time * 4), NULL, true);
@@ -1959,9 +1959,9 @@ int SendDataTagEOF(uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, ui
// Decodes a message from a tag and displays its metadata and content
#define DBD15STATLEN 48
static void DbdecodeIso15693Answer(int len, uint8_t *d) {
static void DbdecodeIso15693Answer(int n, const uint8_t *d) {
if (len > 3) {
if (n > 3) {
char status[DBD15STATLEN + 1] = {0};
@@ -2007,7 +2007,7 @@ static void DbdecodeIso15693Answer(int len, uint8_t *d) {
strncat(status, "No error ", DBD15STATLEN - strlen(status));
}
if (CheckCrc15(d, len))
if (CheckCrc15(d, n))
strncat(status, "[+] crc ( " _GREEN_("ok") " )", DBD15STATLEN - strlen(status));
else
strncat(status, "[!] crc ( " _RED_("fail") " )", DBD15STATLEN - strlen(status));
@@ -2127,7 +2127,7 @@ void EmlClearIso15693(void) {
// Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands
// all demodulation performed in arm rather than host. - greg
void SimTagIso15693(uint8_t *uid, uint8_t block_size) {
void SimTagIso15693(const uint8_t *uid, uint8_t block_size) {
// free eventually allocated BigBuf memory
BigBuf_free_keep_EM();
@@ -2581,7 +2581,7 @@ void SimTagIso15693(uint8_t *uid, uint8_t block_size) {
AddCrc15(recv, recvLen);
recvLen += 2;
CodeIso15693AsTag(recv, recvLen);
tosend_t *ts = get_tosend();
const tosend_t *ts = get_tosend();
uint32_t response_time = reader_eof_time + DELAY_ISO15693_VCD_TO_VICC_SIM;
if (tag->expectFsk) { // Not suppoted yet
@@ -2890,21 +2890,14 @@ void SetTag15693Uid(const uint8_t *uid) {
uint8_t cmd[4][9] = {
{ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3e, 0x00, 0x00, 0x00, 0x00, 0xE9, 0x8F},
{ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3f, 0x69, 0x96, 0x00, 0x00, 0x8A, 0xBB},
{ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x38},
{ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x39}
// Command 3 : 02 21 38 u8u7u6u5 (where uX = uid byte X)
{ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x38, uid[7], uid[6], uid[5], uid[4]},
// Command 4 : 02 21 39 u4u3u2u1 (where uX = uid byte X)
{ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x39, uid[3], uid[2], uid[1], uid[0]}
};
// Command 3 : 02 21 38 u8u7u6u5 (where uX = uid byte X)
cmd[2][3] = uid[7];
cmd[2][4] = uid[6];
cmd[2][5] = uid[5];
cmd[2][6] = uid[4];
// Command 4 : 02 21 39 u4u3u2u1 (where uX = uid byte X)
cmd[3][3] = uid[3];
cmd[3][4] = uid[2];
cmd[3][5] = uid[1];
cmd[3][6] = uid[0];
AddCrc15(cmd[2], 7);
AddCrc15(cmd[3], 7);
@@ -2938,6 +2931,53 @@ void SetTag15693Uid(const uint8_t *uid) {
switch_off();
}
// Set the UID on Magic ISO15693 tag ( Gen2 ?)
// E0 00 09 - seem to be command
// 0x41, 0x40 - seem to be block referens
void SetTag15693Uid_v2(const uint8_t *uid) {
LED_A_ON();
uint8_t cmd[4][10] = {
{ ISO15_REQ_DATARATE_HIGH, ISO15693_MAGIC_WRITE, 0x09, 0x47, 0x3f, 0x03, 0x8b, 0x00, 0x00, 0x00 },
{ ISO15_REQ_DATARATE_HIGH, ISO15693_MAGIC_WRITE, 0x09, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
// hf 15 raw -wac -d 02 e0 09 41 + uid first four bytes
{ISO15_REQ_DATARATE_HIGH, ISO15693_MAGIC_WRITE, 0x09, 0x40, uid[7], uid[6], uid[5], uid[4], 0x00, 0x00},
// hf 15 raw -wac -d 02 e0 09 40 + uid last four bytes
{ISO15_REQ_DATARATE_HIGH, ISO15693_MAGIC_WRITE, 0x09, 0x41, uid[3], uid[2], uid[1], uid[0], 0x00, 0x00}
};
uint8_t buf[ISO15693_MAX_RESPONSE_LENGTH] = {0x00};
uint32_t start_time = 0;
uint32_t eof_time = 0;
uint16_t recvlen = 0;
int res = PM3_SUCCESS;
for (int i = 0; i < 4; i++) {
AddCrc15(cmd[i], 8);
res = SendDataTag(
cmd[i],
sizeof(cmd[i]),
(i == 0) ? true : false,
true,
buf,
sizeof(buf),
start_time,
ISO15693_READER_TIMEOUT_WRITE,
&eof_time,
&recvlen
);
start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER;
}
reply_ng(CMD_HF_ISO15693_CSETUID_V2, res, NULL, 0);
switch_off();
}
static void init_password_15693_Slix(uint8_t *buffer, const uint8_t *pwd, const uint8_t *rnd) {
memcpy(buffer, pwd, 4);
if (rnd) {
@@ -2988,7 +3028,7 @@ static uint32_t disable_privacy_15693_Slix(uint32_t start_time, uint32_t *eof_ti
return PM3_SUCCESS;
}
static uint32_t set_pass_15693_Slix(uint32_t start_time, uint32_t *eof_time, uint8_t pass_id, const uint8_t *password, uint8_t *uid) {
static uint32_t set_pass_15693_Slix(uint32_t start_time, uint32_t *eof_time, uint8_t pass_id, const uint8_t *password, const uint8_t *uid) {
uint8_t rnd[2];
@@ -3101,7 +3141,7 @@ static uint32_t enable_eas_15693_Slix(uint32_t start_time, uint32_t *eof_time, c
return PM3_SUCCESS;
}
static uint32_t write_password_15693_Slix(uint32_t start_time, uint32_t *eof_time, uint8_t pwd_id, const uint8_t *password, uint8_t *uid) {
static uint32_t write_password_15693_Slix(uint32_t start_time, uint32_t *eof_time, uint8_t pwd_id, const uint8_t *password, const uint8_t *uid) {
uint8_t new_pwd_cmd[] = { (ISO15_REQ_DATARATE_HIGH | ISO15_REQ_ADDRESS), ISO15693_WRITE_PASSWORD, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, pwd_id, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+4 -3
View File
@@ -47,18 +47,19 @@ int GetIso15693AnswerFromTag(uint8_t *response, uint16_t max_len, uint16_t timeo
void AcquireRawAdcSamplesIso15693(void);
void ReaderIso15693(iso15_card_select_t *p_card); // ISO15693 reader
void EmlClearIso15693(void);
void SimTagIso15693(uint8_t *uid, uint8_t block_size); // simulate an ISO15693 tag
void SimTagIso15693(const uint8_t *uid, uint8_t block_size); // simulate an ISO15693 tag
void BruteforceIso15693Afi(uint32_t flags); // find an AFI of a tag
void SendRawCommand15693(iso15_raw_cmd_t *packet); // send arbitrary commands from CLI
void SniffIso15693(uint8_t jam_search_len, uint8_t *jam_search_string, bool iclass);
int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
int SendDataTag(const uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv,
uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time, uint16_t *resp_len);
int SendDataTagEOF(uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time, bool fsk, bool recv_speed, uint16_t *resp_len);
void SetTag15693Uid(const uint8_t *uid);
void SetTag15693Uid_v2(const uint8_t *uid);
void WritePasswordSlixIso15693(const uint8_t *old_password, const uint8_t *new_password, uint8_t pwd_id);
void DisablePrivacySlixIso15693(const uint8_t *password);
@@ -67,5 +68,5 @@ void DisableEAS_AFISlixIso15693(const uint8_t *password, bool usepwd);
void EnableEAS_AFISlixIso15693(const uint8_t *password, bool usepwd);
void PassProtextEASSlixIso15693(const uint8_t *password);
void PassProtectAFISlixIso15693(const uint8_t *password);
void WriteAFIIso15693(const uint8_t *password, bool usepwd, uint8_t *uid, bool use_uid, uint8_t afi);
void WriteAFIIso15693(const uint8_t *password, bool use_pwd, uint8_t *uid, bool use_uid, uint8_t afi);
#endif
+18 -12
View File
@@ -118,7 +118,9 @@ static size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
volatile uint8_t adc_val = AT91C_BASE_SSC->SSC_RHR;
if (g_logging) logSampleSimple(adc_val);
if (g_logging) {
logSampleSimple(adc_val);
}
// Only test field changes if state of adc values matter
if (wait == false) {
@@ -157,7 +159,10 @@ static size_t lf_count_edge_periods_ex(size_t max, bool wait, bool detect_gap) {
}
}
if (g_logging) logSampleSimple(0xFF);
if (g_logging) {
logSampleSimple(0xFF);
}
return 0;
}
@@ -210,16 +215,18 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
sc->averaging = 0;
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, sc->divisor);
if (reader) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
} else {
if (simulate)
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC);
else
// Sniff
//FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC);
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE);
if (simulate) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC);
} else {
// Sniff
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC);
// FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_TOGGLE_MODE);
}
}
// Connect the A/D to the peak-detected low-frequency path.
@@ -230,10 +237,7 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
// When in reader mode, give the field a bit of time to settle.
// 313T0 = 313 * 8us = 2504us = 2.5ms Hitag2 tags needs to be fully powered.
// if (reader) {
// 10 ms
SpinDelay(10);
// }
// Steal this pin from the SSP (SPI communication channel with fpga) and use it to control the modulation
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
@@ -264,7 +268,9 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
uint32_t bufsize = 10000;
// use malloc
if (g_logging) initSampleBufferEx(&bufsize, true);
if (g_logging) {
initSampleBufferEx(&bufsize, true);
}
lf_sample_mean();
}
+21 -6
View File
@@ -2227,13 +2227,27 @@ void T55xxWakeUp(uint32_t pwd, uint8_t flags, bool ledcontrol) {
/*-------------- Cloning routines -----------*/
static void WriteT55xx(const uint32_t *blockdata, uint8_t startblock, uint8_t numblocks, bool ledcontrol) {
t55xx_write_block_t cmd;
cmd.pwd = 0;
cmd.flags = 0;
for (uint8_t i = numblocks + startblock; i > startblock; i--) {
cmd.data = blockdata[i - 1];
cmd.blockno = i - 1;
// Sanity checks
if (blockdata == NULL || numblocks == 0) {
reply_ng(CMD_LF_T55XX_WRITEBL, PM3_EINVARG, NULL, 0);
return;
}
t55xx_write_block_t cmd = {
.pwd = 0,
.flags = 0
};
// write in reverse order since we don't want to set
// a password enabled configuration first....
while (numblocks--) {
// zero based index
cmd.data = blockdata[numblocks];
cmd.blockno = startblock + numblocks;
// since this fct sends a NG packet every time, this loop will send I number of NG
T55xxWriteBlock((uint8_t *)&cmd, ledcontrol);
}
}
@@ -2435,6 +2449,7 @@ int copy_em410x_to_t55xx(uint8_t card, uint8_t clock, uint32_t id_hi, uint32_t i
} else { // T5555 (Q5)
data[0] = T5555_SET_BITRATE(clock) | T5555_MODULATION_MANCHESTER | (blocks << T5555_MAXBLOCK_SHIFT);
}
if (card == 2) {
WriteEM4x05(data, 4, 3, ledcontrol);
if (add_electra) {
+38 -15
View File
@@ -134,10 +134,11 @@ void initSampleBuffer(uint32_t *sample_size) {
}
void initSampleBufferEx(uint32_t *sample_size, bool use_malloc) {
if (sample_size == NULL) {
Dbprintf("initSampleBufferEx, param NULL");
return;
}
BigBuf_free_keep_EM();
// We can't erase the buffer now, it would drastically delay the acquisition
@@ -181,14 +182,26 @@ void logSampleSimple(uint8_t sample) {
void logSample(uint8_t sample, uint8_t decimation, uint8_t bits_per_sample, bool avg) {
if (!data.buffer) return;
if (!data.buffer) {
return;
}
// keep track of total gather samples regardless how many was discarded.
if (samples.counter-- == 0) return;
if (samples.counter-- == 0) {
return;
}
if (bits_per_sample == 0) bits_per_sample = 1;
if (bits_per_sample > 8) bits_per_sample = 8;
if (decimation == 0) decimation = 1;
if (bits_per_sample == 0) {
bits_per_sample = 1;
}
if (bits_per_sample > 8) {
bits_per_sample = 8;
}
if (decimation == 0) {
decimation = 1;
}
if (avg) {
samples.sum += sample;
@@ -198,7 +211,9 @@ void logSample(uint8_t sample, uint8_t decimation, uint8_t bits_per_sample, bool
if (decimation > 1) {
samples.dec_counter++;
if (samples.dec_counter < decimation) return;
if (samples.dec_counter < decimation) {
return;
}
samples.dec_counter = 0;
}
@@ -246,12 +261,13 @@ void logSample(uint8_t sample, uint8_t decimation, uint8_t bits_per_sample, bool
**/
void LFSetupFPGAForADC(int divisor, bool reader_field) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
if ((divisor == 1) || (divisor < 0) || (divisor > 255))
if ((divisor == 1) || (divisor < 0) || (divisor > 255)) {
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_134); //~134kHz
else if (divisor == 0)
} else if (divisor == 0) {
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, LF_DIVISOR_125); //125kHz
else
} else {
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, divisor);
}
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER | (reader_field ? FPGA_LF_ADC_READER_FIELD : 0));
@@ -517,7 +533,7 @@ int ReadLF_realtime(bool reader_field) {
// Request USB transmission and change FIFO bank
if (async_usb_write_requestWrite() == false) {
return_value = PM3_EIO;
break;
goto out;
}
// Reset sample
@@ -534,9 +550,12 @@ int ReadLF_realtime(bool reader_field) {
}
}
}
LED_D_OFF();
return_value = async_usb_write_stop();
out:
LED_D_OFF();
// DoAcquisition() end
StopTicks();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
@@ -623,12 +642,14 @@ void doT55x7Acquisition(size_t sample_size, bool ledcontrol) {
// skip until first high samples begin to change
if (startFound || sample > T55xx_READ_LOWER_THRESHOLD + T55xx_READ_TOL) {
// if just found start - recover last sample
if (!startFound) {
if (startFound == false) {
dest[i++] = lastSample;
startFound = true;
}
// collect samples
dest[i++] = sample;
if (i < bufsize) {
dest[i++] = sample;
}
}
}
}
@@ -698,13 +719,15 @@ void doCotagAcquisition(void) {
firstlow = true;
}
++i;
if (sample > COTAG_ONE_THRESHOLD) {
dest[i] = 255;
++i;
} else if (sample < COTAG_ZERO_THRESHOLD) {
dest[i] = 0;
++i;
} else {
dest[i] = dest[i - 1];
++i;
}
}
}
+28 -15
View File
@@ -158,7 +158,9 @@ void MifareDesfireGetInformation(void) {
// card select - information
if (!iso14443a_select_card(NULL, &card, NULL, true, 0, false)) {
if (g_dbglevel >= DBG_ERROR) DbpString("Can't select card");
if (g_dbglevel >= DBG_ERROR) {
DbpString("Can't select card");
}
payload.isOK = 1; // 2 == can not select
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
switch_off();
@@ -183,18 +185,22 @@ void MifareDesfireGetInformation(void) {
}
if (len < sizeof(payload.versionHW) + 1) {
Dbprintf("Tag answer to MFDES_GET_VERSION was too short: data in Hardware Information is probably invalid.");
print_result("Answer", resp, len);
memset(resp + len, 0xFF, sizeof(payload.versionHW) + 1 - len); // clear remaining bytes
payload.isOK = 3; // 3 == DOESN'T ANSWER TO GET_VERSION
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
switch_off();
if (g_dbglevel >= DBG_ERROR) {
Dbprintf("Tag answer to MFDES_GET_VERSION was too short: data in Hardware Information is probably invalid.");
print_result("Answer", resp, len);
}
return;
}
memcpy(payload.versionHW, resp + 1, sizeof(payload.versionHW));
// ADDITION_FRAME 1
cmd[1] = MFDES_ADDITIONAL_FRAME;
len = DesfireAPDU(cmd, cmd_len, resp);
len = DesfireAPDU(cmd, cmd_len, resp);
if (!len) {
print_result("ERROR <--: ", resp, len);
payload.isOK = 3; // 3 == DOESN'T ANSWER TO GET_VERSION
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
switch_off();
@@ -202,9 +208,14 @@ void MifareDesfireGetInformation(void) {
}
if (len < sizeof(payload.versionSW) + 1) {
Dbprintf("Tag answer to MFDES_ADDITIONAL_FRAME 1 was too short: data in Software Information is probably invalid.");
print_result("Answer", resp, len);
memset(resp + len, 0xFF, sizeof(payload.versionSW) + 1 - len); // clear remaining bytes
payload.isOK = 3; // 3 == DOESN'T ANSWER TO GET_VERSION
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
switch_off();
if (g_dbglevel >= DBG_ERROR) {
Dbprintf("Tag answer to MFDES_ADDITIONAL_FRAME 1 was too short: data in Software Information is probably invalid.");
print_result("Answer", resp, len);
}
return;
}
memcpy(payload.versionSW, resp + 1, sizeof(payload.versionSW));
@@ -212,7 +223,6 @@ void MifareDesfireGetInformation(void) {
// ADDITION_FRAME 2
len = DesfireAPDU(cmd, cmd_len, resp);
if (!len) {
print_result("ERROR <--: ", resp, len);
payload.isOK = 3; // 3 == DOESN'T ANSWER TO GET_VERSION
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
switch_off();
@@ -220,16 +230,19 @@ void MifareDesfireGetInformation(void) {
}
if (len < sizeof(payload.details) + 1) {
Dbprintf("Tag answer to MFDES_ADDITIONAL_FRAME 2 was too short: data in Batch number and Production date is probably invalid");
print_result("Answer", resp, len);
memset(resp + len, 0xFF, sizeof(payload.details) + 1 - len); // clear remaining bytes
payload.isOK = 3; // 3 == DOESN'T ANSWER TO GET_VERSION
reply_ng(CMD_HF_DESFIRE_INFO, PM3_ESOFT, (uint8_t *)&payload, sizeof(payload));
switch_off();
if (g_dbglevel >= DBG_ERROR) {
Dbprintf("Tag answer to MFDES_ADDITIONAL_FRAME 2 was too short: data in Batch number and Production date is probably invalid");
print_result("Answer", resp, len);
}
return;
}
memcpy(payload.details, resp + 1, sizeof(payload.details));
LED_B_ON();
reply_ng(CMD_HF_DESFIRE_INFO, PM3_SUCCESS, (uint8_t *)&payload, sizeof(payload));
LED_B_OFF();
// reset the pcb_blocknum,
pcb_blocknum = 0;
+1 -1
View File
@@ -153,7 +153,7 @@ Definition 14. Define the rotate key function rk : (F 82 ) 8 × N → (F 82 ) 8
rk(x [0] . . . x [7] , 0) = x [0] . . . x [7]
rk(x [0] . . . x [7] , n + 1) = rk(rl(x [0] ) . . . rl(x [7] ), n)
**/
static void rk(uint8_t *key, uint8_t n, uint8_t *outp_key) {
static void rk(const uint8_t *key, uint8_t n, uint8_t *outp_key) {
memcpy(outp_key, key, 8);
uint8_t j;
while (n-- > 0) {
+88 -47
View File
@@ -113,11 +113,14 @@ kvsprintf(char const *fmt, void *arg, int radix, va_list ap) {
for (;;) {
padc = ' ';
width = 0;
while ((ch = (u_char) * fmt++) != '%' || stop) {
PCHAR(ch);
if (ch == '\0')
if (ch == '\0') {
return (retval);
}
}
percent = fmt - 1;
qflag = 0;
lflag = 0;
@@ -178,36 +181,43 @@ reswitch:
for (n = 0;; ++fmt) {
n = n * 10 + ch - '0';
ch = *fmt;
if (ch < '0' || ch > '9')
if (ch < '0' || ch > '9') {
break;
}
}
if (dot)
if (dot) {
dwidth = n;
else
} else {
width = n;
}
goto reswitch;
case 'b':
num = (u_int)va_arg(ap, int);
p = va_arg(ap, char *);
for (q = ksprintn(nbuf, num, *p++, NULL, 0); *q;)
for (q = ksprintn(nbuf, num, *p++, NULL, 0); *q;) {
PCHAR(*q--);
}
if (num == 0)
if (num == 0) {
break;
}
for (tmp = 0; *p;) {
n = *p++;
if (num & (1 << (n - 1))) {
PCHAR(tmp ? ',' : '<');
for (; (n = *p) > ' '; ++p)
for (; (n = *p) > ' '; ++p) {
PCHAR(n);
}
tmp = 1;
} else
for (; *p > ' '; ++p)
continue;
} else {
for (; *p > ' '; ++p) {};
}
}
if (tmp)
if (tmp) {
PCHAR('>');
}
break;
case 'c':
PCHAR(va_arg(ap, int));
@@ -215,15 +225,19 @@ reswitch:
case 'D':
up = va_arg(ap, u_char *);
p = va_arg(ap, char *);
if (!width)
if (!width) {
width = 16;
}
while (width--) {
PCHAR(hex2ascii(*up >> 4));
PCHAR(hex2ascii(*up & 0x0f));
up++;
if (width)
for (q = p; *q; q++)
if (width) {
for (q = p; *q; q++) {
PCHAR(*q);
}
}
}
break;
case 'd':
@@ -235,8 +249,9 @@ reswitch:
if (hflag) {
hflag = 0;
cflag = 1;
} else
} else {
hflag = 1;
}
goto reswitch;
case 'j':
jflag = 1;
@@ -245,8 +260,9 @@ reswitch:
if (lflag) {
lflag = 0;
qflag = 1;
} else
} else {
lflag = 1;
}
goto reswitch;
case 'n':
if (jflag)
@@ -278,29 +294,38 @@ reswitch:
goto reswitch;
case 'r':
base = radix;
if (sign)
if (sign) {
goto handle_sign;
}
goto handle_nosign;
case 's':
p = va_arg(ap, char *);
if (p == NULL)
if (p == NULL) {
p = "(null)";
if (!dot)
}
if (!dot) {
n = strlen(p);
else
for (n = 0; n < dwidth && p[n]; n++)
continue;
} else {
for (n = 0; n < dwidth && p[n]; n++) {};
}
width -= n;
if (!ladjust && width > 0)
while (width--)
if (!ladjust && width > 0) {
while (width--) {
PCHAR(padc);
while (n--)
}
}
while (n--) {
PCHAR(*p++);
if (ladjust && width > 0)
while (width--)
}
if (ladjust && width > 0) {
while (width--) {
PCHAR(padc);
}
}
break;
case 't':
tflag = 1;
@@ -361,22 +386,31 @@ number:
neg = 1;
num = -(intmax_t)num;
}
p = ksprintn(nbuf, num, base, &tmp, upper);
if (sharpflag && num != 0) {
if (base == 8)
tmp++;
else if (base == 16)
tmp += 2;
}
if (neg)
tmp++;
if (!ladjust && padc != '0' && width
&& (width -= tmp) > 0)
while (width--)
p = ksprintn(nbuf, num, base, &tmp, upper);
if (sharpflag && num != 0) {
if (base == 8) {
tmp++;
} else if (base == 16) {
tmp += 2;
}
}
if (neg) {
tmp++;
}
if (!ladjust && padc != '0' && width && (width -= tmp) > 0) {
while (width--) {
PCHAR(padc);
if (neg)
}
}
if (neg) {
PCHAR('-');
}
if (sharpflag && num != 0) {
if (base == 8) {
PCHAR('0');
@@ -385,21 +419,28 @@ number:
PCHAR('x');
}
}
if (!ladjust && width && (width -= tmp) > 0)
while (width--)
PCHAR(padc);
while (*p)
if (!ladjust && width && (width -= tmp) > 0) {
while (width--) {
PCHAR(padc);
}
}
while (*p) {
PCHAR(*p--);
}
if (ladjust && width && (width -= tmp) > 0)
while (width--)
if (ladjust && width && (width -= tmp) > 0) {
while (width--) {
PCHAR(padc);
}
}
break;
default:
while (percent < fmt)
while (percent < fmt) {
PCHAR(*percent++);
}
/*
* Since we ignore an formatting argument it is no
* longer safe to obey the remaining formatting
+13 -5
View File
@@ -639,24 +639,32 @@ void rdv40_spiffs_safe_print_tree(void) {
struct spiffs_dirent e;
struct spiffs_dirent *pe = &e;
char *resolvedlink = (char *)BigBuf_calloc(11 + SPIFFS_OBJ_NAME_LEN);
char *linkdest = (char *)BigBuf_calloc(SPIFFS_OBJ_NAME_LEN);
bool printed = false;
SPIFFS_opendir(&fs, "/", &d);
while ((pe = SPIFFS_readdir(&d, pe))) {
char resolvedlink[11 + SPIFFS_OBJ_NAME_LEN];
memset(resolvedlink, 0, sizeof(resolvedlink));
if (rdv40_spiffs_is_symlink((const char *)pe->name)) {
char linkdest[SPIFFS_OBJ_NAME_LEN];
read_from_spiffs((char *)pe->name, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN);
sprintf(resolvedlink, "(.lnk) --> %s", linkdest);
// Kind of stripping the .lnk extension
strtok((char *)pe->name, ".");
} else {
memset(resolvedlink, 0, sizeof(resolvedlink));
}
Dbprintf("[%04x]\t " _YELLOW_("%i") " B |-- %s%s", pe->obj_id, pe->size, pe->name, resolvedlink);
Dbprintf("[%04x] " _YELLOW_("%5i") " B |-- %s%s", pe->obj_id, pe->size, pe->name, resolvedlink);
printed = true;
}
if (printed == false) {
DbpString("<empty>");
}
SPIFFS_closedir(&d);
rdv40_spiffs_lazy_mount_rollback(changed);
BigBuf_free();
}
void rdv40_spiffs_safe_wipe(void) {
+1 -1
View File
@@ -85,7 +85,7 @@ static size_t us_rxfifo_high = 0;
static void usart_fill_rxfifo(void) {
uint16_t rxfifo_free = 0;
uint16_t rxfifo_free;
if (pUS1->US_RNCR == 0) { // One buffer got filled, backup buffer being used
+61 -18
View File
@@ -31,67 +31,110 @@ size_t nbytes(size_t nbits) {
}
//convert hex digit to integer
uint8_t hex2int(char hexchar) {
switch (hexchar) {
uint8_t hex2int(char x) {
switch (x) {
case '0':
return 0;
break;
case '1':
return 1;
break;
case '2':
return 2;
break;
case '3':
return 3;
break;
case '4':
return 4;
break;
case '5':
return 5;
break;
case '6':
return 6;
break;
case '7':
return 7;
break;
case '8':
return 8;
break;
case '9':
return 9;
break;
case 'a':
case 'A':
return 10;
break;
case 'b':
case 'B':
return 11;
break;
case 'c':
case 'C':
return 12;
break;
case 'd':
case 'D':
return 13;
break;
case 'e':
case 'E':
return 14;
break;
case 'f':
case 'F':
return 15;
break;
default:
return 0;
}
}
/*
The following methods comes from Rfidler sourcecode.
https://github.com/ApertureLabsLtd/RFIDler/blob/master/firmware/Pic32/RFIDler.X/src/
*/
// convert hex to sequence of 0/1 bit values
// returns number of bits converted
int hex2binarray(char *target, char *source) {
return hex2binarray_n(target, source, strlen(source));
}
int hex2binarray_n(char *target, const char *source, int sourcelen) {
int count = 0;
// process 4 bits (1 hex digit) at a time
while (sourcelen--) {
char x = *(source++);
*(target++) = (x >> 7) & 1;
*(target++) = (x >> 6) & 1;
*(target++) = (x >> 5) & 1;
*(target++) = (x >> 4) & 1;
*(target++) = (x >> 3) & 1;
*(target++) = (x >> 2) & 1;
*(target++) = (x >> 1) & 1;
*(target++) = (x & 1);
count += 8;
}
return count;
}
int binarray2hex(const uint8_t *bs, int bs_len, uint8_t *hex) {
int count = 0;
int byte_index = 0;
// Clear output buffer
memset(hex, 0, bs_len >> 3);
for (int i = 0; i < bs_len; i++) {
// Set the appropriate bit in hex
if (bs[i] == 1) {
hex[byte_index] |= (1 << (7 - (count % 8)));
}
count++;
// Move to the next byte if 8 bits have been filled
if (count % 8 == 0) {
byte_index++;
}
}
return count;
}
void LEDsoff(void) {
LED_A_OFF();
LED_B_OFF();
+4 -16
View File
@@ -68,21 +68,6 @@
#define BUTTON_DOUBLE_CLICK -2
#define BUTTON_ERROR -99
#ifndef REV8
#define REV8(x) ((((x)>>7)&1)+((((x)>>6)&1)<<1)+((((x)>>5)&1)<<2)+((((x)>>4)&1)<<3)+((((x)>>3)&1)<<4)+((((x)>>2)&1)<<5)+((((x)>>1)&1)<<6)+(((x)&1)<<7))
#endif
#ifndef REV16
#define REV16(x) (REV8(x) + (REV8 ((x) >> 8) << 8))
#endif
#ifndef REV32
#define REV32(x) (REV16(x) + (REV16((x) >> 16) << 16))
#endif
#ifndef REV64
#define REV64(x) (REV32(x) + ((uint64_t)(REV32((x) >> 32) << 32)))
#endif
#ifndef BIT32
#define BIT32(x,n) ((((x)[(n)>>5])>>((n)))&1)
@@ -97,8 +82,11 @@
#endif
size_t nbytes(size_t nbits);
uint8_t hex2int(char x);
uint8_t hex2int(char hexchar);
int hex2binarray(char *target, char *source);
int hex2binarray_n(char *target, const char *source, int sourcelen);
int binarray2hex(const uint8_t *bs, int bs_len, uint8_t *hex);
void LED(int led, int ms);
void LEDsoff(void);
+2 -2
View File
@@ -296,9 +296,9 @@ static void UsbPacketReceived(uint8_t *packet) {
}
// delay_loop(1) = 3.07us
static volatile uint32_t c;
static volatile uint32_t ccc;
static void __attribute__((optimize("O0"))) delay_loop(uint32_t delay) {
for (c = delay * 2; c; c--) {};
for (ccc = delay * 2; ccc; ccc--) {};
}
static void flash_mode(void) {
+10 -5
View File
@@ -45,6 +45,7 @@ endif()
find_package(PkgConfig)
if (NOT SKIPQT EQUAL 1)
if(APPLE AND EXISTS /usr/local/opt/qt5)
# Homebrew installs Qt5 (up to at least 5.11.0) in
# /usr/local/opt/qt5. Ensure that it can be found by CMake
@@ -55,16 +56,17 @@ if (NOT SKIPQT EQUAL 1)
# e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5)
endif(APPLE AND EXISTS /usr/local/opt/qt5)
if(APPLE AND EXISTS /opt/homebrew/opt/qt5)
if(APPLE AND EXISTS /opt/homebrew/opt/qt@5)
# Homebrew on Apple Silicon installs Qt5 in
# /opt/homebrew/opt/qt5. Ensure that it can be found by CMake
# /opt/homebrew/opt/qt@5. Ensure that it can be found by CMake
# since it is not in the default /usr/local prefix.
# Add it to PATHS so that it doesn't override the
# CMAKE_PREFIX_PATH environment variable.
# QT_FIND_PACKAGE_OPTIONS should be passed to find_package,
# e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /opt/homebrew/opt/qt5)
endif(APPLE AND EXISTS /opt/homebrew/opt/qt5)
list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /opt/homebrew/opt/qt@5)
endif(APPLE AND EXISTS /opt/homebrew/opt/qt@5)
set(QT_PACKAGELIST
Qt5Core
Qt5Widgets
@@ -261,6 +263,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/common/cardhelper.c
${PM3_ROOT}/common/generator.c
${PM3_ROOT}/common/bruteforce.c
${PM3_ROOT}/common/hitag2/hitag2_crypto.c
${PM3_ROOT}/client/src/crypto/asn1dump.c
${PM3_ROOT}/client/src/crypto/asn1utils.c
${PM3_ROOT}/client/src/crypto/libpcrypto.c
@@ -454,7 +457,6 @@ if (APPLE)
message(STATUS "AppKit.framework found! ${APPKIT_LIBRARY}")
set(ADDITIONAL_LNK "-framework Foundation" "-framework AppKit")
endif()
endif (APPLE)
if ((NOT SKIPQT EQUAL 1) AND (Qt5_FOUND))
@@ -732,6 +734,9 @@ target_include_directories(proxmark3 PRIVATE
if (NOT APPLE)
# required for Raspberry Pi, but breaks with clang (OSX). Need to be at the end of the linker line.
set(ADDITIONAL_LNK ${ADDITIONAL_LNK} -Wl,--as-needed -latomic -Wl,--no-as-needed)
else (NOT APPLE)
#set_property(TARGET proxmark3 PROPERTY LINK_FLAGS "-Wl,-undefined dynamic_lookup")
set(ADDITIONAL_LNK ${ADDITIONAL_LNK} -Wl,-undefined,dynamic_lookup)
endif (NOT APPLE)
if (NOT JANSSON_FOUND)
+7 -6
View File
@@ -37,7 +37,7 @@ OBJDIR = obj
ifeq ($(USE_BREW),1)
INCLUDES += -I$(BREW_PREFIX)/include
LDLIBS += -L$(BREW_PREFIX)/lib
PKG_CONFIG_ENV := PKG_CONFIG_PATH=$(BREW_PREFIX)/lib/pkgconfig:$(BREW_PREFIX)/opt/qt/lib/pkgconfig:$(BREW_PREFIX)/opt/qt5/lib/pkgconfig
PKG_CONFIG_ENV := PKG_CONFIG_PATH=$(BREW_PREFIX)/lib/pkgconfig:$(BREW_PREFIX)/opt/qt@5/lib/pkgconfig:$(BREW_PREFIX)/opt/qt@5/lib/pkgconfig
endif
ifeq ($(USE_MACPORTS),1)
@@ -281,16 +281,16 @@ endif
## Python3 (optional)
ifneq ($(SKIPPYTHON),1)
PYTHONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags python3 2>/dev/null)
PYTHONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs python3 2>/dev/null)
# since python3.8, applications willing to embed python must use -embed:
PYTHONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags python3-embed 2>/dev/null)
PYTHONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs python3-embed 2>/dev/null)
ifneq ($(PYTHONLDLIBS),)
PYTHONLIBLD = $(PYTHONLDLIBS)
PYTHONLIBINC = $(subst -I,-isystem ,$(PYTHONINCLUDES))
PYTHON_FOUND = 1
else
# since python3.8, applications willing to embed python must use -embed:
PYTHONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags python3-embed 2>/dev/null)
PYTHONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs python3-embed 2>/dev/null)
PYTHONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags python3 2>/dev/null)
PYTHONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs python3 2>/dev/null)
ifneq ($(PYTHONLDLIBS),)
PYTHONLIBLD = $(PYTHONLDLIBS)
PYTHONLIBINC = $(subst -I,-isystem ,$(PYTHONINCLUDES))
@@ -771,6 +771,7 @@ SRCS += bucketsort.c \
crc32.c \
crc64.c \
commonutil.c \
hitag2/hitag2_crypto.c \
iso15693tools.c \
legic_prng.c \
lfdemod.c \
+7 -2
View File
@@ -54,7 +54,7 @@ typedef int (*get_func)(void *data);
typedef struct {
get_func get;
void *data;
char buffer[5];
char buffer[7];
size_t buffer_pos;
int state;
int line;
@@ -179,11 +179,16 @@ static int stream_get(stream_t *stream, json_error_t *error) {
size_t i, count;
count = utf8_check_first(c);
if (!count)
if (count == 0) {
goto out;
}
// whatif count == 1 ?!?
assert(count >= 2);
assert(count <= 4);
// if count == 4 , i will become 5 and overflow.
for (i = 1; i < count; i++)
stream->buffer[i] = stream->get(stream->data);
+18 -6
View File
@@ -1,13 +1,25 @@
#
# Mifare Default Keys
# -- Iceman version --
# -- contribute to this list, sharing is caring --
#
# Lets see how long it takes before other project takes this file
# and claim they created it.
#
# factory HT2 pwd
4D494B52
# factory HT2 crypto key
4F4E4D494B52
#
# GE HT2 reader
#
# TSPL
5453504C
05040202
25293C2F
# Gone in 360 seconds
FFFF814632FF
#
# Paxton HT2
BDF5E846
#
#
# GE HT2 reader
# TSPL
5453504C
05040202
25293C2F
+36 -4
View File
@@ -307,7 +307,7 @@ E3429281EFC1
# EPI Envisionte
AAFB06045877
#
# gym
# Gyms / Fitness Clubs / Health Clubs / Wellness Centres
#
# Fysiken A
3E65E4FB65B3
@@ -318,8 +318,8 @@ AAFB06045877
#
# https://mattionline.de/fitnessstudio-armband-reverse-engineering/
# https://mattionline.de/milazycracker/
# gym wistband A, same as Fysiken A
# gym wistband B
# Gym Wristband A - Same as Fysiken A
# Gym Wristband B
81CC25EBBB6A
195DC63DB3A3
#
@@ -330,9 +330,13 @@ A05DBD98E0FC
AA4DDA458EBB
EAB8066C7479
#
# Nordic Wellness A, same as Fysiken A
# Nordic Wellness A - Same as Fysiken A
# Nordic Wellness B
E5519E1CC92B
#
# Jett's 24 Hour Fitness S0 KA/B
# 049979614077
# 829338771705
#
# Hotel KeyCard
D3B595E9DD63
@@ -1110,6 +1114,14 @@ EA0FD73CB149
FC0001877BF7
FD8705E721B0
00ADA2CD516D
518108E061E2
558AAD64EB5B
001122334455
6CA761AB6CA7
B1C4A8F7F6E3
FF75AFDA5A3C
FCDDF7767C10
A6B3F6C8F1D4
#
#
237A4D0D9119
@@ -2417,3 +2429,23 @@ EC2B9FD483CA
# Hotel Intelier Orange - Benicasim, Spain
# block 1 - key A
04256CFE0425
# InsideWash Membership Card - Portugal
C18063858BB9
# Universidade de São Paulo (USP) student card
17B50E38F1B0
24E311F594CE
3794FBFB1A54
43B229069F6A
4531952F765F
4943F2F35E0A
4985E681EF88
4F56C88E0337
710070E92C79
8A036C5C35D4
A027BD830A06
D33673C19243
D89A506542F2
E5813CD228F1
FAB943906E9C
+12 -5
View File
@@ -46,6 +46,7 @@ endif()
find_package(PkgConfig)
if (NOT SKIPQT EQUAL 1)
if(APPLE AND EXISTS /usr/local/opt/qt5)
# Homebrew installs Qt5 (up to at least 5.11.0) in
# /usr/local/opt/qt5. Ensure that it can be found by CMake
@@ -56,16 +57,17 @@ if (NOT SKIPQT EQUAL 1)
# e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /usr/local/opt/qt5)
endif(APPLE AND EXISTS /usr/local/opt/qt5)
if(APPLE AND EXISTS /opt/homebrew/opt/qt5)
if(APPLE AND EXISTS /opt/homebrew/opt/qt@5)
# Homebrew on Apple Silicon installs Qt5 in
# /opt/homebrew/opt/qt5. Ensure that it can be found by CMake
# /opt/homebrew/opt/qt@5. Ensure that it can be found by CMake
# since it is not in the default /usr/local prefix.
# Add it to PATHS so that it doesn't override the
# CMAKE_PREFIX_PATH environment variable.
# QT_FIND_PACKAGE_OPTIONS should be passed to find_package,
# e.g. find_package(Qt5Core ${QT_FIND_PACKAGE_OPTIONS})
list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /opt/homebrew/opt/qt5)
endif(APPLE AND EXISTS /opt/homebrew/opt/qt5)
list(APPEND QT_FIND_PACKAGE_OPTIONS PATHS /opt/homebrew/opt/qt@5)
endif(APPLE AND EXISTS /opt/homebrew/opt/qt@5)
set(QT_PACKAGELIST
Qt5Core
Qt5Widgets
@@ -262,6 +264,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/common/cardhelper.c
${PM3_ROOT}/common/generator.c
${PM3_ROOT}/common/bruteforce.c
${PM3_ROOT}/common/hitag2/hitag2_crypto.c
${PM3_ROOT}/client/src/crypto/asn1dump.c
${PM3_ROOT}/client/src/crypto/asn1utils.c
${PM3_ROOT}/client/src/crypto/libpcrypto.c
@@ -455,7 +458,6 @@ if (APPLE)
message(STATUS "AppKit.framework found! ${APPKIT_LIBRARY}")
set(ADDITIONAL_LNK "-framework Foundation" "-framework AppKit")
endif()
endif (APPLE)
if ((NOT SKIPQT EQUAL 1) AND (Qt5_FOUND))
@@ -675,6 +677,8 @@ if (NOT SKIPPYTHON EQUAL 1)
endif (NOT SKIPPYTHON EQUAL 1)
message(STATUS "===================================================================")
add_definitions(-DHAVE_SNPRINTF)
add_library(pm3rrg_rdv4 SHARED
${PM3_ROOT}/client/src/proxmark3.c
${TARGET_SOURCES}
@@ -733,6 +737,9 @@ target_include_directories(pm3rrg_rdv4 PRIVATE
if (NOT APPLE)
# required for Raspberry Pi, but breaks with clang (OSX). Need to be at the end of the linker line.
set(ADDITIONAL_LNK ${ADDITIONAL_LNK} -Wl,--as-needed -latomic -Wl,--no-as-needed)
else (NOT APPLE)
#set_property(TARGET proxmark3 PROPERTY LINK_FLAGS "-Wl,-undefined dynamic_lookup")
set(ADDITIONAL_LNK ${ADDITIONAL_LNK} -Wl,-undefined,dynamic_lookup)
endif (NOT APPLE)
if (NOT JANSSON_FOUND)
+10 -11
View File
@@ -167,12 +167,11 @@ local function help()
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
end
-- read LEGIC data
local function readlegicdata(offset, len, iv)
-- read LEGIC info
local function readlegicinfo()
-- Read data
local d0 = ('%04X%04X%02X'):format(offset, len, iv)
local c = Command:newNG{cmd = cmds.CMD_HF_LEGIC_READER, data = d0}
local result, err = c:sendNG()
local c = Command:newNG{cmd = cmds.CMD_HF_LEGIC_INFO, data = nil}
local result, err = c:sendNG(false, 2000)
if not result then return oops(err) end
-- result is a packed data structure, data starts at offset 33
return result
@@ -404,15 +403,15 @@ local function writeToTag(plainBytes)
return
end
readbytes = readlegicdata(0, 4, 0x55)
readbytes = readlegicinfo()
-- gather MCD & MSN from new Tag - this must be enterd manually
print("\nthese are the MCD MSN0 MSN1 MSN2 from the Tag that has being read:")
-- readbytes is a usbcommandOLD package, hence 32 bytes offset until data.
plainBytes[1] = ('%02x'):format(readbytes:byte(33))
plainBytes[2] = ('%02x'):format(readbytes:byte(34))
plainBytes[3] = ('%02x'):format(readbytes:byte(35))
plainBytes[4] = ('%02x'):format(readbytes:byte(36))
-- readbytes is a table with uid data as hex string in Data key
plainBytes[1] = readbytes.Data:sub(1,2)
plainBytes[2] = readbytes.Data:sub(3,4)
plainBytes[3] = readbytes.Data:sub(5,6)
plainBytes[4] = readbytes.Data:sub(7,8)
MCD = plainBytes[1]
MSN0 = plainBytes[2]
+1 -1
View File
@@ -38,7 +38,7 @@ example = [[
]]
usage = [[
script run hf_mfu_easywrite -h -k <passwd> -c -w -u <uid> -t <type> -p <passwd> -a <pack> -s <signature> -o <otp> -v <version>
script run hf_mfu_magicwrite -h -k <passwd> -c -w -u <uid> -t <type> -p <passwd> -a <pack> -s <signature> -o <otp> -v <version>
]]
arguments = [[
-h this help
+128
View File
@@ -0,0 +1,128 @@
local getopt = require('getopt')
copyright = ''
author = "TheChamp669"
version = 'v1.0.0'
desc = [[
Perform bulk enrollment of 26 bit AWID style RFID Tags
For more info, check the comments in the code
]]
example = [[
--
script run lf_awid_bulkclone.lua -f 1 -b 1000
]]
usage = [[
script run lf_awid_bulkclone.lua -f facility -b base_id_num
]]
arguments = [[
-h : this help
-f : facility id
-b : starting card id
]]
local DEBUG = true
---
-- A debug printout-function
local function dbg(args)
if not DEBUG then return end
if type(args) == 'table' then
local i = 1
while args[i] do
dbg(args[i])
i = i+1
end
else
print('###', args)
end
end
---
-- This is only meant to be used when errors occur
local function oops(err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, errr
end
---
-- Usage help
local function help()
print(copyright)
print(author)
print(version)
print(desc)
print(ansicolors.cyan..'Usage'..ansicolors.reset)
print(usage)
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
print(arguments)
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
end
---
-- Exit message
local function exitMsg(msg)
print( string.rep('--',20) )
print( string.rep('--',20) )
print(msg)
print()
end
local function showHelp()
print("Usage: script run <scriptname> [-h]")
print("Options:")
print("-h \t This help")
end
local function main(args)
print( string.rep('--',20) )
print( string.rep('--',20) )
print()
if #args == 0 then return help() end
for o, a in getopt.getopt(args, 'f:b:c:h') do
if o == 'h' then return help() end
if o == 'f' then
if isempty(a) then
print('You did not supply a facility code, using 255')
fc = 255
else
fc = a
end
end
if o == 'b' then
if isempty(a) then
print('You did not supply a starting card number, using 59615')
cn = 59615
else
cn = a
end
end
end
-- Example starting values
local sessionStart = os.date("%Y_%m_%d_%H_%M_%S") -- Capture the session start time
print("Session Start: " .. sessionStart)
print("Facility Code,Card Number")
while true do
print(string.format("Preparing to Write: Facility Code %d, Card Number %d", fc, cn))
local command = string.format("lf awid clone --fmt 26 --fc %d --cn %d", fc, cn)
core.console(command)
print(string.format("%d,%d", fc, cn))
print("Press Enter to continue with the next card number or type 'q' and press Enter to quit.")
local user_input = io.read()
if user_input:lower() == 'q' then
break
else
cn = cn + 1
end
end
end
main(args)
+130
View File
@@ -0,0 +1,130 @@
local getopt = require('getopt')
local cmds = require('commands')
copyright = ''
author = "TheChamop669"
version = 'v1.0.0'
desc = [[
Perform bulk enrollment of 26 bit H10301 style RFID Tags
For more info, check the comments in the code
]]
example = [[
--
script run lf_hid_bulkclone_v2.lua -f 1 -b 1000
]]
usage = [[
script run lf_hid_bulkclone_v2.lua -f facility -b base_id_num
]]
arguments = [[
-h : this help
-f : facility id
-b : starting card id
]]
local DEBUG = true
---
-- A debug printout-function
local function dbg(args)
if not DEBUG then return end
if type(args) == 'table' then
local i = 1
while args[i] do
dbg(args[i])
i = i+1
end
else
print('###', args)
end
end
---
-- This is only meant to be used when errors occur
local function oops(err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, errr
end
---
-- Usage help
local function help()
print(copyright)
print(author)
print(version)
print(desc)
print(ansicolors.cyan..'Usage'..ansicolors.reset)
print(usage)
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
print(arguments)
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
end
---
-- Exit message
local function exitMsg(msg)
print( string.rep('--',20) )
print( string.rep('--',20) )
print(msg)
print()
end
local function main(args)
print( string.rep('--',20) )
print( string.rep('--',20) )
print()
if #args == 0 then return help() end
for o, a in getopt.getopt(args, 'f:b:h') do
if o == 'h' then return help() end
if o == 'f' then
if isempty(a) then
print('You did not supply a facility code, using 0')
fc = 10
else
fc = a
end
end
if o == 'b' then
if isempty(a) then
print('You did not supply a starting card number, using 1000')
cn = 1000
else
cn = a
end
end
end
local successful_writes = {}
local timestamp = os.date('%Y-%m-%d %H:%M:%S', os.time())
while true do
print(string.format("Writing Facility Code: %d, Card Number: %d", fc, cn))
local command = string.format("lf hid clone -w H10301 --fc %d --cn %d", fc, cn)
core.console(command)
table.insert(successful_writes, string.format("%d,%d", fc, cn))
print("Press Enter to write the next card, type 'r' and press Enter to retry, or type 'q' and press Enter to quit.")
local user_input = io.read()
if user_input:lower() == 'q' then
print("Timestamp: ", timestamp)
print("Successful Writes:")
for _, v in ipairs(successful_writes) do print(v) end
break
elseif user_input:lower() ~= 'r' then
cn = cn + 1
end
end
end
main(args)
--[[
Notes:
1. The `lf hid clone` command is used to write HID formatted data to T5577 cards, using the H10301 format.
2. The script prompts the user for the initial facility code and card number at the start of the session.
3. Users can continue to write to the next card, retry the current write, or quit the session by responding to the prompts.
4. Upon quitting, the script prints all successful writes along with a timestamp.
5. Password-related features have been removed in this version of the script as they are not supported by the `lf hid clone` command.
]]
+125
View File
@@ -0,0 +1,125 @@
local getopt = require('getopt')
local cmds = require('commands')
copyright = ''
author = "TheChamp669"
version = 'v1.0.0'
desc = [[
Perform bulk enrollment of 26 bit IO Prox / Kantech style RFID Tags
The vnc is set to 2.
For more info, check the comments in the code
]]
example = [[
--
script run lf_ioprox_bulkclone.lua -f 1 -b 1000
]]
usage = [[
script run lf_ioprox_bulkclone.lua -f facility -b base_id_num
]]
arguments = [[
-h : this help
-f : facility id
-b : starting card id
]]
local DEBUG = true
---
-- A debug printout-function
local function dbg(args)
if not DEBUG then return end
if type(args) == 'table' then
local i = 1
while args[i] do
dbg(args[i])
i = i+1
end
else
print('###', args)
end
end
---
-- This is only meant to be used when errors occur
local function oops(err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, errr
end
---
-- Usage help
local function help()
print(copyright)
print(author)
print(version)
print(desc)
print(ansicolors.cyan..'Usage'..ansicolors.reset)
print(usage)
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
print(arguments)
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
end
---
-- Exit message
local function exitMsg(msg)
print( string.rep('--',20) )
print( string.rep('--',20) )
print(msg)
print()
end
local function main(args)
print( string.rep('--',20) )
print( string.rep('--',20) )
print()
if #args == 0 then return help() end
for o, a in getopt.getopt(args, 'f:b:h') do
if o == 'h' then return help() end
if o == 'f' then
if isempty(a) then
print('You did not supply a facility code, using 0')
fc = 0
else
fc = a
end
end
if o == 'b' then
if isempty(a) then return oops('You must supply the flag -b (starting card number)') end
cn = a
end
end
local successful_writes = {}
local timestamp = os.date('%Y-%m-%d %H:%M:%S', os.time())
while true do
print(string.format("Setting fob to Facility Code: %d, Card Number: %d", fc, cn))
-- Writing to block 0 with the specific data for ioProx card format
core.console("lf t55xx write -b 0 -d 00147040")
-- Command to set facility code and card number on the fob
local command = string.format("lf io clone --vn 2 --fc %d --cn %d", fc, cn)
core.console(command)
table.insert(successful_writes, string.format("%d,%d", fc, cn))
print("Fob created successfully.")
print("Press Enter to create the next fob, type 'r' and press Enter to retry, or type 'q' and press Enter to quit.")
local user_input = io.read()
if user_input:lower() == 'q' then
print("Timestamp: ", timestamp)
print("Successful Writes:")
for _, v in ipairs(successful_writes) do print(v) end
break
elseif user_input:lower() ~= 'r' then
cn = cn + 1
end
end
end
main(args)
+4
View File
@@ -67,6 +67,9 @@ FRA_OrganizationalAuthority_Contract_Provider = {
0x021: {
1: 'Bordeaux (TBM / Keolis)',
},
0x057: {
1: 'Lyon (TCL / Keolis)',
},
0x072: {
1: 'Tours (filbleu / Keolis)',
},
@@ -84,6 +87,7 @@ FRA_OrganizationalAuthority_Contract_Provider = {
},
0x908: {
1: 'Rennes (STAR / Keolis)',
8: 'Saint-Malo (MAT / RATP)',
},
0x911: {
5: 'Besançon (Ginko / Keolis)',
+28 -4
View File
@@ -362,10 +362,10 @@
},
{
"AID": "554E49",
"Vendor": "University of Ljubljana",
"Vendor": "Slovenian Universities",
"Country": "SI",
"Name": "University of Ljubljana Student ID",
"Description": "",
"Name": "Slovenian University Student ID",
"Description": "Issued by University of Ljubljana, Maribor and Primorska",
"Type": "student"
},
{
@@ -559,5 +559,29 @@
"Name": "SALTO Access credential",
"Description": "",
"Type": "pacs"
},
{
"AID": "4791DA",
"Vendor": "Prima Systems",
"Country": "SI",
"Name": "Prima FlexAir Access Control",
"Description": "FIDs: 00 - DRM, 01 - Access Event Log, 04 - Access Permissions",
"Type": "pacs"
},
{
"AID": "FF30FF",
"Vendor": "Metrolinx",
"Country": "CA",
"Name": "Presto Card",
"Description": "",
"Type": "transport"
},
{
"AID": "002000",
"Vendor": "Metrolinx",
"Country": "CA",
"Name": "Presto Card",
"Description": "",
"Type": "transport"
}
]
]
+42 -2
View File
@@ -2284,7 +2284,7 @@
"Vendor": "Apple",
"Country": "",
"Name": "Apple Home Key Framework",
"Description": "Home Key configuration applet. Selected after a first transaction on a newely-invited device (allegedly for mailbox sync/attestation exchange)",
"Description": "Home Key configuration applet. Used for attestation exchange",
"Type": ""
},
{
@@ -2292,7 +2292,39 @@
"Vendor": "Apple",
"Country": "",
"Name": "Apple Home Key",
"Description": "NFC Home Key for select HomeKit-compatible locks",
"Description": "NFC Home Key for select HomeKit-compatible locks based on Apple UnifiedAccess protocol",
"Type": "access"
},
{
"AID": "A0000008580202",
"Vendor": "Apple",
"Country": "",
"Name": "Apple Access Key Framework",
"Description": "Access Key configuration applet. Used for attestation exchange",
"Type": ""
},
{
"AID": "A0000008580201",
"Vendor": "Apple",
"Country": "",
"Name": "Apple Access Key",
"Description": "NFC Access Key for commercial properties based on Apple UnifiedAccess protocol",
"Type": "access"
},
{
"AID": "A000000909ACCE5502",
"Vendor": "Connectivity Standards Alliance (CSA)",
"Country": "",
"Name": "Aliro Framework",
"Description": "Used during key provisioning, configuration, attestation exchange",
"Type": ""
},
{
"AID": "A000000909ACCE5501",
"Vendor": "Connectivity Standards Alliance (CSA)",
"Country": "",
"Name": "Aliro",
"Description": "",
"Type": "access"
},
{
@@ -2430,5 +2462,13 @@
"Name": "CEPAS",
"Description": "Transit and e-money card used in Singapore",
"Type": "transport"
},
{
"AID": "A0000004040125",
"Vendor": "Ile-de-France Mobilites",
"Country": "France",
"Name": "Navigo",
"Description": "CALYPSO-based transit card",
"Type": "transport"
}
]
+126
View File
@@ -0,0 +1,126 @@
{
"versions": {
"01": {
"tci": {
"000000": {
"id": "tci-vas-or-pay",
"name": "VAS or payment",
"description": "Used when a reader needs a pass or a payment card. Sometimes called VAS over Payment"
},
"000001": {
"id": "tci-vas-and-pay",
"name": "VAS and payment",
"description": "Also called single tap mode. Allows reading multiple passes with different ids in one tap"
},
"000002": {
"id": "tci-vas-only",
"name": "VAS only",
"description": "Used when a reader requests passes only"
},
"000003": {
"id": "tci-pay-only",
"name": "VAS only",
"description": "Used when a reader requests payment cards only. Also disables express mode for chinese transit cards"
},
"cf0000": {
"id": "tci-ignore",
"name": "Ignore",
"description": "iPhones before IOS17 emit this frame so that other apple devices don't react to the field"
}
}
},
"02": {
"types": {
"01": {
"id": "terminal-type-transit",
"name": "Transit",
"description": "Used by express-mode enabled transit terminals",
"subtypes": {
"00": {
"id": "terminal-subtype-default",
"name": "Default subtype",
"description": "",
"tci": {
"030400": {
"id": "tci-hop-fastpass",
"name": "HOP Fastpass",
"description": ""
},
"030002": {
"id": "tci-transit-for-london",
"name": "TFL",
"description": "First publically known TCI, found by Proxmark community member"
},
"030001": {
"id": "tci-wmata",
"name": "SmartTrip",
"description": ""
},
"030005": {
"id": "tci-la-tapp",
"name": "LA Tap",
"description": ""
},
"030007": {
"id": "tci-clipper",
"name": "Clipper",
"description": ""
},
"03095a": {
"id": "tci-navigo",
"name": "Navigo",
"description": ""
}
},
"data": {
"length": 5,
"name": "Fallback EMV payment networks",
"description": "Bit mask of allowed EMV open loop payment cards. First byte is responsible for most popular payment networks"
}
}
}
},
"02": {
"id": "terminal-type-access",
"name": "Access",
"description": "Used by express-mode enabled access and key readers",
"subtypes": {
"00": {
"id": "terminal-subtype-venue",
"name": "Venue",
"description": "Used by following venues: Offices, Parks, Universities",
"tci": {
"no-info-add-if-found": ""
}
},
"06": {
"id": "terminal-subtype-home-key",
"name": "Home Key",
"description": "Used by home key",
"tci": {
"021100": {
"id": "tci-homekey",
"name": "Home Key",
"description": ""
}
}
},
"09": {
"id": "terminal-subtype-automotive-pairing",
"name": "Automotive",
"description": "Used by cars for access and setup",
"tci": {
"no-info-add-if-found": ""
}
}
}
}
}
}
}
}
+5
View File
@@ -55,6 +55,11 @@
"name": "Transit: Clipper",
"description": ""
},
{
"value": "6a02c8010003095a0000000000",
"name": "Transit: Navigo",
"description": ""
},
{
"value": "6a02c3020002ffff",
+9 -46
View File
@@ -40,11 +40,7 @@ static bool TestKVV(void) {
bool res = memcmp(KeyKvv, kvv, CIPURSE_KVV_LENGTH) == 0;
if (res)
PrintAndLogEx(INFO, "kvv.............. " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "kvv.............. " _RED_("fail"));
PrintAndLogEx(SUCCESS, "kvv.............. ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
@@ -58,11 +54,7 @@ static bool TestISO9797M2(void) {
res = res && (FindISO9797M2PaddingDataLen(data, ddatalen) == 4);
if (res)
PrintAndLogEx(INFO, "ISO9797M2........ " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "ISO9797M2........ " _RED_("fail"));
PrintAndLogEx(SUCCESS, "ISO9797M2........ ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
@@ -92,11 +84,7 @@ static bool TestSMI(void) {
res = res && (CipurseCGetSMI(&ctx, false) == 0x88);
res = res && (CipurseCGetSMI(&ctx, true) == 0x89);
if (res)
PrintAndLogEx(INFO, "SMI.............. " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "SMI.............. " _RED_("fail"));
PrintAndLogEx(SUCCESS, "SMI.............. ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
@@ -115,15 +103,10 @@ static bool TestMIC(void) {
res = res && (CipurseCCheckMIC(TestData, 6, mic));
if (res)
PrintAndLogEx(INFO, "MIC.............. " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "MIC.............. " _RED_("fail"));
PrintAndLogEx(SUCCESS, "MIC.............. ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
static bool TestAuth(void) {
CipurseContext_t ctx = {0};
CipurseCClearContext(&ctx);
@@ -159,11 +142,7 @@ static bool TestAuth(void) {
uint8_t framekey[] = {0xCF, 0x6F, 0x3A, 0x47, 0xFC, 0xAC, 0x8D, 0x38, 0x25, 0x75, 0x8B, 0xFC, 0x8B, 0x61, 0x68, 0xF3};
res = res && (memcmp(ctx.frameKey, framekey, sizeof(framekey)) == 0);
if (res)
PrintAndLogEx(INFO, "Auth............. " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "Auth............. " _RED_("fail"));
PrintAndLogEx(SUCCESS, "Auth............. ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
@@ -211,11 +190,7 @@ static bool TestMAC(void) {
uint8_t framekey4[] = {0xA0, 0x65, 0x1A, 0x62, 0x56, 0x5D, 0xD7, 0xC9, 0x32, 0xAE, 0x1D, 0xE0, 0xCF, 0x8D, 0xC1, 0xB9};
res = res && (memcmp(ctx.frameKey, framekey4, sizeof(framekey4)) == 0);
if (res)
PrintAndLogEx(INFO, "channel MAC...... " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "channel MAC...... " _RED_("fail"));
PrintAndLogEx(SUCCESS, "channel MAC...... ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
@@ -259,11 +234,7 @@ static bool TestEncDec(void) {
res = res && (dstdatalen == 16);
res = res && (memcmp(dstdata, TestData, 16) == 0);
if (res)
PrintAndLogEx(INFO, "channel EncDec... " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "channel EncDec... " _RED_("fail"));
PrintAndLogEx(SUCCESS, "channel EncDec... ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
@@ -351,11 +322,7 @@ static bool TestAPDU(void) {
res = res && (memcmp(test6, dstdata, dstdatalen) == 0);
res = res && (sw == 0xccdd);
if (res)
PrintAndLogEx(INFO, "apdu............. " _GREEN_("passed"));
else
PrintAndLogEx(ERR, "apdu............. " _RED_("fail"));
PrintAndLogEx(SUCCESS, "apdu............. ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
return res;
}
@@ -374,11 +341,7 @@ bool CIPURSETest(bool verbose) {
res = res && TestAPDU();
PrintAndLogEx(INFO, "---------------------------");
if (res)
PrintAndLogEx(SUCCESS, " Tests [ %s ]", _GREEN_("ok"));
else
PrintAndLogEx(FAILED, " Tests [ %s ]", _RED_("fail"));
PrintAndLogEx(SUCCESS, "Tests ( %s )", (res) ? _GREEN_("ok") : _RED_("fail"));
PrintAndLogEx(NORMAL, "");
return res;
}
+17 -6
View File
@@ -435,6 +435,8 @@ static int CmdrevengSearch(const char *Cmd) {
return 0;
}
str_lower(inHexStr);
// try each model and get result
for (int i = 0; i < count; i++) {
/*if (found) {
@@ -479,16 +481,21 @@ static int CmdrevengSearch(const char *Cmd) {
ans = RunModel(Models[i], outHex, false, 0, result);
if (ans) {
str_lower(result);
// test for match
if (memcmp(result, inCRC, crcChars) == 0) {
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel: %s | value: %s\n", Models[i], result);
PrintAndLogEx(SUCCESS, "model... " _YELLOW_("%s"), Models[i]);
PrintAndLogEx(SUCCESS, "value... %s\n", result);
//optional - stop searching if found...
found = true;
} else {
if (crcChars > 2) {
char *swapEndian = SwapEndianStr(result, crcChars, crcChars);
if (memcmp(swapEndian, inCRC, crcChars) == 0) {
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel: %s | value endian swapped: %s\n", Models[i], swapEndian);
PrintAndLogEx(SUCCESS, "model... " _YELLOW_("%s"), Models[i]);
PrintAndLogEx(SUCCESS, "value endian swapped... %s\n", swapEndian);
// optional - stop searching if found...
found = true;
}
@@ -498,16 +505,20 @@ static int CmdrevengSearch(const char *Cmd) {
}
ans = RunModel(Models[i], outHex, true, 0, revResult);
if (ans) {
str_lower(revResult);
// test for match
if (memcmp(revResult, inCRC, crcChars) == 0) {
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel reversed: %s | value: %s\n", Models[i], revResult);
PrintAndLogEx(SUCCESS, "model reversed... " _YELLOW_("%s"), Models[i]);
PrintAndLogEx(SUCCESS, "value... %s\n", revResult);
// optional - stop searching if found...
found = true;
} else {
if (crcChars > 2) {
char *swapEndian = SwapEndianStr(revResult, crcChars, crcChars);
if (memcmp(swapEndian, inCRC, crcChars) == 0) {
PrintAndLogEx(SUCCESS, "\nfound possible match\nmodel reversed: %s | value endian swapped: %s\n", Models[i], swapEndian);
PrintAndLogEx(SUCCESS, "model reversed... " _YELLOW_("%s"), Models[i]);
PrintAndLogEx(SUCCESS, "value endian swapped... %s\n", swapEndian);
// optional - stop searching if found...
found = true;
}
@@ -520,9 +531,9 @@ static int CmdrevengSearch(const char *Cmd) {
free(Models[i]);
}
if (found == false)
if (found == false) {
PrintAndLogEx(FAILED, "\nno matches found\n");
}
return PM3_SUCCESS;
}
+435 -245
View File
File diff suppressed because it is too large. Load diff
-1
View File
@@ -81,7 +81,6 @@ int printDemodBuff(uint8_t offset, bool strip_leading, bool invert, bool print_h
void setDemodBuff(const uint8_t *buff, size_t size, size_t start_idx);
bool getDemodBuff(uint8_t *buff, size_t *size);
void save_restoreDB(uint8_t saveOpt);// option '1' to save g_DemodBuffer any other to restore
int AutoCorrelate(const int *in, int *out, size_t len, size_t window, bool SaveGrph, bool verbose);
int getSamples(uint32_t n, bool verbose);
+8 -3
View File
@@ -26,7 +26,7 @@
static int CmdHelp(const char *Cmd);
int flashmem_spiffs_load(char *destfn, uint8_t *data, size_t datalen) {
int flashmem_spiffs_load(const char *destfn, const uint8_t *data, size_t datalen) {
int ret_val = PM3_SUCCESS;
@@ -429,9 +429,14 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
PrintAndLogEx(HINT, "Use 'trace list -1 -t ...' to view, 'trace save -f ...' to save");
}
if (dlen) {
if (dlen || slen) {
// save to file
char fn[FILE_PATH_SIZE] = {0};
// prefer dest name
// else source name
if (dlen) {
strncpy(fn, dest, dlen);
} else {
@@ -439,7 +444,7 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
}
// set file extension
char *suffix = strchr(fn, '.');
const char *suffix = strchr(fn, '.');
if (suffix) {
saveFile(fn, suffix, dump, len);
} else {
+1 -1
View File
@@ -22,7 +22,7 @@
#include "common.h"
int CmdFlashMemSpiFFS(const char *Cmd);
int flashmem_spiffs_load(char *destfn, uint8_t *data, size_t datalen);
int flashmem_spiffs_load(const char *destfn, const uint8_t *data, size_t datalen);
int flashmem_spiffs_download(char *fn, uint8_t fnlen, void **pdest, size_t *destlen);
#endif
+14 -12
View File
@@ -95,6 +95,16 @@ int CmdHFSearch(const char *Cmd) {
}
}
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for Topaz tag...");
if (IfPm3Iso14443a()) {
if (readTopazUid(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n");
success[TOPAZ] = true;
res = PM3_SUCCESS;
}
}
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for LTO-CM tag...");
if (IfPm3Iso14443a()) {
@@ -119,7 +129,8 @@ int CmdHFSearch(const char *Cmd) {
}
}
// ICT
/*
// ICT
if (IfPm3Iso14443a()) {
int sel_state = infoHF14A(false, false, false);
if (sel_state > 0) {
@@ -131,6 +142,7 @@ int CmdHFSearch(const char *Cmd) {
infoHF14A4Applications(verbose);
}
}
*/
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for LEGIC tag...");
@@ -142,16 +154,6 @@ int CmdHFSearch(const char *Cmd) {
}
}
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for Topaz tag...");
if (IfPm3Iso14443a()) {
if (readTopazUid(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n");
success[TOPAZ] = true;
res = PM3_SUCCESS;
}
}
// texkom
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for TEXKOM tag...");
@@ -176,7 +178,7 @@ int CmdHFSearch(const char *Cmd) {
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for ISO14443-B tag...");
if (IfPm3Iso14443b()) {
if (readHF14B(false, false) == PM3_SUCCESS) {
if (readHF14B(false, false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 14443-B tag") " found\n");
success[ISO_14443B] = true;
res = PM3_SUCCESS;
+105 -34
View File
@@ -863,7 +863,7 @@ int CmdHF14ASim(const char *Cmd) {
if ((flags & FLAG_NR_AR_ATTACK) != FLAG_NR_AR_ATTACK)
break;
nonces_t *data = (nonces_t *)resp.data.asBytes;
const nonces_t *data = (nonces_t *)resp.data.asBytes;
readerAttack(k_sector, k_sectors_cnt, data[0], setEmulatorMem, verbose);
keypress = kbd_enter_pressed();
@@ -888,10 +888,10 @@ int CmdHF14ASim(const char *Cmd) {
int CmdHF14ASniff(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14a sniff",
"Collect data from the field and save into command buffer.\n"
"Buffer accessible from command `hf 14a list`\n",
" hf 14a sniff -c -r");
"Sniff the communication between Hitag reader and tag.\n"
"Use `hf 14a list` to view collected data.",
" hf 14a sniff -c -r"
);
void *argtable[] = {
arg_param_begin,
arg_lit0("c", "card", "triggered by first data from card"),
@@ -918,10 +918,13 @@ int CmdHF14ASniff(const char *Cmd) {
SendCommandNG(CMD_HF_ISO14443A_SNIFF, (uint8_t *)&param, sizeof(uint8_t));
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " to abort sniffing");
if (interactive) {
PacketResponseNG resp;
WaitForResponse(CMD_HF_ISO14443A_SNIFF, &resp);
PrintAndLogEx(INFO, "Done!");
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf 14a list")"` to view captured tracelog");
PrintAndLogEx(HINT, "Try `" _YELLOW_("trace save -h") "` to save tracelog for later analysing");
}
return PM3_SUCCESS;
}
@@ -988,7 +991,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
// CRC Check
if (iLen == -1) {
if (silentMode == false) {
PrintAndLogEx(ERR, "ISO 14443A CRC error.");
PrintAndLogEx(ERR, "ISO 14443A CRC error");
}
return PM3_ECRC;
}
@@ -1096,7 +1099,7 @@ int SelectCard14443A_4(bool disconnect, bool verbose, iso14a_card_select_t *card
return SelectCard14443A_4_WithParameters(disconnect, verbose, card, NULL);
}
static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout) {
static int CmdExchangeAPDU(bool chainingin, const uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout) {
*chainingout = false;
size_t timeout = 1500;
@@ -1155,7 +1158,7 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, timeout)) {
uint8_t *recv = resp.data.asBytes;
const uint8_t *recv = resp.data.asBytes;
int iLen = resp.oldarg[0];
uint8_t res = resp.oldarg[1];
@@ -1213,7 +1216,7 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
return PM3_SUCCESS;
}
int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
int ExchangeAPDU14a(const uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
*dataoutlen = 0;
bool chaining = false;
int res;
@@ -1516,7 +1519,7 @@ static int CmdHF14ACmdRaw(const char *Cmd) {
}
// TODO: allow to use reader command with both data and polling configuration
if (use_ecp | use_magsafe) {
if (use_ecp || use_magsafe) {
PrintAndLogEx(WARNING, "ECP and Magsafe not supported with this command at this moment. Instead use 'hf 14a reader -sk --ecp/--mag'");
// flags |= ISO14A_USE_MAGSAFE;
// flags |= ISO14A_USE_ECP;
@@ -1662,23 +1665,85 @@ static void printTag(const char *tag) {
PrintAndLogEx(SUCCESS, " " _YELLOW_("%s"), tag);
}
typedef enum {
MTNONE = 0,
MTCLASSIC = 1,
MTMINI = 2,
MTDESFIRE = 4,
MTPLUS = 8,
MTULTRALIGHT = 16,
HID_SEOS = 32,
MTOTHER = 64,
MTEMV = 128,
MTFUDAN = 256,
MTISO18092 = 512,
MT424 = 1024,
} nxp_mifare_type_t;
int detect_nxp_card(uint8_t sak, uint16_t atqa, uint64_t select_status) {
int type = MTNONE;
if ((sak & 0x02) != 0x02) {
if ((sak & 0x19) == 0x19) {
type |= MTCLASSIC;
} else if ((sak & 0x40) == 0x40) {
type |= MTISO18092;
} else if ((sak & 0x38) == 0x38) {
type |= MTCLASSIC;
} else if ((sak & 0x18) == 0x18) {
if (select_status == 1) {
type |= MTPLUS;
} else {
type |= MTCLASSIC;
}
} else if ((sak & 0x09) == 0x09) {
type |= MTMINI;
} else if ((sak & 0x28) == 0x28) {
type |= MTCLASSIC;
} else if ((sak & 0x08) == 0x08) {
if (select_status == 1) {
type |= MTPLUS;
} else {
type |= MTCLASSIC;
}
} else if ((sak & 0x11) == 0x11) {
type |= MTPLUS;
} else if ((sak & 0x10) == 0x10) {
type |= MTPLUS;
} else if ((sak & 0x01) == 0x01) {
type |= MTCLASSIC;
} else if ((sak & 0x24) == 0x24) {
type |= MTDESFIRE;
} else if ((sak & 0x20) == 0x20) {
if (select_status == 1) {
if ((atqa & 0x0040) == 0x0040) {
if ((atqa & 0x0300) == 0x0300) {
type |= MTDESFIRE;
} else {
type |= MTPLUS;
}
} else {
if ((atqa & 0x0001) == 0x0001) {
type |= HID_SEOS;
} else {
type |= MTPLUS;
}
if ((atqa & 0x0004) == 0x0004) {
type |= MTEMV;
}
}
type |= (MTDESFIRE | MT424);
}
} else if ((sak & 0x04) == 0x04) {
type |= MTDESFIRE;
} else {
type |= MTULTRALIGHT;
}
} else if ((sak & 0x0A) == 0x0A) {
if ((atqa & 0x0003) == 0x0003) {
type |= MTFUDAN;
} else if ((atqa & 0x0005) == 0x0005) {
type |= MTFUDAN;
}
} else if ((sak & 0x53) == 0x53) {
type |= MTFUDAN;
}
return type;
}
// Based on NXP AN10833 Rev 3.6 and NXP AN10834 Rev 4.1
static int detect_nxp_card(uint8_t sak, uint16_t atqa, uint64_t select_status) {
static int detect_nxp_card_print(uint8_t sak, uint16_t atqa, uint64_t select_status) {
int type = MTNONE;
PrintAndLogEx(SUCCESS, "Possible types:");
@@ -1826,7 +1891,7 @@ static int detect_nxp_card(uint8_t sak, uint16_t atqa, uint64_t select_status) {
printTag("FM11RF005SH (FUDAN Shanghai Metro)");
type |= MTFUDAN;
} else if ((atqa & 0x0005) == 0x0005) {
printTag("FM11RF005M (FUDAN MIFARE Classic clone)");
printTag("FM11RF005M (FUDAN ISO14443A w Crypto-1 algo)");
type |= MTFUDAN;
}
} else if ((sak & 0x53) == 0x53) {
@@ -2004,6 +2069,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, resp.oldarg[0]);
bool isMifareMini = false;
bool isMifareClassic = true;
bool isMifareDESFire = false;
bool isMifarePlus = false;
@@ -2017,8 +2083,9 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
int nxptype = MTNONE;
if (card.uidlen <= 4) {
nxptype = detect_nxp_card(card.sak, ((card.atqa[1] << 8) + card.atqa[0]), select_status);
nxptype = detect_nxp_card_print(card.sak, ((card.atqa[1] << 8) + card.atqa[0]), select_status);
isMifareMini = ((nxptype & MTMINI) == MTMINI);
isMifareClassic = ((nxptype & MTCLASSIC) == MTCLASSIC);
isMifareDESFire = ((nxptype & MTDESFIRE) == MTDESFIRE);
isMifarePlus = ((nxptype & MTPLUS) == MTPLUS);
@@ -2043,8 +2110,9 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
isMifareClassic = false;
break;
case 0x04: // NXP
nxptype = detect_nxp_card(card.sak, ((card.atqa[1] << 8) + card.atqa[0]), select_status);
nxptype = detect_nxp_card_print(card.sak, ((card.atqa[1] << 8) + card.atqa[0]), select_status);
isMifareMini = ((nxptype & MTMINI) == MTMINI);
isMifareClassic = ((nxptype & MTCLASSIC) == MTCLASSIC);
isMifareDESFire = ((nxptype & MTDESFIRE) == MTDESFIRE);
isMifarePlus = ((nxptype & MTPLUS) == MTPLUS);
@@ -2133,7 +2201,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
} else if (card.atqa[0] == 0x05) {
// Uses MIFARE Crypto-1 algo
printTag("FM11RF005M (FUDAN MIFARE Classic clone)");
printTag("FM11RF005M (FUDAN ISO14443A w Crypto-1 algo)");
}
break;
}
@@ -2380,10 +2448,13 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
} else {
if (card.ats[pos] == 0x80 || card.ats[pos] == 0x00) {
PrintAndLogEx(SUCCESS, " %s (compact TLV data object)", sprint_hex_inrow(&card.ats[pos], calen));
PrintAndLogEx(SUCCESS, "%s (compact TLV data object)", sprint_hex_inrow(&card.ats[pos], calen));
get_compact_tlv(card.ats + pos, calen);
} else {
PrintAndLogEx(SUCCESS, " %s", sprint_hex_inrow(card.ats + pos, calen));
PrintAndLogEx(SUCCESS, "%s - %s"
, sprint_hex_inrow(card.ats + pos, calen)
, sprint_ascii(card.ats + pos, calen)
);
}
PrintAndLogEx(NORMAL, "");
@@ -2492,7 +2563,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
uint16_t isMagic = 0;
if (isMifareClassic) {
if (isMifareClassic || isMifareMini) {
isMagic = detect_mf_magic(true, MF_KEY_B, 0xFFFFFFFFFFFF);
}
@@ -2500,7 +2571,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
isMagic = detect_mf_magic(false, MF_KEY_A, 0);
}
if (isMifareClassic) {
if (isMifareClassic || isMifareMini) {
int res = detect_classic_static_nonce();
if (res == NONCE_STATIC) {
PrintAndLogEx(SUCCESS, "Static nonce......... " _YELLOW_("yes"));
@@ -2591,7 +2662,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
PrintAndLogEx(HINT, "Hint: try `" _YELLOW_("hf ntag424 info") "`");
}
if (isMifareClassic) {
if (isMifareClassic || isMifareMini) {
if (((isMagic & MAGIC_FLAG_GEN_1A) == MAGIC_FLAG_GEN_1A) || ((isMagic & MAGIC_FLAG_GEN_1B) == MAGIC_FLAG_GEN_1B)) {
PrintAndLogEx(HINT, "Hint: use `" _YELLOW_("hf mf c*") "` magic commands");
+18 -1
View File
@@ -36,6 +36,21 @@ typedef struct {
const char *hint;
} hintAIDList_t;
typedef enum {
MTNONE = 0,
MTCLASSIC = 1,
MTMINI = 2,
MTDESFIRE = 4,
MTPLUS = 8,
MTULTRALIGHT = 16,
HID_SEOS = 32,
MTOTHER = 64,
MTEMV = 128,
MTFUDAN = 256,
MTISO18092 = 512,
MT424 = 1024,
} nxp_mifare_type_t;
int CmdHF14A(const char *Cmd);
int CmdHF14ASniff(const char *Cmd); // used by hf topaz sniff
int CmdHF14ASim(const char *Cmd); // used by hf mfu sim
@@ -43,13 +58,15 @@ int CmdHF14ANdefRead(const char *Cmd); // used by cmdnfc.c
int CmdHF14ANdefFormat(const char *Cmd); // used by cmdnfc.c
int CmdHF14ANdefWrite(const char *Cmd); // used by cmdnfc.c
int detect_nxp_card(uint8_t sak, uint16_t atqa, uint64_t select_status);
int hf14a_getconfig(hf14a_config *config);
int hf14a_setconfig(hf14a_config *config, bool verbose);
int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search);
int infoHF14A4Applications(bool verbose);
const char *getTagInfo(uint8_t uid);
int Hf14443_4aGetCardData(iso14a_card_select_t *card);
int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
int ExchangeAPDU14a(const uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool silentMode);
iso14a_polling_parameters_t iso14a_get_polling_parameters(bool use_ecp, bool use_magsafe);
+282 -42
View File
@@ -56,6 +56,14 @@
#define ST25_SIZE_2K 4
#define ST25_SIZE_4K 5
typedef struct {
const char *desc;
const char *apdu;
const uint8_t apdulen;
} transport_14b_apdu_t;
// iso14b apdu input frame length
static uint16_t apdu_frame_length = 0;
//static uint16_t ats_fsc[] = {16, 24, 32, 40, 48, 64, 96, 128, 256};
@@ -379,24 +387,34 @@ static bool get_14b_UID(uint8_t *d, iso14b_type_t *found_type) {
* filename must match '^hf-14b-[0-9A-F]{16}'
*/
uint8_t *get_uid_from_filename(const char *filename) {
static uint8_t uid[8] ;
memset(uid, 0, 8) ;
char uidinhex[17] ;
if (strlen(filename) < 23 || strncmp(filename, "hf-14b-", 7)) {
static uint8_t uid[8];
memset(uid, 0, 8);
if (strlen(filename) < 23) {
PrintAndLogEx(ERR, "can't get uid from filename '%s'. Expected format is hf-14b-<uid>...", filename);
return uid ;
return uid;
}
char *found = strstr(filename, "hf-14b-");
if (found == NULL) {
PrintAndLogEx(ERR, "can't get uid from filename '%s'. Expected format is hf-14b-<uid>...", filename);
return uid;
}
// extract uid part from filename
strncpy(uidinhex, filename + 7, 16) ;
uidinhex[16] = '\0' ;
char uidinhex[17] = {0};
strncpy(uidinhex, found + 7, 16);
uidinhex[16] = '\0';
int len = hex_to_bytes(uidinhex, uid, 8);
if (len == 8)
if (len == 8) {
return SwapEndian64(uid, 8, 8);
else {
} else {
PrintAndLogEx(ERR, "get_uid_from_filename failed: hex_to_bytes returned %d", len);
memset(uid, 0, 8);
}
return uid ;
return uid;
}
// print full atqb info
@@ -868,7 +886,8 @@ static int CmdHF14BSniff(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14b sniff",
"Sniff the communication reader and tag",
"Sniff the communication between reader and tag.\n"
"Use `hf 14b list` to view collected data.",
"hf 14b sniff"
);
@@ -879,12 +898,12 @@ static int CmdHF14BSniff(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " to abort sniffing");
PacketResponseNG resp;
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO14443B_SNIFF, NULL, 0);
WaitForResponse(CMD_HF_ISO14443B_SNIFF, &resp);
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf 14b list") "` to view captured tracelog");
PrintAndLogEx(HINT, "Try `" _YELLOW_("trace save -h") "` to save tracelog for later analysing");
return PM3_SUCCESS;
@@ -1484,13 +1503,15 @@ static int CmdHF14BReader(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_lit0(NULL, "plot", "show anticollision signal trace in plot window"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0("@", NULL, "optional - continuous reader mode"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool verbose = arg_get_lit(ctx, 1);
bool cm = arg_get_lit(ctx, 2);
bool read_plot = arg_get_lit(ctx, 1);
bool verbose = arg_get_lit(ctx, 2);
bool cm = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
if (cm) {
@@ -1499,7 +1520,7 @@ static int CmdHF14BReader(const char *Cmd) {
clear_trace_14b();
return readHF14B(cm, verbose);
return readHF14B(cm, verbose, read_plot);
}
// Read SRI512|SRIX4K block
@@ -2462,11 +2483,20 @@ static int CmdHF14BAPDU(const char *Cmd) {
}
PrintAndLogEx(INFO, "<<<< %s", sprint_hex(data, datalen));
PrintAndLogEx(SUCCESS, "APDU response: " _YELLOW_("%02x %02x") " - %s"
, data[datalen - 2]
, data[datalen - 1]
, GetAPDUCodeDescription(data[datalen - 2], data[datalen - 1])
);
uint16_t sw = get_sw(data, datalen);
if (sw != ISO7816_OK) {
PrintAndLogEx(SUCCESS, "APDU response: " _YELLOW_("%02x %02x") " - %s"
, data[datalen - 2]
, data[datalen - 1]
, GetAPDUCodeDescription(data[datalen - 2], data[datalen - 1])
);
} else {
PrintAndLogEx(SUCCESS, "APDU response: " _GREEN_("%02x %02x") " - %s"
, data[datalen - 2]
, data[datalen - 1]
, GetAPDUCodeDescription(data[datalen - 2], data[datalen - 1])
);
}
// TLV decoder
if (decode_TLV && datalen > 4) {
@@ -2642,24 +2672,232 @@ static int CmdHF14BView(const char *Cmd) {
return PM3_SUCCESS;
}
static int CmdHF14BCalypsoRead(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14b calypso",
"Reads out the contents of a ISO14443B Calypso card\n",
"hf 14b calypso"
);
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
transport_14b_apdu_t cmds[] = {
{"01.Select ICC file", "\x94\xa4\x08\x00\x04\x3f\x00\x00\x02", 9},
{"02.ICC", "\x94\xb2\x01\x04\x1d", 5},
{"03.Select EnvHol file", "\x94\xa4\x08\x00\x04\x20\x00\x20\x01", 9},
{"04.EnvHol1", "\x94\xb2\x01\x04\x1d", 5},
{"05.Select EvLog file", "\x94\xa4\x08\x00\x04\x20\x00\x20\x10", 9},
{"06.EvLog1", "\x94\xb2\x01\x04\x1d", 5},
{"07.EvLog2", "\x94\xb2\x02\x04\x1d", 5},
{"08.EvLog3", "\x94\xb2\x03\x04\x1d", 5},
{"09.Select ConList file", "\x94\xa4\x08\x00\x04\x20\x00\x20\x50", 9},
{"10.ConList", "\x94\xb2\x01\x04\x1d", 5},
{"11.Select Contra file", "\x94\xa4\x08\x00\x04\x20\x00\x20\x20", 9},
{"12.Contra1", "\x94\xb2\x01\x04\x1d", 5},
{"13.Contra2", "\x94\xb2\x02\x04\x1d", 5},
{"14.Contra3", "\x94\xb2\x03\x04\x1d", 5},
{"15.Contra4", "\x94\xb2\x04\x04\x1d", 5},
{"16.Select Counter file", "\x94\xa4\x08\x00\x04\x20\x00\x20\x69", 9},
{"17.Counter", "\x94\xb2\x01\x04\x1d", 5},
{"18.Select SpecEv file", "\x94\xa4\x08\x00\x04\x20\x00\x20\x40", 9},
{"19.SpecEv1", "\x94\xb2\x01\x04\x1d", 5},
};
/*
local CLA = '94'
local _calypso_cmds = {
-- Break down of command bytes:
-- A4 = select
-- Master File 3F00
-- 0x3F = master file
-- 0x00 = master file id, is constant to 0x00.
-- DF Dedicated File 38nn
-- can be seen as directories
-- 0x38
-- 0xNN id
-- ["01.Select ICC file"] = '0294 a4 080004 3f00 0002',
-- EF Elementary File
-- EF1 Pin file
-- EF2 Key file
-- Grey Lock file
-- Electronic deposit file
-- Electronic Purse file
-- Electronic Transaction log file
*/
bool activate_field = true;
bool leave_signal_on = true;
uint8_t response[PM3_CMD_DATA_SIZE] = { 0x00 };
for (int i = 0; i < ARRAYLEN(cmds); i++) {
int user_timeout = -1;
int resplen = 0;
int res = exchange_14b_apdu(
(uint8_t *)cmds[i].apdu,
cmds[i].apdulen,
activate_field,
leave_signal_on,
response,
PM3_CMD_DATA_SIZE,
&resplen,
user_timeout
);
if (res != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "sending command failed, aborting!");
switch_off_field_14b();
return res;
}
uint16_t sw = get_sw(response, resplen);
if (sw != ISO7816_OK) {
PrintAndLogEx(ERR, "Sending command failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
switch_off_field_14b();
return PM3_ESOFT;
}
PrintAndLogEx(INFO, "%s - %s", cmds[i].desc, sprint_hex(response, resplen));
activate_field = false;
}
switch_off_field_14b();
return PM3_SUCCESS;
}
static int CmdHF14BMobibRead(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14b mobib",
"Reads out the contents of a ISO14443B Mobib card\n",
"hf 14b mobib"
);
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
transport_14b_apdu_t cmds[] = {
{"01.SELECT AID 1TIC.ICA", "\x00\xa4\x04\x00\x08\x31\x54\x49\x43\x2e\x49\x43\x41", 13},
{"02.Select ICC file a", "\x00\xa4\x00\x00\x02\x3f\x00", 7},
{"03.Select ICC file b", "\x00\xa4\x00\x00\x02\x00\x02", 7},
{"04.ICC", "\x00\xb2\x01\x04\x1d", 5},
{"05.Select Holder file", "\x00\xa4\x00\x00\x02\x3f\x1c", 7},
{"06.Holder1", "\x00\xb2\x01\x04\x1d", 5},
{"07.Holder2", "\x00\xb2\x02\x04\x1d", 5},
{"08.Select EnvHol file a", "\x00\xa4\x00\x00\x00", 5},
{"09.Select EnvHol file b", "\x00\xa4\x00\x00\x02\x20\x00", 7},
{"10.Select EnvHol file c", "\x00\xa4\x00\x00\x02\x20\x01", 7},
{"11.EnvHol1", "\x00\xb2\x01\x04\x1D", 5},
{"11.EnvHol2", "\x00\xb2\x02\x04\x1D", 5},
{"12.Select EvLog file", "\x00\xa4\x00\x00\x02\x20\x10", 7},
{"13.EvLog1", "\x00\xb2\x01\x04\x1D", 5},
{"14.EvLog2", "\x00\xb2\x02\x04\x1D", 5},
{"15.EvLog3", "\x00\xb2\x03\x04\x1D", 5},
{"16.Select ConList file", "\x00\xa4\x00\x00\x02\x20\x50", 7},
{"17.ConList", "\x00\xb2\x01\x04\x1D", 5},
{"18.Select Contra file", "\x00\xa4\x00\x00\x02\x20\x20", 7},
{"19.Contra1", "\x00\xb2\x01\x04\x1D", 5},
{"20.Contra2", "\x00\xb2\x02\x04\x1D", 5},
{"21.Contra3", "\x00\xb2\x03\x04\x1D", 5},
{"22.Contra4", "\x00\xb2\x04\x04\x1D", 5},
{"23.Contra5", "\x00\xb2\x05\x04\x1D", 5},
{"24.Contra6", "\x00\xb2\x06\x04\x1D", 5},
{"25.Contra7", "\x00\xb2\x07\x04\x1D", 5},
{"26.Contra8", "\x00\xb2\x08\x04\x1D", 5},
{"27.Contra9", "\x00\xb2\x09\x04\x1D", 5},
{"28.ContraA", "\x00\xb2\x0a\x04\x1D", 5},
{"29.ContraB", "\x00\xb2\x0b\x04\x1D", 5},
{"30.ContraC", "\x00\xb2\x0c\x04\x1D", 5},
{"31.Select Counter file", "\x00\xa4\x00\x00\x02\x20\x69", 7},
{"32.Counter", "\x00\xb2\x01\x04\x1D", 5},
{"33.Select LoadLog file a", "\x00\xa4\x00\x00\x00", 5},
{"34.Select LoadLog file b", "\x00\xa4\x00\x00\x02\x10\x00", 7},
{"35.Select LoadLog file c", "\x00\xa4\x00\x00\x02\x10\x14", 7},
{"36.LoadLog", "\x00\xb2\x01\x04\x1D", 5},
{"37.Select Purcha file", "\x00\xa4\x00\x00\x02\x10\x15", 7},
{"38.Purcha1", "\x00\xb2\x01\x04\x1D", 5},
{"39.Purcha2", "\x00\xb2\x02\x04\x1D", 5},
{"40.Purcha3", "\x00\xb2\x03\x04\x1D", 5},
{"41.Select SpecEv file a", "\x00\xa4\x00\x00\x00", 5},
{"42.Select SpecEv file b", "\x00\xa4\x00\x00\x02\x20\x00", 7},
{"43.Select SpecEv file c", "\x00\xa4\x00\x00\x02\x20\x40", 7},
{"44.SpecEv1", "\x00\xb2\x01\x04\x1D", 5},
{"45.SpecEv2", "\x00\xb2\x02\x04\x1D", 5},
{"46.SpecEv3", "\x00\xb2\x03\x04\x1D", 5},
{"47.SpecEv4", "\x00\xb2\x04\x04\x1d", 5},
};
bool activate_field = true;
bool leave_signal_on = true;
uint8_t response[PM3_CMD_DATA_SIZE] = { 0x00 };
for (int i = 0; i < ARRAYLEN(cmds); i++) {
int user_timeout = -1;
int resplen = 0;
int res = exchange_14b_apdu(
(uint8_t *)cmds[i].apdu,
cmds[i].apdulen,
activate_field,
leave_signal_on,
response,
PM3_CMD_DATA_SIZE,
&resplen,
user_timeout
);
if (res != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "sending command failed, aborting!");
switch_off_field_14b();
return res;
}
uint16_t sw = get_sw(response, resplen);
if (sw != ISO7816_OK) {
PrintAndLogEx(ERR, "Sending command failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
switch_off_field_14b();
return PM3_ESOFT;
}
PrintAndLogEx(INFO, "%s - %s", cmds[i].desc, sprint_hex(response, resplen));
activate_field = false;
}
switch_off_field_14b();
return PM3_SUCCESS;
}
static command_t CommandTable[] = {
{"---------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"},
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"list", CmdHF14BList, AlwaysAvailable, "List ISO-14443-B history"},
{"---------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operations") " -----------------------"},
{"apdu", CmdHF14BAPDU, IfPm3Iso14443b, "Send ISO 14443-4 APDU to tag"},
{"dump", CmdHF14BDump, IfPm3Iso14443b, "Read all memory pages of an ISO-14443-B tag, save to file"},
{"info", CmdHF14Binfo, IfPm3Iso14443b, "Tag information"},
{"ndefread", CmdHF14BNdefRead, IfPm3Iso14443b, "Read NDEF file on tag"},
{"raw", CmdHF14BRaw, IfPm3Iso14443b, "Send raw hex data to tag"},
{"rdbl", CmdHF14BSriRdBl, IfPm3Iso14443b, "Read SRI512/SRIX4 block"},
{"reader", CmdHF14BReader, IfPm3Iso14443b, "Act as a ISO-14443-B reader to identify a tag"},
{"restore", CmdHF14BRestore, IfPm3Iso14443b, "Restore from file to all memory pages of an ISO-14443-B tag"},
{"sim", CmdHF14BSim, IfPm3Iso14443b, "Fake ISO ISO-14443-B tag"},
{"sniff", CmdHF14BSniff, IfPm3Iso14443b, "Eavesdrop ISO-14443-B"},
{"wrbl", CmdHF14BSriWrbl, IfPm3Iso14443b, "Write data to a SRI512/SRIX4 tag"},
{"view", CmdHF14BView, AlwaysAvailable, "Display content from tag dump file"},
{"valid", CmdSRIX4kValid, AlwaysAvailable, "SRIX4 checksum test"},
{"---------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"},
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"list", CmdHF14BList, AlwaysAvailable, "List ISO-14443-B history"},
{"---------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operations") " -----------------------"},
{"apdu", CmdHF14BAPDU, IfPm3Iso14443b, "Send ISO 14443-4 APDU to tag"},
{"dump", CmdHF14BDump, IfPm3Iso14443b, "Read all memory pages of an ISO-14443-B tag, save to file"},
{"info", CmdHF14Binfo, IfPm3Iso14443b, "Tag information"},
{"ndefread", CmdHF14BNdefRead, IfPm3Iso14443b, "Read NDEF file on tag"},
{"raw", CmdHF14BRaw, IfPm3Iso14443b, "Send raw hex data to tag"},
{"rdbl", CmdHF14BSriRdBl, IfPm3Iso14443b, "Read SRI512/SRIX4 block"},
{"reader", CmdHF14BReader, IfPm3Iso14443b, "Act as a ISO-14443-B reader to identify a tag"},
{"restore", CmdHF14BRestore, IfPm3Iso14443b, "Restore from file to all memory pages of an ISO-14443-B tag"},
{"sim", CmdHF14BSim, IfPm3Iso14443b, "Fake ISO ISO-14443-B tag"},
{"sniff", CmdHF14BSniff, IfPm3Iso14443b, "Eavesdrop ISO-14443-B"},
{"wrbl", CmdHF14BSriWrbl, IfPm3Iso14443b, "Write data to a SRI512/SRIX4 tag"},
{"view", CmdHF14BView, AlwaysAvailable, "Display content from tag dump file"},
{"valid", CmdSRIX4kValid, AlwaysAvailable, "SRIX4 checksum test"},
{"---------", CmdHelp, AlwaysAvailable, "------------------ " _CYAN_("Calypso / Mobib") " ------------------"},
{"calypso", CmdHF14BCalypsoRead, IfPm3Iso14443b, "Read contents of a Calypso card"},
{"mobib", CmdHF14BMobibRead, IfPm3Iso14443b, "Read contents of a Mobib card"},
{NULL, NULL, NULL, NULL}
};
@@ -2692,7 +2930,7 @@ int infoHF14B(bool verbose, bool do_aid_search) {
}
// get and print general info about all known 14b chips
int readHF14B(bool loop, bool verbose) {
int readHF14B(bool loop, bool verbose, bool read_plot) {
bool found = false;
int res = PM3_SUCCESS;
do {
@@ -2724,9 +2962,11 @@ int readHF14B(bool loop, bool verbose) {
if (found)
goto plot;
plot:
res = handle_hf_plot(verbose);
if (res != PM3_SUCCESS) {
PrintAndLogEx(DEBUG, "plot failed");
if (read_plot) {
res = handle_hf_plot(verbose);
if (res != PM3_SUCCESS) {
PrintAndLogEx(DEBUG, "plot failed");
}
}
} while (loop && kbd_enter_pressed() == false);
+1 -1
View File
@@ -30,5 +30,5 @@ int exchange_14b_apdu(uint8_t *datain, int datainlen, bool activate_field, bool
int select_card_14443b_4(bool disconnect, iso14b_card_select_t *card);
int infoHF14B(bool verbose, bool do_aid_search);
int readHF14B(bool loop, bool verbose);
int readHF14B(bool loop, bool verbose, bool read_plot);
#endif
+95 -31
View File
@@ -122,6 +122,23 @@ static const productName_t uidmapping[] = {
{ 0xE002080000000000LL, 24, "ST Microelectronics; LRI2K [IC id = 08]"},
{ 0xE0020A0000000000LL, 24, "ST Microelectronics; LRIS2K [IC id = 10]"},
{ 0xE002440000000000LL, 24, "ST Microelectronics; LRIS64K [IC id = 68]"},
{ 0xe002230000000000LL, 24, "ST Microelectronics; ST25TV02K"},
{ 0xe002230000000000LL, 24, "ST Microelectronics; ST25TV512"},
{ 0xe002080000000000LL, 24, "ST Microelectronics; ST25TV02KC"},
{ 0xe002080000000000LL, 24, "ST Microelectronics; ST25TV512C"},
{ 0xe002350000000000LL, 24, "ST Microelectronics; ST25TV04K-P"},
{ 0xe002480000000000LL, 24, "ST Microelectronics; ST25TV16K"},
{ 0xe002480000000000LL, 24, "ST Microelectronics; ST25TV64K"},
/*
ST25TV02K 0xe0 02 23
ST25TV512 0xe0 02 23
ST25TV02KC 0xe00208
ST25TV512C 0xe00208
ST25TV04K-P 0xe00235
ST25TV16K 0xe00248
ST25TV64K 0xe00248
*/
{ 0xE003000000000000LL, 16, "Hitachi, Ltd Japan" },
@@ -267,14 +284,16 @@ static int nxp_15693_print_signature(uint8_t *uid, uint8_t *signature) {
#define PUBLIC_ECDA_KEYLEN 33
const ecdsa_publickey_t nxp_15693_public_keys[] = {
{"NXP MIFARE Classic MFC1C14_x", "044F6D3F294DEA5737F0F46FFEE88A356EED95695DD7E0C27A591E6F6F65962BAF"},
{"Manufacturer MIFARE Classic / QL88", "046F70AC557F5461CE5052C8E4A7838C11C7A236797E8A0730A101837C004039C2"},
{"NXP ICODE DNA, ICODE SLIX2", "048878A2A2D3EEC336B4F261A082BD71F9BE11C4E2E896648B32EFA59CEA6E59F0"},
{"NXP Public key", "04A748B6A632FBEE2C0897702B33BEA1C074998E17B84ACA04FF267E5D2C91F6DC"},
{"NXP Ultralight Ev1", "0490933BDCD6E99B4E255E3DA55389A827564E11718E017292FAF23226A96614B8"},
{"NXP NTAG21x (2013)", "04494E1A386D3D3CFE3DC10E5DE68A499B1C202DB5B132393E89ED19FE5BE8BC61"},
{"MIKRON Public key", "04f971eda742a4a80d32dcf6a814a707cc3dc396d35902f72929fdcd698b3468f2"},
{"VivoKey Spark1 Public key", "04d64bb732c0d214e7ec580736acf847284b502c25c0f7f2fa86aace1dada4387a"},
{"NXP MIFARE Classic MFC1C14_x", "044F6D3F294DEA5737F0F46FFEE88A356EED95695DD7E0C27A591E6F6F65962BAF"},
{"MIFARE Classic / QL88", "046F70AC557F5461CE5052C8E4A7838C11C7A236797E8A0730A101837C004039C2"},
{"NXP ICODE DNA, ICODE SLIX2", "048878A2A2D3EEC336B4F261A082BD71F9BE11C4E2E896648B32EFA59CEA6E59F0"},
{"NXP Public key", "04A748B6A632FBEE2C0897702B33BEA1C074998E17B84ACA04FF267E5D2C91F6DC"},
{"NXP Ultralight Ev1", "0490933BDCD6E99B4E255E3DA55389A827564E11718E017292FAF23226A96614B8"},
{"NXP NTAG21x (2013)", "04494E1A386D3D3CFE3DC10E5DE68A499B1C202DB5B132393E89ED19FE5BE8BC61"},
{"MIKRON Public key", "04F971EDA742A4A80D32DCF6A814A707CC3DC396D35902F72929FDCD698B3468F2"},
{"VivoKey Spark1 Public key", "04D64BB732C0D214E7EC580736ACF847284B502C25C0F7F2FA86AACE1DADA4387A"},
{"TruST25 (ST) key 01?", "041D92163650161A2548D33881C235D0FB2315C2C31A442F23C87ACF14497C0CBA"},
{"TruST25 (ST) key 04?", "04101E188A8B4CDDBC62D5BC3E0E6850F0C2730E744B79765A0E079907FBDB01BC"},
};
/*
uint8_t nxp_15693_public_keys[][PUBLIC_ECDA_KEYLEN] = {
@@ -354,7 +373,6 @@ static int nxp_15693_print_signature(uint8_t *uid, uint8_t *signature) {
break;
}
// try with sha256
res = ecdsa_signature_r_s_verify(MBEDTLS_ECP_DP_SECP128R1, key, revuid, sizeof(revuid), revsign, sizeof(revsign), true);
is_valid = (res == 0);
@@ -398,7 +416,7 @@ static int nxp_15693_print_signature(uint8_t *uid, uint8_t *signature) {
// get a product description based on the UID
// uid[8] tag uid
// returns description of the best match
static const char *getTagInfo_15(uint8_t *uid) {
static const char *getTagInfo_15(const uint8_t *uid) {
if (uid == NULL) {
return "";
}
@@ -455,6 +473,26 @@ static const char *TagErrorStr(uint8_t error) {
}
}
static int iso15_error_handling_card_response(uint8_t *d, uint16_t n) {
if (check_crc(CRC_15693, d, n) == false) {
PrintAndLogEx(FAILED, "crc ( " _RED_("fail") " )");
return PM3_ECRC;
}
if ((d[0] & ISO15_RES_ERROR) == ISO15_RES_ERROR) {
if (d[1] == 0x0F || d[1] == 0x10) {
return PM3_EOUTOFBOUND;
}
PrintAndLogEx(ERR, "iso15693 card returned error %i: %s", d[0], TagErrorStr(d[0]));
return PM3_EWRONGANSWER;
}
return PM3_SUCCESS;
}
// fast method to just read the UID of a tag (collision detection not supported)
// *buf should be large enough to fit the 64bit uid
// returns 1 if succeeded
@@ -696,7 +734,7 @@ static int CmdHF15Samples(const char *Cmd) {
return PM3_SUCCESS;
}
static int NxpTestEAS(uint8_t *uid) {
static int NxpTestEAS(const uint8_t *uid) {
if (uid == NULL) {
return PM3_EINVARG;
@@ -1144,7 +1182,7 @@ static void hf15EmlClear(void) {
WaitForResponse(CMD_HF_ISO15693_EML_CLEAR, &resp);
}
static int hf15EmlSetMem(uint8_t *data, uint16_t count, size_t offset) {
static int hf15EmlSetMem(const uint8_t *data, uint16_t count, size_t offset) {
struct p {
uint32_t offset;
uint16_t count;
@@ -1194,13 +1232,14 @@ static int CmdHF15ELoad(const char *Cmd) {
return res;
}
if (bytes_read != sizeof(iso15_tag_t)) {
PrintAndLogEx(FAILED, "Memory image is not matching tag structure.");
if (bytes_read == 0) {
PrintAndLogEx(FAILED, "Memory image empty.");
free(tag);
return PM3_EINVARG;
}
if (bytes_read == 0) {
PrintAndLogEx(FAILED, "Memory image empty.");
if (bytes_read != sizeof(iso15_tag_t)) {
PrintAndLogEx(FAILED, "Memory image is not matching tag structure.");
free(tag);
return PM3_EINVARG;
}
@@ -1317,7 +1356,7 @@ static void print_blocks_15693(iso15_tag_t *tag, bool dense_output) {
for (int i = 0; i < tag->pagesCount; i++) {
uint8_t *blk = d + (i * blocksize);
const uint8_t *blk = d + (i * blocksize);
// suppress repeating blocks, truncate as such that the first and last block with the same data is shown
// but the blocks in between are replaced with a single line of "......" if dense_output is enabled
@@ -1812,6 +1851,7 @@ static int CmdHF15Dump(const char *Cmd) {
iso15_tag_t *tag = (iso15_tag_t *)calloc(1, sizeof(iso15_tag_t));
if (tag == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
free(packet);
return PM3_EMALLOC;
};
@@ -1826,6 +1866,7 @@ static int CmdHF15Dump(const char *Cmd) {
PrintAndLogEx(INFO, "Using scan mode");
if (getUID(verbose, false, uid) != PM3_SUCCESS) {
free(packet);
free(tag);
PrintAndLogEx(WARNING, "no tag found");
return PM3_EINVARG;
}
@@ -1855,18 +1896,27 @@ static int CmdHF15Dump(const char *Cmd) {
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_ISO15693_COMMAND, &resp, 2000) == false) {
PrintAndLogEx(DEBUG, "iso15693 timeout");
free(packet);
free(tag);
return PM3_ETIMEOUT;
}
if (resp.length < 2) {
PrintAndLogEx(WARNING, "iso15693 card doesn't answer to systeminfo command (%d)", resp.length);
free(packet);
free(tag);
return PM3_EWRONGANSWER;
}
uint8_t *d = resp.data.asBytes;
uint8_t dCpt = 10;
ISO15_ERROR_HANDLING_CARD_RESPONSE(d, resp.length);
int res = iso15_error_handling_card_response(d, resp.length);
if (res != PM3_SUCCESS) {
free(tag);
free(packet);
return res;
}
memcpy(tag->uid, &d[2], 8);
@@ -1973,6 +2023,7 @@ static int CmdHF15Dump(const char *Cmd) {
if (no_save) {
PrintAndLogEx(INFO, "Called with no save option");
PrintAndLogEx(NORMAL, "");
free(tag);
return PM3_SUCCESS;
}
@@ -1986,6 +2037,7 @@ static int CmdHF15Dump(const char *Cmd) {
pm3_save_dump(filename, (uint8_t *)tag, sizeof(iso15_tag_t), jsf15_v4);
free(tag);
return PM3_SUCCESS;
}
@@ -2418,7 +2470,7 @@ static int CmdHF15Readblock(const char *Cmd) {
return PM3_SUCCESS;
}
static int hf_15_write_blk(uint8_t *pm3flags, uint16_t flags, uint8_t *uid, bool fast, uint8_t blockno, uint8_t *data, uint8_t dlen) {
static int hf_15_write_blk(const uint8_t *pm3flags, uint16_t flags, const uint8_t *uid, bool fast, uint8_t blockno, const uint8_t *data, uint8_t dlen) {
// request to be sent to device/card
// 2 + 8 + 1 + (4|8) + 2
@@ -2642,13 +2694,14 @@ static int CmdHF15Restore(const char *Cmd) {
return res;
}
if (bytes_read != sizeof(iso15_tag_t)) {
PrintAndLogEx(FAILED, "Memory image is not matching tag structure.");
if (bytes_read == 0) {
PrintAndLogEx(FAILED, "Memory image empty.");
free(tag);
return PM3_EINVARG;
}
if (bytes_read == 0) {
PrintAndLogEx(FAILED, "Memory image empty.");
if (bytes_read != sizeof(iso15_tag_t)) {
PrintAndLogEx(FAILED, "Memory image is not matching tag structure.");
free(tag);
return PM3_EINVARG;
}
@@ -2676,7 +2729,7 @@ static int CmdHF15Restore(const char *Cmd) {
size_t bytes = 0;
uint16_t i = 0;
uint8_t *data = calloc(tag->bytesPerPage, sizeof(uint8_t));
uint32_t tried = 0;
uint32_t tried;
while (bytes < (tag->pagesCount * tag->bytesPerPage)) {
// copy over the data to the request
@@ -2735,11 +2788,14 @@ static int CmdHF15CSetUID(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 15 csetuid",
"Set UID for magic Chinese card (only works with such cards)\n",
"hf 15 csetuid -u E011223344556677");
"hf 15 csetuid -u E011223344556677 -> use gen1 command\n"
"hf 15 csetuid -u E011223344556677 --v2 -> use gen2 command"
);
void *argtable[] = {
arg_param_begin,
arg_str1("u", "uid", "<hex>", "UID, 8 hex bytes"),
arg_lit0("2", "v2", "Use gen2 magic command"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -2750,6 +2806,7 @@ static int CmdHF15CSetUID(const char *Cmd) {
int uidlen = 0;
CLIGetHexWithReturn(ctx, 1, payload.uid, &uidlen);
bool use_v2 = arg_get_lit(ctx, 2);
CLIParserFree(ctx);
if (uidlen != HF15_UID_LENGTH) {
@@ -2775,8 +2832,14 @@ static int CmdHF15CSetUID(const char *Cmd) {
PrintAndLogEx(INFO, "Writing...");
PacketResponseNG resp;
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO15693_CSETUID, (uint8_t *)&payload, sizeof(payload));
if (WaitForResponseTimeout(CMD_HF_ISO15693_CSETUID, &resp, 2000) == false) {
uint16_t cmd = CMD_HF_ISO15693_CSETUID;
if (use_v2) {
cmd = CMD_HF_ISO15693_CSETUID_V2;
}
SendCommandNG(cmd, (uint8_t *)&payload, sizeof(payload));
if (WaitForResponseTimeout(cmd, &resp, 2000) == false) {
PrintAndLogEx(WARNING, "timeout while waiting for reply");
DropField();
return PM3_ESOFT;
@@ -3296,13 +3359,14 @@ static int CmdHF15View(const char *Cmd) {
return res;
}
if (bytes_read != sizeof(iso15_tag_t)) {
PrintAndLogEx(FAILED, "Memory image is not matching tag structure.");
if (bytes_read == 0) {
PrintAndLogEx(FAILED, "Memory image empty.");
free(tag);
return PM3_EINVARG;
}
if (bytes_read == 0) {
PrintAndLogEx(FAILED, "Memory image empty.");
if (bytes_read != sizeof(iso15_tag_t)) {
PrintAndLogEx(FAILED, "Memory image is not matching tag structure.");
free(tag);
return PM3_EINVARG;
}
+2
View File
@@ -93,6 +93,8 @@ static int CmdHFCryptoRFSniff(const char *Cmd) {
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO14443B_SNIFF, NULL, 0);
PacketResponseNG resp;
WaitForResponse(CMD_HF_ISO14443B_SNIFF, &resp);
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf cryptorf list") "` to view captured tracelog");
PrintAndLogEx(HINT, "Try `" _YELLOW_("trace save -f hf_cryptorf_mytrace") "` to save tracelog for later analysing");
+1 -1
View File
@@ -32,7 +32,7 @@
#include "crapto1/crapto1.h" // prng_successor
#include "commonutil.h" // num_to_bytes
#include "util_posix.h" // msclock
#include "ui.h" // searchhomedirectory
#include "ui.h" // search home directory
#include "proxgui.h" // Picture Window
// Max file size in bytes. Used in several places.
+5 -2
View File
@@ -312,13 +312,13 @@ static int CmdHFFelicaList(const char *Cmd) {
int read_felica_uid(bool loop, bool verbose) {
int res = PM3_SUCCESS;
int res = PM3_ETIMEOUT;
do {
clearCommandBuffer();
SendCommandMIX(CMD_HF_FELICA_COMMAND, FELICA_CONNECT, 0, 0, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
uint8_t status = resp.oldarg[0] & 0xFF;
@@ -342,7 +342,10 @@ int read_felica_uid(bool loop, bool verbose) {
}
PrintAndLogEx(SUCCESS, "IDm: " _GREEN_("%s"), sprint_hex_inrow(card.IDm, sizeof(card.IDm)));
set_last_known_card(card);
res = PM3_SUCCESS;
}
} while (loop && kbd_enter_pressed() == false);
DropField();
+9 -7
View File
@@ -2147,8 +2147,9 @@ static int CmdHFiClassDump(const char *Cmd) {
write_dump:
if (have_credit_key && pagemap != 0x01 && aa2_success == false)
if (have_credit_key && pagemap != 0x01 && aa2_success == false) {
PrintAndLogEx(INFO, "Reading AA2 failed. dumping AA1 data to file");
}
// print the dump
printIclassDumpContents(tag_data, 1, (bytes_got / 8), bytes_got, dense_output);
@@ -2852,8 +2853,8 @@ static int CmdHFiClass_loclass(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "filename with nr/mac data from `hf iclass sim -t 2` "),
arg_lit0(NULL, "test", "Perform self-test"),
arg_lit0(NULL, "long", "Perform self-test, including long ones"),
arg_lit0(NULL, "test", "Perform self test"),
arg_lit0(NULL, "long", "Perform self test, including long ones"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -3580,7 +3581,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
CLIParserInit(&ctx, "hf iclass chk",
"Checkkeys loads a dictionary text file with 8byte hex keys to test authenticating against a iClass tag",
"hf iclass chk -f iclass_default_keys.dic\n"
"hf iclass chk -f iclass_default_keys.dic --elite");
"hf iclass chk -f iclass_elite_keys.dic --elite");
void *argtable[] = {
arg_param_begin,
@@ -3776,9 +3777,10 @@ out:
static int CmdHFiClassLookUp(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf iclass lookup",
"Lookup keys takes some sniffed trace data and tries to verify what key was used against a dictionary file",
"This command take sniffed trace data and try to recovery a iCLASS Standard or iCLASS Elite key.",
"hf iclass lookup --csn 9655a400f8ff12e0 --epurse f0ffffffffffffff --macs 0000000089cb984b -f iclass_default_keys.dic\n"
"hf iclass lookup --csn 9655a400f8ff12e0 --epurse f0ffffffffffffff --macs 0000000089cb984b -f iclass_default_keys.dic --elite");
"hf iclass lookup --csn 9655a400f8ff12e0 --epurse f0ffffffffffffff --macs 0000000089cb984b -f iclass_default_keys.dic --elite"
);
void *argtable[] = {
arg_param_begin,
@@ -4628,9 +4630,9 @@ static int CmdHFiClassSAM(const char *Cmd) {
}
static command_t CommandTable[] = {
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("General") " ---------------------"},
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"list", CmdHFiClassList, AlwaysAvailable, "List iclass history"},
// {"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("General") " ---------------------"},
{"-----------", CmdHelp, IfPm3Iclass, "------------------- " _CYAN_("Operations") " -------------------"},
// {"clone", CmdHFiClassClone, IfPm3Iclass, "Create a HID credential to Picopass / iCLASS tag"},
{"dump", CmdHFiClassDump, IfPm3Iclass, "Dump Picopass / iCLASS tag to file"},
+7 -7
View File
@@ -120,7 +120,7 @@ static int derive_app_key(uint8_t *uid, uint8_t *app_key) {
}
// Might miss payload..
static int diversify_mifare_key(uint8_t *uid, uint8_t *app_key) {
static int diversify_mifare_key(const uint8_t *uid, uint8_t *app_key) {
if (uid == NULL || app_key == NULL) {
return PM3_EINVARG;
}
@@ -152,7 +152,7 @@ static int diversify_mifare_key(uint8_t *uid, uint8_t *app_key) {
return PM3_SUCCESS;
}
static int decrypt_card_sector(uint8_t *uid, uint8_t *sector_data, uint8_t len, uint8_t *plain) {
static int decrypt_card_sector(uint8_t *uid, const uint8_t *sector_data, uint8_t len, uint8_t *plain) {
if (uid == NULL || sector_data == NULL || plain == NULL) {
return PM3_EINVARG;
}
@@ -203,7 +203,7 @@ static int derive_mifare_key_b(uint8_t *uid, uint8_t *app_key) {
return derive_mifare_key(uid, ICT_MIFARE_B_KEY, app_key);
}
static int decrypt_card_file(uint8_t *card_file, uint8_t len, uint8_t *plain) {
static int decrypt_card_file(const uint8_t *card_file, uint8_t len, uint8_t *plain) {
if (card_file == NULL || plain == NULL) {
return PM3_EINVARG;
}
@@ -211,7 +211,7 @@ static int decrypt_card_file(uint8_t *card_file, uint8_t len, uint8_t *plain) {
uint8_t input[ICT_FILE_SIZE];
memcpy(input, card_file, len);
uint8_t key[AES_KEY_LEN];
uint8_t key[AES_KEY_LEN] = {0};
// memcpy(key, ICT_DESFIRE_FILEKEY, AES_KEY_LEN);
uint8_t iv[16] = {0};
@@ -230,7 +230,7 @@ static int decrypt_card_file(uint8_t *card_file, uint8_t len, uint8_t *plain) {
return PM3_SUCCESS;
}
static int encrypt_card_file(uint8_t *card_file, uint8_t len, bool padding, uint8_t *enc) {
static int encrypt_card_file(const uint8_t *card_file, uint8_t len, bool padding, uint8_t *enc) {
if (len > ICT_FILE_SIZE) {
return PM3_EINVARG;
@@ -243,7 +243,7 @@ static int encrypt_card_file(uint8_t *card_file, uint8_t len, bool padding, uint
memset(input + len, 0x4C, 128 - len);
}
uint8_t key[AES_KEY_LEN];
uint8_t key[AES_KEY_LEN] = {0};
// memcpy(key, ICT_DESFIRE_FILEKEY, AES_KEY_LEN);
uint8_t iv[16] = {0};
@@ -262,7 +262,7 @@ static int encrypt_card_file(uint8_t *card_file, uint8_t len, bool padding, uint
return PM3_SUCCESS;
}
static void itc_decode_card_blob(uint8_t *data, uint8_t card_type) {
static void itc_decode_card_blob(const uint8_t *data, uint8_t card_type) {
if (data == NULL) {
return;
}
+2 -2
View File
@@ -238,7 +238,7 @@ static void jooki_print(uint8_t *b64, uint8_t *result, bool verbose) {
static int jooki_selftest(void) {
PrintAndLogEx(INFO, "======== " _CYAN_("selftest") " ===========================================");
PrintAndLogEx(INFO, "======== " _CYAN_("self test") " ===========================================");
for (int i = 0; i < ARRAYLEN(jooks); i++) {
if (strlen(jooks[i].b64) == 0)
continue;
@@ -296,7 +296,7 @@ static int CmdHF14AJookiEncode(const char *Cmd) {
arg_param_begin,
arg_str0("u", "uid", "<hex>", "uid bytes"),
arg_lit0("r", NULL, "read uid from tag instead"),
arg_lit0("t", NULL, "selftest"),
arg_lit0("t", NULL, "self test"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0(NULL, "dragon", "figurine type"),
arg_lit0(NULL, "fox", "figurine type"),
+7 -4
View File
@@ -365,7 +365,7 @@ int applyIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool i
break;
case MIFARE_ULEV1_AUTH:
if (cmdsize == 7)
snprintf(exp, size, "PWD-AUTH KEY: " _GREEN_("0x%02X%02X%02X%02X"), cmd[1], cmd[2], cmd[3], cmd[4]);
snprintf(exp, size, "PWD-AUTH: " _GREEN_("0x%02X%02X%02X%02X"), cmd[1], cmd[2], cmd[3], cmd[4]);
else
snprintf(exp, size, "PWD-AUTH");
break;
@@ -704,6 +704,9 @@ void annotateIso15693(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
case ISO15693_READ_SIGNATURE:
snprintf(exp, size, "READ_SIGNATURE");
return;
case ISO15693_MAGIC_WRITE:
snprintf(exp, size, "MAGIC_WRITEBLOCK");
return;
default:
break;
}
@@ -2103,9 +2106,9 @@ void annotateMifare(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize,
break;
}
if ((MifareAuthState == masNone) || (MifareAuthState == masError))
if ((MifareAuthState == masNone) || (MifareAuthState == masError)) {
annotateIso14443a(exp, size, cmd, cmdsize, isResponse);
}
}
static void mf_get_paritybinstr(char *s, uint32_t val, uint8_t par) {
@@ -2223,7 +2226,7 @@ bool DecodeMifareData(uint8_t *cmd, uint8_t cmdsize, uint8_t *parity, bool isRes
char sat[5] = {0, 0, 0, 0, 0};
mf_get_paritybinstr(sat, AuthData.at_enc, AuthData.at_enc_par);
PrintAndLogEx(NORMAL, "Nested authentication detected. ");
PrintAndLogEx(NORMAL, "Nested authentication detected!");
PrintAndLogEx(NORMAL, "tools/mf_nonce_brute/mf_nonce_brute %x %x %s %x %x %s %x %s %s\n"
, AuthData.uid
, AuthData.nt_enc
+203 -140
View File
@@ -70,8 +70,16 @@ int mfc_ev1_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, in
// ref: MIFARE Classic EV1 Originality Signature Validation
#define PUBLIC_MFCEV1_ECDA_KEYLEN 33
const ecdsa_publickey_t nxp_mfc_public_keys[] = {
{"NXP MIFARE Classic MFC1C14_x", "044F6D3F294DEA5737F0F46FFEE88A356EED95695DD7E0C27A591E6F6F65962BAF"},
{"Manufacturer MIFARE Classic / QL88", "046F70AC557F5461CE5052C8E4A7838C11C7A236797E8A0730A101837C004039C2"},
{"NXP MIFARE Classic MFC1C14_x", "044F6D3F294DEA5737F0F46FFEE88A356EED95695DD7E0C27A591E6F6F65962BAF"},
{"MIFARE Classic / QL88", "046F70AC557F5461CE5052C8E4A7838C11C7A236797E8A0730A101837C004039C2"},
{"NXP ICODE DNA, ICODE SLIX2", "048878A2A2D3EEC336B4F261A082BD71F9BE11C4E2E896648B32EFA59CEA6E59F0"},
{"NXP Public key", "04A748B6A632FBEE2C0897702B33BEA1C074998E17B84ACA04FF267E5D2C91F6DC"},
{"NXP Ultralight Ev1", "0490933BDCD6E99B4E255E3DA55389A827564E11718E017292FAF23226A96614B8"},
{"NXP NTAG21x (2013)", "04494E1A386D3D3CFE3DC10E5DE68A499B1C202DB5B132393E89ED19FE5BE8BC61"},
{"MIKRON Public key", "04F971EDA742A4A80D32DCF6A814A707CC3DC396D35902F72929FDCD698B3468F2"},
{"VivoKey Spark1 Public key", "04D64BB732C0D214E7EC580736ACF847284B502C25C0F7F2FA86AACE1DADA4387A"},
{"TruST25 (ST) key 01?", "041D92163650161A2548D33881C235D0FB2315C2C31A442F23C87ACF14497C0CBA"},
{"TruST25 (ST) key 04?", "04101E188A8B4CDDBC62D5BC3E0E6850F0C2730E744B79765A0E079907FBDB01BC"},
};
uint8_t i;
@@ -621,7 +629,7 @@ static int mfc_read_tag(iso14a_card_select_t *card, uint8_t *carddata, uint8_t n
fflush(stdout);
if (kbd_enter_pressed()) {
PrintAndLogEx(WARNING, "\nAborted via keyboard!\n");
PrintAndLogEx(WARNING, "\naborted via keyboard!\n");
free(fptr);
free(keyA);
free(keyB);
@@ -779,7 +787,7 @@ static int mf_load_keys(uint8_t **pkeyBlock, uint32_t *pkeycnt, uint8_t *userkey
PrintAndLogEx(DEBUG, _YELLOW_("%2d") " - %s", i, sprint_hex(*pkeyBlock + i * MIFARE_KEY_SIZE, MIFARE_KEY_SIZE));
}
*pkeycnt += numKeys;
PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%d") " dynamic keys", numKeys);
PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") " user keys", numKeys);
}
// Handle default keys
@@ -798,7 +806,6 @@ static int mf_load_keys(uint8_t **pkeyBlock, uint32_t *pkeycnt, uint8_t *userkey
*pkeycnt += ARRAYLEN(g_mifare_default_keys);
PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%zu") " keys from hardcoded default array", ARRAYLEN(g_mifare_default_keys));
// Handle user supplied dictionary file
if (fnlen > 0) {
uint32_t loaded_numKeys = 0;
@@ -4245,13 +4252,18 @@ void printKeyTableEx(size_t sectorscnt, sector_t *e_sector, uint8_t start_sector
s = i;
}
PrintAndLogEx(SUCCESS, " " _YELLOW_("%03d") " | %03d | %s | %s | %s | %s"
char extra[24] = {0x00};
if (sectorscnt == 18 && i > 15) {
strcat(extra, "( " _MAGENTA_("*") " )");
}
PrintAndLogEx(SUCCESS, " " _YELLOW_("%03d") " | %03d | %s | %s | %s | %s %s"
, s
, mfSectorTrailerOfSector(s)
, strA, resA
, strB, resB
, extra
);
}
PrintAndLogEx(SUCCESS, "-----+-----+--------------+---+--------------+----");
@@ -4268,6 +4280,10 @@ void printKeyTableEx(size_t sectorscnt, sector_t *e_sector, uint8_t start_sector
_YELLOW_("A") ":keyA "
" )"
);
if (sectorscnt == 18) {
PrintAndLogEx(INFO, "( " _MAGENTA_("*") " ) These sectors used for signature. Lays outside of user memory");
}
} else {
PrintAndLogEx(SUCCESS, "( " _RED_("0") ":Failed / " _GREEN_("1") ":Success )");
}
@@ -4711,7 +4727,7 @@ static int CmdHF14AMfEView(const char *Cmd) {
arg_lit0(NULL, "2k", "MIFARE Classic/Plus 2k"),
arg_lit0(NULL, "4k", "MIFARE Classic 4k / S70"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0(NULL, "sk", "Save extracted keys to file"),
arg_lit0(NULL, "sk", "Save extracted keys to binary file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -6803,9 +6819,9 @@ int CmdHFMFNDEFWrite(const char *Cmd) {
// find next available block
block_no++;
if (mfIsSectorTrailer(block_no)) {
block_no++;
// skip sectors which isn't ndef formatted
while (freemem[mfSectorNum(block_no)] == 0) {
block_no++;
@@ -7149,8 +7165,9 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
CLIParserFree(ctx);
// sanity checks
if (res || (!res && uidlen && uidlen != sizeof(uid))) {
PrintAndLogEx(ERR, "UID must include 8 HEX symbols");
PrintAndLogEx(ERR, "UID must include 4 hex bytes");
return PM3_EINVARG;
}
@@ -7555,7 +7572,7 @@ static int CmdHF14AMfView(const char *Cmd) {
arg_param_begin,
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_lit0("v", "verbose", "verbose output"),
arg_lit0(NULL, "sk", "Save extracted keys to file"),
arg_lit0(NULL, "sk", "Save extracted keys to binary file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -7650,6 +7667,127 @@ static int CmdHF14AMfView(const char *Cmd) {
return PM3_SUCCESS;
}
static int parse_gtu_cfg(uint8_t *d, size_t n) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "---------- " _CYAN_("GTU Gen4 Configuration") " -------------------------------------");
if (n != 30 && n != 32) {
PrintAndLogEx(INFO, "%s", sprint_hex_inrow(d, n));
PrintAndLogEx(INFO, "%zu bytes", n);
PrintAndLogEx(WARNING, "Unknown config format");
return PM3_SUCCESS;
}
PrintAndLogEx(INFO, _YELLOW_("%s"), sprint_hex_inrow(d, n));
PrintAndLogEx(INFO, "%zu bytes", n);
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, _CYAN_("Config 1 - UID & modes"));
PrintAndLogEx(INFO, "%s", sprint_hex_inrow(d, 8));
PrintAndLogEx(INFO, "%02X.............. " NOLF, d[0]);
bool is_ul_enabled = (d[0] == 1);
switch (d[0]) {
case 0x00:
PrintAndLogEx(NORMAL, "MIFARE Classic mode");
break;
case 0x01:
PrintAndLogEx(NORMAL, "MIFARE Ultralight/NTAG mode");
break;
default:
PrintAndLogEx(NORMAL, _RED_("unknown"));
break;
}
PrintAndLogEx(INFO, "..%02X............ UID " NOLF, d[1]);
switch (d[1]) {
case 0x00:
PrintAndLogEx(NORMAL, _GREEN_("4") " byte");
break;
case 0x01:
PrintAndLogEx(NORMAL, _GREEN_("7") " byte");
break;
case 0x02:
PrintAndLogEx(NORMAL, _GREEN_("10") " byte");
break;
default:
PrintAndLogEx(NORMAL, _RED_("unknown"));
break;
}
PrintAndLogEx(INFO, "...." _YELLOW_("%s") ".... " _YELLOW_("Password"), sprint_hex_inrow(&d[2], 4));
PrintAndLogEx(INFO, "............%02X.. GTU mode " NOLF, d[6]);
switch (d[6]) {
case 0x00:
PrintAndLogEx(NORMAL, _GREEN_("pre-write") " - shadow data can be written");
break;
case 0x01:
PrintAndLogEx(NORMAL, _GREEN_("restore mode"));
break;
case 0x02:
PrintAndLogEx(NORMAL, "disabled");
break;
case 0x03:
PrintAndLogEx(NORMAL, "disabled, high speed R/W mode for Ultralight ?");
break;
default:
PrintAndLogEx(NORMAL, _RED_("unknown"));
break;
}
PrintAndLogEx(INFO, "..............%02X unknown", d[7]);
PrintAndLogEx(INFO, "");
// ATS seems to have 16 bytes reserved
PrintAndLogEx(INFO, _CYAN_("Config 2 - ATS"));
PrintAndLogEx(INFO, "%s", sprint_hex_inrow(d + 8, 16));
PrintAndLogEx(INFO, "%s.............. ATS ( %d bytes )", sprint_hex_inrow(&d[8], d[7]), d[7]);
PrintAndLogEx(INFO, "..................%s Reserved for ATS", sprint_hex_inrow(d + 8 + d[7], 16 - d[7]));
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, _CYAN_("Config 3 - Limits"));
PrintAndLogEx(INFO, "%s", sprint_hex_inrow(d + 24, (n - 24)));
PrintAndLogEx(INFO, "%02X%02X............ ATQA", d[24], d[25]);
PrintAndLogEx(INFO, "....%02X.......... SAK", d[26]);
PrintAndLogEx(INFO, "......%02X........ " NOLF, d[27]);
switch (d[27]) {
case 0x00:
PrintAndLogEx(NORMAL, "%s", (is_ul_enabled) ? _GREEN_("Ultralight EV1") : "Ultralight Ev1");
break;
case 0x01:
PrintAndLogEx(NORMAL, "%s", (is_ul_enabled) ? _GREEN_("NTAG") : "NTAG");
break;
case 0x02:
PrintAndLogEx(NORMAL, "%s", (is_ul_enabled) ? _GREEN_("Ultralight C") : "Ultralight C");
break;
case 0x03:
PrintAndLogEx(NORMAL, "%s", (is_ul_enabled) ? _GREEN_("Ultralight") : "Ultralight");
break;
default:
PrintAndLogEx(NORMAL, _RED_("unknown"));
break;
}
PrintAndLogEx(INFO, "........%02X...... Max R/W sectors", d[28]);
PrintAndLogEx(INFO, "..........%02X.... " NOLF, d[29]);
switch (d[29]) {
case 0x00:
PrintAndLogEx(NORMAL, _GREEN_("CUID enabled"));
break;
case 0x01:
PrintAndLogEx(NORMAL, "CUID disabled");
break;
case 0x02:
PrintAndLogEx(NORMAL, "Default value. Same behaviour as 00?");
break;
default:
PrintAndLogEx(NORMAL, _RED_("unknown"));
break;
}
PrintAndLogEx(INFO, "............%s unknown", sprint_hex_inrow(d + 30, n - 30));
PrintAndLogEx(INFO, "");
return PM3_SUCCESS;
}
// info about Gen4 GTU card
static int CmdHF14AGen4Info(const char *cmd) {
CLIParserContext *ctx;
@@ -7657,11 +7795,13 @@ static int CmdHF14AGen4Info(const char *cmd) {
"Read info about magic gen4 GTU card.",
"hf mf ginfo --> get info with default password 00000000\n"
"hf mf ginfo --pwd 01020304 --> get info with password\n"
"hf mf ginfo -d 00000000000002090978009102BDAC19131011121314151604001800FF0002FD -v --> decode config block"
);
void *argtable[] = {
arg_param_begin,
arg_lit0("v", "verbose", "verbose output"),
arg_str0("p", "pwd", "<hex>", "password 4bytes"),
arg_str0("p", "pwd", "<hex>", "password 4 bytes"),
arg_str0("d", "data", "<hex>", "config bytes 32 bytes"),
arg_param_end
};
CLIExecWithReturn(ctx, cmd, argtable, true);
@@ -7670,6 +7810,10 @@ static int CmdHF14AGen4Info(const char *cmd) {
int pwd_len = 0;
uint8_t pwd[4] = {0};
CLIGetHexWithReturn(ctx, 2, pwd, &pwd_len);
int dlen = 0;
uint8_t data[32] = {0};
CLIGetHexWithReturn(ctx, 3, data, &dlen);
CLIParserFree(ctx);
if (pwd_len != 0 && pwd_len != 4) {
@@ -7679,156 +7823,74 @@ static int CmdHF14AGen4Info(const char *cmd) {
uint8_t resp[40] = {0};
size_t resplen = 0;
int res = mfG4GetConfig(pwd, resp, &resplen, verbose);
if (res != PM3_SUCCESS || resplen == 0) {
if (res == PM3_ETIMEOUT)
PrintAndLogEx(ERR, "No card in the field or card command timeout.");
else
PrintAndLogEx(ERR, "Error get config. Maybe not a Gen4 card?. error=%d rlen=%zu", res, resplen);
return PM3_ESOFT;
int res = 0;
if (dlen != 32) {
res = mfG4GetConfig(pwd, resp, &resplen, verbose);
if (res != PM3_SUCCESS || resplen == 0) {
if (res == PM3_ETIMEOUT)
PrintAndLogEx(ERR, "No card in the field or card command timeout.");
else
PrintAndLogEx(ERR, "Error get config. Maybe not a Gen4 card?. error=%d rlen=%zu", res, resplen);
return PM3_ESOFT;
}
} else {
memcpy(resp, data, dlen);
resplen = 32;
}
PrintAndLogEx(INFO, "---------- Gen4 configuration ----------");
if (resplen != 30 && resplen != 32) {
PrintAndLogEx(INFO, "Raw config [%02zu] %s", resplen, sprint_hex_inrow(resp, resplen));
PrintAndLogEx(WARNING, "Unknown config format");
return PM3_SUCCESS;
}
if (verbose)
PrintAndLogEx(INFO, "Raw config [%02zu]..... %s", resplen, sprint_hex_inrow(resp, resplen));
PrintAndLogEx(INFO, "UL protocol......... %02x" NOLF, resp[0]);
switch (resp[0]) {
case 0x00:
PrintAndLogEx(NORMAL, " (MIFARE Classic mode)");
break;
case 0x01:
PrintAndLogEx(NORMAL, " (MIFARE Ultralight/NTAG mode)");
break;
default:
PrintAndLogEx(NORMAL, " (unknown %02x)", resp[0]);
break;
}
parse_gtu_cfg(resp, resplen);
uint8_t uid_len = resp[1];
PrintAndLogEx(INFO, "UID length.......... %02x" NOLF, resp[1]);
switch (resp[1]) {
case 0x00:
PrintAndLogEx(NORMAL, " (4 byte)");
break;
case 0x01:
PrintAndLogEx(NORMAL, " (7 byte)");
break;
case 0x02:
PrintAndLogEx(NORMAL, " (10 byte)");
break;
default:
PrintAndLogEx(NORMAL, " (unknown %02x)", resp[1]);
break;
}
PrintAndLogEx(INFO, "Password............ %s", sprint_hex_inrow(&resp[2], 4));
PrintAndLogEx(INFO, "GTU mode............ %02x" NOLF, resp[6]);
switch (resp[6]) {
case 0x00:
PrintAndLogEx(NORMAL, " (pre-write, shadow data can be written)");
break;
case 0x01:
PrintAndLogEx(NORMAL, " (restore mode)");
break;
case 0x02:
PrintAndLogEx(NORMAL, " (disabled)");
break;
case 0x03:
PrintAndLogEx(NORMAL, " (disabled, high speed R/W mode for Ultralight?)");
break;
default:
PrintAndLogEx(NORMAL, " (unknown %02x)", resp[6]);
break;
}
PrintAndLogEx(INFO, "ATS [%02d]............ %s", resp[7], sprint_hex_inrow(&resp[8], resp[7]));
PrintAndLogEx(INFO, "ATQA................ %02x%02x", resp[25], resp[24]);
PrintAndLogEx(INFO, "SAK................. %02x", resp[26]);
PrintAndLogEx(INFO, "UL mode............. %02x" NOLF, resp[27]);
switch (resp[27]) {
case 0x00:
PrintAndLogEx(NORMAL, " (UL EV1)");
break;
case 0x01:
PrintAndLogEx(NORMAL, " (NTAG)");
break;
case 0x02:
PrintAndLogEx(NORMAL, " (UL-C)");
break;
case 0x03:
PrintAndLogEx(NORMAL, " (UL)");
break;
default:
PrintAndLogEx(NORMAL, " (unknown %02x)", resp[27]);
break;
}
PrintAndLogEx(INFO, "max rd/wr sectors... %02x", resp[28]);
PrintAndLogEx(INFO, "block0 direct wr.... %02x" NOLF, resp[29]);
switch (resp[29]) {
case 0x00:
PrintAndLogEx(NORMAL, " (Activate direct write to block 0 (Same behaviour of Gen2 cards. Some readers may identify the card as magic))");
break;
case 0x01:
PrintAndLogEx(NORMAL, " (Deactivate direct write to block 0 (Same behaviour of vanilla cards))");
break;
case 0x02:
PrintAndLogEx(NORMAL, " (Default value. Same behaviour as 00?");
break;
default:
PrintAndLogEx(NORMAL, " (unknown %02x)", resp[29]);
break;
}
res = mfG4GetFactoryTest(pwd, resp, &resplen, false);
if (res == PM3_SUCCESS && resplen > 2) {
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, _CYAN_("Factory test"));
if (verbose) {
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, "Raw test [%02zu]....... %s", resplen, sprint_hex_inrow(resp, resplen));
PrintAndLogEx(INFO, "Raw......... %s", sprint_hex_inrow(resp, resplen));
}
if (resp[resplen - 2] == 0x66 && resp[resplen - 1] == 0x66)
PrintAndLogEx(INFO, "Card type........... generic");
else if (resp[resplen - 2] == 0x02 && resp[resplen - 1] == 0xaa)
PrintAndLogEx(INFO, "Card type........... limited functionality");
else if (resp[resplen - 2] == 0x03 && resp[resplen - 1] == 0xa0)
PrintAndLogEx(INFO, "Card type........... old card version");
else if (resp[resplen - 2] == 0x06 && resp[resplen - 1] == 0xa0)
PrintAndLogEx(INFO, "Card type........... new card version");
else
PrintAndLogEx(INFO, "Card type........... unknown %02x%02x", resp[resplen - 2], resp[resplen - 1]);
if (memcmp(resp + resplen - 2, "\x66\x66", 2) == 0) {
PrintAndLogEx(INFO, "Card type... Generic");
} else if (memcmp(resp + resplen - 2, "\x02\xAA", 2) == 0) {
PrintAndLogEx(INFO, "Card type... " _RED_("Limited functionality"));
} else if (memcmp(resp + resplen - 2, "\x03\xA0", 2) == 0) {
PrintAndLogEx(INFO, "Card type... Old card version");
} else if (memcmp(resp + resplen - 2, "\x06\xA0", 2) == 0) {
PrintAndLogEx(INFO, "Card type... " _GREEN_("New card version"));
} else {
PrintAndLogEx(INFO, "Card type... " _RED_("unknown %02X%02X"), resp[resplen - 2], resp[resplen - 1]);
}
}
// read block 0
res = mfG4GetBlock(pwd, 0, resp, MAGIC_INIT | MAGIC_OFF);
if (res == PM3_SUCCESS) {
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, "Block 0............. %s", sprint_hex_inrow(resp, 16));
PrintAndLogEx(INFO, _CYAN_("Block 0 test"));
PrintAndLogEx(INFO, "Block 0..... %s", sprint_hex_inrow(resp, 16));
switch (uid_len) {
case 0x00:
PrintAndLogEx(INFO, "UID [4]............. %s", sprint_hex(resp, 4));
PrintAndLogEx(INFO, "UID [4]..... %s", sprint_hex_inrow(resp, 4));
break;
case 0x01:
PrintAndLogEx(INFO, "UID [7]............. %s", sprint_hex(resp, 7));
PrintAndLogEx(INFO, "UID [7]..... %s", sprint_hex_inrow(resp, 7));
break;
case 0x02:
PrintAndLogEx(INFO, "UID [10]............ %s", sprint_hex(resp, 10));
PrintAndLogEx(INFO, "UID [10..... %s", sprint_hex_inrow(resp, 10));
break;
default:
break;
}
}
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
@@ -8496,7 +8558,8 @@ static int CmdHF14AGen4ChangePwd(const char *Cmd) {
}
static void parse_gdm_cfg(const uint8_t *d) {
PrintAndLogEx(SUCCESS, "------------------- " _CYAN_("GDM Configuration") " -----------------------------------------");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "------------------- " _CYAN_("GDM Gen4 Configuration") " -----------------------------------------");
PrintAndLogEx(SUCCESS, _YELLOW_("%s"), sprint_hex_inrow(d, MFBLOCK_SIZE));
PrintAndLogEx(SUCCESS, _YELLOW_("%02X%02X") "............................ %s %s"
, d[0]
@@ -8504,10 +8567,10 @@ static void parse_gdm_cfg(const uint8_t *d) {
, (d[0] == 0x85 && d[1] == 0x00) ? "Magic wakeup disabled" : _GREEN_("Magic wakeup enabled")
, (d[0] == 0x85 && d[1] == 0x00) ? "" : ((d[0] == 0x7A && d[1] == 0xFF) ? _GREEN_("with GDM cfg block access") : _RED_(", no GDM cfg block access"))
);
PrintAndLogEx(SUCCESS, "...." _YELLOW_("%02X") ".......................... Magic wakeup style %s", d[2], ((d[2] == 0x85) ? "GDM 20(7)/23" : "Gen1a 40(7)/43"));
PrintAndLogEx(SUCCESS, "......" _YELLOW_("%02X%02X%02X") ".................... n/a", d[3], d[4], d[5]);
PrintAndLogEx(SUCCESS, "...." _YELLOW_("%02X") ".......................... Magic wakeup style " _YELLOW_("%s"), d[2], ((d[2] == 0x85) ? "GDM 20(7)/23" : "Gen1a 40(7)/43"));
PrintAndLogEx(SUCCESS, "......" _YELLOW_("%02X%02X%02X") ".................... unknown", d[3], d[4], d[5]);
PrintAndLogEx(SUCCESS, "............" _YELLOW_("%02X") ".................. %s", d[6], (d[6] == 0x5A) ? "Key B use blocked when readable by ACL" : "Key B use allowed when readable by ACL");
PrintAndLogEx(SUCCESS, ".............." _YELLOW_("%02X") "................ %s", d[7], (d[7] == 0x5A) ? _GREEN_("CUID - Block 0 Direct Write Enabled") : "CUID - Block 0 Direct Write Disabled");
PrintAndLogEx(SUCCESS, ".............." _YELLOW_("%02X") "................ %s", d[7], (d[7] == 0x5A) ? _GREEN_("CUID enabled") : "CUID Disabled");
PrintAndLogEx(SUCCESS, "................" _YELLOW_("%02X") ".............. n/a", d[8]);
const char *pers;
@@ -8531,13 +8594,14 @@ static void parse_gdm_cfg(const uint8_t *d) {
pers = "4B UID from Block 0";
break;
}
PrintAndLogEx(SUCCESS, ".................." _YELLOW_("%02X") "............ MFC EV1 perso... " _YELLOW_("%s"), d[9], pers);
PrintAndLogEx(SUCCESS, ".................." _YELLOW_("%02X") "............ MFC EV1 perso. " _YELLOW_("%s"), d[9], pers);
PrintAndLogEx(SUCCESS, "...................." _YELLOW_("%02X") ".......... %s", d[10], (d[10] == 0x5A) ? _GREEN_("Shadow mode enabled") : "Shadow mode disabled");
PrintAndLogEx(SUCCESS, "......................" _YELLOW_("%02X") "........ %s", d[11], (d[11] == 0x5A) ? _GREEN_("Magic auth enabled") : "Magic auth disabled");
PrintAndLogEx(SUCCESS, "........................" _YELLOW_("%02X") "...... %s", d[12], (d[12] == 0x5A) ? _GREEN_("Static encrypted nonce enabled") : "Static encrypted nonce disabled");
PrintAndLogEx(SUCCESS, ".........................." _YELLOW_("%02X") ".... %s", d[13], (d[13] == 0x5A) ? _GREEN_("MFC EV1 signature enabled") : "MFC EV1 signature disabled");
PrintAndLogEx(SUCCESS, "............................" _YELLOW_("%02X") ".. n/a", d[14]);
PrintAndLogEx(SUCCESS, ".............................." _YELLOW_("%02X") " SAK", d[15]);
PrintAndLogEx(NORMAL, "");
}
static int CmdHF14AGen4_GDM_ParseCfg(const char *Cmd) {
@@ -9298,7 +9362,6 @@ static int CmdHF14AMfInfo(const char *Cmd) {
if (verbose) {
PrintAndLogEx(SUCCESS, "ATQA: %02X %02X", card.atqa[1], card.atqa[0]);
}
return select_status;
}
@@ -9398,7 +9461,7 @@ static int CmdHF14AMfInfo(const char *Cmd) {
(blockdata[8] == 0x04 && blockdata[15] == 0x90) ||
(memcmp(blockdata + 8, "\x62\x63\x64\x65\x66\x67\x68\x69", 8) == 0)
) {
PrintAndLogEx(SUCCESS, "FUDAN detected");
PrintAndLogEx(SUCCESS, "FUDAN based card");
}
if (e_sector[1].foundKey[MF_KEY_A] && (e_sector[1].Key[MF_KEY_A] == 0x2A2C13CC242A)) {
+130 -42
View File
@@ -144,7 +144,9 @@ typedef enum {
DESFIRE_EV3,
DESFIRE_LIGHT,
PLUS_EV1,
PLUS_EV2,
NTAG413DNA,
NTAG424,
} nxp_cardtype_t;
typedef enum {
@@ -244,27 +246,31 @@ static char *getProtocolStr(uint8_t id, bool hw) {
return buf;
}
static char *getVersionStr(uint8_t major, uint8_t minor) {
static char *getVersionStr(uint8_t type, uint8_t major, uint8_t minor) {
static char buf[40] = {0x00};
char *retStr = buf;
if (major == 0x00)
if (type == 0x01 && major == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire MF3ICD40") " )", major, minor);
else if (major == 0x01 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV1") " )", major, minor);
else if (major == 0x12 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2") " )", major, minor);
else if (major == 0x22 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2 XL") " )", major, minor);
else if (major == 0x42 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2") " )", major, minor);
else if (major == 0x33 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV3") " )", major, minor);
else if (major == 0x30 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire Light") " )", major, minor);
else if (major == 0x10 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("NTAG413DNA") " )", major, minor);
else if (type == 0x01 && major == 0x01 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV1") " )", major, minor);
else if (type == 0x01 && major == 0x12 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2") " )", major, minor);
else if (type == 0x01 && major == 0x22 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2 XL") " )", major, minor);
else if (type == 0x01 && major == 0x42 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2") " )", major, minor);
else if (type == 0x01 && major == 0x33 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV3") " )", major, minor);
else if (type == 0x01 && major == 0x30 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire Light") " )", major, minor);
else if (type == 0x02 && major == 0x11 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("Plus EV1") " )", major, minor);
else if (type == 0x02 && major == 0x22 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("Plus EV2") " )", major, minor);
else
snprintf(retStr, sizeof(buf), "%x.%x ( " _YELLOW_("Unknown") " )", major, minor);
return buf;
@@ -272,6 +278,34 @@ static char *getVersionStr(uint8_t major, uint8_t minor) {
//04 01 01 01 00 1A 05
}
static char *getTypeStr(uint8_t type) {
static char buf[40] = {0x00};
char *retStr = buf;
switch (type) {
case 0x01:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("DESFire") " )", type);
break;
case 0x02:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("Plus") " )", type);
break;
case 0x03:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("Ultralight") " )", type);
break;
case 0x04:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("NTAG") " )", type);
break;
case 0x81:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("Smartcard") " )", type);
break;
default:
break;
}
return buf;
}
static char noCommentStr[1] = { 0x00 };
static const char *getAidCommentStr(uint8_t *aid) {
for (int i = 0; i < ARRAYLEN(commonAids); i++) {
@@ -282,26 +316,51 @@ static const char *getAidCommentStr(uint8_t *aid) {
return noCommentStr;
}
static nxp_cardtype_t getCardType(uint8_t major, uint8_t minor) {
static nxp_cardtype_t getCardType(uint8_t type, uint8_t major, uint8_t minor) {
if (major == 0x00)
// DESFire MF3ICD40
if (type == 0x01 && major == 0x00 && minor == 0x02)
return DESFIRE_MF3ICD40;
if (major == 0x01 && minor == 0x00)
// DESFire EV1
if (type == 0x01 && major == 0x01 && minor == 0x00)
return DESFIRE_EV1;
if (major == 0x12 && minor == 0x00)
// DESFire EV2
if (type == 0x01 && major == 0x12 && minor == 0x00)
return DESFIRE_EV2;
if (major == 0x22 && minor == 0x00)
if (type == 0x01 && major == 0x22 && minor == 0x00)
return DESFIRE_EV2_XL;
if (major == 0x42 && minor == 0x00)
return DESFIRE_EV2;
if (major == 0x33 && minor == 0x00)
// DESFire EV3
if (type == 0x01 && major == 0x33 && minor == 0x00)
return DESFIRE_EV3;
if (major == 0x30 && minor == 0x00)
// DESFire Light
if (type == 0x08 && major == 0x30 && minor == 0x00)
return DESFIRE_LIGHT;
if (major == 0x11 && minor == 0x00)
// combo card DESFire / EMV
if (type == 0x81 && major == 0x42 && minor == 0x00)
return DESFIRE_EV2;
// Plus EV1
if (type == 0x02 && major == 0x11 && minor == 0x00)
return PLUS_EV1;
// Plus Ev2
if (type == 0x02 && major == 0x22 && minor == 0x00)
return PLUS_EV2;
// NTAG 413 DNA
if (major == 0x10 && minor == 0x00)
return NTAG413DNA;
// NTAG 424
if (type == 0x04 && major == 0x30 && minor == 0x00)
return NTAG424;
return DESFIRE_UNKNOWN;
}
@@ -341,9 +400,9 @@ static const char *getProductTypeStr(const uint8_t *versionhw) {
}
static int mfdes_get_info(mfdes_info_res_t *info) {
SendCommandNG(CMD_HF_DESFIRE_INFO, NULL, 0);
PacketResponseNG resp;
PacketResponseNG resp;
SendCommandNG(CMD_HF_DESFIRE_INFO, NULL, 0);
if (WaitForResponseTimeout(CMD_HF_DESFIRE_INFO, &resp, 1500) == false) {
PrintAndLogEx(WARNING, "Command execute timeout");
DropField();
@@ -353,6 +412,7 @@ static int mfdes_get_info(mfdes_info_res_t *info) {
memcpy(info, resp.data.asBytes, sizeof(mfdes_info_res_t));
if (resp.status != PM3_SUCCESS) {
switch (info->isOK) {
case 1:
PrintAndLogEx(WARNING, "Can't select card");
@@ -657,13 +717,33 @@ static int CmdHF14ADesInfo(const char *Cmd) {
return res;
}
nxp_cardtype_t cardtype = getCardType(info.versionHW[3], info.versionHW[4]);
nxp_cardtype_t cardtype = getCardType(info.versionHW[1], info.versionHW[3], info.versionHW[4]);
if (cardtype == PLUS_EV1) {
PrintAndLogEx(INFO, "Card seems to be MIFARE Plus EV1. Try " _YELLOW_("`hf mfp info`"));
DropField();
return PM3_SUCCESS;
}
if (cardtype == PLUS_EV2) {
PrintAndLogEx(INFO, "Card seems to be MIFARE Plus EV2. Try " _YELLOW_("`hf mfp info`"));
DropField();
return PM3_SUCCESS;
}
if (cardtype == NTAG424) {
PrintAndLogEx(INFO, "Card seems to be NTAG 424. Try " _YELLOW_("`hf ntag424 info`"));
DropField();
return PM3_SUCCESS;
}
if (cardtype == DESFIRE_UNKNOWN) {
PrintAndLogEx(INFO, "HW Version.. %s", sprint_hex_inrow(info.versionHW, sizeof(info.versionHW)));
PrintAndLogEx(INFO, "SW Version.. %s", sprint_hex_inrow(info.versionSW, sizeof(info.versionSW)));
PrintAndLogEx(INFO, "Version data identification failed. Report to Iceman!");
DropField();
return PM3_SUCCESS;
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "---------------------------------- " _CYAN_("Tag Information") " ----------------------------------");
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(info.uid, info.uidlen));
@@ -680,16 +760,16 @@ static int CmdHF14ADesInfo(const char *Cmd) {
PrintAndLogEx(INFO, " raw: %s", sprint_hex_inrow(info.versionHW, sizeof(info.versionHW)));
PrintAndLogEx(INFO, " Vendor Id: " _YELLOW_("%s"), getTagInfo(info.versionHW[0]));
PrintAndLogEx(INFO, " Type: " _YELLOW_("0x%02X"), info.versionHW[1]);
PrintAndLogEx(INFO, " Type: %s", getTypeStr(info.versionHW[1]));
PrintAndLogEx(INFO, " Subtype: " _YELLOW_("0x%02X"), info.versionHW[2]);
PrintAndLogEx(INFO, " Version: %s", getVersionStr(info.versionHW[3], info.versionHW[4]));
PrintAndLogEx(INFO, " Version: %s", getVersionStr(info.versionHW[1], info.versionHW[3], info.versionHW[4]));
PrintAndLogEx(INFO, " Storage size: %s", getCardSizeStr(info.versionHW[5]));
PrintAndLogEx(INFO, " Protocol: %s", getProtocolStr(info.versionHW[6], true));
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Software Information"));
PrintAndLogEx(INFO, " raw: %s", sprint_hex_inrow(info.versionSW, sizeof(info.versionSW)));
PrintAndLogEx(INFO, " Vendor Id: " _YELLOW_("%s"), getTagInfo(info.versionSW[0]));
PrintAndLogEx(INFO, " Type: " _YELLOW_("0x%02X"), info.versionSW[1]);
PrintAndLogEx(INFO, " Type: %s", getTypeStr(info.versionSW[1]));
PrintAndLogEx(INFO, " Subtype: " _YELLOW_("0x%02X"), info.versionSW[2]);
PrintAndLogEx(INFO, " Version: " _YELLOW_("%d.%d"), info.versionSW[3], info.versionSW[4]);
PrintAndLogEx(INFO, " Storage size: %s", getCardSizeStr(info.versionSW[5]));
@@ -1339,8 +1419,9 @@ static int CmdHF14aDesChk(const char *Cmd) {
}
if (pattern2b && startPattern < 0x10000) {
if (verbose == false)
if (verbose == false) {
PrintAndLogEx(NORMAL, "p" NOLF);
}
aeskeyListLen = 0;
deskeyListLen = 0;
@@ -1350,29 +1431,34 @@ static int CmdHF14aDesChk(const char *Cmd) {
}
if (dict_filenamelen) {
if (verbose == false)
if (verbose == false) {
PrintAndLogEx(NORMAL, "d" NOLF);
}
uint32_t keycnt = 0;
res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 16, &keycnt, endFilePosition, &endFilePosition, false);
if (res == PM3_SUCCESS && endFilePosition)
if (res == PM3_SUCCESS && endFilePosition) {
deskeyListLen = keycnt;
}
keycnt = 0;
res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &keycnt, endFilePosition, &endFilePosition, false);
if (res == PM3_SUCCESS && endFilePosition)
if (res == PM3_SUCCESS && endFilePosition) {
aeskeyListLen = keycnt;
}
keycnt = 0;
res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 16, &keycnt, endFilePosition, &endFilePosition, false);
if (res == PM3_SUCCESS && endFilePosition)
if (res == PM3_SUCCESS && endFilePosition) {
k3kkeyListLen = keycnt;
}
continue;
}
}
if (verbose == false)
if (verbose == false) {
PrintAndLogEx(NORMAL, "");
}
// save keys to json
if ((jsonnamelen > 0) && result) {
@@ -2661,7 +2747,7 @@ static int CmdHF14ADesDeleteApp(const char *Cmd) {
arg_str0("m", "cmode", "<plain|mac|encrypt>", "Communicaton mode"),
arg_str0("c", "ccset", "<native|niso|iso>", "Communicaton command set"),
arg_str0(NULL, "schann", "<d40|ev1|ev2|lrp>", "Secure channel"),
arg_str0(NULL, "aid", "<hex>", "Application ID of delegated application (3 hex bytes, big endian)"),
arg_str0(NULL, "aid", "<hex>", "Application ID to delete (3 hex bytes, big endian)"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -2686,7 +2772,7 @@ static int CmdHF14ADesDeleteApp(const char *Cmd) {
return PM3_ESOFT;
}
res = DesfireSelectAndAuthenticate(&dctx, securechann, appid, verbose);
res = DesfireSelectAndAuthenticate(&dctx, securechann, 0x000000, verbose);
if (res != PM3_SUCCESS) {
DropField();
return res;
@@ -4768,13 +4854,15 @@ static int DesfileReadFileAndPrint(DesfireContext_t *dctx,
PrintAndLogEx(WARNING, "File needs to be authenticated with key 0x%02x or 0x%02x but current authentication key is 0x%02x", fsettings.rAccess, fsettings.rwAccess, dctx->keyNum);
if (fsettings.rAccess == 0x0f && fsettings.rwAccess == 0x0f)
PrintAndLogEx(WARNING, "File access denied. All read access rights is 0x0f.");
PrintAndLogEx(WARNING, "File access denied. All read access rights is 0x0F");
if (verbose)
PrintAndLogEx(INFO, "Got file type: %s. Option: %s. comm mode: %s",
if (verbose) {
PrintAndLogEx(INFO, _CYAN_("File type:") " %s Option: %s comm mode: %s",
GetDesfireFileType(fsettings.fileType),
CLIGetOptionListStr(DesfireReadFileTypeOpts, filetype),
CLIGetOptionListStr(DesfireCommunicationModeOpts, fsettings.commMode));
CLIGetOptionListStr(DesfireCommunicationModeOpts, fsettings.commMode)
);
}
} else {
PrintAndLogEx(WARNING, "GetFileSettings error. Can't get file type.");
}
+103 -50
View File
@@ -83,23 +83,31 @@ static char *getProtocolStr(uint8_t id, bool hw) {
return buf;
}
static char *getVersionStr(uint8_t major, uint8_t minor) {
static char *getVersionStr(uint8_t type, uint8_t major, uint8_t minor) {
static char buf[40] = {0x00};
char *retStr = buf;
if (major == 0x00)
if (type == 0x01 && major == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire MF3ICD40") " )", major, minor);
else if (major == 0x01 && minor == 0x00)
else if (major == 0x10 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("NTAG413DNA") " )", major, minor);
else if (type == 0x01 && major == 0x01 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV1") " )", major, minor);
else if (major == 0x12 && minor == 0x00)
else if (type == 0x01 && major == 0x12 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2") " )", major, minor);
else if (major == 0x33 && minor == 0x00)
else if (type == 0x01 && major == 0x22 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2 XL") " )", major, minor);
else if (type == 0x01 && major == 0x42 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV2") " )", major, minor);
else if (type == 0x01 && major == 0x33 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire EV3") " )", major, minor);
else if (major == 0x30 && minor == 0x00)
else if (type == 0x01 && major == 0x30 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("DESFire Light") " )", major, minor);
else if (major == 0x11 && minor == 0x00)
else if (type == 0x02 && major == 0x11 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("Plus EV1") " )", major, minor);
else if (type == 0x02 && major == 0x22 && minor == 0x00)
snprintf(retStr, sizeof(buf), "%x.%x ( " _GREEN_("Plus EV2") " )", major, minor);
else
snprintf(retStr, sizeof(buf), "%x.%x ( " _YELLOW_("Unknown") " )", major, minor);
return buf;
@@ -111,50 +119,72 @@ static char *getTypeStr(uint8_t type) {
char *retStr = buf;
switch (type) {
case 1:
case 0x01:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("DESFire") " )", type);
break;
case 2:
case 0x02:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("Plus") " )", type);
break;
case 3:
case 0x03:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("Ultralight") " )", type);
break;
case 4:
case 0x04:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("NTAG") " )", type);
break;
case 0x81:
snprintf(retStr, sizeof(buf), "0x%02X ( " _YELLOW_("Smartcard") " )", type);
break;
default:
break;
}
return buf;
}
static nxp_cardtype_t getCardType(uint8_t major, uint8_t minor) {
static nxp_cardtype_t getCardType(uint8_t type, uint8_t major, uint8_t minor) {
// DESFire MF3ICD40
if (major == 0x00 && minor == 0x00)
if (type == 0x01 && major == 0x00 && minor == 0x02)
return DESFIRE_MF3ICD40;
// DESFire EV1
if (major == 0x01 && minor == 0x00)
if (type == 0x01 && major == 0x01 && minor == 0x00)
return DESFIRE_EV1;
// DESFire EV2
if (major == 0x12 && minor == 0x00)
if (type == 0x01 && major == 0x12 && minor == 0x00)
return DESFIRE_EV2;
if (type == 0x01 && major == 0x22 && minor == 0x00)
return DESFIRE_EV2_XL;
// DESFire EV3
if (major == 0x33 && minor == 0x00)
if (type == 0x01 && major == 0x33 && minor == 0x00)
return DESFIRE_EV3;
// DESFire Light
if (major == 0x30 && minor == 0x00)
if (type == 0x08 && major == 0x30 && minor == 0x00)
return DESFIRE_LIGHT;
// combo card DESFire / EMV
if (type == 0x81 && major == 0x42 && minor == 0x00)
return DESFIRE_EV2;
// Plus EV1
if (major == 0x11 && minor == 0x00)
if (type == 0x02 && major == 0x11 && minor == 0x00)
return PLUS_EV1;
// Plus Ev2
if (type == 0x02 && major == 0x22 && minor == 0x00)
return PLUS_EV2;
// NTAG 413 DNA
if (type == 0x04 && major == 0x10 && minor == 0x00)
return NTAG413DNA;
// NTAG 424
if (type == 0x04 && major == 0x30 && minor == 0x00)
return NTAG424;
return MFP_UNKNOWN;
}
@@ -241,7 +271,7 @@ static int plus_print_version(uint8_t *version) {
PrintAndLogEx(INFO, " Vendor Id: " _YELLOW_("%s"), getTagInfo(version[0]));
PrintAndLogEx(INFO, " Type: %s", getTypeStr(version[1]));
PrintAndLogEx(INFO, " Subtype: " _YELLOW_("0x%02X"), version[2]);
PrintAndLogEx(INFO, " Version: %s", getVersionStr(version[3], version[4]));
PrintAndLogEx(INFO, " Version: %s", getVersionStr(version[1], version[3], version[4]));
PrintAndLogEx(INFO, " Storage size: %s", getCardSizeStr(version[5]));
PrintAndLogEx(INFO, " Protocol: %s", getProtocolStr(version[6], true));
PrintAndLogEx(NORMAL, "");
@@ -324,17 +354,41 @@ static int CmdHFMFPInfo(const char *Cmd) {
if (supportVersion) {
int cardtype = getCardType(version[3], version[4]);
if (cardtype == 6) {
if (supportSignature) {
PrintAndLogEx(INFO, " Tech...... " _GREEN_("MIFARE Plus EV1"));
} else {
PrintAndLogEx(INFO, " Tech...... " _YELLOW_("MIFARE Plus SE/X"));
int cardtype = getCardType(version[1], version[3], version[4]);
switch (cardtype) {
case PLUS_EV1: {
if (supportSignature) {
PrintAndLogEx(INFO, "Tech..... " _GREEN_("MIFARE Plus EV1"));
} else {
PrintAndLogEx(INFO, "Tech..... " _YELLOW_("MIFARE Plus SE/X"));
}
isPlus = true;
break;
}
case PLUS_EV2: {
if (supportSignature) {
PrintAndLogEx(INFO, "Tech..... " _GREEN_("MIFARE Plus EV2"));
} else {
PrintAndLogEx(INFO, "Tech..... " _YELLOW_("MIFARE Plus EV2 ???"));
}
isPlus = true;
break;
}
case DESFIRE_MF3ICD40:
case DESFIRE_EV1:
case DESFIRE_EV2:
case DESFIRE_EV2_XL:
case DESFIRE_EV3:
case DESFIRE_LIGHT: {
PrintAndLogEx(HINT, "Card seems to be MIFARE DESFire. Try " _YELLOW_("`hf mfdes info`"));
PrintAndLogEx(NORMAL, "");
DropField();
return PM3_SUCCESS;
}
default: {
PrintAndLogEx(INFO, "Tech..... Unknown ( " _YELLOW_("%u") " )", cardtype);
break;
}
isPlus = true;
} else {
PrintAndLogEx(INFO, " Tech...... Unknown ( " _YELLOW_("%u") " )", cardtype);
}
}
@@ -343,37 +397,37 @@ static int CmdHFMFPInfo(const char *Cmd) {
uint16_t ATQA = card.atqa[0] + (card.atqa[1] << 8);
if (ATQA & 0x0004) {
PrintAndLogEx(INFO, " Size...... " _GREEN_("2K") " (%s UID)", (ATQA & 0x0040) ? "7" : "4");
PrintAndLogEx(INFO, "Size..... " _GREEN_("2K") " (%s UID)", (ATQA & 0x0040) ? "7" : "4");
isPlus = true;
}
if (ATQA & 0x0002) {
PrintAndLogEx(INFO, " Size...... " _GREEN_("4K") " (%s UID)", (ATQA & 0x0040) ? "7" : "4");
PrintAndLogEx(INFO, "Size..... " _GREEN_("4K") " (%s UID)", (ATQA & 0x0040) ? "7" : "4");
isPlus = true;
}
uint8_t SLmode = 0xFF;
if (isPlus) {
if (card.sak == 0x08) {
PrintAndLogEx(INFO, " SAK....... " _GREEN_("2K 7b UID"));
PrintAndLogEx(INFO, "SAK...... " _GREEN_("2K 7b UID"));
if (select_status == 2) SLmode = 1;
}
if (card.sak == 0x18) {
PrintAndLogEx(INFO, " SAK....... " _GREEN_("4K 7b UID"));
PrintAndLogEx(INFO, "SAK...... " _GREEN_("4K 7b UID"));
if (select_status == 2) SLmode = 1;
}
if (card.sak == 0x10) {
PrintAndLogEx(INFO, " SAK....... " _GREEN_("2K"));
PrintAndLogEx(INFO, "SAK...... " _GREEN_("2K"));
if (select_status == 2) SLmode = 2;
}
if (card.sak == 0x11) {
PrintAndLogEx(INFO, " SAK....... " _GREEN_("4K"));
PrintAndLogEx(INFO, "SAK...... " _GREEN_("4K"));
if (select_status == 2) SLmode = 2;
}
}
if (card.sak == 0x20) {
if (card.ats_len > 0) {
PrintAndLogEx(INFO, " SAK....... " _GREEN_("MIFARE Plus SL0/SL3") " or " _GREEN_("MIFARE DESFire"));
PrintAndLogEx(INFO, "SAK...... " _GREEN_("MIFARE Plus SL0/SL3") " or " _GREEN_("MIFARE DESFire"));
SLmode = 3;
// check SL0
uint8_t data[128] = {0};
@@ -382,7 +436,7 @@ static int CmdHFMFPInfo(const char *Cmd) {
uint8_t cmd[3 + 16] = {0xa8, 0x90, 0x90, 0x00};
int res = ExchangeRAW14a(cmd, sizeof(cmd), true, false, data, sizeof(data), &datalen, false);
if (res != PM3_SUCCESS) {
PrintAndLogEx(INFO, "identification failed");
PrintAndLogEx(INFO, "Identification failed");
PrintAndLogEx(NORMAL, "");
DropField();
return PM3_SUCCESS;
@@ -399,14 +453,14 @@ static int CmdHFMFPInfo(const char *Cmd) {
data[0] != 0x6E) {
PrintAndLogEx(INFO, _RED_("Send copy to iceman of this command output!"));
PrintAndLogEx(INFO, "data: %s", sprint_hex(data, datalen));
PrintAndLogEx(INFO, "Data... %s", sprint_hex(data, datalen));
}
if ((memcmp(data, "\x67\x00", 2) == 0) || // wrong length
(memcmp(data, "\x1C\x83\x0C", 3) == 0) // desfire answers
) {
PrintAndLogEx(INFO, " result.... " _RED_("MIFARE DESFire"));
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`hf mfdes info`"));
PrintAndLogEx(INFO, "Result... " _RED_("MIFARE DESFire"));
PrintAndLogEx(NORMAL, "");
DropField();
return PM3_SUCCESS;
@@ -415,11 +469,10 @@ static int CmdHFMFPInfo(const char *Cmd) {
// } else if (memcmp(data, "\x6E\x00", 2) == 0) { // Class not supported
isPlus = false;
} else {
PrintAndLogEx(INFO, " result.... " _GREEN_("MIFARE Plus SL0/SL3"));
PrintAndLogEx(INFO, "Result... " _GREEN_("MIFARE Plus SL0/SL3"));
}
if ((datalen > 1) &&
(data[0] == 0x09)) {
if ((datalen > 1) && (data[0] == 0x09)) {
SLmode = 0;
}
}
@@ -431,29 +484,29 @@ static int CmdHFMFPInfo(const char *Cmd) {
PrintAndLogEx(INFO, "--- " _CYAN_("Security Level (SL)"));
if (SLmode != 0xFF)
PrintAndLogEx(SUCCESS, " SL mode... " _YELLOW_("SL%d"), SLmode);
PrintAndLogEx(SUCCESS, "SL mode... " _YELLOW_("SL%d"), SLmode);
else
PrintAndLogEx(WARNING, " SL mode... " _YELLOW_("unknown"));
PrintAndLogEx(WARNING, "SL mode... " _YELLOW_("unknown"));
switch (SLmode) {
case 0:
PrintAndLogEx(INFO, " SL 0: initial delivery configuration, used for card personalization");
PrintAndLogEx(INFO, "SL 0: initial delivery configuration, used for card personalization");
break;
case 1:
PrintAndLogEx(INFO, " SL 1: backwards functional compatibility mode (with MIFARE Classic 1K / 4K) with an optional AES authentication");
PrintAndLogEx(INFO, "SL 1: backwards functional compatibility mode (with MIFARE Classic 1K / 4K) with an optional AES authentication");
break;
case 2:
PrintAndLogEx(INFO, " SL 2: 3-Pass Authentication based on AES followed by MIFARE CRYPTO1 authentication, communication secured by MIFARE CRYPTO1");
PrintAndLogEx(INFO, "SL 2: 3-Pass Authentication based on AES followed by MIFARE CRYPTO1 authentication, communication secured by MIFARE CRYPTO1");
break;
case 3:
PrintAndLogEx(INFO, " SL 3: 3-Pass authentication based on AES, data manipulation commands secured by AES encryption and an AES based MACing method.");
PrintAndLogEx(INFO, "SL 3: 3-Pass authentication based on AES, data manipulation commands secured by AES encryption and an AES based MACing method.");
break;
default:
break;
}
}
} else {
PrintAndLogEx(INFO, " Mifare Plus info not available");
PrintAndLogEx(INFO, "MIFARE Plus info not available");
}
PrintAndLogEx(NORMAL, "");
DropField();
+4
View File
@@ -25,9 +25,13 @@ typedef enum {
DESFIRE_MF3ICD40,
DESFIRE_EV1,
DESFIRE_EV2,
DESFIRE_EV2_XL,
DESFIRE_EV3,
DESFIRE_LIGHT,
PLUS_EV1,
PLUS_EV2,
NTAG413DNA,
NTAG424
} nxp_cardtype_t;
typedef struct mfp_key_item {
+14 -10
View File
@@ -215,11 +215,12 @@ int ul_read_uid(uint8_t *uid) {
PrintAndLogEx(DEBUG, "iso14443a card select failed");
return PM3_ESOFT;
}
memcpy(uid, card.uid, 7);
if (card.uidlen != 7) {
PrintAndLogEx(WARNING, "Wrong sized UID, expected 7 bytes, got " _RED_("%d"), card.uidlen);
return PM3_ESOFT;
return PM3_ELENGTH;
}
memcpy(uid, card.uid, 7);
return PM3_SUCCESS;
}
@@ -1245,13 +1246,16 @@ static int ulev1_print_signature(uint64_t tagtype, uint8_t *uid, uint8_t *signat
// ref: AN11350 NTAG 21x Originality Signature Validation
// ref: AN11341 MIFARE Ultralight EV1 Originality Signature Validation
const ecdsa_publickey_t nxp_mfu_public_keys[] = {
{"NXP MIFARE Classic MFC1C14_x", "044F6D3F294DEA5737F0F46FFEE88A356EED95695DD7E0C27A591E6F6F65962BAF"},
{"Manufacturer MIFARE Classic / QL88", "046F70AC557F5461CE5052C8E4A7838C11C7A236797E8A0730A101837C004039C2"},
{"NXP ICODE DNA, ICODE SLIX2", "048878A2A2D3EEC336B4F261A082BD71F9BE11C4E2E896648B32EFA59CEA6E59F0"},
{"NXP Public key", "04A748B6A632FBEE2C0897702B33BEA1C074998E17B84ACA04FF267E5D2C91F6DC"},
{"NXP Ultralight Ev1", "0490933BDCD6E99B4E255E3DA55389A827564E11718E017292FAF23226A96614B8"},
{"NXP NTAG21x (2013)", "04494E1A386D3D3CFE3DC10E5DE68A499B1C202DB5B132393E89ED19FE5BE8BC61"},
{"MIKRON Public key", "04F971EDA742A4A80D32DCF6A814A707CC3DC396D35902F72929FDCD698B3468F2"},
{"NXP MIFARE Classic MFC1C14_x", "044F6D3F294DEA5737F0F46FFEE88A356EED95695DD7E0C27A591E6F6F65962BAF"},
{"MIFARE Classic / QL88", "046F70AC557F5461CE5052C8E4A7838C11C7A236797E8A0730A101837C004039C2"},
{"NXP ICODE DNA, ICODE SLIX2", "048878A2A2D3EEC336B4F261A082BD71F9BE11C4E2E896648B32EFA59CEA6E59F0"},
{"NXP Public key", "04A748B6A632FBEE2C0897702B33BEA1C074998E17B84ACA04FF267E5D2C91F6DC"},
{"NXP Ultralight Ev1", "0490933BDCD6E99B4E255E3DA55389A827564E11718E017292FAF23226A96614B8"},
{"NXP NTAG21x (2013)", "04494E1A386D3D3CFE3DC10E5DE68A499B1C202DB5B132393E89ED19FE5BE8BC61"},
{"MIKRON Public key", "04F971EDA742A4A80D32DCF6A814A707CC3DC396D35902F72929FDCD698B3468F2"},
{"VivoKey Spark1 Public key", "04D64BB732C0D214E7EC580736ACF847284B502C25C0F7F2FA86AACE1DADA4387A"},
{"TruST25 (ST) key 01?", "041D92163650161A2548D33881C235D0FB2315C2C31A442F23C87ACF14497C0CBA"},
{"TruST25 (ST) key 04?", "04101E188A8B4CDDBC62D5BC3E0E6850F0C2730E744B79765A0E079907FBDB01BC"},
};
// https://www.nxp.com/docs/en/application-note/AN13452.pdf
@@ -3249,7 +3253,7 @@ int CmdHF14MfUTamper(const char *Cmd) {
}
}
if (enable | disable | lock_msg) {
if (enable || disable || lock_msg) {
if (ul_select(&card) == false) {
PrintAndLogEx(ERR, "Unable to select tag");
+7 -6
View File
@@ -38,6 +38,7 @@
// NTAG424 commands currently implemented
// icenam: should be able to use 14a / msdes to annotate NTAG424 communications
#define NTAG424_CMD_GET_FILE_SETTINGS 0xF5
#define NTAG424_CMD_CHANGE_FILE_SETTINGS 0x5F
#define NTAG424_CMD_CHANGE_KEY 0xC4
@@ -280,7 +281,7 @@ static void ntag424_calc_receive_iv(ntag424_session_keys_t *session_keys, uint8_
aes_encode(zero_iv, session_keys->encryption, iv_clear, out_ivc, 16);
}
static void ntag424_calc_mac(ntag424_session_keys_t *session_keys, uint8_t command, uint8_t *data, uint8_t datalen, uint8_t *out_mac) {
static void ntag424_calc_mac(const ntag424_session_keys_t *session_keys, uint8_t command, const uint8_t *data, uint8_t datalen, uint8_t *out_mac) {
uint8_t mac_input_header[] = { command,
(uint8_t)session_keys->command_counter, (uint8_t)(session_keys->command_counter >> 8),
session_keys->ti[0], session_keys->ti[1], session_keys->ti[2], session_keys->ti[3]
@@ -445,7 +446,7 @@ static int ntag424_get_file_settings(uint8_t fileno, ntag424_file_settings_t *se
return PM3_SUCCESS;
}
static int ntag424_write_file_settings(uint8_t fileno, ntag424_file_settings_t *settings, ntag424_session_keys_t *session_keys) {
static int ntag424_write_file_settings(uint8_t fileno, const ntag424_file_settings_t *settings, ntag424_session_keys_t *session_keys) {
// ------- Convert file settings to the format for writing
file_settings_write_t write_settings = {
@@ -807,7 +808,7 @@ static int ntag424_get_signature(uint8_t *signature_out) {
return PM3_SUCCESS;
}
static int ntag424_change_key(uint8_t keyno, uint8_t *new_key, uint8_t *old_key, uint8_t version, ntag424_session_keys_t *session_keys) {
static int ntag424_change_key(uint8_t keyno, const uint8_t *new_key, const uint8_t *old_key, uint8_t version, ntag424_session_keys_t *session_keys) {
// -------- Calculate xor and crc
uint8_t key[16] = {0};
uint8_t crc[4] = {0};
@@ -965,7 +966,7 @@ static int CmdHF_ntag424_auth(const char *Cmd) {
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
int keyno;
int keyno = 0;
uint8_t key[16] = {0};
if (ntag424_cli_get_auth_information(ctx, 1, 2, &keyno, key) != PM3_SUCCESS) {
CLIParserFree(ctx);
@@ -1019,7 +1020,7 @@ static int CmdHF_ntag424_read(const char *Cmd) {
int fileno = arg_get_int(ctx, 1);
int keyno;
int keyno = 0;
uint8_t key[16] = {0};
bool auth = (ntag424_cli_get_auth_information(ctx, 2, 3, &keyno, key) == PM3_SUCCESS);
@@ -1248,7 +1249,7 @@ static int CmdHF_ntag424_changefilesettings(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, false);
int fileno = arg_get_int(ctx, 1);
int keyno;
int keyno = 0;
uint8_t key[16] = {0};
uint8_t has_options = 0;
+9
View File
@@ -23,6 +23,7 @@
#define TIMEOUT 2000
// get ST Microelectronics chip model (from UID)
const char *get_st_chip_model(uint8_t pc) {
switch (pc) {
case 0x0:
@@ -41,12 +42,18 @@ const char *get_st_chip_model(uint8_t pc) {
return "SRT512";
case 0xC4:
return "ST25TA64K";
case 0xC5:
return "ST25TA16K";
case 0xE2:
return "ST25??? IKEA Rothult";
case 0xE3:
return "ST25TA02KB";
case 0xE4:
return "ST25TA512B";
case 0xE5:
return "ST25TA512";
case 0xA2:
return "ST25TA02K-P";
case 0xA3:
return "ST25TA02KB-P";
case 0xF3:
@@ -55,6 +62,8 @@ const char *get_st_chip_model(uint8_t pc) {
return "Unknown";
}
}
/*
// print UID info from SRx chips (ST Microelectronics)
void print_st_general_info(uint8_t *data, uint8_t len) {
+115 -2
View File
@@ -32,11 +32,37 @@
#include "cmdnfc.h" // print_type4_cc_info
#include "commonutil.h" // get_sw
#include "protocols.h" // ISO7816 APDU return codes
#include "crypto/libpcrypto.h" // ecdsa
#define TIMEOUT 2000
static int CmdHelp(const char *Cmd);
static bool st25ta_select(iso14a_card_select_t *card) {
clearCommandBuffer();
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 0, 0, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
DropField();
return false;
} else {
uint16_t len = (resp.oldarg[1] & 0xFFFF);
if (len == 0) {
PrintAndLogEx(DEBUG, "iso14443a card select failed");
DropField();
return false;
}
if (card) {
memcpy(card, resp.data.asBytes, sizeof(iso14a_card_select_t));
}
}
return true;
}
static void print_st25ta_system_info(uint8_t *d, uint8_t n) {
if (n < 0x12) {
PrintAndLogEx(WARNING, "Not enough bytes read from system file");
@@ -121,6 +147,86 @@ static void print_st25ta_system_info(uint8_t *d, uint8_t n) {
*/
}
static int print_st25ta_signature(uint8_t *uid, uint8_t *signature) {
#define PUBLIC_ECDA_KEYLEN 33
// known public keys for the originality check (source: https://github.com/alexbatalov/node-nxp-originality-verifier)
// ref: AN11350 NTAG 21x Originality Signature Validation
// ref: AN11341 MIFARE Ultralight EV1 Originality Signature Validation
const ecdsa_publickey_t nxp_mfu_public_keys[] = {
{"NXP MIFARE Classic MFC1C14_x", "044F6D3F294DEA5737F0F46FFEE88A356EED95695DD7E0C27A591E6F6F65962BAF"},
{"MIFARE Classic / QL88", "046F70AC557F5461CE5052C8E4A7838C11C7A236797E8A0730A101837C004039C2"},
{"NXP ICODE DNA, ICODE SLIX2", "048878A2A2D3EEC336B4F261A082BD71F9BE11C4E2E896648B32EFA59CEA6E59F0"},
{"NXP Public key", "04A748B6A632FBEE2C0897702B33BEA1C074998E17B84ACA04FF267E5D2C91F6DC"},
{"NXP Ultralight Ev1", "0490933BDCD6E99B4E255E3DA55389A827564E11718E017292FAF23226A96614B8"},
{"NXP NTAG21x (2013)", "04494E1A386D3D3CFE3DC10E5DE68A499B1C202DB5B132393E89ED19FE5BE8BC61"},
{"MIKRON Public key", "04F971EDA742A4A80D32DCF6A814A707CC3DC396D35902F72929FDCD698B3468F2"},
{"VivoKey Spark1 Public key", "04D64BB732C0D214E7EC580736ACF847284B502C25C0F7F2FA86AACE1DADA4387A"},
{"TruST25 (ST) key 01?", "041D92163650161A2548D33881C235D0FB2315C2C31A442F23C87ACF14497C0CBA"},
{"TruST25 (ST) key 04?", "04101E188A8B4CDDBC62D5BC3E0E6850F0C2730E744B79765A0E079907FBDB01BC"},
};
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Signature"));
for (uint8_t i = 0; i < ARRAYLEN(nxp_mfu_public_keys); i++) {
int dl = 0;
uint8_t key[PUBLIC_ECDA_KEYLEN] = {0};
param_gethex_to_eol(nxp_mfu_public_keys[i].value, 0, key, PUBLIC_ECDA_KEYLEN, &dl);
int res = ecdsa_signature_r_s_verify(MBEDTLS_ECP_DP_SECP128R1, key, uid, 7, signature, 32, true);
if (res == 0) {
PrintAndLogEx(INFO, " IC signature public key name: " _GREEN_("%s"), nxp_mfu_public_keys[i].desc);
PrintAndLogEx(INFO, "IC signature public key value: %s", nxp_mfu_public_keys[i].value);
PrintAndLogEx(INFO, " Elliptic curve parameters: NID_secp128r1");
PrintAndLogEx(INFO, " TAG IC Signature: %s", sprint_hex_inrow(signature, 32));
PrintAndLogEx(SUCCESS, " Signature verification ( " _GREEN_("successful") " )");
return PM3_SUCCESS;
}
}
return PM3_ESOFT;
}
static int st25ta_get_signature(uint8_t *signature) {
/*
hf 14a raw -sck 0200A4040007D276000085010100
hf 14a raw -ck 0300A4000C020001
hf 14a raw -c 02a2b000e020
*/
typedef struct {
const char *apdu;
uint8_t apdulen;
} transport_st25a_apdu_t;
transport_st25a_apdu_t cmds[] = {
{ "\x00\xA4\x04\x00\x07\xD2\x76\x00\x00\x85\x01\x01\x00", 13 },
{ "\x00\xA4\x00\x0C\x02\x00\x01", 7 },
{ "\xa2\xb0\x00\xe0\x20", 5 },
};
uint8_t resp[40] = {0};
int resplen = 0;
bool activate_field = true;
for (uint8_t i = 0; i < ARRAYLEN(cmds); i++) {
int res = ExchangeAPDU14a((uint8_t *)cmds[i].apdu, cmds[i].apdulen, activate_field, true, resp, sizeof(resp), &resplen);
if (res != PM3_SUCCESS) {
DropField();
return res;
}
activate_field = false;
}
if (signature) {
memcpy(signature, resp, 32);
}
DropField();
return PM3_SUCCESS;
}
// ST25TA
static int infoHFST25TA(void) {
@@ -225,13 +331,20 @@ static int infoHFST25TA(void) {
return PM3_ESOFT;
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------");
PrintAndLogEx(NORMAL, "");
iso14a_card_select_t card;
if (st25ta_select(&card)) {
uint8_t sig[32] = {0};
if (st25ta_get_signature(sig) == PM3_SUCCESS) {
print_st25ta_signature(card.uid, sig);
}
}
print_type4_cc_info(st_cc_data, sizeof(st_cc_data));
print_st25ta_system_info(response, resplen - 2);
return PM3_SUCCESS;
}
+8
View File
@@ -829,8 +829,16 @@ static int CmdHFTopazSniff(const char *Cmd) {
CLIParserFree(ctx);
uint8_t param = 0;
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " to abort sniffing");
SendCommandNG(CMD_HF_ISO14443A_SNIFF, (uint8_t *)&param, sizeof(uint8_t));
PacketResponseNG resp;
WaitForResponse(CMD_HF_ISO14443A_SNIFF, &resp);
PrintAndLogEx(INFO, "Done!");
PrintAndLogEx(HINT, "Try `" _YELLOW_("hf topaz list")"` to view captured tracelog");
PrintAndLogEx(HINT, "Try `" _YELLOW_("trace save -h") "` to save tracelog for later analysing");
return PM3_SUCCESS;
}
+2 -2
View File
@@ -1085,8 +1085,8 @@ static int CmdTune(const char *Cmd) {
, LF_DIV2FREQ(LF_DIVISOR_134)
);
g_GraphTraceLen = 256;
g_CursorCPos = LF_DIVISOR_125;
g_CursorDPos = LF_DIVISOR_134;
g_MarkerC.pos = LF_DIVISOR_125;
g_MarkerD.pos = LF_DIVISOR_134;
ShowGraphWindow();
RepaintGraphWindow();
} else {
+16 -5
View File
@@ -289,8 +289,9 @@ int CmdLFCommandRead(const char *Cmd) {
bool cm = arg_get_lit(ctx, 10);
CLIParserFree(ctx);
if (g_session.pm3_present == false)
if (g_session.pm3_present == false) {
return PM3_ENOTTY;
}
#define PAYLOAD_HEADER_SIZE (12 + (3 * LF_CMDREAD_MAX_EXTRA_SYMBOLS))
struct p {
@@ -311,6 +312,7 @@ int CmdLFCommandRead(const char *Cmd) {
payload.keep_field_on = keep_field_on;
payload.verbose = verbose;
memset(payload.symbol_extra, 0, sizeof(payload.symbol_extra));
memset(payload.period_extra, 0, sizeof(payload.period_extra));
if (add_crc_ht && (cmd_len <= 120)) {
// Hitag 1, Hitag S, ZX8211
@@ -1535,8 +1537,12 @@ static bool check_chiptype(bool getDeviceData) {
if (!getDeviceData) return retval;
save_restoreGB(GRAPH_SAVE);
save_restoreDB(GRAPH_SAVE);
//Save the state of the Graph and Demod Buffers
buffer_savestate_t saveState_gb = save_bufferS32(g_GraphBuffer, g_GraphTraceLen);
saveState_gb.offset = g_GridOffset;
buffer_savestate_t saveState_db = save_buffer8(g_DemodBuffer, g_DemodBufferLen);
saveState_db.clock = g_DemodClock;
saveState_db.offset = g_DemodStartIdx;
//check for em4x05/em4x69 chips first
uint32_t word = 0;
@@ -1575,8 +1581,13 @@ static bool check_chiptype(bool getDeviceData) {
PrintAndLogEx(INFO, "Couldn't identify a chipset");
out:
save_restoreGB(GRAPH_RESTORE);
save_restoreDB(GRAPH_RESTORE);
restore_buffer8(saveState_db, g_DemodBuffer);
g_DemodClock = saveState_db.clock;
g_DemodStartIdx = saveState_db.offset;
restore_bufferS32(saveState_gb, g_GraphBuffer);
g_GridOffset = saveState_gb.offset;
return retval;
}
+31 -9
View File
@@ -41,15 +41,17 @@ static int sendPing(void) {
SendCommandNG(CMD_PING, NULL, 0);
clearCommandBuffer();
PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_PING, &resp, 1000))
if (WaitForResponseTimeout(CMD_PING, &resp, 1000) == false) {
return PM3_ETIMEOUT;
}
return PM3_SUCCESS;
}
static int sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, size_t bs_len, bool verbose) {
if (verbose)
if (verbose) {
PrintAndLogEx(INFO, "Trying FC: " _YELLOW_("%u") " CN: " _YELLOW_("%u"), fc, cn);
}
if (getAWIDBits(fmtlen, fc, cn, bits) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Error with tag bitstream generation.");
@@ -149,7 +151,7 @@ int demodAWID(bool verbose) {
return PM3_EMALLOC;
}
size_t size = getFromGraphBuf(bits);
size_t size = getFromGraphBuffer(bits);
if (size == 0) {
PrintAndLogEx(DEBUG, "DEBUG: Error - AWID not enough samples");
free(bits);
@@ -205,6 +207,11 @@ int demodAWID(bool verbose) {
free(bits);
return PM3_ESOFT;
}
char binstr[68] = {0};
binarray_2_binstr(binstr, (char *)bits, size);
PrintAndLogEx(DEBUG, "no parity... %s", binstr);
// ok valid card found!
// Index map
@@ -230,35 +237,47 @@ int demodAWID(bool verbose) {
uint8_t fmtLen = bytebits_to_byte(bits, 8);
switch (fmtLen) {
case 26:
case 26: {
fc = bytebits_to_byte(bits + 9, 8);
cardnum = bytebits_to_byte(bits + 17, 16);
code1 = bytebits_to_byte(bits + 8, fmtLen);
PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, rawHi2, rawHi, rawLo);
break;
case 34:
}
case 34: {
fc = bytebits_to_byte(bits + 9, 8);
cardnum = bytebits_to_byte(bits + 17, 24);
code1 = bytebits_to_byte(bits + 8, (fmtLen - 32));
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
break;
case 37:
}
case 36: {
fc = bytebits_to_byte(bits + 14, 11);
cardnum = bytebits_to_byte(bits + 25, 18);
code1 = bytebits_to_byte(bits + 8, (fmtLen - 32));
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
break;
}
case 37: {
fc = bytebits_to_byte(bits + 9, 13);
cardnum = bytebits_to_byte(bits + 22, 18);
code1 = bytebits_to_byte(bits + 8, (fmtLen - 32));
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d")" FC: " _GREEN_("%d")" Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
break;
}
// case 40:
// break;
case 50:
case 50: {
fc = bytebits_to_byte(bits + 9, 16);
cardnum = bytebits_to_byte(bits + 25, 32);
code1 = bytebits_to_byte(bits + 8, (fmtLen - 32));
code2 = bytebits_to_byte(bits + 8 + (fmtLen - 32), 32);
PrintAndLogEx(SUCCESS, "AWID - len: " _GREEN_("%d") " FC: " _GREEN_("%d") " Card: " _GREEN_("%u") " - Wiegand: " _GREEN_("%x%08x") ", Raw: %08x%08x%08x", fmtLen, fc, cardnum, code1, code2, rawHi2, rawHi, rawLo);
break;
}
default:
if (fmtLen > 32) {
cardnum = bytebits_to_byte(bits + 8 + (fmtLen - 17), 16);
@@ -288,7 +307,9 @@ static int CmdAWIDDemod(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf awid demod",
"Try to find AWID Prox preamble, if found decode / descramble data",
"lf awid demod"
"lf awid demod\n"
"lf awid demod --raw "
);
void *argtable[] = {
@@ -566,9 +587,10 @@ static int CmdAWIDBrute(const char *Cmd) {
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "this help"},
{"brute", CmdAWIDBrute, IfPm3Lf, "bruteforce card number against reader"},
{"clone", CmdAWIDClone, IfPm3Lf, "clone AWID tag to T55x7, Q5/T5555 or EM4305/4469"},
{"demod", CmdAWIDDemod, AlwaysAvailable, "demodulate an AWID FSK tag from the GraphBuffer"},
{"reader", CmdAWIDReader, IfPm3Lf, "attempt to read and extract tag data"},
{"clone", CmdAWIDClone, IfPm3Lf, "clone AWID tag to T55x7 or Q5/T5555"},
{"sim", CmdAWIDSim, IfPm3Lf, "simulate AWID tag"},
{"brute", CmdAWIDBrute, IfPm3Lf, "bruteforce card number against reader"},
{"watch", CmdAWIDWatch, IfPm3Lf, "continuously watch for cards. Reader mode"},
+1 -1
View File
@@ -238,7 +238,7 @@ static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"demod", CmdDestronDemod, AlwaysAvailable, "demodulate an Destron tag from the GraphBuffer"},
{"reader", CmdDestronReader, IfPm3Lf, "attempt to read and extract tag data"},
{"clone", CmdDestronClone, IfPm3Lf, "clone Destron tag to T55x7"},
{"clone", CmdDestronClone, IfPm3Lf, "clone Destron tag to T55x7, Q5/T5555 or EM4305/4469"},
{"sim", CmdDestronSim, IfPm3Lf, "simulate Destron tag"},
{NULL, NULL, NULL, NULL}
};
+1 -1
View File
@@ -745,7 +745,7 @@ static command_t CommandTable[] = {
{"brute", CmdEM410xBrute, IfPm3Lf, "reader bruteforce attack by simulating EM410x tags"},
{"watch", CmdEM410xWatch, IfPm3Lf, "watches for EM410x 125/134 kHz tags"},
{"spoof", CmdEM410xSpoof, IfPm3Lf, "watches for EM410x 125/134 kHz tags, and replays them" },
{"clone", CmdEM410xClone, IfPm3Lf, "write EM410x Tag ID to T55x7 or Q5/T5555 tag"},
{"clone", CmdEM410xClone, IfPm3Lf, "clone EM410x Tag ID to T55x7, Q5/T5555 or EM4305/4469"},
{NULL, NULL, NULL, NULL}
};
+55 -20
View File
@@ -58,6 +58,40 @@ static const char *em4x69_annotation [] = {"Info", "UID", "Password", "Lock", "C
static int CmdHelp(const char *Cmd);
static int CmdEM4x05CloneHelp(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf em 4x05 clonehelp",
"Display a list of available commands for cloning specific techs on EM4305/4469 tags",
"lf em 4x05 clonehelp"
);
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
PrintAndLogEx(NORMAL, "For cloning specific techs on EM4305/4469 tags, see commands available in corresponding LF sub-menus, e.g.:");
PrintAndLogEx(NORMAL, _GREEN_("lf awid clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf destron clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf em 410x clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf fdxb clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf gallagher clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf hid clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf jablotron clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf keri clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf nedap clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf nexwatch clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf noralsy clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf pac clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf paradox clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf presco clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf pyramid clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf securakey clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf viking clone --em"));
PrintAndLogEx(NORMAL, _GREEN_("lf visa2000 clone --em"));
return PM3_SUCCESS;
}
// 1 = EM4x69
// 2 = EM4x05
static em_tech_type_t em_get_card_type(uint32_t config) {
@@ -141,7 +175,7 @@ static bool em4x05_download_samples(void) {
return false;
}
setGraphBuf(got, sizeof(got));
setGraphBuffer(got, sizeof(got));
// set signal properties low/high/mean/amplitude and is_noise detection
computeSignalProperties(got, sizeof(got));
RepaintGraphWindow();
@@ -1716,9 +1750,9 @@ int CmdEM4x05Chk(const char *Cmd) {
res = loadFileDICTIONARY_safe(filename, (void **) &keyBlock, 4, &keycount);
if (res != PM3_SUCCESS || keycount == 0 || keyBlock == NULL) {
PrintAndLogEx(WARNING, "no keys found in file");
if (keyBlock != NULL)
if (keyBlock != NULL) {
free(keyBlock);
}
return PM3_ESOFT;
}
@@ -2496,7 +2530,7 @@ int CmdEM4x05Sniff(const char *Cmd) {
static int CmdEM4x05View(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf em ex05 view",
CLIParserInit(&ctx, "lf em 4x05 view",
"Print a EM4205/4305/4369/4469 dump file\n"
"note:\n"
"We don't track if password is known in current dump file formats.\n"
@@ -2552,7 +2586,7 @@ static int CmdEM4x05View(const char *Cmd) {
static int CmdEM4x05Config(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf em ex05 config",
CLIParserInit(&ctx, "lf em 4x05 config",
"Create common configuration blocks",
"lf em 4x05 config"
);
@@ -2595,21 +2629,22 @@ static int CmdEM4x05Config(const char *Cmd) {
}
static command_t CommandTable[] = {
{"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"},
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operations") " -----------------------"},
{"brute", CmdEM4x05Brute, IfPm3Lf, "Bruteforce password"},
{"chk", CmdEM4x05Chk, IfPm3Lf, "Check passwords from dictionary"},
{"config", CmdEM4x05Config, AlwaysAvailable, "Create common configuration words"},
{"demod", CmdEM4x05Demod, AlwaysAvailable, "Demodulate a EM4x05/EM4x69 tag from the GraphBuffer"},
{"dump", CmdEM4x05Dump, IfPm3Lf, "Dump EM4x05/EM4x69 tag"},
{"info", CmdEM4x05Info, IfPm3Lf, "Tag information"},
{"read", CmdEM4x05Read, IfPm3Lf, "Read word data from EM4x05/EM4x69"},
{"sniff", CmdEM4x05Sniff, AlwaysAvailable, "Attempt to recover em4x05 commands from sample buffer"},
{"unlock", CmdEM4x05Unlock, IfPm3Lf, "Execute tear off against EM4x05/EM4x69"},
{"view", CmdEM4x05View, AlwaysAvailable, "Display content from tag dump file"},
{"wipe", CmdEM4x05Wipe, IfPm3Lf, "Wipe EM4x05/EM4x69 tag"},
{"write", CmdEM4x05Write, IfPm3Lf, "Write word data to EM4x05/EM4x69"},
{"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"},
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"-----------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operations") " -----------------------"},
{"clonehelp", CmdEM4x05CloneHelp, IfPm3Lf, "Shows the available clone commands"},
{"brute", CmdEM4x05Brute, IfPm3Lf, "Bruteforce password"},
{"chk", CmdEM4x05Chk, IfPm3Lf, "Check passwords"},
{"config", CmdEM4x05Config, AlwaysAvailable, "Create common configuration words"},
{"demod", CmdEM4x05Demod, AlwaysAvailable, "Demodulate a EM4x05/EM4x69 tag from the GraphBuffer"},
{"dump", CmdEM4x05Dump, IfPm3Lf, "Dump EM4x05/EM4x69 tag"},
{"info", CmdEM4x05Info, IfPm3Lf, "Tag information"},
{"read", CmdEM4x05Read, IfPm3Lf, "Read word data from EM4x05/EM4x69"},
{"sniff", CmdEM4x05Sniff, AlwaysAvailable, "Attempt to recover em4x05 commands from sample buffer"},
{"unlock", CmdEM4x05Unlock, IfPm3Lf, "Execute tear off against EM4x05/EM4x69"},
{"view", CmdEM4x05View, AlwaysAvailable, "Display content from tag dump file"},
{"wipe", CmdEM4x05Wipe, IfPm3Lf, "Wipe EM4x05/EM4x69 tag"},
{"write", CmdEM4x05Write, IfPm3Lf, "Write word data to EM4x05/EM4x69"},
{NULL, NULL, NULL, NULL}
};
+14 -7
View File
@@ -63,10 +63,10 @@ static void em4x50_print_result(const em4x50_word_t *words, int fwr, int lwr) {
s = _YELLOW_("control cfg ( locked )");
break;
case EM4X50_DEVICE_SERIAL:
s = _YELLOW_("device serial number ( RO )");
s = _YELLOW_("serial number ( RO )");
break;
case EM4X50_DEVICE_ID:
s = _YELLOW_("device identification ( RO )");
s = _YELLOW_("device id ( RO )");
break;
default:
s = "user data";
@@ -602,8 +602,11 @@ int read_em4x50_uid(void) {
};
em4x50_word_t words[EM4X50_NO_WORDS];
int res = em4x50_read(&etd, words);
if (res == PM3_SUCCESS)
if (res == PM3_SUCCESS) {
PrintAndLogEx(INFO, " Serial: " _GREEN_("%s"), sprint_hex(words[EM4X50_DEVICE_SERIAL].byte, 4));
} else {
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
}
return res;
}
@@ -612,7 +615,10 @@ int read_em4x50_uid(void) {
// read protected) -> selective read mode
int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out) {
em4x50_data_t edata = { .pwd_given = false, .addr_given = false };
em4x50_data_t edata = {
.pwd_given = false,
.addr_given = false,
};
if (etd != NULL) {
edata = *etd;
@@ -630,9 +636,10 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out) {
return PM3_ESOFT;
}
uint8_t *data = resp.data.asBytes;
em4x50_read_data_response_t *o = (em4x50_read_data_response_t *)resp.data.asBytes;
em4x50_word_t words[EM4X50_NO_WORDS] = {0};
em4x50_prepare_result(data, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words);
em4x50_prepare_result((uint8_t *)o->words, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words);
if (out != NULL) {
memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS);
@@ -1331,7 +1338,7 @@ static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("operations") " ---------------------"},
{"brute", CmdEM4x50Brute, IfPm3EM4x50, "Bruteforce attack to find password"},
{"chk", CmdEM4x50Chk, IfPm3EM4x50, "Check passwords from dictionary"},
{"chk", CmdEM4x50Chk, IfPm3EM4x50, "Check passwords"},
{"dump", CmdEM4x50Dump, IfPm3EM4x50, "Dump EM4x50 tag"},
{"info", CmdEM4x50Info, IfPm3EM4x50, "Tag information"},
{"login", CmdEM4x50Login, IfPm3EM4x50, "Login into EM4x50 tag"},
+150 -71
View File
@@ -164,10 +164,18 @@ typedef struct _em4x70_cmd_input_verify_auth_t {
ID48LIB_GRN grn;
} em4x70_cmd_input_verify_auth_t;
static int CmdHelp(const char *Cmd);
typedef struct _em4x70_cmd_input_calculate_t {
ID48LIB_KEY key;
ID48LIB_NONCE rn;
} em4x70_cmd_input_calculate_t;
typedef struct _em4x70_cmd_output_calculate_t {
ID48LIB_FRN frn;
ID48LIB_GRN grn;
} em4x70_cmd_output_calculate_t;
static void fill_buffer_prng_bytes(void *buffer, size_t byte_count) {
if (byte_count <= 0) {
if (byte_count == 0) {
return;
}
@@ -225,14 +233,10 @@ static int get_em4x70_info(const em4x70_cmd_input_info_t *opts, em4x70_tag_info_
if (WaitForResponseTimeout(CMD_LF_EM4X70_INFO, &resp, TIMEOUT) == false) {
return PM3_ETIMEOUT;
}
//iceman: prefer to have specific return code check.
// like resp.status != PM3_SUCCESS if looking for failure
if (resp.status) {
if (resp.status == PM3_SUCCESS) {
memcpy(data_out, resp.data.asBytes, sizeof(em4x70_tag_info_t));
return PM3_SUCCESS;
}
return PM3_ESOFT;
return resp.status;
}
static int writeblock_em4x70(const em4x70_cmd_input_writeblock_t *opts, em4x70_tag_info_t *data_out) {
@@ -251,14 +255,10 @@ static int writeblock_em4x70(const em4x70_cmd_input_writeblock_t *opts, em4x70_t
if (WaitForResponseTimeout(CMD_LF_EM4X70_WRITE, &resp, TIMEOUT) == false) {
return PM3_ETIMEOUT;
}
//iceman: prefer to have specific return code check.
// like resp.status != PM3_SUCCESS if looking for failure
if (resp.status) {
if (resp.status == PM3_SUCCESS) {
memcpy(data_out, resp.data.asBytes, sizeof(em4x70_tag_info_t));
return PM3_SUCCESS;
}
return PM3_ESOFT;
return resp.status;
}
static int auth_em4x70(const em4x70_cmd_input_auth_t *opts, em4x70_cmd_output_auth_t *data_out) {
@@ -276,20 +276,15 @@ static int auth_em4x70(const em4x70_cmd_input_auth_t *opts, em4x70_cmd_output_au
if (WaitForResponseTimeout(CMD_LF_EM4X70_AUTH, &resp, TIMEOUT) == false) {
return PM3_ETIMEOUT;
}
//iceman: prefer to have specific return code check.
// like resp.status != PM3_SUCCESS if looking for failure
if (resp.status) {
if (resp.status == PM3_SUCCESS) {
// Response is 20-bit from tag
// HACKHACK -- It appears the byte order differs from what is expected?
data_out->grn.grn[0] = resp.data.asBytes[2];
data_out->grn.grn[1] = resp.data.asBytes[1];
data_out->grn.grn[2] = resp.data.asBytes[0];
//memcpy(data_out, &resp.data.asBytes[0], sizeof(ID48LIB_GRN));
return PM3_SUCCESS;
}
return PM3_ESOFT;
return resp.status;
}
static int setkey_em4x70(const em4x70_cmd_input_setkey_t *opts) {
@@ -305,13 +300,7 @@ static int setkey_em4x70(const em4x70_cmd_input_setkey_t *opts) {
if (WaitForResponseTimeout(CMD_LF_EM4X70_SETKEY, &resp, TIMEOUT) == false) {
return PM3_ETIMEOUT;
}
//iceman: prefer to have specific return code check.
// like resp.status != PM3_SUCCESS if looking for failure
if (resp.status) {
return PM3_SUCCESS;
}
return PM3_ESOFT;
return resp.status;
}
static int brute_em4x70(const em4x70_cmd_input_brute_t *opts, em4x70_cmd_output_brute_t *data_out) {
@@ -346,14 +335,10 @@ static int brute_em4x70(const em4x70_cmd_input_brute_t *opts, em4x70_cmd_output_
}
if (WaitForResponseTimeout(CMD_LF_EM4X70_BRUTE, &resp, TIMEOUT)) {
//iceman: prefer to have specific return code check.
// like resp.status != PM3_SUCCESS if looking for failure
if (resp.status) {
if (resp.status == PM3_SUCCESS) {
memcpy(data_out, resp.data.asBytes, sizeof(em4x70_cmd_output_brute_t));
return PM3_SUCCESS;
}
return PM3_ESOFT;
return resp.status;
}
// NOTE: It takes about 11 seconds per 0x0100 authentication attempts.
@@ -383,15 +368,10 @@ static int unlock_em4x70(const em4x70_cmd_input_unlock_t *opts, em4x70_tag_info_
if (WaitForResponseTimeout(CMD_LF_EM4X70_UNLOCK, &resp, TIMEOUT) == false) {
return PM3_ETIMEOUT;
}
//iceman: prefer to have specific return code check.
// like resp.status != PM3_SUCCESS if looking for failure
if (resp.status) {
if (resp.status == PM3_SUCCESS) {
memcpy(data_out, resp.data.asBytes, sizeof(em4x70_tag_info_t));
return PM3_SUCCESS;
}
return PM3_ESOFT;
return resp.status;
}
static int setpin_em4x70(const em4x70_cmd_input_setpin_t *opts, em4x70_tag_info_t *data_out) {
@@ -408,14 +388,10 @@ static int setpin_em4x70(const em4x70_cmd_input_setpin_t *opts, em4x70_tag_info_
if (WaitForResponseTimeout(CMD_LF_EM4X70_SETPIN, &resp, TIMEOUT) == false) {
return PM3_ETIMEOUT;
}
//iceman: prefer to have specific return code check.
// like resp.status != PM3_SUCCESS if looking for failure
if (resp.status) {
if (resp.status == PM3_SUCCESS) {
memcpy(data_out, resp.data.asBytes, sizeof(em4x70_tag_info_t));
return PM3_SUCCESS;
}
return PM3_ESOFT;
return resp.status;
}
static int recover_em4x70(const em4x70_cmd_input_recover_t *opts, em4x70_cmd_output_recover_t *data_out) {
@@ -463,23 +439,8 @@ static int verify_auth_em4x70(const em4x70_cmd_input_verify_auth_t *opts) {
return result;
}
// used by `lf search` and `search`, this is a quick test for EM4x70 tag
// In alignment with other tags implementations, this also dumps basic information
// about the tag, if one is found.
// Use helper function `get_em4x70_info()` if wanting to limit / avoid output.
bool detect_4x70_block(void) {
em4x70_tag_info_t info;
em4x70_cmd_input_info_t opts = { 0 };
int result = get_em4x70_info(&opts, &info);
if (result == PM3_ETIMEOUT) { // consider removing this output?
PrintAndLogEx(WARNING, "Timeout while waiting for reply.");
}
return result == PM3_SUCCESS;
}
int CmdEM4x70Info(const char *Cmd) {
static int CmdEM4x70Info(const char *Cmd) {
// invoke reading of a EM4x70 tag which has to be on the antenna because
// decoding is done by the device (not on client side)
@@ -519,7 +480,7 @@ int CmdEM4x70Info(const char *Cmd) {
return result;
}
int CmdEM4x70Write(const char *Cmd) {
static int CmdEM4x70Write(const char *Cmd) {
// write one block/word (16 bits) to the tag at given block address (0-15)
CLIParserContext *ctx;
@@ -571,7 +532,7 @@ int CmdEM4x70Write(const char *Cmd) {
return result;
}
int CmdEM4x70Brute(const char *Cmd) {
static int CmdEM4x70Brute(const char *Cmd) {
// From paper "Dismantling Megamos Crypto", Roel Verdult, Flavio D. Garcia and Barıs¸ Ege.
// Partial Key-Update Attack (optimized version)
@@ -581,7 +542,9 @@ int CmdEM4x70Brute(const char *Cmd) {
"This attack does NOT write anything to the tag.\n"
"Before starting this attack, 0000 must be written to the 16-bit key block: 'lf em 4x70 write -b 9 -d 0000'.\n"
"After success, the 16-bit key block have to be restored with the key found: 'lf em 4x70 write -b 9 -d c0de'\n",
"lf em 4x70 brute -b 9 --rnd 45F54ADA252AAC --frn 4866BB70 --> bruteforcing key bits k95...k80\n"
"lf em 4x70 brute -b 9 --rnd 45F54ADA252AAC --frn 4866BB70 --> bruteforcing key bits k95...k80 (pm3 test key)\n"
"lf em 4x70 brute -b 8 --rnd 3FFE1FB6CC513F --frn F355F1A0 --> bruteforcing key bits k79...k64 (research paper key)\n"
"lf em 4x70 brute -b 7 --rnd 7D5167003571F8 --frn 982DBCC0 --> bruteforcing key bits k63...k48 (autorecovery test key)\n"
);
void *argtable[] = {
arg_param_begin,
@@ -655,7 +618,7 @@ int CmdEM4x70Brute(const char *Cmd) {
return result;
}
int CmdEM4x70Unlock(const char *Cmd) {
static int CmdEM4x70Unlock(const char *Cmd) {
// send pin code to device, unlocking it for writing
CLIParserContext *ctx;
@@ -703,7 +666,7 @@ int CmdEM4x70Unlock(const char *Cmd) {
return result;
}
int CmdEM4x70Auth(const char *Cmd) {
static int CmdEM4x70Auth(const char *Cmd) {
// Authenticate transponder
// Send 56-bit random number + pre-computed f(rnd, k) to transponder.
@@ -716,6 +679,7 @@ int CmdEM4x70Auth(const char *Cmd) {
" If F(RN) is correct based on the tag key, the tag will give a 20-bit response\n",
"lf em 4x70 auth --rnd 45F54ADA252AAC --frn 4866BB70 --> (using pm3 test key)\n"
"lf em 4x70 auth --rnd 3FFE1FB6CC513F --frn F355F1A0 --> (using research paper key)\n"
"lf em 4x70 auth --rnd 7D5167003571F8 --frn 982DBCC0 --> (autorecovery test key)\n"
);
void *argtable[] = {
@@ -762,7 +726,7 @@ int CmdEM4x70Auth(const char *Cmd) {
return result;
}
int CmdEM4x70SetPIN(const char *Cmd) {
static int CmdEM4x70SetPIN(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf em 4x70 setpin",
"Write new PIN\n",
@@ -807,12 +771,13 @@ int CmdEM4x70SetPIN(const char *Cmd) {
return result;
}
int CmdEM4x70SetKey(const char *Cmd) {
static int CmdEM4x70SetKey(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf em 4x70 setkey",
"Write new 96-bit key to tag\n",
"lf em 4x70 setkey -k F32AA98CF5BE4ADFA6D3480B (pm3 test key)\n"
"lf em 4x70 setkey -k A090A0A02080000000000000 (research paper key)\n"
"lf em 4x70 setkey -k 022A028C02BE000102030405 (autorecovery test key)\n"
);
void *argtable[] = {
@@ -932,6 +897,7 @@ static int CmdEM4x70Recover_ParseArgs(const char *Cmd, em4x70_cmd_input_recover_
,
"lf em 4x70 recover --key F32AA98CF5BE --rnd 45F54ADA252AAC --frn 4866BB70 --grn 9BD180 (pm3 test key)\n"
"lf em 4x70 recover --key A090A0A02080 --rnd 3FFE1FB6CC513F --frn F355F1A0 --grn 609D60 (research paper key)\n"
"lf em 4x70 recover --key 022A028C02BE --rnd 7D5167003571F8 --frn 982DBCC0 --grn 36C0E0 (autorecovery test key)\n"
);
void *argtable[] = {
@@ -1003,7 +969,7 @@ static int CmdEM4x70Recover_ParseArgs(const char *Cmd, em4x70_cmd_input_recover_
return result;
}
int CmdEM4x70Recover(const char *Cmd) {
static int CmdEM4x70Recover(const char *Cmd) {
// From paper "Dismantling Megamos Crypto", Roel Verdult, Flavio D. Garcia and Barıs¸ Ege.
// Partial Key-Update Attack -- final 48 bits (after optimized version gets k95..k48)
em4x70_recovery_data_t recover_ctx = {0};
@@ -1137,6 +1103,7 @@ static int CmdEM4x70AutoRecover_ParseArgs(const char *Cmd, em4x70_cmd_input_reco
,
"lf em 4x70 autorecover --rnd 45F54ADA252AAC --frn 4866BB70 --grn 9BD180 (pm3 test key)\n"
"lf em 4x70 autorecover --rnd 3FFE1FB6CC513F --frn F355F1A0 --grn 609D60 (research paper key)\n"
"lf em 4x70 autorecover --rnd 7D5167003571F8 --frn 982DBCC0 --grn 36C0E0 (autorecovery test key)\n"
);
void *argtable[] = {
@@ -1471,6 +1438,97 @@ static int CmdEM4x70AutoRecover(const char *Cmd) {
return result;
}
static int CmdEM4x70Calc_ParseArgs(const char *Cmd, em4x70_cmd_input_calculate_t *out_results) {
memset(out_results, 0, sizeof(em4x70_cmd_input_calculate_t));
int result = PM3_SUCCESS;
CLIParserContext *ctx;
CLIParserInit(
&ctx,
"lf em 4x70 calc",
"Calculates both the reader and tag challenge for a user-provided key and rnd.\n"
,
"lf em 4x70 calc --key F32AA98CF5BE4ADFA6D3480B --rnd 45F54ADA252AAC (pm3 test key)\n" // --frn 4866BB70 --grn 9BD180
"lf em 4x70 calc --key A090A0A02080000000000000 --rnd 3FFE1FB6CC513F (research paper key)\n" // --frn F355F1A0 --grn 609D60
"lf em 4x70 calc --key 022A028C02BE000102030405 --rnd 7D5167003571F8 (autorecovery test key)\n" // --frn 982DBCC0 --grn 36C0E0
);
void *argtable[] = {
arg_param_begin,
arg_str1(NULL, "key", "<hex>", "Key 96-bit as 12 hex bytes"),
arg_str1(NULL, "rnd", "<hex>", "56-bit random value sent to tag for authentication"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
int key_len = 0; // must be 12 bytes hex data
int rnd_len = 0; // must be 7 bytes hex data
// These macros hide early function return on error ... including free'ing ctx.
CLIGetHexWithReturn(ctx, 1, out_results->key.k, &key_len);
CLIGetHexWithReturn(ctx, 2, out_results->rn.rn, &rnd_len);
CLIParserFree(ctx);
if (key_len != 12) {
PrintAndLogEx(FAILED, "Key length must be 12 bytes, got %d", key_len);
result = PM3_EINVARG;
}
if (rnd_len != 7) {
PrintAndLogEx(FAILED, "Random number length must be 7 bytes, got %d", rnd_len);
result = PM3_EINVARG;
}
return result;
}
static int CmdEM4x70Calc(const char *Cmd) {
em4x70_cmd_input_calculate_t opts = {0};
em4x70_cmd_output_calculate_t data = {0};
// 0. Parse the command line
int result = CmdEM4x70Calc_ParseArgs(Cmd, &opts);
if (PM3_SUCCESS != result) {
return result;
}
// There are no failure paths. All inputs are valid, and ID48LIB doesn't add any failure paths.
id48lib_generator(&opts.key, &opts.rn, &data.frn, &data.grn);
char key_string[24 + 1] = {0};
char rnd_string[14 + 1] = {0};
char frn_string[ 8 + 1] = {0};
char grn_string[ 6 + 1] = {0};
if (true) {
snprintf(
key_string, 25,
"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
opts.key.k[ 0], opts.key.k[ 1], opts.key.k[ 2], opts.key.k[ 3],
opts.key.k[ 4], opts.key.k[ 5], opts.key.k[ 6], opts.key.k[ 7],
opts.key.k[ 8], opts.key.k[ 9], opts.key.k[10], opts.key.k[11]
);
snprintf(
rnd_string, 15,
"%02X%02X%02X%02X%02X%02X%02X",
opts.rn.rn[0], opts.rn.rn[1], opts.rn.rn[2], opts.rn.rn[3], opts.rn.rn[4], opts.rn.rn[5], opts.rn.rn[6]
);
snprintf(
frn_string, 9,
"%02X%02X%02X%02X",
data.frn.frn[0], data.frn.frn[1], data.frn.frn[2], data.frn.frn[3]
);
snprintf(
grn_string, 7,
"%02X%02X%02X",
data.grn.grn[0], data.grn.grn[1], data.grn.grn[2]
);
}
PrintAndLogEx(SUCCESS, "KEY: %s RND: %s FRN: " _GREEN_("%s") " GRN: " _GREEN_("%s"), key_string, rnd_string, frn_string, grn_string);
return PM3_SUCCESS;
}
// Must be declared to be used in the table,
// but cannot be defined yet because it uses the table.
static int CmdHelp(const char *Cmd);
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
@@ -1481,6 +1539,7 @@ static command_t CommandTable[] = {
{"auth", CmdEM4x70Auth, IfPm3EM4x70, "Authenticate EM4x70"},
{"setpin", CmdEM4x70SetPIN, IfPm3EM4x70, "Write PIN"},
{"setkey", CmdEM4x70SetKey, IfPm3EM4x70, "Write key"},
{"calc", CmdEM4x70Calc, AlwaysAvailable, "Calculate EM4x70 challenge and response"},
{"recover", CmdEM4x70Recover, AlwaysAvailable, "Recover remaining key from partial key"},
{"autorecover", CmdEM4x70AutoRecover, IfPm3EM4x70, "Recover entire key from writable tag"},
{NULL, NULL, NULL, NULL}
@@ -1492,7 +1551,27 @@ static int CmdHelp(const char *Cmd) {
return PM3_SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////
// Only two functions need to be non-static:
// * CmdLFEM4X70()
// * detect_4x70_block()
int CmdLFEM4X70(const char *Cmd) {
clearCommandBuffer();
return CmdsParse(CommandTable, Cmd);
}
// used by `lf search` and `search`, this is a quick test for EM4x70 tag
// In alignment with other tags implementations, this also dumps basic information
// about the tag, if one is found.
// Use helper function `get_em4x70_info()` if wanting to limit / avoid output.
bool detect_4x70_block(void) {
em4x70_tag_info_t info;
em4x70_cmd_input_info_t opts = { 0 };
int result = get_em4x70_info(&opts, &info);
if (result == PM3_ETIMEOUT) { // consider removing this output?
PrintAndLogEx(WARNING, "Timeout while waiting for reply.");
}
return result == PM3_SUCCESS;
}
-8
View File
@@ -24,14 +24,6 @@
#define TIMEOUT 2000
int CmdLFEM4X70(const char *Cmd);
int CmdEM4x70Info(const char *Cmd);
int CmdEM4x70Write(const char *Cmd);
int CmdEM4x70Brute(const char *Cmd);
int CmdEM4x70Unlock(const char *Cmd);
int CmdEM4x70Auth(const char *Cmd);
int CmdEM4x70SetPIN(const char *Cmd);
int CmdEM4x70SetKey(const char *Cmd);
int CmdEM4x70Recover(const char *Cmd);
// for `lf search`:
bool detect_4x70_block(void);
+1 -1
View File
@@ -889,7 +889,7 @@ static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "this help"},
{"demod", CmdFdxBDemod, AlwaysAvailable, "demodulate a FDX-B ISO11784/85 tag from the GraphBuffer"},
{"reader", CmdFdxBReader, IfPm3Lf, "attempt to read at 134kHz and extract tag data"},
{"clone", CmdFdxBClone, IfPm3Lf, "clone animal ID tag to T55x7 or Q5/T5555"},
{"clone", CmdFdxBClone, IfPm3Lf, "clone animal ID tag to T55x7, Q5/T5555 or EM4305/4469"},
{"sim", CmdFdxBSim, IfPm3Lf, "simulate Animal ID tag"},
{NULL, NULL, NULL, NULL}
};
+1 -1
View File
@@ -380,7 +380,7 @@ static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"demod", CmdGallagherDemod, AlwaysAvailable, "demodulate an GALLAGHER tag from the GraphBuffer"},
{"reader", CmdGallagherReader, IfPm3Lf, "attempt to read and extract tag data"},
{"clone", CmdGallagherClone, IfPm3Lf, "clone GALLAGHER tag to T55x7"},
{"clone", CmdGallagherClone, IfPm3Lf, "clone GALLAGHER tag to T55x7, Q5/T5555 or EM4305/4469"},
{"sim", CmdGallagherSim, IfPm3Lf, "simulate GALLAGHER tag"},
{NULL, NULL, NULL, NULL}
};
+2 -2
View File
@@ -122,7 +122,7 @@ int demodHID(bool verbose) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return PM3_EMALLOC;
}
size_t size = getFromGraphBuf(bits);
size_t size = getFromGraphBuffer(bits);
if (size == 0) {
PrintAndLogEx(DEBUG, "DEBUG: Error - " _RED_("HID not enough samples"));
free(bits);
@@ -679,7 +679,7 @@ static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "this help"},
{"demod", CmdHIDDemod, AlwaysAvailable, "demodulate HID Prox tag from the GraphBuffer"},
{"reader", CmdHIDReader, IfPm3Lf, "attempt to read and extract tag data"},
{"clone", CmdHIDClone, IfPm3Lf, "clone HID tag to T55x7"},
{"clone", CmdHIDClone, IfPm3Lf, "clone HID tag to T55x7, Q5/T5555 or EM4305/4469"},
{"sim", CmdHIDSim, IfPm3Lf, "simulate HID tag"},
{"brute", CmdHIDBrute, IfPm3Lf, "bruteforce facility code or card number against reader"},
{"watch", CmdHIDWatch, IfPm3Lf, "continuously watch for cards. Reader mode"},
+1386 -228
View File
File diff suppressed because it is too large. Load diff
+11 -2
View File
@@ -22,11 +22,14 @@
#include "common.h"
#define HITAG_NRAR_SIZE 8
#define HITAG_CRYPTOKEY_SIZE 6
#define HITAG_PASSWORD_SIZE 4
#define HITAG_UID_SIZE 4
#define HITAG_BLOCK_SIZE 4
#define HITAG2_MAX_BYTE_SIZE (12 * HITAG_BLOCK_SIZE)
#define HITAG2_MAX_BLOCKS 8
#define HITAG2_MAX_BYTE_SIZE (HITAG2_MAX_BLOCKS * HITAG_BLOCK_SIZE)
// need to see which limits these cards has
#define HITAG1_MAX_BYTE_SIZE 64
#define HITAGS_MAX_BYTE_SIZE 64
@@ -35,12 +38,18 @@
#define HITAG2_CONFIG_BLOCK 3
#define HITAG2_CONFIG_OFFSET (HITAG_BLOCK_SIZE * HITAG2_CONFIG_BLOCK)
#define HITAG_DICTIONARY "ht2_default"
int CmdLFHitag(const char *Cmd);
int readHitagUid(void);
void annotateHitag1(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, bool is_response);
void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, bool is_response);
void annotateHitag2(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, uint8_t bits, bool is_response, const uint64_t *keys, uint32_t keycount, bool isdecrypted);
void annotateHitagS(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, bool is_response);
void annotateHitag2_init(void);
bool hitag2_get_plain(uint8_t *plain, uint8_t *plen);
void hitag2_annotate_plain(char *exp, size_t size, const uint8_t *cmd, uint8_t cmdsize, uint8_t bits);
uint8_t hitag1_CRC_check(uint8_t *d, uint32_t nbit);
#endif
Loaded 100 of 207 files, more files were not shown because too many files have changed in this diff. Show more