From c47578c04884cfa5ae5ec9830492d6e37cb3bf5f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 1 Aug 2024 16:43:25 +0200 Subject: [PATCH] sort mfc tools --- .gitignore | 11 ----- Makefile | 33 ++++++-------- armsrc/mifaresim.c | 4 +- client/src/cmdhflist.c | 2 +- tools/mf_fudan_rf08s/Makefile | 33 -------------- tools/mf_nonce_brute/Makefile | 25 ----------- tools/mfc/card_only/.gitignore | 13 ++++++ tools/mfc/card_only/Makefile | 36 ++++++++++++++++ tools/{mfkey => mfc/card_only}/nested_util.c | 0 tools/{mfkey => mfc/card_only}/nested_util.h | 0 .../{nonce2key => mfc/card_only}/nonce2key.c | 3 +- .../card_only/staticnested_0nt.c} | 0 .../card_only/staticnested_1nt.c} | 0 .../card_only/staticnested_2nt.c} | 0 tools/mfc/card_only/staticnested_2nt_test.sh | 9 ++++ .../card_only/staticnested_2x1nt_rf08s.c} | 4 +- .../staticnested_2x1nt_rf08s_1key.c} | 0 tools/mfc/card_reader/.gitignore | 10 +++++ tools/{mfkey => mfc/card_reader}/Makefile | 23 +++++----- .../card_reader}/iso14443crc.c | 0 .../card_reader}/iso14443crc.h | 0 .../card_reader}/mf_nonce_brute.c | 0 .../card_reader/mf_nonce_brute_examples.md} | 4 +- .../card_reader}/mf_trace_brute.c | 0 tools/{mfkey => mfc/card_reader}/mfkey32.c | 0 tools/{mfkey => mfc/card_reader}/mfkey32v2.c | 0 tools/{mfkey => mfc/card_reader}/mfkey64.c | 0 .../card_reader/mfkey_examples.md} | 43 +++++++++++-------- .../card_reader}/protocol.h | 0 .../card_reader}/sleep.c | 0 .../card_reader}/sleep.h | 0 .../card_reader}/util_posix.c | 0 .../card_reader}/util_posix.h | 0 tools/{ => mfc}/pm3_eml2lower.sh | 0 tools/{ => mfc}/pm3_eml2mfd.py | 0 tools/{ => mfc}/pm3_eml2upper.sh | 0 tools/{ => mfc}/pm3_eml_mfd_test.py | 0 tools/{ => mfc}/pm3_gen_dictionary.py | 0 tools/{ => mfc}/pm3_gen_mfsim.sh | 0 tools/{ => mfc}/pm3_key_file_diff.py | 0 tools/{ => mfc}/pm3_mf7b_wipe.py | 0 tools/{ => mfc}/pm3_mfd2eml.py | 0 tools/{ => mfc}/pm3_mfdread.py | 0 tools/mfkey/.gitignore | 7 --- tools/mfkey/test_static.sh | 9 ---- tools/nonce2key/Makefile | 19 -------- tools/nonce2key/readme.txt | 7 --- tools/pm3_tears_for_fears.py | 0 tools/pm3_tests.sh | 23 +++++++--- 49 files changed, 143 insertions(+), 175 deletions(-) delete mode 100644 tools/mf_fudan_rf08s/Makefile delete mode 100644 tools/mf_nonce_brute/Makefile create mode 100644 tools/mfc/card_only/.gitignore create mode 100644 tools/mfc/card_only/Makefile rename tools/{mfkey => mfc/card_only}/nested_util.c (100%) rename tools/{mfkey => mfc/card_only}/nested_util.h (100%) rename tools/{nonce2key => mfc/card_only}/nonce2key.c (91%) rename tools/{mf_fudan_rf08s/rf08s_nested.c => mfc/card_only/staticnested_0nt.c} (100%) rename tools/{mf_fudan_rf08s/rf08s_nested_known.c => mfc/card_only/staticnested_1nt.c} (100%) rename tools/{mfkey/staticnested.c => mfc/card_only/staticnested_2nt.c} (100%) create mode 100755 tools/mfc/card_only/staticnested_2nt_test.sh rename tools/{mf_fudan_rf08s/rf08s_nested_known_collision.c => mfc/card_only/staticnested_2x1nt_rf08s.c} (97%) rename tools/{mf_fudan_rf08s/rf08s_nested_known_match.c => mfc/card_only/staticnested_2x1nt_rf08s_1key.c} (100%) create mode 100644 tools/mfc/card_reader/.gitignore rename tools/{mfkey => mfc/card_reader}/Makefile (59%) rename tools/{mf_nonce_brute => mfc/card_reader}/iso14443crc.c (100%) rename tools/{mf_nonce_brute => mfc/card_reader}/iso14443crc.h (100%) rename tools/{mf_nonce_brute => mfc/card_reader}/mf_nonce_brute.c (100%) rename tools/{mf_nonce_brute/README.md => mfc/card_reader/mf_nonce_brute_examples.md} (98%) rename tools/{mf_nonce_brute => mfc/card_reader}/mf_trace_brute.c (100%) rename tools/{mfkey => mfc/card_reader}/mfkey32.c (100%) rename tools/{mfkey => mfc/card_reader}/mfkey32v2.c (100%) rename tools/{mfkey => mfc/card_reader}/mfkey64.c (100%) rename tools/{mfkey/example_trace.txt => mfc/card_reader/mfkey_examples.md} (65%) rename tools/{mf_nonce_brute => mfc/card_reader}/protocol.h (100%) rename tools/{mf_nonce_brute => mfc/card_reader}/sleep.c (100%) rename tools/{mf_nonce_brute => mfc/card_reader}/sleep.h (100%) rename tools/{mf_nonce_brute => mfc/card_reader}/util_posix.c (100%) rename tools/{mf_nonce_brute => mfc/card_reader}/util_posix.h (100%) rename tools/{ => mfc}/pm3_eml2lower.sh (100%) rename tools/{ => mfc}/pm3_eml2mfd.py (100%) rename tools/{ => mfc}/pm3_eml2upper.sh (100%) rename tools/{ => mfc}/pm3_eml_mfd_test.py (100%) rename tools/{ => mfc}/pm3_gen_dictionary.py (100%) rename tools/{ => mfc}/pm3_gen_mfsim.sh (100%) mode change 100644 => 100755 rename tools/{ => mfc}/pm3_key_file_diff.py (100%) rename tools/{ => mfc}/pm3_mf7b_wipe.py (100%) rename tools/{ => mfc}/pm3_mfd2eml.py (100%) rename tools/{ => mfc}/pm3_mfdread.py (100%) delete mode 100644 tools/mfkey/.gitignore delete mode 100755 tools/mfkey/test_static.sh delete mode 100644 tools/nonce2key/Makefile delete mode 100644 tools/nonce2key/readme.txt mode change 100644 => 100755 tools/pm3_tears_for_fears.py diff --git a/.gitignore b/.gitignore index c76ccfe27..174c9579b 100644 --- a/.gitignore +++ b/.gitignore @@ -74,21 +74,10 @@ flasher lua luac tools/fpga_compress/fpga_compress -tools/mfkey/mfkey32 -tools/mfkey/mfkey64 -tools/mfkey/staticnested -tools/nonce2key/nonce2key tools/cryptorf/cm tools/cryptorf/sm tools/cryptorf/sma tools/cryptorf/sma_multi -tools/mf_fudan_rf08s/rf08s_nested -tools/mf_fudan_rf08s/rf08s_nested_known -tools/mf_fudan_rf08s/rf08s_nested_known_collision -tools/mf_fudan_rf08s/rf08s_nested_known_match -tools/mf_fudan_rf08s/keys* -tools/mf_nonce_brute/mf_nonce_brute -tools/mf_nonce_brute/mf_trace_brute tools/jtag_openocd/openocd_configuration tools/mfd_aes_brute/mfd_aes_brute tools/mfd_aes_brute/mfd_multi_brute diff --git a/Makefile b/Makefile index 35cbae7ea..6702f92d1 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ ifneq (,$(DESTDIR)) endif endif -all clean install uninstall check: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% mf_nonce_brute/% mfd_aes_brute/% fpga_compress/% cryptorf/% +all clean install uninstall check: %: client/% bootrom/% armsrc/% recovery/% mfc_card_only/% mfc_card_reader/% mfd_aes_brute/% fpga_compress/% cryptorf/% # hitag2crack toolsuite is not yet integrated in "all", it must be called explicitly: "make hitag2crack" #all clean install uninstall check: %: hitag2crack/% @@ -112,13 +112,10 @@ endif cryptorf/check: FORCE $(info [*] CHECK $(patsubst %/check,%,$@)) $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) -mfkey/check: FORCE +mfc_card_only/check: FORCE $(info [*] CHECK $(patsubst %/check,%,$@)) $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) -nonce2key/check: FORCE - $(info [*] CHECK $(patsubst %/check,%,$@)) - $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) -mf_nonce_brute/check: FORCE +mfc_card_reader/check: FORCE $(info [*] CHECK $(patsubst %/check,%,$@)) $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) mfd_aes_brute/check: FORCE @@ -151,15 +148,12 @@ check: common/check cryptorf/%: FORCE $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C tools/cryptorf $(patsubst cryptorf/%,%,$@) DESTDIR=$(MYDESTDIR) -mfkey/%: FORCE +mfc_card_only/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) DESTDIR=$(MYDESTDIR) -nonce2key/%: FORCE + $(Q)$(MAKE) --no-print-directory -C tools/mfc/card_only $(patsubst mfc_card_only/%,%,$@) DESTDIR=$(MYDESTDIR) +mfc_card_reader/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/nonce2key $(patsubst nonce2key/%,%,$@) DESTDIR=$(MYDESTDIR) -mf_nonce_brute/%: FORCE - $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/mf_nonce_brute $(patsubst mf_nonce_brute/%,%,$@) DESTDIR=$(MYDESTDIR) + $(Q)$(MAKE) --no-print-directory -C tools/mfc/card_reader $(patsubst mfc_card_reader/%,%,$@) DESTDIR=$(MYDESTDIR) mfd_aes_brute/%: FORCE $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C tools/mfd_aes_brute $(patsubst mfd_aes_brute/%,%,$@) DESTDIR=$(MYDESTDIR) @@ -185,7 +179,7 @@ hitag2crack/%: FORCE $(Q)$(MAKE) --no-print-directory -C tools/hitag2crack $(patsubst hitag2crack/%,%,$@) DESTDIR=$(MYDESTDIR) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) -.PHONY: all clean install uninstall help _test bootrom fullimage recovery client mfkey nonce2key mf_nonce_brute mfd_aes_brute hitag2crack style miscchecks release FORCE udev accessrights cleanifplatformchanged +.PHONY: all clean install uninstall help _test bootrom fullimage recovery client mfc_card_only mfc_card_reader mfd_aes_brute hitag2crack style miscchecks release FORCE udev accessrights cleanifplatformchanged help: @echo "Multi-OS Makefile" @@ -203,9 +197,8 @@ help: @echo @echo "+ client - Make only the OS-specific host client" @echo "+ cryptorf - Make tools/cryptorf" - @echo "+ mfkey - Make tools/mfkey" - @echo "+ nonce2key - Make tools/nonce2key" - @echo "+ mf_nonce_brute - Make tools/mf_nonce_brute" + @echo "+ mfc_card_only - Make tools/mfc/card_only" + @echo "+ mfc_card_reader - Make tools/mfc/card_reader" @echo "+ mfd_aes_brute - Make tools/mfd_aes_brute" @echo "+ hitag2crack - Make tools/hitag2crack" @echo "+ fpga_compress - Make tools/fpga_compress" @@ -245,11 +238,9 @@ recovery: recovery/all cryptorf: cryptorf/all -mfkey: mfkey/all +mfc_card_only: mfc_card_only/all -nonce2key: nonce2key/all - -mf_nonce_brute: mf_nonce_brute/all +mfc_card_reader: mfc_card_reader/all mfd_aes_brute: mfd_aes_brute/all diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index a58851fa7..4cb6ae74b 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -1364,7 +1364,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1 , ar_nr_resp[i].sector , (ar_nr_resp[i].keytype == AUTHKEYA) ? "key A" : "key B" ); - Dbprintf("../tools/mfkey/mfkey32 %08x %08x %08x %08x %08x %08x", + Dbprintf("../tools/mfc_card_reader/mfkey32 %08x %08x %08x %08x %08x %08x", ar_nr_resp[i].cuid, //UID ar_nr_resp[i].nonce, //NT ar_nr_resp[i].nr, //NR1 @@ -1383,7 +1383,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1 , ar_nr_resp[i].sector , (ar_nr_resp[i].keytype == AUTHKEYB) ? "key A" : "key B" ); - Dbprintf("../tools/mfkey/mfkey32v2 %08x %08x %08x %08x %08x %08x %08x", + Dbprintf("../tools/mfc_card_reader/mfkey32v2 %08x %08x %08x %08x %08x %08x %08x", ar_nr_resp[i].cuid, //UID ar_nr_resp[i].nonce, //NT ar_nr_resp[i].nr, //NR1 diff --git a/client/src/cmdhflist.c b/client/src/cmdhflist.c index 0d78d1441..bc2fdce02 100644 --- a/client/src/cmdhflist.c +++ b/client/src/cmdhflist.c @@ -2235,7 +2235,7 @@ bool DecodeMifareData(uint8_t *cmd, uint8_t cmdsize, uint8_t *parity, bool isRes mf_get_paritybinstr(sat, AuthData.at_enc, AuthData.at_enc_par); PrintAndLogEx(NORMAL, "Nested authentication detected!"); - PrintAndLogEx(NORMAL, "tools/mf_nonce_brute/mf_nonce_brute %x %x %s %x %x %s %x %s %s\n" + PrintAndLogEx(NORMAL, "tools/mfc/card_reader/mf_nonce_brute %x %x %s %x %x %s %x %s %s\n" , AuthData.uid , AuthData.nt_enc , snt diff --git a/tools/mf_fudan_rf08s/Makefile b/tools/mf_fudan_rf08s/Makefile deleted file mode 100644 index a8a888291..000000000 --- a/tools/mf_fudan_rf08s/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -MYSRCPATHS = ../../common ../../common/crapto1 -MYSRCS = crypto1.c crapto1.c bucketsort.c -MYINCLUDES = -I../../include -I../../common -MYCFLAGS = -O3 -MYDEFS = - -BINS = rf08s_nested rf08s_nested_known rf08s_nested_known_collision rf08s_nested_known_match - -INSTALLTOOLS = $(BINS) - -include ../../Makefile.host - -# rf08s_nested.c needs pthread support. Older glibc needs it externally -ifneq ($(SKIPPTHREAD),1) - MYLDLIBS += -lpthread -endif - -# checking platform can be done only after Makefile.host -ifneq (,$(findstring MINGW,$(platform))) - # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z) - # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1 - CFLAGS += -D_ISOC99_SOURCE -endif - -# macOS doesn't like these compiler params -ifneq ($(platform),Darwin) - MYCFLAGS += --param max-completely-peeled-insns=1000 --param max-completely-peel-times=10000 -endif - -rf08s_nested : $(OBJDIR)/rf08s_nested.o $(MYOBJS) -rf08s_nested_known : $(OBJDIR)/rf08s_nested_known.o $(MYOBJS) -rf08s_nested_known_collision : $(OBJDIR)/rf08s_nested_known_collision.o $(MYOBJS) -rf08s_nested_known_match : $(OBJDIR)/rf08s_nested_known_match.o $(MYOBJS) diff --git a/tools/mf_nonce_brute/Makefile b/tools/mf_nonce_brute/Makefile deleted file mode 100644 index 35711a460..000000000 --- a/tools/mf_nonce_brute/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -MYSRCPATHS = ../../common ../../common/crapto1 -MYSRCS = crypto1.c crapto1.c bucketsort.c iso14443crc.c sleep.c util_posix.c -MYINCLUDES = -I../../include -I../../common -MYCFLAGS = -O3 -MYDEFS = -MYLDLIBS = -ifneq ($(SKIPPTHREAD),1) -MYLDLIBS += -lpthread -endif - -BINS = mf_nonce_brute mf_trace_brute -INSTALLTOOLS = $(BINS) - -include ../../Makefile.host - -# checking platform can be done only after Makefile.host -ifneq (,$(findstring MINGW,$(platform))) - # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z) - # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1 - CFLAGS += -D_ISOC99_SOURCE -endif - -mf_nonce_brute : $(OBJDIR)/mf_nonce_brute.o $(MYOBJS) - -mf_trace_brute : $(OBJDIR)/mf_trace_brute.o $(MYOBJS) diff --git a/tools/mfc/card_only/.gitignore b/tools/mfc/card_only/.gitignore new file mode 100644 index 000000000..ce1578aac --- /dev/null +++ b/tools/mfc/card_only/.gitignore @@ -0,0 +1,13 @@ +nonce2key +staticnested_0nt +staticnested_1nt +staticnested_2nt +staticnested_2x1nt_rf08s_1key +staticnested_2x1nt_rf08s +nonce2key.exe +staticnested_0nt.exe +staticnested_1nt.exe +staticnested_2nt.exe +staticnested_2x1nt_rf08s_1key.exe +staticnested_2x1nt_rf08s.exe +keys*.dic diff --git a/tools/mfc/card_only/Makefile b/tools/mfc/card_only/Makefile new file mode 100644 index 000000000..9d357df55 --- /dev/null +++ b/tools/mfc/card_only/Makefile @@ -0,0 +1,36 @@ +ROOTPATH = ../../.. +MYSRCPATHS = $(ROOTPATH)/common $(ROOTPATH)/common/crapto1 +MYSRCS = crypto1.c crapto1.c bucketsort.c nested_util.c +MYINCLUDES = -I$(ROOTPATH)/include -I$(ROOTPATH)/common +MYCFLAGS = -O3 +MYDEFS = + +BINS = nonce2key staticnested_0nt staticnested_1nt staticnested_2nt staticnested_2x1nt_rf08s_1key staticnested_2x1nt_rf08s + +INSTALLTOOLS = $(BINS) + +include $(ROOTPATH)/Makefile.host + +# nested_util.c needs pthread support. Older glibc needs it externally +ifneq ($(SKIPPTHREAD),1) + MYLDLIBS += -lpthread +endif + +# checking platform can be done only after Makefile.host +ifneq (,$(findstring MINGW,$(platform))) + # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z) + # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1 + CFLAGS += -D_ISOC99_SOURCE +endif + +# macOS doesn't like these compiler params +ifneq ($(platform),Darwin) + MYCFLAGS += --param max-completely-peeled-insns=1000 --param max-completely-peel-times=10000 +endif + +nonce2key : $(OBJDIR)/nonce2key.o $(MYOBJS) +staticnested_0nt : $(OBJDIR)/staticnested_0nt.o $(MYOBJS) +staticnested_1nt : $(OBJDIR)/staticnested_1nt.o $(MYOBJS) +staticnested_2nt : $(OBJDIR)/staticnested_2nt.o $(MYOBJS) +staticnested_2x1nt_rf08s_1key : $(OBJDIR)/staticnested_2x1nt_rf08s_1key.o $(MYOBJS) +staticnested_2x1nt_rf08s : $(OBJDIR)/staticnested_2x1nt_rf08s.o $(MYOBJS) diff --git a/tools/mfkey/nested_util.c b/tools/mfc/card_only/nested_util.c similarity index 100% rename from tools/mfkey/nested_util.c rename to tools/mfc/card_only/nested_util.c diff --git a/tools/mfkey/nested_util.h b/tools/mfc/card_only/nested_util.h similarity index 100% rename from tools/mfkey/nested_util.h rename to tools/mfc/card_only/nested_util.h diff --git a/tools/nonce2key/nonce2key.c b/tools/mfc/card_only/nonce2key.c similarity index 91% rename from tools/nonce2key/nonce2key.c rename to tools/mfc/card_only/nonce2key.c index d7ccec0bb..a3cc145e8 100644 --- a/tools/nonce2key/nonce2key.c +++ b/tools/mfc/card_only/nonce2key.c @@ -13,7 +13,8 @@ int main(const int argc, const char *argv[]) { nr = rr = 0; if (argc < 5) { - printf("\nsyntax: %s \n\n", argv[0]); + printf("\nsyntax: %s \n", argv[0]); + printf("example: %s 92c0456b 73294ab7 a3fbfb537343eb7b 070608090e060a02\n\n", argv[0]); return 1; } sscanf(argv[1], "%08x", &uid); diff --git a/tools/mf_fudan_rf08s/rf08s_nested.c b/tools/mfc/card_only/staticnested_0nt.c similarity index 100% rename from tools/mf_fudan_rf08s/rf08s_nested.c rename to tools/mfc/card_only/staticnested_0nt.c diff --git a/tools/mf_fudan_rf08s/rf08s_nested_known.c b/tools/mfc/card_only/staticnested_1nt.c similarity index 100% rename from tools/mf_fudan_rf08s/rf08s_nested_known.c rename to tools/mfc/card_only/staticnested_1nt.c diff --git a/tools/mfkey/staticnested.c b/tools/mfc/card_only/staticnested_2nt.c similarity index 100% rename from tools/mfkey/staticnested.c rename to tools/mfc/card_only/staticnested_2nt.c diff --git a/tools/mfc/card_only/staticnested_2nt_test.sh b/tools/mfc/card_only/staticnested_2nt_test.sh new file mode 100755 index 000000000..ee47fb13d --- /dev/null +++ b/tools/mfc/card_only/staticnested_2nt_test.sh @@ -0,0 +1,9 @@ +./staticnested_2nt 461dce03 7eef3586 ffb02eda 322bc14d ffc875ca; +./staticnested_2nt 461dce03 7eef3586 7f21594f 322bc14d 7f815fba; +./staticnested_2nt 461dce03 7eef3586 ff315fe7 322bc14d ffc1364d; +./staticnested_2nt 461dce03 7eef3586 d742a617 322bc14d d7f2f337; +./staticnested_2nt 461dce03 7eef3586 5e3e037c 322bc14d 5ef705c2; +./staticnested_2nt 461dce03 7eef3586 5fcaebc6 322bc14d 5f72de17; +./staticnested_2nt 461dce03 7eef3586 3fbcfb30 322bc14d 3fe4c47c; +./staticnested_2nt 461dce03 7eef3586 1fb6b496 322bc14d 1f4eebdd; +./staticnested_2nt 461dce03 7eef3586 7fa28c7e 322bc14d 7f62b3d6; diff --git a/tools/mf_fudan_rf08s/rf08s_nested_known_collision.c b/tools/mfc/card_only/staticnested_2x1nt_rf08s.c similarity index 97% rename from tools/mf_fudan_rf08s/rf08s_nested_known_collision.c rename to tools/mfc/card_only/staticnested_2x1nt_rf08s.c index a48b370b5..a7451fdc4 100644 --- a/tools/mf_fudan_rf08s/rf08s_nested_known_collision.c +++ b/tools/mfc/card_only/staticnested_2x1nt_rf08s.c @@ -8,7 +8,7 @@ // * Use backdoor on the targeted sector to get the clear static nested nT for keyA and for keyB // * Generate 2 lists of key candidates based on clear and encrypted nT // * Search couples of keyA/keyB satisfying some obscure relationship -// * Use the resulting dictionary to bruteforce the keyA (and rf08s_nested_known_match for keyB) +// * Use the resulting dictionary to bruteforce the keyA (and staticnested_2x1nt_rf08s_1key for keyB) // // Doegox, 2024 @@ -69,7 +69,7 @@ static uint16_t compute_seednt16_nt32(uint32_t nt32, uint64_t key) { int main(int argc, char *const argv[]) { if (argc != 3) { printf("Usage:\n %s keys___.dic keys___.dic\n" - " where both dict files are produced by rf08s_nested_known *for the same UID and same sector*\n", + " where both dict files are produced by staticnested_1nt *for the same UID and same sector*\n", argv[0]); return 1; } diff --git a/tools/mf_fudan_rf08s/rf08s_nested_known_match.c b/tools/mfc/card_only/staticnested_2x1nt_rf08s_1key.c similarity index 100% rename from tools/mf_fudan_rf08s/rf08s_nested_known_match.c rename to tools/mfc/card_only/staticnested_2x1nt_rf08s_1key.c diff --git a/tools/mfc/card_reader/.gitignore b/tools/mfc/card_reader/.gitignore new file mode 100644 index 000000000..fdca31da5 --- /dev/null +++ b/tools/mfc/card_reader/.gitignore @@ -0,0 +1,10 @@ +mfkey32 +mfkey32v2 +mfkey64 +mf_nonce_brute +mf_trace_brute +mfkey32.exe +mfkey32v2.exe +mfkey64.exe +mf_nonce_brute.exe +mf_trace_brute.exe diff --git a/tools/mfkey/Makefile b/tools/mfc/card_reader/Makefile similarity index 59% rename from tools/mfkey/Makefile rename to tools/mfc/card_reader/Makefile index d5b14f1a3..eaadd4e1a 100644 --- a/tools/mfkey/Makefile +++ b/tools/mfc/card_reader/Makefile @@ -1,18 +1,18 @@ -MYSRCPATHS = ../../common ../../common/crapto1 -MYSRCS = crypto1.c crapto1.c bucketsort.c nested_util.c -MYINCLUDES = -I../../include -I../../common +ROOTPATH = ../../.. +MYSRCPATHS = $(ROOTPATH)/common $(ROOTPATH)/common/crapto1 +MYSRCS = crypto1.c crapto1.c bucketsort.c iso14443crc.c sleep.c util_posix.c +MYINCLUDES = -I$(ROOTPATH)/include -I$(ROOTPATH)/common MYCFLAGS = -O3 MYDEFS = +MYLDLIBS = +ifneq ($(SKIPPTHREAD),1) +MYLDLIBS += -lpthread +endif -BINS = mfkey32 mfkey32v2 mfkey64 staticnested +BINS = mfkey32 mfkey32v2 mfkey64 mf_nonce_brute mf_trace_brute INSTALLTOOLS = $(BINS) -include ../../Makefile.host - -# nested_util.c needs pthread support. Older glibc needs it externally -ifneq ($(SKIPPTHREAD),1) - MYLDLIBS += -lpthread -endif +include $(ROOTPATH)/Makefile.host # checking platform can be done only after Makefile.host ifneq (,$(findstring MINGW,$(platform))) @@ -29,4 +29,5 @@ endif mfkey32 : $(OBJDIR)/mfkey32.o $(MYOBJS) mfkey32v2 : $(OBJDIR)/mfkey32v2.o $(MYOBJS) mfkey64 : $(OBJDIR)/mfkey64.o $(MYOBJS) -staticnested : $(OBJDIR)/staticnested.o $(MYOBJS) +mf_nonce_brute : $(OBJDIR)/mf_nonce_brute.o $(MYOBJS) +mf_trace_brute : $(OBJDIR)/mf_trace_brute.o $(MYOBJS) diff --git a/tools/mf_nonce_brute/iso14443crc.c b/tools/mfc/card_reader/iso14443crc.c similarity index 100% rename from tools/mf_nonce_brute/iso14443crc.c rename to tools/mfc/card_reader/iso14443crc.c diff --git a/tools/mf_nonce_brute/iso14443crc.h b/tools/mfc/card_reader/iso14443crc.h similarity index 100% rename from tools/mf_nonce_brute/iso14443crc.h rename to tools/mfc/card_reader/iso14443crc.h diff --git a/tools/mf_nonce_brute/mf_nonce_brute.c b/tools/mfc/card_reader/mf_nonce_brute.c similarity index 100% rename from tools/mf_nonce_brute/mf_nonce_brute.c rename to tools/mfc/card_reader/mf_nonce_brute.c diff --git a/tools/mf_nonce_brute/README.md b/tools/mfc/card_reader/mf_nonce_brute_examples.md similarity index 98% rename from tools/mf_nonce_brute/README.md rename to tools/mfc/card_reader/mf_nonce_brute_examples.md index 1b18a1a6a..a5d95f864 100644 --- a/tools/mf_nonce_brute/README.md +++ b/tools/mfc/card_reader/mf_nonce_brute_examples.md @@ -1,14 +1,14 @@ mf_nonce_brute ============== -Nested auntenticated sector key recovery tool +Nested autenticated sector key recovery tool ----------------------------------------------- Compatible tags: * Mifare Classic 1k (4k) * Mifare Plus in SL1 mode -To recover keys to nested auntenticated sectors you need a reader-card communication log. To get it use +To recover keys to nested autenticated sectors you need a reader-card communication log. To get it use hardware tools that able to sniff communication (for example Proxmark3 or HydraNFC). This enhanced version: diff --git a/tools/mf_nonce_brute/mf_trace_brute.c b/tools/mfc/card_reader/mf_trace_brute.c similarity index 100% rename from tools/mf_nonce_brute/mf_trace_brute.c rename to tools/mfc/card_reader/mf_trace_brute.c diff --git a/tools/mfkey/mfkey32.c b/tools/mfc/card_reader/mfkey32.c similarity index 100% rename from tools/mfkey/mfkey32.c rename to tools/mfc/card_reader/mfkey32.c diff --git a/tools/mfkey/mfkey32v2.c b/tools/mfc/card_reader/mfkey32v2.c similarity index 100% rename from tools/mfkey/mfkey32v2.c rename to tools/mfc/card_reader/mfkey32v2.c diff --git a/tools/mfkey/mfkey64.c b/tools/mfc/card_reader/mfkey64.c similarity index 100% rename from tools/mfkey/mfkey64.c rename to tools/mfc/card_reader/mfkey64.c diff --git a/tools/mfkey/example_trace.txt b/tools/mfc/card_reader/mfkey_examples.md similarity index 65% rename from tools/mfkey/example_trace.txt rename to tools/mfc/card_reader/mfkey_examples.md index b068c0577..f2e3e137f 100644 --- a/tools/mfkey/example_trace.txt +++ b/tools/mfc/card_reader/mfkey_examples.md @@ -1,4 +1,5 @@ -:: TRACE +## Sample trace +``` + 50422: : 26 + 64: 0: TAG 04 00 + 944: : 93 20 @@ -9,32 +10,38 @@ + 113: 0: TAG 82 a4 16 6c + 1287: : a1 e4 58 ce 6e ea 41 e0 + 64: 0: TAG 5c ad f4 39 +``` +Usage with sample trace: +`./mfkey64 9C599B32 82A4166C A1E458CE 6EEA41E0 5CADF439` -:: Sample of trace above, -./mfkey64 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439 +## Other examples ------------------------------------------------------------------------------------------------------ -:: For mfkey32, you want to get two different NR_0/NR_1 values. +For mfkey32, you want to get two different NR_0/NR_1 values. -:: +``` +# ./mfkey32 52B0F519 5417D1F8 4D545EA7 E15AC8C2 DAC1A7F4 5AE5C37F +``` -:: For mfkey32v2 (moebius), you want to get two different NT/NT1 values. (like in the SIM commands) - -:: +For mfkey32v2 (moebius), you want to get two different NT/NT1 values. (like in the SIM commands) +``` +# ./mfkey32v2 12345678 1AD8DF2B 1D316024 620EF048 30D6CB07 C52077E2 837AC61A ./mfkey32v2 52B0F519 5417D1F8 4D545EA7 E15AC8C2 A1BA88C6 DAC1A7F4 5AE5C37F +``` -:: for mfkey64, you want to have the AT response from tag. - -:: +For mfkey64, you want to have the AT response from tag. +``` +# ./mfkey64 9C599B32 82A4166C A1E458CE 6EEA41E0 5CADF439 ./mfkey64 52B0F519 5417D1F8 4D545EA7 E15AC8C2 5056E41B +``` ------------------------------------------------------------------------------------------------------ -New functionality from @zhovner, ------------------------------------------------------------------------------------------------------ ### Communication decryption +A new functionality from @zhovner + +Example: given the following trace +``` RDR 26 TAG 04 00 RDR 93 20 @@ -54,10 +61,11 @@ TAG 49 e2 c9 de f4 86 8d 17 77 67 0e 58 4c 27 23 02 86 f4 RDR fb dc d7 c1 TAG 4a bd 96 4b 07 d3 56 3a a0 66 ed 0a 2e ac 7f 63 12 bf RDR 9f 91 49 ea +``` +`./mfkey64 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea` -./mfkey64 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea - +``` Recovering key for: uid: 14579f69 nt: ce844261 @@ -94,3 +102,4 @@ Decrypted communication: {dec8}: 61148834 Found Key: [091e639cb715] +``` diff --git a/tools/mf_nonce_brute/protocol.h b/tools/mfc/card_reader/protocol.h similarity index 100% rename from tools/mf_nonce_brute/protocol.h rename to tools/mfc/card_reader/protocol.h diff --git a/tools/mf_nonce_brute/sleep.c b/tools/mfc/card_reader/sleep.c similarity index 100% rename from tools/mf_nonce_brute/sleep.c rename to tools/mfc/card_reader/sleep.c diff --git a/tools/mf_nonce_brute/sleep.h b/tools/mfc/card_reader/sleep.h similarity index 100% rename from tools/mf_nonce_brute/sleep.h rename to tools/mfc/card_reader/sleep.h diff --git a/tools/mf_nonce_brute/util_posix.c b/tools/mfc/card_reader/util_posix.c similarity index 100% rename from tools/mf_nonce_brute/util_posix.c rename to tools/mfc/card_reader/util_posix.c diff --git a/tools/mf_nonce_brute/util_posix.h b/tools/mfc/card_reader/util_posix.h similarity index 100% rename from tools/mf_nonce_brute/util_posix.h rename to tools/mfc/card_reader/util_posix.h diff --git a/tools/pm3_eml2lower.sh b/tools/mfc/pm3_eml2lower.sh similarity index 100% rename from tools/pm3_eml2lower.sh rename to tools/mfc/pm3_eml2lower.sh diff --git a/tools/pm3_eml2mfd.py b/tools/mfc/pm3_eml2mfd.py similarity index 100% rename from tools/pm3_eml2mfd.py rename to tools/mfc/pm3_eml2mfd.py diff --git a/tools/pm3_eml2upper.sh b/tools/mfc/pm3_eml2upper.sh similarity index 100% rename from tools/pm3_eml2upper.sh rename to tools/mfc/pm3_eml2upper.sh diff --git a/tools/pm3_eml_mfd_test.py b/tools/mfc/pm3_eml_mfd_test.py similarity index 100% rename from tools/pm3_eml_mfd_test.py rename to tools/mfc/pm3_eml_mfd_test.py diff --git a/tools/pm3_gen_dictionary.py b/tools/mfc/pm3_gen_dictionary.py similarity index 100% rename from tools/pm3_gen_dictionary.py rename to tools/mfc/pm3_gen_dictionary.py diff --git a/tools/pm3_gen_mfsim.sh b/tools/mfc/pm3_gen_mfsim.sh old mode 100644 new mode 100755 similarity index 100% rename from tools/pm3_gen_mfsim.sh rename to tools/mfc/pm3_gen_mfsim.sh diff --git a/tools/pm3_key_file_diff.py b/tools/mfc/pm3_key_file_diff.py similarity index 100% rename from tools/pm3_key_file_diff.py rename to tools/mfc/pm3_key_file_diff.py diff --git a/tools/pm3_mf7b_wipe.py b/tools/mfc/pm3_mf7b_wipe.py similarity index 100% rename from tools/pm3_mf7b_wipe.py rename to tools/mfc/pm3_mf7b_wipe.py diff --git a/tools/pm3_mfd2eml.py b/tools/mfc/pm3_mfd2eml.py similarity index 100% rename from tools/pm3_mfd2eml.py rename to tools/mfc/pm3_mfd2eml.py diff --git a/tools/pm3_mfdread.py b/tools/mfc/pm3_mfdread.py similarity index 100% rename from tools/pm3_mfdread.py rename to tools/mfc/pm3_mfdread.py diff --git a/tools/mfkey/.gitignore b/tools/mfkey/.gitignore deleted file mode 100644 index ec7f413e5..000000000 --- a/tools/mfkey/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -mfkey32 -mfkey32v2 -mfkey64 - -mfkey32.exe -mfkey32v2.exe -mfkey64.exe diff --git a/tools/mfkey/test_static.sh b/tools/mfkey/test_static.sh deleted file mode 100755 index 7fd180d8a..000000000 --- a/tools/mfkey/test_static.sh +++ /dev/null @@ -1,9 +0,0 @@ -./staticnested 461dce03 7eef3586 ffb02eda 322bc14d ffc875ca; -./staticnested 461dce03 7eef3586 7f21594f 322bc14d 7f815fba; -./staticnested 461dce03 7eef3586 ff315fe7 322bc14d ffc1364d; -./staticnested 461dce03 7eef3586 d742a617 322bc14d d7f2f337; -./staticnested 461dce03 7eef3586 5e3e037c 322bc14d 5ef705c2; -./staticnested 461dce03 7eef3586 5fcaebc6 322bc14d 5f72de17; -./staticnested 461dce03 7eef3586 3fbcfb30 322bc14d 3fe4c47c; -./staticnested 461dce03 7eef3586 1fb6b496 322bc14d 1f4eebdd; -./staticnested 461dce03 7eef3586 7fa28c7e 322bc14d 7f62b3d6; diff --git a/tools/nonce2key/Makefile b/tools/nonce2key/Makefile deleted file mode 100644 index a4b0bde05..000000000 --- a/tools/nonce2key/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -MYSRCPATHS = ../../common ../../common/crapto1 -MYSRCS = crypto1.c crapto1.c bucketsort.c -MYINCLUDES = -I../../include -I../../common -MYCFLAGS = -MYDEFS = - -BINS = nonce2key -INSTALLTOOLS = $(BINS) - -include ../../Makefile.host - -# checking platform can be done only after Makefile.host -ifneq (,$(findstring MINGW,$(platform))) - # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z) - # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1 - CFLAGS += -D_ISOC99_SOURCE -endif - -nonce2key : $(OBJDIR)/nonce2key.o $(MYOBJS) diff --git a/tools/nonce2key/readme.txt b/tools/nonce2key/readme.txt deleted file mode 100644 index cb25a412a..000000000 --- a/tools/nonce2key/readme.txt +++ /dev/null @@ -1,7 +0,0 @@ -To test the nonce2key tool. - -:: tip -You can use the output from "hf mf mifare" to use with this tool. - -:: sample -./nonce2key 92c0456b 73294ab7 a3fbfb537343eb7b 070608090e060a02 diff --git a/tools/pm3_tears_for_fears.py b/tools/pm3_tears_for_fears.py old mode 100644 new mode 100755 diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index a35512df4..e096bccac 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -10,6 +10,7 @@ SLOWTESTS=false OPENCLTESTS=false TESTALL=true TESTMFKEY=false +TESTSTATICNESTED=false TESTNONCE2KEY=false TESTMFNONCEBRUTE=false TESTMFDAESBRUTE=false @@ -28,7 +29,7 @@ while (( "$#" )); do case "$1" in -h|--help) echo """ -Usage: $0 [--long] [--opencl] [--clientbin /path/to/proxmark3] [mfkey|nonce2key|mf_nonce_brute|mfd_aes_brute|cryptorf|fpga_compress|bootrom|armsrc|client|recovery|common] +Usage: $0 [--long] [--opencl] [--clientbin /path/to/proxmark3] [mfkey|nonce2key|mf_nonce_brute|staticnested|mfd_aes_brute|cryptorf|fpga_compress|bootrom|armsrc|client|recovery|common] --long: Enable slow tests --opencl: Enable tests requiring OpenCL (preferably a Nvidia GPU) --clientbin ...: Specify path to proxmark3 binary to test @@ -73,6 +74,11 @@ Usage: $0 [--long] [--opencl] [--clientbin /path/to/proxmark3] [mfkey|nonce2key| TESTMFNONCEBRUTE=true shift ;; + staticnested) + TESTALL=false + TESTSTATICNESTED=true + shift + ;; mfd_aes_brute) TESTALL=false TESTMFDAESBRUTE=true @@ -262,7 +268,7 @@ while true; do if ! CheckExecute "xorcheck test" "tools/xorcheck.py 04 00 80 64 ba" "final LRC XOR byte value: 5A"; then break; fi if ! CheckExecute "findbits test" "tools/findbits.py 73 0110010101110011" "Match at bit 9: 011001010"; then break; fi if ! CheckExecute "findbits_test test" "tools/findbits_test.py 2>&1" "OK"; then break; fi - if ! CheckExecute "pm3_eml_mfd test" "tools/pm3_eml_mfd_test.py 2>&1" "OK"; then break; fi + if ! CheckExecute "pm3_eml_mfd test" "tools/mfc/pm3_eml_mfd_test.py 2>&1" "OK"; then break; fi if ! CheckExecute "recover_pk test" "tools/recover_pk.py selftests 2>&1" "Tests:.*\(.*ok.*"; then break; fi if ! CheckExecute "mkversion create test" "tools/mkversion.sh --short" 'Iceman/'; then break; fi fi @@ -284,23 +290,26 @@ while true; do if ! CheckFileExist "fpgacompress exists" "$FPGACPMPRESSBIN"; then break; fi fi if $TESTALL || $TESTMFKEY; then - echo -e "\n${C_BLUE}Testing mfkey:${C_NC} ${MFKEY32V2BIN:=./tools/mfkey/mfkey32v2} ${MFKEY64BIN:=./tools/mfkey/mfkey64} ${STATICNESTEDBIN:=./tools/mfkey/staticnested}" + echo -e "\n${C_BLUE}Testing mfkey:${C_NC} ${MFKEY32V2BIN:=./tools/mfc/card_reader/mfkey32v2} ${MFKEY64BIN:=./tools/mfc/card_reader/mfkey64}" if ! CheckFileExist "mfkey32v2 exists" "$MFKEY32V2BIN"; then break; fi if ! CheckFileExist "mfkey64 exists" "$MFKEY64BIN"; then break; fi - if ! CheckFileExist "staticnested exists" "$STATICNESTEDBIN"; then break; fi # Need a decent example for mfkey32... if ! CheckExecute "mfkey32v2 test" "$MFKEY32V2BIN 12345678 1AD8DF2B 1D316024 620EF048 30D6CB07 C52077E2 837AC61A" "Found Key: \[a0a1a2a3a4a5\]"; then break; fi if ! CheckExecute "mfkey64 test" "$MFKEY64BIN 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439" "Found Key: \[ffffffffffff\]"; then break; fi if ! CheckExecute "mfkey64 long trace test" "$MFKEY64BIN 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea" "Found Key: \[091e639cb715\]"; then break; fi - if ! CheckExecute "staticnested test" "$STATICNESTEDBIN 461dce03 7eef3586 7fa28c7e 322bc14d 7f62b3d6" "\[ 2 \].*ffffffffff40.*"; then break; fi + fi + if $TESTALL || $TESTSTATICNESTED; then + echo -e "\n${C_BLUE}Testing staticnested:${C_NC} ${STATICNESTED2NTBIN:=./tools/mfc/card_only/staticnested_2nt}" + if ! CheckFileExist "staticnested_2nt exists" "$STATICNESTED2NTBIN"; then break; fi + if ! CheckExecute "staticnested_2nt test" "$STATICNESTED2NTBIN 461dce03 7eef3586 7fa28c7e 322bc14d 7f62b3d6" "\[ 2 \].*ffffffffff40.*"; then break; fi fi if $TESTALL || $TESTNONCE2KEY; then - echo -e "\n${C_BLUE}Testing nonce2key:${C_NC} ${NONCE2KEYBIN:=./tools/nonce2key/nonce2key}" + echo -e "\n${C_BLUE}Testing nonce2key:${C_NC} ${NONCE2KEYBIN:=./tools/mfc/card_only/nonce2key}" if ! CheckFileExist "nonce2key exists" "$NONCE2KEYBIN"; then break; fi if ! CheckExecute "nonce2key test" "$NONCE2KEYBIN e9cadd9c a8bf4a12 a020a8285858b090 050f010607060e07 5693be6c00000000" "key recovered: fc00018778f7"; then break; fi fi if $TESTALL || $TESTMFNONCEBRUTE; then - echo -e "\n${C_BLUE}Testing mf_nonce_brute:${C_NC} ${MFNONCEBRUTEBIN:=./tools/mf_nonce_brute/mf_nonce_brute}" + echo -e "\n${C_BLUE}Testing mf_nonce_brute:${C_NC} ${MFNONCEBRUTEBIN:=./tools/mfc/card_reader/mf_nonce_brute}" if ! CheckFileExist "mf_nonce_brute exists" "$MFNONCEBRUTEBIN"; then break; fi if ! CheckExecute slow "mf_nonce_brute test 1/2" "$MFNONCEBRUTEBIN 9c599b32 5a920d85 1011 98d76b77 d6c6e870 0000 ca7e0b63 0111 3e709c8a" "Key found \[.*ffffffffffff.*\]"; then break; fi if ! CheckExecute slow "mf_nonce_brute test 2/2" "$MFNONCEBRUTEBIN 96519578 d7e3c6ac 0011 cd311951 9da49e49 0010 2bb22e00 0100 a4f7f398" "Key found \[.*3b7e4fd575ad.*\]"; then break; fi