Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fa173c727 | ||
|
|
0792d05efa | ||
|
|
1bebaf6aee | ||
|
|
f06c2fafbe | ||
|
|
67da1c8ca5 | ||
|
|
63392baa40 | ||
|
|
640b4a5f3b | ||
|
|
eb31bcad07 | ||
|
|
eb5aa9e08e | ||
|
|
25932cafb7 | ||
|
|
22555cc5da | ||
|
|
4547d4ba7c | ||
|
|
3515370185 | ||
|
|
9a75cbe169 | ||
|
|
86d36a3be3 | ||
|
|
a7dfd06354 | ||
|
|
a5d02c6ba2 | ||
|
|
3210384ef9 | ||
|
|
b00e5d3a22 | ||
|
|
ee674405bc | ||
|
|
5cb19b0645 | ||
|
|
16fab8bd44 | ||
|
|
dc44d0fda5 | ||
|
|
e917491d4a | ||
|
|
4725ae5c22 | ||
|
|
6ba00b7bee | ||
|
|
0378d91595 | ||
|
|
2ca43e0e2d | ||
|
|
92c288ab85 | ||
|
|
c1729ca264 | ||
|
|
f7f0605207 | ||
|
|
2dfb0706fa | ||
|
|
4f682501f1 | ||
|
|
c4e019ec60 | ||
|
|
2108ab6101 | ||
|
|
646f1a5b97 | ||
|
|
24d6013f10 | ||
|
|
2699060eeb | ||
|
|
076158cc15 | ||
|
|
d143d9a65c | ||
|
|
8156274007 | ||
|
|
cd14990dc5 | ||
|
|
5b7e013f1a | ||
|
|
7fb5716ea3 | ||
|
|
af7aa26c14 | ||
|
|
9b37250453 | ||
|
|
b5e6d21128 | ||
|
|
69a2cc1ff0 | ||
|
|
4dcf12fd8d | ||
|
|
31b1117a51 | ||
|
|
86bac8fe8c | ||
|
|
0a4b67bd7e | ||
|
|
b70d462a06 | ||
|
|
5f2edb9bb8 | ||
|
|
15fbfafac1 | ||
|
|
1fa5e28a38 | ||
|
|
1a6c38ab20 | ||
|
|
7fd5730d89 | ||
|
|
ec26b6d84f | ||
|
|
add2eb8e9d | ||
|
|
3d8a15d361 | ||
|
|
8c880e4a3f | ||
|
|
bcec294606 | ||
|
|
27aa9a2085 | ||
|
|
387009ab6a | ||
|
|
2d610b8dc0 | ||
|
|
911d4f9df2 | ||
|
|
990e7b5e1f | ||
|
|
d4c281ff17 | ||
|
|
80e1c7f0d4 | ||
|
|
d83196fb35 | ||
|
|
73be29db44 | ||
|
|
fd3a644289 | ||
|
|
3a8c3174a8 | ||
|
|
88593f9b8b | ||
|
|
6fbb13ba41 | ||
|
|
9a2395d40f | ||
|
|
f49bc8ebaa | ||
|
|
606f65496c | ||
|
|
9c672d8289 | ||
|
|
b4edcb9510 | ||
|
|
32e29d9340 | ||
|
|
5558db3019 | ||
|
|
082bea661d | ||
|
|
94794f7519 | ||
|
|
53e1e32409 | ||
|
|
23338b3f39 | ||
|
|
f41d6fad53 | ||
|
|
27ce314051 | ||
|
|
e68be39a41 | ||
|
|
edcd9b4ca9 | ||
|
|
566d9957a8 | ||
|
|
6a9c3d4dcd | ||
|
|
a79b1b9e82 | ||
|
|
411c684e6a | ||
|
|
e2a1f30b40 | ||
|
|
fd098ba12f | ||
|
|
7acf507826 | ||
|
|
ab84cb459a | ||
|
|
b46930394a | ||
|
|
f3404d841c | ||
|
|
083a9ce945 | ||
|
|
5c5ce2144d | ||
|
|
82268b9a69 | ||
|
|
fd5e79b991 | ||
|
|
3ef1486e79 | ||
|
|
186ed6fb07 | ||
|
|
fb13d52e7c | ||
|
|
7225ea6ac4 | ||
|
|
81d7ac1f59 | ||
|
|
a5ee3f50b6 | ||
|
|
d654f6e78f | ||
|
|
0fc3d533e6 | ||
|
|
320646c573 | ||
|
|
4e5b514315 | ||
|
|
cb131c2718 | ||
|
|
9701c6f0c3 | ||
|
|
a04fa57f86 | ||
|
|
be67eb123b | ||
|
|
0871dfe99a | ||
|
|
e9241a8462 | ||
|
|
f9fbc2cf41 | ||
|
|
13d8a3570b | ||
|
|
f861f2d438 | ||
|
|
296c375092 | ||
|
|
34ddd4a75c | ||
|
|
810eaeac25 | ||
|
|
9be3473864 | ||
|
|
91a16e4d9e | ||
|
|
4acc370dbf | ||
|
|
2b2a1cc0a2 | ||
|
|
749c23a6b5 | ||
|
|
359469c0a5 | ||
|
|
23d9783b26 | ||
|
|
be65279475 | ||
|
|
2105dbc379 | ||
|
|
db9667d0fb | ||
|
|
c32f655023 | ||
|
|
04cfe2a43e | ||
|
|
83837699e1 | ||
|
|
804acfbefa | ||
|
|
f0022e4280 | ||
|
|
90210fe588 | ||
|
|
7b9fe29cf3 | ||
|
|
18e4c072e7 | ||
|
|
a223570dbf | ||
|
|
0479a1b82e | ||
|
|
b2e587afa5 | ||
|
|
79e72fc8bf | ||
|
|
490c211361 | ||
|
|
9287e872f1 | ||
|
|
ce0431601a | ||
|
|
503c03caa2 | ||
|
|
bbd6f51586 | ||
|
|
ada340de94 | ||
|
|
01e57db5f1 | ||
|
|
585670d55c | ||
|
|
4e07fc2b31 | ||
|
|
e35a4e292d | ||
|
|
176b543069 | ||
|
|
744107035f | ||
|
|
b378a369d1 | ||
|
|
ee16112d29 | ||
|
|
23928b4041 | ||
|
|
66c57e8652 | ||
|
|
8c3d0c7957 | ||
|
|
b8e8c41f28 | ||
|
|
3ff2f28305 | ||
|
|
1349b6d282 | ||
|
|
d5fb619308 | ||
|
|
eecdad7ac8 | ||
|
|
8d3e301b55 | ||
|
|
4b92118f1f | ||
|
|
428ee718d3 | ||
|
|
d402903db5 | ||
|
|
4da2a9a496 | ||
|
|
dcec8d6e71 | ||
|
|
74f1936132 | ||
|
|
96c58db8e8 | ||
|
|
607f1bb26c | ||
|
|
bb0445d886 | ||
|
|
36e7736603 | ||
|
|
b6a39768a1 | ||
|
|
00c5af4256 | ||
|
|
c312bae516 | ||
|
|
0d8bb030d1 | ||
|
|
473b5679e2 | ||
|
|
a2f9012e13 | ||
|
|
841828eb48 | ||
|
|
fd129df163 | ||
|
|
45ae30fe88 | ||
|
|
ad50e59738 | ||
|
|
d4bc190dd4 | ||
|
|
8be79bb781 | ||
|
|
335c1444bd | ||
|
|
d078680bb6 | ||
|
|
2119e46701 | ||
|
|
07bfef1550 | ||
|
|
6e517a40f5 | ||
|
|
1ca356531e | ||
|
|
fbbfeaa977 | ||
|
|
c716467a7e | ||
|
|
047b94fbaa | ||
|
|
4f2b35872d | ||
|
|
f9322dfe6c | ||
|
|
6765c2294c | ||
|
|
a753485054 | ||
|
|
d5beb66508 | ||
|
|
3b5ee30e05 | ||
|
|
74c66d89ff | ||
|
|
84b565bec4 | ||
|
|
b90348e66b | ||
|
|
a021ada83f | ||
|
|
59e4875e6c | ||
|
|
1287454781 | ||
|
|
c156e33ad9 | ||
|
|
67fb546887 | ||
|
|
70275e3d56 | ||
|
|
23232f8aa3 | ||
|
|
fe4ee76ff9 | ||
|
|
3c35a87dee | ||
|
|
a3d7cfcf4a | ||
|
|
a9244b8ea4 | ||
|
|
814c86d078 | ||
|
|
5b9039d825 | ||
|
|
a33ba30092 | ||
|
|
dc772aae6b | ||
|
|
55cab29364 | ||
|
|
0cbf42e0ec | ||
|
|
8227834730 | ||
|
|
2a895383c9 | ||
|
|
d06a152c69 | ||
|
|
9744f8afbb | ||
|
|
2163d78126 | ||
|
|
0655b6389e | ||
|
|
2ed6c90e28 | ||
|
|
b36b61feb0 | ||
|
|
b2983ba025 | ||
|
|
c847896a15 | ||
|
|
42cdd34e59 | ||
|
|
cb4a0e2333 | ||
|
|
45ce045276 | ||
|
|
c2cba6eadd | ||
|
|
bb08fd2b42 | ||
|
|
4746e4a2be | ||
|
|
03c44244bf | ||
|
|
1a69d609d0 | ||
|
|
d052a64a47 | ||
|
|
7068d59f6a | ||
|
|
e31276199f | ||
|
|
4f55fbe4e4 | ||
|
|
8314077fe9 | ||
|
|
2965aa0d45 | ||
|
|
3be06e21aa | ||
|
|
62a7b1a6dd | ||
|
|
ac0ad3e7c3 | ||
|
|
76d8fa060c | ||
|
|
bf6d9f3531 | ||
|
|
48812b9bf2 | ||
|
|
3f43c061d7 | ||
|
|
ed97f94e2f | ||
|
|
b5b14e246b | ||
|
|
c3a7a11ae7 | ||
|
|
e86e5fd293 | ||
|
|
d64ee17c93 | ||
|
|
812c58f601 | ||
|
|
430d5cd3b9 | ||
|
|
3550f11726 | ||
|
|
49521078e5 | ||
|
|
a8a1c77343 | ||
|
|
50b12485a1 | ||
|
|
3ca7fe8bce | ||
|
|
8f4d3026cb | ||
|
|
8dbfd018a3 | ||
|
|
bfbc2fd09d | ||
|
|
0970558491 | ||
|
|
19789381df | ||
|
|
eb2324ed93 | ||
|
|
cf3cb6e03a | ||
|
|
013a7a4caf | ||
|
|
a8fa5dae1a | ||
|
|
bc1c47e81b | ||
|
|
926fbe5354 | ||
|
|
dfc40a2ea3 | ||
|
|
55327112a8 | ||
|
|
cccf4f440c | ||
|
|
216cd09635 | ||
|
|
6f10a6d9d7 | ||
|
|
14a58a7427 | ||
|
|
65f8bdfe31 | ||
|
|
56336d9d82 | ||
|
|
2aa1c8361a | ||
|
|
d326f99a36 | ||
|
|
cd5fb7add7 | ||
|
|
c00b25e89e | ||
|
|
22bff9e85b | ||
|
|
3f705650c0 | ||
|
|
a790c49348 | ||
|
|
9d36ae9cd5 | ||
|
|
59d17c236c | ||
|
|
30708b4553 | ||
|
|
7c6cebb6c3 | ||
|
|
c56b7a2903 | ||
|
|
899e571957 | ||
|
|
853e2bd9ff | ||
|
|
ec4dccb12b | ||
|
|
59839f1107 | ||
|
|
145ee3baa7 | ||
|
|
ec6f9e78b6 | ||
|
|
67b1752748 | ||
|
|
932780bcb5 | ||
|
|
a641b67edd | ||
|
|
631cdc62b3 | ||
|
|
7bc8c85626 | ||
|
|
0f53e9a0cb | ||
|
|
74a3920c0d | ||
|
|
f448ed5c51 | ||
|
|
05fb168e0b | ||
|
|
82a3aa90e0 | ||
|
|
42b5602692 | ||
|
|
a8604e3ff9 | ||
|
|
c99249a169 | ||
|
|
55d3f441be | ||
|
|
bfe3c26277 | ||
|
|
c827b4e582 | ||
|
|
124c415679 | ||
|
|
6ed1853320 |
No files matched your search
@@ -31,9 +31,13 @@ Run `tools/release_tests.sh` on:
|
||||
- [ ] Kali
|
||||
- [ ] Debian Stable
|
||||
- [ ] Debian Testing
|
||||
- [ ] Ubuntu 22
|
||||
- [ ] Ubuntu 24.04 (LTS)
|
||||
- [ ] Ubuntu 24.10
|
||||
- [ ] Ubuntu 25.04
|
||||
- [ ] ParrotOS
|
||||
- [ ] Fedora 37
|
||||
- [ ] Fedora 41 (till 2025-11-19)
|
||||
- [ ] Fedora 42 (till 2026-05-13)
|
||||
- [ ] Fedora 43 (till 2026-12-02)
|
||||
- [ ] OpenSuse Leap
|
||||
- [ ] OpenSuse Tumbleweed
|
||||
- [ ] OSX (MacPorts)
|
||||
|
||||
+51
-9
@@ -2,11 +2,52 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
||||
|
||||
## [Blue Ice][2025-03-25]
|
||||
## [Daddy Iceman][2025-06-16]
|
||||
- Fixed edge case in fm11rf08s key recovery tools (@doegox)
|
||||
- Removed `--par` from `lf em 4x70` commands.
|
||||
- Changed `hf 14a info` - refactored code to be able to detect card technology across the client easier (@iceman1001)
|
||||
- Changed `hf mf info` - now informs better if a different card technology is detected (@iceman1001)
|
||||
- Changed `hf mf autopwn` - now exits if desfire is detected and limit attacks if mifare plus is detected (@iceman1001)
|
||||
- Changed `hf mfp chk` - improved key handling and output (@iceman1001)
|
||||
- Fix `hf mf dump` - added a check for keyfile to contain enough keys for card (@iceman1001)
|
||||
- Fix `hf mf eview` - now viewing 2k, 4k cards doesn't get wrong background color (@iceman1001)
|
||||
- Changed `hf mf info` - skip checking if it detects a MIFARE Ultralight family card (@iceman1001)
|
||||
- Changed `hf mf rdsc` - it now addeds the used key to the output in the sector trailer (@iceman1001)
|
||||
- Added the `PM3ULTIMATE` platform in the build / docs. *untested* (@iceman1001)
|
||||
- Added fpga compilation for PM3ULTIMATE device (@n-hutton)
|
||||
- Updated the ATR list (@iceman1001)
|
||||
- Fixed fpga binary images to use fixed seed 2 (@n-hutton)
|
||||
- Added `hf iclass sam --info` - option that returns sam specific details (@antiklesys)
|
||||
- Changed `hf iclass sim -t 7` - implemented simulation that glitches key block responses (@antiklesys)
|
||||
- Changed `hf iclass sim -t 6` - implemented simulation that glitches sio block (@antiklesys)
|
||||
- Changed `hf iclass legbrute` - implemented multithreading support (@antiklesys)
|
||||
- Changed `hf iclass legrec` - added a --sl option for further speed increase by tweaking the communication delays (@antiklesys)
|
||||
- Changed `hf iclass legrec` - added a --fast option for further speed increase and automated AA2 block selection (@antiklesys)
|
||||
- Changed `hf iclass legrec` - additional code optimizations gaining a ~147% speed increase (@antiklesys)
|
||||
- Changed `hf iclass tear` - readability improvements for erase phase (@antiklesys)
|
||||
- Changed `hf iclass legrec` - code optimizations gaining a ~8% speed increase (@antiklesys)
|
||||
- Modified `hf iclass tear` - now has a device side implementation also. (@antiklesys) (@iceman1001)
|
||||
- Changed `hf iclass info` - now uses CSN values based checks (@antiklesys)
|
||||
- Changed `hf iclass dump` - now uses default AA1 key when called without a key or key index (@iceman1001)
|
||||
- Renamed `hf iclass trbl` to `hf iclass tear` (@iceman1001)
|
||||
- Changed `hw tearoff` - the device side message is now debug log controlled (@iceman1001)
|
||||
- Changed `pm3.sh` - Serial ports enumeration on Proxspace3.xx / MINGW environments, now using powershell.exe since wmic is deprecated (@iceman1001)
|
||||
- Fixed `hf iclass trbl` - to correctly use the credit key when passed and show partial tearoff results (@antiklesys)
|
||||
- Fixed `hf iclass legbrute` was not correctly parsing the index value
|
||||
- Fixed `hf mf ekeyprn` - failed to download emulator memory due to wrong size calculation (@iceman1001)
|
||||
- Fixed `hf mf fchk --mem` to actually use flash dict (@doegox)
|
||||
- Fixed `make install` on OSX thanks DaveItsLong (@doegox)
|
||||
- Added new standalone mode `HF_ST25_TEAROFF` to store/restore ST25TB tags with tearoff for counters (@seclabz)
|
||||
- Added `hf_mfu_ultra.lua` script enables restoring dump to ULTRA/UL-5 tags and clearing previously written ULTRA tags (@mak-42)
|
||||
- Fixed `hf mfu sim` to make persistent the counter increases in the emulator memory (@sup3rgiu)
|
||||
- Fixed `hf mf mad` to correctly display MAD version 2 card publisher sector (@BIOS9)
|
||||
- Fixed `lf hitag dump` and related commands stability when tag is configured in public mode/TTF mode (@rfidgeek1337)
|
||||
|
||||
## [Blue Ice.4.20142][2025-03-25]
|
||||
- Added `des_talk.py` script for easier MIFARE DESFire handling (@trigat)
|
||||
- Fixed `hf 14b info` - wrong endianess when looking for lock bits etc (@gentilkiwi)
|
||||
- Changed `hf mf autopwn` - tries to detect static encrypted nonces and also user cancel during chk keys (@iceman1001)
|
||||
- Added option to `hf mf autopwn` to use SPI flash dictionary (@jmichelp)
|
||||
- Changed `hf mf autopwn` - added option to use SPI flash dictionary (@jmichelp)
|
||||
- Changed `trace list -t seos` - now annotate ISO7816 (@iceman1001)
|
||||
- Updated aid and mad json files (@iceman1001)
|
||||
- Changed `hf 14a apdu` - now can be interrupted and dynamically adds time (@iceman1001)
|
||||
@@ -38,9 +79,9 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
|
||||
- Changed `hf mf cload` - now accepts MFC Ev1 sized dumps (@iceman1001)
|
||||
- Changed `hf mfu info` - now properly identify ULEv1 AES 50pF (@iceman1001)
|
||||
- Changed `hf mf info` - now differentiates between full USCUID and cut down ZUID chips (@nvx)
|
||||
- Changed `lf hitag chk` - added key counter, client side abort and minor delay (@iceman1001)
|
||||
- Changed `lf hitag chk` - added key counter, client side abort and minor delay (@iceman1001)
|
||||
- Added `hf seos sam` - Added support for HID SAM SEOS communications (@jkramarz)
|
||||
- Changed (extended) area accessible by spiffs into last page of FLASH (@piotrva)
|
||||
- Changed the extended area accessible by spiffs into last page of FLASH (@piotrva)
|
||||
- Changed flash-stored key dictionaries (Mifare, iClass, T55XX) and T55XX configurations to SPIFFS files (@piotrva)
|
||||
- Changed `lf em 410x sim` to use default gap value of 0 and extended help (@piotrva)
|
||||
- Changed `hf 14a info` - now identifies MIAFRE Duox (@iceman1001)
|
||||
@@ -54,13 +95,14 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
|
||||
- Changed extended area for Mifare keys in SPI flash to hold 4095 keys (@piotrva)
|
||||
- Fixed DESFire D40 secure channel crypto (@nvx)
|
||||
- Fixed `hf mfp info` fix signature check on 4b UID cards (@doegox)
|
||||
- Automatically set maximum read/write block when using predefined types in `hf_mf_ultimatecard` script (@piotrva)
|
||||
- Changed SPI flash detection to calculate the size instead of table lookup, updated spi_flash_decode.py script with more ICs (@ANTodorov)
|
||||
- Changed `hf_mf_ultimatecard` - it now automatically set maximum read/write block when using predefined types (@piotrva)
|
||||
- Changed SPI flash detection to calculate the size instead of table lookup (@ANTodorov)
|
||||
- Changed `spi_flash_decode.py` script with more ICs (@ANTodorov)
|
||||
- Fixed `hf/lf tune` segfault when called from script (@doegox)
|
||||
- Added option to set and get maximum read/write block number using `hf_mf_ultimatecard` script (@piotrva)
|
||||
- Changed `hf_mf_ultimatecard` - added option to set and get maximum read/write block number (@piotrva)
|
||||
- Added JEDEC information for SPI flash W25Q64JV (@ANTodorov)
|
||||
- Added special iclass legacy config cards in `hf iclass configcard` (@antiklesys)
|
||||
- Added simulation function to `hf iclass legrec` (@antiklesys)
|
||||
- Changed `hf iclass configcard` - added special iclass legacy config cards (@antiklesys)
|
||||
- Changed `hf iclass legrec` - added simulation function (@antiklesys)
|
||||
- Added keys from Momentum firmware projects. (@onovy)
|
||||
- Added Dutch Statistics Agency default key (@eagle00789)
|
||||
- Fixed Wiegand decode with hex input dropping the first bit (@emilyastranova)
|
||||
|
||||
@@ -204,7 +204,7 @@ help:
|
||||
@echo "+ fpga_compress - Make tools/fpga_compress"
|
||||
@echo
|
||||
@echo "+ style - Apply some automated source code formatting rules"
|
||||
@echo "+ commands - Regenerate commands documentation files and autocompletion data
|
||||
@echo "+ commands - Regenerate commands documentation files and autocompletion data"
|
||||
@echo "+ check - Run offline tests. Set CHECKARGS to pass arguments to the test script"
|
||||
@echo "+ .../check - Run offline tests against specific target. See above."
|
||||
@echo "+ miscchecks - Detect various encoding issues in source code"
|
||||
@@ -264,8 +264,11 @@ ifeq ($(PLATFORM_CHANGED),true)
|
||||
$(Q)$(MAKE) --no-print-directory -C bootrom clean
|
||||
$(Q)$(MAKE) --no-print-directory -C armsrc clean
|
||||
$(Q)$(MAKE) --no-print-directory -C recovery clean
|
||||
$(Q)$(MAKE) --no-print-directory -C client clean
|
||||
$(Q)$(MAKE) --no-print-directory -C tools/fpga_compress clean
|
||||
# clean the client only if PLATFORM got changed from or to PM3ICOPYX
|
||||
ifeq (PM3ICOPYX,$(filter PM3ICOPYX, $(PLATFORM) $(CACHED_PLATFORM)))
|
||||
$(Q)$(MAKE) --no-print-directory -C client clean
|
||||
endif
|
||||
$(Q)$(ECHO) CACHED_PLATFORM=$(PLATFORM) > .Makefile.options.cache
|
||||
$(Q)$(ECHO) CACHED_PLATFORM_EXTRAS=$(PLATFORM_EXTRAS) >> .Makefile.options.cache
|
||||
$(Q)$(ECHO) CACHED_PLATFORM_DEFS=$(PLATFORM_DEFS) >> .Makefile.options.cache
|
||||
|
||||
@@ -14,6 +14,9 @@ PLATFORM=PM3RDV4
|
||||
#PLATFORM=PM3ICOPYX
|
||||
#PLATFORM_EXTRAS=FLASH
|
||||
|
||||
# For PM3 Ultimate:
|
||||
# uncomment the line below
|
||||
#PLATFORM=PM3ULTIMATE
|
||||
|
||||
# If you want more than one PLATFORM_EXTRAS option, separate them by spaces:
|
||||
#PLATFORM_EXTRAS=BTADDON
|
||||
@@ -27,6 +30,10 @@ PLATFORM=PM3RDV4
|
||||
# Only available with PLATFORM=PM3GENERIC
|
||||
#LED_ORDER=PM3EASY
|
||||
|
||||
# Uncomment a line below to change default USART baud rate
|
||||
# defaults to 115200 used by HC-05 in Blueshark
|
||||
#USART_BAUD_RATE=19200
|
||||
|
||||
# Uncomment the lines below in order to make a 256KB image
|
||||
# and comment out the lines above
|
||||
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ void BigBuf_Clear_ext(bool verbose) {
|
||||
memset(BigBuf, 0, s_bigbuf_size);
|
||||
clear_trace();
|
||||
if (verbose) {
|
||||
Dbprintf("Buffer cleared (%i bytes)", s_bigbuf_size);
|
||||
if (g_dbglevel >= DBG_ERROR) Dbprintf("Buffer cleared (%i bytes)", s_bigbuf_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@
|
||||
|
||||
#define MAX_FRAME_SIZE 256 // maximum allowed ISO14443 frame
|
||||
#define MAX_PARITY_SIZE ((MAX_FRAME_SIZE + 7) / 8)
|
||||
#define MAX_MIFARE_FRAME_SIZE 18 // biggest Mifare frame is answer to a read (one block = 16 Bytes) + 2 Bytes CRC
|
||||
#define MAX_MIFARE_PARITY_SIZE 3 // need 18 parity bits for the 18 Byte above. 3 Bytes are enough to store these
|
||||
#define MAX_MIFARE_FRAME_SIZE 19 // biggest Mifare frame is UL AES answer to AUTH (1 + 16 Bytes) + 2 Bytes CRC
|
||||
#define MAX_MIFARE_PARITY_SIZE 3 // need 19 parity bits for the 19 Byte above. 3 Bytes are enough to store these
|
||||
#define CARD_MEMORY_SIZE 4096
|
||||
// For now we're storing FM11RF08S nonces in the upper 1k of CARD_MEMORY_SIZE
|
||||
// but we might have to allocate extra space if one day we've to support sth like a FM11RF32S
|
||||
|
||||
@@ -119,6 +119,9 @@ define KNOWN_STANDALONE_DEFINITIONS
|
||||
| HF_REBLAY | 14A Relay over BT |
|
||||
| (RDV4 only) | - Salvador Mendoza |
|
||||
+----------------------------------------------------------+
|
||||
| HF_ST25_TEAROFF | Store/restore ST25TB tags with |
|
||||
| | tear-off for counters - SecLabz |
|
||||
+----------------------------------------------------------+
|
||||
| HF_TCPRST | IKEA Rothult read/sim/dump/emul |
|
||||
| | - Nick Draffen |
|
||||
+----------------------------------------------------------+
|
||||
@@ -139,11 +142,11 @@ endef
|
||||
|
||||
STANDALONE_MODES := LF_SKELETON
|
||||
STANDALONE_MODES += LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RSWW LF_EM4100RWC LF_HIDBRUTE LF_HIDFCBRUTE LF_ICEHID LF_MULTIHID LF_NEDAP_SIM LF_NEXID LF_PROXBRUTE LF_PROX2BRUTE LF_SAMYRUN LF_THAREXDE
|
||||
STANDALONE_MODES += HF_14ASNIFF HF_14BSNIFF HF_15SNIFF HF_15SIM HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_CRAFTBYTE HF_ICECLASS HF_LEGIC HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG
|
||||
STANDALONE_MODES += HF_14ASNIFF HF_14BSNIFF HF_15SNIFF HF_15SIM HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_CRAFTBYTE HF_ICECLASS HF_LEGIC HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY HF_ST25_TEAROFF HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG
|
||||
STANDALONE_MODES += DANKARMULTI
|
||||
STANDALONE_MODES_REQ_BT := HF_CARDHOPPER HF_REBLAY
|
||||
STANDALONE_MODES_REQ_SMARTCARD :=
|
||||
STANDALONE_MODES_REQ_FLASH := LF_HIDFCBRUTE LF_ICEHID LF_NEXID LF_THAREXDE HF_BOG HF_COLIN HF_ICECLASS HF_LEGICSIM HF_MFCSIM
|
||||
STANDALONE_MODES_REQ_FLASH := LF_HIDFCBRUTE LF_ICEHID LF_NEXID LF_THAREXDE HF_BOG HF_COLIN HF_ICECLASS HF_LEGICSIM HF_MFCSIM HF_ST25_TEAROFF
|
||||
ifneq ($(filter $(STANDALONE),$(STANDALONE_MODES)),)
|
||||
STANDALONE_PLATFORM_DEFS += -DWITH_STANDALONE_$(STANDALONE)
|
||||
ifneq ($(filter $(STANDALONE),$(STANDALONE_MODES_REQ_SMARTCARD)),)
|
||||
|
||||
@@ -157,6 +157,10 @@ endif
|
||||
ifneq (,$(findstring WITH_STANDALONE_HF_YOUNG,$(APP_CFLAGS)))
|
||||
SRC_STANDALONE = hf_young.c
|
||||
endif
|
||||
# WITH_STANDALONE_HF_ST25_TEAROFF
|
||||
ifneq (,$(findstring WITH_STANDALONE_HF_ST25_TEAROFF,$(APP_CFLAGS)))
|
||||
SRC_STANDALONE = hf_st25_tearoff.c
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring WITH_STANDALONE_DANKARMULTI,$(APP_CFLAGS)))
|
||||
SRC_STANDALONE = dankarmulti.c
|
||||
|
||||
@@ -59,7 +59,7 @@ static const uint8_t magicCARD[4] = "CARD";
|
||||
static const uint8_t magicEND [4] = "\xff" "END";
|
||||
static const uint8_t magicRSRT[7] = "RESTART";
|
||||
static const uint8_t magicERR [4] = "\xff" "ERR";
|
||||
static uint8_t magicACK [1] = "\xfe"; // is constant, but must be passed to API that doesn't like that
|
||||
static const uint8_t magicACK [1] = "\xfe";
|
||||
|
||||
// Forward declarations
|
||||
static void become_reader(void);
|
||||
@@ -72,7 +72,7 @@ static bool try_use_canned_response(const uint8_t *, int, tag_response_info_t *)
|
||||
static void reply_with_packet(packet_t *);
|
||||
|
||||
static void read_packet(packet_t *);
|
||||
static void write_packet(packet_t *);
|
||||
static void write_packet(const packet_t *);
|
||||
|
||||
static bool GetIso14443aCommandFromReaderInterruptible(uint8_t *, uint16_t, uint8_t *, int *);
|
||||
|
||||
@@ -146,7 +146,7 @@ static void become_reader(void) {
|
||||
packet_t packet = { 0 };
|
||||
packet_t *rx = &packet;
|
||||
packet_t *tx = &packet;
|
||||
uint8_t toCard[256] = { 0 };
|
||||
uint8_t toCard[MAX_FRAME_SIZE] = { 0 };
|
||||
uint8_t parity[MAX_PARITY_SIZE] = { 0 };
|
||||
|
||||
while (1) {
|
||||
@@ -178,11 +178,15 @@ static void become_reader(void) {
|
||||
AddCrc14A(toCard, rx->len);
|
||||
ReaderTransmit(toCard, rx->len + 2, NULL);
|
||||
|
||||
tx->len = ReaderReceive(tx->dat, sizeof(tx->dat), parity);
|
||||
if (tx->len == 0) {
|
||||
// read to toCard instead of tx->dat directly to allow the extra byte for the CRC
|
||||
uint16_t fromCardLen = ReaderReceive(toCard, sizeof(toCard), parity);
|
||||
if (fromCardLen <= 2) {
|
||||
tx->len = sizeof(magicERR);
|
||||
memcpy(tx->dat, magicERR, sizeof(magicERR));
|
||||
} else tx->len -= 2; // cut off the CRC
|
||||
} else {
|
||||
tx->len = fromCardLen - 2; // cut off the CRC
|
||||
memcpy(tx->dat, toCard, tx->len);
|
||||
}
|
||||
|
||||
write_packet(tx);
|
||||
}
|
||||
@@ -229,14 +233,15 @@ static void become_card(void) {
|
||||
|
||||
tag_response_info_t *canned;
|
||||
uint32_t cuid;
|
||||
uint32_t counters[3] = { 0 };
|
||||
uint8_t tearings[3] = { 0xbd, 0xbd, 0xbd };
|
||||
uint8_t pages;
|
||||
SimulateIso14443aInit(tagType, flags, data, NULL, 0, &canned, &cuid, counters, tearings, &pages);
|
||||
if (SimulateIso14443aInit(tagType, flags, data, NULL, 0, &canned, &cuid, &pages) == false) {
|
||||
DbpString(_RED_("Error initializing the emulation process!"));
|
||||
return;
|
||||
}
|
||||
|
||||
DbpString(_CYAN_("[@]") " Setup done - entering emulation loop");
|
||||
int fromReaderLen;
|
||||
uint8_t fromReaderDat[256] = { 0 };
|
||||
uint8_t fromReaderDat[MAX_FRAME_SIZE] = { 0 };
|
||||
uint8_t parity[MAX_PARITY_SIZE] = { 0 };
|
||||
packet_t packet = { 0 };
|
||||
packet_t *tx = &packet;
|
||||
@@ -277,8 +282,14 @@ static void become_card(void) {
|
||||
memcpy(tx->dat, fromReaderDat, tx->len);
|
||||
write_packet(tx);
|
||||
|
||||
if (no_reply) {
|
||||
// since the RATS reply has already been sent waiting here will can result in missing the next reader command
|
||||
// if we do get a reply later on while waiting for the next reader message it will be safely ignored
|
||||
continue;
|
||||
}
|
||||
|
||||
read_packet(rx);
|
||||
if (!no_reply && rx->len > 0) {
|
||||
if (rx->len > 0) {
|
||||
reply_with_packet(rx);
|
||||
}
|
||||
}
|
||||
@@ -344,7 +355,13 @@ static void cook_ats(packet_t *ats, uint8_t fwi, uint8_t sfgi) {
|
||||
|
||||
uint8_t orig_t0 = ats->dat[1];
|
||||
// Update FSCI in T0 from the received ATS
|
||||
t0 |= orig_t0 & 0x0F;
|
||||
uint8_t fsci = orig_t0 & 0x0F;
|
||||
if (fsci > 8) {
|
||||
// our packet length maxes out at 255 bytes, an FSCI of 8 requires 256 bytes
|
||||
// but since we drop the 2 byte CRC16 we're safe capping this at 8
|
||||
fsci = 8;
|
||||
}
|
||||
t0 |= fsci;
|
||||
|
||||
uint8_t len = ats->len - 2;
|
||||
uint8_t *orig_ats_ptr = &ats->dat[2];
|
||||
@@ -449,20 +466,12 @@ static bool try_use_canned_response(const uint8_t *dat, int len, tag_response_in
|
||||
}
|
||||
|
||||
|
||||
static uint8_t g_responseBuffer [512 ] = { 0 };
|
||||
static uint8_t g_modulationBuffer[1024] = { 0 };
|
||||
static uint8_t g_responseBuffer [MAX_FRAME_SIZE] = { 0 };
|
||||
|
||||
static void reply_with_packet(packet_t *packet) {
|
||||
tag_response_info_t response = { 0 };
|
||||
response.response = g_responseBuffer;
|
||||
response.modulation = g_modulationBuffer;
|
||||
|
||||
memcpy(response.response, packet->dat, packet->len);
|
||||
AddCrc14A(response.response, packet->len);
|
||||
response.response_n = packet->len + 2;
|
||||
|
||||
prepare_tag_modulation(&response, sizeof(g_modulationBuffer));
|
||||
EmSendPrecompiledCmd(&response);
|
||||
memcpy(g_responseBuffer, packet->dat, packet->len);
|
||||
AddCrc14A(g_responseBuffer, packet->len);
|
||||
EmSendCmd(g_responseBuffer, packet->len + 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -496,19 +505,27 @@ static void read_packet(packet_t *packet) {
|
||||
|
||||
// clear any remaining buffered data
|
||||
while (cardhopper_data_available()) {
|
||||
cardhopper_read(packet->dat, 255);
|
||||
cardhopper_read(packet->dat, sizeof(packet->dat));
|
||||
}
|
||||
|
||||
packet->len = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
cardhopper_write(magicACK, sizeof(magicACK));
|
||||
|
||||
if (packet->len > (MAX_FRAME_SIZE - 2)) {
|
||||
// this will overrun MAX_FRAME_SIZE once we re-add the CRC
|
||||
// in theory this should never happen but better to be defensive
|
||||
packet->len = 0;
|
||||
cardhopper_write(magicERR, sizeof(magicERR));
|
||||
} else {
|
||||
cardhopper_write(magicACK, sizeof(magicACK));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void write_packet(packet_t *packet) {
|
||||
cardhopper_write((uint8_t *) packet, packet->len + 1);
|
||||
static void write_packet(const packet_t *packet) {
|
||||
cardhopper_write((const uint8_t *) packet, packet->len + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "mifaresim.h" // mifare1ksim
|
||||
#include "mifareutil.h"
|
||||
#include "proxmark3_arm.h"
|
||||
#include "spiffs.h"
|
||||
#include "standalone.h" // standalone definitions
|
||||
#include "string.h"
|
||||
#include "ticks.h"
|
||||
@@ -534,7 +535,14 @@ void RunMod(void) {
|
||||
SpinErr(LED_D, 50, 8);
|
||||
partialEmulation = true;
|
||||
} else {
|
||||
DbpString("[" _GREEN_("+") "] " _GREEN_("Emulator memory filled completely."));
|
||||
#ifdef WITH_FLASH
|
||||
DbpString("[" _GREEN_("+") "] " _GREEN_("Emulator memory filled completely. Start storing card in spiff memory."));
|
||||
uint8_t *emCARD = BigBuf_get_EM_addr();
|
||||
char dumpFileName[30] = {0};
|
||||
sprintf(dumpFileName, DUMP_FILE, mattyrun_card.uid[0], mattyrun_card.uid[1], mattyrun_card.uid[2], mattyrun_card.uid[3]);
|
||||
rdv40_spiffs_write(dumpFileName, emCARD, 1024, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
Dbprintf("[" _GREEN_("+") "] " _GREEN_("Stored card on %s"), dumpFileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
state = STATE_EMULATE;
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
// Filename to store the card info in spiff memory
|
||||
#define DUMP_FILE "hf_mattyrun_dump_%02x%02x%02x%02x.bin"
|
||||
|
||||
// Set of standard keys to be used
|
||||
static uint64_t const MATTYRUN_MFC_DEFAULT_KEYS[] = {
|
||||
0xFFFFFFFFFFFF, // Default key
|
||||
|
||||
@@ -379,7 +379,7 @@ void RunMod(void) {
|
||||
BigBuf_free_keep_EM();
|
||||
|
||||
// tag type: 11 = ISO/IEC 14443-4 - javacard (JCOP)
|
||||
if (SimulateIso14443aInit(11, flags, data, NULL, 0, &responses, &cuid, NULL, NULL, NULL) == false) {
|
||||
if (SimulateIso14443aInit(11, flags, data, NULL, 0, &responses, &cuid, NULL) == false) {
|
||||
BigBuf_free_keep_EM();
|
||||
reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EINIT, NULL, 0);
|
||||
DbpString(_RED_("Error initializing the emulation process!"));
|
||||
|
||||
@@ -268,7 +268,7 @@ void RunMod() {
|
||||
BigBuf_free_keep_EM();
|
||||
|
||||
// 4 = ISO/IEC 14443-4 - javacard (JCOP)
|
||||
if (SimulateIso14443aInit(4, flags, data, NULL, 0, &responses, &cuid, NULL, NULL, NULL) == false) {
|
||||
if (SimulateIso14443aInit(4, flags, data, NULL, 0, &responses, &cuid, NULL) == false) {
|
||||
BigBuf_free_keep_EM();
|
||||
reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EINIT, NULL, 0);
|
||||
DbpString(_RED_("Error initializing the emulation process!"));
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -118,8 +118,6 @@ void RunMod(void) {
|
||||
uint8_t tagType = 10; // 10 = ST25TA IKEA Rothult
|
||||
tag_response_info_t *responses;
|
||||
uint32_t cuid = 0;
|
||||
uint32_t counters[3] = { 0x00, 0x00, 0x00 };
|
||||
uint8_t tearings[3] = { 0xbd, 0xbd, 0xbd };
|
||||
uint8_t pages = 0;
|
||||
|
||||
// command buffers
|
||||
@@ -193,7 +191,7 @@ void RunMod(void) {
|
||||
|
||||
memcpy(data, stuid, sizeof(stuid));
|
||||
|
||||
if (SimulateIso14443aInit(tagType, flags, data, NULL, 0, &responses, &cuid, counters, tearings, &pages) == false) {
|
||||
if (SimulateIso14443aInit(tagType, flags, data, NULL, 0, &responses, &cuid, &pages) == false) {
|
||||
BigBuf_free_keep_EM();
|
||||
reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EINIT, NULL, 0);
|
||||
DbpString(_YELLOW_("!!") "Error initializing the simulation process!");
|
||||
@@ -371,7 +369,7 @@ void RunMod(void) {
|
||||
|
||||
memcpy(data, stuid, sizeof(stuid));
|
||||
|
||||
if (SimulateIso14443aInit(tagType, flags, data, NULL, 0, &responses, &cuid, counters, tearings, &pages) == false) {
|
||||
if (SimulateIso14443aInit(tagType, flags, data, NULL, 0, &responses, &cuid, &pages) == false) {
|
||||
BigBuf_free_keep_EM();
|
||||
reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EINIT, NULL, 0);
|
||||
DbpString(_YELLOW_("!!") "Error initializing the simulation process!");
|
||||
|
||||
+31
-23
@@ -99,12 +99,13 @@ int tearoff_hook(void) {
|
||||
if (g_tearoff_enabled) {
|
||||
if (g_tearoff_delay_us == 0) {
|
||||
Dbprintf(_RED_("No tear-off delay configured!"));
|
||||
g_tearoff_enabled = false;
|
||||
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
|
||||
}
|
||||
SpinDelayUsPrecision(g_tearoff_delay_us);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
g_tearoff_enabled = false;
|
||||
Dbprintf(_YELLOW_("Tear-off triggered!"));
|
||||
if (g_dbglevel >= DBG_ERROR) Dbprintf(_YELLOW_("Tear-off triggered!"));
|
||||
return PM3_ETEAROFF;
|
||||
} else {
|
||||
return PM3_SUCCESS; // SUCCESS = the hook didn't do anything
|
||||
@@ -254,7 +255,7 @@ static uint32_t MeasureAntennaTuningLfData(void) {
|
||||
void print_stack_usage(void) {
|
||||
for (uint32_t *p = _stack_start; ; ++p) {
|
||||
if (*p != 0xdeadbeef) {
|
||||
Dbprintf(" Max stack usage......... %d / %d bytes", (uint32_t)_stack_end - (uint32_t)p, (uint32_t)_stack_end - (uint32_t)_stack_start);
|
||||
Dbprintf(" Max stack usage..... %d / %d bytes", (uint32_t)_stack_end - (uint32_t)p, (uint32_t)_stack_end - (uint32_t)_stack_start);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -365,7 +366,7 @@ static void print_debug_level(void) {
|
||||
sprintf(dbglvlstr, "extended");
|
||||
break;
|
||||
}
|
||||
Dbprintf(" Debug log level......... %d ( " _YELLOW_("%s")" )", g_dbglevel, dbglvlstr);
|
||||
Dbprintf(" Debug log level..... %d ( " _YELLOW_("%s")" )", g_dbglevel, dbglvlstr);
|
||||
}
|
||||
|
||||
// measure the Connection Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
|
||||
@@ -421,11 +422,11 @@ static void SendStatus(uint32_t wait) {
|
||||
print_debug_level();
|
||||
|
||||
tosend_t *ts = get_tosend();
|
||||
Dbprintf(" ToSendMax............... %d", ts->max);
|
||||
Dbprintf(" ToSend BUFFERSIZE....... %d", TOSEND_BUFFER_SIZE);
|
||||
Dbprintf(" ToSendMax........... %d", ts->max);
|
||||
Dbprintf(" ToSend BUFFERSIZE... %d", TOSEND_BUFFER_SIZE);
|
||||
while ((AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINRDY) == 0); // Wait for MAINF value to become available...
|
||||
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINF; // Get # main clocks within 16 slow clocks
|
||||
Dbprintf(" Slow clock.............. %d Hz", (16 * MAINCK) / mainf);
|
||||
Dbprintf(" Slow clock.......... %d Hz", (16 * MAINCK) / mainf);
|
||||
uint32_t delta_time = 0;
|
||||
uint32_t start_time = GetTickCount();
|
||||
#define SLCK_CHECK_MS 50
|
||||
@@ -449,10 +450,11 @@ static void SendStatus(uint32_t wait) {
|
||||
} else {
|
||||
num = 0;
|
||||
}
|
||||
|
||||
if (num > 0) {
|
||||
Dbprintf(" Mifare.................. "_YELLOW_("%u")" keys (spiffs: "_GREEN_("%s")")", num, MF_KEYS_FILE);
|
||||
Dbprintf(" Mifare... "_YELLOW_("%u")" keys - "_GREEN_("%s"), num, MF_KEYS_FILE);
|
||||
} else {
|
||||
Dbprintf(" Mifare.................. "_RED_("%u")" keys (spiffs: "_RED_("%s")")", num, MF_KEYS_FILE);
|
||||
Dbprintf(" Mifare... "_RED_("%u")" keys - "_RED_("%s"), num, MF_KEYS_FILE);
|
||||
}
|
||||
|
||||
if (exists_in_spiffs(T55XX_KEYS_FILE)) {
|
||||
@@ -460,10 +462,11 @@ static void SendStatus(uint32_t wait) {
|
||||
} else {
|
||||
num = 0;
|
||||
}
|
||||
|
||||
if (num > 0) {
|
||||
Dbprintf(" T55xx................... "_YELLOW_("%u")" keys (spiffs: "_GREEN_("%s")")", num, T55XX_KEYS_FILE);
|
||||
Dbprintf(" T55xx.... "_YELLOW_("%u")" keys - "_GREEN_("%s"), num, T55XX_KEYS_FILE);
|
||||
} else {
|
||||
Dbprintf(" T55xx................... "_RED_("%u")" keys (spiffs: "_RED_("%s")")", num, T55XX_KEYS_FILE);
|
||||
Dbprintf(" T55xx.... "_RED_("%u")" keys - "_RED_("%s"), num, T55XX_KEYS_FILE);
|
||||
}
|
||||
|
||||
if (exists_in_spiffs(ICLASS_KEYS_FILE)) {
|
||||
@@ -471,10 +474,11 @@ static void SendStatus(uint32_t wait) {
|
||||
} else {
|
||||
num = 0;
|
||||
}
|
||||
|
||||
if (num > 0) {
|
||||
Dbprintf(" iClass.................. "_YELLOW_("%u")" keys (spiffs: "_GREEN_("%s")")", num, ICLASS_KEYS_FILE);
|
||||
Dbprintf(" iClass... "_YELLOW_("%u")" keys - "_GREEN_("%s"), num, ICLASS_KEYS_FILE);
|
||||
} else {
|
||||
Dbprintf(" iClass.................. "_RED_("%u")" keys (spiffs: "_RED_("%s")")", num, ICLASS_KEYS_FILE);
|
||||
Dbprintf(" iClass... "_RED_("%u")" keys - "_RED_("%s"), num, ICLASS_KEYS_FILE);
|
||||
}
|
||||
#endif
|
||||
DbpString("");
|
||||
@@ -1664,13 +1668,13 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
break;
|
||||
}
|
||||
case CMD_HF_ISO14443A_GET_CONFIG: {
|
||||
hf14a_config *hf14aconfig = getHf14aConfig();
|
||||
reply_ng(CMD_HF_ISO14443A_GET_CONFIG, PM3_SUCCESS, (uint8_t *)hf14aconfig, sizeof(hf14a_config));
|
||||
hf14a_config_t *c = getHf14aConfig();
|
||||
reply_ng(CMD_HF_ISO14443A_GET_CONFIG, PM3_SUCCESS, (uint8_t *)c, sizeof(hf14a_config_t));
|
||||
break;
|
||||
}
|
||||
case CMD_HF_ISO14443A_SET_CONFIG: {
|
||||
hf14a_config c;
|
||||
memcpy(&c, packet->data.asBytes, sizeof(hf14a_config));
|
||||
hf14a_config_t c;
|
||||
memcpy(&c, packet->data.asBytes, sizeof(hf14a_config_t));
|
||||
setHf14aConfig(&c);
|
||||
break;
|
||||
}
|
||||
@@ -1806,7 +1810,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
struct p {
|
||||
bool turn_off_field;
|
||||
uint8_t keyno;
|
||||
uint8_t key[18];
|
||||
uint8_t key[16];
|
||||
} PACKED;
|
||||
struct p *payload = (struct p *) packet->data.asBytes;
|
||||
MifareUL_AES_Auth(payload->turn_off_field, payload->keyno, payload->key);
|
||||
@@ -1969,7 +1973,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
struct p *payload = (struct p *) packet->data.asBytes;
|
||||
|
||||
//
|
||||
size_t size = payload->blockno * payload->blockwidth;
|
||||
size_t size = payload->blockcnt * payload->blockwidth;
|
||||
if (size > PM3_CMD_DATA_SIZE) {
|
||||
reply_ng(CMD_HF_MIFARE_EML_MEMGET, PM3_EMALLOC, NULL, 0);
|
||||
return;
|
||||
@@ -2226,6 +2230,10 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
iclass_credit_epurse((iclass_credit_epurse_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_HF_ICLASS_TEARBL: {
|
||||
iClass_TearBlock((iclass_tearblock_req_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_HFSNIFF
|
||||
@@ -2354,7 +2362,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
|
||||
uint16_t available;
|
||||
uint16_t pre_available = 0;
|
||||
uint8_t *dest = BigBuf_malloc(USART_FIFOLEN);
|
||||
uint8_t *dest = BigBuf_calloc(USART_FIFOLEN);
|
||||
uint32_t wait = payload->waittime;
|
||||
|
||||
StartTicks();
|
||||
@@ -2398,7 +2406,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
|
||||
uint16_t available;
|
||||
uint16_t pre_available = 0;
|
||||
uint8_t *dest = BigBuf_malloc(USART_FIFOLEN);
|
||||
uint8_t *dest = BigBuf_calloc(USART_FIFOLEN);
|
||||
uint32_t wait = payload->waittime;
|
||||
|
||||
StartTicks();
|
||||
@@ -2694,7 +2702,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
|
||||
uint32_t size = packet->oldarg[1];
|
||||
|
||||
uint8_t *buff = BigBuf_malloc(size);
|
||||
uint8_t *buff = BigBuf_calloc(size);
|
||||
if (buff == NULL) {
|
||||
if (g_dbglevel >= DBG_DEBUG) Dbprintf("Failed to allocate memory");
|
||||
// Trigger a finish downloading signal with an PM3_EMALLOC
|
||||
@@ -2899,7 +2907,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
case CMD_FLASHMEM_DOWNLOAD: {
|
||||
|
||||
LED_B_ON();
|
||||
uint8_t *mem = BigBuf_malloc(PM3_CMD_DATA_SIZE);
|
||||
uint8_t *mem = BigBuf_calloc(PM3_CMD_DATA_SIZE);
|
||||
uint32_t startidx = packet->oldarg[0];
|
||||
uint32_t numofbytes = packet->oldarg[1];
|
||||
// arg0 = startindex
|
||||
@@ -2931,7 +2939,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||
case CMD_FLASHMEM_INFO: {
|
||||
|
||||
LED_B_ON();
|
||||
rdv40_validation_t *info = (rdv40_validation_t *)BigBuf_malloc(sizeof(rdv40_validation_t));
|
||||
rdv40_validation_t *info = (rdv40_validation_t *)BigBuf_calloc(sizeof(rdv40_validation_t));
|
||||
|
||||
bool isok = Flash_ReadData(FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_pages64k), info->signature, FLASH_MEM_SIGNATURE_LEN);
|
||||
|
||||
|
||||
+1
-1
@@ -748,7 +748,7 @@ void em4x50_chk(const char *filename, bool ledcontrol) {
|
||||
uint16_t pwd_count = 0;
|
||||
uint32_t size = size_in_spiffs(filename);
|
||||
pwd_count = size / 4;
|
||||
uint8_t *pwds = BigBuf_malloc(size);
|
||||
uint8_t *pwds = BigBuf_calloc(size);
|
||||
|
||||
rdv40_spiffs_read_as_filetype(filename, pwds, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
|
||||
|
||||
+25
-31
@@ -45,7 +45,7 @@
|
||||
#define DPRINTF_EXTENDED(x) do { if ((FORCE_ENABLE_LOGGING) || (g_dbglevel >= DBG_EXTENDED)) { Dbprintf x ; } } while (0);
|
||||
#define DPRINTF_PROLIX(x) do { if ((FORCE_ENABLE_LOGGING) || (g_dbglevel > DBG_EXTENDED)) { Dbprintf x ; } } while (0);
|
||||
// EM4170 requires a parity bit on commands, other variants do not.
|
||||
static bool g_command_parity = true;
|
||||
static bool g_deprecated_command_parity = false;
|
||||
static em4x70_tag_t g_tag = { 0 };
|
||||
|
||||
|
||||
@@ -905,8 +905,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_id(em4x70_command_bitstream_t
|
||||
bool result = true;
|
||||
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
|
||||
out_cmd_bitstream->command = EM4X70_COMMAND_ID;
|
||||
//uint8_t cmd = with_command_parity ? 0x3u : 0x1u;
|
||||
uint8_t cmd = 0x3u;
|
||||
uint8_t cmd = 0x3u; // CMD + Parity bit == 0b001'1
|
||||
result = result && add_nibble_to_bitstream(&out_cmd_bitstream->to_send, cmd, false);
|
||||
out_cmd_bitstream->to_receive.bitcount = 32;
|
||||
if (out_cmd_bitstream->to_send.bitcount != expected_bits_to_send) {
|
||||
@@ -920,8 +919,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_um1(em4x70_command_bitstream_
|
||||
bool result = true;
|
||||
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
|
||||
out_cmd_bitstream->command = EM4X70_COMMAND_UM1;
|
||||
//uint8_t cmd = with_command_parity ? 0x5u : 0x2u;
|
||||
uint8_t cmd = 0x5u;
|
||||
uint8_t cmd = 0x5u; // CMD + Parity bit == 0b010'1
|
||||
result = result && add_nibble_to_bitstream(&out_cmd_bitstream->to_send, cmd, false);
|
||||
out_cmd_bitstream->to_receive.bitcount = 32;
|
||||
if (out_cmd_bitstream->to_send.bitcount != expected_bits_to_send) {
|
||||
@@ -935,8 +933,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_um2(em4x70_command_bitstream_
|
||||
bool result = true;
|
||||
memset(out_cmd_bitstream, 0, sizeof(em4x70_command_bitstream_t));
|
||||
out_cmd_bitstream->command = EM4X70_COMMAND_UM2;
|
||||
//uint8_t cmd = with_command_parity ? 0xFu : 0x7u;
|
||||
uint8_t cmd = 0xFu;
|
||||
uint8_t cmd = 0xFu; // CMD + Parity bit == 0b111'1
|
||||
result = result && add_nibble_to_bitstream(&out_cmd_bitstream->to_send, cmd, false);
|
||||
out_cmd_bitstream->to_receive.bitcount = 64;
|
||||
if (out_cmd_bitstream->to_send.bitcount != expected_bits_to_send) {
|
||||
@@ -954,8 +951,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_auth(em4x70_command_bitstream
|
||||
|
||||
em4x70_bitstream_t *s = &out_cmd_bitstream->to_send;
|
||||
|
||||
// uint8_t cmd = with_command_parity ? 0x6u : 0x3u;
|
||||
uint8_t cmd = 0x6u; // HACK - always sent with cmd parity
|
||||
uint8_t cmd = 0x6u; // CMD + Parity bit == 0b011'0
|
||||
result = result && add_nibble_to_bitstream(s, cmd, false);
|
||||
|
||||
// Reader: [RM][0][Command][N55..N0][0000000][f(RN)27..f(RN)0]
|
||||
@@ -1004,8 +1000,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_pin(em4x70_command_bitstream_
|
||||
|
||||
out_cmd_bitstream->command = EM4X70_COMMAND_PIN;
|
||||
|
||||
//uint8_t cmd = with_command_parity ? 0x9u : 0x4u;
|
||||
uint8_t cmd = 0x9u; // HACK - always sent with cmd parity, with extra zero bit in RM?
|
||||
uint8_t cmd = 0x9u; // CMD + Parity bit == 0b100'1
|
||||
result = result && add_nibble_to_bitstream(s, cmd, false);
|
||||
|
||||
// Send tag's ID ... indexes 4 .. 35
|
||||
@@ -1037,8 +1032,7 @@ static bool create_legacy_em4x70_bitstream_for_cmd_write(em4x70_command_bitstrea
|
||||
|
||||
em4x70_bitstream_t *s = &out_cmd_bitstream->to_send;
|
||||
|
||||
//uint8_t cmd = with_command_parity ? 0xAu : 0x5u;
|
||||
uint8_t cmd = 0xAu; // HACK - always sent with cmd parity, with extra zero bit in RM?
|
||||
uint8_t cmd = 0xAu; // CMD + Parity bit == 0b101'0
|
||||
result = result && add_nibble_to_bitstream(s, cmd, false);
|
||||
|
||||
if ((address & 0x0Fu) != address) {
|
||||
@@ -1097,7 +1091,7 @@ static int authenticate(const uint8_t *rnd, const uint8_t *frnd, uint8_t *respon
|
||||
em4x70_command_bitstream_t auth_cmd;
|
||||
|
||||
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
|
||||
generator->auth(&auth_cmd, g_command_parity, rnd, frnd);
|
||||
generator->auth(&auth_cmd, g_deprecated_command_parity, rnd, frnd);
|
||||
|
||||
bool result = send_bitstream_and_read(&auth_cmd);
|
||||
if (result) {
|
||||
@@ -1185,7 +1179,7 @@ static int bruteforce(const uint8_t address, const uint8_t *rnd, const uint8_t *
|
||||
static int send_pin(const uint32_t pin) {
|
||||
em4x70_command_bitstream_t send_pin_cmd;
|
||||
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
|
||||
generator->pin(&send_pin_cmd, g_command_parity, &g_tag.data[4], pin);
|
||||
generator->pin(&send_pin_cmd, g_deprecated_command_parity, &g_tag.data[4], pin);
|
||||
|
||||
bool result = send_bitstream_wait_ack_wait_read(&send_pin_cmd);
|
||||
return result ? PM3_SUCCESS : PM3_ESOFT;
|
||||
@@ -1196,7 +1190,7 @@ static int write(const uint16_t word, const uint8_t address) {
|
||||
em4x70_command_bitstream_t write_cmd;
|
||||
|
||||
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
|
||||
generator->write(&write_cmd, g_command_parity, word, address);
|
||||
generator->write(&write_cmd, g_deprecated_command_parity, word, address);
|
||||
|
||||
bool result = send_bitstream_wait_ack_wait_ack(&write_cmd);
|
||||
if (!result) {
|
||||
@@ -1283,7 +1277,7 @@ static uint8_t encoded_bit_array_to_byte(const uint8_t *bits, int count_of_bits)
|
||||
static bool em4x70_read_id(void) {
|
||||
em4x70_command_bitstream_t read_id_cmd;
|
||||
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
|
||||
generator->id(&read_id_cmd, g_command_parity);
|
||||
generator->id(&read_id_cmd, g_deprecated_command_parity);
|
||||
|
||||
bool result = send_bitstream_and_read(&read_id_cmd);
|
||||
if (result) {
|
||||
@@ -1300,7 +1294,7 @@ static bool em4x70_read_id(void) {
|
||||
static bool em4x70_read_um1(void) {
|
||||
em4x70_command_bitstream_t read_um1_cmd;
|
||||
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
|
||||
generator->um1(&read_um1_cmd, g_command_parity);
|
||||
generator->um1(&read_um1_cmd, g_deprecated_command_parity);
|
||||
|
||||
bool result = send_bitstream_and_read(&read_um1_cmd);
|
||||
if (result) {
|
||||
@@ -1319,7 +1313,7 @@ static bool em4x70_read_um1(void) {
|
||||
static bool em4x70_read_um2(void) {
|
||||
em4x70_command_bitstream_t read_um2_cmd;
|
||||
const em4x70_command_generators_t *generator = &legacy_em4x70_command_generators;
|
||||
generator->um2(&read_um2_cmd, g_command_parity);
|
||||
generator->um2(&read_um2_cmd, g_deprecated_command_parity);
|
||||
|
||||
bool result = send_bitstream_and_read(&read_um2_cmd);
|
||||
if (result) {
|
||||
@@ -1435,7 +1429,7 @@ void em4x70_info(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
bool success_with_UM2 = false;
|
||||
|
||||
// Support tags with and without command parity bits
|
||||
g_command_parity = etd->parity;
|
||||
g_deprecated_command_parity = false;
|
||||
|
||||
init_tag();
|
||||
em4x70_setup_read();
|
||||
@@ -1463,10 +1457,10 @@ void em4x70_info(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
void em4x70_write(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
int status = PM3_ESOFT;
|
||||
|
||||
g_command_parity = etd->parity;
|
||||
g_deprecated_command_parity = false;
|
||||
|
||||
// Disable to prevent sending corrupted data to the tag.
|
||||
if (g_command_parity) {
|
||||
if (g_deprecated_command_parity) {
|
||||
DPRINTF_ALWAYS(("Use of `--par` option with `lf em 4x70 write` is non-functional and may corrupt data on the tag."));
|
||||
// reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
|
||||
// return;
|
||||
@@ -1499,7 +1493,7 @@ void em4x70_unlock(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
|
||||
int status = PM3_ESOFT;
|
||||
|
||||
g_command_parity = etd->parity;
|
||||
g_deprecated_command_parity = false;
|
||||
|
||||
init_tag();
|
||||
em4x70_setup_read();
|
||||
@@ -1534,10 +1528,10 @@ void em4x70_auth(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
|
||||
uint8_t response[3] = {0};
|
||||
|
||||
g_command_parity = etd->parity;
|
||||
g_deprecated_command_parity = false;
|
||||
|
||||
// Disable to prevent sending corrupted data to the tag.
|
||||
if (g_command_parity) {
|
||||
if (g_deprecated_command_parity) {
|
||||
DPRINTF_ALWAYS(("Use of `--par` option with `lf em 4x70 auth` is non-functional."));
|
||||
// reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
|
||||
// return;
|
||||
@@ -1562,10 +1556,10 @@ void em4x70_brute(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
int status = PM3_ESOFT;
|
||||
uint8_t response[2] = {0};
|
||||
|
||||
g_command_parity = etd->parity;
|
||||
g_deprecated_command_parity = false;
|
||||
|
||||
// Disable to prevent sending corrupted data to the tag.
|
||||
if (g_command_parity) {
|
||||
if (g_deprecated_command_parity) {
|
||||
DPRINTF_ALWAYS(("Use of `--par` option with `lf em 4x70 brute` is non-functional and may corrupt data on the tag."));
|
||||
// reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
|
||||
// return;
|
||||
@@ -1590,10 +1584,10 @@ void em4x70_write_pin(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
|
||||
int status = PM3_ESOFT;
|
||||
|
||||
g_command_parity = etd->parity;
|
||||
g_deprecated_command_parity = false;
|
||||
|
||||
// Disable to prevent sending corrupted data to the tag.
|
||||
if (g_command_parity) {
|
||||
if (g_deprecated_command_parity) {
|
||||
DPRINTF_ALWAYS(("Use of `--par` option with `lf em 4x70 setpin` is non-functional and may corrupt data on the tag."));
|
||||
// reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
|
||||
// return;
|
||||
@@ -1639,10 +1633,10 @@ void em4x70_write_key(const em4x70_data_t *etd, bool ledcontrol) {
|
||||
|
||||
int status = PM3_ESOFT;
|
||||
|
||||
g_command_parity = etd->parity;
|
||||
g_deprecated_command_parity = false;
|
||||
|
||||
// Disable to prevent sending corrupted data to the tag.
|
||||
if (g_command_parity) {
|
||||
if (g_deprecated_command_parity) {
|
||||
DPRINTF_ALWAYS(("Use of `--par` option with `lf em 4x70 setkey` is non-functional and may corrupt data on the tag."));
|
||||
// reply_ng(CMD_LF_EM4X70_WRITE, PM3_ENOTIMPL, NULL, 0);
|
||||
// return;
|
||||
|
||||
+2
-2
@@ -857,7 +857,7 @@ void SmartCardRaw(const smart_card_raw_t *p) {
|
||||
LED_D_ON();
|
||||
|
||||
uint16_t len = 0;
|
||||
uint8_t *resp = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *resp = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
// check if alloacted...
|
||||
smartcard_command_t flags = p->flags;
|
||||
|
||||
@@ -937,7 +937,7 @@ void SmartCardUpgrade(uint64_t arg0) {
|
||||
bool isOK = true;
|
||||
uint16_t length = arg0, pos = 0;
|
||||
const uint8_t *fwdata = BigBuf_get_addr();
|
||||
uint8_t *verfiydata = BigBuf_malloc(I2C_BLOCK_SIZE);
|
||||
uint8_t *verfiydata = BigBuf_calloc(I2C_BLOCK_SIZE);
|
||||
|
||||
while (length) {
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@
|
||||
// 8051 speaks with smart card.
|
||||
// 1000*50*3.07 = 153.5ms
|
||||
// 1 byte transfer == 1ms with max frame being 256 bytes
|
||||
#define SIM_WAIT_DELAY 88000 // about 270ms delay // 109773 -- about 337.7ms delay
|
||||
#define SIM_WAIT_DELAY 150000 // about 270ms delay // 109773 -- about 337.7ms delay
|
||||
|
||||
|
||||
void I2C_recovery(void);
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ static void SmartCardDirectSend(uint8_t prepend, const smart_card_raw_t *p, uint
|
||||
LED_D_ON();
|
||||
|
||||
uint16_t len = 0;
|
||||
uint8_t *resp = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *resp = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
resp[0] = prepend;
|
||||
// check if alloacted...
|
||||
smartcard_command_t flags = p->flags;
|
||||
|
||||
+787
-151
File diff suppressed because it is too large.
Load diff
@@ -34,6 +34,7 @@
|
||||
// times in samples @ 212kHz when acting as reader
|
||||
#define ICLASS_READER_TIMEOUT_ACTALL 330 // 1558us, nominal 330us + 7slots*160us = 1450us
|
||||
#define ICLASS_READER_TIMEOUT_UPDATE 3390 // 16000us, nominal 4-15ms
|
||||
#define ICLASS_READER_TIMEOUT_UPDATE_FAST 1500 // A copy of ICLASS_READER_TIMEOUT_UPDATE with reduced timeout values
|
||||
#define ICLASS_READER_TIMEOUT_OTHERS 80 // 380us, nominal 330us
|
||||
|
||||
// The length of a received command will in most cases be no more than 18 bytes.
|
||||
@@ -72,4 +73,5 @@ uint8_t get_pagemap(const picopass_hdr_t *hdr);
|
||||
void iclass_send_as_reader(uint8_t *frame, int len, uint32_t *start_time, uint32_t *end_time, bool shallow_mod);
|
||||
|
||||
void iClass_Recover(iclass_recover_req_t *msg);
|
||||
void iClass_TearBlock(iclass_tearblock_req_t *msg);
|
||||
#endif
|
||||
+181
-91
@@ -36,9 +36,9 @@
|
||||
#include "protocols.h"
|
||||
#include "generator.h"
|
||||
#include "desfire_crypto.h" // UL-C authentication helpers
|
||||
#include "mifare.h" // for iso14a_polling_frame_t structure
|
||||
|
||||
#define MAX_ISO14A_TIMEOUT 524288
|
||||
|
||||
// this timeout is in MS
|
||||
static uint32_t iso14a_timeout;
|
||||
|
||||
@@ -133,6 +133,34 @@ static uint32_t LastProxToAirDuration;
|
||||
#define SEC_Y 0x00
|
||||
#define SEC_Z 0xc0
|
||||
|
||||
|
||||
static const iso14a_polling_frame_t WUPA_CMD_FRAME = {
|
||||
.frame = { ISO14443A_CMD_WUPA },
|
||||
.frame_length = 1,
|
||||
.last_byte_bits = 7,
|
||||
.extra_delay = 0
|
||||
};
|
||||
|
||||
static const iso14a_polling_frame_t MAGWUPA_CMD_FRAMES[] = {
|
||||
{{ MAGSAFE_CMD_WUPA_1 }, 1, 7, 0},
|
||||
{{ MAGSAFE_CMD_WUPA_2 }, 1, 7, 0},
|
||||
{{ MAGSAFE_CMD_WUPA_3 }, 1, 7, 0},
|
||||
{{ MAGSAFE_CMD_WUPA_4 }, 1, 7, 0}
|
||||
};
|
||||
|
||||
// Polling frames and configurations
|
||||
iso14a_polling_parameters_t WUPA_POLLING_PARAMETERS = {
|
||||
.frames = { {{ ISO14443A_CMD_WUPA }, 1, 7, 0 }},
|
||||
.frame_count = 1,
|
||||
.extra_timeout = 0,
|
||||
};
|
||||
|
||||
iso14a_polling_parameters_t REQA_POLLING_PARAMETERS = {
|
||||
.frames = { {{ ISO14443A_CMD_REQA }, 1, 7, 0 }},
|
||||
.frame_count = 1,
|
||||
.extra_timeout = 0,
|
||||
};
|
||||
|
||||
/*
|
||||
Default HF 14a config is set to:
|
||||
forceanticol = 0 (auto)
|
||||
@@ -140,21 +168,17 @@ Default HF 14a config is set to:
|
||||
forcecl2 = 0 (auto)
|
||||
forcecl3 = 0 (auto)
|
||||
forcerats = 0 (auto)
|
||||
magsafe = 0 (disabled)
|
||||
polling_loop_annotation = {{0}, 0, 0, 0} (disabled)
|
||||
*/
|
||||
static hf14a_config hf14aconfig = { 0, 0, 0, 0, 0 } ;
|
||||
static hf14a_config_t hf14aconfig = { 0, 0, 0, 0, 0, 0, {{0}, 0, 0, 0} };
|
||||
|
||||
static iso14a_polling_parameters_t hf14a_polling_parameters = {
|
||||
.frames = { {{ ISO14443A_CMD_WUPA }, 1, 7, 0 }},
|
||||
.frame_count = 1,
|
||||
.extra_timeout = 0
|
||||
};
|
||||
|
||||
// Polling frames and configurations
|
||||
iso14a_polling_parameters_t WUPA_POLLING_PARAMETERS = {
|
||||
.frames = { {{ ISO14443A_CMD_WUPA }, 1, 7, 0} },
|
||||
.frame_count = 1,
|
||||
.extra_timeout = 0,
|
||||
};
|
||||
iso14a_polling_parameters_t REQA_POLLING_PARAMETERS = {
|
||||
.frames = { {{ ISO14443A_CMD_REQA }, 1, 7, 0} },
|
||||
.frame_count = 1,
|
||||
.extra_timeout = 0,
|
||||
};
|
||||
|
||||
// parity isn't used much
|
||||
static uint8_t parity_array[MAX_PARITY_SIZE] = {0};
|
||||
@@ -166,31 +190,40 @@ struct Crypto1State crypto1_state = {0, 0};
|
||||
|
||||
void printHf14aConfig(void) {
|
||||
DbpString(_CYAN_("HF 14a config"));
|
||||
Dbprintf(" [a] Anticol override.... %s%s%s",
|
||||
Dbprintf(" [a] Anticol override........... %s%s%s",
|
||||
(hf14aconfig.forceanticol == 0) ? _GREEN_("std") " ( follow standard )" : "",
|
||||
(hf14aconfig.forceanticol == 1) ? _RED_("force") " ( always do anticol )" : "",
|
||||
(hf14aconfig.forceanticol == 2) ? _RED_("skip") " ( always skip anticol )" : ""
|
||||
);
|
||||
Dbprintf(" [b] BCC override........ %s%s%s",
|
||||
Dbprintf(" [b] BCC override............... %s%s%s",
|
||||
(hf14aconfig.forcebcc == 0) ? _GREEN_("std") " ( follow standard )" : "",
|
||||
(hf14aconfig.forcebcc == 1) ? _RED_("fix") " ( fix bad BCC )" : "",
|
||||
(hf14aconfig.forcebcc == 2) ? _RED_("ignore") " ( ignore bad BCC, always use card BCC )" : ""
|
||||
);
|
||||
Dbprintf(" [2] CL2 override........ %s%s%s",
|
||||
Dbprintf(" [2] CL2 override............... %s%s%s",
|
||||
(hf14aconfig.forcecl2 == 0) ? _GREEN_("std") " ( follow standard )" : "",
|
||||
(hf14aconfig.forcecl2 == 1) ? _RED_("force") " ( always do CL2 )" : "",
|
||||
(hf14aconfig.forcecl2 == 2) ? _RED_("skip") " ( always skip CL2 )" : ""
|
||||
);
|
||||
Dbprintf(" [3] CL3 override........ %s%s%s",
|
||||
Dbprintf(" [3] CL3 override............... %s%s%s",
|
||||
(hf14aconfig.forcecl3 == 0) ? _GREEN_("std") " ( follow standard )" : "",
|
||||
(hf14aconfig.forcecl3 == 1) ? _RED_("force") " ( always do CL3 )" : "",
|
||||
(hf14aconfig.forcecl3 == 2) ? _RED_("skip") " ( always skip CL3 )" : ""
|
||||
);
|
||||
Dbprintf(" [r] RATS override....... %s%s%s",
|
||||
Dbprintf(" [r] RATS override.............. %s%s%s",
|
||||
(hf14aconfig.forcerats == 0) ? _GREEN_("std") " ( follow standard )" : "",
|
||||
(hf14aconfig.forcerats == 1) ? _RED_("force") " ( always do RATS )" : "",
|
||||
(hf14aconfig.forcerats == 2) ? _RED_("skip") " ( always skip RATS )" : ""
|
||||
);
|
||||
Dbprintf(" [m] Magsafe polling............ %s",
|
||||
(hf14aconfig.magsafe == 1) ? _GREEN_("enabled") : _YELLOW_("disabled")
|
||||
);
|
||||
Dbprintf(" [p] Polling loop annotation.... %s %*D",
|
||||
(hf14aconfig.polling_loop_annotation.frame_length <= 0) ? _YELLOW_("disabled") : _GREEN_("enabled"),
|
||||
hf14aconfig.polling_loop_annotation.frame_length,
|
||||
hf14aconfig.polling_loop_annotation.frame,
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,21 +234,64 @@ void printHf14aConfig(void) {
|
||||
* @brief setSamplingConfig
|
||||
* @param sc
|
||||
*/
|
||||
void setHf14aConfig(const hf14a_config *hc) {
|
||||
|
||||
if ((hc->forceanticol >= 0) && (hc->forceanticol <= 2))
|
||||
void setHf14aConfig(const hf14a_config_t *hc) {
|
||||
if ((hc->forceanticol >= 0) && (hc->forceanticol <= 2)) {
|
||||
hf14aconfig.forceanticol = hc->forceanticol;
|
||||
if ((hc->forcebcc >= 0) && (hc->forcebcc <= 2))
|
||||
}
|
||||
|
||||
if ((hc->forcebcc >= 0) && (hc->forcebcc <= 2)) {
|
||||
hf14aconfig.forcebcc = hc->forcebcc;
|
||||
if ((hc->forcecl2 >= 0) && (hc->forcecl2 <= 2))
|
||||
}
|
||||
|
||||
if ((hc->forcecl2 >= 0) && (hc->forcecl2 <= 2)) {
|
||||
hf14aconfig.forcecl2 = hc->forcecl2;
|
||||
if ((hc->forcecl3 >= 0) && (hc->forcecl3 <= 2))
|
||||
}
|
||||
|
||||
if ((hc->forcecl3 >= 0) && (hc->forcecl3 <= 2)) {
|
||||
hf14aconfig.forcecl3 = hc->forcecl3;
|
||||
if ((hc->forcerats >= 0) && (hc->forcerats <= 2))
|
||||
}
|
||||
|
||||
if ((hc->forcerats >= 0) && (hc->forcerats <= 2)) {
|
||||
hf14aconfig.forcerats = hc->forcerats;
|
||||
}
|
||||
|
||||
if ((hc->magsafe >= 0) && (hc->magsafe <= 1)) {
|
||||
hf14aconfig.magsafe = hc->magsafe;
|
||||
}
|
||||
|
||||
if (hc->polling_loop_annotation.frame_length >= 0) {
|
||||
memcpy(&hf14aconfig.polling_loop_annotation, &hc->polling_loop_annotation, sizeof(iso14a_polling_frame_t));
|
||||
}
|
||||
|
||||
// iceman: Somehow I think we should memcpy WUPA_CMD and all other hf14a_polling_parameters.frames[xxx] assignments
|
||||
// right now we are assigning...
|
||||
|
||||
// Derive polling loop configuration based on 14a config
|
||||
hf14a_polling_parameters.frames[0] = WUPA_CMD_FRAME;
|
||||
hf14a_polling_parameters.frame_count = 1;
|
||||
hf14a_polling_parameters.extra_timeout = 0;
|
||||
|
||||
if (hf14aconfig.magsafe == 1) {
|
||||
|
||||
for (int i = 0; i < ARRAYLEN(MAGWUPA_CMD_FRAMES); i++) {
|
||||
if (hf14a_polling_parameters.frame_count < ARRAYLEN(hf14a_polling_parameters.frames) - 1) {
|
||||
hf14a_polling_parameters.frames[hf14a_polling_parameters.frame_count] = MAGWUPA_CMD_FRAMES[i];
|
||||
hf14a_polling_parameters.frame_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hf14aconfig.polling_loop_annotation.frame_length > 0) {
|
||||
|
||||
if (hf14a_polling_parameters.frame_count < ARRAYLEN(hf14a_polling_parameters.frames) - 1) {
|
||||
hf14a_polling_parameters.frames[hf14a_polling_parameters.frame_count] = hf14aconfig.polling_loop_annotation;
|
||||
hf14a_polling_parameters.frame_count++;
|
||||
}
|
||||
hf14a_polling_parameters.extra_timeout = 250;
|
||||
}
|
||||
}
|
||||
|
||||
hf14a_config *getHf14aConfig(void) {
|
||||
hf14a_config_t *getHf14aConfig(void) {
|
||||
return &hf14aconfig;
|
||||
}
|
||||
|
||||
@@ -520,6 +596,9 @@ void Demod14aInit(uint8_t *d, uint16_t n, uint8_t *par) {
|
||||
RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time) {
|
||||
|
||||
if (Demod.len == Demod.output_len) {
|
||||
// Flush last parity bits
|
||||
Demod.parityBits <<= (8 - (Demod.len & 0x0007)); // left align remaining parity bits
|
||||
Demod.parity[Demod.parityLen++] = Demod.parityBits; // and store them
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -592,7 +671,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t
|
||||
|
||||
if (Demod.bitCount > 0) { // there are some remaining data bits
|
||||
Demod.shiftReg >>= (9 - Demod.bitCount); // right align the decoded bits
|
||||
Demod.output[Demod.len++] = Demod.shiftReg & 0xff; // and add them to the output
|
||||
Demod.output[Demod.len++] = (Demod.shiftReg & 0xff); // and add them to the output
|
||||
Demod.parityBits <<= 1; // add a (void) parity bit
|
||||
Demod.parityBits <<= (8 - (Demod.len & 0x0007)); // left align remaining parity bits
|
||||
Demod.parity[Demod.parityLen++] = Demod.parityBits; // and store them
|
||||
@@ -729,12 +808,12 @@ void RAMFUNC SniffIso14443a(uint8_t param) {
|
||||
set_tracing(true);
|
||||
|
||||
// The command (reader -> tag) that we're receiving.
|
||||
uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
|
||||
uint8_t *receivedCmdPar = BigBuf_malloc(MAX_PARITY_SIZE);
|
||||
uint8_t *receivedCmd = BigBuf_calloc(MAX_FRAME_SIZE);
|
||||
uint8_t *receivedCmdPar = BigBuf_calloc(MAX_PARITY_SIZE);
|
||||
|
||||
// The response (tag -> reader) that we're receiving.
|
||||
uint8_t *receivedResp = BigBuf_malloc(MAX_FRAME_SIZE);
|
||||
uint8_t *receivedRespPar = BigBuf_malloc(MAX_PARITY_SIZE);
|
||||
uint8_t *receivedResp = BigBuf_calloc(MAX_FRAME_SIZE);
|
||||
uint8_t *receivedRespPar = BigBuf_calloc(MAX_PARITY_SIZE);
|
||||
|
||||
uint8_t previous_data = 0;
|
||||
int maxDataLen = 0, dataLen;
|
||||
@@ -1108,7 +1187,7 @@ bool prepare_allocated_tag_modulation(tag_response_info_t *response_info, uint8_
|
||||
|
||||
bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data,
|
||||
uint8_t *ats, size_t ats_len, tag_response_info_t **responses,
|
||||
uint32_t *cuid, uint32_t counters[3], uint8_t tearings[3], uint8_t *pages) {
|
||||
uint32_t *cuid, uint8_t *pages) {
|
||||
uint8_t sak = 0;
|
||||
// The first response contains the ATQA (note: bytes are transmitted in reverse order).
|
||||
static uint8_t rATQA[2] = { 0x00 };
|
||||
@@ -1155,14 +1234,11 @@ bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data,
|
||||
mfu_dump_t *mfu_header = (mfu_dump_t *) BigBuf_get_EM_addr();
|
||||
*pages = MAX(mfu_header->pages, 15);
|
||||
|
||||
// counters and tearing flags
|
||||
// tearing flags
|
||||
// for old dumps with all zero headers, we need to set default values.
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
|
||||
counters[i] = le24toh(mfu_header->counter_tearing[i]);
|
||||
|
||||
if (mfu_header->counter_tearing[i][3] != 0x00) {
|
||||
tearings[i] = mfu_header->counter_tearing[i][3];
|
||||
if (mfu_header->counter_tearing[i][3] == 0x00) {
|
||||
mfu_header->counter_tearing[i][3] = 0xBD;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1210,14 +1286,11 @@ bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data,
|
||||
mfu_dump_t *mfu_header = (mfu_dump_t *) BigBuf_get_EM_addr();
|
||||
*pages = MAX(mfu_header->pages, 19);
|
||||
|
||||
// counters and tearing flags
|
||||
// tearing flags
|
||||
// for old dumps with all zero headers, we need to set default values.
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
|
||||
counters[i] = le24toh(mfu_header->counter_tearing[i]);
|
||||
|
||||
if (mfu_header->counter_tearing[i][3] != 0x00) {
|
||||
tearings[i] = mfu_header->counter_tearing[i][3];
|
||||
if (mfu_header->counter_tearing[i][3] == 0x00) {
|
||||
mfu_header->counter_tearing[i][3] = 0xBD;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1463,8 +1536,6 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
||||
tag_response_info_t *responses;
|
||||
uint32_t cuid = 0;
|
||||
uint32_t nonce = 0;
|
||||
uint32_t counters[3] = { 0x00, 0x00, 0x00 };
|
||||
uint8_t tearings[3] = { 0xbd, 0xbd, 0xbd };
|
||||
uint8_t pages = 0;
|
||||
|
||||
// Here, we collect CUID, block1, keytype1, NT1, NR1, AR1, CUID, block2, keytyp2, NT2, NR2, AR2
|
||||
@@ -1508,12 +1579,22 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
||||
.modulation_n = 0
|
||||
};
|
||||
|
||||
if (SimulateIso14443aInit(tagType, flags, useruid, ats, ats_len, &responses, &cuid, counters, tearings, &pages) == false) {
|
||||
if (SimulateIso14443aInit(tagType, flags, useruid, ats, ats_len, &responses, &cuid, &pages) == false) {
|
||||
BigBuf_free_keep_EM();
|
||||
reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EINIT, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
mfu_dump_t *mfu_em_dump = NULL;
|
||||
if (tagType == 2 || tagType == 7) {
|
||||
mfu_em_dump = (mfu_dump_t *)BigBuf_get_EM_addr();
|
||||
if (!mfu_em_dump) {
|
||||
if (g_dbglevel >= DBG_ERROR) Dbprintf("[-] ERROR: Failed to get EM address for MFU/NTAG operations.");
|
||||
reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EMALLOC, NULL, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We need to listen to the high-frequency, peak-detected path.
|
||||
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
|
||||
|
||||
@@ -1683,14 +1764,14 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
||||
} else {
|
||||
// first blocks of emu are header
|
||||
uint16_t start = (block * 4) + MFU_DUMP_PREFIX_LENGTH;
|
||||
uint8_t emdata[MAX_MIFARE_FRAME_SIZE] = {0};
|
||||
uint8_t emdata[MIFARE_BLOCK_SIZE + CRC16_SIZE] = {0};
|
||||
emlGet(emdata, start, MIFARE_BLOCK_SIZE);
|
||||
AddCrc14A(emdata, MIFARE_BLOCK_SIZE);
|
||||
EmSendCmd(emdata, sizeof(emdata));
|
||||
numReads++; // Increment number of times reader requested a block
|
||||
|
||||
if (exitAfterNReads > 0 && numReads == exitAfterNReads) {
|
||||
Dbprintf("[MFUEMUL_WORK] %d reads done, exiting", numReads);
|
||||
Dbprintf("[MFUEMUL_WORK] " _YELLOW_("%u") " reads done, exiting", numReads);
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
@@ -1702,7 +1783,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
||||
// block1 = 4byte UID.
|
||||
p_response = &responses[RESP_INDEX_UIDC1];
|
||||
} else { // all other tags (16 byte block tags)
|
||||
uint8_t emdata[MAX_MIFARE_FRAME_SIZE] = {0};
|
||||
uint8_t emdata[MIFARE_BLOCK_SIZE + CRC16_SIZE] = {0};
|
||||
emlGet(emdata, block, MIFARE_BLOCK_SIZE);
|
||||
AddCrc14A(emdata, MIFARE_BLOCK_SIZE);
|
||||
EmSendCmd(emdata, sizeof(emdata));
|
||||
@@ -1794,8 +1875,8 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
||||
// send NACK 0x0 == invalid argument
|
||||
EmSend4bit(CARD_NACK_IV);
|
||||
} else {
|
||||
uint8_t cmd[] = {0x00, 0x00, 0x00, 0x14, 0xa5};
|
||||
htole24(counters[index], cmd);
|
||||
uint8_t cmd[] = {0, 0, 0, 0x14, 0xa5};
|
||||
memcpy(cmd, mfu_em_dump->counter_tearing[index], 3);
|
||||
AddCrc14A(cmd, sizeof(cmd) - 2);
|
||||
EmSendCmd(cmd, sizeof(cmd));
|
||||
}
|
||||
@@ -1806,13 +1887,16 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
||||
// send NACK 0x0 == invalid argument
|
||||
EmSend4bit(CARD_NACK_IV);
|
||||
} else {
|
||||
uint32_t val = le24toh(receivedCmd + 2) + counters[index];
|
||||
uint32_t val = le24toh(mfu_em_dump->counter_tearing[index]); // get current counter value
|
||||
val += le24toh(receivedCmd + 2); // increment in
|
||||
|
||||
// if new value + old value is bigger 24bits, fail
|
||||
if (val > 0xFFFFFF) {
|
||||
// send NACK 0x4 == counter overflow
|
||||
EmSend4bit(CARD_NACK_NA);
|
||||
} else {
|
||||
counters[index] = val;
|
||||
htole24(val, mfu_em_dump->counter_tearing[index]);
|
||||
|
||||
// send ACK
|
||||
EmSend4bit(CARD_ACK);
|
||||
}
|
||||
@@ -1826,7 +1910,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
||||
EmSend4bit(CARD_NACK_IV);
|
||||
} else {
|
||||
uint8_t cmd[3] = {0, 0, 0};
|
||||
cmd[0] = tearings[index];
|
||||
cmd[0] = mfu_em_dump->counter_tearing[index][3];
|
||||
AddCrc14A(cmd, sizeof(cmd) - 2);
|
||||
EmSendCmd(cmd, sizeof(cmd));
|
||||
}
|
||||
@@ -2360,7 +2444,7 @@ int EmSendCmd14443aRaw(const uint8_t *resp, uint16_t respLen) {
|
||||
|
||||
int EmSend4bit(uint8_t resp) {
|
||||
Code4bitAnswerAsTag(resp);
|
||||
tosend_t *ts = get_tosend();
|
||||
const tosend_t *ts = get_tosend();
|
||||
int res = EmSendCmd14443aRaw(ts->buf, ts->max);
|
||||
// do the tracing for the previous reader request and this tag answer:
|
||||
uint8_t par[1] = {0x00};
|
||||
@@ -2382,7 +2466,7 @@ int EmSendCmdPar(uint8_t *resp, uint16_t respLen, uint8_t *par) {
|
||||
}
|
||||
int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision) {
|
||||
CodeIso14443aAsTagPar(resp, respLen, par, collision);
|
||||
tosend_t *ts = get_tosend();
|
||||
const tosend_t *ts = get_tosend();
|
||||
int res = EmSendCmd14443aRaw(ts->buf, ts->max);
|
||||
|
||||
// do the tracing for the previous reader request and this tag answer:
|
||||
@@ -2549,28 +2633,27 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint16_t rec_max
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing) {
|
||||
|
||||
void ReaderTransmitBitsPar(const uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing) {
|
||||
CodeIso14443aBitsAsReaderPar(frame, bits, par);
|
||||
// Send command to tag
|
||||
tosend_t *ts = get_tosend();
|
||||
const tosend_t *ts = get_tosend();
|
||||
TransmitFor14443a(ts->buf, ts->max, timing);
|
||||
if (g_trigger) LED_A_ON();
|
||||
|
||||
LogTrace(frame, nbytes(bits), (LastTimeProxToAirStart << 4) + DELAY_ARM2AIR_AS_READER, ((LastTimeProxToAirStart + LastProxToAirDuration) << 4) + DELAY_ARM2AIR_AS_READER, par, true);
|
||||
}
|
||||
|
||||
void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing) {
|
||||
void ReaderTransmitPar(const uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing) {
|
||||
ReaderTransmitBitsPar(frame, len * 8, par, timing);
|
||||
}
|
||||
|
||||
static void ReaderTransmitBits(uint8_t *frame, uint16_t len, uint32_t *timing) {
|
||||
static void ReaderTransmitBits(const uint8_t *frame, uint16_t len, uint32_t *timing) {
|
||||
// Generate parity and redirect
|
||||
GetParity(frame, len / 8, parity_array);
|
||||
ReaderTransmitBitsPar(frame, len, parity_array, timing);
|
||||
}
|
||||
|
||||
void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing) {
|
||||
void ReaderTransmit(const uint8_t *frame, uint16_t len, uint32_t *timing) {
|
||||
// Generate parity and redirect
|
||||
GetParity(frame, len, parity_array);
|
||||
ReaderTransmitBitsPar(frame, len * 8, parity_array, timing);
|
||||
@@ -2608,9 +2691,9 @@ void iso14443a_antifuzz(uint32_t flags) {
|
||||
int len = 0;
|
||||
|
||||
// allocate buffers:
|
||||
uint8_t *received = BigBuf_malloc(MAX_FRAME_SIZE);
|
||||
uint8_t *receivedPar = BigBuf_malloc(MAX_PARITY_SIZE);
|
||||
uint8_t *resp = BigBuf_malloc(20);
|
||||
uint8_t *received = BigBuf_calloc(MAX_FRAME_SIZE);
|
||||
uint8_t *receivedPar = BigBuf_calloc(MAX_PARITY_SIZE);
|
||||
uint8_t *resp = BigBuf_calloc(20);
|
||||
|
||||
memset(received, 0x00, MAX_FRAME_SIZE);
|
||||
memset(received, 0x00, MAX_PARITY_SIZE);
|
||||
@@ -2697,30 +2780,40 @@ static void iso14a_set_ATS_times(const uint8_t *ats) {
|
||||
}
|
||||
|
||||
|
||||
static int GetATQA(uint8_t *resp, uint16_t resp_len, uint8_t *resp_par, iso14a_polling_parameters_t *polling_parameters) {
|
||||
#define WUPA_RETRY_TIMEOUT 10
|
||||
static int GetATQA(uint8_t *resp, uint16_t resp_len, uint8_t *resp_par, const iso14a_polling_parameters_t *polling_parameters) {
|
||||
#define RETRY_TIMEOUT 10
|
||||
|
||||
uint32_t save_iso14a_timeout = iso14a_get_timeout();
|
||||
iso14a_set_timeout(1236 / 128 + 1); // response to WUPA is expected at exactly 1236/fc. No need to wait longer.
|
||||
|
||||
// refactored to use local pointer, now no modification of polling_parameters pointer is done
|
||||
// I don't think the intention was to modify polling_parameters when sending in WUPA_POLLING_PARAMETERS etc.
|
||||
// Modify polling_params, if null use default values.
|
||||
iso14a_polling_parameters_t p;
|
||||
memcpy(&p, (uint8_t *)polling_parameters, sizeof(iso14a_polling_parameters_t));
|
||||
|
||||
if (polling_parameters == NULL) {
|
||||
memcpy(&p, (uint8_t *)&hf14a_polling_parameters, sizeof(iso14a_polling_parameters_t));
|
||||
}
|
||||
|
||||
bool first_try = true;
|
||||
uint32_t retry_timeout = WUPA_RETRY_TIMEOUT * polling_parameters->frame_count + polling_parameters->extra_timeout;
|
||||
uint32_t start_time = 0;
|
||||
int len;
|
||||
uint32_t retry_timeout = ((RETRY_TIMEOUT * p.frame_count) + p.extra_timeout);
|
||||
uint32_t start_time = 0;
|
||||
uint8_t curr = 0;
|
||||
|
||||
uint8_t current_frame = 0;
|
||||
|
||||
// Use the temporary polling parameters
|
||||
do {
|
||||
iso14a_polling_frame_t *frame_parameters = &polling_parameters->frames[current_frame];
|
||||
const iso14a_polling_frame_t *frp = &p.frames[curr];
|
||||
|
||||
if (frame_parameters->last_byte_bits == 8) {
|
||||
ReaderTransmit(frame_parameters->frame, frame_parameters->frame_length, NULL);
|
||||
if (frp->last_byte_bits == 8) {
|
||||
ReaderTransmit(frp->frame, frp->frame_length, NULL);
|
||||
} else {
|
||||
ReaderTransmitBitsPar(frame_parameters->frame, frame_parameters->last_byte_bits, NULL, NULL);
|
||||
ReaderTransmitBitsPar(frp->frame, frp->last_byte_bits, NULL, NULL);
|
||||
}
|
||||
|
||||
if (frame_parameters->extra_delay) {
|
||||
SpinDelay(frame_parameters->extra_delay);
|
||||
if (frp->extra_delay) {
|
||||
SpinDelay(frp->extra_delay);
|
||||
}
|
||||
|
||||
// Receive the ATQA
|
||||
@@ -2729,12 +2822,12 @@ static int GetATQA(uint8_t *resp, uint16_t resp_len, uint8_t *resp_par, iso14a_p
|
||||
// We set the start_time here otherwise in some cases we miss the window and only ever try once
|
||||
if (first_try) {
|
||||
start_time = GetTickCount();
|
||||
first_try = false;
|
||||
}
|
||||
|
||||
first_try = false;
|
||||
|
||||
// Go over frame configurations, loop back when we reach the end
|
||||
current_frame = current_frame < (polling_parameters->frame_count - 1) ? current_frame + 1 : 0;
|
||||
curr = (curr < (p.frame_count - 1)) ? curr + 1 : 0;
|
||||
|
||||
} while (len == 0 && GetTickCountDelta(start_time) <= retry_timeout);
|
||||
|
||||
iso14a_set_timeout(save_iso14a_timeout);
|
||||
@@ -2743,7 +2836,7 @@ static int GetATQA(uint8_t *resp, uint16_t resp_len, uint8_t *resp_par, iso14a_p
|
||||
|
||||
|
||||
int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats) {
|
||||
return iso14443a_select_cardEx(uid_ptr, p_card, cuid_ptr, anticollision, num_cascades, no_rats, &WUPA_POLLING_PARAMETERS);
|
||||
return iso14443a_select_cardEx(uid_ptr, p_card, cuid_ptr, anticollision, num_cascades, no_rats, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -3016,7 +3109,7 @@ int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades) {
|
||||
uint8_t sak = 0x04; // cascade uid
|
||||
int cascade_level = 1;
|
||||
|
||||
if (GetATQA(resp, sizeof(resp), resp_par, &WUPA_POLLING_PARAMETERS) == 0) {
|
||||
if (GetATQA(resp, sizeof(resp), resp_par, NULL) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3249,7 +3342,7 @@ void ReaderIso14443a(PacketCommandNG *c) {
|
||||
true,
|
||||
0,
|
||||
((param & ISO14A_NO_RATS) == ISO14A_NO_RATS),
|
||||
((param & ISO14A_USE_CUSTOM_POLLING) == ISO14A_USE_CUSTOM_POLLING) ? (iso14a_polling_parameters_t *)cmd : &WUPA_POLLING_PARAMETERS
|
||||
((param & ISO14A_USE_CUSTOM_POLLING) == ISO14A_USE_CUSTOM_POLLING) ? (iso14a_polling_parameters_t *)cmd : NULL
|
||||
);
|
||||
// TODO: Improve by adding a cmd parser pointer and moving it by struct length to allow combining data with polling params
|
||||
FpgaDisableTracing();
|
||||
@@ -3985,9 +4078,7 @@ void DetectNACKbug(void) {
|
||||
// i = number of authentications sent. Not always 256, since we are trying to sync but close to it.
|
||||
FpgaDisableTracing();
|
||||
|
||||
uint8_t *data = BigBuf_malloc(4);
|
||||
data[0] = isOK;
|
||||
data[1] = num_nacks;
|
||||
uint8_t data[4] = {isOK, num_nacks, 0, 0};
|
||||
num_to_bytes(i, 2, data + 2);
|
||||
reply_ng(CMD_HF_MIFARE_NACK_DETECT, status, data, 4);
|
||||
|
||||
@@ -4008,8 +4099,6 @@ void SimulateIso14443aTagAID(uint8_t tagType, uint16_t flags, uint8_t *uid,
|
||||
uint8_t *getdata_response, size_t getdata_response_len) {
|
||||
tag_response_info_t *responses;
|
||||
uint32_t cuid = 0;
|
||||
uint32_t counters[3] = { 0x00, 0x00, 0x00 };
|
||||
uint8_t tearings[3] = { 0xbd, 0xbd, 0xbd };
|
||||
uint8_t pages = 0;
|
||||
|
||||
// command buffers
|
||||
@@ -4050,7 +4139,7 @@ void SimulateIso14443aTagAID(uint8_t tagType, uint16_t flags, uint8_t *uid,
|
||||
.modulation_n = 0
|
||||
};
|
||||
|
||||
if (SimulateIso14443aInit(tagType, flags, uid, ats, ats_len, &responses, &cuid, counters, tearings, &pages) == false) {
|
||||
if (SimulateIso14443aInit(tagType, flags, uid, ats, ats_len, &responses, &cuid, &pages) == false) {
|
||||
BigBuf_free_keep_EM();
|
||||
reply_ng(CMD_HF_MIFARE_SIMULATE, PM3_EINIT, NULL, 0);
|
||||
return;
|
||||
@@ -4125,8 +4214,9 @@ void SimulateIso14443aTagAID(uint8_t tagType, uint16_t flags, uint8_t *uid,
|
||||
uint8_t offset = 0;
|
||||
switch (receivedCmd[0]) {
|
||||
case 0x0B: // IBlock with CID
|
||||
case 0x0A:
|
||||
case 0x0A: {
|
||||
offset = 1;
|
||||
}
|
||||
case 0x02: // IBlock without CID
|
||||
case 0x03: {
|
||||
dynamic_response_info.response[0] = receivedCmd[0];
|
||||
|
||||
+6
-6
@@ -125,8 +125,8 @@ typedef enum {
|
||||
#endif
|
||||
|
||||
void printHf14aConfig(void);
|
||||
void setHf14aConfig(const hf14a_config *hc);
|
||||
hf14a_config *getHf14aConfig(void);
|
||||
void setHf14aConfig(const hf14a_config_t *hc);
|
||||
hf14a_config_t *getHf14aConfig(void);
|
||||
void iso14a_set_timeout(uint32_t timeout);
|
||||
uint32_t iso14a_get_timeout(void);
|
||||
|
||||
@@ -152,14 +152,14 @@ void SimulateIso14443aTagAID(uint8_t tagType, uint16_t flags, uint8_t *uid,
|
||||
|
||||
bool SimulateIso14443aInit(uint8_t tagType, uint16_t flags, uint8_t *data,
|
||||
uint8_t *ats, size_t ats_len, tag_response_info_t **responses,
|
||||
uint32_t *cuid, uint32_t counters[3], uint8_t tearings[3], uint8_t *pages);
|
||||
uint32_t *cuid, uint8_t *pages);
|
||||
|
||||
bool GetIso14443aCommandFromReader(uint8_t *received, uint16_t received_maxlen, uint8_t *par, int *len);
|
||||
void iso14443a_antifuzz(uint32_t flags);
|
||||
void ReaderIso14443a(PacketCommandNG *c);
|
||||
void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing);
|
||||
void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing);
|
||||
void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing);
|
||||
void ReaderTransmit(const uint8_t *frame, uint16_t len, uint32_t *timing);
|
||||
void ReaderTransmitBitsPar(const uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing);
|
||||
void ReaderTransmitPar(const uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing);
|
||||
uint16_t ReaderReceive(uint8_t *receivedAnswer, uint16_t answer_maxlen, uint8_t *par);
|
||||
|
||||
void iso14443a_setup(uint8_t fpga_minor_mode);
|
||||
|
||||
+6
-3
@@ -1585,7 +1585,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) {
|
||||
void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len, uint32_t *start_time, uint32_t *eof_time, bool framing) {
|
||||
const tosend_t *ts = get_tosend();
|
||||
CodeIso14443bAsReader(cmd, len, framing);
|
||||
TransmitFor14443b_AsReader(start_time);
|
||||
@@ -1800,7 +1800,7 @@ static int iso14443b_select_cts_card(iso14b_cts_card_select_t *card) {
|
||||
/**
|
||||
* SRx Initialise.
|
||||
*/
|
||||
static int iso14443b_select_srx_card(iso14b_card_select_t *card) {
|
||||
int iso14443b_select_srx_card(iso14b_card_select_t *card) {
|
||||
// INITIATE command: wake up the tag using the INITIATE
|
||||
static const uint8_t init_srx[] = { ISO14443B_INITIATE, 0x00, 0x97, 0x5b };
|
||||
uint8_t r_init[3] = { 0x00 };
|
||||
@@ -2135,6 +2135,9 @@ static int iso14443b_select_picopass_card(picopass_hdr_t *hdr) {
|
||||
static uint8_t act_all[] = { ICLASS_CMD_ACTALL };
|
||||
static uint8_t identify[] = { ICLASS_CMD_READ_OR_IDENTIFY };
|
||||
static uint8_t read_conf[] = { ICLASS_CMD_READ_OR_IDENTIFY, 0x01, 0xfa, 0x22 };
|
||||
|
||||
// ICLASS_CMD_SELECT 0x81 tells ISO14443b/BPSK coding/106 kbits/s
|
||||
// ICLASS_CMD_SELECT 0x41 tells ISO14443b/BPSK coding/423 kbits/s
|
||||
uint8_t select[] = { 0x80 | ICLASS_CMD_SELECT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
uint8_t read_aia[] = { ICLASS_CMD_READ_OR_IDENTIFY, 0x05, 0xde, 0x64};
|
||||
uint8_t read_check_cc[] = { 0x80 | ICLASS_CMD_READCHECK, 0x02 };
|
||||
@@ -2307,7 +2310,7 @@ void iso14443b_setup(void) {
|
||||
//
|
||||
// I tried to be systematic and check every answer of the tag, every CRC, etc...
|
||||
//-----------------------------------------------------------------------------
|
||||
static int read_14b_srx_block(uint8_t blocknr, uint8_t *block) {
|
||||
int read_14b_srx_block(uint8_t blocknr, uint8_t *block) {
|
||||
|
||||
uint8_t cmd[] = {ISO14443B_READ_BLK, blocknr, 0x00, 0x00};
|
||||
AddCrc14B(cmd, 2);
|
||||
|
||||
@@ -45,8 +45,11 @@ int iso14443b_select_card(iso14b_card_select_t *card);
|
||||
|
||||
void SimulateIso14443bTag(const uint8_t *pupi);
|
||||
void read_14b_st_block(uint8_t blocknr);
|
||||
int read_14b_srx_block(uint8_t blocknr, uint8_t *block);
|
||||
int iso14443b_select_srx_card(iso14b_card_select_t *card);
|
||||
void SniffIso14443b(void);
|
||||
void SendRawCommand14443B(iso14b_raw_cmd_t *p);
|
||||
void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len, uint32_t *start_time, uint32_t *eof_time, bool framing);
|
||||
|
||||
// States for 14B SIM command
|
||||
#define SIM_POWER_OFF 0
|
||||
|
||||
+1
-1
@@ -2657,7 +2657,7 @@ void BruteforceIso15693Afi(uint32_t flags) {
|
||||
Dbprintf("AFI = %i UID = %s", i, iso15693_sprintUID(NULL, recv + 2));
|
||||
}
|
||||
|
||||
aborted = (BUTTON_PRESS() && data_available());
|
||||
aborted = (BUTTON_PRESS() || data_available());
|
||||
if (aborted) {
|
||||
break;
|
||||
}
|
||||
|
||||
+7
-2
@@ -236,8 +236,13 @@ void lf_init(bool reader, bool simulate, bool ledcontrol) {
|
||||
FpgaSetupSsc(FPGA_MAJOR_MODE_LF_READER);
|
||||
|
||||
// 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.
|
||||
SpinDelay(10);
|
||||
// Optimal timing window for LF ADC measurements to be performed:
|
||||
// minimum: 313T0 = 313 * 8us = 2504us = 2.50ms - Hitag2 tag internal powerup time
|
||||
// 280T0 = 280 * 8us = 2240us = 2.24ms - HitagS minimum time before the first command (powerup time)
|
||||
// maximum: 545T0 = 545 * 8us = 4360us = 4.36ms - Hitag2 command waiting time before it starts transmitting in public mode (if configured so)
|
||||
// 565T0 = 565 * 8us = 4520us = 4.52ms - HitagS waiting time before entering TTF mode (if configured so)
|
||||
// Thus (2.50 ms + 4.36 ms) / 2 ~= 3 ms (rounded down to integer), should be a good timing for both tag models
|
||||
SpinDelay(3);
|
||||
|
||||
// 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;
|
||||
|
||||
+5
-4
@@ -1955,6 +1955,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||
}
|
||||
// Replace client provided keys
|
||||
datain = dictkeys;
|
||||
keyCount = key_mem_available;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2908,7 +2909,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
|
||||
}
|
||||
|
||||
// read block
|
||||
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, sizeof(receivedAnswer), receivedAnswerPar, NULL) != MAX_MIFARE_FRAME_SIZE)) {
|
||||
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, sizeof(receivedAnswer), receivedAnswerPar, NULL) != MIFARE_BLOCK_SIZE + CRC16_SIZE)) {
|
||||
if (g_dbglevel >= DBG_ERROR) Dbprintf("read block send command error");
|
||||
errormsg = 0;
|
||||
break;
|
||||
@@ -3514,7 +3515,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
|
||||
|
||||
int retval = PM3_SUCCESS;
|
||||
uint8_t block_cmd[5] = { 0x90, 0xf0, 0xcc, 0xcc, 0x10 };
|
||||
uint8_t cmdlen = sizeof(block_cmd) + MAX_MIFARE_FRAME_SIZE;
|
||||
uint8_t cmdlen = sizeof(block_cmd) + MIFARE_BLOCK_SIZE + CRC16_SIZE;
|
||||
uint8_t *cmd = BigBuf_calloc(cmdlen);
|
||||
|
||||
iso14a_card_select_t *card_info = (iso14a_card_select_t *) BigBuf_calloc(sizeof(iso14a_card_select_t));
|
||||
@@ -3531,7 +3532,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
|
||||
|
||||
bool doReselect = false;
|
||||
if (block_len < MIFARE_BLOCK_SIZE) {
|
||||
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, 0, &cmd[sizeof(block_cmd)], MAX_MIFARE_FRAME_SIZE, NULL, NULL) != MAX_MIFARE_FRAME_SIZE)) {
|
||||
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, 0, &cmd[sizeof(block_cmd)], MIFARE_BLOCK_SIZE + CRC16_SIZE, NULL, NULL) != MIFARE_BLOCK_SIZE + CRC16_SIZE)) {
|
||||
if (g_dbglevel >= DBG_ERROR) Dbprintf("Read manufacturer block failed");
|
||||
retval = PM3_ESOFT;
|
||||
goto OUT;
|
||||
@@ -3566,7 +3567,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
|
||||
}
|
||||
}
|
||||
|
||||
retval = DoGen3Cmd(cmd, sizeof(block_cmd) + MAX_MIFARE_FRAME_SIZE);
|
||||
retval = DoGen3Cmd(cmd, sizeof(block_cmd) + MIFARE_BLOCK_SIZE + CRC16_SIZE);
|
||||
}
|
||||
|
||||
OUT:
|
||||
|
||||
+4
-4
@@ -1039,8 +1039,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t
|
||||
}
|
||||
}
|
||||
AddCrc14A(response, MIFARE_BLOCK_SIZE);
|
||||
mf_crypto1_encrypt(pcs, response, MAX_MIFARE_FRAME_SIZE, response_par);
|
||||
EmSendCmdPar(response, MAX_MIFARE_FRAME_SIZE, response_par);
|
||||
mf_crypto1_encrypt(pcs, response, MIFARE_BLOCK_SIZE + CRC16_SIZE, response_par);
|
||||
EmSendCmdPar(response, MIFARE_BLOCK_SIZE + CRC16_SIZE, response_par);
|
||||
FpgaDisableTracing();
|
||||
|
||||
if (g_dbglevel >= DBG_EXTENDED) {
|
||||
@@ -1052,7 +1052,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t
|
||||
numReads++;
|
||||
|
||||
if (exitAfterNReads > 0 && numReads == exitAfterNReads) {
|
||||
Dbprintf("[MFEMUL_WORK] %d reads done, exiting", numReads);
|
||||
Dbprintf("[MFEMUL_WORK] " _YELLOW_("%u") " reads done, exiting", numReads);
|
||||
finished = true;
|
||||
}
|
||||
break;
|
||||
@@ -1309,7 +1309,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t
|
||||
// WRITE BL2
|
||||
case MFEMUL_WRITEBL2: {
|
||||
|
||||
if (receivedCmd_len == MAX_MIFARE_FRAME_SIZE) {
|
||||
if (receivedCmd_len == MIFARE_BLOCK_SIZE + CRC16_SIZE) {
|
||||
|
||||
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec);
|
||||
|
||||
|
||||
+2
-6
@@ -100,7 +100,7 @@ uint16_t mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t
|
||||
uint16_t pos;
|
||||
uint8_t dcmd[4] = {cmd, data, 0x00, 0x00};
|
||||
uint8_t ecmd[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t par[1] = {0x00}; // 1 Byte parity is enough here
|
||||
uint8_t par[MAX_MIFARE_PARITY_SIZE] = {0x00}; // used for cmd and answer
|
||||
AddCrc14A(dcmd, 2);
|
||||
memcpy(ecmd, dcmd, sizeof(dcmd));
|
||||
|
||||
@@ -440,21 +440,17 @@ int mifare_ultra_aes_auth(uint8_t keyno, uint8_t *keybytes) {
|
||||
uint8_t key[16] = { 0 };
|
||||
memcpy(key, keybytes, sizeof(key));
|
||||
|
||||
uint16_t len = 0;
|
||||
|
||||
// 1 cmd + 16 bytes + 2 crc
|
||||
uint8_t resp[19] = {0x00};
|
||||
uint8_t respPar[5] = {0};
|
||||
|
||||
|
||||
// setup AES
|
||||
mbedtls_aes_context actx;
|
||||
mbedtls_aes_init(&actx);
|
||||
mbedtls_aes_init(&actx);
|
||||
mbedtls_aes_setkey_dec(&actx, key, 128);
|
||||
|
||||
// Send REQUEST AUTHENTICATION / receive tag nonce
|
||||
len = mifare_sendcmd_short(NULL, CRYPT_NONE, MIFARE_ULAES_AUTH_1, keyno, resp, sizeof(resp), respPar, NULL);
|
||||
uint16_t len = mifare_sendcmd_short(NULL, CRYPT_NONE, MIFARE_ULAES_AUTH_1, keyno, resp, sizeof(resp), respPar, NULL);
|
||||
if (len != 19) {
|
||||
if (g_dbglevel >= DBG_ERROR) Dbprintf("Cmd Error: %02x - expected 19 got " _RED_("%u"), resp[0], len);
|
||||
return 0;
|
||||
|
||||
+85
-15
@@ -218,13 +218,14 @@ out:
|
||||
*
|
||||
* @return Status code indicating success or failure of the operation.
|
||||
*/
|
||||
int sam_get_version(void) {
|
||||
int sam_get_version(bool info) {
|
||||
int res = PM3_SUCCESS;
|
||||
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("start sam_get_version");
|
||||
}
|
||||
|
||||
uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *response = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
uint16_t response_len = ISO7816_MAX_FRAME;
|
||||
|
||||
uint8_t payload[] = {
|
||||
@@ -252,8 +253,9 @@ int sam_get_version(void) {
|
||||
// 82 01
|
||||
// 01
|
||||
// 90 00
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("end sam_get_version");
|
||||
}
|
||||
|
||||
if (response[5] != 0xbd) {
|
||||
Dbprintf("Invalid SAM response");
|
||||
@@ -266,18 +268,18 @@ int sam_get_version(void) {
|
||||
}
|
||||
uint8_t *sam_version_an = sam_find_asn1_node(sam_response_an, 0x80);
|
||||
if (sam_version_an == NULL) {
|
||||
if (g_dbglevel >= DBG_ERROR) DbpString("SAM get version failed");
|
||||
if (g_dbglevel >= DBG_ERROR) DbpString(_RED_("SAM: get version failed"));
|
||||
goto error;
|
||||
}
|
||||
uint8_t *sam_build_an = sam_find_asn1_node(sam_response_an, 0x81);
|
||||
if (sam_build_an == NULL) {
|
||||
if (g_dbglevel >= DBG_ERROR) DbpString("SAM get firmware ID failed");
|
||||
if (g_dbglevel >= DBG_ERROR) DbpString(_RED_("SAM: get firmware ID failed"));
|
||||
goto error;
|
||||
}
|
||||
if (g_dbglevel >= DBG_INFO) {
|
||||
DbpString("SAM get version successful");
|
||||
Dbprintf("Firmware version: %X.%X", sam_version_an[2], sam_version_an[3]);
|
||||
Dbprintf("Firmware ID: ");
|
||||
if (g_dbglevel >= DBG_INFO || info) {
|
||||
DbpString(_BLUE_("-- SAM Information --"));
|
||||
Dbprintf(_YELLOW_("Firmware version: ")"%X.%X", sam_version_an[2], sam_version_an[3]);
|
||||
Dbprintf(_YELLOW_("Firmware ID: "));
|
||||
Dbhexdump(sam_build_an[1], sam_build_an + 2, false);
|
||||
}
|
||||
goto out;
|
||||
@@ -289,8 +291,78 @@ error:
|
||||
out:
|
||||
BigBuf_free();
|
||||
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("end sam_get_version");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int sam_get_serial_number(void) {
|
||||
int res = PM3_SUCCESS;
|
||||
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("start sam_get_serial_number");
|
||||
}
|
||||
|
||||
uint8_t *response = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
uint16_t response_len = ISO7816_MAX_FRAME;
|
||||
|
||||
uint8_t payload[] = {
|
||||
0xa0, 0x02, // <- SAM command
|
||||
0x96, 0x00 // <- get serial number
|
||||
};
|
||||
uint16_t payload_len = sizeof(payload);
|
||||
|
||||
sam_send_payload(
|
||||
0x44, 0x0a, 0x44,
|
||||
payload,
|
||||
&payload_len,
|
||||
response,
|
||||
&response_len
|
||||
);
|
||||
|
||||
//resp:
|
||||
//c1 64 00 00 00
|
||||
// bd 0e <- SAM response
|
||||
// 8a 0c <- get serial number response
|
||||
// 61 01 13 51 22 66 6e 15 3e 1b ff ff
|
||||
//90 00
|
||||
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("end sam_get_serial_number");
|
||||
}
|
||||
|
||||
if (response[5] != 0xbd) {
|
||||
Dbprintf("Invalid SAM response");
|
||||
goto error;
|
||||
} else {
|
||||
uint8_t *sam_response_an = sam_find_asn1_node(response + 5, 0x8a);
|
||||
if (sam_response_an == NULL) {
|
||||
if (g_dbglevel >= DBG_ERROR) DbpString(_RED_("SAM: get response failed"));
|
||||
goto error;
|
||||
}
|
||||
uint8_t *sam_serial_an = sam_response_an + 2;
|
||||
if (sam_serial_an == NULL) {
|
||||
if (g_dbglevel >= DBG_ERROR) DbpString(_RED_("SAM get serial number failed"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
Dbprintf(_YELLOW_("Serial Number: "));
|
||||
Dbhexdump(sam_response_an[1], sam_serial_an, false);
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
error:
|
||||
res = PM3_ESOFT;
|
||||
|
||||
out:
|
||||
BigBuf_free();
|
||||
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("end sam_get_serial_number");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -350,12 +422,10 @@ void sam_append_asn1_node(const uint8_t *root, const uint8_t *node, uint8_t type
|
||||
}
|
||||
|
||||
void sam_send_ack(void) {
|
||||
uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *response = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
uint16_t response_len = ISO7816_MAX_FRAME;
|
||||
|
||||
uint8_t payload[] = {
|
||||
0xa0, 0
|
||||
};
|
||||
uint8_t payload[] = { 0xa0, 0 };
|
||||
uint16_t payload_len = sizeof(payload);
|
||||
|
||||
sam_send_payload(
|
||||
|
||||
+2
-1
@@ -39,7 +39,8 @@ int sam_send_payload(
|
||||
uint16_t *response_len
|
||||
);
|
||||
|
||||
int sam_get_version(void);
|
||||
int sam_get_version(bool info);
|
||||
int sam_get_serial_number(void);
|
||||
|
||||
uint8_t *sam_find_asn1_node(const uint8_t *root, const uint8_t type);
|
||||
void sam_append_asn1_node(const uint8_t *root, const uint8_t *node, uint8_t type, const uint8_t *const data, uint8_t len);
|
||||
|
||||
+18
-10
@@ -46,11 +46,12 @@
|
||||
*/
|
||||
static int sam_send_request_iso15(const uint8_t *const request, const uint8_t request_len, uint8_t *response, uint8_t *response_len, const bool shallow_mod, const bool break_on_nr_mac, const bool prevent_epurse_update) {
|
||||
int res = PM3_SUCCESS;
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("start sam_send_request_iso14a");
|
||||
}
|
||||
|
||||
uint8_t *buf1 = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *buf2 = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *buf1 = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *buf2 = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
if (buf1 == NULL || buf2 == NULL) {
|
||||
res = PM3_EMALLOC;
|
||||
goto out;
|
||||
@@ -255,10 +256,10 @@ out:
|
||||
*/
|
||||
static int sam_set_card_detected_picopass(const picopass_hdr_t *card_select) {
|
||||
int res = PM3_SUCCESS;
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("start sam_set_card_detected");
|
||||
|
||||
uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
}
|
||||
uint8_t *response = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
uint16_t response_len = ISO7816_MAX_FRAME;
|
||||
|
||||
// a0 12
|
||||
@@ -314,8 +315,9 @@ error:
|
||||
out:
|
||||
BigBuf_free();
|
||||
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("end sam_set_card_detected");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -336,11 +338,14 @@ int sam_picopass_get_pacs(PacketCommandNG *c) {
|
||||
const bool breakOnNrMac = !!(flags & BITMASK(2));
|
||||
const bool preventEpurseUpdate = !!(flags & BITMASK(3));
|
||||
const bool shallow_mod = !!(flags & BITMASK(4));
|
||||
const bool info = !!(flags & BITMASK(5));
|
||||
|
||||
uint8_t *cmd = c->data.asBytes + 1;
|
||||
uint16_t cmd_len = c->length - 1;
|
||||
|
||||
int res = PM3_EFAILED;
|
||||
uint8_t sam_response[ISO7816_MAX_FRAME] = { 0x00 };
|
||||
uint8_t sam_response_len = 0;
|
||||
|
||||
clear_trace();
|
||||
I2C_Reset_EnterMainProgram();
|
||||
@@ -349,7 +354,12 @@ int sam_picopass_get_pacs(PacketCommandNG *c) {
|
||||
StartTicks();
|
||||
|
||||
// step 1: ping SAM
|
||||
sam_get_version();
|
||||
sam_get_version(info);
|
||||
|
||||
if (info) {
|
||||
sam_get_serial_number();
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!skipDetect) {
|
||||
// step 2: get card information
|
||||
@@ -369,8 +379,6 @@ int sam_picopass_get_pacs(PacketCommandNG *c) {
|
||||
}
|
||||
|
||||
// step 3: SamCommand RequestPACS, relay NFC communication
|
||||
uint8_t sam_response[ISO7816_MAX_FRAME] = { 0x00 };
|
||||
uint8_t sam_response_len = 0;
|
||||
res = sam_send_request_iso15(cmd, cmd_len, sam_response, &sam_response_len, shallow_mod, breakOnNrMac, preventEpurseUpdate);
|
||||
if (res != PM3_SUCCESS) {
|
||||
goto err;
|
||||
|
||||
+7
-5
@@ -51,13 +51,14 @@
|
||||
*/
|
||||
static int sam_set_card_detected_seos(iso14a_card_select_t *card_select) {
|
||||
int res = PM3_SUCCESS;
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("start sam_set_card_detected");
|
||||
}
|
||||
|
||||
uint8_t *request = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *request = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
uint16_t request_len = ISO7816_MAX_FRAME;
|
||||
|
||||
uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *response = BigBuf_calloc(ISO7816_MAX_FRAME);
|
||||
uint16_t response_len = ISO7816_MAX_FRAME;
|
||||
|
||||
const uint8_t payload[] = {
|
||||
@@ -107,8 +108,9 @@ error:
|
||||
out:
|
||||
BigBuf_free();
|
||||
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("end sam_set_card_detected");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -280,7 +282,7 @@ int sam_seos_get_pacs(PacketCommandNG *c) {
|
||||
StartTicks();
|
||||
|
||||
// step 1: ping SAM
|
||||
sam_get_version();
|
||||
sam_get_version(false);
|
||||
|
||||
if (skipDetect == false) {
|
||||
// step 2: get card information
|
||||
|
||||
+1
-1
@@ -312,7 +312,7 @@ static int is_valid_filename(const char *filename) {
|
||||
*/
|
||||
static void copy_in_spiffs(const char *src, const char *dst) {
|
||||
uint32_t size = size_in_spiffs(src);
|
||||
uint8_t *mem = BigBuf_malloc(size);
|
||||
uint8_t *mem = BigBuf_calloc(size);
|
||||
read_from_spiffs(src, (uint8_t *)mem, size);
|
||||
write_to_spiffs(dst, (uint8_t *)mem, size);
|
||||
}
|
||||
|
||||
+1
-1
@@ -218,7 +218,7 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) {
|
||||
}
|
||||
|
||||
// transfer from device to client
|
||||
int usart_writebuffer_sync(uint8_t *data, size_t len) {
|
||||
int usart_writebuffer_sync(const uint8_t *data, size_t len) {
|
||||
|
||||
// Wait for current PDC bank to be free
|
||||
// (and check next bank too, in case there will be a usart_writebuffer_async)
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ extern uint32_t g_usart_baudrate;
|
||||
extern uint8_t g_usart_parity;
|
||||
|
||||
void usart_init(uint32_t baudrate, uint8_t parity);
|
||||
int usart_writebuffer_sync(uint8_t *data, size_t len);
|
||||
int usart_writebuffer_sync(const uint8_t *data, size_t len);
|
||||
uint32_t usart_read_ng(uint8_t *data, size_t len);
|
||||
uint16_t usart_rxdata_available(void);
|
||||
|
||||
|
||||
+10
-2
@@ -889,11 +889,19 @@ endif
|
||||
ifneq (,$(INSTALLSHARE))
|
||||
$(Q)$(INSTALLSUDO) $(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
|
||||
# hack ahead: inject installation path into pm3_resources.py
|
||||
$(Q)sed -i 's|^TOOLS_PATH \?= \?None|TOOLS_PATH="$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)"|' pyscripts/pm3_resources.py
|
||||
$(Q)sed -i 's|^DICTS_PATH \?= \?None|DICTS_PATH="$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)/dictionaries"|' pyscripts/pm3_resources.py
|
||||
ifeq ($(platform),Darwin)
|
||||
$(Q)sed -E -i '' 's|^TOOLS_PATH \?= \?None|TOOLS_PATH="$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)"|' pyscripts/pm3_resources.py
|
||||
$(Q)sed -E -i '' 's|^DICTS_PATH \?= \?None|DICTS_PATH="$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)/dictionaries"|' pyscripts/pm3_resources.py
|
||||
$(Q)$(INSTALLSUDO) $(CP) $(INSTALLSHARE) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
|
||||
$(Q)sed -E -i '' 's|^TOOLS_PATH \?=.*|TOOLS_PATH = None|' pyscripts/pm3_resources.py
|
||||
$(Q)sed -E -i '' 's|^DICTS_PATH \?=.*|DICTS_PATH = None|' pyscripts/pm3_resources.py
|
||||
else
|
||||
$(Q)sed -i 's|^TOOLS_PATH \?= \?None|TOOLS_PATH="$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)"|' pyscripts/pm3_resources.py
|
||||
$(Q)sed -i 's|^DICTS_PATH \?= \?None|DICTS_PATH="$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)/dictionaries"|' pyscripts/pm3_resources.py
|
||||
$(Q)$(INSTALLSUDO) $(CP) $(INSTALLSHARE) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
|
||||
$(Q)sed -i 's|^TOOLS_PATH \?=.*|TOOLS_PATH = None|' pyscripts/pm3_resources.py
|
||||
$(Q)sed -i 's|^DICTS_PATH \?=.*|DICTS_PATH = None|' pyscripts/pm3_resources.py
|
||||
endif
|
||||
endif
|
||||
@true
|
||||
|
||||
|
||||
@@ -3621,12 +3621,12 @@ TRex *trex_compile(const TRexChar *pattern, const TRexChar **error, int flags) {
|
||||
exp->_first = trex_newnode(exp, OP_EXPR);
|
||||
exp->_error = error;
|
||||
exp->_jmpbuf = malloc(sizeof(jmp_buf));
|
||||
|
||||
|
||||
if (exp->_jmpbuf == NULL) {
|
||||
trex_free(exp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
exp->_flags = flags;
|
||||
if (setjmp(*((jmp_buf *)exp->_jmpbuf)) == 0) {
|
||||
int res = trex_list(exp);
|
||||
|
||||
@@ -179,7 +179,9 @@
|
||||
#ifndef unlikely
|
||||
# define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#endif
|
||||
#ifndef unreachable
|
||||
# define unreachable() __builtin_unreachable()
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
|
||||
@@ -1905,15 +1905,14 @@ FF16014FEFC7
|
||||
# Food GEM
|
||||
6686FADE5566
|
||||
#
|
||||
# Samsung Data Systems (SDS) — Electronic Locks
|
||||
# Gen 1 S10 KA/KB is FFFFFFFFFFFF, incompatible with Gen 2 locks
|
||||
#
|
||||
# SDS Gen 2 S10 KB
|
||||
# Samsung Data Systems (SDS)
|
||||
# 10-11 A/B (Gen 2)
|
||||
9B7C25052FC3
|
||||
C22E04247D9A
|
||||
6C4F77534170
|
||||
704153564F6C
|
||||
#
|
||||
# Data from Discord, French pool
|
||||
# SDS Gen 2 S10 KA
|
||||
9B7C25052FC3
|
||||
494446555455
|
||||
#
|
||||
# Data from Discord, seems to be related to ASSA
|
||||
@@ -3108,3 +3107,80 @@ AB921CF0752C
|
||||
265A5F32DE73
|
||||
567D734C403C
|
||||
2426217B3B3B
|
||||
#
|
||||
# Card keys from Andalusian public transport system (Consorcio de Transportes)
|
||||
1848A8D1E4C5
|
||||
16EE1FE134E4
|
||||
5246B8F4ACFC
|
||||
515A8209843C
|
||||
0EF7636AA829
|
||||
E59D0F78C413
|
||||
5AF68604DD6B
|
||||
B0BCB22DCBA3
|
||||
51B3EF60BF56
|
||||
99100225D83B
|
||||
63C88F562B97
|
||||
B30B6A5AD434
|
||||
D33E4A4A0041
|
||||
9C0A4CC89D61
|
||||
5204D83D8CD3
|
||||
A662F9DC0D3D
|
||||
#
|
||||
# Card keys from EMT Malaga (Spain) bus system
|
||||
41534E354936
|
||||
454D41343253
|
||||
4541444C4130
|
||||
46305234324E
|
||||
505444505232
|
||||
5239425A3546
|
||||
454449434631
|
||||
414F4544384C
|
||||
344E4F4E4937
|
||||
45444E413254
|
||||
3255534D3033
|
||||
4F554D523935
|
||||
3141544D3735
|
||||
494E47463539
|
||||
32414F4E3341
|
||||
41534C473637
|
||||
534E41395430
|
||||
41364C38364F
|
||||
525241414D39
|
||||
41304532334F
|
||||
4D4545494F35
|
||||
4E324C453045
|
||||
394143494E32
|
||||
5352554E3245
|
||||
324553553036
|
||||
444D414E3539
|
||||
324745413232
|
||||
4E4E41455236
|
||||
394C52493639
|
||||
4D4941413236
|
||||
414D504F3243
|
||||
434C414E3639
|
||||
# Key for Waferlock shadow programming card and shadow user card
|
||||
333030313536
|
||||
#
|
||||
# Poland Warsaw public transport card keys
|
||||
2481118e5355
|
||||
b6f0fc87f57f
|
||||
e4fdac292bed
|
||||
5888180adbe6
|
||||
d572c9491137
|
||||
64ea317b7abd
|
||||
a39a286285db
|
||||
898989890823
|
||||
898989891789
|
||||
898989893089
|
||||
b6e56bad206a
|
||||
8fe6fa230c69
|
||||
4d1095f1af34
|
||||
1ad2f99bb9e9
|
||||
891089898989
|
||||
896389898989
|
||||
890163898989
|
||||
898927638989
|
||||
898989063889
|
||||
898989428989
|
||||
898989048989
|
||||
@@ -4,6 +4,7 @@ ffffffffffffffff
|
||||
0011223344556677
|
||||
1122334455667788
|
||||
a0a1a2a3a4a5a6a7
|
||||
d3f7d3f7d3f7d3f7
|
||||
00000000000000000000000000000000 #NXP Default 3DES/AES
|
||||
000000000000000000000000000000000000000000000000 #NXP Default 3K3DES
|
||||
00112233445566778899AABBCCDDEEFF0102030405060708
|
||||
|
||||
@@ -0,0 +1,357 @@
|
||||
local ansicolors = require('ansicolors')
|
||||
local cmds = require('commands')
|
||||
local getopt = require('getopt')
|
||||
local lib14a = require('read14a')
|
||||
local utils = require('utils')
|
||||
|
||||
-- globals
|
||||
copyright = ''
|
||||
author = 'Dmitry Malenok'
|
||||
version = 'v1.0.0'
|
||||
desc = [[
|
||||
The script provides functionality for writing Mifare Ultralight Ultra/UL-5 tags.
|
||||
]]
|
||||
example = [[
|
||||
-- restpre (write) dump to tag
|
||||
]]..ansicolors.yellow..[[script run hf_mfu_ultra -f hf-mfu-3476FF1514D866-dump.bin -k ffffffff -r]]..ansicolors.reset..[[
|
||||
|
||||
-- wipe tag (]]..ansicolors.red..[[Do not use it with UL-5!]]..ansicolors.reset..[[)
|
||||
]]..ansicolors.yellow..[[script run hf_mfu_ultra -k 1d237f76 -w ]]..ansicolors.reset..[[
|
||||
]]
|
||||
usage = [[
|
||||
script run hf_mfu_ultra -h -f <dump filename> -k <passwd> -w -r
|
||||
]]
|
||||
arguments = [[
|
||||
-h this help
|
||||
-f filename for the datadump to read (bin)
|
||||
-k pwd to use with the restore and wipe operations
|
||||
-r restore a binary dump to tag
|
||||
-w wipe tag (]]..ansicolors.red..[[Do not use it with UL-5!]]..ansicolors.reset..[[)
|
||||
|
||||
]]
|
||||
|
||||
|
||||
local _password = nil
|
||||
local _defaultPassword = 'FFFFFFFF'
|
||||
local _dumpstart = 0x38*2 + 1
|
||||
---
|
||||
|
||||
--- Handles errors
|
||||
local function error(err)
|
||||
print(ansicolors.red.."ERROR:"..ansicolors.reset, err)
|
||||
core.clearCommandBuffer()
|
||||
return nil, err
|
||||
end
|
||||
---
|
||||
|
||||
-- sets the global password variable
|
||||
local function setPassword(password)
|
||||
if password == nil or #password == 0 then
|
||||
_password = nil;
|
||||
elseif #password ~= 8 then
|
||||
return false, 'Password must be 4 hex bytes'
|
||||
else
|
||||
_password = password
|
||||
end
|
||||
return true, 'Sets'
|
||||
end
|
||||
|
||||
|
||||
--- Parses response data
|
||||
local function parseResponse(rawResponse)
|
||||
local resp = Command.parse(rawResponse)
|
||||
local len = tonumber(resp.arg1) * 2
|
||||
return string.sub(tostring(resp.data), 0, len);
|
||||
end
|
||||
---
|
||||
|
||||
--- Sends raw data to PM3 and returns raw response if any
|
||||
local function sendRaw(rawdata, options)
|
||||
|
||||
local flags = lib14a.ISO14A_COMMAND.ISO14A_RAW
|
||||
|
||||
if options.keep_signal then
|
||||
flags = flags + lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT
|
||||
end
|
||||
|
||||
if options.connect then
|
||||
flags = flags + lib14a.ISO14A_COMMAND.ISO14A_CONNECT
|
||||
end
|
||||
|
||||
if options.no_select then
|
||||
flags = flags + lib14a.ISO14A_COMMAND.ISO14A_NO_SELECT
|
||||
end
|
||||
|
||||
if options.append_crc then
|
||||
flags = flags + lib14a.ISO14A_COMMAND.ISO14A_APPEND_CRC
|
||||
end
|
||||
|
||||
local arg2 = #rawdata / 2
|
||||
if options.bits7 then
|
||||
arg2 = arg2 | tonumber(bit32.lshift(7, 16))
|
||||
end
|
||||
|
||||
local command = Command:newMIX{cmd = cmds.CMD_HF_ISO14443A_READER,
|
||||
arg1 = flags,
|
||||
arg2 = arg2,
|
||||
data = rawdata}
|
||||
return command:sendMIX(options.ignore_response)
|
||||
end
|
||||
---
|
||||
|
||||
--- Sends raw data to PM3 and returns parsed response
|
||||
local function sendWithResponse(payload, options)
|
||||
local opts;
|
||||
if options then
|
||||
opts = options
|
||||
else
|
||||
opts = {ignore_response = false, keep_signal = true, append_crc = true}
|
||||
end
|
||||
local rawResp, err = sendRaw(payload, opts)
|
||||
if err then return err end
|
||||
return parseResponse(rawResp)
|
||||
end
|
||||
---
|
||||
|
||||
-- Authenticates if password is provided
|
||||
local function authenticate(password)
|
||||
if password then
|
||||
local resp, err = sendWithResponse('1B'..password)
|
||||
if err then return err end
|
||||
-- looking for 2 bytes (4 symbols) of PACK and 2 bytes (4 symbols) of CRC
|
||||
if not resp or #resp ~=8 then return false, 'It seems that password is wrong' end
|
||||
return true
|
||||
end
|
||||
return true
|
||||
end
|
||||
--
|
||||
|
||||
-- selects tag and authenticates if password is provided
|
||||
local function connect()
|
||||
core.clearCommandBuffer()
|
||||
local info, err = lib14a.read(true, true)
|
||||
if err then
|
||||
lib14a.disconnect()
|
||||
return false, err
|
||||
end
|
||||
core.clearCommandBuffer()
|
||||
|
||||
return authenticate(_password)
|
||||
end
|
||||
--
|
||||
|
||||
-- reconnects and selects tag again
|
||||
local function reconnect()
|
||||
lib14a.disconnect()
|
||||
utils.Sleep(1)
|
||||
local info, err = connect()
|
||||
if not info then return false, "Unable to select tag: "..err end
|
||||
return true
|
||||
end
|
||||
--
|
||||
|
||||
-- checks tag version
|
||||
local function checkTagVersion()
|
||||
local resp, err = sendWithResponse('60');
|
||||
if err or resp == nil then return false, err end
|
||||
if string.find(resp, '0034210101000E03') ~= 1 then return false, 'Wrong tag version: '..string.sub(resp,1,-5) end
|
||||
return true
|
||||
end
|
||||
--
|
||||
|
||||
-- sends magic wakeup command
|
||||
local function magicWakeup()
|
||||
io.write('Sending magic wakeup command...')
|
||||
local resp, err = sendRaw('5000', {ignore_response = false, append_crc = true})
|
||||
if err or resp == nil then return false, "Unable to send first magic wakeup command: "..err end
|
||||
resp, err = sendRaw('40', {connect = true, no_select = true, ignore_response = false, keep_signal = true, append_crc = false, bits7 = true})
|
||||
if err or resp == nil then return false, "Unable to send first magic wakeup command: "..err end
|
||||
resp, err = sendRaw('43', {ignore_response = false, keep_signal = true, append_crc = false})
|
||||
if err or resp == nil then return false, "Unable to send second magic wakeup command: "..err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
return true
|
||||
end
|
||||
--
|
||||
|
||||
-- Writes dump to tag
|
||||
local function writeDump(filename)
|
||||
print(string.rep('--',20))
|
||||
local info, err = connect()
|
||||
if not info then return false, "Unable to select tag: "..err end
|
||||
info, err = checkTagVersion()
|
||||
if not info then return info, err end
|
||||
|
||||
-- load dump from file
|
||||
if not filename then return false, 'No dump filename provided' end
|
||||
io.write('Loading dump from file '..filename..'...')
|
||||
local dump
|
||||
dump, err = utils.ReadDumpFile(filename)
|
||||
if not dump then return false, err end
|
||||
if #dump ~= _dumpstart - 1 + 0xa4*2 then return false, 'Invalid dump file' end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
|
||||
local resp
|
||||
for i = 3, 0x23 do
|
||||
local blockStart = i * 8 + _dumpstart
|
||||
local block = string.sub(dump, blockStart, blockStart + 7)
|
||||
local cblock = string.format('%02x',i)
|
||||
io.write('Writing block 0x'..cblock..'...')
|
||||
resp, err = sendWithResponse('A2'..cblock..block)
|
||||
if err ~= nil then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
end
|
||||
|
||||
-- set password
|
||||
io.write('Setting password and pack ')
|
||||
info, err = reconnect()
|
||||
if not info then return false, err end
|
||||
local passwordStart = 0x27*8 + _dumpstart
|
||||
local password = string.sub(dump, passwordStart, passwordStart + 7)
|
||||
local packBlock = string.sub(dump, passwordStart+8, passwordStart + 15)
|
||||
io.write('(password: '..password..') (pack block: '..packBlock..')...')
|
||||
resp, err = sendWithResponse('A227'..password)
|
||||
if err ~= nil then return false, err end
|
||||
resp, err = sendWithResponse('A228'..packBlock)
|
||||
if err ~= nil then return false, err end
|
||||
if not setPassword(password) then return false, 'Unable to set password' end
|
||||
info, err = reconnect()
|
||||
if not info then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
|
||||
-- set configs and locks
|
||||
for i = 0x24, 0x26 do
|
||||
local blockStart = i * 8 + _dumpstart
|
||||
local block = string.sub(dump, blockStart, blockStart + 7)
|
||||
local cblock = string.format('%02x',i)
|
||||
io.write('Writing block 0x'..cblock..'...')
|
||||
resp, err = sendWithResponse('A2'..cblock..block)
|
||||
if err ~= nil then return false, err end
|
||||
info, err = reconnect()
|
||||
if not info then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
end
|
||||
|
||||
info, err = magicWakeup()
|
||||
if not info then return false, err end
|
||||
-- set uid and locks
|
||||
for i = 0x2, 0x0, -1 do
|
||||
local blockStart = i * 8 + _dumpstart
|
||||
local block = string.sub(dump, blockStart, blockStart + 7)
|
||||
local cblock = string.format('%02x',i)
|
||||
io.write('Writing block 0x'..cblock..'...')
|
||||
resp, err = sendWithResponse('A2'..cblock..block, {connect = i == 0x2, ignore_response = false, keep_signal = i ~= 0, append_crc = true})
|
||||
if err ~= nil then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
end
|
||||
|
||||
print(ansicolors.green..'The dump has been written to the tag.'..ansicolors.reset)
|
||||
return true
|
||||
end
|
||||
--
|
||||
|
||||
-- Wipes tag
|
||||
local function wipe()
|
||||
print(string.rep('--',20))
|
||||
print('Wiping tag')
|
||||
|
||||
local info, err = connect()
|
||||
if not info then return false, "Unable to select tag: "..err end
|
||||
info, err = checkTagVersion()
|
||||
if not info then return info, err end
|
||||
|
||||
|
||||
local resp
|
||||
-- clear lock bytes on page 0x02
|
||||
resp, err = sendWithResponse('3000')
|
||||
if err or resp == nil then return false, err end
|
||||
local currentLowLockPage = string.sub(resp,17,24)
|
||||
if(string.sub(currentLowLockPage,5,8) ~= '0000') then
|
||||
info, err = magicWakeup()
|
||||
if not info then return false, err end
|
||||
local newLowLockPage = string.sub(currentLowLockPage,1,4)..'0000'
|
||||
io.write('Clearing lock bytes on page 0x02...')
|
||||
resp, err = sendWithResponse('A202'..newLowLockPage, {connect = true, ignore_response = false, keep_signal = true, append_crc = true})
|
||||
if err ~= nil then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
end
|
||||
|
||||
-- clear lock bytes on page 0x24
|
||||
io.write('Clearing lock bytes on page 0x24...')
|
||||
info, err = reconnect()
|
||||
if not info then return false, err end
|
||||
resp, err = sendWithResponse('A224000000BD')
|
||||
if err ~= nil then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
|
||||
-- clear configs
|
||||
io.write('Clearing cfg0 and cfg1...')
|
||||
resp, err = sendWithResponse('A225000000FF')
|
||||
if err ~= nil then return false, err end
|
||||
resp, err = sendWithResponse('A22600050000')
|
||||
if err ~= nil then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
|
||||
-- clear password
|
||||
io.write('Reseting password (and pack) to default ('.._defaultPassword..') and 0000...')
|
||||
info, err = reconnect()
|
||||
if not info then return false, err end
|
||||
resp, err = sendWithResponse('A227'.._defaultPassword)
|
||||
if err ~= nil then return false, err end
|
||||
resp, err = sendWithResponse('A22800000000')
|
||||
if err ~= nil then return false, err end
|
||||
if not setPassword(_defaultPassword) then return false, 'Unable to set password' end
|
||||
info, err = reconnect()
|
||||
if not info then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
|
||||
-- clear other blocks
|
||||
for i = 3, 0x23 do
|
||||
local cblock = string.format('%02x',i)
|
||||
io.write('Clearing block 0x'..cblock..'...')
|
||||
resp, err = sendWithResponse('A2'..cblock..'00000000')
|
||||
if err ~= nil then return false, err end
|
||||
print(ansicolors.green..'done'..ansicolors.reset..'.')
|
||||
end
|
||||
|
||||
print(ansicolors.green..'The tag has been wiped.'..ansicolors.reset)
|
||||
|
||||
lib14a.disconnect()
|
||||
return true
|
||||
end
|
||||
--
|
||||
|
||||
-- Prints 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
|
||||
---
|
||||
|
||||
-- The main entry point
|
||||
local function main(args)
|
||||
if #args == 0 then return help() end
|
||||
|
||||
local dumpFilename = nil
|
||||
|
||||
for opt, value in getopt.getopt(args, 'hf:k:rw') do
|
||||
local res, err
|
||||
res = true
|
||||
if opt == "h" then return help() end
|
||||
if opt == "f" then dumpFilename = value end
|
||||
if opt == 'k' then res, err = setPassword(value) end
|
||||
if opt == 'r' then res, err = writeDump(dumpFilename) end
|
||||
if opt == 'w' then res, err = wipe() end
|
||||
if not res then return error(err) end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
main(args)
|
||||
@@ -0,0 +1,747 @@
|
||||
--[[
|
||||
Simple script to program DIY kyber crystals
|
||||
works on real kyber crystals and EM4305 2.12x12mm chips
|
||||
simply run the program and select a profile via a number
|
||||
|
||||
issues
|
||||
if you are getting errors when trying to read or write a chip
|
||||
run the cmd "lf tune" with no chip on the device, then move the chip over the coils till you see the lowest voltage. try different angles and in the center and or the edge of the antenna ring.
|
||||
once you find the lowest voltage then try running the script again.
|
||||
if thats still not working run "lf tune" again and put the chip in the best position like before
|
||||
the total voltage may be too high to reduce it slowly lower tin foil over the antenna and watch the voltage.
|
||||
the foil should be a bit bigger than the coil exact size does not matter.
|
||||
|
||||
data pulled from here
|
||||
https://docs.google.com/spreadsheets/d/13P_GE6tNYpGvoVUTEQvA3SQzMqpZ-SoiWaTNoJoTV9Q/edit?usp=sharing
|
||||
--]]
|
||||
|
||||
local cmds = require('commands')
|
||||
local utils = require('utils')
|
||||
|
||||
|
||||
function send_command(cmd)
|
||||
core.console(cmd)
|
||||
return ""
|
||||
end
|
||||
|
||||
function get_profile_data(profile_name)
|
||||
local profiles = {
|
||||
["wipe chip"] = {
|
||||
[0] = "00000000",
|
||||
[1] = "00000000",
|
||||
[2] = "00000000",
|
||||
[3] = "00000000",
|
||||
[4] = "00000000",
|
||||
[5] = "00000000",
|
||||
[6] = "00000000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Qui-Gon Jinn"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6147FBB3",
|
||||
[2] = "00000000",
|
||||
[3] = "000064FC",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "0C803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Qui-Gon Jinn 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6148C1EF",
|
||||
[2] = "00000000",
|
||||
[3] = "000050C2",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "0C803000",
|
||||
[7] = "00000000",
|
||||
[8] = "10000040",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Yoda"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "660A50D6",
|
||||
[2] = "00000000",
|
||||
[3] = "0000379F",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "00C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100040",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Yoda 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667B2FEE",
|
||||
[2] = "00000000",
|
||||
[3] = "0000BDB6",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "00C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100040",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Yoda 8-Ball"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "67AD7FC8",
|
||||
[2] = "00000000",
|
||||
[3] = "0000E0FE",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "5D183000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000140",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Old Obi-Wan"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6147BBB9",
|
||||
[2] = "00000000",
|
||||
[3] = "0000BE24",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "29803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Old Luke"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "614097AE",
|
||||
[2] = "00000000",
|
||||
[3] = "0000C134",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "25C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100060",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Old Obi-Wan 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "614009A2",
|
||||
[2] = "00000000",
|
||||
[3] = "0000CF62",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "29803000",
|
||||
[7] = "00000000",
|
||||
[8] = "01000060",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Old Luke 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "75952DE5",
|
||||
[2] = "00000000",
|
||||
[3] = "00009988",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "25C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00010060",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Old Obi-Wan 3"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "65413B42",
|
||||
[2] = "00000000",
|
||||
[3] = "00001702",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "29803000",
|
||||
[7] = "00000000",
|
||||
[8] = "01000060",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Mace Windu"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6147CCD4",
|
||||
[2] = "00000000",
|
||||
[3] = "0000A092",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "63C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Mace Windu 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6609B150",
|
||||
[2] = "00000000",
|
||||
[3] = "0000287E",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "63C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00010070",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Mace Windu 3"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "613F42AD",
|
||||
[2] = "00000000",
|
||||
[3] = "00002147",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "6F803000",
|
||||
[7] = "00000000",
|
||||
[8] = "01000070",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Mace Windu 4"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667B5B82",
|
||||
[2] = "00000000",
|
||||
[3] = "000050DF",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "6F803000",
|
||||
[7] = "00000000",
|
||||
[8] = "10000070",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Mace Windu 5"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "614869C4",
|
||||
[2] = "00000000",
|
||||
[3] = "0000D691",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "6F803000",
|
||||
[7] = "00000000",
|
||||
[8] = "01000070",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Mace Windu 6"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "759BEA43",
|
||||
[2] = "00000000",
|
||||
[3] = "00006CA0",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "63C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100070",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Mace Windu 7"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "768E0D9D",
|
||||
[2] = "00000000",
|
||||
[3] = "0000668C",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "6F803000",
|
||||
[7] = "00000000",
|
||||
[8] = "01000070",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Temple Guard"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "60954FDA",
|
||||
[2] = "00000000",
|
||||
[3] = "0000905A",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "7B003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Maz Kanata"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6679DFF4",
|
||||
[2] = "00000000",
|
||||
[3] = "0000D691",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "77403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100030",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Maz Kanata 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "60953999",
|
||||
[2] = "00000000",
|
||||
[3] = "0000F521",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "77403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100030",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Temple Guard 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667A67C5",
|
||||
[2] = "00000000",
|
||||
[3] = "00002B9C",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "7B003000",
|
||||
[7] = "00000000",
|
||||
[8] = "10000030",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Maz Kanata 3"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7A213721",
|
||||
[2] = "00000000",
|
||||
[3] = "000083AB",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "77403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00010030",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Chirrut Îmwe"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6094F399",
|
||||
[2] = "00000000",
|
||||
[3] = "00009519",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "14403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Chirrut Îmwe 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667A9AB7",
|
||||
[2] = "00000000",
|
||||
[3] = "00003BE4",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "14403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00010000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Ahsoka Tano"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667B1626",
|
||||
[2] = "00000000",
|
||||
[3] = "00007907",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "18003000",
|
||||
[7] = "00000000",
|
||||
[8] = "10000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Chirrut Îmwe 3"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667B7E07",
|
||||
[2] = "00000000",
|
||||
[3] = "00002960",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "14403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Darth Vader"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6148C4F8",
|
||||
[2] = "00000000",
|
||||
[3] = "0000FDFF",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "5E003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Darth Sidious"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "613F8964",
|
||||
[2] = "00000000",
|
||||
[3] = "0000C0C1",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "52403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Darth Maul"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "613FD2A9",
|
||||
[2] = "00000000",
|
||||
[3] = "0000DAD2",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "46C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Count Dooku"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6140880C",
|
||||
[2] = "00000000",
|
||||
[3] = "0000952D",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "31403000",
|
||||
[7] = "00000000",
|
||||
[8] = "00010010",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Darth Vader 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667B33DC",
|
||||
[2] = "00000000",
|
||||
[3] = "0000E804",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "5E003000",
|
||||
[7] = "00000000",
|
||||
[8] = "01000010",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Darth Maul 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "667B26E9",
|
||||
[2] = "00000000",
|
||||
[3] = "00007689",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "46C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100010",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Vader 8-Ball"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6A92B478",
|
||||
[2] = "00000000",
|
||||
[3] = "00004CD1",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "3E183000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000110",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Darth Maul 3"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7597EF7E",
|
||||
[2] = "00000000",
|
||||
[3] = "00003BC0",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "46C03000",
|
||||
[7] = "00000000",
|
||||
[8] = "00100010",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Darth Sidious 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "768E4402",
|
||||
[2] = "00000000",
|
||||
[3] = "0000A0D2",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "52403000",
|
||||
[7] = "00000000",
|
||||
[8] = "10000010",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Snoke"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "6540BD8F",
|
||||
[2] = "00000000",
|
||||
[3] = "000064B9",
|
||||
[4] = "0001805F",
|
||||
[5] = "000001FF",
|
||||
[6] = "1B183000",
|
||||
[7] = "00000000",
|
||||
[8] = "00001010",
|
||||
[9] = "00000000"
|
||||
},
|
||||
["Luke Skywalker"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "804B08F0",
|
||||
[2] = "00000000",
|
||||
[3] = "00006BF1",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "0C803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "050D0000"
|
||||
},
|
||||
["Luminara Unduli"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B83C85A",
|
||||
[2] = "00000000",
|
||||
[3] = "000052CE",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "0C803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "180D0000"
|
||||
},
|
||||
["Plo Koon"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B8998F3",
|
||||
[2] = "00000000",
|
||||
[3] = "00007703",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "29803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "040D0000"
|
||||
},
|
||||
["Plo Koon 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B8413EA",
|
||||
[2] = "00000000",
|
||||
[3] = "0000D8F3",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "29803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "040D0000"
|
||||
},
|
||||
["Plo Koon 3"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B84222B",
|
||||
[2] = "00000000",
|
||||
[3] = "000023E3",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "29803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "040D0000"
|
||||
},
|
||||
["Mace Windu S2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B8936EA",
|
||||
[2] = "00000000",
|
||||
[3] = "0000520D",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "6F803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "070D0000"
|
||||
},
|
||||
["General Grievous"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B896284",
|
||||
[2] = "00000000",
|
||||
[3] = "00008529",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "6F803000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "060D0000"
|
||||
},
|
||||
["Rey Skywalker"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B88F3F4",
|
||||
[2] = "00000000",
|
||||
[3] = "00001511",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "7B003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "170D0000"
|
||||
},
|
||||
["Rey Skywalker 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B841039",
|
||||
[2] = "00000000",
|
||||
[3] = "0000EA22",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "7B003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "170D0000"
|
||||
},
|
||||
["Krin Dagbard"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B894F46",
|
||||
[2] = "00000000",
|
||||
[3] = "00007BC2",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "18003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "140D0000"
|
||||
},
|
||||
["Krin Dagbard 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B841797",
|
||||
[2] = "00000000",
|
||||
[3] = "00006A58",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "18003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "140D0000"
|
||||
},
|
||||
["Grand Inquisitor"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B841185",
|
||||
[2] = "00000000",
|
||||
[3] = "00004656",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "5E003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "130D0000"
|
||||
},
|
||||
["Maul"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7B895525",
|
||||
[2] = "00000000",
|
||||
[3] = "00003104",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "5E003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "110D0000"
|
||||
},
|
||||
["Grand Inquisitor 2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "804B091A",
|
||||
[2] = "00000000",
|
||||
[3] = "00005909",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "5E003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "130D0000"
|
||||
},
|
||||
["Asajj Ventress"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "7A1C1F46",
|
||||
[2] = "00000000",
|
||||
[3] = "00008E4D",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "5E003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "080D0000"
|
||||
},
|
||||
["Darth Sidious s2"] = {
|
||||
[0] = "00040072",
|
||||
[1] = "00000000",
|
||||
[2] = "00000000",
|
||||
[3] = "00000000",
|
||||
[4] = "0001805F",
|
||||
[5] = "18C631FF",
|
||||
[6] = "5E003000",
|
||||
[7] = "00000000",
|
||||
[8] = "00000000",
|
||||
[9] = "010D0000"
|
||||
}
|
||||
}
|
||||
|
||||
-- When called without arguments, return the whole table
|
||||
if not profile_name then
|
||||
return profiles
|
||||
end
|
||||
|
||||
-- Otherwise return the specific profile or wipe chip
|
||||
return profiles[profile_name] or profiles["wipe chip"]
|
||||
end
|
||||
|
||||
function get_profile_names()
|
||||
-- Get the complete profiles table from get_profile_data
|
||||
local all_profiles = get_profile_data()
|
||||
|
||||
local names = {}
|
||||
for name, _ in pairs(all_profiles) do
|
||||
table.insert(names, name)
|
||||
end
|
||||
table.sort(names)
|
||||
return names
|
||||
end
|
||||
|
||||
function select_profile()
|
||||
local profile_names = get_profile_names()
|
||||
|
||||
print("\nAvailable profiles:")
|
||||
for i, name in ipairs(profile_names) do
|
||||
print(string.format("%d. %s", i, name))
|
||||
end
|
||||
|
||||
while true do
|
||||
io.write("\nSelect profile (1-" .. #profile_names .. "): ")
|
||||
local choice = tonumber(io.read())
|
||||
|
||||
if choice and choice >= 1 and choice <= #profile_names then
|
||||
return profile_names[choice]
|
||||
else
|
||||
print("Invalid selection. Please try again.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function main()
|
||||
print("\n[=== kyber crystal programmer ===]")
|
||||
|
||||
-- Get profile from command line argument or prompt user
|
||||
local profile_name = args and args[1]
|
||||
if not profile_name then
|
||||
--print("\nNo profile specified as argument.")
|
||||
profile_name = select_profile()
|
||||
end
|
||||
|
||||
local data_to_write = get_profile_data(profile_name)
|
||||
print("\n[+] Using profile: " .. profile_name)
|
||||
|
||||
-- Display what will be written
|
||||
print("\n[+] Data to be written:")
|
||||
for addr, data in pairs(data_to_write) do
|
||||
print(string.format("Address %d: %s", addr, data))
|
||||
end
|
||||
|
||||
-- Step 1: Wipe the tag
|
||||
print("\n[+] Wiping tag...")
|
||||
send_command("lf em 4x05 wipe --4305")
|
||||
|
||||
-- Step 2: Write data
|
||||
print("\n[+] Writing data...")
|
||||
for addr, data in pairs(data_to_write) do
|
||||
send_command("lf em 4x05 write -a " .. addr .. " -d " .. data)
|
||||
utils.Sleep(0.5)
|
||||
end
|
||||
|
||||
-- Step 3: Read back and display data for verification
|
||||
print("\n[+] Verifying writes by reading back data...")
|
||||
for addr, expected_data in pairs(data_to_write) do
|
||||
local output = send_command("lf em 4x05 read -a " .. addr)
|
||||
end
|
||||
|
||||
print("\n[+] Read complete. Review output above.")
|
||||
end
|
||||
|
||||
main()
|
||||
@@ -1,128 +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
|
||||
|
||||
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)
|
||||
@@ -1,131 +1,131 @@
|
||||
local getopt = require('getopt')
|
||||
local ansicolors = require('ansicolors')
|
||||
local cmds = require('commands')
|
||||
|
||||
copyright = ''
|
||||
author = "TheChamop669"
|
||||
version = 'v1.0.1'
|
||||
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.
|
||||
]]
|
||||
local getopt = require('getopt')
|
||||
local ansicolors = require('ansicolors')
|
||||
local cmds = require('commands')
|
||||
|
||||
copyright = ''
|
||||
author = "TheChamop669"
|
||||
version = 'v1.0.1'
|
||||
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.
|
||||
]]
|
||||
@@ -1,125 +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)
|
||||
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)
|
||||
+487
-487
@@ -1,488 +1,488 @@
|
||||
local getopt = require('getopt')
|
||||
local utils = require('utils')
|
||||
local ac = require('ansicolors')
|
||||
local os = require('os')
|
||||
local dash = string.rep('--', 32)
|
||||
local dir = os.getenv('HOME') .. '/.proxmark3/logs/'
|
||||
local logfile = (io.popen('dir /a-d /o-d /tw /b/s "' .. dir .. '" 2>nul:'):read("*a"):match("%C+"))
|
||||
local log_file_path = dir .. "Paxton_log.txt"
|
||||
local nam = ""
|
||||
local pm3 = require('pm3')
|
||||
p = pm3.pm3()
|
||||
local command = core.console
|
||||
command('clear')
|
||||
|
||||
author = ' Author: jareckib - 30.01.2025'
|
||||
tutorial = ' Based on Equipter tutorial - Downgrade Paxton to EM4102'
|
||||
version = ' version v1.20'
|
||||
desc = [[
|
||||
The script automates the copying of Paxton fobs read - write.
|
||||
It also allows manual input of data for blocks 4-7.
|
||||
The third option is reading data stored in the log file and create new fob.
|
||||
Additionally, the script calculates the ID for downgrading Paxton to EM4102.
|
||||
|
||||
]]
|
||||
usage = [[
|
||||
script run paxton_clone
|
||||
]]
|
||||
arguments = [[
|
||||
script run paxton_clone -h : this help
|
||||
]]
|
||||
|
||||
local debug = true
|
||||
|
||||
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
|
||||
|
||||
local function help()
|
||||
print()
|
||||
print(author)
|
||||
print(tutorial)
|
||||
print(version)
|
||||
print(desc)
|
||||
print(ac.cyan..' Usage'..ac.reset)
|
||||
print(usage)
|
||||
print(ac.cyan..' Arguments'..ac.reset)
|
||||
print(arguments)
|
||||
end
|
||||
|
||||
local function reset_log_file()
|
||||
local file = io.open(logfile, "w+")
|
||||
file:write("")
|
||||
file:close()
|
||||
end
|
||||
|
||||
local function read_log_file(logfile)
|
||||
local file = io.open(logfile, "r")
|
||||
if not file then
|
||||
error(" Could not open the file")
|
||||
end
|
||||
local content = file:read("*all")
|
||||
file:close()
|
||||
return content
|
||||
end
|
||||
|
||||
local function parse_blocks(result)
|
||||
local blocks = {}
|
||||
for line in result:gmatch("[^\r\n]+") do
|
||||
local block_num, block_data = line:match("%[%=%]%s+%d/0x0([4-7])%s+%|%s+([0-9A-F ]+)")
|
||||
if block_num and block_data then
|
||||
block_num = tonumber(block_num)
|
||||
block_data = block_data:gsub("%s+", "")
|
||||
blocks[block_num] = block_data
|
||||
end
|
||||
end
|
||||
return blocks
|
||||
end
|
||||
|
||||
local function hex_to_bin(hex_string)
|
||||
local bin_string = ""
|
||||
local hex_to_bin_map = {
|
||||
['0'] = "0000", ['1'] = "0001", ['2'] = "0010", ['3'] = "0011",
|
||||
['4'] = "0100", ['5'] = "0101", ['6'] = "0110", ['7'] = "0111",
|
||||
['8'] = "1000", ['9'] = "1001", ['A'] = "1010", ['B'] = "1011",
|
||||
['C'] = "1100", ['D'] = "1101", ['E'] = "1110", ['F'] = "1111"
|
||||
}
|
||||
for i = 1, #hex_string do
|
||||
bin_string = bin_string .. hex_to_bin_map[hex_string:sub(i, i)]
|
||||
end
|
||||
return bin_string
|
||||
end
|
||||
|
||||
local function remove_last_two_bits(binary_str)
|
||||
return binary_str:sub(1, #binary_str - 2)
|
||||
end
|
||||
|
||||
local function split_into_5bit_chunks(binary_str)
|
||||
local chunks = {}
|
||||
for i = 1, #binary_str, 5 do
|
||||
table.insert(chunks, binary_str:sub(i, i + 4))
|
||||
end
|
||||
return chunks
|
||||
end
|
||||
|
||||
local function remove_parity_bit(chunks)
|
||||
local no_parity_chunks = {}
|
||||
for _, chunk in ipairs(chunks) do
|
||||
if #chunk == 5 then
|
||||
table.insert(no_parity_chunks, chunk:sub(2))
|
||||
end
|
||||
end
|
||||
return no_parity_chunks
|
||||
end
|
||||
|
||||
local function convert_to_hex(chunks)
|
||||
local hex_values = {}
|
||||
for _, chunk in ipairs(chunks) do
|
||||
if #chunk > 0 then
|
||||
table.insert(hex_values, string.format("%X", tonumber(chunk, 2)))
|
||||
end
|
||||
end
|
||||
return hex_values
|
||||
end
|
||||
|
||||
local function convert_to_decimal(chunks)
|
||||
local decimal_values = {}
|
||||
for _, chunk in ipairs(chunks) do
|
||||
table.insert(decimal_values, tonumber(chunk, 2))
|
||||
end
|
||||
return decimal_values
|
||||
end
|
||||
|
||||
local function find_until_before_f(hex_values)
|
||||
local result = {}
|
||||
for _, value in ipairs(hex_values) do
|
||||
if value == 'F' then
|
||||
break
|
||||
end
|
||||
table.insert(result, value)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function process_block(block)
|
||||
local binary_str = hex_to_bin(block)
|
||||
binary_str = remove_last_two_bits(binary_str)
|
||||
local chunks = split_into_5bit_chunks(binary_str)
|
||||
local no_parity_chunks = remove_parity_bit(chunks)
|
||||
return no_parity_chunks
|
||||
end
|
||||
|
||||
local function calculate_id_net(blocks)
|
||||
local all_hex_values = {}
|
||||
for _, block in ipairs(blocks) do
|
||||
local hex_values = convert_to_hex(process_block(block))
|
||||
for _, hex in ipairs(hex_values) do
|
||||
table.insert(all_hex_values, hex)
|
||||
end
|
||||
end
|
||||
local selected_hex_values = find_until_before_f(all_hex_values)
|
||||
if #selected_hex_values == 0 then
|
||||
error(ac.red..' Error: '..ac.reset..'No valid data found in blocks 4 and 5')
|
||||
end
|
||||
local combined_hex = table.concat(selected_hex_values)
|
||||
if not combined_hex:match("^%x+$") then
|
||||
error(ac.red..' Error: '..ac.reset..'Invalid data in blocks 4 and 5')
|
||||
end
|
||||
local decimal_id = tonumber(combined_hex)
|
||||
local stripped_hex_id = string.format("%X", decimal_id)
|
||||
local padded_hex_id = string.format("%010X", decimal_id)
|
||||
return decimal_id, padded_hex_id
|
||||
end
|
||||
|
||||
local function calculate_id_switch(blocks)
|
||||
local all_decimal_values = {}
|
||||
for _, block in ipairs(blocks) do
|
||||
local decimal_values = convert_to_decimal(process_block(block))
|
||||
for _, dec in ipairs(decimal_values) do
|
||||
table.insert(all_decimal_values, dec)
|
||||
end
|
||||
end
|
||||
if #all_decimal_values < 15 then
|
||||
error(ac.red..' Error:'..ac.reset..' Not enough data after processing blocks 4, 5, 6, and 7')
|
||||
end
|
||||
local id_positions = {9, 11, 13, 15, 2, 4, 6, 8}
|
||||
local id_numbers = {}
|
||||
for _, pos in ipairs(id_positions) do
|
||||
table.insert(id_numbers, all_decimal_values[pos])
|
||||
end
|
||||
local decimal_id = tonumber(table.concat(id_numbers))
|
||||
local padded_hex_id = string.format("%010X", decimal_id)
|
||||
return decimal_id, padded_hex_id
|
||||
end
|
||||
|
||||
local function name_exists_in_log(name)
|
||||
local file = io.open(log_file_path, "r")
|
||||
if not file then
|
||||
return false
|
||||
end
|
||||
local pattern = "^Name:%s*" .. name .. "%s*$"
|
||||
for line in file:lines() do
|
||||
if line:match(pattern) then
|
||||
file:close()
|
||||
return true
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
return false
|
||||
end
|
||||
|
||||
local function log_result(blocks, em410_id, name)
|
||||
local log_file = io.open(log_file_path, "a")
|
||||
if log_file then
|
||||
log_file:write("Name: " .. name .. "\n")
|
||||
log_file:write("Date: ", os.date("%Y-%m-%d %H:%M:%S"), "\n")
|
||||
for i = 4, 7 do
|
||||
log_file:write(string.format("Block %d: %s\n", i, blocks[i] or "nil"))
|
||||
end
|
||||
log_file:write(string.format('EM4102 ID: %s\n', em410_id or "nil"))
|
||||
log_file:write('--------------------------\n')
|
||||
log_file:close()
|
||||
print(' Log saved as: pm3/.proxmark3/logs/' ..ac.yellow..' Paxton_log.txt'..ac.reset)
|
||||
else
|
||||
print(" Failed to open log file for writing.")
|
||||
end
|
||||
end
|
||||
|
||||
local function verify_written_data(original_blocks)
|
||||
p:console('lf hitag read --ht2 -k BDF5E846')
|
||||
local result = read_log_file(logfile)
|
||||
local verified_blocks = parse_blocks(result)
|
||||
local success = true
|
||||
for i = 4, 7 do
|
||||
if original_blocks[i] ~= verified_blocks[i] then
|
||||
print(' Verification failed.. Block '..ac.green.. i ..ac.reset.. ' inconsistent.')
|
||||
success = false
|
||||
end
|
||||
end
|
||||
|
||||
if success then
|
||||
print(ac.green..' Verification successful. Data was written correctly.' .. ac.reset)
|
||||
else
|
||||
print(ac.yellow.. ' Adjust the position of the Paxton fob on the coil.' .. ac.reset)
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3)
|
||||
while true do
|
||||
io.write(" Create Paxton choose " .. ac.cyan .. "1" .. ac.reset .. " or EM4102 choose " .. ac.cyan .. "2 " .. ac.reset)
|
||||
local choice = io.read()
|
||||
if choice == "1" then
|
||||
io.write(" Place the" .. ac.cyan .. " Paxton " .. ac.reset .. "Fob on the coil to write.." .. ac.green .. " ENTER " .. ac.reset .. "to continue..")
|
||||
io.read()
|
||||
print(dash)
|
||||
p:console("lf hitag wrbl --ht2 -p 4 -d " .. blocks[4] .. " -k BDF5E846")
|
||||
p:console("lf hitag wrbl --ht2 -p 5 -d " .. blocks[5] .. " -k BDF5E846")
|
||||
p:console("lf hitag wrbl --ht2 -p 6 -d " .. blocks[6] .. " -k BDF5E846")
|
||||
p:console("lf hitag wrbl --ht2 -p 7 -d " .. blocks[7] .. " -k BDF5E846")
|
||||
reset_log_file()
|
||||
--timer(5)
|
||||
verify_written_data(blocks)
|
||||
elseif choice == "2" then
|
||||
io.write(" Place the" .. ac.cyan .. " T5577 " .. ac.reset .. "tag on the coil and press" .. ac.green .. " ENTER " .. ac.reset .. "to continue..")
|
||||
io.read()
|
||||
p:console("lf em 410x clone --id " .. padded_hex_id)
|
||||
print(' Cloned EM4102 to T5577 with ID ' ..ac.green.. padded_hex_id ..ac.reset)
|
||||
else
|
||||
print(ac.yellow .. " Invalid choice." .. ac.reset .. " Please enter " .. ac.cyan .. "1" .. ac.reset .. " or " .. ac.cyan .. "2" .. ac.reset)
|
||||
goto ask_again
|
||||
end
|
||||
while true do
|
||||
print(dash)
|
||||
io.write(" Make next RFID Fob"..ac.cyan.." (y/n) "..ac.reset)
|
||||
local another = io.read()
|
||||
if another:lower() == "n" then
|
||||
if was_option_3 then
|
||||
print(" No writing to Paxton_log.txt - Name: " ..ac.green.. nam .. ac.reset.. " exist")
|
||||
return
|
||||
end
|
||||
print()
|
||||
print(ac.green .. " Saving Paxton_log file..." .. ac.reset)
|
||||
while true do
|
||||
io.write(" Enter a name for database (cannot be empty/duplicate): "..ac.yellow)
|
||||
name = io.read()
|
||||
io.write(ac.reset..'')
|
||||
if name == nil or name:match("^%s*$") then
|
||||
print(ac.red .. ' ERROR:'..ac.reset..' Name cannot be empty.')
|
||||
else
|
||||
if name_exists_in_log(name) then
|
||||
print(ac.yellow .. ' Name exists!!! '..ac.reset.. 'Please choose a different name.')
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
log_result(blocks, padded_hex_id, name)
|
||||
print(ac.green .. " Log saved successfully!" .. ac.reset)
|
||||
reset_log_file()
|
||||
return
|
||||
elseif another:lower() == "y" then
|
||||
goto ask_again
|
||||
else
|
||||
print(ac.yellow.." Invalid response."..ac.reset.." Please enter"..ac.cyan.." y"..ac.reset.." or"..ac.cyan.." n"..ac.reset)
|
||||
end
|
||||
end
|
||||
::ask_again::
|
||||
end
|
||||
end
|
||||
|
||||
local function is_valid_hex(input)
|
||||
return #input == 8 and input:match("^[0-9A-Fa-f]+$")
|
||||
end
|
||||
|
||||
local function main(args)
|
||||
while true do
|
||||
for o, a in getopt.getopt(args, 'h') do
|
||||
if o == 'h' then return help() end
|
||||
end
|
||||
command('clear')
|
||||
print(dash)
|
||||
print(ac.green .. ' Select option: ' .. ac.reset)
|
||||
print(ac.cyan .. ' 1' .. ac.reset .. ' - Read Paxton blocks 4-7 to make a copy')
|
||||
print(ac.cyan .. ' 2' .. ac.reset .. ' - Manually input data for Paxton blocks 4-7')
|
||||
print(ac.cyan .. " 3" .. ac.reset .. " - Search in Paxton_log by name and use the data")
|
||||
print(dash)
|
||||
while true do
|
||||
io.write(' Your choice '..ac.cyan..'(1/2/3): ' .. ac.reset)
|
||||
input_option = io.read()
|
||||
if input_option == "1" or input_option == "2" or input_option == "3" then
|
||||
break
|
||||
else
|
||||
print(ac.yellow .. ' Invalid choice.' .. ac.reset .. ' Please enter ' .. ac.cyan .. '1' .. ac.reset .. ' or ' .. ac.cyan .. '2' .. ac.reset..' or'..ac.cyan..' 3'..ac.reset)
|
||||
end
|
||||
end
|
||||
local was_option_3 = false
|
||||
if input_option == "1" then
|
||||
local show_place_message = true
|
||||
while true do
|
||||
if show_place_message then
|
||||
io.write(' Place the' .. ac.cyan .. ' Paxton' .. ac.reset .. ' Fob on the coil to read..' .. ac.green .. 'ENTER' .. ac.reset .. ' to continue..')
|
||||
end
|
||||
io.read()
|
||||
print(dash)
|
||||
p:console('lf hitag read --ht2 -k BDF5E846')
|
||||
if not logfile then
|
||||
error(" No files in this directory")
|
||||
end
|
||||
local result = read_log_file(logfile)
|
||||
local blocks = parse_blocks(result)
|
||||
local empty_block = false
|
||||
for i = 4, 7 do
|
||||
if not blocks[i] then
|
||||
empty_block = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if empty_block then
|
||||
io.write(ac.yellow .. ' Adjust the Fob position on the coil.' .. ac.reset .. ' Press' .. ac.green .. ' ENTER' .. ac.reset .. ' to continue..')
|
||||
show_place_message = false
|
||||
else
|
||||
print(' Readed blocks:')
|
||||
print()
|
||||
for i = 4, 7 do
|
||||
if blocks[i] then
|
||||
print(string.format(" Block %d: %s%s%s", i, ac.yellow, blocks[i], ac.reset))
|
||||
end
|
||||
end
|
||||
local decimal_id, padded_hex_id
|
||||
if blocks[5] and (blocks[5]:sub(4, 4) == 'F' or blocks[5]:sub(4, 4) == 'f') then
|
||||
print(dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Net2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_net({blocks[4], blocks[5]})
|
||||
else
|
||||
print(dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Switch2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_switch({blocks[4], blocks[5], blocks[6], blocks[7]})
|
||||
end
|
||||
print(string.format(" ID for EM4102 is: %s", ac.green .. padded_hex_id .. ac.reset))
|
||||
print(dash)
|
||||
handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3)
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif input_option == "2" then
|
||||
local blocks = {}
|
||||
for i = 4, 7 do
|
||||
while true do
|
||||
io.write(ac.reset..' Enter data for block ' .. i .. ': ' .. ac.yellow)
|
||||
local input = io.read()
|
||||
input = input:upper()
|
||||
if is_valid_hex(input) then
|
||||
blocks[i] = input
|
||||
break
|
||||
else
|
||||
print(ac.yellow .. ' Invalid input.' .. ac.reset .. ' Each block must be 4 bytes (8 hex characters).')
|
||||
end
|
||||
end
|
||||
end
|
||||
local decimal_id, padded_hex_id
|
||||
if blocks[5] and (blocks[5]:sub(4, 4) == 'F' or blocks[5]:sub(4, 4) == 'f') then
|
||||
print(ac.reset.. dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Net2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_net({blocks[4], blocks[5]})
|
||||
else
|
||||
print(ac.reset.. dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Switch2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_switch({blocks[4], blocks[5], blocks[6], blocks[7]})
|
||||
end
|
||||
print(dash)
|
||||
print(string.format(" ID for EM4102 is: %s", ac.green .. padded_hex_id .. ac.reset))
|
||||
print(dash)
|
||||
if not padded_hex_id then
|
||||
print(ac.red..' ERROR: '..ac.reset.. 'Invalid block data provided')
|
||||
return
|
||||
end
|
||||
handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3)
|
||||
break
|
||||
elseif input_option == "3" then
|
||||
was_option_3 = true
|
||||
local retries = 3
|
||||
while retries > 0 do
|
||||
io.write(' Enter the name to search ('..retries..' attempts) : '..ac.yellow)
|
||||
local user_input = io.read()
|
||||
io.write(ac.reset..'')
|
||||
if user_input == nil or user_input:match("^%s*$") then
|
||||
print(ac.yellow..' Error: '..ac.reset.. 'Empty name !!!')
|
||||
end
|
||||
local name_clean = "^Name:%s*" .. user_input:gsub("%s", "%%s") .. "%s*$"
|
||||
local file = io.open(log_file_path, "r")
|
||||
if not file then
|
||||
print(ac.red .. ' Error:'..ac.reset.. 'Could not open log file.')
|
||||
return
|
||||
end
|
||||
local lines = {}
|
||||
for line in file:lines() do
|
||||
table.insert(lines, line)
|
||||
end
|
||||
file:close()
|
||||
local found = false
|
||||
for i = 1, #lines do
|
||||
if lines[i]:match(name_clean) then
|
||||
nam = user_input
|
||||
local blocks = {
|
||||
[4] = lines[i + 2]:match("Block 4: (.+)"),
|
||||
[5] = lines[i + 3]:match("Block 5: (.+)"),
|
||||
[6] = lines[i + 4]:match("Block 6: (.+)"),
|
||||
[7] = lines[i + 5]:match("Block 7: (.+)")
|
||||
}
|
||||
local em4102_id = lines[i + 6]:match("EM4102 ID: (.+)")
|
||||
print(dash)
|
||||
print(' I found the data under the name: '..ac.yellow ..nam.. ac.reset)
|
||||
for j = 4, 7 do
|
||||
print(string.format(" Block %d: %s%s%s", j, ac.yellow, blocks[j] or "N/A", ac.reset))
|
||||
end
|
||||
print(" EM4102 ID: " .. ac.green .. (em4102_id or "N/A") .. ac.reset)
|
||||
print(dash)
|
||||
local decimal_id, padded_hex_id = em4102_id, em4102_id
|
||||
handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3, nam)
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not found then
|
||||
retries = retries - 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
if retries == 0 then
|
||||
print(ac.yellow .. " Name not found after 3 attempts." .. ac.reset)
|
||||
end
|
||||
end
|
||||
print(dash)
|
||||
print(' Exiting script Lua...')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local getopt = require('getopt')
|
||||
local utils = require('utils')
|
||||
local ac = require('ansicolors')
|
||||
local os = require('os')
|
||||
local dash = string.rep('--', 32)
|
||||
local dir = os.getenv('HOME') .. '/.proxmark3/logs/'
|
||||
local logfile = (io.popen('dir /a-d /o-d /tw /b/s "' .. dir .. '" 2>nul:'):read("*a"):match("%C+"))
|
||||
local log_file_path = dir .. "Paxton_log.txt"
|
||||
local nam = ""
|
||||
local pm3 = require('pm3')
|
||||
p = pm3.pm3()
|
||||
local command = core.console
|
||||
command('clear')
|
||||
|
||||
author = ' Author: jareckib - 30.01.2025'
|
||||
tutorial = ' Based on Equipter tutorial - Downgrade Paxton to EM4102'
|
||||
version = ' version v1.20'
|
||||
desc = [[
|
||||
The script automates the copying of Paxton fobs read - write.
|
||||
It also allows manual input of data for blocks 4-7.
|
||||
The third option is reading data stored in the log file and create new fob.
|
||||
Additionally, the script calculates the ID for downgrading Paxton to EM4102.
|
||||
|
||||
]]
|
||||
usage = [[
|
||||
script run paxton_clone
|
||||
]]
|
||||
arguments = [[
|
||||
script run paxton_clone -h : this help
|
||||
]]
|
||||
|
||||
local debug = true
|
||||
|
||||
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
|
||||
|
||||
local function help()
|
||||
print()
|
||||
print(author)
|
||||
print(tutorial)
|
||||
print(version)
|
||||
print(desc)
|
||||
print(ac.cyan..' Usage'..ac.reset)
|
||||
print(usage)
|
||||
print(ac.cyan..' Arguments'..ac.reset)
|
||||
print(arguments)
|
||||
end
|
||||
|
||||
local function reset_log_file()
|
||||
local file = io.open(logfile, "w+")
|
||||
file:write("")
|
||||
file:close()
|
||||
end
|
||||
|
||||
local function read_log_file(logfile)
|
||||
local file = io.open(logfile, "r")
|
||||
if not file then
|
||||
error(" Could not open the file")
|
||||
end
|
||||
local content = file:read("*all")
|
||||
file:close()
|
||||
return content
|
||||
end
|
||||
|
||||
local function parse_blocks(result)
|
||||
local blocks = {}
|
||||
for line in result:gmatch("[^\r\n]+") do
|
||||
local block_num, block_data = line:match("%[%=%]%s+%d/0x0([4-7])%s+%|%s+([0-9A-F ]+)")
|
||||
if block_num and block_data then
|
||||
block_num = tonumber(block_num)
|
||||
block_data = block_data:gsub("%s+", "")
|
||||
blocks[block_num] = block_data
|
||||
end
|
||||
end
|
||||
return blocks
|
||||
end
|
||||
|
||||
local function hex_to_bin(hex_string)
|
||||
local bin_string = ""
|
||||
local hex_to_bin_map = {
|
||||
['0'] = "0000", ['1'] = "0001", ['2'] = "0010", ['3'] = "0011",
|
||||
['4'] = "0100", ['5'] = "0101", ['6'] = "0110", ['7'] = "0111",
|
||||
['8'] = "1000", ['9'] = "1001", ['A'] = "1010", ['B'] = "1011",
|
||||
['C'] = "1100", ['D'] = "1101", ['E'] = "1110", ['F'] = "1111"
|
||||
}
|
||||
for i = 1, #hex_string do
|
||||
bin_string = bin_string .. hex_to_bin_map[hex_string:sub(i, i)]
|
||||
end
|
||||
return bin_string
|
||||
end
|
||||
|
||||
local function remove_last_two_bits(binary_str)
|
||||
return binary_str:sub(1, #binary_str - 2)
|
||||
end
|
||||
|
||||
local function split_into_5bit_chunks(binary_str)
|
||||
local chunks = {}
|
||||
for i = 1, #binary_str, 5 do
|
||||
table.insert(chunks, binary_str:sub(i, i + 4))
|
||||
end
|
||||
return chunks
|
||||
end
|
||||
|
||||
local function remove_parity_bit(chunks)
|
||||
local no_parity_chunks = {}
|
||||
for _, chunk in ipairs(chunks) do
|
||||
if #chunk == 5 then
|
||||
table.insert(no_parity_chunks, chunk:sub(2))
|
||||
end
|
||||
end
|
||||
return no_parity_chunks
|
||||
end
|
||||
|
||||
local function convert_to_hex(chunks)
|
||||
local hex_values = {}
|
||||
for _, chunk in ipairs(chunks) do
|
||||
if #chunk > 0 then
|
||||
table.insert(hex_values, string.format("%X", tonumber(chunk, 2)))
|
||||
end
|
||||
end
|
||||
return hex_values
|
||||
end
|
||||
|
||||
local function convert_to_decimal(chunks)
|
||||
local decimal_values = {}
|
||||
for _, chunk in ipairs(chunks) do
|
||||
table.insert(decimal_values, tonumber(chunk, 2))
|
||||
end
|
||||
return decimal_values
|
||||
end
|
||||
|
||||
local function find_until_before_f(hex_values)
|
||||
local result = {}
|
||||
for _, value in ipairs(hex_values) do
|
||||
if value == 'F' then
|
||||
break
|
||||
end
|
||||
table.insert(result, value)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function process_block(block)
|
||||
local binary_str = hex_to_bin(block)
|
||||
binary_str = remove_last_two_bits(binary_str)
|
||||
local chunks = split_into_5bit_chunks(binary_str)
|
||||
local no_parity_chunks = remove_parity_bit(chunks)
|
||||
return no_parity_chunks
|
||||
end
|
||||
|
||||
local function calculate_id_net(blocks)
|
||||
local all_hex_values = {}
|
||||
for _, block in ipairs(blocks) do
|
||||
local hex_values = convert_to_hex(process_block(block))
|
||||
for _, hex in ipairs(hex_values) do
|
||||
table.insert(all_hex_values, hex)
|
||||
end
|
||||
end
|
||||
local selected_hex_values = find_until_before_f(all_hex_values)
|
||||
if #selected_hex_values == 0 then
|
||||
error(ac.red..' Error: '..ac.reset..'No valid data found in blocks 4 and 5')
|
||||
end
|
||||
local combined_hex = table.concat(selected_hex_values)
|
||||
if not combined_hex:match("^%x+$") then
|
||||
error(ac.red..' Error: '..ac.reset..'Invalid data in blocks 4 and 5')
|
||||
end
|
||||
local decimal_id = tonumber(combined_hex)
|
||||
local stripped_hex_id = string.format("%X", decimal_id)
|
||||
local padded_hex_id = string.format("%010X", decimal_id)
|
||||
return decimal_id, padded_hex_id
|
||||
end
|
||||
|
||||
local function calculate_id_switch(blocks)
|
||||
local all_decimal_values = {}
|
||||
for _, block in ipairs(blocks) do
|
||||
local decimal_values = convert_to_decimal(process_block(block))
|
||||
for _, dec in ipairs(decimal_values) do
|
||||
table.insert(all_decimal_values, dec)
|
||||
end
|
||||
end
|
||||
if #all_decimal_values < 15 then
|
||||
error(ac.red..' Error:'..ac.reset..' Not enough data after processing blocks 4, 5, 6, and 7')
|
||||
end
|
||||
local id_positions = {9, 11, 13, 15, 2, 4, 6, 8}
|
||||
local id_numbers = {}
|
||||
for _, pos in ipairs(id_positions) do
|
||||
table.insert(id_numbers, all_decimal_values[pos])
|
||||
end
|
||||
local decimal_id = tonumber(table.concat(id_numbers))
|
||||
local padded_hex_id = string.format("%010X", decimal_id)
|
||||
return decimal_id, padded_hex_id
|
||||
end
|
||||
|
||||
local function name_exists_in_log(name)
|
||||
local file = io.open(log_file_path, "r")
|
||||
if not file then
|
||||
return false
|
||||
end
|
||||
local pattern = "^Name:%s*" .. name .. "%s*$"
|
||||
for line in file:lines() do
|
||||
if line:match(pattern) then
|
||||
file:close()
|
||||
return true
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
return false
|
||||
end
|
||||
|
||||
local function log_result(blocks, em410_id, name)
|
||||
local log_file = io.open(log_file_path, "a")
|
||||
if log_file then
|
||||
log_file:write("Name: " .. name .. "\n")
|
||||
log_file:write("Date: ", os.date("%Y-%m-%d %H:%M:%S"), "\n")
|
||||
for i = 4, 7 do
|
||||
log_file:write(string.format("Block %d: %s\n", i, blocks[i] or "nil"))
|
||||
end
|
||||
log_file:write(string.format('EM4102 ID: %s\n', em410_id or "nil"))
|
||||
log_file:write('--------------------------\n')
|
||||
log_file:close()
|
||||
print(' Log saved as: pm3/.proxmark3/logs/' ..ac.yellow..' Paxton_log.txt'..ac.reset)
|
||||
else
|
||||
print(" Failed to open log file for writing.")
|
||||
end
|
||||
end
|
||||
|
||||
local function verify_written_data(original_blocks)
|
||||
p:console('lf hitag read --ht2 -k BDF5E846')
|
||||
local result = read_log_file(logfile)
|
||||
local verified_blocks = parse_blocks(result)
|
||||
local success = true
|
||||
for i = 4, 7 do
|
||||
if original_blocks[i] ~= verified_blocks[i] then
|
||||
print(' Verification failed.. Block '..ac.green.. i ..ac.reset.. ' inconsistent.')
|
||||
success = false
|
||||
end
|
||||
end
|
||||
|
||||
if success then
|
||||
print(ac.green..' Verification successful. Data was written correctly.' .. ac.reset)
|
||||
else
|
||||
print(ac.yellow.. ' Adjust the position of the Paxton fob on the coil.' .. ac.reset)
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3)
|
||||
while true do
|
||||
io.write(" Create Paxton choose " .. ac.cyan .. "1" .. ac.reset .. " or EM4102 choose " .. ac.cyan .. "2 " .. ac.reset)
|
||||
local choice = io.read()
|
||||
if choice == "1" then
|
||||
io.write(" Place the" .. ac.cyan .. " Paxton " .. ac.reset .. "Fob on the coil to write.." .. ac.green .. " ENTER " .. ac.reset .. "to continue..")
|
||||
io.read()
|
||||
print(dash)
|
||||
p:console("lf hitag wrbl --ht2 -p 4 -d " .. blocks[4] .. " -k BDF5E846")
|
||||
p:console("lf hitag wrbl --ht2 -p 5 -d " .. blocks[5] .. " -k BDF5E846")
|
||||
p:console("lf hitag wrbl --ht2 -p 6 -d " .. blocks[6] .. " -k BDF5E846")
|
||||
p:console("lf hitag wrbl --ht2 -p 7 -d " .. blocks[7] .. " -k BDF5E846")
|
||||
reset_log_file()
|
||||
--timer(5)
|
||||
verify_written_data(blocks)
|
||||
elseif choice == "2" then
|
||||
io.write(" Place the" .. ac.cyan .. " T5577 " .. ac.reset .. "tag on the coil and press" .. ac.green .. " ENTER " .. ac.reset .. "to continue..")
|
||||
io.read()
|
||||
p:console("lf em 410x clone --id " .. padded_hex_id)
|
||||
print(' Cloned EM4102 to T5577 with ID ' ..ac.green.. padded_hex_id ..ac.reset)
|
||||
else
|
||||
print(ac.yellow .. " Invalid choice." .. ac.reset .. " Please enter " .. ac.cyan .. "1" .. ac.reset .. " or " .. ac.cyan .. "2" .. ac.reset)
|
||||
goto ask_again
|
||||
end
|
||||
while true do
|
||||
print(dash)
|
||||
io.write(" Make next RFID Fob"..ac.cyan.." (y/n) "..ac.reset)
|
||||
local another = io.read()
|
||||
if another:lower() == "n" then
|
||||
if was_option_3 then
|
||||
print(" No writing to Paxton_log.txt - Name: " ..ac.green.. nam .. ac.reset.. " exist")
|
||||
return
|
||||
end
|
||||
print()
|
||||
print(ac.green .. " Saving Paxton_log file..." .. ac.reset)
|
||||
while true do
|
||||
io.write(" Enter a name for database (cannot be empty/duplicate): "..ac.yellow)
|
||||
name = io.read()
|
||||
io.write(ac.reset..'')
|
||||
if name == nil or name:match("^%s*$") then
|
||||
print(ac.red .. ' ERROR:'..ac.reset..' Name cannot be empty.')
|
||||
else
|
||||
if name_exists_in_log(name) then
|
||||
print(ac.yellow .. ' Name exists!!! '..ac.reset.. 'Please choose a different name.')
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
log_result(blocks, padded_hex_id, name)
|
||||
print(ac.green .. " Log saved successfully!" .. ac.reset)
|
||||
reset_log_file()
|
||||
return
|
||||
elseif another:lower() == "y" then
|
||||
goto ask_again
|
||||
else
|
||||
print(ac.yellow.." Invalid response."..ac.reset.." Please enter"..ac.cyan.." y"..ac.reset.." or"..ac.cyan.." n"..ac.reset)
|
||||
end
|
||||
end
|
||||
::ask_again::
|
||||
end
|
||||
end
|
||||
|
||||
local function is_valid_hex(input)
|
||||
return #input == 8 and input:match("^[0-9A-Fa-f]+$")
|
||||
end
|
||||
|
||||
local function main(args)
|
||||
while true do
|
||||
for o, a in getopt.getopt(args, 'h') do
|
||||
if o == 'h' then return help() end
|
||||
end
|
||||
command('clear')
|
||||
print(dash)
|
||||
print(ac.green .. ' Select option: ' .. ac.reset)
|
||||
print(ac.cyan .. ' 1' .. ac.reset .. ' - Read Paxton blocks 4-7 to make a copy')
|
||||
print(ac.cyan .. ' 2' .. ac.reset .. ' - Manually input data for Paxton blocks 4-7')
|
||||
print(ac.cyan .. " 3" .. ac.reset .. " - Search in Paxton_log by name and use the data")
|
||||
print(dash)
|
||||
while true do
|
||||
io.write(' Your choice '..ac.cyan..'(1/2/3): ' .. ac.reset)
|
||||
input_option = io.read()
|
||||
if input_option == "1" or input_option == "2" or input_option == "3" then
|
||||
break
|
||||
else
|
||||
print(ac.yellow .. ' Invalid choice.' .. ac.reset .. ' Please enter ' .. ac.cyan .. '1' .. ac.reset .. ' or ' .. ac.cyan .. '2' .. ac.reset..' or'..ac.cyan..' 3'..ac.reset)
|
||||
end
|
||||
end
|
||||
local was_option_3 = false
|
||||
if input_option == "1" then
|
||||
local show_place_message = true
|
||||
while true do
|
||||
if show_place_message then
|
||||
io.write(' Place the' .. ac.cyan .. ' Paxton' .. ac.reset .. ' Fob on the coil to read..' .. ac.green .. 'ENTER' .. ac.reset .. ' to continue..')
|
||||
end
|
||||
io.read()
|
||||
print(dash)
|
||||
p:console('lf hitag read --ht2 -k BDF5E846')
|
||||
if not logfile then
|
||||
error(" No files in this directory")
|
||||
end
|
||||
local result = read_log_file(logfile)
|
||||
local blocks = parse_blocks(result)
|
||||
local empty_block = false
|
||||
for i = 4, 7 do
|
||||
if not blocks[i] then
|
||||
empty_block = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if empty_block then
|
||||
io.write(ac.yellow .. ' Adjust the Fob position on the coil.' .. ac.reset .. ' Press' .. ac.green .. ' ENTER' .. ac.reset .. ' to continue..')
|
||||
show_place_message = false
|
||||
else
|
||||
print(' Readed blocks:')
|
||||
print()
|
||||
for i = 4, 7 do
|
||||
if blocks[i] then
|
||||
print(string.format(" Block %d: %s%s%s", i, ac.yellow, blocks[i], ac.reset))
|
||||
end
|
||||
end
|
||||
local decimal_id, padded_hex_id
|
||||
if blocks[5] and (blocks[5]:sub(4, 4) == 'F' or blocks[5]:sub(4, 4) == 'f') then
|
||||
print(dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Net2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_net({blocks[4], blocks[5]})
|
||||
else
|
||||
print(dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Switch2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_switch({blocks[4], blocks[5], blocks[6], blocks[7]})
|
||||
end
|
||||
print(string.format(" ID for EM4102 is: %s", ac.green .. padded_hex_id .. ac.reset))
|
||||
print(dash)
|
||||
handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3)
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif input_option == "2" then
|
||||
local blocks = {}
|
||||
for i = 4, 7 do
|
||||
while true do
|
||||
io.write(ac.reset..' Enter data for block ' .. i .. ': ' .. ac.yellow)
|
||||
local input = io.read()
|
||||
input = input:upper()
|
||||
if is_valid_hex(input) then
|
||||
blocks[i] = input
|
||||
break
|
||||
else
|
||||
print(ac.yellow .. ' Invalid input.' .. ac.reset .. ' Each block must be 4 bytes (8 hex characters).')
|
||||
end
|
||||
end
|
||||
end
|
||||
local decimal_id, padded_hex_id
|
||||
if blocks[5] and (blocks[5]:sub(4, 4) == 'F' or blocks[5]:sub(4, 4) == 'f') then
|
||||
print(ac.reset.. dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Net2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_net({blocks[4], blocks[5]})
|
||||
else
|
||||
print(ac.reset.. dash)
|
||||
print(' Identified Paxton ' .. ac.cyan .. 'Switch2' .. ac.reset)
|
||||
decimal_id, padded_hex_id = calculate_id_switch({blocks[4], blocks[5], blocks[6], blocks[7]})
|
||||
end
|
||||
print(dash)
|
||||
print(string.format(" ID for EM4102 is: %s", ac.green .. padded_hex_id .. ac.reset))
|
||||
print(dash)
|
||||
if not padded_hex_id then
|
||||
print(ac.red..' ERROR: '..ac.reset.. 'Invalid block data provided')
|
||||
return
|
||||
end
|
||||
handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3)
|
||||
break
|
||||
elseif input_option == "3" then
|
||||
was_option_3 = true
|
||||
local retries = 3
|
||||
while retries > 0 do
|
||||
io.write(' Enter the name to search ('..retries..' attempts) : '..ac.yellow)
|
||||
local user_input = io.read()
|
||||
io.write(ac.reset..'')
|
||||
if user_input == nil or user_input:match("^%s*$") then
|
||||
print(ac.yellow..' Error: '..ac.reset.. 'Empty name !!!')
|
||||
end
|
||||
local name_clean = "^Name:%s*" .. user_input:gsub("%s", "%%s") .. "%s*$"
|
||||
local file = io.open(log_file_path, "r")
|
||||
if not file then
|
||||
print(ac.red .. ' Error:'..ac.reset.. 'Could not open log file.')
|
||||
return
|
||||
end
|
||||
local lines = {}
|
||||
for line in file:lines() do
|
||||
table.insert(lines, line)
|
||||
end
|
||||
file:close()
|
||||
local found = false
|
||||
for i = 1, #lines do
|
||||
if lines[i]:match(name_clean) then
|
||||
nam = user_input
|
||||
local blocks = {
|
||||
[4] = lines[i + 2]:match("Block 4: (.+)"),
|
||||
[5] = lines[i + 3]:match("Block 5: (.+)"),
|
||||
[6] = lines[i + 4]:match("Block 6: (.+)"),
|
||||
[7] = lines[i + 5]:match("Block 7: (.+)")
|
||||
}
|
||||
local em4102_id = lines[i + 6]:match("EM4102 ID: (.+)")
|
||||
print(dash)
|
||||
print(' I found the data under the name: '..ac.yellow ..nam.. ac.reset)
|
||||
for j = 4, 7 do
|
||||
print(string.format(" Block %d: %s%s%s", j, ac.yellow, blocks[j] or "N/A", ac.reset))
|
||||
end
|
||||
print(" EM4102 ID: " .. ac.green .. (em4102_id or "N/A") .. ac.reset)
|
||||
print(dash)
|
||||
local decimal_id, padded_hex_id = em4102_id, em4102_id
|
||||
handle_cloning(decimal_id, padded_hex_id, blocks, was_option_3, nam)
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not found then
|
||||
retries = retries - 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
if retries == 0 then
|
||||
print(ac.yellow .. " Name not found after 3 attempts." .. ac.reset)
|
||||
end
|
||||
end
|
||||
print(dash)
|
||||
print(' Exiting script Lua...')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
main(args)
|
||||
+141
-41
@@ -28,6 +28,7 @@ Full license text: <https://www.gnu.org/licenses/gpl-3.0.html>
|
||||
|
||||
import subprocess
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
@@ -100,24 +101,33 @@ def send_proxmark_command(command):
|
||||
|
||||
def authenticate_and_menu():
|
||||
|
||||
com_mode = input("Enter communication mode (PLAIN, MAC, ENCRYPT) (Default: PLAIN): ").strip() or "plain"
|
||||
key_type = input("Enter key type (DES, 2TDEA, 3TDEA, AES): ").strip()
|
||||
key = input("Enter 8, 16, 24 or 32-byte hex key (no spaces): ").strip()
|
||||
key = input("Enter 8, 16, or 24-byte hex key (no spaces): ").strip()
|
||||
|
||||
# Authenticate
|
||||
auth_command = f"hf mfdes auth -t {key_type} -k {key}"
|
||||
auth_command = f"hf mfdes auth -t {key_type} -k {key} -m {com_mode}"
|
||||
auth_response = send_proxmark_command(auth_command)
|
||||
print(auth_response)
|
||||
# print("DEBUG: Raw Proxmark response:\n", repr(auth_response))
|
||||
|
||||
# Check for Proxmark failure messages
|
||||
if "error" in auth_response.lower() or "must have" in auth_response.lower():
|
||||
print("❌ Authentication failed. Check your connection, key, and key type.")
|
||||
print("❌ Authentication failed. Check your connection, mode, key type, and key.")
|
||||
return
|
||||
|
||||
while True:
|
||||
|
||||
# Get AIDs
|
||||
aids_command = f"hf mfdes getaids -n 0 -t {key_type} -k {key}"
|
||||
aids_command = f"hf mfdes getaids -n 0 -t {key_type} -k {key} -m {com_mode}"
|
||||
aids_response = send_proxmark_command(aids_command)
|
||||
|
||||
# Check for communication mode errors
|
||||
com_mode_error_match = re.search(r"Wrong communication mode", aids_response)
|
||||
crc_error_match = re.search(r"CRC32 error", aids_response)
|
||||
if com_mode_error_match or crc_error_match:
|
||||
print("❌ Incorrect communication mode.\n")
|
||||
return
|
||||
|
||||
print(aids_response)
|
||||
|
||||
# Regex to match valid 6-character hex AIDs
|
||||
@@ -144,7 +154,8 @@ def authenticate_and_menu():
|
||||
print("3. Delete an AID")
|
||||
print("4. Format PICC")
|
||||
print("5. Show free memory")
|
||||
print("6. Exit")
|
||||
print("6. Change keys")
|
||||
print("7. Exit")
|
||||
|
||||
choice = input("Enter your choice: ").strip()
|
||||
|
||||
@@ -157,32 +168,39 @@ def authenticate_and_menu():
|
||||
selected_aid = aids[selected_index]
|
||||
print(f"\nSelecting AID: {selected_aid}")
|
||||
|
||||
select_command = f"hf mfdes selectapp --aid {selected_aid} -t {key_type} -k {key}"
|
||||
select_command = f"hf mfdes selectapp --aid {selected_aid} -t {key_type} -k {key} -m {com_mode}"
|
||||
select_response = send_proxmark_command(select_command)
|
||||
print(select_response)
|
||||
|
||||
# Retrieve AID key 0
|
||||
aid_key_type = input(f"Enter AID encryption algorithm (DES, 2TDEA, 3TDEA, AES) (Default: {key_type.upper()}): ").strip() or key_type
|
||||
aid_key = input(f"Enter AID key (Default: {key}): ").strip() or key
|
||||
|
||||
# Show file menu
|
||||
aid_file_menu(selected_aid, key_type, key)
|
||||
aid_file_menu(selected_aid, key_type, key, com_mode, aid_key_type, aid_key)
|
||||
|
||||
elif choice == "2":
|
||||
create_aid(key_type, key)
|
||||
create_aid(key_type, key, com_mode)
|
||||
|
||||
elif choice == "3":
|
||||
delete_aid(key_type, key)
|
||||
delete_aid(key_type, key, com_mode)
|
||||
|
||||
elif choice == "4":
|
||||
format_picc(key_type, key)
|
||||
format_picc(key_type, key, com_mode)
|
||||
|
||||
elif choice == "5":
|
||||
free_memory(key_type, key)
|
||||
free_memory(key_type, key, com_mode)
|
||||
|
||||
elif choice == "6":
|
||||
change_key(key_type, key, com_mode)
|
||||
|
||||
elif choice == "7":
|
||||
print("Exiting...")
|
||||
break
|
||||
else:
|
||||
print("Invalid choice, please try again.")
|
||||
|
||||
def aid_file_menu(selected_aid, key_type, key):
|
||||
def aid_file_menu(selected_aid, key_type, key, com_mode, aid_key_type, aid_key):
|
||||
|
||||
while True:
|
||||
print(f"\n[ AID {selected_aid} is open ]")
|
||||
@@ -191,50 +209,52 @@ def aid_file_menu(selected_aid, key_type, key):
|
||||
print("2. Read a File")
|
||||
print("3. Create a File")
|
||||
print("4. Write to a File")
|
||||
print("5. Delete a File")
|
||||
print("6. Exit")
|
||||
print("5. Edit File Restrictions")
|
||||
print("6. Delete a File")
|
||||
print("7. Back")
|
||||
|
||||
choice = input("Enter your choice: ").strip()
|
||||
|
||||
if choice == "1":
|
||||
list_files(selected_aid, key_type, key)
|
||||
list_files(selected_aid, key_type, key, com_mode, aid_key_type, aid_key)
|
||||
elif choice == "2":
|
||||
read_file(selected_aid, key_type, key)
|
||||
read_file(selected_aid, key_type, key, com_mode, aid_key_type, aid_key)
|
||||
elif choice == "3":
|
||||
create_file(selected_aid, key_type, key)
|
||||
create_file(selected_aid, key_type, key, com_mode, aid_key_type, aid_key)
|
||||
elif choice == "4":
|
||||
write_to_file(selected_aid, key_type, key)
|
||||
write_to_file(selected_aid, key_type, key, com_mode, aid_key_type, aid_key)
|
||||
elif choice == "5":
|
||||
delete_file(selected_aid, key_type, key)
|
||||
edit_file_restriction(selected_aid, key_type, key, com_mode, aid_key_type, aid_key)
|
||||
elif choice == "6":
|
||||
delete_file(selected_aid, key_type, key, com_mode, aid_key_type, aid_key)
|
||||
elif choice == "7":
|
||||
print("Returning to AID selection...")
|
||||
break
|
||||
else:
|
||||
print("Invalid choice, please try again.")
|
||||
|
||||
def create_aid(key_type, key):
|
||||
def create_aid(key_type, key, com_mode):
|
||||
|
||||
aid = input("Enter new AID (6 hex characters, e.g., 112233): ").strip()
|
||||
iso_fid = input("Enter ISO File ID (4 hex characters, e.g., 1234): ").strip()
|
||||
dstalgo = input("Enter encryption algorithm (DES, 2TDEA, 3TDEA, AES): ").strip().upper()
|
||||
|
||||
create_command = f"hf mfdes createapp -n 0 --aid {aid} --fid {iso_fid} --dstalgo {dstalgo} -t {key_type} -k {key} -a"
|
||||
dstalgo = input(f"Enter encryption algorithm (DES, 2TDEA, 3TDEA, AES) (Default: {key_type.upper()}): ").strip() or key_type
|
||||
create_command = f"hf mfdes createapp -n 0 --aid {aid} --fid {iso_fid} --dstalgo {dstalgo} -t {key_type} -k {key} -m {com_mode} -a"
|
||||
response = send_proxmark_command(create_command)
|
||||
print(response)
|
||||
|
||||
def delete_aid(key_type, key):
|
||||
def delete_aid(key_type, key, com_mode):
|
||||
|
||||
aid = input("Enter AID to delete (6 hex characters): ").strip()
|
||||
delete_command = f"hf mfdes deleteapp --aid {aid} -n 0 -t {key_type} -k {key}"
|
||||
delete_command = f"hf mfdes deleteapp --aid {aid} -n 0 -t {key_type} -k {key} -m {com_mode}"
|
||||
response = send_proxmark_command(delete_command)
|
||||
print(response)
|
||||
|
||||
def format_picc(key_type, key):
|
||||
def format_picc(key_type, key, com_mode):
|
||||
|
||||
confirm = input("Are you sure you want to format the PICC? This will erase all data. (y/n): ").strip().lower()
|
||||
|
||||
if confirm == "y":
|
||||
format_command = f"hf mfdes formatpicc -t {key_type} -k {key} -v"
|
||||
format_command = f"hf mfdes formatpicc -t {key_type} -k {key} -m {com_mode} -v"
|
||||
response = send_proxmark_command(format_command)
|
||||
print(response)
|
||||
elif confirm == "n":
|
||||
@@ -242,9 +262,9 @@ def format_picc(key_type, key):
|
||||
else:
|
||||
print("Invalid input. Please enter 'y' or 'n'.")
|
||||
|
||||
def free_memory(key_type, key):
|
||||
def free_memory(key_type, key, com_mode):
|
||||
|
||||
memory_command = f"hf mfdes freemem -t {key_type} -k {key}"
|
||||
memory_command = f"hf mfdes freemem -t {key_type} -k {key} -m {com_mode}"
|
||||
response = send_proxmark_command(memory_command)
|
||||
|
||||
for line in response.splitlines():
|
||||
@@ -254,10 +274,54 @@ def free_memory(key_type, key):
|
||||
|
||||
print("❌ Unable to retrieve free memory information.")
|
||||
|
||||
def list_files(aid, key_type, key):
|
||||
def change_key(key_type, key, com_mode):
|
||||
print("\nChange Key - Choose Target:")
|
||||
print("1. PICC (Card Master Key)")
|
||||
print("2. Application Key")
|
||||
|
||||
target = input("Change key for (1/2)? (Default: 1): ").strip() or "1"
|
||||
aid = ""
|
||||
|
||||
if target == "2":
|
||||
aid = input("Enter 6-digit AID (e.g., 010203): ").strip()
|
||||
|
||||
print("\n!! Verify and securely store the new key !!")
|
||||
print("Key length guide:")
|
||||
print(" DES : 8 bytes (16 hex chars)")
|
||||
print(" 2TDEA : 16 bytes (32 hex chars)")
|
||||
print(" 3TDEA : 24 bytes (48 hex chars)")
|
||||
print(" AES : 16 bytes (32 hex chars)")
|
||||
|
||||
newalgo = input(f"Enter new key encryption algorithm (DES, 2TDEA, 3TDEA, AES) "
|
||||
f"(Default: {key_type.upper()}): ").strip() or key_type
|
||||
newkey = input(f"Enter new 8, 16, or 24-byte hex key (no spaces) (Default: {key}): ").strip() or key
|
||||
|
||||
confirm = input("Are you sure you want to change the key? (Key 0) (y or n): ").strip().lower()
|
||||
|
||||
if confirm == "y":
|
||||
changekey_command = f"hf mfdes changekey -n 0 -t {key_type} -k {key} -m {com_mode} " \
|
||||
f"--newalgo {newalgo} --newkey {newkey} --newver 00 -v"
|
||||
if aid:
|
||||
app_key_type = input(f"Enter original application encryption algorithm (DES, 2TDEA, 3TDEA, AES) "
|
||||
f"(Default: DES): ").strip() or "DES"
|
||||
app_key = input(f"Enter original application key "
|
||||
f"(Default: 0000000000000000): ").strip() or "0000000000000000"
|
||||
changekey_command = f"hf mfdes changekey -n 0 -t {app_key_type} -k {app_key} -m {com_mode} " \
|
||||
f"--newalgo {newalgo} --newkey {newkey} --newver 00 --aid {aid} -v"
|
||||
|
||||
response = send_proxmark_command(changekey_command)
|
||||
print(response)
|
||||
print("\nReauthenticate with the master key.")
|
||||
sys.exit()
|
||||
|
||||
elif confirm == "n":
|
||||
print("Cancelled.")
|
||||
else:
|
||||
print("Invalid input. Please enter 'y' or 'n'.")
|
||||
|
||||
def list_files(aid, key_type, key, com_mode, aid_key_type, aid_key):
|
||||
print("\nFetching file list...")
|
||||
command = f"hf mfdes getfileids --aid {aid} -t {key_type} -k {key}"
|
||||
command = f"hf mfdes getfileids --aid {aid} -t {aid_key_type} -k {aid_key} -m {com_mode}"
|
||||
response = send_proxmark_command(command)
|
||||
|
||||
# Extract file IDs by looking for "File ID:" regex
|
||||
@@ -276,7 +340,7 @@ def list_files(aid, key_type, key):
|
||||
print("No files found in this AID.")
|
||||
return []
|
||||
|
||||
def read_file(aid, key_type, key):
|
||||
def read_file(aid, key_type, key, com_mode, aid_key_type, aid_key):
|
||||
|
||||
file_id = input("Enter file ID to read: ").strip()
|
||||
|
||||
@@ -288,7 +352,8 @@ def read_file(aid, key_type, key):
|
||||
length_input = input("Enter length to read (e.g., 16 for 16 bytes, 64 for 64 bytes, default full read): ").strip() or "0"
|
||||
length_hex = format(int(length_input), '06X') # Convert to 3-byte hex
|
||||
|
||||
read_command = f"hf mfdes read --aid {aid} --fid {file_id} -t {key_type} -k {key} --offset {offset_hex} --length {length_hex}"
|
||||
read_command = f"hf mfdes read --aid {aid} --fid {file_id} -t {aid_key_type} -k {aid_key} " \
|
||||
f"--offset {offset_hex} --length {length_hex} -m {com_mode}"
|
||||
response = send_proxmark_command(read_command)
|
||||
|
||||
# Extract and display file content
|
||||
@@ -299,7 +364,7 @@ def read_file(aid, key_type, key):
|
||||
|
||||
return response
|
||||
|
||||
def create_file(aid, key_type, key):
|
||||
def create_file(aid, key_type, key, com_mode, aid_key_type, aid_key):
|
||||
|
||||
# Prompt for file ID in hex format
|
||||
file_id = input("Enter file ID (2 hex characters, e.g., 01, 02): ").strip()
|
||||
@@ -332,16 +397,17 @@ def create_file(aid, key_type, key):
|
||||
print(f"Invalid file size: {e}")
|
||||
return
|
||||
|
||||
create_command = f"hf mfdes createfile --aid {aid} --fid {file_id} --isofid {iso_file_id} --size {file_size_hex} -t {key_type} -k {key}"
|
||||
create_command = f"hf mfdes createfile --aid {aid} --fid {file_id} --isofid {iso_file_id} " \
|
||||
f"--size {file_size_hex} -t {aid_key_type} -k {aid_key} -m {com_mode}"
|
||||
response = send_proxmark_command(create_command)
|
||||
print(response)
|
||||
|
||||
def write_to_file(aid, key_type, key):
|
||||
def write_to_file(aid, key_type, key, com_mode, aid_key_type, aid_key):
|
||||
|
||||
file_id = input("Enter file ID to write to: ").strip()
|
||||
|
||||
# Get file size
|
||||
file_size_command = f"hf mfdes getfilesettings --aid {aid} --fid {file_id} -t {key_type} -k {key}"
|
||||
file_size_command = f"hf mfdes getfilesettings --aid {aid} --fid {file_id} -t {aid_key_type} -k {aid_key} -m {com_mode}"
|
||||
response = send_proxmark_command(file_size_command)
|
||||
|
||||
# Extract the file size from the response
|
||||
@@ -376,15 +442,49 @@ def write_to_file(aid, key_type, key):
|
||||
else:
|
||||
print("❌ Invalid choice. Please choose 1 for text or 2 for hex.")
|
||||
|
||||
write_command = f"hf mfdes write --aid {aid} --fid {file_id} -t {key_type} -k {key} -d {write_data_hex}"
|
||||
write_command = f"hf mfdes write --aid {aid} --fid {file_id} -t {aid_key_type} -k {aid_key} -d {write_data_hex} -m {com_mode}"
|
||||
response = send_proxmark_command(write_command)
|
||||
print(response)
|
||||
|
||||
def delete_file(aid, key_type, key):
|
||||
def edit_file_restriction(aid, key_type, key, com_mode, aid_key_type, aid_key):
|
||||
while True:
|
||||
print("\nNOTE: This only works if you have changed the default keys.")
|
||||
print("The Proxmark3 and other tools will automatically attempt to read files using DESFire default keys.")
|
||||
print("\nWould you like to apply or remove a key from the file?")
|
||||
print("1. Apply key 0 (Requires authentication for access)")
|
||||
print("2. Remove key (Make file freely accessible)")
|
||||
print("3. Back")
|
||||
|
||||
choice = input("Enter your choice (1, 2, or 3): ").strip()
|
||||
|
||||
if choice == "3":
|
||||
print("Returning to the previous menu.")
|
||||
break
|
||||
|
||||
file_id = input("Enter file ID to update: ").strip()
|
||||
|
||||
if choice == "1":
|
||||
edit_file_command = f"hf mfdes chfilesettings --rawrights 0000 --aid {aid} --fid {file_id} -t {aid_key_type} -k {aid_key} -m {com_mode}"
|
||||
print("Applying key 0 for read, write, and change access. This ensures authentication is required to access the file.")
|
||||
|
||||
elif choice == "2":
|
||||
# Must use encrypt communications mode to remove restrictions
|
||||
edit_file_command = f"hf mfdes chfilesettings --rawrights EEEE --aid {aid} --fid {file_id} -t {aid_key_type} -k {aid_key} -m encrypt"
|
||||
print("Removing key restrictions. File will be freely accessible.")
|
||||
|
||||
else:
|
||||
print("❌ Invalid choice. Please enter 1, 2, or 3.")
|
||||
continue
|
||||
|
||||
response = send_proxmark_command(edit_file_command)
|
||||
print(response)
|
||||
break
|
||||
|
||||
def delete_file(aid, key_type, key, com_mode, aid_key_type, aid_key):
|
||||
|
||||
file_id = input("Enter file ID to delete: ").strip()
|
||||
|
||||
delete_command = f"hf mfdes deletefile --aid {aid} --fid {file_id} -t {key_type} -k {key}"
|
||||
delete_command = f"hf mfdes deletefile --aid {aid} --fid {file_id} -t {aid_key_type} -k {aid_key} -m {com_mode}"
|
||||
response = send_proxmark_command(delete_command)
|
||||
print(response)
|
||||
|
||||
|
||||
@@ -90,13 +90,14 @@ def lprint(s='', end='\n', flush=False, prompt="[" + color("=", fg="yellow") +
|
||||
- logfile (R)
|
||||
"""
|
||||
s = f"{prompt}" + f"\n{prompt}".join(s.split('\n'))
|
||||
print(s, end=end, flush=flush)
|
||||
safe_s = s.encode('utf-8', errors='ignore').decode('utf-8')
|
||||
print(safe_s, end=end, flush=flush)
|
||||
|
||||
if log is True:
|
||||
global logbuffer
|
||||
if logfile is not None:
|
||||
with open(logfile, 'a') as f:
|
||||
f.write(s + end)
|
||||
with open(logfile, 'a', encoding='utf-8') as f:
|
||||
f.write(safe_s + end)
|
||||
else:
|
||||
# buffering
|
||||
logbuffer += s + end
|
||||
|
||||
@@ -211,6 +211,37 @@ def Describe_Usage_2_1(Usage, ContractMediumEndDate, Certificate):
|
||||
print(' left... :', Usage.nom_bits_left())
|
||||
print(' [CER] Usage : {:04x}'.format(Certificate.nom(16)))
|
||||
|
||||
def Describe_Usage_2_2(Usage, ContractMediumEndDate, Certificate):
|
||||
EventDateStamp = Usage.nom(10)
|
||||
EventTimeStamp = Usage.nom(11)
|
||||
unk0 = Usage.nom_bits(8)
|
||||
EventCode_Nature = Usage.nom(5)
|
||||
EventCode_Type = Usage.nom(5)
|
||||
unk1 = Usage.nom_bits(11)
|
||||
EventGeoRouteId = Usage.nom(14)
|
||||
EventGeoRoute_Direction = Usage.nom(2)
|
||||
EventGeoVehicleId = Usage.nom(16)
|
||||
unk2 = Usage.nom_bits(4)
|
||||
EventValidityTimeFirstStamp = Usage.nom(11)
|
||||
unk3 = Usage.nom_bits(3)
|
||||
EventCountPassengers_mb = Usage.nom(4)
|
||||
|
||||
print(' DateStamp : {} ({})'.format(EventDateStamp, (datetime(1997, 1, 1) + timedelta(days = ContractMediumEndDate - EventDateStamp)).strftime('%Y-%m-%d')))
|
||||
print(' TimeStamp : {} ({:02d}:{:02d})'. format(EventTimeStamp, EventTimeStamp // 60, EventTimeStamp % 60))
|
||||
print(' unk0... :', unk0)
|
||||
print(' Code/Nature : 0x{:x} ({})'.format(EventCode_Nature, TYPE_EventCode_Nature.get(EventCode_Nature, '?')))
|
||||
print(' Code/Type : 0x{:x} ({})'.format(EventCode_Type, TYPE_EventCode_Type.get(EventCode_Type, '?')))
|
||||
print(' unk1... :', unk1)
|
||||
print(' GeoRouteId : {}'. format(EventGeoRouteId))
|
||||
print(' Direction : {} ({})'. format(EventGeoRoute_Direction, TYPE_EventGeoRoute_Direction.get(EventGeoRoute_Direction, '?')))
|
||||
print(' GeoVehicleId : {}'. format(EventGeoVehicleId))
|
||||
print(' unk2... :', unk2)
|
||||
print(' ValidityTimeFirstStamp: {} ({:02d}:{:02d})'. format(EventValidityTimeFirstStamp, EventValidityTimeFirstStamp // 60, EventValidityTimeFirstStamp % 60))
|
||||
print(' unk3... :', unk3)
|
||||
print(' Passengers(?) : {}'. format(EventCountPassengers_mb))
|
||||
print(' left... :', Usage.nom_bits_left())
|
||||
print(' [CER] Usage : {:04x}'.format(Certificate.nom(16)))
|
||||
|
||||
def Describe_Usage_3(Usage, ContractMediumEndDate, Certificate):
|
||||
EventDateStamp = Usage.nom(10)
|
||||
EventTimeStamp = Usage.nom(11)
|
||||
@@ -258,6 +289,7 @@ ISO_Countries = {
|
||||
|
||||
FRA_OrganizationalAuthority_Contract_Provider = {
|
||||
0x000: {
|
||||
1: InterticHelper('Valenciennes', 'Transvilles / Keolis', Describe_Usage_1_1),
|
||||
5: InterticHelper('Lille', 'Ilévia / Keolis', Describe_Usage_1_1),
|
||||
7: InterticHelper('Lens-Béthune', 'Tadao / Transdev', Describe_Usage_1_1),
|
||||
},
|
||||
@@ -289,7 +321,7 @@ FRA_OrganizationalAuthority_Contract_Provider = {
|
||||
0x502: {
|
||||
83: InterticHelper('Annecy', 'Sibra', Describe_Usage_2),
|
||||
84: InterticHelper('Bourg-en-Bresse', 'Rubis / Keolis'),
|
||||
10: InterticHelper('Clermont-Ferrand', 'T2C'),
|
||||
10: InterticHelper('Clermont-Ferrand', 'T2C', Describe_Usage_2_2),
|
||||
},
|
||||
0x907: {
|
||||
1: InterticHelper('Dijon', 'Divia / Keolis'),
|
||||
@@ -315,6 +347,9 @@ FRA_OrganizationalAuthority_Contract_Provider = {
|
||||
4: InterticHelper('Angers', 'Irigo / RATP', Describe_Usage_1_2),
|
||||
7: InterticHelper('Saint-Nazaire', 'Stran'),
|
||||
},
|
||||
0x920: {
|
||||
9: InterticHelper('Aix-en-Provence', 'Aixenbus / Keolis', Describe_Usage_2_1),
|
||||
},
|
||||
}
|
||||
|
||||
MAR_OrganizationalAuthority_Contract_Provider = {
|
||||
|
||||
@@ -36,7 +36,7 @@ DIR_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
if TOOLS_PATH is None:
|
||||
if os.path.basename(os.path.dirname(DIR_PATH)) == 'client':
|
||||
# dev setup
|
||||
DEV_TOOLS_PATH = os.path.normpath(os.path.join(DIR_PATH, "..", "..", "tools", "mfc", "card_only"))
|
||||
DEV_TOOLS_PATH = os.path.normpath(os.path.join(DIR_PATH, "..", "..", "tools"))
|
||||
if os.path.isdir(DEV_TOOLS_PATH):
|
||||
TOOLS_PATH = DEV_TOOLS_PATH
|
||||
|
||||
@@ -62,11 +62,11 @@ def find_tool(tool_name):
|
||||
str: The full path to the tool if found, otherwise None.
|
||||
"""
|
||||
if TOOLS_PATH is not None:
|
||||
tool = os.path.join(TOOLS_PATH, tool_name)
|
||||
if os.path.isfile(tool):
|
||||
return tool
|
||||
elif os.path.isfile(tool + ".exe"):
|
||||
return tool + ".exe"
|
||||
for root, _, files in os.walk(TOOLS_PATH):
|
||||
if tool_name in files:
|
||||
return os.path.join(root, tool_name)
|
||||
elif tool_name + ".exe" in files:
|
||||
return os.path.join(root, tool_name + ".exe")
|
||||
# if not found, search in the user PATH
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
env_tool = os.path.join(path, tool_name)
|
||||
|
||||
@@ -391,12 +391,20 @@
|
||||
"Description": "Key as a Service // FID 01: Standard Data",
|
||||
"Type": "pacs"
|
||||
},
|
||||
{
|
||||
"AID": "F51780",
|
||||
"Vendor": "ASSA ABLOY",
|
||||
"Country": "SE",
|
||||
"Name": "SMARTair",
|
||||
"Description": "SMARTair Credential",
|
||||
"Type": "pacs"
|
||||
},
|
||||
{
|
||||
"AID": "F51BC0",
|
||||
"Vendor": "STid Group",
|
||||
"Country": "FR",
|
||||
"Name": "CCT Card / DTA Tag / PCG Fob",
|
||||
"Description": "STid Easyline / Architect Access Credetials",
|
||||
"Description": "STid Easyline / Architect Access Credentials",
|
||||
"Type": "pacs"
|
||||
},
|
||||
{
|
||||
@@ -887,12 +895,20 @@
|
||||
"Description": "car2go - Member Card // Multi Functional Badge / Private Application #1",
|
||||
"Type": "carsharing"
|
||||
},
|
||||
{
|
||||
"AID": "000005",
|
||||
"Vendor": "Transports Metropolitans de Barcelona (TMB)",
|
||||
"Country": "ES",
|
||||
"Name": "T-mobilitat (BCN)",
|
||||
"Description": "BCN T-mobilitat",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "000001",
|
||||
"Vendor": "Invalid / Reserved",
|
||||
"Country": "",
|
||||
"Name": "Invalid / Reserved",
|
||||
"Description": "Used by ATL Breeze, MAD Tarjeta Transporte Publico, and YVR Compass",
|
||||
"Description": "Used by ATL Breeze, PHL FREEDOM, and YVR Compass",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
@@ -915,7 +931,7 @@
|
||||
"AID": "010000",
|
||||
"Vendor": "Consorcio Regional de Transportes Publicos Regulares de Madrid (CRTM)",
|
||||
"Country": "ES",
|
||||
"Name": "Tarjeta Transporte Publico (MAD) (Alternative Endian)",
|
||||
"Name": "Tarjeta Transporte Publico (MAD)",
|
||||
"Description": "MAD Public Transport Card",
|
||||
"Type": "transport"
|
||||
},
|
||||
@@ -1183,6 +1199,22 @@
|
||||
"Description": "DUB Leap Card // Transport for Ireland // FIDs: 01,1F: Backup Data; 02-0A: Standard Data",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "402301",
|
||||
"Vendor": "Ministry of Transport, Communications and Works of the Republic of Cyprus",
|
||||
"Country": "CY",
|
||||
"Name": "motion BUS CARD (ECN)",
|
||||
"Description": "ECN motion BUS CARD (App 1)",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "415431",
|
||||
"Vendor": "Athens Urban Transport Organization (OASA)",
|
||||
"Country": "GR",
|
||||
"Name": "ATH.ENA CARD (ATH)",
|
||||
"Description": "ATH ATH.ENA CARD",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "444D01",
|
||||
"Vendor": "Delhi Metro Rail Corporation Limited",
|
||||
@@ -1255,6 +1287,14 @@
|
||||
"Description": "FIDs: 00-07: Standard Data",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "502301",
|
||||
"Vendor": "Ministry of Transport, Communications and Works of the Republic of Cyprus",
|
||||
"Country": "CY",
|
||||
"Name": "motion BUS CARD (ECN)",
|
||||
"Description": "ECN motion BUS CARD (App 2)",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "534531",
|
||||
"Vendor": "Transport for New South Wales (TfNSW)",
|
||||
@@ -1287,6 +1327,14 @@
|
||||
"Description": "FIDs 01: Product Retailer; 02: Service Provider; 03: Special Event; 04: Stored Value; 05: General Event Log; 06: SV Reload Log; 0A: Environment; 0C: Card Holder",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "602301",
|
||||
"Vendor": "Ministry of Transport, Communications and Works of the Republic of Cyprus",
|
||||
"Country": "CY",
|
||||
"Name": "motion BUS CARD (ECN)",
|
||||
"Description": "ECN motion BUS CARD (App 3)",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "634000",
|
||||
"Vendor": "Doha Metro and Lusail Tram via Qatar Rail",
|
||||
@@ -1303,6 +1351,14 @@
|
||||
"Description": "Umo Mobility Card",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "7A007A",
|
||||
"Vendor": "Regional Transportation Commission of Southern Nevada (RTC) via Masabi Ltd",
|
||||
"Country": "US",
|
||||
"Name": "RTC TAP & GO (LAS)",
|
||||
"Description": "LAS TAP & GO; Masabi Justride Tap and Ride DESFire Smartcard",
|
||||
"Type": "transport"
|
||||
},
|
||||
{
|
||||
"AID": "784000",
|
||||
"Vendor": "Roads & Transport Authority (Government of Dubai)",
|
||||
|
||||
+201
-17
File diff suppressed because it is too large.
Load diff
@@ -576,10 +576,11 @@ static int CmdFlashMemSpiFFSView(const char *Cmd) {
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"-----------", CmdHelp, IfPm3Flash, "------------------- " _CYAN_("Operations") " -------------------"},
|
||||
{"copy", CmdFlashMemSpiFFSCopy, IfPm3Flash, "Copy a file to another (destructively) in SPIFFS file system"},
|
||||
{"check", CmdFlashMemSpiFFSCheck, IfPm3Flash, "Check/try to defrag faulty/fragmented file system"},
|
||||
{"dump", CmdFlashMemSpiFFSDump, IfPm3Flash, "Dump a file from SPIFFS file system"},
|
||||
{"info", CmdFlashMemSpiFFSInfo, IfPm3Flash, "Print file system info and usage statistics"},
|
||||
{"info", CmdFlashMemSpiFFSInfo, IfPm3Flash, "File system information and usage statistics"},
|
||||
{"mount", CmdFlashMemSpiFFSMount, IfPm3Flash, "Mount the SPIFFS file system if not already mounted"},
|
||||
{"remove", CmdFlashMemSpiFFSRemove, IfPm3Flash, "Remove a file from SPIFFS file system"},
|
||||
{"rename", CmdFlashMemSpiFFSRename, IfPm3Flash, "Rename/move a file in SPIFFS file system"},
|
||||
|
||||
+1
-1
@@ -600,7 +600,7 @@ static command_t CommandTable[] = {
|
||||
{"texkom", CmdHFTexkom, AlwaysAvailable, "{ Texkom RFIDs... }"},
|
||||
{"thinfilm", CmdHFThinfilm, AlwaysAvailable, "{ Thinfilm RFIDs... }"},
|
||||
{"topaz", CmdHFTopaz, AlwaysAvailable, "{ TOPAZ (NFC Type 1) RFIDs... }"},
|
||||
{"vas", CmdHFVAS, AlwaysAvailable, "{ Apple Value Added Service }"},
|
||||
{"vas", CmdHFVAS, AlwaysAvailable, "{ Apple Value Added Service... }"},
|
||||
#ifdef HAVE_GD
|
||||
{"waveshare", CmdHFWaveshare, AlwaysAvailable, "{ Waveshare NFC ePaper... }"},
|
||||
#endif
|
||||
|
||||
+848
-427
File diff suppressed because it is too large.
Load diff
+22
-5
@@ -20,7 +20,7 @@
|
||||
#define CMDHF14A_H__
|
||||
|
||||
#include "common.h"
|
||||
#include "pm3_cmd.h" //hf14a_config
|
||||
#include "pm3_cmd.h" //hf14a_config_t
|
||||
#include "mifare.h" // structs
|
||||
|
||||
// structure and database for uid -> tagtype lookups
|
||||
@@ -36,6 +36,16 @@ typedef struct {
|
||||
const char *hint;
|
||||
} hintAIDList_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t vendor_id;
|
||||
uint8_t product_type;
|
||||
uint8_t product_subtype;
|
||||
uint8_t major_product_version;
|
||||
uint8_t minor_product_version;
|
||||
uint8_t storage_size;
|
||||
uint8_t protocol_type;
|
||||
} version_hw_t;
|
||||
|
||||
typedef enum {
|
||||
MTNONE = 0,
|
||||
MTCLASSIC = 1,
|
||||
@@ -49,6 +59,9 @@ typedef enum {
|
||||
MTFUDAN = 256,
|
||||
MTISO18092 = 512,
|
||||
MT424 = 1024,
|
||||
MTULTRALIGHT_C = 2048,
|
||||
MTDUOX = 4096,
|
||||
MTNTAG = 8192,
|
||||
} nxp_mifare_type_t;
|
||||
|
||||
int CmdHF14A(const char *Cmd);
|
||||
@@ -59,10 +72,13 @@ 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 detect_nxp_card(uint8_t sak, uint16_t atqa, uint64_t select_status,
|
||||
uint8_t ats_hist_len, uint8_t *ats_hist,
|
||||
bool version_hw_available, version_hw_t *version_hw);
|
||||
|
||||
int hf14a_getconfig(hf14a_config_t *config);
|
||||
int hf14a_setconfig(hf14a_config_t *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);
|
||||
@@ -70,10 +86,11 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card);
|
||||
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);
|
||||
int SelectCard14443A_4(bool disconnect, bool verbose, iso14a_card_select_t *card);
|
||||
int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card_select_t *card, iso14a_polling_parameters_t *polling_parameters);
|
||||
|
||||
bool Get_apdu_in_framing(void);
|
||||
void Set_apdu_in_framing(bool v);
|
||||
int hf14a_getversion_data(iso14a_card_select_t *card, uint64_t select_status, version_hw_t *hw);
|
||||
|
||||
#endif
|
||||
@@ -1411,7 +1411,7 @@ static bool HF14B_ask_ct_reader(bool verbose) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HF14B_picopass_reader(bool verbose, bool info) {
|
||||
static bool HF14B_picopass_reader(bool verbose) {
|
||||
|
||||
iso14b_raw_cmd_t packet = {
|
||||
.flags = (ISO14B_CONNECT | ISO14B_SELECT_PICOPASS | ISO14B_DISCONNECT),
|
||||
@@ -1437,10 +1437,8 @@ bool HF14B_picopass_reader(bool verbose, bool info) {
|
||||
return false;
|
||||
}
|
||||
memcpy(card, resp.data.asBytes, sizeof(picopass_hdr_t));
|
||||
if (info) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, "iCLASS / Picopass CSN: " _GREEN_("%s"), sprint_hex(card->csn, sizeof(card->csn)));
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, "iCLASS / Picopass CSN: " _GREEN_("%s"), sprint_hex(card->csn, sizeof(card->csn)));
|
||||
free(card);
|
||||
return true;
|
||||
}
|
||||
@@ -3029,14 +3027,15 @@ int infoHF14B(bool verbose, bool do_aid_search) {
|
||||
|
||||
// try unknown 14b read commands (to be identified later)
|
||||
// could be read of calypso, CEPAS, moneo, or pico pass.
|
||||
if (verbose) PrintAndLogEx(FAILED, "no 14443-B tag found");
|
||||
if (verbose) {
|
||||
PrintAndLogEx(FAILED, "no 14443-B tag found");
|
||||
}
|
||||
return PM3_EOPABORTED;
|
||||
}
|
||||
|
||||
// get and print general info about all known 14b chips
|
||||
int readHF14B(bool loop, bool verbose, bool read_plot) {
|
||||
bool found = false;
|
||||
bool info = true;
|
||||
int res = PM3_SUCCESS;
|
||||
do {
|
||||
found = false;
|
||||
@@ -3052,7 +3051,7 @@ int readHF14B(bool loop, bool verbose, bool read_plot) {
|
||||
goto plot;
|
||||
|
||||
// Picopass
|
||||
found |= HF14B_picopass_reader(verbose, info);
|
||||
found |= HF14B_picopass_reader(verbose);
|
||||
if (found)
|
||||
goto plot;
|
||||
|
||||
|
||||
@@ -31,6 +31,5 @@ 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, bool read_plot);
|
||||
bool HF14B_picopass_reader(bool verbose, bool info);
|
||||
|
||||
#endif
|
||||
@@ -279,22 +279,22 @@ static int CmdHF15Help(const char *Cmd);
|
||||
static int nxp_15693_print_signature(uint8_t *uid, uint8_t *signature) {
|
||||
|
||||
int reason = 0;
|
||||
int index = originality_check_verify(uid, 8, signature, 32, PK_MFC);
|
||||
int index = originality_check_verify(uid, 8, signature, 32, PK_15);
|
||||
if (index >= 0) {
|
||||
reason = 1;
|
||||
} else {
|
||||
// try with sha256
|
||||
index = originality_check_verify_ex(uid, 8, signature, 32, PK_MFC, false, true);
|
||||
index = originality_check_verify_ex(uid, 8, signature, 32, PK_15, false, true);
|
||||
if (index >= 0) {
|
||||
reason = 2;
|
||||
} else {
|
||||
// try with reversed uid / signature
|
||||
index = originality_check_verify_ex(uid, 8, signature, 32, PK_MFC, true, false);
|
||||
index = originality_check_verify_ex(uid, 8, signature, 32, PK_15, true, false);
|
||||
if (index >= 0) {
|
||||
reason = 3;
|
||||
} else {
|
||||
// try with sha256 and reversed uid / signature
|
||||
index = originality_check_verify_ex(uid, 8, signature, 32, PK_MFC, true, true);
|
||||
index = originality_check_verify_ex(uid, 8, signature, 32, PK_15, true, true);
|
||||
if (index >= 0) {
|
||||
reason = 3;
|
||||
}
|
||||
|
||||
@@ -1888,7 +1888,8 @@ static int CmdHFCipurseDefault(const char *Cmd) {
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help."},
|
||||
{"info", CmdHFCipurseInfo, IfPm3Iso14443a, "Get info about CIPURSE tag"},
|
||||
{"-----------", CmdHelp, IfPm3Iso14443a, "------------------- " _CYAN_("Operations") " -------------------"},
|
||||
{"info", CmdHFCipurseInfo, IfPm3Iso14443a, "Tag information"},
|
||||
{"select", CmdHFCipurseSelect, IfPm3Iso14443a, "Select CIPURSE application or file"},
|
||||
{"auth", CmdHFCipurseAuth, IfPm3Iso14443a, "Authenticate CIPURSE tag"},
|
||||
{"read", CmdHFCipurseReadFile, IfPm3Iso14443a, "Read binary file"},
|
||||
|
||||
@@ -2449,8 +2449,9 @@ static int CmdHFeMRTDList(const char *Cmd) {
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"-----------", CmdHelp, IfPm3Iso14443, "------------------- " _CYAN_("Operations") " -------------------"},
|
||||
{"dump", CmdHFeMRTDDump, IfPm3Iso14443, "Dump eMRTD files to binary files"},
|
||||
{"info", CmdHFeMRTDInfo, AlwaysAvailable, "Display info about an eMRTD"},
|
||||
{"info", CmdHFeMRTDInfo, AlwaysAvailable, "Tag information"},
|
||||
{"list", CmdHFeMRTDList, AlwaysAvailable, "List ISO 14443A/7816 history"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -913,7 +913,8 @@ static int CmdHFFido2GetAssertion(const char *cmd) {
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help."},
|
||||
{"list", CmdHFFidoList, AlwaysAvailable, "List ISO 14443A history"},
|
||||
{"info", CmdHFFidoInfo, IfPm3Iso14443a, "Info about FIDO tag."},
|
||||
{"-----------", CmdHelp, IfPm3Iso14443a, "------------------- " _CYAN_("Operations") " -------------------"},
|
||||
{"info", CmdHFFidoInfo, IfPm3Iso14443a, "Tag information"},
|
||||
{"reg", CmdHFFidoRegister, IfPm3Iso14443a, "FIDO U2F Registration Message."},
|
||||
{"auth", CmdHFFidoAuthenticate, IfPm3Iso14443a, "FIDO U2F Authentication Message."},
|
||||
{"make", CmdHFFido2MakeCredential, IfPm3Iso14443a, "FIDO2 MakeCredential command."},
|
||||
|
||||
+974
-444
File diff suppressed because it is too large.
Load diff
@@ -358,7 +358,7 @@ end:
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"select", CmdHFKSX6924Select, IfPm3Iso14443a, "Select application, and leave field up"},
|
||||
{"info", CmdHFKSX6924Info, IfPm3Iso14443a, "Get info about a KS X 6924 (T-Money, Snapper+) transit card"},
|
||||
{"info", CmdHFKSX6924Info, IfPm3Iso14443a, "Tag information"},
|
||||
{"balance", CmdHFKSX6924Balance, IfPm3Iso14443a, "Get current purse balance"},
|
||||
{"init", CmdHFKSX6924Initialize, IfPm3Iso14443a, "Perform transaction initialization with Mpda"},
|
||||
{"prec", CmdHFKSX6924PRec, IfPm3Iso14443a, "Send proprietary get record command (CLA=90, INS=4C)"},
|
||||
|
||||
@@ -131,7 +131,7 @@ static int lto_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response, uint16
|
||||
SendCommandMIX(CMD_HF_ISO14443A_READER, arg0, arg1, 0, cmd, len);
|
||||
PacketResponseNG resp;
|
||||
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
|
||||
if (verbose) PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
+651
-69
File diff suppressed because it is too large.
Load diff
@@ -35,9 +35,13 @@ void printKeyTable(size_t sectorscnt, sector_t *e_sector);
|
||||
void printKeyTableEx(size_t sectorscnt, sector_t *e_sector, uint8_t start_sector);
|
||||
// void printKeyTableEx(size_t sectorscnt, sector_t *e_sector, uint8_t start_sector, bool singel_sector);
|
||||
|
||||
|
||||
bool mfc_value(const uint8_t *d, int32_t *val);
|
||||
void mf_print_sector_hdr(uint8_t sector);
|
||||
void mf_print_block_one(uint8_t blockno, uint8_t *d, bool verbose);
|
||||
|
||||
int mf_print_keys(uint16_t n, uint8_t *d);
|
||||
void mf_print_blocks(uint16_t n, uint8_t *d, bool verbose);
|
||||
|
||||
int mfc_ev1_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature_len);
|
||||
#endif
|
||||
+123
-76
@@ -89,15 +89,6 @@ typedef struct mfdes_data {
|
||||
uint8_t *data;
|
||||
} PACKED mfdes_data_t;
|
||||
|
||||
typedef struct mfdes_info_res {
|
||||
uint8_t isOK;
|
||||
uint8_t uid[7];
|
||||
uint8_t uidlen;
|
||||
uint8_t versionHW[7];
|
||||
uint8_t versionSW[7];
|
||||
uint8_t details[14];
|
||||
} PACKED mfdes_info_res_t;
|
||||
|
||||
typedef struct mfdes_value {
|
||||
uint8_t fileno; //01
|
||||
uint8_t value[16];
|
||||
@@ -136,21 +127,6 @@ typedef enum {
|
||||
MFDES_VALUE_FILE
|
||||
} MFDES_FILE_TYPE_T;
|
||||
|
||||
typedef enum {
|
||||
DESFIRE_UNKNOWN = 0,
|
||||
DESFIRE_MF3ICD40,
|
||||
DESFIRE_EV1,
|
||||
DESFIRE_EV2,
|
||||
DESFIRE_EV2_XL,
|
||||
DESFIRE_EV3,
|
||||
DESFIRE_LIGHT,
|
||||
PLUS_EV1,
|
||||
PLUS_EV2,
|
||||
NTAG413DNA,
|
||||
NTAG424,
|
||||
DUOX,
|
||||
} nxp_cardtype_t;
|
||||
|
||||
typedef enum {
|
||||
DESFIRE_UNKNOWN_PROD = 0,
|
||||
DESFIRE_PHYSICAL,
|
||||
@@ -332,7 +308,7 @@ static const char *getAidCommentStr(uint32_t aid) {
|
||||
return "";
|
||||
}
|
||||
|
||||
static nxp_cardtype_t getCardType(uint8_t type, uint8_t major, uint8_t minor) {
|
||||
nxp_cardtype_t getCardType(uint8_t type, uint8_t major, uint8_t minor) {
|
||||
|
||||
// DESFire MF3ICD40
|
||||
if (type == 0x01 && major == 0x00 && minor == 0x02)
|
||||
@@ -385,7 +361,7 @@ static nxp_cardtype_t getCardType(uint8_t type, uint8_t major, uint8_t minor) {
|
||||
if (type == 0x04 && major == 0x30 && minor == 0x00)
|
||||
return NTAG424;
|
||||
|
||||
return DESFIRE_UNKNOWN;
|
||||
return NXP_UNKNOWN;
|
||||
}
|
||||
|
||||
// ref: https://www.nxp.com/docs/en/application-note/AN12343.pdf p7
|
||||
@@ -423,7 +399,7 @@ static const char *getProductTypeStr(const uint8_t *versionhw) {
|
||||
return "UNKNOWN PROD";
|
||||
}
|
||||
|
||||
static int mfdes_get_info(mfdes_info_res_t *info) {
|
||||
int mfdes_get_info(mfdes_info_res_t *info) {
|
||||
|
||||
PacketResponseNG resp;
|
||||
SendCommandNG(CMD_HF_DESFIRE_INFO, NULL, 0);
|
||||
@@ -710,7 +686,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
if (cardtype == DESFIRE_UNKNOWN) {
|
||||
if (cardtype == NXP_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!");
|
||||
@@ -817,7 +793,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||
|
||||
if (aidbuflen > 2) {
|
||||
|
||||
uint8_t j = aidbuflen / 3;
|
||||
uint8_t j = (aidbuflen / 3);
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, "--- " _CYAN_("AID list") " ( " _YELLOW_("%u") " found )", j);
|
||||
|
||||
@@ -826,6 +802,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||
uint32_t aid = DesfireAIDByteToUint(&aidbuf[i]);
|
||||
PrintAndLogEx(SUCCESS, _YELLOW_("%06X") ", %s", aid, getAidCommentStr(aid));
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
}
|
||||
|
||||
DesfireFillPICCInfo(&dctx, &PICCInfo, true);
|
||||
@@ -1186,8 +1163,8 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
CLIParserInit(&ctx, "hf mfdes chk",
|
||||
"Checks keys with MIFARE DESFire card.",
|
||||
"hf mfdes chk --aid 123456 -k 000102030405060708090a0b0c0d0e0f -> check key on aid 0x123456\n"
|
||||
"hf mfdes chk -d mfdes_default_keys -> check keys against all existing aid on card\n"
|
||||
"hf mfdes chk -d mfdes_default_keys --aid 123456 -> check keys against aid 0x123456\n"
|
||||
"hf mfdes chk -f mfdes_default_keys -> check keys against all existing aid on card\n"
|
||||
"hf mfdes chk -f mfdes_default_keys --aid 123456 -> check keys against aid 0x123456\n"
|
||||
"hf mfdes chk --aid 123456 --pattern1b -j keys -> check all 1-byte keys pattern on aid 0x123456 and save found keys to `keys.json`\n"
|
||||
"hf mfdes chk --aid 123456 --pattern2b --startp2b FA00 -> check all 2-byte keys pattern on aid 0x123456. Start from key FA00FA00...FA00");
|
||||
|
||||
@@ -1195,7 +1172,7 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
arg_param_begin,
|
||||
arg_str0(NULL, "aid", "<hex>", "Use specific AID (3 hex bytes, big endian)"),
|
||||
arg_str0("k", "key", "<hex>", "Key for checking (HEX 16 bytes)"),
|
||||
arg_str0("d", "dict", "<fn>", "Dictionary file with keys"),
|
||||
arg_str0("f", "file", "<fn>", "Filename of dictionary"),
|
||||
arg_lit0(NULL, "pattern1b", "Check all 1-byte combinations of key (0000...0000, 0101...0101, 0202...0202, ...)"),
|
||||
arg_lit0(NULL, "pattern2b", "Check all 2-byte combinations of key (0000...0000, 0001...0001, 0002...0002, ...)"),
|
||||
arg_str0(NULL, "startp2b", "<pattern>", "Start key (2-byte HEX) for 2-byte search (use with `--pattern2b`)"),
|
||||
@@ -1208,12 +1185,12 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
bool APDULogging = arg_get_lit(ctx, 11);
|
||||
|
||||
int aidlength = 0;
|
||||
uint8_t aid[3] = {0};
|
||||
CLIGetHexWithReturn(ctx, 1, aid, &aidlength);
|
||||
|
||||
swap24(aid);
|
||||
|
||||
uint8_t vkey[16] = {0};
|
||||
int vkeylen = 0;
|
||||
CLIGetHexWithReturn(ctx, 2, vkey, &vkeylen);
|
||||
@@ -1292,17 +1269,26 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
int kdfInputLen = 0;
|
||||
CLIGetHexWithReturn(ctx, 10, kdfInput, &kdfInputLen);
|
||||
|
||||
bool APDULogging = arg_get_lit(ctx, 11);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
SetAPDULogging(APDULogging);
|
||||
|
||||
// 1-byte pattern search mode
|
||||
if (pattern1b) {
|
||||
for (uint32_t i = 0; i < 0x100; i++)
|
||||
|
||||
for (uint32_t i = 0; i < 0x100; i++) {
|
||||
memset(aeskeyList[i], i, 16);
|
||||
for (uint32_t i = 0; i < 0x100; i++)
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 0x100; i++) {
|
||||
memset(deskeyList[i], i, 8);
|
||||
for (uint32_t i = 0; i < 0x100; i++)
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < 0x100; i++) {
|
||||
memset(k3kkeyList[i], i, 24);
|
||||
}
|
||||
|
||||
aeskeyListLen = 0x100;
|
||||
deskeyListLen = 0x100;
|
||||
k3kkeyListLen = 0x100;
|
||||
@@ -1318,18 +1304,21 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
if (dict_filenamelen) {
|
||||
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &deskeyListLen, 0, &endFilePosition, true);
|
||||
if (res == PM3_SUCCESS && endFilePosition)
|
||||
if (res == PM3_SUCCESS && endFilePosition) {
|
||||
PrintAndLogEx(SUCCESS, "First part of des dictionary successfully loaded.");
|
||||
}
|
||||
|
||||
endFilePosition = 0;
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &aeskeyListLen, 0, &endFilePosition, true);
|
||||
if (res == PM3_SUCCESS && endFilePosition)
|
||||
if (res == PM3_SUCCESS && endFilePosition) {
|
||||
PrintAndLogEx(SUCCESS, "First part of aes dictionary successfully loaded.");
|
||||
}
|
||||
|
||||
endFilePosition = 0;
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &k3kkeyListLen, 0, &endFilePosition, true);
|
||||
if (res == PM3_SUCCESS && endFilePosition)
|
||||
if (res == PM3_SUCCESS && endFilePosition) {
|
||||
PrintAndLogEx(SUCCESS, "First part of k3kdes dictionary successfully loaded.");
|
||||
}
|
||||
|
||||
endFilePosition = 0;
|
||||
}
|
||||
@@ -1351,8 +1340,9 @@ static int CmdHF14aDesChk(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " k3kdes keys", k3kkeyListLen);
|
||||
}
|
||||
|
||||
if (verbose == false)
|
||||
if (verbose == false) {
|
||||
PrintAndLogEx(INFO, "Search keys:");
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
uint8_t app_ids[78] = {0};
|
||||
@@ -1507,7 +1497,7 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
"Detect key type and tries to find one from the list.",
|
||||
"hf mfdes detect -> detect key 0 from PICC level\n"
|
||||
"hf mfdes detect --schann d40 -> detect key 0 from PICC level via secure channel D40\n"
|
||||
"hf mfdes detect --dict mfdes_default_keys -> detect key 0 from PICC level with help of the standard dictionary\n"
|
||||
"hf mfdes detect -f mfdes_default_keys -> detect key 0 from PICC level with help of the standard dictionary\n"
|
||||
"hf mfdes detect --aid 123456 -n 2 --save -> detect key 2 from app 123456 and if succeed - save params to defaults (`default` command)\n"
|
||||
"hf mfdes detect --isoid df01 --save -> detect key 0 and save to defaults with card in the LRP mode");
|
||||
|
||||
@@ -1525,7 +1515,7 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
arg_str0(NULL, "schann", "<d40|ev1|ev2|lrp>", "Secure channel"),
|
||||
arg_str0(NULL, "aid", "<hex>", "Application ID (3 hex bytes, big endian)"),
|
||||
arg_str0(NULL, "isoid", "<hex>", "Application ISO ID (ISO DF ID) (2 hex bytes, big endian)."),
|
||||
arg_str0(NULL, "dict", "<fn>", "Dictionary file name with keys"),
|
||||
arg_str0("f", "file", "<fn>", "Filename of dictionary"),
|
||||
arg_lit0(NULL, "save", "Save found key and parameters to defaults"),
|
||||
arg_param_end
|
||||
};
|
||||
@@ -1570,28 +1560,38 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
|
||||
uint8_t data[250] = {0};
|
||||
size_t datalen = 0;
|
||||
|
||||
res = DesfireGetKeySettings(&dctx, data, &datalen);
|
||||
if (res == PM3_SUCCESS && datalen >= 2) {
|
||||
|
||||
uint8_t num_keys = data[1];
|
||||
|
||||
switch (num_keys >> 6) {
|
||||
case 0:
|
||||
case 0: {
|
||||
keytypes[T_DES] = true;
|
||||
keytypes[T_3DES] = true;
|
||||
break;
|
||||
case 1:
|
||||
}
|
||||
case 1: {
|
||||
keytypes[T_3K3DES] = true;
|
||||
break;
|
||||
case 2:
|
||||
}
|
||||
case 2: {
|
||||
keytypes[T_AES] = true;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// if fail - check auth commands
|
||||
AuthCommandsChk_t authCmdCheck = {0};
|
||||
DesfireCheckAuthCommands(selectway, id, NULL, 0, &authCmdCheck);
|
||||
|
||||
if (authCmdCheck.checked) {
|
||||
|
||||
if (authCmdCheck.auth) {
|
||||
keytypes[T_DES] = true;
|
||||
keytypes[T_3DES] = true;
|
||||
@@ -1600,14 +1600,17 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
keytypes[T_3K3DES] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (authCmdCheck.authAES || authCmdCheck.authEV2) {
|
||||
keytypes[T_AES] = true;
|
||||
}
|
||||
|
||||
if (authCmdCheck.authLRP) {
|
||||
keytypes[T_AES] = true;
|
||||
uselrp = true;
|
||||
securechann = DACLRP;
|
||||
}
|
||||
|
||||
} else {
|
||||
// if nothing helps - we check DES only
|
||||
keytypes[T_DES] = true;
|
||||
@@ -1622,10 +1625,13 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
if (DesfireMFSelected(selectway, id))
|
||||
|
||||
if (DesfireMFSelected(selectway, id)) {
|
||||
PrintAndLogEx(INFO, "Check PICC key num: %d (0x%02x)", dctx.keyNum, dctx.keyNum);
|
||||
else
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "Check: %s key num: %d (0x%02x)", DesfireWayIDStr(selectway, id), dctx.keyNum, dctx.keyNum);
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "keys: DES: %s 2TDEA: %s 3TDEA: %s AES: %s LRP: %s",
|
||||
keytypes[T_DES] ? _GREEN_("YES") : _RED_("NO"),
|
||||
keytypes[T_3DES] ? _GREEN_("YES") : _RED_("NO"),
|
||||
@@ -1639,43 +1645,61 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
bool found = false;
|
||||
size_t errcount = 0;
|
||||
for (uint8_t ktype = T_DES; ktype <= T_AES; ktype++) {
|
||||
if (!keytypes[ktype])
|
||||
|
||||
if (keytypes[ktype] == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
dctx.keyType = ktype;
|
||||
if (verbose)
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(INFO, "Scan key type: %s", CLIGetOptionListStr(DesfireAlgoOpts, dctx.keyType));
|
||||
}
|
||||
|
||||
if (dict_filenamelen == 0) {
|
||||
// keys from mifaredefault.h
|
||||
for (int i = 0; i < g_mifare_plus_default_keys_len; i++) {
|
||||
|
||||
uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||
if (hex_to_bytes(g_mifare_plus_default_keys[i], key, 16) != 16)
|
||||
if (hex_to_bytes(g_mifare_plus_default_keys[i], key, 16) != 16) {
|
||||
continue;
|
||||
if (ktype == T_3K3DES)
|
||||
}
|
||||
|
||||
if (ktype == T_3K3DES) {
|
||||
memcpy(&key[16], key, 8);
|
||||
}
|
||||
|
||||
res = DesfireAuthCheck(&dctx, selectway, id, securechann, key);
|
||||
if (res == PM3_SUCCESS) {
|
||||
found = true;
|
||||
break; // all the params already in the dctx
|
||||
}
|
||||
|
||||
if (res == -10) {
|
||||
if (verbose)
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(ERR, "Can't select AID. There is no connection with card.");
|
||||
}
|
||||
|
||||
found = false;
|
||||
break; // we can't select app after invalid 1st auth stages
|
||||
}
|
||||
|
||||
if (res == -11) {
|
||||
|
||||
if (errcount > 10) {
|
||||
if (verbose)
|
||||
if (verbose) {
|
||||
PrintAndLogEx(ERR, "Too much errors (%zu) from card", errcount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
errcount++;
|
||||
} else
|
||||
|
||||
} else {
|
||||
errcount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// keys from file
|
||||
uint8_t keyList[MAX_KEYS_LIST_LEN * MAX_KEY_LEN] = {0};
|
||||
@@ -1683,49 +1707,65 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
size_t keylen = desfire_get_key_length(dctx.keyType);
|
||||
size_t endFilePosition = 0;
|
||||
|
||||
while (!found) {
|
||||
while (found == false) {
|
||||
|
||||
res = loadFileDICTIONARYEx((char *)dict_filename, keyList, sizeof(keyList), NULL, keylen, &keyListLen, endFilePosition, &endFilePosition, verbose);
|
||||
if (res != 1 && res != PM3_SUCCESS)
|
||||
if (res != 1 && res != PM3_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < keyListLen; i++) {
|
||||
|
||||
res = DesfireAuthCheck(&dctx, selectway, id, securechann, &keyList[i * keylen]);
|
||||
if (res == PM3_SUCCESS) {
|
||||
found = true;
|
||||
break; // all the params already in the dctx
|
||||
}
|
||||
|
||||
if (res == -10) {
|
||||
if (verbose)
|
||||
if (verbose) {
|
||||
PrintAndLogEx(ERR, "Can't select AID. There is no connection with card.");
|
||||
}
|
||||
|
||||
found = false;
|
||||
break; // we can't select app after invalid 1st auth stages
|
||||
}
|
||||
|
||||
if (res == -11) {
|
||||
|
||||
if (errcount > 10) {
|
||||
if (verbose)
|
||||
if (verbose) {
|
||||
PrintAndLogEx(ERR, "Too much errors (%zu) from card", errcount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
errcount++;
|
||||
} else
|
||||
|
||||
} else {
|
||||
errcount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (endFilePosition == 0)
|
||||
if (endFilePosition == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (found)
|
||||
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (DesfireMFSelected(selectway, id))
|
||||
|
||||
if (DesfireMFSelected(selectway, id)) {
|
||||
PrintAndLogEx(INFO, _GREEN_("Found") " key num: %d (0x%02x)", dctx.keyNum, dctx.keyNum);
|
||||
else
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "Found key for: %s key num: %d (0x%02x)", DesfireWayIDStr(selectway, id), dctx.keyNum, dctx.keyNum);
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "channel " _GREEN_("%s") " key " _GREEN_("%s") " [%d]: " _GREEN_("%s"),
|
||||
CLIGetOptionListStr(DesfireSecureChannelOpts, securechann),
|
||||
@@ -1740,6 +1780,7 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
DropField();
|
||||
|
||||
if (found && save) {
|
||||
|
||||
defaultKeyNum = dctx.keyNum;
|
||||
defaultAlgoId = dctx.keyType;
|
||||
memcpy(defaultKey, dctx.key, DESFIRE_MAX_KEY_SIZE);
|
||||
@@ -1750,17 +1791,16 @@ static int CmdHF14aDesDetect(const char *Cmd) {
|
||||
defaultCommSet = dctx.cmdSet;
|
||||
|
||||
PrintAndLogEx(INFO, "-----------" _CYAN_("Default parameters") "---------------------------------");
|
||||
|
||||
PrintAndLogEx(INFO, "Key Num : %d", defaultKeyNum);
|
||||
PrintAndLogEx(INFO, "Algo : %s", CLIGetOptionListStr(DesfireAlgoOpts, defaultAlgoId));
|
||||
PrintAndLogEx(INFO, "Key : %s", sprint_hex(defaultKey, desfire_get_key_length(defaultAlgoId)));
|
||||
PrintAndLogEx(INFO, "KDF algo : %s", CLIGetOptionListStr(DesfireKDFAlgoOpts, defaultKdfAlgo));
|
||||
PrintAndLogEx(INFO, "KDF input : [%d] %s", defaultKdfInputLen, sprint_hex(defaultKdfInput, defaultKdfInputLen));
|
||||
PrintAndLogEx(INFO, "Secure chan : %s", CLIGetOptionListStr(DesfireSecureChannelOpts, defaultSecureChannel));
|
||||
PrintAndLogEx(INFO, "Command set : %s", CLIGetOptionListStr(DesfireCommandSetOpts, defaultCommSet));
|
||||
PrintAndLogEx(INFO, _GREEN_("Saved"));
|
||||
PrintAndLogEx(INFO, "Key Num....... %d", defaultKeyNum);
|
||||
PrintAndLogEx(INFO, "Algo.......... %s", CLIGetOptionListStr(DesfireAlgoOpts, defaultAlgoId));
|
||||
PrintAndLogEx(INFO, "Key........... %s", sprint_hex(defaultKey, desfire_get_key_length(defaultAlgoId)));
|
||||
PrintAndLogEx(INFO, "KDF algo...... %s", CLIGetOptionListStr(DesfireKDFAlgoOpts, defaultKdfAlgo));
|
||||
PrintAndLogEx(INFO, "KDF input..... [%d] %s", defaultKdfInputLen, sprint_hex(defaultKdfInput, defaultKdfInputLen));
|
||||
PrintAndLogEx(INFO, "Secure chan... %s", CLIGetOptionListStr(DesfireSecureChannelOpts, defaultSecureChannel));
|
||||
PrintAndLogEx(INFO, "Command set... %s", CLIGetOptionListStr(DesfireCommandSetOpts, defaultCommSet));
|
||||
PrintAndLogEx(INFO, "Parameters saved to in-memory ( %s )", _GREEN_("ok"));
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2133,6 +2173,9 @@ static int CmdHF14ADesBruteApps(const char *Cmd) {
|
||||
startAid[1] = 0x00;
|
||||
startAid[2] = 0x0F;
|
||||
}
|
||||
|
||||
reverse_array(startAid, 3);
|
||||
reverse_array(endAid, 3);
|
||||
uint32_t idStart = DesfireAIDByteToUint(startAid);
|
||||
uint32_t idEnd = DesfireAIDByteToUint(endAid);
|
||||
if (idStart > idEnd) {
|
||||
@@ -3282,11 +3325,15 @@ static int CmdHF14ADesGetAIDs(const char *Cmd) {
|
||||
}
|
||||
|
||||
if (buflen >= 3) {
|
||||
PrintAndLogEx(INFO, "---- " _CYAN_("AID list") " ----");
|
||||
|
||||
uint8_t j = (buflen / 3);
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, "--- " _CYAN_("AID list") " ( " _YELLOW_("%u") " found )", j);
|
||||
for (int i = 0; i < buflen; i += 3) {
|
||||
uint32_t aid = DesfireAIDByteToUint(&buf[i]);
|
||||
PrintAndLogEx(SUCCESS, _YELLOW_("%06X") " %s", aid, getAidCommentStr(aid));
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "There is no applications on the card");
|
||||
}
|
||||
|
||||
+40
-19
@@ -20,6 +20,44 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// Ev1 card limits
|
||||
#define MAX_NUM_KEYS 0x0F
|
||||
#define MAX_APPLICATION_COUNT 28
|
||||
#define MAX_FILE_COUNT 32
|
||||
#define MAX_FRAME_SIZE 60
|
||||
#define FRAME_PAYLOAD_SIZE (MAX_FRAME_SIZE - 5)
|
||||
|
||||
// Ev2 card limits
|
||||
// Ev3 card limits
|
||||
// Light card limits
|
||||
// Light Ev1 card limits
|
||||
|
||||
#define NOT_YET_AUTHENTICATED 0xFF
|
||||
|
||||
typedef enum {
|
||||
NXP_UNKNOWN = 0,
|
||||
DESFIRE_MF3ICD40,
|
||||
DESFIRE_EV1,
|
||||
DESFIRE_EV2,
|
||||
DESFIRE_EV2_XL,
|
||||
DESFIRE_EV3,
|
||||
DESFIRE_LIGHT,
|
||||
PLUS_EV1,
|
||||
PLUS_EV2,
|
||||
NTAG413DNA,
|
||||
NTAG424,
|
||||
DUOX,
|
||||
} nxp_cardtype_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t isOK;
|
||||
uint8_t uid[7];
|
||||
uint8_t uidlen;
|
||||
uint8_t versionHW[7];
|
||||
uint8_t versionSW[7];
|
||||
uint8_t details[14];
|
||||
} PACKED mfdes_info_res_t;
|
||||
|
||||
int CmdHFMFDes(const char *Cmd);
|
||||
|
||||
/*
|
||||
@@ -29,24 +67,7 @@ int getKeySettings(uint8_t *aid);
|
||||
*/
|
||||
|
||||
int desfire_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, size_t signature_len);
|
||||
|
||||
// Ev1 card limits
|
||||
#define MAX_NUM_KEYS 0x0F
|
||||
#define MAX_APPLICATION_COUNT 28
|
||||
#define MAX_FILE_COUNT 32
|
||||
#define MAX_FRAME_SIZE 60
|
||||
#define FRAME_PAYLOAD_SIZE (MAX_FRAME_SIZE - 5)
|
||||
|
||||
// Ev2 card limits
|
||||
|
||||
// Ev3 card limits
|
||||
|
||||
// Light card limits
|
||||
|
||||
// Light Ev1 card limits
|
||||
|
||||
#define NOT_YET_AUTHENTICATED 0xFF
|
||||
|
||||
|
||||
nxp_cardtype_t getCardType(uint8_t type, uint8_t major, uint8_t minor);
|
||||
int mfdes_get_info(mfdes_info_res_t *info);
|
||||
|
||||
#endif
|
||||
+436
-246
File diff suppressed because it is too large.
Load diff
+2
-15
@@ -19,20 +19,7 @@
|
||||
#define CMDHFMFP_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef enum {
|
||||
MFP_UNKNOWN = 0,
|
||||
DESFIRE_MF3ICD40,
|
||||
DESFIRE_EV1,
|
||||
DESFIRE_EV2,
|
||||
DESFIRE_EV2_XL,
|
||||
DESFIRE_EV3,
|
||||
DESFIRE_LIGHT,
|
||||
PLUS_EV1,
|
||||
PLUS_EV2,
|
||||
NTAG413DNA,
|
||||
NTAG424
|
||||
} nxp_cardtype_t;
|
||||
#include "mifare/mifare4.h"
|
||||
|
||||
typedef struct mfp_key_item {
|
||||
uint8_t a[16];
|
||||
@@ -46,5 +33,5 @@ typedef struct mfp_keys {
|
||||
|
||||
int CmdHFMFP(const char *Cmd);
|
||||
int CmdHFMFPNDEFRead(const char *Cmd);
|
||||
|
||||
int mfp_data_crypt(mf4Session_t *mf4session, uint8_t *dati, uint8_t *dato, bool rev);
|
||||
#endif
|
||||
+57
-36
@@ -299,7 +299,7 @@ static const char *getUlev1CardSizeStr(uint8_t fsize) {
|
||||
|
||||
// is LSB set?
|
||||
if (fsize & 1)
|
||||
snprintf(buf, sizeof(buf), "%02X, (%u <-> %u bytes)", fsize, usize, lsize);
|
||||
snprintf(buf, sizeof(buf), "%02X, (%u - %u bytes)", fsize, usize, lsize);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "%02X, (%u bytes)", fsize, lsize);
|
||||
return buf;
|
||||
@@ -451,7 +451,7 @@ static int ul_comp_write(uint8_t page, const uint8_t *data, uint8_t datalen) {
|
||||
uint8_t response[1] = {0xFF};
|
||||
ul_send_cmd_raw(cmd, 2 + datalen, response, sizeof(response));
|
||||
// ACK
|
||||
if (response[0] == 0x0a) {
|
||||
if (response[0] == CARD_ACK) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
// NACK
|
||||
@@ -464,13 +464,31 @@ static int ulc_requestAuthentication(uint8_t *nonce, uint16_t nonceLength) {
|
||||
return ul_send_cmd_raw(cmd, sizeof(cmd), nonce, nonceLength);
|
||||
}
|
||||
|
||||
int mfuc_test_authentication_support(void) {
|
||||
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
PrintAndLogEx(DEBUG, "iso14443a card select timeout");
|
||||
DropField();
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
uint8_t nonce1[11] = {0x00};
|
||||
int resplen = ulc_requestAuthentication(nonce1, sizeof(nonce1));
|
||||
DropField();
|
||||
if (resplen == 11) { // ULC nonce
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
static int ulev1_requestAuthentication(const uint8_t *pwd, uint8_t *pack, uint16_t packLength) {
|
||||
|
||||
uint8_t cmd[] = {MIFARE_ULEV1_AUTH, pwd[0], pwd[1], pwd[2], pwd[3]};
|
||||
int len = ul_send_cmd_raw(cmd, sizeof(cmd), pack, packLength);
|
||||
// NACK tables different tags, but between 0-9 is a NEGATIVE response.
|
||||
// ACK == 0xA
|
||||
if (len == 1 && pack[0] <= 0x09) {
|
||||
// should only give you PACK (4 byytes)
|
||||
if (len == 1) {
|
||||
return PM3_EWRONGANSWER;
|
||||
}
|
||||
return len;
|
||||
@@ -498,10 +516,7 @@ static int ulaes_requestAuthentication(const uint8_t *key, uint8_t keyno, bool s
|
||||
if (WaitForResponseTimeout(CMD_HF_MIFAREULAES_AUTH, &resp, 1500) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
if (resp.status != PM3_SUCCESS) {
|
||||
return resp.status;
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
return resp.status;
|
||||
}
|
||||
|
||||
static int ulc_authentication(const uint8_t *key, bool switch_off_field) {
|
||||
@@ -1613,6 +1628,7 @@ static int mfu_dump_tag(uint16_t pages, void **pdata, uint16_t *len) {
|
||||
if (WaitForResponseTimeout(CMD_ACK, &resp, 2500) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(*pdata);
|
||||
*pdata = NULL;
|
||||
res = PM3_ETIMEOUT;
|
||||
goto out;
|
||||
}
|
||||
@@ -1620,6 +1636,7 @@ static int mfu_dump_tag(uint16_t pages, void **pdata, uint16_t *len) {
|
||||
if (resp.oldarg[0] != 1) {
|
||||
PrintAndLogEx(WARNING, "Failed reading card");
|
||||
free(*pdata);
|
||||
*pdata = NULL;
|
||||
res = PM3_ESOFT;
|
||||
goto out;
|
||||
}
|
||||
@@ -1635,6 +1652,7 @@ static int mfu_dump_tag(uint16_t pages, void **pdata, uint16_t *len) {
|
||||
if (GetFromDevice(BIG_BUF, *pdata, buffer_size, startindex, NULL, 0, NULL, 2500, false) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(*pdata);
|
||||
*pdata = NULL;
|
||||
res = PM3_ETIMEOUT;
|
||||
goto out;
|
||||
}
|
||||
@@ -1666,7 +1684,7 @@ typedef struct {
|
||||
} mfu_otp_identify_t;
|
||||
|
||||
static mfu_otp_identify_t mfu_otp_ident_table[] = {
|
||||
{ "SALTO Systems card", 12, 4, "534C544F", ul_c_otpgenA, NULL },
|
||||
{ "SALTO Systems card", 12, 4, "534C544F", ul_c_otpgenA, "report to iceman!" },
|
||||
{ NULL, 0, 0, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -1832,7 +1850,7 @@ static uint8_t mfu_max_len(void) {
|
||||
return n;
|
||||
}
|
||||
|
||||
static int mfu_get_version_uid(uint8_t *version, uint8_t *uid) {
|
||||
int mfu_get_version_uid(uint8_t *version, uint8_t *uid) {
|
||||
iso14a_card_select_t card;
|
||||
if (ul_select(&card) == false) {
|
||||
return PM3_ESOFT;
|
||||
@@ -1945,7 +1963,7 @@ static int mfu_fingerprint(uint64_t tagtype, bool hasAuthKey, const uint8_t *aut
|
||||
// OTP checks
|
||||
mfu_otp_identify_t *item = mfu_match_otp_fingerprint(uid, data);
|
||||
if (item) {
|
||||
PrintAndLogEx(SUCCESS, _GREEN_("%s"), item->desc);
|
||||
PrintAndLogEx(SUCCESS, _BACK_GREEN_(" %s "), item->desc);
|
||||
res = PM3_SUCCESS;
|
||||
|
||||
if (item->hint) {
|
||||
@@ -2018,12 +2036,12 @@ uint64_t GetHF14AMfU_Type(void) {
|
||||
return MFU_TT_UL_ERROR;
|
||||
|
||||
// Ultralight - ATQA / SAK
|
||||
if (card.atqa[1] != 0x00 || card.atqa[0] != 0x44 || card.sak != 0x00) {
|
||||
if (card.atqa[1] != 0x00 || card.sak != 0x00) {
|
||||
//PrintAndLogEx(NORMAL, "Tag is not Ultralight | NTAG | MY-D |ST25TN [ATQA: %02X %02X SAK: %02X]\n", card.atqa[1], card.atqa[0], card.sak);
|
||||
DropField();
|
||||
return MFU_TT_UL_ERROR;
|
||||
}
|
||||
if (card.uid[0] == 0x02) {
|
||||
if ((card.uid[0] == 0x02) && (card.atqa[0] == 0x44)) {
|
||||
// ST25TN
|
||||
// read SYSBLOCK
|
||||
uint8_t data[4] = {0x00};
|
||||
@@ -2045,7 +2063,7 @@ uint64_t GetHF14AMfU_Type(void) {
|
||||
}
|
||||
}
|
||||
|
||||
} else if (card.uid[0] == 0x05) {
|
||||
} else if ((card.uid[0] == 0x05) && (card.atqa[0] == 0x44)) {
|
||||
// Infineon MY-D tests Exam high nibble
|
||||
DropField();
|
||||
uint8_t nib = (card.uid[1] & 0xf0) >> 4;
|
||||
@@ -2066,7 +2084,7 @@ uint64_t GetHF14AMfU_Type(void) {
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// Note that SAK might be 0x44 but also e.g. 0x04 for cards in Random ID mode
|
||||
uint8_t version[10] = {0x00};
|
||||
int len = ulev1_getVersion(version, sizeof(version));
|
||||
DropField();
|
||||
@@ -2317,8 +2335,8 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
|
||||
uint8_t ulc_conf[16] = {0x00};
|
||||
status = ul_read(0x28, ulc_conf, sizeof(ulc_conf));
|
||||
if (status <= 0) {
|
||||
PrintAndLogEx(ERR, "Error: tag didn't answer to READ UL-C");
|
||||
PrintAndLogEx(HINT, "Hint: Tag is most likely fully read protected");
|
||||
PrintAndLogEx(ERR, "Error: tag didn't answer to page 40 read command");
|
||||
PrintAndLogEx(HINT, "Hint: tag config may be set to read-protect those pages, try dumping");
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -2707,8 +2725,9 @@ static int CmdHF14AMfUWrBl(const char *Cmd) {
|
||||
|
||||
// starting with getting tagtype
|
||||
uint64_t tagtype = GetHF14AMfU_Type();
|
||||
if (tagtype == MFU_TT_UL_ERROR)
|
||||
if (tagtype == MFU_TT_UL_ERROR) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
uint8_t maxblockno = 0;
|
||||
for (uint8_t idx = 1; idx < ARRAYLEN(UL_TYPES_ARRAY); idx++) {
|
||||
@@ -3845,17 +3864,17 @@ static int CmdHF14AMfUSim(const char *Cmd) {
|
||||
static int CmdHF14AMfUCAuth(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mfu cauth",
|
||||
"Tests 3DES password on Mifare Ultralight-C tag.\n"
|
||||
"If password is not specified, a set of known defaults will be tested.",
|
||||
"Tests 3DES key on Mifare Ultralight-C tag.\n"
|
||||
"If key is not specified, a set of known defaults will be tried.",
|
||||
"hf mfu cauth\n"
|
||||
"hf mfu cauth --key 000102030405060708090a0b0c0d0e0f"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str0(NULL, "key", "<hex>", "Authentication key (UL-C 16 hex bytes)"),
|
||||
arg_str0(NULL, "key", "<hex>", "Authentication key (16 bytes in hex)"),
|
||||
arg_lit0("l", NULL, "Swap entered key's endianness"),
|
||||
arg_lit0("k", NULL, "Keep field on (only if a password is provided)"),
|
||||
arg_lit0("k", NULL, "Keep field on (only if a key is provided)"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
@@ -3907,16 +3926,16 @@ static int CmdHF14AMfUAESAuth(const char *Cmd) {
|
||||
CLIParserInit(&ctx, "hf mfu aesauth",
|
||||
"Tests AES key on Mifare Ultralight AES tags.\n"
|
||||
"If no key is specified, null key will be tried.\n"
|
||||
"Key index 0: DataProtKey (default)\n"
|
||||
"Key index 1: UIDRetrKey\n"
|
||||
"Key index 2: OriginalityKey\n",
|
||||
" Key index 0... DataProtKey (default)\n"
|
||||
" Key index 1... UIDRetrKey\n"
|
||||
" Key index 2... OriginalityKey\n",
|
||||
"hf mfu aesauth\n"
|
||||
"hf mfu aesauth --key <32 bytes> --index <0..2>"
|
||||
"hf mfu aesauth --key <16 hex bytes> --index <0..2>"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str0(NULL, "key", "<hex>", "AES key (32 hex bytes)"),
|
||||
arg_str0(NULL, "key", "<hex>", "AES key (16 hex bytes)"),
|
||||
arg_int0("i", "index", "<0..2>", "Key index, default: 0"),
|
||||
arg_lit0("k", NULL, "Keep field on (only if a key is provided)"),
|
||||
arg_param_end
|
||||
@@ -3924,7 +3943,7 @@ static int CmdHF14AMfUAESAuth(const char *Cmd) {
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
int ak_len = 0;
|
||||
uint8_t authentication_key[32] = {0};
|
||||
uint8_t authentication_key[16] = {0};
|
||||
uint8_t *authKeyPtr = authentication_key;
|
||||
CLIGetHexWithReturn(ctx, 1, authentication_key, &ak_len);
|
||||
int key_index = arg_get_int_def(ctx, 2, 0);
|
||||
@@ -3934,9 +3953,9 @@ static int CmdHF14AMfUAESAuth(const char *Cmd) {
|
||||
|
||||
if (ak_len == 0) {
|
||||
// default to null key
|
||||
ak_len = 32;
|
||||
ak_len = 16;
|
||||
}
|
||||
if (ak_len != 32) {
|
||||
if (ak_len != 16) {
|
||||
PrintAndLogEx(WARNING, "Invalid key length");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
@@ -4147,17 +4166,17 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
|
||||
|
||||
// Enforce bad BCC handling temporarily as BCC will be wrong between
|
||||
// block 1 write and block2 write
|
||||
hf14a_config config;
|
||||
hf14a_config_t config;
|
||||
SendCommandNG(CMD_HF_ISO14443A_GET_CONFIG, NULL, 0);
|
||||
if (WaitForResponseTimeout(CMD_HF_ISO14443A_GET_CONFIG, &resp, 2000) == false) {
|
||||
PrintAndLogEx(WARNING, "command execute timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
memcpy(&config, resp.data.asBytes, sizeof(hf14a_config));
|
||||
memcpy(&config, resp.data.asBytes, sizeof(hf14a_config_t));
|
||||
int8_t oldconfig_bcc = config.forcebcc;
|
||||
if (oldconfig_bcc != 2) {
|
||||
config.forcebcc = 2;
|
||||
SendCommandNG(CMD_HF_ISO14443A_SET_CONFIG, (uint8_t *)&config, sizeof(hf14a_config));
|
||||
SendCommandNG(CMD_HF_ISO14443A_SET_CONFIG, (uint8_t *)&config, sizeof(hf14a_config_t));
|
||||
}
|
||||
|
||||
// block 0.
|
||||
@@ -4200,7 +4219,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) {
|
||||
// restore BCC config
|
||||
if (oldconfig_bcc != 2) {
|
||||
config.forcebcc = oldconfig_bcc;
|
||||
SendCommandNG(CMD_HF_ISO14443A_SET_CONFIG, (uint8_t *)&config, sizeof(hf14a_config));
|
||||
SendCommandNG(CMD_HF_ISO14443A_SET_CONFIG, (uint8_t *)&config, sizeof(hf14a_config_t));
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
@@ -4609,7 +4628,7 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) {
|
||||
|
||||
// we be getting ACK that we are silently ignoring here..
|
||||
|
||||
if (!WaitForResponseTimeout(CMD_HF_MFU_OTP_TEAROFF, &resp, 2000)) {
|
||||
if (WaitForResponseTimeout(CMD_HF_MFU_OTP_TEAROFF, &resp, 2000) == false) {
|
||||
PrintAndLogEx(WARNING, "Failed");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -4630,11 +4649,13 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) {
|
||||
got_post = true;
|
||||
}
|
||||
}
|
||||
if (! got_post) {
|
||||
|
||||
if (!got_post) {
|
||||
PrintAndLogEx(FAILED, "Failed to read block BEFORE");
|
||||
error_retries++;
|
||||
continue; // try again
|
||||
}
|
||||
|
||||
error_retries = 0;
|
||||
char prestr[20] = {0};
|
||||
snprintf(prestr, sizeof(prestr), "%s", sprint_hex_inrow(pre, sizeof(pre)));
|
||||
@@ -4917,7 +4938,7 @@ static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
PacketResponseNG resp;
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t*)&payload, sizeof(payload));
|
||||
if (!WaitForResponseTimeout(CMD_HF_MFU_COUNTER_TEAROFF, &resp, 2000)) {
|
||||
if (WaitForResponseTimeout(CMD_HF_MFU_COUNTER_TEAROFF, &resp, 2000) == false) {
|
||||
PrintAndLogEx(WARNING, "\ntear off command failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ int ul_print_type(uint64_t tagtype, uint8_t spaces);
|
||||
void mfu_print_dump(mfu_dump_t *card, uint16_t pages, uint8_t startpage, bool dense_output);
|
||||
int ul_read_uid(uint8_t *uid);
|
||||
int trace_mfuc_try_default_3des_keys(uint8_t **correct_key, int state, uint8_t (*authdata)[16]);
|
||||
int mfu_get_version_uid(uint8_t *version, uint8_t *uid);
|
||||
int mfuc_test_authentication_support(void);
|
||||
|
||||
int CmdHFMFUltra(const char *Cmd);
|
||||
int CmdHF14MfuNDEFRead(const char *Cmd);
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
#include "crc32.h"
|
||||
#include "cmdhfmfdes.h"
|
||||
|
||||
#define NTAG424_MAX_BYTES 412
|
||||
|
||||
#define NTAG424_MAX_BYTES 412
|
||||
#define NTAG424_RESPONSE_LENGTH 2
|
||||
|
||||
// NTAG424 commands currently implemented
|
||||
// icenam: should be able to use 14a / msdes to annotate NTAG424 communications
|
||||
@@ -542,19 +542,17 @@ static void ntag424_print_file_settings(uint8_t fileno, const ntag424_file_setti
|
||||
|
||||
// NTAG424 only have one static application, so we select it here
|
||||
static int ntag424_select_application(void) {
|
||||
const size_t RESPONSE_LENGTH = 2;
|
||||
uint8_t cmd[] = {0x00, 0xA4, 0x04, 0x0C, 0x07, 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01, 0x00 };
|
||||
uint8_t resp[RESPONSE_LENGTH];
|
||||
uint8_t resp[NTAG424_RESPONSE_LENGTH];
|
||||
int outlen = 0;
|
||||
int res;
|
||||
|
||||
res = ExchangeAPDU14a(cmd, sizeof(cmd), false, true, resp, RESPONSE_LENGTH, &outlen);
|
||||
int res = ExchangeAPDU14a(cmd, sizeof(cmd), false, true, resp, NTAG424_RESPONSE_LENGTH, &outlen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Failed to send apdu");
|
||||
return res;
|
||||
}
|
||||
|
||||
if (outlen != RESPONSE_LENGTH || resp[RESPONSE_LENGTH - 2] != 0x90 || resp[RESPONSE_LENGTH - 1] != 0x00) {
|
||||
if (outlen != NTAG424_RESPONSE_LENGTH || resp[NTAG424_RESPONSE_LENGTH - 2] != 0x90 || resp[NTAG424_RESPONSE_LENGTH - 1] != 0x00) {
|
||||
PrintAndLogEx(ERR, "Failed to select application");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -762,7 +760,7 @@ static int ntag424_write_data(uint8_t fileno, uint32_t offset, uint32_t num_byte
|
||||
static int ntag424_read_data(uint8_t fileno, uint16_t offset, uint16_t num_bytes, uint8_t *out, ntag424_communication_mode_t comm_mode, ntag424_session_keys_t *session_keys) {
|
||||
uint8_t cmd_header[] = {
|
||||
fileno,
|
||||
(uint8_t)offset, (uint8_t)(offset << 8), (uint8_t)(offset << 16), // offset
|
||||
(uint8_t)offset, (uint8_t)(offset >> 8), (uint8_t)(offset >> 16), // offset
|
||||
(uint8_t)num_bytes, (uint8_t)(num_bytes >> 8), 0x00
|
||||
};
|
||||
|
||||
|
||||
@@ -562,7 +562,7 @@ static int select_DF_verify(uint8_t *response, uint8_t response_length, uint8_t
|
||||
}
|
||||
|
||||
// ----------------- MAC Key Generation -----------------
|
||||
uint8_t cmac[8];
|
||||
uint8_t cmac[16];
|
||||
uint8_t MAC_key[24] = {0x00};
|
||||
memcpy(MAC_key, keys[key_index].privMacKey, 16);
|
||||
create_cmac(MAC_key, input, cmac, sizeof(input), encryption_algorithm);
|
||||
@@ -1351,7 +1351,7 @@ static int CmdHfSeosGDF(const char *Cmd) {
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
int key_index = arg_get_int_def(ctx, 1, -1);
|
||||
int key_index = arg_get_int_def(ctx, 1, 0);
|
||||
|
||||
CLIParserFree(ctx);
|
||||
return seos_global_df(key_index);
|
||||
|
||||
+96
-38
@@ -24,6 +24,7 @@
|
||||
#include "cmdtrace.h"
|
||||
#include "cliparser.h"
|
||||
#include "cmdhf14a.h"
|
||||
#include "crypto/asn1utils.h" // ASN1 decode / print
|
||||
#include "protocols.h" // definitions of ISO14A/7816 protocol
|
||||
#include "iso7816/apduinfo.h" // GetAPDUCodeDescription
|
||||
#include "commonutil.h" // get_sw
|
||||
@@ -32,6 +33,7 @@
|
||||
#include "cmdhf14a.h" // apdu chaining
|
||||
|
||||
#define TIMEOUT 2000
|
||||
#define MAX_CERT_SIZE 768
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
@@ -51,17 +53,22 @@ static int CmdHelp(const char *Cmd);
|
||||
*/
|
||||
|
||||
// TESLA
|
||||
static int info_hf_tesla(void) {
|
||||
static int info_hf_tesla(bool parse_certs) {
|
||||
|
||||
bool activate_field = true;
|
||||
bool keep_field_on = true;
|
||||
uint8_t response[PM3_CMD_DATA_SIZE];
|
||||
uint8_t response[MAX_CERT_SIZE]; // Some cards have pretty large certificates
|
||||
int resplen = 0;
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
// --------------- Select TESLA application ----------------
|
||||
uint8_t aSELECT_AID[80];
|
||||
int aSELECT_AID_n = 0;
|
||||
param_gethex_to_eol("00a404000a7465736c614c6f676963", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
|
||||
param_gethex_to_eol("00a404000a7465736c614c6f67696300", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
|
||||
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
@@ -73,7 +80,7 @@ static int info_hf_tesla(void) {
|
||||
|
||||
if ((resplen < 2) || (sw != ISO7816_OK)) {
|
||||
|
||||
param_gethex_to_eol("00a404000af465736c614c6f676963", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
|
||||
param_gethex_to_eol("00a404000af465736c614c6f67696300", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
|
||||
res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
@@ -92,9 +99,9 @@ static int info_hf_tesla(void) {
|
||||
|
||||
|
||||
// --------------- ECDH public key file reading ----------------
|
||||
uint8_t pk[3][65] = {{0}};
|
||||
uint8_t pk[4][65] = {{0}};
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
|
||||
uint8_t aSELECT_PK[5] = {0x80, 0x04, i, 0x00, 0x00};
|
||||
res = ExchangeAPDU14a(aSELECT_PK, sizeof(aSELECT_PK), activate_field, keep_field_on, response, sizeof(response), &resplen);
|
||||
@@ -110,7 +117,7 @@ static int info_hf_tesla(void) {
|
||||
|
||||
uint8_t aREAD_FORM_FACTOR[30];
|
||||
int aREAD_FORM_FACTOR_n = 0;
|
||||
param_gethex_to_eol("80140000", 0, aREAD_FORM_FACTOR, sizeof(aREAD_FORM_FACTOR), &aREAD_FORM_FACTOR_n);
|
||||
param_gethex_to_eol("8014000000", 0, aREAD_FORM_FACTOR, sizeof(aREAD_FORM_FACTOR), &aREAD_FORM_FACTOR_n);
|
||||
res = ExchangeAPDU14a(aREAD_FORM_FACTOR, aREAD_FORM_FACTOR_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
@@ -149,23 +156,58 @@ static int info_hf_tesla(void) {
|
||||
Set_apdu_in_framing(true);
|
||||
for (uint8_t i = 0; i < 5; i++) {
|
||||
|
||||
uint8_t aSELECT_CERT[PM3_CMD_DATA_SIZE] = {0x80, 0x06, i, 0x00, 0x00, 0x00, 0xFF};
|
||||
int aSELECT_CERT_n = 7;
|
||||
// First, read the certificate length
|
||||
uint8_t aSELECT_CERT[PM3_CMD_DATA_SIZE] = {0x80, 0x06, i, 0x00, 0x04};
|
||||
int aSELECT_CERT_n = 5;
|
||||
|
||||
res = ExchangeAPDU14a(aSELECT_CERT, aSELECT_CERT_n, activate_field, keep_field_on, response, PM3_CMD_DATA_SIZE, &resplen);
|
||||
res = ExchangeAPDU14a(aSELECT_CERT, aSELECT_CERT_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Could not read certificate %i length", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
sw = get_sw(response, resplen);
|
||||
bool cert_len_present = false;
|
||||
|
||||
if (sw == ISO7816_OK) {
|
||||
// save CERT for later
|
||||
uint8_t cert[515] = {0};
|
||||
memcpy(cert, response, resplen - 2);
|
||||
|
||||
if (sw == ISO7816_OK && resplen > 3) {
|
||||
uint16_t cert_len = response[0] << 8 | response[1];
|
||||
PrintAndLogEx(INFO, "CERT # %i", i);
|
||||
PrintAndLogEx(INFO, "%s", sprint_hex_inrow(cert, resplen - 2));
|
||||
if (cert_len == 0x3082) {
|
||||
cert_len = (response[2] << 8 | response[3]) + 4;
|
||||
PrintAndLogEx(INFO, "Length (calculated from ASN.1): %i", cert_len);
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "Length (included at start of cert slot): %i", cert_len);
|
||||
cert_len_present = true;
|
||||
}
|
||||
cert_len += 2; // Add 2 bytes for the 9000 at the end
|
||||
// Read the entire cert (extended length APDU)
|
||||
aSELECT_CERT[4] = 0x00;
|
||||
aSELECT_CERT[5] = (cert_len >> 8) & 0xff;
|
||||
aSELECT_CERT[6] = cert_len & 0xff;
|
||||
aSELECT_CERT_n = 7;
|
||||
|
||||
res = ExchangeAPDU14a(aSELECT_CERT, aSELECT_CERT_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Could not read certificate %i (return code %i)", i, res);
|
||||
continue;
|
||||
}
|
||||
|
||||
sw = get_sw(response, resplen);
|
||||
if (sw == ISO7816_OK) {
|
||||
// save CERT for later
|
||||
uint8_t cert[MAX_CERT_SIZE] = {0};
|
||||
memcpy(cert, response, resplen - 2);
|
||||
|
||||
PrintAndLogEx(INFO, "%s", sprint_hex_inrow(cert + (cert_len_present ? 2 : 0), resplen - 2));
|
||||
if (parse_certs) {
|
||||
asn1_print(cert + (cert_len_present ? 2 : 0), cert_len - 2, " ");
|
||||
}
|
||||
}
|
||||
} else if (sw == 0x6f17) {
|
||||
PrintAndLogEx(INFO, "CERT # %i", i);
|
||||
PrintAndLogEx(INFO, "No certificate in slot %i", i);
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Could not read certificate %i", i);
|
||||
}
|
||||
}
|
||||
Set_apdu_in_framing(false);
|
||||
@@ -175,30 +217,28 @@ static int info_hf_tesla(void) {
|
||||
// vehicle public key , 16 byte CHALLENGE
|
||||
// 00112233445566778899AABBCCDDEEFF
|
||||
// 0x51 = 81 dec
|
||||
// param_gethex_to_eol("8011000051 046F08AE62526ABB5690643458152AC963CF5D7C113949F3C2453D1DDC6E4385B430523524045A22F5747BF236F1B5F60F0EA32DC2B8276D75ACDE9813EF77C330 00112233445566778899AABBCCDDEEFF", 0, aAUTH, sizeof(aAUTH), &aAUTH_n);
|
||||
param_gethex_to_eol("8011000051046F08AE62526ABB5690643458152AC963CF5D7C113949F3C2453D1DDC6E4385B430523524045A22F5747BF236F1B5F60F0EA32DC2B8276D75ACDE9813EF77C33000112233445566778899AABBCCDDEEFF", 0, aAUTH, sizeof(aAUTH), &aAUTH_n);
|
||||
// param_gethex_to_eol("8011000051 046F08AE62526ABB5690643458152AC963CF5D7C113949F3C2453D1DDC6E4385B430523524045A22F5747BF236F1B5F60F0EA32DC2B8276D75ACDE9813EF77C330 00112233445566778899AABBCCDDEEFF", 0, aAUTH, sizeof(aAUTH), &aAUTH_n);
|
||||
param_gethex_to_eol("8011000051046F08AE62526ABB5690643458152AC963CF5D7C113949F3C2453D1DDC6E4385B430523524045A22F5747BF236F1B5F60F0EA32DC2B8276D75ACDE9813EF77C33000112233445566778899AABBCCDDEEFF00", 0, aAUTH, sizeof(aAUTH), &aAUTH_n);
|
||||
res = ExchangeAPDU14a(aAUTH, aAUTH_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
PrintAndLogEx(ERR, "Could not exchange authentication challenge");
|
||||
} else {
|
||||
|
||||
uint8_t auth[resplen - 2];
|
||||
uint8_t auth[resplen - 2];
|
||||
|
||||
sw = get_sw(response, resplen);
|
||||
if (sw == ISO7816_OK) {
|
||||
// store CHALLENGE for later
|
||||
memcpy(auth, response, sizeof(auth));
|
||||
sw = get_sw(response, resplen);
|
||||
if (sw == ISO7816_OK) {
|
||||
// store CHALLENGE for later
|
||||
memcpy(auth, response, sizeof(auth));
|
||||
}
|
||||
PrintAndLogEx(INFO, "CHALL......... %s", sprint_hex_inrow(auth, sizeof(auth)));
|
||||
}
|
||||
|
||||
keep_field_on = false;
|
||||
DropField();
|
||||
DropField(); // No further interaction with the card is needed
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "PUBLIC KEY");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
PrintAndLogEx(INFO, "%d - %s", i, sprint_hex_inrow(pk[i], 65));
|
||||
}
|
||||
PrintAndLogEx(INFO, "Form factor... %s " NOLF, sprint_hex_inrow(form_factor, sizeof(form_factor)));
|
||||
@@ -207,16 +247,33 @@ static int info_hf_tesla(void) {
|
||||
|
||||
switch (form_factor_value) {
|
||||
case 0x0001:
|
||||
PrintAndLogEx(NORMAL, "( card )");
|
||||
PrintAndLogEx(NORMAL, "(NXP P60 card)");
|
||||
break;
|
||||
case 0x0002:
|
||||
PrintAndLogEx(NORMAL, "(NXP P71 card)");
|
||||
break;
|
||||
case 0x0021:
|
||||
PrintAndLogEx(NORMAL, "(Model 3 fob without passive entry)");
|
||||
break;
|
||||
case 0x0022:
|
||||
PrintAndLogEx(NORMAL, "( fob )");
|
||||
PrintAndLogEx(NORMAL, "(Model 3 fob with passive entry)");
|
||||
break;
|
||||
case 0x0023:
|
||||
case 0x0025:
|
||||
case 0x0026:
|
||||
PrintAndLogEx(NORMAL, "(Model S fob)");
|
||||
break;
|
||||
case 0x0024:
|
||||
PrintAndLogEx(NORMAL, "(Model X fob)");
|
||||
break;
|
||||
case 0x0031:
|
||||
PrintAndLogEx(NORMAL, "( phone app )");
|
||||
PrintAndLogEx(NORMAL, "(Android phone app with NFC)");
|
||||
break;
|
||||
case 0x0032:
|
||||
PrintAndLogEx(NORMAL, "(iOS phone app with NFC)");
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(NORMAL, "( unknown )");
|
||||
PrintAndLogEx(NORMAL, "(Unknown)");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -224,8 +281,6 @@ static int info_hf_tesla(void) {
|
||||
PrintAndLogEx(INFO, "Version....... %s", sprint_hex_inrow(version, sizeof(version)));
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "CHALL......... %s", sprint_hex_inrow(auth, sizeof(auth)));
|
||||
|
||||
PrintAndLogEx(INFO, "Fingerprint");
|
||||
if ((memcmp(pk[0], pk[1], 65) == 0)) {
|
||||
PrintAndLogEx(INFO, " GaussKey detected");
|
||||
@@ -244,11 +299,14 @@ static int CmdHFTeslaInfo(const char *Cmd) {
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("p", "parse", "Parse the certificates as ASN.1"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
bool parse_certs = arg_get_lit(ctx, 1);
|
||||
CLIParserFree(ctx);
|
||||
return info_hf_tesla();
|
||||
return info_hf_tesla(parse_certs);
|
||||
}
|
||||
|
||||
static int CmdHFTeslaList(const char *Cmd) {
|
||||
|
||||
@@ -664,7 +664,7 @@ static int CmdHFTexkomReader(const char *Cmd) {
|
||||
SendCommandNG(CMD_HF_ACQ_RAW_ADC, (uint8_t *)&samplesCount, sizeof(uint32_t));
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_HF_ACQ_RAW_ADC, &resp, 2500)) {
|
||||
if (WaitForResponseTimeout(CMD_HF_ACQ_RAW_ADC, &resp, 2500) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ int CmdHfThinFilmSim(const char *Cmd) {
|
||||
int ret;
|
||||
while (!(ret = kbd_enter_pressed())) {
|
||||
|
||||
if (WaitForResponseTimeout(CMD_HF_THINFILM_SIMULATE, &resp, 500) == 0) {
|
||||
if (WaitForResponseTimeout(CMD_HF_THINFILM_SIMULATE, &resp, 500) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1013,8 +1013,8 @@ static int CmdHFXeroxRdBl(const char *Cmd) {
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"list", CmdHFXeroxList, AlwaysAvailable, "List ISO-14443B history"},
|
||||
{"--------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("General") " -----------------------"},
|
||||
{"info", CmdHFXeroxInfo, IfPm3Iso14443b, "Short info on Fuji/Xerox tag"},
|
||||
{"--------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("Operations") " -----------------------"},
|
||||
{"info", CmdHFXeroxInfo, IfPm3Iso14443b, "Tag information"},
|
||||
{"dump", CmdHFXeroxDump, IfPm3Iso14443b, "Read all memory pages of an Fuji/Xerox tag, save to file"},
|
||||
{"reader", CmdHFXeroxReader, IfPm3Iso14443b, "Act like a Fuji/Xerox reader"},
|
||||
{"view", CmdHFXeroxView, AlwaysAvailable, "Display content from tag dump file"},
|
||||
|
||||
+8
-4
@@ -928,15 +928,19 @@ static int CmdTune(const char *Cmd) {
|
||||
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
PrintAndLogEx(INPLACE, "% 3i", timeout_max - timeout);
|
||||
while (!WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING, &resp, 500)) {
|
||||
|
||||
while (WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING, &resp, 500) == false) {
|
||||
|
||||
fflush(stdout);
|
||||
if (timeout >= timeout_max) {
|
||||
PrintAndLogEx(WARNING, "\nNo response from Proxmark3. Aborting...");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
timeout++;
|
||||
PrintAndLogEx(INPLACE, "% 3i", timeout_max - timeout);
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
if (resp.status != PM3_SUCCESS) {
|
||||
@@ -1592,7 +1596,7 @@ void pm3_version_short(void) {
|
||||
PrintAndLogEx(NORMAL, " Client.... %s", temp);
|
||||
|
||||
bool armsrc_mismatch = false;
|
||||
char *ptr = strstr(payload->versionstr, " os: ");
|
||||
char *ptr = strstr(payload->versionstr, "OS......... ");
|
||||
if (ptr != NULL) {
|
||||
ptr = strstr(ptr, "\n");
|
||||
if ((ptr != NULL) && (strlen(g_version_information.armsrc) == 9)) {
|
||||
@@ -1607,7 +1611,7 @@ void pm3_version_short(void) {
|
||||
if (ptr != NULL) {
|
||||
char *ptr_end = strstr(ptr, "\n");
|
||||
if (ptr_end != NULL) {
|
||||
uint8_t len = ptr_end - 19 - ptr;
|
||||
uint8_t len = ptr_end - 12 - ptr;
|
||||
PrintAndLogEx(NORMAL, " Bootrom... %.*s", len, ptr + 12);
|
||||
}
|
||||
}
|
||||
@@ -1617,7 +1621,7 @@ void pm3_version_short(void) {
|
||||
if (ptr != NULL) {
|
||||
char *ptr_end = strstr(ptr, "\n");
|
||||
if (ptr_end != NULL) {
|
||||
uint8_t len = ptr_end - 14 - ptr;
|
||||
uint8_t len = ptr_end - 12 - ptr;
|
||||
PrintAndLogEx(NORMAL, " OS........ %.*s", len, ptr + 12);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -435,15 +435,17 @@ int CmdLFCommandRead(const char *Cmd) {
|
||||
|
||||
i = 10;
|
||||
// 20sec wait loop
|
||||
while (!WaitForResponseTimeout(CMD_LF_MOD_THEN_ACQ_RAW_ADC, &resp, 2000) && i != 0) {
|
||||
while (WaitForResponseTimeout(CMD_LF_MOD_THEN_ACQ_RAW_ADC, &resp, 2000) == false && i != 0) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(NORMAL, "." NOLF);
|
||||
}
|
||||
i--;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
}
|
||||
|
||||
if (resp.status != PM3_SUCCESS) {
|
||||
PrintAndLogEx(WARNING, "command failed.");
|
||||
return PM3_ESOFT;
|
||||
@@ -595,7 +597,7 @@ int lf_getconfig(sample_config *config) {
|
||||
|
||||
SendCommandNG(CMD_LF_SAMPLING_GET_CONFIG, NULL, 0);
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_LF_SAMPLING_GET_CONFIG, &resp, 2000)) {
|
||||
if (WaitForResponseTimeout(CMD_LF_SAMPLING_GET_CONFIG, &resp, 2000) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -797,10 +799,12 @@ static int lf_read_internal(bool realtime, bool verbose, uint64_t samples) {
|
||||
payload.samples = (samples > MAX_LF_SAMPLES) ? MAX_LF_SAMPLES : samples;
|
||||
SendCommandNG(CMD_LF_ACQ_RAW_ADC, (uint8_t *)&payload, sizeof(payload));
|
||||
PacketResponseNG resp;
|
||||
|
||||
if (is_trigger_threshold_set) {
|
||||
WaitForResponse(CMD_LF_ACQ_RAW_ADC, &resp);
|
||||
} else {
|
||||
if (!WaitForResponseTimeout(CMD_LF_ACQ_RAW_ADC, &resp, 2500)) {
|
||||
|
||||
if (WaitForResponseTimeout(CMD_LF_ACQ_RAW_ADC, &resp, 2500) == false) {
|
||||
PrintAndLogEx(WARNING, "(lf_read) command execution time out");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
@@ -2013,7 +2013,7 @@ int CmdEM4x05Unlock(const char *Cmd) {
|
||||
|
||||
PrintAndLogEx(INFO, "----------------------------------------------------------------------------\n");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>'") " to exit");
|
||||
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " to exit");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--------------- " _CYAN_("start") " -----------------------\n");
|
||||
|
||||
|
||||
@@ -639,10 +639,8 @@ int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
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((uint8_t *)o->words, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words);
|
||||
em4x50_prepare_result(resp.data.asBytes, etd->addresses & 0xFF, (etd->addresses >> 8) & 0xFF, words);
|
||||
|
||||
if (out != NULL) {
|
||||
memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS);
|
||||
|
||||
+28
-78
@@ -86,18 +86,12 @@ typedef struct _em4x70_tag_info_t {
|
||||
uint8_t Raw[32];
|
||||
} em4x70_tag_info_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_info_t {
|
||||
uint8_t use_parity;
|
||||
} em4x70_cmd_input_info_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_writeblock_t {
|
||||
uint8_t use_parity;
|
||||
uint8_t block;
|
||||
uint8_t value[2];
|
||||
} em4x70_cmd_input_writeblock_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_brute_t {
|
||||
uint8_t use_parity;
|
||||
ID48LIB_NONCE rn;
|
||||
ID48LIB_FRN frn;
|
||||
uint8_t block;
|
||||
@@ -121,12 +115,10 @@ typedef struct _em4x70_cmd_output_brute_t {
|
||||
} em4x70_cmd_output_brute_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_unlock_t {
|
||||
uint8_t use_parity;
|
||||
uint8_t pin[4];
|
||||
} em4x70_cmd_input_unlock_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_auth_t {
|
||||
uint8_t use_parity;
|
||||
ID48LIB_NONCE rn;
|
||||
ID48LIB_FRN frn;
|
||||
} em4x70_cmd_input_auth_t;
|
||||
@@ -136,12 +128,10 @@ typedef struct _em4x70_cmd_output_auth_t {
|
||||
} em4x70_cmd_output_auth_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_setpin_t {
|
||||
uint8_t use_parity;
|
||||
uint8_t pin[4];
|
||||
} em4x70_cmd_input_setpin_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_setkey_t {
|
||||
uint8_t use_parity;
|
||||
ID48LIB_KEY key;
|
||||
} em4x70_cmd_input_setkey_t;
|
||||
|
||||
@@ -151,7 +141,6 @@ typedef struct _em4x70_cmd_input_recover_t {
|
||||
ID48LIB_NONCE nonce;
|
||||
ID48LIB_FRN frn;
|
||||
ID48LIB_GRN grn;
|
||||
bool parity; // if true, add parity bit to commands sent to tag
|
||||
bool verify; // if true, tag must be present
|
||||
} em4x70_cmd_input_recover_t;
|
||||
|
||||
@@ -164,7 +153,6 @@ typedef struct _em4x70_cmd_output_recover_t {
|
||||
} em4x70_cmd_output_recover_t;
|
||||
|
||||
typedef struct _em4x70_cmd_input_verify_auth_t {
|
||||
uint8_t use_parity;
|
||||
ID48LIB_NONCE rn;
|
||||
ID48LIB_FRN frn;
|
||||
ID48LIB_GRN grn;
|
||||
@@ -228,12 +216,12 @@ static void em4x70_print_info_result(const em4x70_tag_info_t *data) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
}
|
||||
|
||||
static int get_em4x70_info(const em4x70_cmd_input_info_t *opts, em4x70_tag_info_t *data_out) {
|
||||
static int get_em4x70_info(em4x70_tag_info_t *data_out) {
|
||||
|
||||
memset(data_out, 0, sizeof(em4x70_tag_info_t));
|
||||
|
||||
// TODO: change firmware to use per-cmd structures
|
||||
em4x70_data_t edata = { .parity = opts->use_parity };
|
||||
em4x70_data_t edata = {0};
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X70_INFO, (uint8_t *)&edata, sizeof(em4x70_data_t));
|
||||
PacketResponseNG resp;
|
||||
@@ -251,10 +239,10 @@ static int writeblock_em4x70(const em4x70_cmd_input_writeblock_t *opts, em4x70_t
|
||||
memset(data_out, 0, sizeof(em4x70_tag_info_t));
|
||||
|
||||
// TODO: change firmware to use per-cmd structures
|
||||
em4x70_data_t etd = {0};
|
||||
etd.address = opts->block;
|
||||
etd.word = BYTES2UINT16(opts->value);
|
||||
etd.parity = opts->use_parity;
|
||||
em4x70_data_t etd = {
|
||||
.address = opts->block,
|
||||
.word = BYTES2UINT16(opts->value),
|
||||
};
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_EM4X70_WRITE, (uint8_t *)&etd, sizeof(etd));
|
||||
@@ -273,7 +261,6 @@ static int auth_em4x70(const em4x70_cmd_input_auth_t *opts, em4x70_cmd_output_au
|
||||
|
||||
// TODO: change firmware to use per-cmd structures
|
||||
em4x70_data_t etd = {0};
|
||||
etd.parity = opts->use_parity;
|
||||
memcpy(&etd.rnd[0], &opts->rn.rn[0], 7);
|
||||
memcpy(&etd.frnd[0], &opts->frn.frn[0], 4);
|
||||
|
||||
@@ -298,7 +285,6 @@ static int setkey_em4x70(const em4x70_cmd_input_setkey_t *opts) {
|
||||
|
||||
// TODO: change firmware to use per-cmd structures
|
||||
em4x70_data_t etd = {0};
|
||||
etd.parity = opts->use_parity;
|
||||
memcpy(&etd.crypt_key[0], &opts->key.k[0], 12);
|
||||
|
||||
clearCommandBuffer();
|
||||
@@ -315,7 +301,6 @@ static int brute_em4x70(const em4x70_cmd_input_brute_t *opts, em4x70_cmd_output_
|
||||
|
||||
// TODO: change firmware to use per-cmd structures
|
||||
em4x70_data_t etd = {0};
|
||||
etd.parity = opts->use_parity;
|
||||
etd.address = opts->block;
|
||||
memcpy(&etd.rnd[0], &opts->rn.rn[0], 7);
|
||||
memcpy(&etd.frnd[0], &opts->frn.frn[0], 4);
|
||||
@@ -366,7 +351,6 @@ static int unlock_em4x70(const em4x70_cmd_input_unlock_t *opts, em4x70_tag_info_
|
||||
|
||||
// TODO: change firmware to use per-cmd structures
|
||||
em4x70_data_t etd = {0};
|
||||
etd.parity = opts->use_parity;
|
||||
etd.pin = BYTES2UINT32(opts->pin);
|
||||
|
||||
clearCommandBuffer();
|
||||
@@ -386,7 +370,6 @@ static int setpin_em4x70(const em4x70_cmd_input_setpin_t *opts, em4x70_tag_info_
|
||||
|
||||
// TODO: change firmware to use per-cmd structures
|
||||
em4x70_data_t etd = {0};
|
||||
etd.parity = opts->use_parity;
|
||||
etd.pin = BYTES2UINT32(opts->pin);
|
||||
|
||||
clearCommandBuffer();
|
||||
@@ -429,7 +412,6 @@ static int recover_em4x70(const em4x70_cmd_input_recover_t *opts, em4x70_cmd_out
|
||||
|
||||
static int verify_auth_em4x70(const em4x70_cmd_input_verify_auth_t *opts) {
|
||||
em4x70_cmd_input_auth_t opts_auth = {
|
||||
.use_parity = opts->use_parity,
|
||||
.rn = opts->rn,
|
||||
.frn = opts->frn,
|
||||
};
|
||||
@@ -458,24 +440,19 @@ static int CmdEM4x70Info(const char *Cmd) {
|
||||
" ID48 does not use command parity (default).\n"
|
||||
" V4070 and EM4170 do require parity bit.",
|
||||
"lf em 4x70 info\n"
|
||||
"lf em 4x70 info --par -> adds parity bit to command\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_param_end
|
||||
};
|
||||
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
em4x70_cmd_input_info_t opts = {
|
||||
.use_parity = arg_get_lit(ctx, 0),
|
||||
};
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// Client command line parsing and validation complete ... now use the helper function
|
||||
em4x70_tag_info_t info;
|
||||
int result = get_em4x70_info(&opts, &info);
|
||||
int result = get_em4x70_info(&info);
|
||||
|
||||
if (result == PM3_ETIMEOUT) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
@@ -494,12 +471,10 @@ static int CmdEM4x70Write(const char *Cmd) {
|
||||
CLIParserInit(&ctx, "lf em 4x70 write",
|
||||
"Write EM4x70\n",
|
||||
"lf em 4x70 write -b 15 -d c0de -> write 'c0de' to block 15\n"
|
||||
"lf em 4x70 write -b 15 -d c0de --par -> adds parity bit to commands\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_int1("b", "block", "<dec>", "block/word address, dec"),
|
||||
arg_str1("d", "data", "<hex>", "data, 2 bytes"),
|
||||
arg_param_end
|
||||
@@ -508,12 +483,12 @@ static int CmdEM4x70Write(const char *Cmd) {
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
em4x70_cmd_input_writeblock_t opts = {
|
||||
.use_parity = arg_get_lit(ctx, 1),
|
||||
.block = arg_get_int_def(ctx, 2, 1),
|
||||
.block = arg_get_int_def(ctx, 1, 1),
|
||||
.value = {0}, // hex value macro exits function, so cannot be initialized here
|
||||
};
|
||||
|
||||
int value_len = 0;
|
||||
CLIGetHexWithReturn(ctx, 3, opts.value, &value_len);
|
||||
CLIGetHexWithReturn(ctx, 2, opts.value, &value_len);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (opts.block >= EM4X70_NUM_BLOCKS) {
|
||||
@@ -555,7 +530,6 @@ static int CmdEM4x70Brute(const char *Cmd) {
|
||||
);
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_int1("b", "block", "<dec>", "block/word address, dec"),
|
||||
arg_str1(NULL, "rnd", "<hex>", "Random 56-bit"),
|
||||
arg_str1(NULL, "frn", "<hex>", "F(RN) 28-bit as 4 hex bytes"),
|
||||
@@ -565,8 +539,7 @@ static int CmdEM4x70Brute(const char *Cmd) {
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
em4x70_cmd_input_brute_t opts = {
|
||||
.use_parity = arg_get_lit(ctx, 1),
|
||||
.block = arg_get_int_def(ctx, 2, 0),
|
||||
.block = arg_get_int_def(ctx, 1, 0),
|
||||
.rn = {{0}}, // hex value macro exits function, so cannot be initialized here
|
||||
.frn = {{0}}, // hex value macro exits function, so cannot be initialized here
|
||||
.partial_key_start = {0}, // hex value macro exits function, so cannot be initialized here
|
||||
@@ -579,15 +552,15 @@ static int CmdEM4x70Brute(const char *Cmd) {
|
||||
}
|
||||
|
||||
int rnd_len = 7;
|
||||
CLIGetHexWithReturn(ctx, 3, opts.rn.rn, &rnd_len);
|
||||
CLIGetHexWithReturn(ctx, 2, opts.rn.rn, &rnd_len);
|
||||
|
||||
int frnd_len = 4;
|
||||
CLIGetHexWithReturn(ctx, 4, opts.frn.frn, &frnd_len);
|
||||
CLIGetHexWithReturn(ctx, 3, opts.frn.frn, &frnd_len);
|
||||
|
||||
// would prefer to use above CLIGetHexWithReturn(), but it does not
|
||||
// appear to support optional arguments.
|
||||
uint32_t start_key = 0;
|
||||
int res = arg_get_u32_hexstr_def_nlen(ctx, 5, 0, &start_key, 2, true); // this stores in NATIVE ENDIAN
|
||||
int res = arg_get_u32_hexstr_def_nlen(ctx, 4, 0, &start_key, 2, true); // this stores in NATIVE ENDIAN
|
||||
if (res == 2) {
|
||||
PrintAndLogEx(WARNING, "start key parameter must be in range [0, FFFF]");
|
||||
CLIParserFree(ctx);
|
||||
@@ -635,11 +608,9 @@ static int CmdEM4x70Unlock(const char *Cmd) {
|
||||
" AAAAAAAA\n"
|
||||
" 00000000\n",
|
||||
"lf em 4x70 unlock -p 11223344 -> Unlock with PIN\n"
|
||||
"lf em 4x70 unlock -p 11223344 --par -> Unlock with PIN using parity commands\n"
|
||||
);
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_str1("p", "pin", "<hex>", "pin, 4 bytes"),
|
||||
arg_param_end
|
||||
};
|
||||
@@ -647,11 +618,10 @@ static int CmdEM4x70Unlock(const char *Cmd) {
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
em4x70_cmd_input_unlock_t opts = {
|
||||
.use_parity = arg_get_lit(ctx, 1),
|
||||
.pin = {0}, // hex value macro exits function, so cannot be initialized here
|
||||
};
|
||||
int pin_len = 0;
|
||||
CLIGetHexWithReturn(ctx, 2, opts.pin, &pin_len);
|
||||
CLIGetHexWithReturn(ctx, 1, opts.pin, &pin_len);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (pin_len != 4) {
|
||||
@@ -691,7 +661,6 @@ static int CmdEM4x70Auth(const char *Cmd) {
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_str1(NULL, "rnd", "<hex>", "Random 56-bit"),
|
||||
arg_str1(NULL, "frn", "<hex>", "F(RN) 28-bit as 4 hex bytes"),
|
||||
arg_param_end
|
||||
@@ -700,15 +669,14 @@ static int CmdEM4x70Auth(const char *Cmd) {
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
em4x70_cmd_input_auth_t opts = {
|
||||
.use_parity = arg_get_lit(ctx, 1),
|
||||
.rn = {{0}}, // hex value macro exits function, so cannot be initialized here
|
||||
.frn = {{0}}, // hex value macro exits function, so cannot be initialized here
|
||||
};
|
||||
int rn_len = 7;
|
||||
CLIGetHexWithReturn(ctx, 2, opts.rn.rn, &rn_len);
|
||||
CLIGetHexWithReturn(ctx, 1, opts.rn.rn, &rn_len);
|
||||
|
||||
int frn_len = 4;
|
||||
CLIGetHexWithReturn(ctx, 3, opts.frn.frn, &frn_len);
|
||||
CLIGetHexWithReturn(ctx, 2, opts.frn.frn, &frn_len);
|
||||
CLIParserFree(ctx);
|
||||
if (rn_len != 7) {
|
||||
PrintAndLogEx(FAILED, "Random number length must be 7 bytes, got %d", rn_len);
|
||||
@@ -738,23 +706,19 @@ static int CmdEM4x70SetPIN(const char *Cmd) {
|
||||
CLIParserInit(&ctx, "lf em 4x70 setpin",
|
||||
"Write new PIN\n",
|
||||
"lf em 4x70 setpin -p 11223344 -> Write new PIN\n"
|
||||
"lf em 4x70 setpin -p 11223344 --par -> Write new PIN using parity commands\n"
|
||||
);
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_str1("p", "pin", "<hex>", "pin, 4 bytes"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
em4x70_cmd_input_setpin_t opts = {
|
||||
.use_parity = arg_get_lit(ctx, 1),
|
||||
.pin = {0}, // hex value macro exits function, so cannot be initialized here
|
||||
};
|
||||
|
||||
int pin_len = 0;
|
||||
CLIGetHexWithReturn(ctx, 2, opts.pin, &pin_len);
|
||||
CLIGetHexWithReturn(ctx, 1, opts.pin, &pin_len);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (pin_len != 4) {
|
||||
@@ -789,19 +753,16 @@ static int CmdEM4x70SetKey(const char *Cmd) {
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_str1("k", "key", "<hex>", "Key as 12 hex bytes"),
|
||||
arg_param_end
|
||||
};
|
||||
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
em4x70_cmd_input_setkey_t opts = {
|
||||
.use_parity = arg_get_lit(ctx, 1),
|
||||
.key = {{0}}, // hex value macro exits function, so cannot be initialized here
|
||||
};
|
||||
int key_len = 12;
|
||||
CLIGetHexWithReturn(ctx, 2, opts.key.k, &key_len);
|
||||
CLIGetHexWithReturn(ctx, 1, opts.key.k, &key_len);
|
||||
CLIParserFree(ctx);
|
||||
if (key_len != 12) {
|
||||
PrintAndLogEx(FAILED, "Key length must be 12 bytes, got %d", key_len);
|
||||
@@ -823,7 +784,6 @@ static int CmdEM4x70SetKey(const char *Cmd) {
|
||||
|
||||
// Now verify authentication using the new key, to ensure it was correctly written
|
||||
em4x70_cmd_input_verify_auth_t opts_v = {
|
||||
.use_parity = opts.use_parity,
|
||||
//.rn = opts_auth.rn,
|
||||
//.frn = opts_auth.frn,
|
||||
//.grn = {{0}},
|
||||
@@ -909,7 +869,6 @@ static int CmdEM4x70Recover_ParseArgs(const char *Cmd, em4x70_cmd_input_recover_
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_str1("k", "key", "<hex>", "Key as 6 hex bytes"),
|
||||
arg_str1(NULL, "rnd", "<hex>", "Random 56-bit"),
|
||||
arg_str1(NULL, "frn", "<hex>", "F(RN) 28-bit as 4 hex bytes"),
|
||||
@@ -931,17 +890,16 @@ static int CmdEM4x70Recover_ParseArgs(const char *Cmd, em4x70_cmd_input_recover_
|
||||
// if all OK so far, convert to internal data structure
|
||||
if (PM3_SUCCESS == result) {
|
||||
// magic number == index in argtable above. Fragile technique!
|
||||
out_results->parity = arg_get_lit(ctx, 1);
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 2), &(out_results->key.k[0]), 12, &key_len)) {
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 1), &(out_results->key.k[0]), 12, &key_len)) {
|
||||
result = PM3_ESOFT;
|
||||
}
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 3), &(out_results->nonce.rn[0]), 7, &rnd_len)) {
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 2), &(out_results->nonce.rn[0]), 7, &rnd_len)) {
|
||||
result = PM3_ESOFT;
|
||||
}
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 4), &(out_results->frn.frn[0]), 4, &frn_len)) {
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 3), &(out_results->frn.frn[0]), 4, &frn_len)) {
|
||||
result = PM3_ESOFT;
|
||||
}
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 5), &(out_results->grn.grn[0]), 3, &grn_len)) {
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 4), &(out_results->grn.grn[0]), 3, &grn_len)) {
|
||||
result = PM3_ESOFT;
|
||||
}
|
||||
//out_results->verify = arg_get_lit(ctx, 6);
|
||||
@@ -1112,7 +1070,6 @@ static int CmdEM4x70AutoRecover_ParseArgs(const char *Cmd, em4x70_cmd_input_reco
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0(NULL, "par", "Add parity bit when sending commands"),
|
||||
arg_str1(NULL, "rnd", "<hex>", "Random 56-bit from known-good authentication"),
|
||||
arg_str1(NULL, "frn", "<hex>", "F(RN) 28-bit as 4 hex bytes from known-good authentication"),
|
||||
arg_str1(NULL, "grn", "<hex>", "G(RN) 20-bit as 3 hex bytes from known-good authentication"),
|
||||
@@ -1125,10 +1082,9 @@ static int CmdEM4x70AutoRecover_ParseArgs(const char *Cmd, em4x70_cmd_input_reco
|
||||
int rnd_len = 0; // must be 7 bytes hex data
|
||||
int frn_len = 0; // must be 4 bytes hex data
|
||||
int grn_len = 0; // must be 3 bytes hex data
|
||||
out_results->parity = arg_get_lit(ctx, 1);
|
||||
CLIGetHexWithReturn(ctx, 2, out_results->nonce.rn, &rnd_len);
|
||||
CLIGetHexWithReturn(ctx, 3, out_results->frn.frn, &frn_len);
|
||||
CLIGetHexWithReturn(ctx, 4, out_results->grn.grn, &grn_len);
|
||||
CLIGetHexWithReturn(ctx, 1, out_results->nonce.rn, &rnd_len);
|
||||
CLIGetHexWithReturn(ctx, 2, out_results->frn.frn, &frn_len);
|
||||
CLIGetHexWithReturn(ctx, 3, out_results->grn.grn, &grn_len);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (rnd_len != 7) {
|
||||
@@ -1190,7 +1146,6 @@ static int CmdEM4x70AutoRecover(const char *Cmd) {
|
||||
PrintAndLogEx(HINT, "Hint: " _YELLOW_("lf em 4x70 auth --rnd %s --frn %s"), rnd_string, frn_string);
|
||||
|
||||
em4x70_cmd_input_auth_t opts_auth = {
|
||||
.use_parity = opts.parity,
|
||||
.rn = opts.nonce,
|
||||
.frn = opts.frn,
|
||||
};
|
||||
@@ -1234,7 +1189,6 @@ static int CmdEM4x70AutoRecover(const char *Cmd) {
|
||||
PrintAndLogEx(HINT, "Hint: " _YELLOW_("lf em 4x70 write -b %d -d 0000"), block);
|
||||
|
||||
em4x70_cmd_input_writeblock_t opt_write_zeros = {
|
||||
.use_parity = opts.parity,
|
||||
.block = block,
|
||||
.value = {0x00, 0x00},
|
||||
};
|
||||
@@ -1255,7 +1209,6 @@ static int CmdEM4x70AutoRecover(const char *Cmd) {
|
||||
PrintAndLogEx(HINT, "Hint: " _YELLOW_("lf em 4x70 brute -b %d --rnd %s --frn %s"), block, rnd_string, frn_string);
|
||||
|
||||
em4x70_cmd_input_brute_t opts_brute = {
|
||||
.use_parity = opts.parity,
|
||||
.block = block,
|
||||
.rn = opts.nonce,
|
||||
.frn = opts.frn,
|
||||
@@ -1294,7 +1247,6 @@ static int CmdEM4x70AutoRecover(const char *Cmd) {
|
||||
PrintAndLogEx(HINT, "Hint: " _YELLOW_("lf em 4x70 write -b %d -d %02X%02X"), block, brute.partial_key[0], brute.partial_key[1]);
|
||||
|
||||
em4x70_cmd_input_writeblock_t opt_write_zeros2 = {
|
||||
.use_parity = opts.parity,
|
||||
.block = block,
|
||||
.value = {brute.partial_key[0], brute.partial_key[1]},
|
||||
};
|
||||
@@ -1354,7 +1306,6 @@ static int CmdEM4x70AutoRecover(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "Step 6. Verify which potential key is actually on the tag");
|
||||
|
||||
em4x70_cmd_input_verify_auth_t opts_v = {
|
||||
.use_parity = opts.parity,
|
||||
//.rn = {{0}},
|
||||
//.frn = {{0}},
|
||||
//.grn = {{0}},
|
||||
@@ -1521,7 +1472,7 @@ static int CmdHelp(const char *Cmd);
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"brute", CmdEM4x70Brute, IfPm3EM4x70, "Bruteforce EM4X70 to find partial key"},
|
||||
{"info", CmdEM4x70Info, IfPm3EM4x70, "Tag information EM4x70"},
|
||||
{"info", CmdEM4x70Info, IfPm3EM4x70, "Tag information"},
|
||||
{"write", CmdEM4x70Write, IfPm3EM4x70, "Write EM4x70"},
|
||||
{"unlock", CmdEM4x70Unlock, IfPm3EM4x70, "Unlock EM4x70 for writing"},
|
||||
{"auth", CmdEM4x70Auth, IfPm3EM4x70, "Authenticate EM4x70"},
|
||||
@@ -1554,9 +1505,8 @@ int CmdLFEM4X70(const char *Cmd) {
|
||||
// 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);
|
||||
int result = get_em4x70_info(&info);
|
||||
|
||||
if (result == PM3_ETIMEOUT) { // consider removing this output?
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
|
||||
@@ -2468,7 +2468,7 @@ static command_t CommandTable[] = {
|
||||
{"hts", CmdLFHitagS, AlwaysAvailable, "{ Hitag S/8211 operations }"},
|
||||
{"htu", CmdLFHitagU, AlwaysAvailable, "{ Hitag µ/8265 operations }"},
|
||||
{"-----------", CmdHelp, IfPm3Hitag, "------------------------ " _CYAN_("General") " ------------------------"},
|
||||
{"info", CmdLFHitagInfo, IfPm3Hitag, "Hitag 2 tag information"},
|
||||
{"info", CmdLFHitagInfo, IfPm3Hitag, "Tag information"},
|
||||
{"reader", CmdLFHitagReader, IfPm3Hitag, "Act like a Hitag 2 reader"},
|
||||
{"test", CmdLFHitag2Selftest, AlwaysAvailable, "Perform self tests"},
|
||||
{"-----------", CmdHelp, IfPm3Hitag, "----------------------- " _CYAN_("Operations") " -----------------------"},
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
#include "cmdlfem4x05.h" //
|
||||
#include "cliparser.h"
|
||||
|
||||
// 8 bytes + null terminator
|
||||
#define PAC_ID_LEN (8 + 1)
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
// PAC_8byte format: preamble (8 mark/idle bits), ascii STX (02), ascii '2' (32), ascii '0' (30), ascii bytes 0..7 (cardid), then xor checksum of cardid bytes
|
||||
@@ -160,12 +163,13 @@ int demodPac(bool verbose) {
|
||||
uint32_t raw3 = bytebits_to_byte(g_DemodBuffer + 64, 32);
|
||||
uint32_t raw4 = bytebits_to_byte(g_DemodBuffer + 96, 32);
|
||||
|
||||
const size_t idLen = 9; // 8 bytes + null terminator
|
||||
uint8_t cardid[idLen];
|
||||
// 8 bytes + null terminator
|
||||
uint8_t cardid[PAC_ID_LEN];
|
||||
int retval = pac_buf_to_cardid(g_DemodBuffer, g_DemodBufferLen, cardid, sizeof(cardid));
|
||||
|
||||
if (retval == PM3_SUCCESS)
|
||||
if (retval == PM3_SUCCESS) {
|
||||
PrintAndLogEx(SUCCESS, "PAC/Stanley - Card: " _GREEN_("%s") ", Raw: %08X%08X%08X%08X", cardid, raw1, raw2, raw3, raw4);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ int clone_t55xx_tag(uint32_t *blockdata, uint8_t numblocks) {
|
||||
ng.flags = 0;
|
||||
|
||||
SendCommandNG(CMD_LF_T55XX_WRITEBL, (uint8_t *)&ng, sizeof(ng));
|
||||
if (!WaitForResponseTimeout(CMD_LF_T55XX_WRITEBL, &resp, T55XX_WRITE_TIMEOUT)) {
|
||||
if (WaitForResponseTimeout(CMD_LF_T55XX_WRITEBL, &resp, T55XX_WRITE_TIMEOUT) == false) {
|
||||
PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -664,7 +664,7 @@ int t55xxWrite(uint8_t block, bool page1, bool usepwd, bool testMode, uint32_t p
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_T55XX_WRITEBL, (uint8_t *)&ng, sizeof(ng));
|
||||
if (!WaitForResponseTimeout(CMD_LF_T55XX_WRITEBL, &resp, 2000)) {
|
||||
if (WaitForResponseTimeout(CMD_LF_T55XX_WRITEBL, &resp, 2000) == false) {
|
||||
PrintAndLogEx(ERR, "Error occurred, device did not ACK write operation.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -1992,7 +1992,7 @@ static int CmdT55xxDangerousRaw(const char *Cmd) {
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_T55XX_DANGERRAW, (uint8_t *)&ng, sizeof(ng));
|
||||
if (!WaitForResponseTimeout(CMD_LF_T55XX_DANGERRAW, &resp, 2000)) {
|
||||
if (WaitForResponseTimeout(CMD_LF_T55XX_DANGERRAW, &resp, 2000) == false) {
|
||||
PrintAndLogEx(ERR, "Error occurred, device did not ACK write operation.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -2840,7 +2840,7 @@ bool AcquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password, u
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_LF_T55XX_READBL, (uint8_t *)&payload, sizeof(payload));
|
||||
if (!WaitForResponseTimeout(CMD_LF_T55XX_READBL, NULL, 2500)) {
|
||||
if (WaitForResponseTimeout(CMD_LF_T55XX_READBL, NULL, 2500) == false) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
return false;
|
||||
}
|
||||
@@ -3435,7 +3435,7 @@ static int CmdT55xxChkPwds(const char *Cmd) {
|
||||
PacketResponseNG resp;
|
||||
|
||||
uint8_t timeout = 0;
|
||||
while (!WaitForResponseTimeout(CMD_LF_T55XX_CHK_PWDS, &resp, 2000)) {
|
||||
while (WaitForResponseTimeout(CMD_LF_T55XX_CHK_PWDS, &resp, 2000) == false) {
|
||||
timeout++;
|
||||
PrintAndLogEx(NORMAL, "." NOLF);
|
||||
if (timeout > 180) {
|
||||
|
||||
@@ -172,7 +172,7 @@ static int CmdVikingClone(const char *Cmd) {
|
||||
|
||||
SendCommandNG(CMD_LF_VIKING_CLONE, (uint8_t *)&payload, sizeof(payload));
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_LF_VIKING_CLONE, &resp, T55XX_WRITE_TIMEOUT)) {
|
||||
if (WaitForResponseTimeout(CMD_LF_VIKING_CLONE, &resp, T55XX_WRITE_TIMEOUT) == false) {
|
||||
PrintAndLogEx(ERR, "Error occurred, device did not respond during write operation.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
@@ -663,7 +663,7 @@ static int CmdSmartUpgrade(const char *Cmd) {
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_SMART_UPLOAD, (uint8_t *)&upload, sizeof(upload));
|
||||
if (!WaitForResponseTimeout(CMD_SMART_UPLOAD, &resp, 2000)) {
|
||||
if (WaitForResponseTimeout(CMD_SMART_UPLOAD, &resp, 2000) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
free(firmware);
|
||||
return PM3_ETIMEOUT;
|
||||
@@ -695,7 +695,7 @@ static int CmdSmartUpgrade(const char *Cmd) {
|
||||
|
||||
free(firmware);
|
||||
SendCommandNG(CMD_SMART_UPGRADE, (uint8_t *)&payload, sizeof(payload));
|
||||
if (!WaitForResponseTimeout(CMD_SMART_UPGRADE, &resp, 2500)) {
|
||||
if (WaitForResponseTimeout(CMD_SMART_UPGRADE, &resp, 2500) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
@@ -876,7 +876,7 @@ static int CmdSmartSetClock(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_SMART_SETCLOCK, (uint8_t *)&payload, sizeof(payload));
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_SMART_SETCLOCK, &resp, 2500)) {
|
||||
if (WaitForResponseTimeout(CMD_SMART_SETCLOCK, &resp, 2500) == false) {
|
||||
PrintAndLogEx(WARNING, "smart card select failed");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ static int usart_tx(uint8_t *data, size_t len) {
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_USART_TX, data, len);
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_USART_TX, &resp, 1000)) {
|
||||
if (WaitForResponseTimeout(CMD_USART_TX, &resp, 1000) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
return resp.status;
|
||||
@@ -49,7 +49,7 @@ static int usart_rx(uint8_t *data, size_t *len, uint32_t waittime) {
|
||||
payload.waittime = waittime;
|
||||
SendCommandNG(CMD_USART_RX, (uint8_t *)&payload, sizeof(payload));
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_USART_RX, &resp, waittime + 500)) {
|
||||
if (WaitForResponseTimeout(CMD_USART_RX, &resp, waittime + 500) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
if (resp.status == PM3_SUCCESS) {
|
||||
@@ -99,7 +99,7 @@ static int set_usart_config(uint32_t baudrate, uint8_t parity) {
|
||||
payload.parity = parity;
|
||||
SendCommandNG(CMD_USART_CONFIG, (uint8_t *)&payload, sizeof(payload));
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_USART_CONFIG, &resp, 1000)) {
|
||||
if (WaitForResponseTimeout(CMD_USART_CONFIG, &resp, 1000) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
return resp.status;
|
||||
|
||||
+2
-2
@@ -871,7 +871,7 @@ int TestProxmark(pm3_device_t *dev) {
|
||||
#endif
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeoutW(CMD_PING, &resp, timeout, false) == 0) {
|
||||
if (WaitForResponseTimeoutW(CMD_PING, &resp, timeout, false) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
@@ -881,7 +881,7 @@ int TestProxmark(pm3_device_t *dev) {
|
||||
}
|
||||
|
||||
SendCommandNG(CMD_CAPABILITIES, NULL, 0);
|
||||
if (WaitForResponseTimeoutW(CMD_CAPABILITIES, &resp, 1000, false) == 0) {
|
||||
if (WaitForResponseTimeoutW(CMD_CAPABILITIES, &resp, 1000, false) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
+41
-25
@@ -165,6 +165,7 @@ static char *filenamemcopy(const char *preferredName, const char *suffix) {
|
||||
|
||||
char *fileName = (char *) calloc(strlen(preferredName) + strlen(suffix) + 1, sizeof(uint8_t));
|
||||
if (fileName == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -993,8 +994,8 @@ int loadFile_safeEx(const char *preferredName, const char *suffix, void **pdata,
|
||||
}
|
||||
|
||||
*pdata = calloc(fsize, sizeof(uint8_t));
|
||||
if (!*pdata) {
|
||||
PrintAndLogEx(FAILED, "error, cannot allocate memory");
|
||||
if (*pdata == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
fclose(f);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
@@ -1044,8 +1045,8 @@ int loadFileEML_safe(const char *preferredName, void **pdata, size_t *datalen) {
|
||||
}
|
||||
|
||||
*pdata = calloc(fsize, sizeof(uint8_t));
|
||||
if (!*pdata) {
|
||||
PrintAndLogEx(FAILED, "error, cannot allocate memory");
|
||||
if (*pdata == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
fclose(f);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
@@ -1091,6 +1092,7 @@ int loadFileEML_safe(const char *preferredName, void **pdata, size_t *datalen) {
|
||||
|
||||
uint8_t *newdump = realloc(*pdata, counter);
|
||||
if (newdump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
free(*pdata);
|
||||
return PM3_EMALLOC;
|
||||
} else {
|
||||
@@ -1366,8 +1368,8 @@ int loadFileMCT_safe(const char *preferredName, void **pdata, size_t *datalen) {
|
||||
}
|
||||
|
||||
*pdata = calloc(fsize, sizeof(uint8_t));
|
||||
if (!*pdata) {
|
||||
PrintAndLogEx(FAILED, "error, cannot allocate memory");
|
||||
if (*pdata == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
fclose(f);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
@@ -1414,6 +1416,7 @@ int loadFileMCT_safe(const char *preferredName, void **pdata, size_t *datalen) {
|
||||
|
||||
uint8_t *newdump = realloc(*pdata, counter);
|
||||
if (newdump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
free(*pdata);
|
||||
return PM3_EMALLOC;
|
||||
} else {
|
||||
@@ -2218,6 +2221,8 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u
|
||||
return loadFileDICTIONARYEx(preferredName, data, 0, datalen, keylen, keycnt, 0, NULL, true);
|
||||
}
|
||||
|
||||
// this function handles exceptional large dictionaries,
|
||||
// using start position and end position parameters.
|
||||
int loadFileDICTIONARYEx(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen, uint8_t keylen, uint32_t *keycnt,
|
||||
size_t startFilePosition, size_t *endFilePosition, bool verbose) {
|
||||
|
||||
@@ -2243,17 +2248,17 @@ int loadFileDICTIONARYEx(const char *preferredName, void *data, size_t maxdatale
|
||||
int retval = PM3_SUCCESS;
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) {
|
||||
if (f == NULL) {
|
||||
PrintAndLogEx(WARNING, "file not found or locked `" _YELLOW_("%s") "`", path);
|
||||
retval = PM3_EFILE;
|
||||
goto out;
|
||||
free(path);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
|
||||
if (startFilePosition) {
|
||||
if (fseek(f, startFilePosition, SEEK_SET) < 0) {
|
||||
fclose(f);
|
||||
retval = PM3_EFILE;
|
||||
goto out;
|
||||
free(path);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2261,6 +2266,7 @@ int loadFileDICTIONARYEx(const char *preferredName, void *data, size_t maxdatale
|
||||
|
||||
// read file
|
||||
while (!feof(f)) {
|
||||
|
||||
long filepos = ftell(f);
|
||||
|
||||
if (!fgets(line, sizeof(line), f)) {
|
||||
@@ -2318,7 +2324,7 @@ int loadFileDICTIONARYEx(const char *preferredName, void *data, size_t maxdatale
|
||||
if (keycnt) {
|
||||
*keycnt = vkeycnt;
|
||||
}
|
||||
out:
|
||||
|
||||
free(path);
|
||||
return retval;
|
||||
}
|
||||
@@ -2343,11 +2349,10 @@ int loadFileDICTIONARY_safe_ex(const char *preferredName, const char *suffix, vo
|
||||
// mf desfire == 3des3k 24 bytes
|
||||
// iclass == 8 bytes
|
||||
// default to 6 bytes.
|
||||
if (keylen != 4 && keylen != 5 && keylen != 6 && keylen != 8 && keylen != 16 && keylen != 24) {
|
||||
if (keylen != 4 && keylen != 5 && keylen != 6 && keylen != 8 && keylen != 12 && keylen != 16 && keylen != 24) {
|
||||
keylen = 6;
|
||||
}
|
||||
|
||||
size_t mem_size;
|
||||
size_t block_size = 10 * keylen;
|
||||
|
||||
// double up since its chars
|
||||
@@ -2358,13 +2363,14 @@ int loadFileDICTIONARY_safe_ex(const char *preferredName, const char *suffix, vo
|
||||
// allocate some space for the dictionary
|
||||
*pdata = calloc(block_size, sizeof(uint8_t));
|
||||
if (*pdata == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
free(path);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
mem_size = block_size;
|
||||
size_t mem_size = block_size;
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) {
|
||||
if (f == NULL) {
|
||||
PrintAndLogEx(WARNING, "file not found or locked `" _YELLOW_("%s") "`", path);
|
||||
retval = PM3_EFILE;
|
||||
goto out;
|
||||
@@ -2377,9 +2383,10 @@ int loadFileDICTIONARY_safe_ex(const char *preferredName, const char *suffix, vo
|
||||
if ((*keycnt * (keylen >> 1)) >= mem_size) {
|
||||
|
||||
mem_size += block_size;
|
||||
*pdata = realloc(*pdata, mem_size);
|
||||
|
||||
*pdata = realloc(*pdata, mem_size);
|
||||
if (*pdata == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
retval = PM3_EFILE;
|
||||
fclose(f);
|
||||
goto out;
|
||||
@@ -2395,6 +2402,7 @@ int loadFileDICTIONARY_safe_ex(const char *preferredName, const char *suffix, vo
|
||||
|
||||
// remove newline/linefeed
|
||||
str_cleanrn(line, strlen(line));
|
||||
str_trim(line);
|
||||
|
||||
// smaller keys than expected is skipped
|
||||
if (strlen(line) < keylen) {
|
||||
@@ -2412,6 +2420,7 @@ int loadFileDICTIONARY_safe_ex(const char *preferredName, const char *suffix, vo
|
||||
|
||||
// larger keys than expected is skipped
|
||||
if (strlen(line) > keylen) {
|
||||
PrintAndLogEx(INFO, "too long line (%zu) ... %s", strlen(line), line);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2473,7 +2482,7 @@ int loadFileBinaryKey(const char *preferredName, const char *suffix, void **keya
|
||||
|
||||
*keya = calloc(fsize, sizeof(uint8_t));
|
||||
if (*keya == NULL) {
|
||||
PrintAndLogEx(FAILED, "error, cannot allocate memory");
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
fclose(f);
|
||||
free(path);
|
||||
return PM3_EMALLOC;
|
||||
@@ -2483,7 +2492,7 @@ int loadFileBinaryKey(const char *preferredName, const char *suffix, void **keya
|
||||
|
||||
*keyb = calloc(fsize, sizeof(uint8_t));
|
||||
if (*keyb == NULL) {
|
||||
PrintAndLogEx(FAILED, "error, cannot allocate memory");
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
fclose(f);
|
||||
free(*keya);
|
||||
free(path);
|
||||
@@ -2663,6 +2672,7 @@ static int convert_plain_mfu_dump(uint8_t **dump, size_t *dumplen, bool verbose)
|
||||
|
||||
mfu_dump_t *mfu = (mfu_dump_t *) calloc(sizeof(mfu_dump_t), sizeof(uint8_t));
|
||||
if (mfu == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
@@ -2700,6 +2710,7 @@ static int convert_old_mfu_dump(uint8_t **dump, size_t *dumplen, bool verbose) {
|
||||
|
||||
mfu_dump_t *mfu_dump = (mfu_dump_t *) calloc(sizeof(mfu_dump_t), sizeof(uint8_t));
|
||||
if (mfu_dump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
@@ -2846,6 +2857,7 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea
|
||||
// explicit absolute (/) or relative path (./) => try only to match it directly
|
||||
char *filename = calloc(strlen(searchname) + 1, sizeof(char));
|
||||
if (filename == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
@@ -3031,18 +3043,22 @@ out:
|
||||
|
||||
int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix, bool silent) {
|
||||
|
||||
if (foundpath == NULL)
|
||||
if (foundpath == NULL) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (searchname == NULL || strlen(searchname) == 0)
|
||||
if (searchname == NULL || strlen(searchname) == 0) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (is_directory(searchname))
|
||||
if (is_directory(searchname)) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
char *filename = filenamemcopy(searchname, suffix);
|
||||
if (filename == NULL)
|
||||
if (filename == NULL) {
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
if (strlen(filename) == 0) {
|
||||
free(filename);
|
||||
@@ -3081,7 +3097,7 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl
|
||||
case JSON: {
|
||||
*pdump = calloc(maxdumplen, sizeof(uint8_t));
|
||||
if (*pdump == NULL) {
|
||||
PrintAndLogEx(WARNING, "fail, cannot allocate memory");
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
@@ -3121,7 +3137,7 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl
|
||||
|
||||
*pdump = calloc(maxdumplen, sizeof(uint8_t));
|
||||
if (*pdump == NULL) {
|
||||
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
res = loadFileNFC_safe(fn, *pdump, maxdumplen, dumplen, dumptype);
|
||||
|
||||
+12
-40
@@ -657,7 +657,7 @@ void invert_hash0(uint8_t k[8]) {
|
||||
x_num_to_bytes(original_z, sizeof(original_z), des_pre_image);
|
||||
|
||||
if (image_match) {
|
||||
PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_GREEN_("valid") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image)));
|
||||
PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_GREEN_("ok") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image)));
|
||||
} else {
|
||||
|
||||
if (g_debugMode > 0) {
|
||||
@@ -982,48 +982,20 @@ static int doTestsWithKnownInputs(void) {
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool readKeyFile(uint8_t *key, size_t keylen) {
|
||||
|
||||
bool retval = false;
|
||||
size_t len = 0;
|
||||
uint8_t *keyptr = NULL;
|
||||
if (loadFile_safe("iclass_key.bin", "", (void **)&keyptr, &len) != PM3_SUCCESS) {
|
||||
return retval;
|
||||
}
|
||||
if (keylen == len) {
|
||||
memcpy(key, keyptr, keylen);
|
||||
retval = true;
|
||||
}
|
||||
free(keyptr);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int doKeyTests(void) {
|
||||
|
||||
PrintAndLogEx(INFO, "Checking if the master key is present (iclass_key.bin)...");
|
||||
uint8_t key[8] = {0};
|
||||
if (readKeyFile(key, sizeof(key)) == false) {
|
||||
PrintAndLogEx(FAILED, "Master key not present, will not be able to do all testcases");
|
||||
} else {
|
||||
|
||||
//Test if it's the right key...
|
||||
uint8_t i;
|
||||
uint8_t j = 0;
|
||||
for (i = 0; i < ARRAYLEN(key); i++)
|
||||
j += key[i];
|
||||
|
||||
if (j != 185) {
|
||||
PrintAndLogEx(INFO, "A key was loaded, but it does not seem to be the correct one. Aborting these tests");
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "Key present");
|
||||
PrintAndLogEx(SUCCESS, "Checking key parity...");
|
||||
des_checkParity(key);
|
||||
|
||||
// Test hashing functions
|
||||
PrintAndLogEx(SUCCESS, "The following tests require the correct 8-byte master key");
|
||||
testKeyDiversificationWithMasterkeyTestcases(key);
|
||||
}
|
||||
uint8_t key[8] = { 0xAE, 0xA6, 0x84, 0xA6, 0xDA, 0xB2, 0x32, 0x78 };
|
||||
uint8_t parity[8] = {0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
key[i] += parity[i];
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Checking key parity...");
|
||||
des_checkParity(key);
|
||||
|
||||
// Test hashing functions
|
||||
PrintAndLogEx(SUCCESS, "The following tests require the correct 8-byte master key");
|
||||
testKeyDiversificationWithMasterkeyTestcases(key);
|
||||
PrintAndLogEx(INFO, "Testing key diversification with non-sensitive keys...");
|
||||
return doTestsWithKnownInputs();
|
||||
}
|
||||
|
||||
@@ -2274,10 +2274,10 @@ int DesfireUpdateRecord(DesfireContext_t *dctx, uint8_t fnum, uint32_t recnum, u
|
||||
|
||||
static void PrintKeySettingsPICC(uint8_t keysettings, uint8_t numkeys, bool print2ndbyte) {
|
||||
PrintAndLogEx(SUCCESS, "PICC level rights");
|
||||
PrintAndLogEx(SUCCESS, "[%c...] CMK Configuration changeable : %s", (keysettings & (1 << 3)) ? '1' : '0', (keysettings & (1 << 3)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "[.%c..] CMK required for create/delete : %s", (keysettings & (1 << 2)) ? '1' : '0', (keysettings & (1 << 2)) ? _GREEN_("NO") : "YES");
|
||||
PrintAndLogEx(SUCCESS, "[..%c.] Directory list access with CMK : %s", (keysettings & (1 << 1)) ? '1' : '0', (keysettings & (1 << 1)) ? _GREEN_("NO") : "YES");
|
||||
PrintAndLogEx(SUCCESS, "[...%c] CMK is changeable : %s", (keysettings & (1 << 0)) ? '1' : '0', (keysettings & (1 << 0)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "[%c...] CMK Configuration changeable : %s", (keysettings & (1 << 3)) ? '1' : '0', (keysettings & (1 << 3)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "[.%c..] CMK required for create/delete : %s", (keysettings & (1 << 2)) ? '1' : '0', (keysettings & (1 << 2)) ? _GREEN_("NO") : _RED_("YES"));
|
||||
PrintAndLogEx(SUCCESS, "[..%c.] CMK required for AID list / GetKeySettings : %s", (keysettings & (1 << 1)) ? '1' : '0', (keysettings & (1 << 1)) ? _GREEN_("NO") : _RED_("YES"));
|
||||
PrintAndLogEx(SUCCESS, "[...%c] CMK is changeable : %s", (keysettings & (1 << 0)) ? '1' : '0', (keysettings & (1 << 0)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "");
|
||||
|
||||
if (print2ndbyte) {
|
||||
@@ -2314,10 +2314,10 @@ static void PrintKeySettingsApp(uint8_t keysettings, uint8_t numkeys, bool print
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "[%c...] AMK Configuration changeable : %s", (keysettings & (1 << 3)) ? '1' : '0', (keysettings & (1 << 3)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "[.%c..] AMK required for create/delete : %s", (keysettings & (1 << 2)) ? '1' : '0', (keysettings & (1 << 2)) ? _GREEN_("NO") : "YES");
|
||||
PrintAndLogEx(SUCCESS, "[..%c.] Directory list access with AMK : %s", (keysettings & (1 << 1)) ? '1' : '0', (keysettings & (1 << 1)) ? _GREEN_("NO") : "YES");
|
||||
PrintAndLogEx(SUCCESS, "[...%c] AMK is changeable : %s", (keysettings & (1 << 0)) ? '1' : '0', (keysettings & (1 << 0)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "[%c...] AMK Configuration changeable : %s", (keysettings & (1 << 3)) ? '1' : '0', (keysettings & (1 << 3)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "[.%c..] AMK required for create/delete : %s", (keysettings & (1 << 2)) ? '1' : '0', (keysettings & (1 << 2)) ? _GREEN_("NO") : _RED_("YES"));
|
||||
PrintAndLogEx(SUCCESS, "[..%c.] AMK required for FID list / GetKeySettings : %s", (keysettings & (1 << 1)) ? '1' : '0', (keysettings & (1 << 1)) ? _GREEN_("NO") : _RED_("YES"));
|
||||
PrintAndLogEx(SUCCESS, "[...%c] AMK is changeable : %s", (keysettings & (1 << 0)) ? '1' : '0', (keysettings & (1 << 0)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
PrintAndLogEx(SUCCESS, "");
|
||||
|
||||
if (print2ndbyte) {
|
||||
|
||||
@@ -106,6 +106,10 @@ void DesfireSetKdf(DesfireContext_t *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, ui
|
||||
}
|
||||
}
|
||||
|
||||
void DesfireSetSecureChannel(DesfireContext_t *ctx, DesfireSecureChannel schann) {
|
||||
ctx->secureChannel = schann;
|
||||
}
|
||||
|
||||
bool DesfireIsAuthenticated(DesfireContext_t *dctx) {
|
||||
return dctx->secureChannel != DACNone;
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ void DesfireSetKey(DesfireContext_t *ctx, uint8_t keyNum, DesfireCryptoAlgorithm
|
||||
void DesfireSetKeyNoClear(DesfireContext_t *ctx, uint8_t keyNum, DesfireCryptoAlgorithm keyType, uint8_t *key);
|
||||
void DesfireSetCommandSet(DesfireContext_t *ctx, DesfireCommandSet cmdSet);
|
||||
void DesfireSetCommMode(DesfireContext_t *ctx, DesfireCommunicationMode commMode);
|
||||
void DesfireSetSecureChannel(DesfireContext_t *ctx, DesfireSecureChannel schann);
|
||||
void DesfireSetKdf(DesfireContext_t *ctx, uint8_t kdfAlgo, uint8_t *kdfInput, uint8_t kdfInputLen);
|
||||
bool DesfireIsAuthenticated(DesfireContext_t *dctx);
|
||||
size_t DesfireGetMACLength(DesfireContext_t *ctx);
|
||||
|
||||
Loaded 100 of 195 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user