From d770e4c57a8e5e95b679af00b3e0f9a6890096d9 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 14 Aug 2019 22:59:14 +0200 Subject: [PATCH 001/347] remove debugstatements --- client/reveng/poly.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/client/reveng/poly.c b/client/reveng/poly.c index 0fc6555d9..44f5709f4 100644 --- a/client/reveng/poly.c +++ b/client/reveng/poly.c @@ -600,9 +600,6 @@ plast(const poly_t poly) { idx = size - 1UL; while (idx && !(accu = poly.bitmap[idx])) --idx; - if (poly.length == 24) - printf("ICE plast B - poly.length %lu vs size %lu idx %lu bitmap %ld\n", poly.length, size, idx, poly.bitmap[idx]); - if (!idx && !(accu = poly.bitmap[idx])) return (0UL); /* now accu == poly.bitmap[idx] and contains last significant term */ @@ -1080,10 +1077,6 @@ praloc(poly_t *poly, unsigned long length) { if (poly->bitmap) { - if (poly->length == 24) - printf("ICE praloc - poly->length %lu\n", poly->length); - - if (poly->length < length) { /* poly->length >= 0, length > 0, size > 0. * poly expanded. clear old last word and all new words @@ -1094,15 +1087,11 @@ praloc(poly_t *poly, unsigned long length) { while (oldsize < size) poly->bitmap[oldsize++] = BMP_C(0); - if (poly->length == 24) printf("ICE praloc MISS A\n"); - } else if (LOFS(length)) { /* poly->length >= length > 0. * poly shrunk. clear new last word */ poly->bitmap[size - 1UL] &= ~(~BMP_C(0) >> LOFS(length)); - - if (poly->length == 24) printf("ICE praloc B size %lu, bm %lu \n", size, poly->bitmap[size - 1UL]); } poly->length = length; From fbbbe98022109520aa8c9b343c8e10413c0f264c Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 12:21:33 +0300 Subject: [PATCH 002/347] add make clean for linux --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3c12e6d3c..079ae5a33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,6 +41,7 @@ install: brew options proxmark3; brew install --HEAD proxmark3; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + make clean; make all; fi From 3ae3adf0a817ac2c3009eace0ed2d7f05c235753 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sun, 18 Aug 2019 11:53:20 +0200 Subject: [PATCH 003/347] Update cheatsheet.md --- doc/cheatsheet.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/cheatsheet.md b/doc/cheatsheet.md index 63c74d1a3..f143438c4 100644 --- a/doc/cheatsheet.md +++ b/doc/cheatsheet.md @@ -1,4 +1,6 @@ # Command Cheat Sheet + + |Generic|Low Frequence 125 kHz|High Frequence 13.56 MHz| |---|---|---| |[Generic](#Generic)|[T55XX](#T55XX)|[Mifare](#Mifare)| @@ -10,6 +12,7 @@ ## Generic +^[Top](#top) Identify High Frequency cards ``` @@ -37,6 +40,7 @@ pm3 --> hw status ``` ## iClass +^[Top](#top) Reverse permute iClass master key ``` @@ -166,6 +170,7 @@ pm3 --> hf iclass lookup u 010a0ffff7ff12e0 p feffffffffffffff m 66348979153c41b ``` ## Mifare +^[Top](#top) Check for default keys ``` @@ -264,6 +269,7 @@ pm3 --> hf mf restore 1 u 4A6CE843 k hf-mf-A29558E4-key.bin f hf-mf-A29558E4-dat ``` ## HID Prox +^[Top](#top) Read HID Prox card ``` @@ -313,6 +319,7 @@ pm3 --> lf hid brute v a 26 f 21 c 200 d 2000 ``` ## Indala +^[Top](#top) Read Indala card ``` @@ -343,6 +350,7 @@ pm3 --> lf indala clone a0000000c2c436c1 ``` ## Hitag +^[Top](#top) Read Hitag information ``` @@ -401,6 +409,7 @@ pm3 --> lf hitag sim c378181c_a8f7.ht2 ``` ## T55XX +^[Top](#top) Detect T55XX card ``` @@ -443,6 +452,7 @@ pm3 --> lf t55xx wipe ``` ## Data +^[Top](#top) Get raw samples [512-40000] ``` @@ -460,6 +470,7 @@ pm3 --> data load ``` ## Lua Scripts +^[Top](#top) List Lua Scripts @@ -489,6 +500,7 @@ pm3 --> script run formatMifare -k FFFFFFFFFFFF -n FFFFFFFFFFFF -x ``` ## Memory +^[Top](#top) Load default keys into memory ``` @@ -506,6 +518,7 @@ pm3 --> mem load f default_iclass_keys i ``` ## Sim Module +^[Top](#top) Upgrade Sim Module firmware ``` @@ -513,6 +526,7 @@ pm3 --> sc upgrade f ../tools/simmodule/SIM011.BIN ``` ## Smart Card +^[Top](#top) Get Smart Card Information ``` From fb6d2fdee84ea92e5e46e344638cbf4a9f9cb566 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 17:31:57 +0300 Subject: [PATCH 004/347] add test script --- .travis.yml | 2 +- pm3test.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 pm3test.sh diff --git a/.travis.yml b/.travis.yml index 079ae5a33..d260b9b47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,5 +50,5 @@ script: if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then proxmark3 -h ; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - ./client/proxmark3 -h ; + ./pm3test.sh; fi \ No newline at end of file diff --git a/pm3test.sh b/pm3test.sh new file mode 100644 index 000000000..3ff3aa5ac --- /dev/null +++ b/pm3test.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 + +C_RED='\033[0;31m' +C_GREEN='\033[0;32m' +C_BLUE='\033[0;34m' +C_NC='\033[0m' # No Color + +function CheckFileExist() { + + if [ -f "$2" ]; then + echo "$1 [OK]" + return 0 + fi + + if ls $2 1> /dev/null 2>&1; then + echo "$1 [OK]" + return 0 + fi + + echo "$1 [Fail]" + return 1 +} + +printf "\n${C_BLUE}RRG Proxmark3 test tool ${C_NC}\n\n" + +while true; do + if ! CheckFileExist "proxmark3 exists" "client/proxmark3"; then break; fi + if ! CheckFileExist "arm image exists" "armsrc/obj/fullimage.elf"; then break; fi + if ! CheckFileExist "bootrom exists" "bootrom/obj/bootrom.elf"; then break; fi + if ! CheckFileExist "hardnested tables exists" "client/hardnested/tables/*.z"; then break; fi + + printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" + exit 0 +done + +printf "\n${C_RED}Tests [FAIL]${C_NC}\n\n" +exit 1 \ No newline at end of file From d84fd0f7d15cc34c698554bfa79da87d2050b8b6 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 17:36:21 +0300 Subject: [PATCH 005/347] del spaces --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d260b9b47..dd4b42898 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ addons: - wget - RfidResearchGroup/proxmark3/arm-none-eabi-gcc taps: RfidResearchGroup/proxmark3 - + install: if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew info proxmark3; @@ -51,4 +51,4 @@ script: proxmark3 -h ; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./pm3test.sh; - fi \ No newline at end of file + fi From 6452c395833a322a37ee24b1eb9fbee65b900b8a Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 17:43:34 +0300 Subject: [PATCH 006/347] small fix --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dd4b42898..e272ea9cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,5 +50,6 @@ script: if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then proxmark3 -h ; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + chmod a+w ./pm3test.sh; ./pm3test.sh; fi From 2510caff4628f0b0e52be9fc234f8925ebd72598 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 18:07:23 +0300 Subject: [PATCH 007/347] add exec tests --- pm3test.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pm3test.sh b/pm3test.sh index 3ff3aa5ac..d9d103910 100644 --- a/pm3test.sh +++ b/pm3test.sh @@ -24,17 +24,37 @@ function CheckFileExist() { return 1 } +function CheckExecute() { + + if eval "$2 | grep -q $3"; then + echo "$1 [OK]" + return 0 + fi + + echo "$1 [Fail]" + return 1 +} + printf "\n${C_BLUE}RRG Proxmark3 test tool ${C_NC}\n\n" while true; do - if ! CheckFileExist "proxmark3 exists" "client/proxmark3"; then break; fi - if ! CheckFileExist "arm image exists" "armsrc/obj/fullimage.elf"; then break; fi - if ! CheckFileExist "bootrom exists" "bootrom/obj/bootrom.elf"; then break; fi - if ! CheckFileExist "hardnested tables exists" "client/hardnested/tables/*.z"; then break; fi + if ! CheckFileExist "proxmark3 exists" "./client/proxmark3"; then break; fi + if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi + if ! CheckFileExist "bootrom exists" "./bootrom/obj/bootrom.elf"; then break; fi + if ! CheckFileExist "hardnested tables exists" "./client/hardnested/tables/*.z"; then break; fi + if ! CheckExecute "proxmark help" "./client/proxmark3 -h" "wait"; then break; fi + if ! CheckExecute "proxmark help text ISO7816" "./client/proxmark3 -t 2>&1" "ISO7816"; then break; fi + if ! CheckExecute "proxmark help text hardnested" "./client/proxmark3 -t 2>&1" "hardnested"; then break; fi + + if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi + + if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:"; then break; fi + #if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test?s? ? OK"; then break; fi + printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" exit 0 done printf "\n${C_RED}Tests [FAIL]${C_NC}\n\n" -exit 1 \ No newline at end of file +exit 1 From 7eb14b015e9601ce285e2b0f72552d9d6ecc96f5 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 18:12:18 +0300 Subject: [PATCH 008/347] travis fix --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e272ea9cc..a533910d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,11 +45,13 @@ install: make all; fi +before_script: + - chmod +x pm3test.sh + script: ## start and run a test script if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then proxmark3 -h ; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - chmod a+w ./pm3test.sh; ./pm3test.sh; fi From 0cfaaf266fce00989ed242e3d816162c422bcfa7 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 18:26:08 +0300 Subject: [PATCH 009/347] added `emv test` and some colors --- pm3test.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pm3test.sh b/pm3test.sh index d9d103910..385ba7579 100644 --- a/pm3test.sh +++ b/pm3test.sh @@ -11,27 +11,27 @@ C_NC='\033[0m' # No Color function CheckFileExist() { if [ -f "$2" ]; then - echo "$1 [OK]" + echo -e "$1 ${C_GREEN}[OK]${C_NC}" return 0 fi if ls $2 1> /dev/null 2>&1; then - echo "$1 [OK]" + echo -e "$1 ${C_GREEN}[OK]${C_NC}" return 0 fi - echo "$1 [Fail]" + echo -e "$1 ${C_RED}[Fail]${C_NC}" return 1 } function CheckExecute() { - if eval "$2 | grep -q $3"; then - echo "$1 [OK]" + if eval "$2 | grep -q '$3'"; then + echo -e "$1 ${C_GREEN}[OK]${C_NC}" return 0 fi - echo "$1 [Fail]" + echo -e "$1 ${C_RED}[Fail]${C_NC}" return 1 } @@ -50,7 +50,7 @@ while true; do if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:"; then break; fi - #if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test?s? ? OK"; then break; fi + if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" exit 0 From 7fc5fe6dd58cace814972d09db3785e7007e12fe Mon Sep 17 00:00:00 2001 From: root Date: Sun, 18 Aug 2019 17:43:54 +0200 Subject: [PATCH 010/347] chg: unifed the dateformat --- tools/fpga_compress/fpga_compress.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/fpga_compress/fpga_compress.c b/tools/fpga_compress/fpga_compress.c index 7777b6d51..bac6a1670 100644 --- a/tools/fpga_compress/fpga_compress.c +++ b/tools/fpga_compress/fpga_compress.c @@ -337,6 +337,8 @@ static int FpgaGatherVersion(FILE *infile, char *infile_name, char *dst, int len for (uint16_t i = 0; i < fpga_info_len; i++) { char c = (char)fgetc(infile); if (i < sizeof(tempstr)) { + if ( c == '/' ) c = '-'; + if ( c == ' ' ) c = '0'; tempstr[i] = c; } } From cc9f2127b124ca3215f086f2b0adcb7173d9592b Mon Sep 17 00:00:00 2001 From: RFID Research Group Date: Sun, 18 Aug 2019 17:58:35 +0200 Subject: [PATCH 011/347] Create FUNDING.yml --- .github/FUNDING.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..2f13a259a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: iceman1001 +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] From 512e28c62e4610183427512fa9b88778bc5938ae Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 19:29:26 +0300 Subject: [PATCH 012/347] add some info (#336) add some info --- pm3test.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pm3test.sh b/pm3test.sh index 385ba7579..09cc6b6cc 100644 --- a/pm3test.sh +++ b/pm3test.sh @@ -37,6 +37,20 @@ function CheckExecute() { printf "\n${C_BLUE}RRG Proxmark3 test tool ${C_NC}\n\n" +if [ "$TRAVIS_COMMIT" ]; then + if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + echo "Travis branch: $TRAVIS_BRANCH slug: $TRAVIS_REPO_SLUG commit: $TRAVIS_COMMIT" + else + echo "Travis pull request: $TRAVIS_PULL_REQUEST branch: $TRAVIS_BRANCH slug: $TRAVIS_PULL_REQUEST_SLUG commit: $TRAVIS_COMMIT" + fi +fi + +printf "git branch: " +git describe --all +printf "git sha: " +git rev-parse HEAD +echo "" + while true; do if ! CheckFileExist "proxmark3 exists" "./client/proxmark3"; then break; fi if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi From 00cc43ec7e48397d9bcfb5cf60ed3f91573dc45b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 18 Aug 2019 19:25:09 +0200 Subject: [PATCH 013/347] textual --- proxmark3.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proxmark3.sh b/proxmark3.sh index 07d2a27d5..be3cfd690 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -7,7 +7,7 @@ PM3PATH=$(dirname "$0") cd "$PM3PATH" || exit 1 function wait4proxmark_Linux { - echo >&2 "[=] Waiting for Proxmark to appear..." + echo >&2 "[=] Waiting for Proxmark3 to appear..." while true; do PM3=$(find /dev/pm3-* /dev/ttyACM* 2>/dev/null | head -1) if [[ $PM3 != "" ]]; then @@ -19,7 +19,7 @@ function wait4proxmark_Linux { } function wait4proxmark_macOS { - echo >&2 "[=] Waiting for Proxmark to appear..." + echo >&2 "[=] Waiting for Proxmark3 to appear..." while true; do PM3=$(find /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) if [[ $PM3 != "" ]]; then @@ -31,7 +31,7 @@ function wait4proxmark_macOS { } function wait4proxmark_Windows { - echo >&2 "[=] Waiting for Proxmark to appear..." + echo >&2 "[=] Waiting for Proxmark3 to appear..." while true; do device=$(wmic path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2') if [[ $device != "" ]]; then @@ -44,7 +44,7 @@ function wait4proxmark_Windows { } function wait4proxmark_WSL { - echo >&2 "[=] Waiting for Proxmark to appear..." + echo >&2 "[=] Waiting for Proxmark3 to appear..." while true; do device=$(wmic.exe path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2') if [[ $device != "" ]]; then From 6647c407af9084a0b20fedf750a2d6c8b07361ad Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Sun, 18 Aug 2019 20:56:38 +0300 Subject: [PATCH 014/347] ios (#337) retry for hardnested added `make all v=1` for linux --- .travis.yml | 12 ++++++++++-- pm3test.sh | 26 +++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index a533910d8..a1c5a6866 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ install: brew install --HEAD proxmark3; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean; - make all; + make all V=1; fi before_script: @@ -50,8 +50,16 @@ before_script: script: ## start and run a test script - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then proxmark3 -h ; +# cd /Users/travis/Library/Caches/Homebrew/proxmark3--git; +# chmod +x pm3test.sh; +# pwd; +# ls -la; +# cd client; +# ls-la; +# cd ..; +# ./pm3test.sh; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./pm3test.sh; fi diff --git a/pm3test.sh b/pm3test.sh index 09cc6b6cc..e127944f6 100644 --- a/pm3test.sh +++ b/pm3test.sh @@ -8,34 +8,46 @@ C_GREEN='\033[0;32m' C_BLUE='\033[0;34m' C_NC='\033[0m' # No Color +# title, file name or file wildcard to check function CheckFileExist() { if [ -f "$2" ]; then echo -e "$1 ${C_GREEN}[OK]${C_NC}" - return 0 + return 0 fi if ls $2 1> /dev/null 2>&1; then echo -e "$1 ${C_GREEN}[OK]${C_NC}" - return 0 + return 0 fi echo -e "$1 ${C_RED}[Fail]${C_NC}" return 1 } +# title, command line, check result, repeat several times if failed function CheckExecute() { - if eval "$2 | grep -q '$3'"; then - echo -e "$1 ${C_GREEN}[OK]${C_NC}" - return 0 + if [ $4 ]; then + local RETRY="1 2 3 e" + else + local RETRY="e" fi + for I in $RETRY + do + if eval "$2 | grep -q '$3'"; then + echo -e "$1 ${C_GREEN}[OK]${C_NC}" + return 0 + fi + if [ ! $I == "e" ]; then echo "retry $I"; fi + done + echo -e "$1 ${C_RED}[Fail]${C_NC}" return 1 } -printf "\n${C_BLUE}RRG Proxmark3 test tool ${C_NC}\n\n" +printf "\n${C_BLUE}RRG/Iceman Proxmark3 test tool ${C_NC}\n\n" if [ "$TRAVIS_COMMIT" ]; then if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then @@ -63,7 +75,7 @@ while true; do if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi - if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:"; then break; fi + if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat"; then break; fi if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" From a4010900eaa29fd86c114af869594b81bf8a6e14 Mon Sep 17 00:00:00 2001 From: Uli Heilmeier Date: Sun, 18 Aug 2019 20:06:15 +0200 Subject: [PATCH 015/347] Doc: Add notes about trace to Wireshark export Adding some notes how to bring trace output into Wireshark. --- doc/trace_wireshark_notes.md | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 doc/trace_wireshark_notes.md diff --git a/doc/trace_wireshark_notes.md b/doc/trace_wireshark_notes.md new file mode 100644 index 000000000..50dd9d082 --- /dev/null +++ b/doc/trace_wireshark_notes.md @@ -0,0 +1,60 @@ +# Trace command notes + +The `trace` command lists the data exchange by the proxmark3 and a tag or a reader in human readable form. + +With `trace list` a table is shown which gives timing information, the src of the data bytes, the transmitted/received bytes itself, a check if the CRC was correct and some decoding of the command. + +To get a more detailed explanation of the transmitted data for ISO14443A traces the output can be converted to a pcapng file to read it with [Wireshark](https://www.wireshark.org/). + +To do so + +* use `trace list 14a x` +* copy the output (starting with the timestamp) into a textfile +* run `text2pcap -t "%S." -l 264 -n ` +* now open your pcapng file in Wireshark or read it with the CLI version `tshark` + +An example frame + +with `trace list 14a`: + +``` +19072 | 29536 | Rdr |93 70 88 04 cf ff bc 7f bb | ok | SELECT_UID +``` + +the same data with `tshark -r foo.pcapng -V -x`: + +``` +Frame 5: 13 bytes on wire (104 bits), 13 bytes captured (104 bits) on interface 0 + Interface id: 0 (unknown) + Interface name: unknown + Encapsulation type: ISO 14443 contactless smartcard standards (177) + Arrival Time: Aug 17, 2019 23:17:00.000002606 CEST + [Time shift for this packet: 0.000000000 seconds] + Epoch Time: 1566076620.000002606 seconds + [Time delta from previous captured frame: 0.000000840 seconds] + [Time delta from previous displayed frame: 0.000000840 seconds] + [Time since reference or first frame: 0.000001907 seconds] + Frame Number: 5 + Frame Length: 13 bytes (104 bits) + Capture Length: 13 bytes (104 bits) + [Frame is marked: False] + [Frame is ignored: False] + [Protocols in frame: iso14443] +ISO 14443 + Pseudo header + Version: 0x00 + Event: Data transfer PCD -> PICC (0xfe) + Length field: 9 + Message: Select + SEL: 0x93 + NVB: 0x70 + CT: 0x88 + UID_CLn: 04cfff + BCC: 0xbc + CRC: 0xbb7f [correct] + [CRC Status: Good] + +0000 00 fe 00 09 93 70 88 04 cf ff bc 7f bb .....p....... +``` + +If the Wireshark ISO14443a dissector is missing some commands or needs some other rework please [file a bug](https://bugs.wireshark.org/bugzilla/). From b98cb5d47cbd118d272695a2961e34e118aeca63 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sun, 18 Aug 2019 21:32:30 +0200 Subject: [PATCH 016/347] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 81c676b8d..0968b1f06 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ _Note that it also supports other Proxmark3 platforms as well!_ |[Notes on Frame format](/doc/new_frame_format.md)||| |[Notes on external flash](/doc/ext_flash_notes.md)||| |[Notes on Termux / Android](/doc/termux_notes.md)||| +|[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||| |[Developing standalone mode](/armsrc/Standalone/readme.md)|[Wiki about standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) || |[Donations](#Donations)||| @@ -54,6 +55,7 @@ If you intend to contribute to the code, please read the [coding style notes](HA - Internal notes on [external flash](/doc/ext_flash_notes.md) - Internal notes on [standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) - Internal notes on [Termux / Android](/doc/termux_notes.md) +- Internal notes on [Wireshark / tracedata](/doc/trace_wireshark_notes.md) ## Cheat sheet Thanks to Alex Dibs, you can enjoy a [command cheat sheet](/doc/cheatsheet.md) From 71c5ae1e1e66bb459ffc87c910f6f0ee69e75274 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 18 Aug 2019 23:35:14 +0200 Subject: [PATCH 017/347] make travis great again (yml parsing failure) --- .travis.yml | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1c5a6866..334b8c890 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,30 +36,22 @@ addons: taps: RfidResearchGroup/proxmark3 install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew info proxmark3; - brew options proxmark3; - brew install --HEAD proxmark3; - elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + brew options proxmark3; + brew install --verbose --HEAD proxmark3; + elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean; make all V=1; fi before_script: - chmod +x pm3test.sh - -script: + +script: ## start and run a test script if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then proxmark3 -h ; -# cd /Users/travis/Library/Caches/Homebrew/proxmark3--git; -# chmod +x pm3test.sh; -# pwd; -# ls -la; -# cd client; -# ls-la; -# cd ..; -# ./pm3test.sh; - elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./pm3test.sh; fi From 6f9ec6dd2426ead3eda737918ff00771700a939b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 19 Aug 2019 15:18:17 +0200 Subject: [PATCH 018/347] FIX: 'spiffs : fixes the device going rouge with bad memory reading' Thanks @megabug --- armsrc/spiffs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/armsrc/spiffs.c b/armsrc/spiffs.c index cb4412264..0296b7620 100644 --- a/armsrc/spiffs.c +++ b/armsrc/spiffs.c @@ -96,9 +96,9 @@ static s32_t rdv40_spiffs_llerase(u32_t addr, u32_t size) { //////////////////////////////////////////////////////////////////////////////// ////// SPIFFS LOW LEVEL OPERATIONS ///////////////////////////////////////////// -static u8_t spiffs_work_buf[RDV40_SPIFFS_WORKBUF_SZ]; -static u8_t spiffs_fds[RDV40_SPIFFS_FDBUF_SZ]; -static u8_t spiffs_cache_buf[RDV40_SPIFFS_CACHE_SZ]; +static u8_t spiffs_work_buf[RDV40_SPIFFS_WORKBUF_SZ] __attribute__((aligned)); +static u8_t spiffs_fds[RDV40_SPIFFS_FDBUF_SZ] __attribute__((aligned)); +static u8_t spiffs_cache_buf[RDV40_SPIFFS_CACHE_SZ] __attribute__((aligned)); static spiffs fs; From a6e5f9922fbfaaa25f17fc50b60dfdaddb56ebd7 Mon Sep 17 00:00:00 2001 From: sguerrini97 Date: Mon, 19 Aug 2019 17:10:25 +0200 Subject: [PATCH 019/347] PCF7931: Print found single/consecutive block(s), fixes to block 1 check and some comments Printing blocks makes it easier to manually reorder blocks when block 0 and 1 are not transmitted --- armsrc/pcf7931.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index 2c679b31f..9f1283b8c 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -146,16 +146,24 @@ bool IsBlock0PCF7931(uint8_t *block) { bool IsBlock1PCF7931(uint8_t *block) { // assuming all RFU bits are set to 0 + + uint8_t rb1 = block[14] & 0x80; + uint8_t rfb = block[14] & 0x7f; + uint8_t rlb = block[15]; + if (block[10] == 0 && block[11] == 0 && block[12] == 0 && block[13] == 0) { - - if ((block[14] & 0x7f) <= 9 - && block[15] <= 9) { + // block 1 is sent only if (RLB >= 1 && RFB <= 1) or RB1 enabled + if (rfb <= rlb + && rfb <= 9 + && rlb <= 9 + && ((rfb <= 1 && rlb >= 1) || rb1)) { return true; } } + return false; } @@ -200,9 +208,11 @@ void ReadPCF7931() { // our logic breaks if we don't get at least two blocks if (n < 2) { + // skip if all 0s block or no blocks if (n == 0 || !memcmp(tmp_blocks[0], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16)) continue; + // add block to single blocks list if (single_blocks_cnt < max_blocks) { for (i = 0; i < single_blocks_cnt; ++i) { if (!memcmp(single_blocks[i], tmp_blocks[0], 16)) { @@ -212,6 +222,7 @@ void ReadPCF7931() { } if (j != 1) { memcpy(single_blocks[single_blocks_cnt], tmp_blocks[0], 16); + print_result("got single block", single_blocks[single_blocks_cnt], 16); single_blocks_cnt++; } j = 0; @@ -221,6 +232,10 @@ void ReadPCF7931() { } Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors); + for (i = 0; i < n; ++i) + { + print_result("got consecutive blocks", tmp_blocks[i], 16); + } i = 0; if (!found_0_1) { @@ -282,7 +297,7 @@ void ReadPCF7931() { Dbprintf("Button pressed, stopping."); goto end; } - } while (found_blocks != max_blocks); + } while (found_blocks < max_blocks); end: Dbprintf("-----------------------------------------"); From e12db2bb5324b02c7bb20332be83df492daa68ca Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Aug 2019 18:43:01 +0300 Subject: [PATCH 020/347] travis osx (#339) changed homebrew install to make all. added pwd to twst script --- .travis.yml | 5 +++-- pm3test.sh | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 334b8c890..5357326c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,8 @@ install: if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew info proxmark3; brew options proxmark3; - brew install --verbose --HEAD proxmark3; + make clean; + make all V=1; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean; make all V=1; @@ -51,7 +52,7 @@ before_script: script: ## start and run a test script if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - proxmark3 -h ; + ./pm3test.sh; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./pm3test.sh; fi diff --git a/pm3test.sh b/pm3test.sh index e127944f6..6c7328475 100644 --- a/pm3test.sh +++ b/pm3test.sh @@ -49,6 +49,9 @@ function CheckExecute() { printf "\n${C_BLUE}RRG/Iceman Proxmark3 test tool ${C_NC}\n\n" +printf "work directory: " +pwd + if [ "$TRAVIS_COMMIT" ]; then if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo "Travis branch: $TRAVIS_BRANCH slug: $TRAVIS_REPO_SLUG commit: $TRAVIS_COMMIT" From ab2100879ed2cd50c614f4afa7fc337d82a339f6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Aug 2019 17:47:11 +0200 Subject: [PATCH 021/347] Get btpin/btfactory available in FPC DEV builds --- client/cmdusart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmdusart.c b/client/cmdusart.c index 0b668bbe7..26b972f82 100644 --- a/client/cmdusart.c +++ b/client/cmdusart.c @@ -763,8 +763,8 @@ static int CmdUsartRXhex(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"btpin", CmdUsartBtPin, IfPm3FpcUsartHostFromUsb, "Change BT add-on PIN"}, - {"btfactory", CmdUsartBtFactory, IfPm3FpcUsartHostFromUsb, "Reset BT add-on to factory settings"}, + {"btpin", CmdUsartBtPin, IfPm3FpcUsartFromUsb, "Change BT add-on PIN"}, + {"btfactory", CmdUsartBtFactory, IfPm3FpcUsartFromUsb, "Reset BT add-on to factory settings"}, {"tx", CmdUsartTX, IfPm3FpcUsartDevFromUsb, "Send string over USART"}, {"rx", CmdUsartRX, IfPm3FpcUsartDevFromUsb, "Receive string over USART"}, {"txrx", CmdUsartTXRX, IfPm3FpcUsartDevFromUsb, "Send string over USART and wait for response"}, From a97c811dd18629741d8b0cf9b27d6dfb41baecd8 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Aug 2019 17:50:53 +0200 Subject: [PATCH 022/347] pm3test +x --- pm3test.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 pm3test.sh diff --git a/pm3test.sh b/pm3test.sh old mode 100644 new mode 100755 From 5be53281dae5e014c305c41e37eef25c203bcba0 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Aug 2019 18:56:00 +0300 Subject: [PATCH 023/347] check get rid of chmod --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5357326c6..17b15fa55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,9 +46,6 @@ install: make all V=1; fi -before_script: - - chmod +x pm3test.sh - script: ## start and run a test script if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then From da279dec3b5317c1ab581094241dc5cb0e93cc3c Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Aug 2019 19:01:08 +0300 Subject: [PATCH 024/347] ignore test if fail --- pm3test.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pm3test.sh b/pm3test.sh index 6c7328475..881c17f23 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -5,6 +5,7 @@ cd "$PM3PATH" || exit 1 C_RED='\033[0;31m' C_GREEN='\033[0;32m' +C_YELLOW='\033[0;33m' C_BLUE='\033[0;34m' C_NC='\033[0m' # No Color @@ -25,7 +26,7 @@ function CheckFileExist() { return 1 } -# title, command line, check result, repeat several times if failed +# title, command line, check result, repeat several times if failed, ignore if fail function CheckExecute() { if [ $4 ]; then @@ -43,6 +44,12 @@ function CheckExecute() { if [ ! $I == "e" ]; then echo "retry $I"; fi done + + if [ $5 ]; then + echo -e "$1 ${C_YELLOW}[Ignored]${C_NC}" + return 0 + fi + echo -e "$1 ${C_RED}[Fail]${C_NC}" return 1 } @@ -78,7 +85,7 @@ while true; do if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi - if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat"; then break; fi + if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" From 5a603e296c4358381d4eadf76319dca739141570 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Aug 2019 19:09:28 +0300 Subject: [PATCH 025/347] add iclass test --- pm3test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pm3test.sh b/pm3test.sh index 881c17f23..beb8e29c6 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -86,6 +86,7 @@ while true; do if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi + if ! CheckExecute "hf mf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "found:"; then break; fi if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" From 48fdf62c09acec5bdde4fe3186e36de993e13ed1 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Aug 2019 19:20:02 +0300 Subject: [PATCH 026/347] iclass test fix --- pm3test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pm3test.sh b/pm3test.sh index beb8e29c6..18e693fbe 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -86,7 +86,7 @@ while true; do if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi - if ! CheckExecute "hf mf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "found:"; then break; fi + if ! CheckExecute "hf mf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "verified ok"; then break; fi if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" From 2b1f6217d5501405296128b2d1d8a44df951a57a Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Aug 2019 19:35:14 +0300 Subject: [PATCH 027/347] appveyor add test --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 3b937c197..4d47bd30f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -321,6 +321,8 @@ test_script: ExecTest "hf mf hardnested" "hf mf hardnested" {bash -lc "cd ~/client;./proxmark3 -c 'hf mf hardnested t 1 000000000000'"} "found:" + ExecTest "hf mf iclass" "hf mf iclass" {bash -lc "cd ~/client;./proxmark3 -c 'hf iclass loclass t'"} "verified ok" + #proxmark crypto tests From dbfe3c277d039b33f6c608095a6c5bb8cebb57dd Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Aug 2019 19:53:59 +0300 Subject: [PATCH 028/347] add V=1 to make --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 4d47bd30f..a1276ca1e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -113,7 +113,7 @@ build_script: #make - bash -c -i 'pwd;make clean;make all' + bash -c -i 'pwd;make clean;make all V=1' #some checks From 2a91310bf505ba35dc8824e5fc87e3352a1afb21 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Aug 2019 18:33:43 +0200 Subject: [PATCH 029/347] pm3test: remove spurious spaces --- pm3test.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pm3test.sh b/pm3test.sh index 18e693fbe..071cecaea 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -11,17 +11,17 @@ C_NC='\033[0m' # No Color # title, file name or file wildcard to check function CheckFileExist() { - + if [ -f "$2" ]; then echo -e "$1 ${C_GREEN}[OK]${C_NC}" return 0 - fi - + fi + if ls $2 1> /dev/null 2>&1; then echo -e "$1 ${C_GREEN}[OK]${C_NC}" return 0 fi - + echo -e "$1 ${C_RED}[Fail]${C_NC}" return 1 } @@ -34,8 +34,8 @@ function CheckExecute() { else local RETRY="e" fi - - for I in $RETRY + + for I in $RETRY do if eval "$2 | grep -q '$3'"; then echo -e "$1 ${C_GREEN}[OK]${C_NC}" @@ -43,13 +43,13 @@ function CheckExecute() { fi if [ ! $I == "e" ]; then echo "retry $I"; fi done - - + + if [ $5 ]; then echo -e "$1 ${C_YELLOW}[Ignored]${C_NC}" return 0 fi - + echo -e "$1 ${C_RED}[Fail]${C_NC}" return 1 } @@ -67,9 +67,9 @@ if [ "$TRAVIS_COMMIT" ]; then fi fi -printf "git branch: " +printf "git branch: " git describe --all -printf "git sha: " +printf "git sha: " git rev-parse HEAD echo "" @@ -88,7 +88,7 @@ while true; do if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi if ! CheckExecute "hf mf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "verified ok"; then break; fi if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi - + printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" exit 0 done From e2e8cecc304d0fd3b71ee3d35d0599db7f8829f6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Aug 2019 18:40:25 +0200 Subject: [PATCH 030/347] pm3test: show output in case of failure --- pm3test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pm3test.sh b/pm3test.sh index 071cecaea..ac0624fdf 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -37,7 +37,8 @@ function CheckExecute() { for I in $RETRY do - if eval "$2 | grep -q '$3'"; then + RES=$(eval "$2") + if echo "$RES" | grep -q "$3"; then echo -e "$1 ${C_GREEN}[OK]${C_NC}" return 0 fi @@ -51,6 +52,7 @@ function CheckExecute() { fi echo -e "$1 ${C_RED}[Fail]${C_NC}" + echo -e "Execution trace:\n$RES" return 1 } From 6e64f67fe32b29a8213b301f508322bd87129972 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Aug 2019 19:09:17 +0200 Subject: [PATCH 031/347] pm3test: more tests --- pm3test.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pm3test.sh b/pm3test.sh index ac0624fdf..119fffbb8 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -76,21 +76,35 @@ git rev-parse HEAD echo "" while true; do + printf "\n${C_BLUE}Testing files:${C_NC}\n" if ! CheckFileExist "proxmark3 exists" "./client/proxmark3"; then break; fi if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi if ! CheckFileExist "bootrom exists" "./bootrom/obj/bootrom.elf"; then break; fi if ! CheckFileExist "hardnested tables exists" "./client/hardnested/tables/*.z"; then break; fi + printf "\n${C_BLUE}Testing basic help:${C_NC}\n" if ! CheckExecute "proxmark help" "./client/proxmark3 -h" "wait"; then break; fi if ! CheckExecute "proxmark help text ISO7816" "./client/proxmark3 -t 2>&1" "ISO7816"; then break; fi if ! CheckExecute "proxmark help text hardnested" "./client/proxmark3 -t 2>&1" "hardnested"; then break; fi - if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi + printf "\n${C_BLUE}Testing data manipulation:${C_NC}\n" + if ! CheckExecute "reveng test" "./client/proxmark3 -c 'reveng -w 8 -s 01020304e3 010204039d'" "CRC-8/SMBUS"; then break; fi + printf "\n${C_BLUE}Testing LF:${C_NC}\n" + if ! CheckExecute "lf em4x05 test" "./client/proxmark3 -c 'data load traces/em4x05.pm3;lf search'" "FDX-B ID found"; then break; fi + + printf "\n${C_BLUE}Testing HF:${C_NC}\n" + if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi - if ! CheckExecute "hf mf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "verified ok"; then break; fi + if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "verified ok"; then break; fi if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi + printf "\n${C_BLUE}Testing tools:${C_NC}\n" + # Need a decent example for mfkey32... + if ! CheckExecute "mfkey32v2 test" "tools/mfkey/mfkey32v2 12345678 1AD8DF2B 1D316024 620EF048 30D6CB07 C52077E2 837AC61A" "Found Key: \[a0a1a2a3a4a5\]"; then break; fi + if ! CheckExecute "mfkey64 test" "tools/mfkey/mfkey64 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439" "Found Key: \[ffffffffffff\]"; then break; fi + if ! CheckExecute "mfkey64 long trace test" "tools/mfkey/./mfkey64 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea" "Found Key: \[091e639cb715\]"; then break; fi + if ! CheckExecute "nonce2key test" "tools/nonce2key/nonce2key e9cadd9c a8bf4a12 a020a8285858b090 050f010607060e07 5693be6c00000000" "key recovered: fc00018778f7"; then break; fi printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" exit 0 done From f06846e2d06b57cdaf1e3e1413e5369cfbf97fc1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 19 Aug 2019 20:24:08 +0200 Subject: [PATCH 032/347] chg: 'hf iclass loclass' - break attack earlier if one csn byte recovery fails. No need to try run it. and some colors... --- client/loclass/cipherutils.c | 13 ++++++++----- client/loclass/elite_crack.c | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index b11f6883a..80364d4e1 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -39,7 +39,7 @@ #include #include #include - +#include "util.h" // sprint_hex #include "commonutil.h" // ARRAYLEN #include "fileutils.h" @@ -160,23 +160,26 @@ void printarr(const char *name, uint8_t *arr, int len) { } void printvar(const char *name, uint8_t *arr, int len) { - int cx, i; +/* + int cx, i; size_t outsize = 40 + strlen(name) + len * 2; char *output = calloc(outsize, sizeof(char)); cx = snprintf(output, outsize, "%s = ", name); for (i = 0; i < len; i++) { cx += snprintf(output + cx, outsize - cx, "%02x", *(arr + i)); //2 bytes per byte } - PrintAndLogEx(NORMAL, output); free(output); + */ + PrintAndLogEx(NORMAL, "%s = " _YELLOW_("%s"), name, sprint_hex(arr, len) ); + } void printarr_human_readable(const char *title, uint8_t *arr, int len) { - int cx, i; + int cx = 0, i; size_t outsize = 100 + strlen(title) + len * 4; char *output = calloc(outsize, sizeof(char)); - cx = snprintf(output, outsize, "\n\t%s\n", title); + PrintAndLogEx(NORMAL, "\n %s", title); for (i = 0; i < len; i++) { if (i % 16 == 0) cx += snprintf(output + cx, outsize - cx, "\n%02x| ", i); diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index a4296f476..74ebfe608 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -479,7 +479,7 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[]) { return 1; } else { PrintAndLogEx(NORMAL, "\n"); - PrintAndLogEx(SUCCESS, "Key verified ok!\n"); + PrintAndLogEx(SUCCESS, _GREEN_("Key verified ok!") ); } return 0; } @@ -502,11 +502,19 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { for (i = 0 ; i * itemsize < dumpsize ; i++) { memcpy(attack, dump + i * itemsize, itemsize); errors += bruteforceItem(*attack, keytable); + if ( errors ) + break; } free(attack); t1 = msclock() - t1; PrintAndLogEx(SUCCESS, "time: %" PRIu64 " seconds", t1 / 1000); + + if ( errors ) { + PrintAndLogEx(ERR, "loclass exiting. Try run " _YELLOW_("`hf iclass sim 2`") "again and collect new data"); + return 1; + } + // Pick out the first 16 bytes of the keytable. // The keytable is now in 16-bit ints, where the upper 8 bits // indicate crack-status. Those must be discarded for the @@ -516,8 +524,10 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { for (i = 0 ; i < 16 ; i++) { first16bytes[i] = keytable[i] & 0xFF; - if (!(keytable[i] & CRACKED)) + if (!(keytable[i] & CRACKED)) { PrintAndLogEx(WARNING, "Warning: we are missing byte %d, custom key calculation will fail...", i); + return 1; + } } errors += calculateMasterKey(first16bytes, NULL); return errors; @@ -532,7 +542,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { int bruteforceFile(const char *filename, uint16_t keytable[]) { FILE *f = fopen(filename, "rb"); if (!f) { - PrintAndLogEx(WARNING, "Failed to read from file '%s'", filename); + PrintAndLogEx(WARNING, "Failed to read from file " _YELLOW_("%s"), filename); return 1; } @@ -612,7 +622,7 @@ static int _testBruteforce() { } else if (fileExists("client/loclass/iclass_dump.bin")) { errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable); } else { - PrintAndLogEx(ERR, "Error: The file iclass_dump.bin was not found!"); + PrintAndLogEx(ERR, "Error: The file " _YELLOW_("iclass_dump.bin") "was not found!"); } } return errors; From f4c810f83bbed7e9fbc332646210ac9d46a5bedd Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 16 Aug 2019 22:49:34 +0200 Subject: [PATCH 033/347] allow override of CFLAG & alike, remove /opt paths --- client/Makefile | 63 +++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/client/Makefile b/client/Makefile index 89f8cfb44..bf047ff7d 100644 --- a/client/Makefile +++ b/client/Makefile @@ -19,25 +19,20 @@ CC = gcc CXX = g++ LD = g++ TAR = tar -TARFLAGS = -C .. --ignore-failed-read -rvf +TARFLAGS ?= -v --ignore-failed-read -r +TARFLAGS += -C .. -f RM = rm -f MV = mv TOUCH = touch FALSE = false -ENV_LDFLAGS := $(LDFLAGS) -ENV_CFLAGS := $(CFLAGS) - platform = $(shell uname) VPATH = ../common ../common/zlib uart OBJDIR = obj -LDLIBS = -ifneq ($(platform),Darwin) - LDLIBS += -L/opt/local/lib -endif -LDLIBS += -L/usr/local/lib -lreadline -lpthread -lm +LDLIBS ?= -L/usr/local/lib +LDLIBS += -lreadline -lpthread -lm # RPi Zero gcc requires -latomic # but MacOSX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld @@ -55,14 +50,16 @@ MBEDTLSLIB = $(MBEDTLSLIBPATH)/libmbedtls.a CBORLIBPATH = ./tinycbor CBORLIB = $(CBORLIBPATH)/tinycbor.a REVENGFLAGS = -DPRESETS -LIBS = -I../common/zlib -Iuart -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -INCLUDES_CLIENT = -I. -I../include -I../common -I/opt/local/include $(LIBS) -LDFLAGS = $(ENV_LDFLAGS) -CFLAGS = $(ENV_CFLAGS) -std=c99 -D_ISOC99_SOURCE $(REVENGFLAGS) $(INCLUDES_CLIENT) -Wall -Werror -g -O3 +LIBS = -I../common/zlib -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) +INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) +CFLAGS ?= -Wall -Werror -g -O3 +# We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: +PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(REVENGFLAGS) $(INCLUDES_CLIENT) ifneq (,$(findstring MINGW,$(platform))) - CFLAGS += -mno-ms-bitfields + PM3CFLAGS += -mno-ms-bitfields endif -CXXFLAGS = -I../include -Wall -O3 +CXXFLAGS ?= -Wall -Werror -O3 +PM3CXXFLAGS = $(CXXFLAGS) -I../include LUAPLATFORM = generic ifneq (,$(findstring MINGW,$(platform))) @@ -93,7 +90,7 @@ ifeq ($(QTINCLUDES), ) MOC = $(shell pkg-config --variable=moc_location QtCore) UIC = $(shell pkg-config --variable=uic_location QtCore) else - CXXFLAGS += -std=c++11 -fPIC + PM3CXXFLAGS += -std=c++11 -fPIC endif ifeq ($(QTINCLUDES), ) # if both pkg-config commands failed, search in common places @@ -103,7 +100,7 @@ ifeq ($(QTINCLUDES), ) ifneq ($(wildcard $(QTDIR)/include/QtWidgets),) QTINCLUDES += -I$(QTDIR)/include/QtWidgets QTLDLIBS = -L$(QTDIR)/lib -lQt5Widgets -lQt5Gui -lQt5Core - CXXFLAGS += -std=c++11 -fPIC + PM3CXXFLAGS += -std=c++11 -fPIC endif MOC = $(QTDIR)/bin/moc UIC = $(QTDIR)/bin/uic @@ -113,7 +110,7 @@ endif ifneq ($(QTLDLIBS),) QTGUIOBJS = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o - CFLAGS += -DHAVE_GUI + PM3CFLAGS += -DHAVE_GUI else QTGUIOBJS = $(OBJDIR)/guidummy.o endif @@ -370,64 +367,52 @@ print-%: ; @echo $* = $($*) $(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%_NOSIMD.d $(info [-] CC(NOSIMD) $<) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_NOSIMD.Td) $(CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS:%.Td=%_NOSIMD.Td) $(PM3CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_NOSIMD.Td $(OBJDIR)/$*_NOSIMD.d $(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%_MMX.d $(info [-] CC(MMX) $<) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_MMX.Td) $(CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS:%.Td=%_MMX.Td) $(PM3CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_MMX.Td $(OBJDIR)/$*_MMX.d $(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%_SSE2.d $(info [-] CC(SSE2) $<) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_SSE2.Td) $(CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS:%.Td=%_SSE2.Td) $(PM3CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_SSE2.Td $(OBJDIR)/$*_SSE2.d $(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%_AVX.d $(info [-] CC(AVX) $<) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX.Td) $(CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_AVX.Td $(OBJDIR)/$*_AVX.d $(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%_AVX2.d $(info [-] CC(AVX2) $<) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX2.Td) $(CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX2.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_AVX2.Td $(OBJDIR)/$*_AVX2.d $(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%_AVX512.d $(info [-] CC(AVX512) $<) - $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d %.o: %.c $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d $(info [-] CC $<) - $(Q)$(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) $(ZLIBFLAGS) -c -o $@ $< $(Q)$(POSTCOMPILE) %.o: %.cpp $(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.d $(info [-] CXX $<) - $(Q)$(CXX) $(DEPFLAGS) $(CXXFLAGS) $(QTINCLUDES) -c -o $@ $< + $(Q)$(CXX) $(DEPFLAGS) $(PM3CXXFLAGS) $(QTINCLUDES) -c -o $@ $< $(Q)$(POSTCOMPILE) %.o: %.m $(OBJDIR)/%.o : %.m $(OBJDIR)/%.d $(info [-] CC $<) - $(Q)$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $< $(Q)$(POSTCOMPILE) -#$(CMDOBJS) $(COREOBJS): $(notdir $(%.c)) %.d -# $(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $< -# $(POSTCOMPILE) - -#$(ZLIBOBJS): $(notdir $(%.c)) %.d -# $(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $< -# $(POSTCOMPILE) - -#$(QTGUIOBJS): $(notdir $(%.cpp)) %.d -# $(CXX) $(DEPFLAGS) $(CXXFLAGS) -c -o $@ $< -# $(POSTCOMPILE) - DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(ZLIBSRCS) $(REVENGSRCS)) \ $(patsubst %.o, %.d, $(MULTIARCHOBJS)) \ $(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \ From cce92d7431aa0df312c17ac4c2aeb882d3d510b1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 17 Aug 2019 23:40:38 +0200 Subject: [PATCH 034/347] Attempt to unify host makefiles with a Makefile.host --- Makefile.host | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Makefile.host diff --git a/Makefile.host b/Makefile.host new file mode 100644 index 000000000..9ab7ce8ca --- /dev/null +++ b/Makefile.host @@ -0,0 +1,72 @@ +# Hide full compilation line: +ifneq ($(V),1) + Q?=@ +endif +# To see full command lines, use make V=1 + +CC = gcc +LD = gcc +RM = rm -f +MV = mv +CP = cp -a +MKDIR = mkdir + +CFLAGS ?= -Wall -Werror -O3 +CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES) + +platform = $(shell uname) + +ifeq ($(platform),Darwin) +AR= /usr/bin/ar rcs +RANLIB= /usr/bin/ranlib +else +AR= ar rcs +RANLIB= ranlib +endif +RM= rm -f +RMDIR= rm -rf + +vpath %.c $(MYSRCPATHS) + +# Flags to generate temporary dependency files +DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td +# make temporary to final dependency files after successful compilation +POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d + +BINDIR := . +OBJDIR := obj + +MYOBJS = $(MYSRCS:%.c=$(OBJDIR)/%.o) +CLEAN = $(foreach bin,$(MYLIBS) $(BINS) $(LIB_A),$(BINDIR)/$(bin)) + +all: $(foreach bin,$(MYLIBS) $(BINS) $(LIB_A),$(BINDIR)/$(bin)) + +clean: + $(Q)$(RM) $(CLEAN) + $(Q)$(RMDIR) $(OBJDIR) + +.PHONY: all clean + +$(BINDIR)/$(LIB_A): $(MYOBJS) + $(info [=] AR $(notdir $@)) + $(Q)$(AR) $@ $(MYOBJS) + $(Q)$(RANLIB) $@ + +$(BINDIR)/% : $(OBJDIR)/%.o $(MYOBJS) $(MYLIBS) + $(info [=] LD $(notdir $@)) + $(Q)$(LD) $(LDFLAGS) $(MYOBJS) $< -o $@ $(MYLIBS) + +$(OBJDIR)/%.o : %.c | $(OBJDIR) + $(info [-] CC $<) + $(Q)$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $< + $(Q)$(POSTCOMPILE) + +$(OBJDIR): + $(Q)$(MKDIR) $(OBJDIR) + +DEPENDENCY_FILES = $(MYOBJS:%.o=%.d) $(BINS:%=$(OBJDIR)/%.d) + +$(DEPENDENCY_FILES): ; +.PRECIOUS: $(DEPENDENCY_FILES) + +-include $(DEPENDENCY_FILES) From 9767c075d90ea8027f6761410dbb1aedc54731d0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 16 Aug 2019 22:06:04 +0200 Subject: [PATCH 035/347] rework jansson Makefile, use Makefile.host --- client/jansson/Makefile | 74 ++++------------------------------------- 1 file changed, 7 insertions(+), 67 deletions(-) diff --git a/client/jansson/Makefile b/client/jansson/Makefile index e06ffbc76..dc4ae230b 100644 --- a/client/jansson/Makefile +++ b/client/jansson/Makefile @@ -1,81 +1,21 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 - -include_HEADERS = jansson.h -nodist_include_HEADERS = jansson_config.h - -LIB_A = libjansson.a -libjansson_la_SOURCES = \ +MYSRCPATHS = +MYINCLUDES = -I. +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE -Wno-unused-function +MYDEFS = -DHAVE_STDINT_H +MYSRCS = \ dump.c \ error.c \ hashtable.c \ - hashtable.h \ hashtable_seed.c \ - jansson_private.h \ load.c \ - lookup3.h \ memory.c \ pack_unpack.c \ strbuffer.c \ - strbuffer.h \ strconv.c \ utf.c \ - utf.h \ path.c \ value.c -libjansson_la_LDFLAGS = \ - -no-undefined \ - -export-symbols-regex '^json_' \ - -version-info 15:0:11 +LIB_A = libjansson.a -CFILES = $(filter %.c, $(libjansson_la_SOURCES)) -CMDOBJS = $(CFILES:%.c=%.o) -CLEAN = $(CMDOBJS) - -platform = $(shell uname) - -CC= gcc -CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function - -LDFLAGS= $(SYSLDFLAGS) $(libjansson_la_LDFLAGS) -LIBS= $(SYSLIBS) $(MYLIBS) -DEFAULT_INCLUDES = -I. -DEFS = -DHAVE_STDINT_H - -ifeq ($(platform),Darwin) -AR= /usr/bin/ar rcs -RANLIB= /usr/bin/ranlib -else -AR= ar rcs -RANLIB= ranlib -endif -RM= rm -f -TST= echo - -SYSLDFLAGS= -SYSLIBS= - -MYLIBS= -MYOBJS= - -$(LIB_A): $(CMDOBJS) - $(info [=] AR $@) - $(Q)$(AR) $(LIB_A) $(CMDOBJS) - $(Q)$(RANLIB) $(LIB_A) - -all: $(LIB_A) - -clean: - $(Q)$(RM) $(CLEAN) - $(Q)$(RM) $(LIB_A) - -%.o: %.c - $(info [-] CC $<) - $(Q)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(CFLAGS) -c -o $@ $< $(LIBS) - -.PHONY: all clean - +include ../../Makefile.host From 7b7883380056262a45a489fd081c7b747be9c23b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 16 Aug 2019 22:06:25 +0200 Subject: [PATCH 036/347] rework liblua Makefile and skip clients compilation, use Makefile.host --- client/liblua/Makefile | 190 +++++------------------------------------ 1 file changed, 22 insertions(+), 168 deletions(-) diff --git a/client/liblua/Makefile b/client/liblua/Makefile index 2b3d7614f..250f4b7ee 100644 --- a/client/liblua/Makefile +++ b/client/liblua/Makefile @@ -1,106 +1,27 @@ -# Makefile for building Lua -# See ../doc/readme.html for installation and customization instructions. +MYSRCPATHS = +MYINCLUDES = -I. +# Lua lib is not ready for C99 style... +#MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYCFLAGS = +MYDEFS = -DLUA_COMPAT_ALL $(SYSCFLAGS) +MYSRCS = lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c \ + lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c \ + ltm.c lundump.c lvm.c lzio.c \ + lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c \ + lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c -# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= +SYSCFLAGS= -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 +LIB_A= liblua.a # Your platform. See PLATS for possible values. PLAT= none -platform= $(shell uname) - -CC= gcc -CFLAGS= -O3 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS) -LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) -LIBS= -lm $(SYSLIBS) $(MYLIBS) - -ifeq ($(platform),Darwin) -AR= /usr/bin/ar rc -RANLIB= /usr/bin/ranlib -else -AR= ar rc -RANLIB= ranlib -endif -RM= rm -f - -SYSCFLAGS= -SYSLDFLAGS= -SYSLIBS= - -MYCFLAGS= -MYLDFLAGS= -MYLIBS= -MYOBJS= - -# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= - -%.o: %.c - $(info [-] CC $<) - $(Q)$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< - PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris -LUA_A= liblua.a -CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ - lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \ - ltm.o lundump.o lvm.o lzio.o -LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \ - lmathlib.o loslib.o lstrlib.o ltablib.o loadlib.o linit.o -BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) - -LUA_T= lua -LUA_O= lua.o - -LUAC_T= luac -LUAC_O= luac.o - -ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O) -ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) -ALL_A= $(LUA_A) - -# Targets start here. default: $(PLAT) -all: $(ALL_T) - -o: $(ALL_O) - -a: $(ALL_A) - -$(LUA_A): $(BASE_O) - $(info [=] AR $@) - $(Q)$(AR) $@ $(BASE_O) - $(Q)$(RANLIB) $@ - -$(LUA_T): $(LUA_O) $(LUA_A) - $(info [=] LD $@) - $(Q)$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) - -$(LUAC_T): $(LUAC_O) $(LUA_A) - $(info [=] LD $@) - $(Q)$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) - -clean: - $(Q)$(RM) $(ALL_T) $(ALL_O) - -depend: - $(info GEN DEPS) - $(Q)$(CC) $(CFLAGS) -MM l*.c - -echo: - @echo "PLAT= $(PLAT)" - @echo "CC= $(CC)" - @echo "CFLAGS= $(CFLAGS)" - @echo "LDFLAGS= $(SYSLDFLAGS)" - @echo "LIBS= $(LIBS)" - @echo "AR= $(AR)" - @echo "RANLIB= $(RANLIB)" - @echo "RM= $(RM)" +include ../../Makefile.host # Convenience targets for popular platforms ALL= all @@ -110,99 +31,32 @@ none: @echo " $(PLATS)" aix: - $(Q)$(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall" + $(Q)$(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" ansi: $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI" bsd: - $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E" + $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" freebsd: - $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline" + $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" generic: $(ALL) linux: - $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -ltermcap -lncurses" + $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" macosx: - $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" + $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" mingw: - $(Q)$(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \ - "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ - "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe - $(Q)$(MAKE) "LUAC_T=luac.exe" luac.exe + $(Q)$(MAKE) $(ALL) posix: $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" solaris: - $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" - -# list targets that do not create files (but not all makes understand .PHONY) -.PHONY: all $(PLATS) default o a clean depend echo none - -# DO NOT DELETE - -lapi.o: lapi.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \ - lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h \ - lvm.h -lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h -lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h -lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h -lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ - lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \ - lstring.h ltable.h lvm.h -lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h -lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h -ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h -ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \ - ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \ - lfunc.h lstring.h lgc.h ltable.h lvm.h -ldo.o: ldo.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h ltm.h \ - lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h \ - lstring.h ltable.h lundump.h lvm.h -ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \ - lzio.h lmem.h lundump.h -lfunc.o: lfunc.c lua.h luaconf.h lfunc.h lobject.h llimits.h lgc.h \ - lstate.h ltm.h lzio.h lmem.h -lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ - lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h -linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h -liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h -llex.o: llex.c lua.h luaconf.h lctype.h llimits.h ldo.h lobject.h \ - lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h -lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h -lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ - ltm.h lzio.h lmem.h ldo.h lgc.h -loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h -lobject.o: lobject.c lua.h luaconf.h lctype.h llimits.h ldebug.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h -lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h -loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h -lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ - lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lfunc.h \ - lstring.h lgc.h ltable.h -lstate.o: lstate.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \ - ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h lstring.h \ - ltable.h -lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \ - ltm.h lzio.h lstring.h lgc.h -lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h -ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ - ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h -ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h -ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \ - lmem.h lstring.h lgc.h ltable.h -lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h -luac.o: luac.c lua.h luaconf.h lauxlib.h lobject.h llimits.h lstate.h \ - ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h -lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h -lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ - lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h -lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \ - lzio.h + $(Q)$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" +.PHONY: all $(PLATS) default clean depend none From 829934886fea392454f80fd47205253b1b7dc0e1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 16 Aug 2019 22:32:22 +0200 Subject: [PATCH 037/347] rework tinycbor Makefile, use Makefile.host --- client/tinycbor/Makefile | 62 +++++++--------------------------------- 1 file changed, 11 insertions(+), 51 deletions(-) diff --git a/client/tinycbor/Makefile b/client/tinycbor/Makefile index af22846e9..6470246d4 100644 --- a/client/tinycbor/Makefile +++ b/client/tinycbor/Makefile @@ -1,11 +1,10 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 - -LIB_A = tinycbor.a -tinycbor_SOURCES = \ +MYSRCPATHS = +MYINCLUDES = +# Strange errors on Mingw when compiling with C99 +#MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYCFLAGS = +MYDEFS = +MYSRCS = \ cborencoder.c \ cborencoder_close_container_checked.c \ cborerrorstrings.c \ @@ -15,48 +14,9 @@ tinycbor_SOURCES = \ cbortojson.c \ cborvalidation.c \ -CFILES = $(filter %.c, $(tinycbor_SOURCES)) -CMDOBJS = $(CFILES:%.c=%.o) -CLEAN = $(CMDOBJS) +LIB_A = tinycbor.a -platform = $(shell uname) - -CC= gcc -CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function -LIBS= $(SYSLIBS) $(MYLIBS) -DEFAULT_INCLUDES = -I. -I.. -DEFS = -DHAVE_STDINT_H - -ifeq ($(platform),Darwin) -AR= /usr/bin/ar rcs -RANLIB= /usr/bin/ranlib -else -AR= ar rcs -RANLIB= ranlib -endif -RM= rm -f -TST= echo - -SYSLDFLAGS= -SYSLIBS= - -MYLIBS= -MYOBJS= - -$(LIB_A): $(CMDOBJS) - $(info [=] AR $@) - $(Q)$(AR) $(LIB_A) $(CMDOBJS) - $(Q)$(RANLIB) $(LIB_A) - -all: $(LIB_A) - -clean: - $(Q)$(RM) $(CLEAN) - $(Q)$(RM) $(LIB_A) - -%.o: %.c - $(info [-] CC $<) - $(Q)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(CFLAGS) -c -o $@ $< $(LIBS) - -.PHONY: all clean +# Strange errors on Mingw when compiling with -O3 +CFLAGS ?= -Wall -Werror -O2 +include ../../Makefile.host From 5d699610c95ca2f71eb472db1de5bb33ad7e1fd5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 17 Aug 2019 11:03:15 +0200 Subject: [PATCH 038/347] rework hid-flasher Makefile --- tools/deprecated-hid-flasher/flasher/Makefile | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tools/deprecated-hid-flasher/flasher/Makefile b/tools/deprecated-hid-flasher/flasher/Makefile index bff511459..52b1229fe 100644 --- a/tools/deprecated-hid-flasher/flasher/Makefile +++ b/tools/deprecated-hid-flasher/flasher/Makefile @@ -5,30 +5,27 @@ #----------------------------------------------------------------------------- CC=gcc -CXX=g++ -#COMMON_FLAGS = -m32 +LD=gcc OBJDIR = obj -LDLIBS = -lreadline -lpthread -CFLAGS = -std=gnu99 -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3 +LDLIBS = +CFLAGS ?= -Wall -Werror -g -O3 +CFLAGS += -std=gnu99 ifeq ($(platform),Darwin) LDLIBS += -lusb-1.0 else LDLIBS += -lusb endif -LDFLAGS = $(COMMON_FLAGS) -CXXFLAGS = - RM = rm -f -BINS = flasher -CLEAN = flasher flasher.exe $(OBJDIR)/*.o *.o +BINS = pm3-hid-flasher +CLEAN = pm3-hid-flasher pm3-hid-flasher.exe $(OBJDIR)/*.o all: $(BINS) -flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(OBJDIR)/proxusb.o - $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@ +pm3-hid-flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(OBJDIR)/proxusb.o + $(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(OBJDIR)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< From aebfe0af1909ad655a81897190ba981d2fd0da1d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 17 Aug 2019 11:23:48 +0200 Subject: [PATCH 039/347] rework mfkey Makefile and move util_posix to common, use Makefile.host --- {client => common}/util_posix.c | 0 {client => common}/util_posix.h | 0 tools/mfkey/Makefile | 34 ++++++++++----------------------- 3 files changed, 10 insertions(+), 24 deletions(-) rename {client => common}/util_posix.c (100%) rename {client => common}/util_posix.h (100%) diff --git a/client/util_posix.c b/common/util_posix.c similarity index 100% rename from client/util_posix.c rename to common/util_posix.c diff --git a/client/util_posix.h b/common/util_posix.h similarity index 100% rename from client/util_posix.h rename to common/util_posix.h diff --git a/tools/mfkey/Makefile b/tools/mfkey/Makefile index 24508265a..27fa95aa0 100644 --- a/tools/mfkey/Makefile +++ b/tools/mfkey/Makefile @@ -1,27 +1,13 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 +MYSRCPATHS = ../../common ../../common/crapto1 +MYSRCS = crypto1.c crapto1.c bucketsort.c +MYINCLUDES = -I../../include -I../../common +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = -VPATH = ../../common ../../common/crapto1 ../../client -CC = gcc -LD = gcc -CFLAGS += -std=c99 -D_ISOC99_SOURCE -I../../include -I../../common -I../../client -Wall -O3 -LDFLAGS += +BINS = mfkey32 mfkey32v2 mfkey64 -OBJS = crypto1.o crapto1.o parity.o util_posix.o bucketsort.o -EXES = mfkey32 mfkey32v2 mfkey64 +include ../../Makefile.host -all: $(OBJS) $(EXES) - -%.o : %.c - $(info [-] CC $<) - $(Q)$(CC) $(CFLAGS) -c -o $@ $< - -% : %.c $(OBJS) - $(info [=] LD $@) - $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $< - -clean: - $(Q)rm -f $(OBJS) $(EXES) +mfkey32 : $(OBJDIR)/mfkey32.o $(MYOBJS) +mfkey32v2 : $(OBJDIR)/mfkey32v2.o $(MYOBJS) +mfkey64 : $(OBJDIR)/mfkey64.o $(MYOBJS) From 43ffed1a261f7a5af1480ff0009b9961e63551bd Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 17 Aug 2019 13:07:27 +0200 Subject: [PATCH 040/347] rework nonce2key Makefile, use common crapto1, use Makefile.host --- tools/nonce2key/Makefile | 39 +-- tools/nonce2key/crapto1.c | 549 ------------------------------------ tools/nonce2key/crapto1.h | 87 ------ tools/nonce2key/crypto1.c | 125 -------- tools/nonce2key/nonce2key.c | 4 +- 5 files changed, 10 insertions(+), 794 deletions(-) delete mode 100644 tools/nonce2key/crapto1.c delete mode 100644 tools/nonce2key/crapto1.h delete mode 100644 tools/nonce2key/crypto1.c diff --git a/tools/nonce2key/Makefile b/tools/nonce2key/Makefile index 481c3e275..8b5d05278 100644 --- a/tools/nonce2key/Makefile +++ b/tools/nonce2key/Makefile @@ -1,34 +1,11 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 +MYSRCPATHS = ../../common ../../common/crapto1 +MYSRCS = crypto1.c crapto1.c bucketsort.c +MYINCLUDES = -I../../include -I../../common +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = -CC = gcc -CFLAGS = -std=c99 -Wall -O3 -I. -LDFLAGS = -std=c99 -Wall -SRC := $(wildcard *.c) -OBJ := $(SRC:.c=.o) -DEP := $(SRC:.c=.d) -PROG := nonce2key +BINS = nonce2key -all: $(PROG) +include ../../Makefile.host -$(PROG): $(OBJ) - $(info [=] LD $@) - $(Q)$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ - -clean: - $(Q)$(RM) $(DEP) $(OBJ) $(PROG) - -ifneq ($(filter clean,$(MAKECMDGOALS)),clean) --include $(DEP) -endif - -%.d: %.c - $(info [-] GEN $@) - $(Q)$(CC) -MM $(CFLAGS) $< | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@ - -%.o: %.c - $(info [-] CC $<) - $(Q)$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< +nonce2key : $(OBJDIR)/nonce2key.o $(MYOBJS) diff --git a/tools/nonce2key/crapto1.c b/tools/nonce2key/crapto1.c deleted file mode 100644 index 3be92c0f2..000000000 --- a/tools/nonce2key/crapto1.c +++ /dev/null @@ -1,549 +0,0 @@ -/* crapto1.c - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, US$ - - Copyright (C) 2008-2014 bla -*/ -#include "crapto1.h" -#include - -#if !defined LOWMEM && defined __GNUC__ -static uint8_t filterlut[1 << 20]; -static void __attribute__((constructor)) fill_lut() { - uint32_t i; - for (i = 0; i < 1 << 20; ++i) - filterlut[i] = filter(i); -} -#define filter(x) (filterlut[(x) & 0xfffff]) -#endif - - - -typedef struct bucket { - uint32_t *head; - uint32_t *bp; -} bucket_t; - -typedef bucket_t bucket_array_t[2][0x100]; - -typedef struct bucket_info { - struct { - uint32_t *head, *tail; - } bucket_info[2][0x100]; - uint32_t numbuckets; -} bucket_info_t; - - -static void bucket_sort_intersect(uint32_t *const estart, uint32_t *const estop, - uint32_t *const ostart, uint32_t *const ostop, - bucket_info_t *bucket_info, bucket_array_t bucket) { - uint32_t *p1, *p2; - uint32_t *start[2]; - uint32_t *stop[2]; - - start[0] = estart; - stop[0] = estop; - start[1] = ostart; - stop[1] = ostop; - - // init buckets to be empty - for (uint32_t i = 0; i < 2; i++) { - for (uint32_t j = 0x00; j <= 0xff; j++) { - bucket[i][j].bp = bucket[i][j].head; - } - } - - // sort the lists into the buckets based on the MSB (contribution bits) - for (uint32_t i = 0; i < 2; i++) { - for (p1 = start[i]; p1 <= stop[i]; p1++) { - uint32_t bucket_index = (*p1 & 0xff000000) >> 24; - *(bucket[i][bucket_index].bp++) = *p1; - } - } - - - // write back intersecting buckets as sorted list. - // fill in bucket_info with head and tail of the bucket contents in the list and number of non-empty buckets. - for (uint32_t i = 0; i < 2; i++) { - p1 = start[i]; - uint32_t nonempty_bucket = 0; - for (uint32_t j = 0x00; j <= 0xff; j++) { - if (bucket[0][j].bp != bucket[0][j].head && bucket[1][j].bp != bucket[1][j].head) { // non-empty intersecting buckets only - bucket_info->bucket_info[i][nonempty_bucket].head = p1; - for (p2 = bucket[i][j].head; p2 < bucket[i][j].bp; *p1++ = *p2++); - bucket_info->bucket_info[i][nonempty_bucket].tail = p1 - 1; - nonempty_bucket++; - } - } - bucket_info->numbuckets = nonempty_bucket; - } -} - -/** update_contribution - * helper, calculates the partial linear feedback contributions and puts in MSB - */ -static inline void update_contribution(uint32_t *item, const uint32_t mask1, const uint32_t mask2) { - uint32_t p = *item >> 25; - - p = p << 1 | parity(*item & mask1); - p = p << 1 | parity(*item & mask2); - *item = p << 24 | (*item & 0xffffff); -} - -/** extend_table - * using a bit of the keystream extend the table of possible lfsr states - */ -static inline void extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in) { - in <<= 24; - for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1) - if (filter(*tbl) ^ filter(*tbl | 1)) { - *tbl |= filter(*tbl) ^ bit; - update_contribution(tbl, m1, m2); - *tbl ^= in; - } else if (filter(*tbl) == bit) { - *++*end = tbl[1]; - tbl[1] = tbl[0] | 1; - update_contribution(tbl, m1, m2); - *tbl++ ^= in; - update_contribution(tbl, m1, m2); - *tbl ^= in; - } else - *tbl-- = *(*end)--; -} -/** extend_table_simple - * using a bit of the keystream extend the table of possible lfsr states - */ -static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit) { - for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1) { - if (filter(*tbl) ^ filter(*tbl | 1)) { // replace - *tbl |= filter(*tbl) ^ bit; - } else if (filter(*tbl) == bit) { // insert - *++*end = *++tbl; - *tbl = tbl[-1] | 1; - } else { // drop - *tbl-- = *(*end)--; - } - } -} -/** recover - * recursively narrow down the search space, 4 bits of keystream at a time - */ -static struct Crypto1State * -recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks, - uint32_t *e_head, uint32_t *e_tail, uint32_t eks, int rem, - struct Crypto1State *sl, uint32_t in, bucket_array_t bucket) { - bucket_info_t bucket_info; - - if (rem == -1) { - for (uint32_t *e = e_head; e <= e_tail; ++e) { - *e = *e << 1 ^ parity(*e & LF_POLY_EVEN) ^ (!!(in & 4)); - for (uint32_t *o = o_head; o <= o_tail; ++o, ++sl) { - sl->even = *o; - sl->odd = *e ^ parity(*o & LF_POLY_ODD); - sl[1].odd = sl[1].even = 0; - } - } - return sl; - } - - for (uint32_t i = 0; i < 4 && rem--; i++) { - oks >>= 1; - eks >>= 1; - in >>= 2; - extend_table(o_head, &o_tail, oks & 1, LF_POLY_EVEN << 1 | 1, LF_POLY_ODD << 1, 0); - if (o_head > o_tail) - return sl; - - extend_table(e_head, &e_tail, eks & 1, LF_POLY_ODD, LF_POLY_EVEN << 1 | 1, in & 3); - if (e_head > e_tail) - return sl; - } - - bucket_sort_intersect(e_head, e_tail, o_head, o_tail, &bucket_info, bucket); - - for (int i = bucket_info.numbuckets - 1; i >= 0; i--) { - sl = recover(bucket_info.bucket_info[1][i].head, bucket_info.bucket_info[1][i].tail, oks, - bucket_info.bucket_info[0][i].head, bucket_info.bucket_info[0][i].tail, eks, - rem, sl, in, bucket); - } - - return sl; -} -/** lfsr_recovery - * recover the state of the lfsr given 32 bits of the keystream - * additionally you can use the in parameter to specify the value - * that was fed into the lfsr at the time the keystream was generated - */ -struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in) { - struct Crypto1State *statelist; - uint32_t *odd_head = 0, *odd_tail = 0, oks = 0; - uint32_t *even_head = 0, *even_tail = 0, eks = 0; - - // split the keystream into an odd and even part - for (int i = 31; i >= 0; i -= 2) - oks = oks << 1 | BEBIT(ks2, i); - for (int i = 30; i >= 0; i -= 2) - eks = eks << 1 | BEBIT(ks2, i); - - odd_head = odd_tail = malloc(sizeof(uint32_t) << 21); - even_head = even_tail = malloc(sizeof(uint32_t) << 21); - statelist = malloc(sizeof(struct Crypto1State) << 18); - if (!odd_tail-- || !even_tail-- || !statelist) { - free(statelist); - statelist = 0; - goto out; - } - - statelist->odd = statelist->even = 0; - - // allocate memory for out of place bucket_sort - bucket_array_t bucket; - - for (uint32_t i = 0; i < 2; i++) { - for (uint32_t j = 0; j <= 0xff; j++) { - bucket[i][j].head = malloc(sizeof(uint32_t) << 14); - if (!bucket[i][j].head) { - goto out; - } - } - } - - // initialize statelists: add all possible states which would result into the rightmost 2 bits of the keystream - for (int i = 1 << 20; i >= 0; --i) { - if (filter(i) == (oks & 1)) - *++odd_tail = i; - if (filter(i) == (eks & 1)) - *++even_tail = i; - } - - // extend the statelists. Look at the next 8 Bits of the keystream (4 Bit each odd and even): - for (uint8_t i = 0; i < 4; i++) { - extend_table_simple(odd_head, &odd_tail, (oks >>= 1) & 1); - extend_table_simple(even_head, &even_tail, (eks >>= 1) & 1); - } - - // the statelists now contain all states which could have generated the last 10 Bits of the keystream. - // 22 bits to go to recover 32 bits in total. From now on, we need to take the "in" - // parameter into account. - in = (in >> 16 & 0xff) | (in << 16) | (in & 0xff00); // Byte swapping - recover(odd_head, odd_tail, oks, even_head, even_tail, eks, 11, statelist, in << 1, bucket); - -out: - for (uint32_t i = 0; i < 2; i++) - for (uint32_t j = 0; j <= 0xff; j++) - free(bucket[i][j].head); - free(odd_head); - free(even_head); - return statelist; -} - -static const uint32_t S1[] = { 0x62141, 0x310A0, 0x18850, 0x0C428, 0x06214, - 0x0310A, 0x85E30, 0xC69AD, 0x634D6, 0xB5CDE, 0xDE8DA, 0x6F46D, 0xB3C83, - 0x59E41, 0xA8995, 0xD027F, 0x6813F, 0x3409F, 0x9E6FA - }; -static const uint32_t S2[] = { 0x3A557B00, 0x5D2ABD80, 0x2E955EC0, 0x174AAF60, - 0x0BA557B0, 0x05D2ABD8, 0x0449DE68, 0x048464B0, 0x42423258, 0x278192A8, - 0x156042D0, 0x0AB02168, 0x43F89B30, 0x61FC4D98, 0x765EAD48, 0x7D8FDD20, - 0x7EC7EE90, 0x7F63F748, 0x79117020 - }; -static const uint32_t T1[] = { - 0x4F37D, 0x279BE, 0x97A6A, 0x4BD35, 0x25E9A, 0x12F4D, 0x097A6, 0x80D66, - 0xC4006, 0x62003, 0xB56B4, 0x5AB5A, 0xA9318, 0xD0F39, 0x6879C, 0xB057B, - 0x582BD, 0x2C15E, 0x160AF, 0x8F6E2, 0xC3DC4, 0xE5857, 0x72C2B, 0x39615, - 0x98DBF, 0xC806A, 0xE0680, 0x70340, 0x381A0, 0x98665, 0x4C332, 0xA272C -}; -static const uint32_t T2[] = { 0x3C88B810, 0x5E445C08, 0x2982A580, 0x14C152C0, - 0x4A60A960, 0x253054B0, 0x52982A58, 0x2FEC9EA8, 0x1156C4D0, 0x08AB6268, - 0x42F53AB0, 0x217A9D58, 0x161DC528, 0x0DAE6910, 0x46D73488, 0x25CB11C0, - 0x52E588E0, 0x6972C470, 0x34B96238, 0x5CFC3A98, 0x28DE96C8, 0x12CFC0E0, - 0x4967E070, 0x64B3F038, 0x74F97398, 0x7CDC3248, 0x38CE92A0, 0x1C674950, - 0x0E33A4A8, 0x01B959D0, 0x40DCACE8, 0x26CEDDF0 - }; -static const uint32_t C1[] = { 0x846B5, 0x4235A, 0x211AD}; -static const uint32_t C2[] = { 0x1A822E0, 0x21A822E0, 0x21A822E0}; -/** Reverse 64 bits of keystream into possible cipher states - * Variation mentioned in the paper. Somewhat optimized version - */ -struct Crypto1State *lfsr_recovery64(uint32_t ks2, uint32_t ks3) { - struct Crypto1State *statelist, *sl; - uint8_t oks[32], eks[32], hi[32]; - uint32_t low = 0, win = 0; - uint32_t *tail, table[1 << 16]; - int i, j; - - sl = statelist = malloc(sizeof(struct Crypto1State) << 4); - if (!sl) - return 0; - sl->odd = sl->even = 0; - - for (i = 30; i >= 0; i -= 2) { - oks[i >> 1] = BEBIT(ks2, i); - oks[16 + (i >> 1)] = BEBIT(ks3, i); - } - for (i = 31; i >= 0; i -= 2) { - eks[i >> 1] = BEBIT(ks2, i); - eks[16 + (i >> 1)] = BEBIT(ks3, i); - } - - for (i = 0xfffff; i >= 0; --i) { - if (filter(i) != oks[0]) - continue; - - *(tail = table) = i; - for (j = 1; tail >= table && j < 29; ++j) - extend_table_simple(table, &tail, oks[j]); - - if (tail < table) - continue; - - for (j = 0; j < 19; ++j) - low = low << 1 | parity(i & S1[j]); - for (j = 0; j < 32; ++j) - hi[j] = parity(i & T1[j]); - - for (; tail >= table; --tail) { - for (j = 0; j < 3; ++j) { - *tail = *tail << 1; - *tail |= parity((i & C1[j]) ^ (*tail & C2[j])); - if (filter(*tail) != oks[29 + j]) - goto continue2; - } - - for (j = 0; j < 19; ++j) - win = win << 1 | parity(*tail & S2[j]); - - win ^= low; - for (j = 0; j < 32; ++j) { - win = win << 1 ^ hi[j] ^ parity(*tail & T2[j]); - if (filter(win) != eks[j]) - goto continue2; - } - - *tail = *tail << 1 | parity(LF_POLY_EVEN & *tail); - sl->odd = *tail ^ parity(LF_POLY_ODD & win); - sl->even = win; - ++sl; - sl->odd = sl->even = 0; -continue2: - ; - } - } - return statelist; -} - -/** lfsr_rollback_bit - * Rollback the shift register in order to get previous states - */ -uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb) { - int out; - uint8_t ret; - uint32_t t; - - s->odd &= 0xffffff; - t = s->odd, s->odd = s->even, s->even = t; - - out = s->even & 1; - out ^= LF_POLY_EVEN & (s->even >>= 1); - out ^= LF_POLY_ODD & s->odd; - out ^= !!in; - out ^= (ret = filter(s->odd)) & (!!fb); - - s->even |= parity(out) << 23; - return ret; -} -/** lfsr_rollback_byte - * Rollback the shift register in order to get previous states - */ -uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb) { - uint8_t ret = 0; - ret |= lfsr_rollback_bit(s, BIT(in, 7), fb) << 7; - ret |= lfsr_rollback_bit(s, BIT(in, 6), fb) << 6; - ret |= lfsr_rollback_bit(s, BIT(in, 5), fb) << 5; - ret |= lfsr_rollback_bit(s, BIT(in, 4), fb) << 4; - ret |= lfsr_rollback_bit(s, BIT(in, 3), fb) << 3; - ret |= lfsr_rollback_bit(s, BIT(in, 2), fb) << 2; - ret |= lfsr_rollback_bit(s, BIT(in, 1), fb) << 1; - ret |= lfsr_rollback_bit(s, BIT(in, 0), fb) << 0; - return ret; -} -/** lfsr_rollback_word - * Rollback the shift register in order to get previous states - */ -uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) { - - uint32_t ret = 0; - ret |= lfsr_rollback_bit(s, BEBIT(in, 31), fb) << (31 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 30), fb) << (30 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 29), fb) << (29 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 28), fb) << (28 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 27), fb) << (27 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 26), fb) << (26 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 25), fb) << (25 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 24), fb) << (24 ^ 24); - - ret |= lfsr_rollback_bit(s, BEBIT(in, 23), fb) << (23 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 22), fb) << (22 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 21), fb) << (21 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 20), fb) << (20 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 19), fb) << (19 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 18), fb) << (18 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 17), fb) << (17 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 16), fb) << (16 ^ 24); - - ret |= lfsr_rollback_bit(s, BEBIT(in, 15), fb) << (15 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 14), fb) << (14 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 13), fb) << (13 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 12), fb) << (12 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 11), fb) << (11 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 10), fb) << (10 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 9), fb) << (9 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 8), fb) << (8 ^ 24); - - ret |= lfsr_rollback_bit(s, BEBIT(in, 7), fb) << (7 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 6), fb) << (6 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 5), fb) << (5 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 4), fb) << (4 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 3), fb) << (3 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 2), fb) << (2 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 1), fb) << (1 ^ 24); - ret |= lfsr_rollback_bit(s, BEBIT(in, 0), fb) << (0 ^ 24); - return ret; -} - -/** nonce_distance - * x,y valid tag nonces, then prng_successor(x, nonce_distance(x, y)) = y - */ -static uint16_t *dist = 0; -int nonce_distance(uint32_t from, uint32_t to) { - if (!dist) { - dist = calloc(2 << 16, sizeof(uint8_t)); - if (!dist) - return -1; - uint16_t x = 1; - for (uint16_t i = 1; i; ++i) { - dist[(x & 0xff) << 8 | x >> 8] = i; - x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15; - } - } - return (65535 + dist[to >> 16] - dist[from >> 16]) % 65535; -} - - -static uint32_t fastfwd[2][8] = { - { 0, 0x4BC53, 0xECB1, 0x450E2, 0x25E29, 0x6E27A, 0x2B298, 0x60ECB}, - { 0, 0x1D962, 0x4BC53, 0x56531, 0xECB1, 0x135D3, 0x450E2, 0x58980} -}; - - -/** lfsr_prefix_ks - * - * Is an exported helper function from the common prefix attack - * Described in the "dark side" paper. It returns an -1 terminated array - * of possible partial(21 bit) secret state. - * The required keystream(ks) needs to contain the keystream that was used to - * encrypt the NACK which is observed when varying only the 3 last bits of Nr - * only correct iff [NR_3] ^ NR_3 does not depend on Nr_3 - */ -uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) { - uint32_t *candidates = calloc(4 << 10, sizeof(uint8_t)); - if (!candidates) return 0; - - uint32_t c, entry; - int size = 0, i, good; - - for (i = 0; i < 1 << 21; ++i) { - for (c = 0, good = 1; good && c < 8; ++c) { - entry = i ^ fastfwd[isodd][c]; - good &= (BIT(ks[c], isodd) == filter(entry >> 1)); - good &= (BIT(ks[c], isodd + 2) == filter(entry)); - } - if (good) - candidates[size++] = i; - } - - candidates[size] = -1; - - return candidates; -} - -/** check_pfx_parity - * helper function which eliminates possible secret states using parity bits - */ -static struct Crypto1State *check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8], uint32_t odd, uint32_t even, struct Crypto1State *sl) { - uint32_t good = 1; - - for (uint32_t c = 0; good && c < 8; ++c) { - sl->odd = odd ^ fastfwd[1][c]; - sl->even = even ^ fastfwd[0][c]; - - lfsr_rollback_bit(sl, 0, 0); - lfsr_rollback_bit(sl, 0, 0); - - uint32_t ks3 = lfsr_rollback_bit(sl, 0, 0); - uint32_t ks2 = lfsr_rollback_word(sl, 0, 0); - uint32_t ks1 = lfsr_rollback_word(sl, prefix | c << 5, 1); - - uint32_t nr = ks1 ^ (prefix | c << 5); - uint32_t rr = ks2 ^ rresp; - - good &= parity(nr & 0x000000ff) ^ parities[c][3] ^ BIT(ks2, 24); - good &= parity(rr & 0xff000000) ^ parities[c][4] ^ BIT(ks2, 16); - good &= parity(rr & 0x00ff0000) ^ parities[c][5] ^ BIT(ks2, 8); - good &= parity(rr & 0x0000ff00) ^ parities[c][6] ^ BIT(ks2, 0); - good &= parity(rr & 0x000000ff) ^ parities[c][7] ^ ks3; - } - - return sl + good; -} - -/** lfsr_common_prefix - * Implentation of the common prefix attack. - * Requires the 28 bit constant prefix used as reader nonce (pfx) - * The reader response used (rr) - * The keystream used to encrypt the observed NACK's (ks) - * The parity bits (par) - * It returns a zero terminated list of possible cipher states after the - * tag nonce was fed in - */ - -struct Crypto1State *lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]) { - struct Crypto1State *statelist, *s; - uint32_t *odd, *even, *o, *e, top; - - odd = lfsr_prefix_ks(ks, 1); - even = lfsr_prefix_ks(ks, 0); - - s = statelist = malloc((sizeof * statelist) << 24); // was << 20. Need more for no_par special attack. Enough??? - if (!s || !odd || !even) { - free(statelist); - statelist = 0; - goto out; - } - - for (o = odd; *o + 1; ++o) - for (e = even; *e + 1; ++e) - for (top = 0; top < 64; ++top) { - *o += 1 << 21; - *e += (!(top & 7) + 1) << 21; - s = check_pfx_parity(pfx, rr, par, *o, *e, s); - } - - s->odd = s->even = 0; -out: - free(odd); - free(even); - return statelist; -} diff --git a/tools/nonce2key/crapto1.h b/tools/nonce2key/crapto1.h deleted file mode 100644 index e1f9c7570..000000000 --- a/tools/nonce2key/crapto1.h +++ /dev/null @@ -1,87 +0,0 @@ -/* crapto1.h - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - MA 02110-1301, US$ - - Copyright (C) 2008-2014 bla -*/ -#ifndef CRAPTO1_H__ -#define CRAPTO1_H__ -#include - -struct Crypto1State {uint32_t odd, even;}; -struct Crypto1State *crypto1_create(uint64_t); -void crypto1_destroy(struct Crypto1State *); -void crypto1_get_lfsr(struct Crypto1State *, uint64_t *); -uint8_t crypto1_bit(struct Crypto1State *, uint8_t, int); -uint8_t crypto1_byte(struct Crypto1State *, uint8_t, int); -uint32_t crypto1_word(struct Crypto1State *, uint32_t, int); -uint32_t prng_successor(uint32_t x, uint32_t n); - -struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in); -struct Crypto1State *lfsr_recovery64(uint32_t ks2, uint32_t ks3); -uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd); -struct Crypto1State *lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]); - -uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb); -uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb); -uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb); -int nonce_distance(uint32_t from, uint32_t to); -#define SWAPENDIAN(x)\ - (x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16) - -#define FOREACH_VALID_NONCE(N, FILTER, FSIZE)\ - uint32_t __n = 0,__M = 0, N = 0;\ - int __i;\ - for(; __n < 1 << 16; N = prng_successor(__M = ++__n, 16))\ - for(__i = FSIZE - 1; __i >= 0; __i--)\ - if(BIT(FILTER, __i) ^ parity(__M & 0xFF01))\ - break;\ - else if(__i)\ - __M = prng_successor(__M, (__i == 7) ? 48 : 8);\ - else - -#define LF_POLY_ODD (0x29CE5C) -#define LF_POLY_EVEN (0x870804) -#define BIT(x, n) ((x) >> (n) & 1) -#define BEBIT(x, n) BIT(x, (n) ^ 24) -static inline int parity(uint32_t x) { -#if !defined __i386__ || !defined __GNUC__ - x ^= x >> 16; - x ^= x >> 8; - x ^= x >> 4; - return BIT(0x6996, x & 0xf); -#else - __asm__("movl %1, %%eax\n" - "mov %%ax, %%cx\n" - "shrl $0x10, %%eax\n" - "xor %%ax, %%cx\n" - "xor %%ch, %%cl\n" - "setpo %%al\n" - "movzx %%al, %0\n": "=r"(x) : "r"(x): "eax", "ecx"); - return x; -#endif -} -static inline int filter(uint32_t const x) { - uint32_t f; - - f = 0xf22c0 >> (x & 0xf) & 16; - f |= 0x6c9c0 >> (x >> 4 & 0xf) & 8; - f |= 0x3c8b0 >> (x >> 8 & 0xf) & 4; - f |= 0x1e458 >> (x >> 12 & 0xf) & 2; - f |= 0x0d938 >> (x >> 16 & 0xf) & 1; - return BIT(0xEC57E80A, f); -} -#endif diff --git a/tools/nonce2key/crypto1.c b/tools/nonce2key/crypto1.c deleted file mode 100644 index f6f4642e2..000000000 --- a/tools/nonce2key/crypto1.c +++ /dev/null @@ -1,125 +0,0 @@ -/* crypto1.c - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - MA 02110-1301, US - - Copyright (C) 2008-2008 bla -*/ -#include "crapto1.h" -#include - -struct Crypto1State *crypto1_create(uint64_t key) { - struct Crypto1State *s = malloc(sizeof(*s)); - if (!s) return NULL; - - s->odd = s->even = 0; - - int i; - //for(i = 47;s && i > 0; i -= 2) { - for (i = 47; i > 0; i -= 2) { - s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7); - s->even = s->even << 1 | BIT(key, i ^ 7); - } - return s; -} -void crypto1_destroy(struct Crypto1State *state) { - free(state); -} -void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) { - int i; - for (*lfsr = 0, i = 23; i >= 0; --i) { - *lfsr = *lfsr << 1 | BIT(state->odd, i ^ 3); - *lfsr = *lfsr << 1 | BIT(state->even, i ^ 3); - } -} -uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted) { - uint32_t feedin; - uint32_t tmp; - uint8_t ret = filter(s->odd); - - feedin = ret & (!!is_encrypted); - feedin ^= !!in; - feedin ^= LF_POLY_ODD & s->odd; - feedin ^= LF_POLY_EVEN & s->even; - s->even = s->even << 1 | parity(feedin); - - tmp = s->odd; - s->odd = s->even; - s->even = tmp; - - return ret; -} -uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted) { - uint8_t ret = 0; - ret |= crypto1_bit(s, BIT(in, 0), is_encrypted) << 0; - ret |= crypto1_bit(s, BIT(in, 1), is_encrypted) << 1; - ret |= crypto1_bit(s, BIT(in, 2), is_encrypted) << 2; - ret |= crypto1_bit(s, BIT(in, 3), is_encrypted) << 3; - ret |= crypto1_bit(s, BIT(in, 4), is_encrypted) << 4; - ret |= crypto1_bit(s, BIT(in, 5), is_encrypted) << 5; - ret |= crypto1_bit(s, BIT(in, 6), is_encrypted) << 6; - ret |= crypto1_bit(s, BIT(in, 7), is_encrypted) << 7; - return ret; -} -uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted) { - uint32_t ret = 0; - ret |= crypto1_bit(s, BEBIT(in, 0), is_encrypted) << (0 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 1), is_encrypted) << (1 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 2), is_encrypted) << (2 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 3), is_encrypted) << (3 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 4), is_encrypted) << (4 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 5), is_encrypted) << (5 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 6), is_encrypted) << (6 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 7), is_encrypted) << (7 ^ 24); - - ret |= crypto1_bit(s, BEBIT(in, 8), is_encrypted) << (8 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 9), is_encrypted) << (9 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 10), is_encrypted) << (10 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 11), is_encrypted) << (11 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 12), is_encrypted) << (12 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 13), is_encrypted) << (13 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 14), is_encrypted) << (14 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 15), is_encrypted) << (15 ^ 24); - - ret |= crypto1_bit(s, BEBIT(in, 16), is_encrypted) << (16 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 17), is_encrypted) << (17 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 18), is_encrypted) << (18 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 19), is_encrypted) << (19 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 20), is_encrypted) << (20 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 21), is_encrypted) << (21 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 22), is_encrypted) << (22 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 23), is_encrypted) << (23 ^ 24); - - ret |= crypto1_bit(s, BEBIT(in, 24), is_encrypted) << (24 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 25), is_encrypted) << (25 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 26), is_encrypted) << (26 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 27), is_encrypted) << (27 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 28), is_encrypted) << (28 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 29), is_encrypted) << (29 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 30), is_encrypted) << (30 ^ 24); - ret |= crypto1_bit(s, BEBIT(in, 31), is_encrypted) << (31 ^ 24); - return ret; -} - -/* prng_successor - * helper used to obscure the keystream during authentication - */ -uint32_t prng_successor(uint32_t x, uint32_t n) { - SWAPENDIAN(x); - while (n--) - x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31; - - return SWAPENDIAN(x); -} diff --git a/tools/nonce2key/nonce2key.c b/tools/nonce2key/nonce2key.c index f4cb10e62..d7ccec0bb 100644 --- a/tools/nonce2key/nonce2key.c +++ b/tools/nonce2key/nonce2key.c @@ -1,4 +1,4 @@ -#include "crapto1.h" +#include "crapto1/crapto1.h" #define __STDC_FORMAT_MACROS #include #include @@ -48,7 +48,7 @@ int main(const int argc, const char *argv[]) { } printf("+----+--------+---+-----+---------------+\n"); - state = lfsr_common_prefix(nr, rr, ks3x, par); + state = lfsr_common_prefix(nr, rr, ks3x, par, false); lfsr_rollback_word(state, uid ^ nt, 0); crypto1_get_lfsr(state, &key_recovered); printf("\nkey recovered: %012" PRIx64 "\n\n", key_recovered); From 6ebae499aad9c751835241633cb77d020789d926 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 16 Aug 2019 22:50:03 +0200 Subject: [PATCH 041/347] rework fpga_compress & isolate zlib: use Makefile.host --- client/Makefile | 30 +++++++----- common/zlib/Makefile | 10 ++++ tools/fpga_compress/Makefile | 89 ++++++---------------------------- tools/fpga_compress/obj/.dummy | 0 4 files changed, 42 insertions(+), 87 deletions(-) create mode 100644 common/zlib/Makefile delete mode 100644 tools/fpga_compress/obj/.dummy diff --git a/client/Makefile b/client/Makefile index bf047ff7d..73a1d1250 100644 --- a/client/Makefile +++ b/client/Makefile @@ -28,7 +28,7 @@ FALSE = false platform = $(shell uname) -VPATH = ../common ../common/zlib uart +VPATH = ../common uart OBJDIR = obj LDLIBS ?= -L/usr/local/lib @@ -49,8 +49,10 @@ MBEDTLSLIBPATH = ../common/mbedtls MBEDTLSLIB = $(MBEDTLSLIBPATH)/libmbedtls.a CBORLIBPATH = ./tinycbor CBORLIB = $(CBORLIBPATH)/tinycbor.a +ZLIBPATH = ../common/zlib +ZLIB = $(ZLIBPATH)/libz.a REVENGFLAGS = -DPRESETS -LIBS = -I../common/zlib -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) +LIBS = -I$(ZLIBPATH) -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) CFLAGS ?= -Wall -Werror -g -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: @@ -251,9 +253,6 @@ ifeq ($(MULTIARCHSRCS), ) CMDSRCS += hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c endif -ZLIBSRCS = deflate.c adler32.c trees.c zutil.c inflate.c inffast.c inftrees.c -ZLIBFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED -#-DDEBUG -Dverbose=1 REVENGSRCS = reveng/preset.c \ reveng/reveng.c \ @@ -267,7 +266,6 @@ QTGUISRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp guidummy.cpp COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o) CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o) OBJCOBJS = $(OBJCSRCS:%.m=$(OBJDIR)/%.o) -ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o) REVENGOBJS = $(REVENGSRCS:%.c=$(OBJDIR)/%.o) MULTIARCHOBJS = $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_NOSIMD.o) \ $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_MMX.o) \ @@ -293,18 +291,18 @@ ifeq "$(SUPPORTS_AVX512)" "True" endif BINS = proxmark3 flasher -CLEAN = $(BINS) $(DEPENDENCY_FILES) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(ZLIBOBJS) $(REVENGOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua reveng/bmptst +CLEAN = $(BINS) $(DEPENDENCY_FILES) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(REVENGOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua reveng/bmptst # need to assign dependancies to build these first... -all: lua_build jansson_build mbedtls_build cbor_build $(BINS) +all: zlib_build lua_build jansson_build mbedtls_build cbor_build $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) -proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(QTLDLIBS) -proxmark3: reveng/bmptst $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) $(REVENGOBJS) lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua +proxmark3: LDLIBS+=$(ZLIB) $(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(QTLDLIBS) +proxmark3: reveng/bmptst $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(REVENGOBJS) lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua $(info [=] LD $@) - $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) $(REVENGOBJS) $(LDLIBS) -o $@ + $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(REVENGOBJS) $(LDLIBS) -o $@ flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS) $(OBJCOBJS) $(info [=] LD $@) @@ -330,6 +328,7 @@ lualibs/mf_default_keys.lua : default_keys.dic clean: $(Q)$(RM) $(CLEAN) + $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) clean @@ -339,6 +338,10 @@ tarbin: $(BINS) $(info [=] TAR ../proxmark3-$(platform)-bin.tar) $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%) +zlib_build: + $(info [*] MAKE zlib) + $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) all + lua_build: $(info [*] MAKE liblua for $(LUAPLATFORM)) $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) $(LUAPLATFORM) @@ -395,10 +398,11 @@ $(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%_AVX512.d $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d + %.o: %.c $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d $(info [-] CC $<) - $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) $(ZLIBFLAGS) -c -o $@ $< + $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $< $(Q)$(POSTCOMPILE) %.o: %.cpp @@ -413,7 +417,7 @@ $(OBJDIR)/%.o : %.m $(OBJDIR)/%.d $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $< $(Q)$(POSTCOMPILE) -DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(ZLIBSRCS) $(REVENGSRCS)) \ +DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(REVENGSRCS)) \ $(patsubst %.o, %.d, $(MULTIARCHOBJS)) \ $(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \ $(patsubst %.m, $(OBJDIR)/%.d, $(OBJCSRCS)) \ diff --git a/common/zlib/Makefile b/common/zlib/Makefile new file mode 100644 index 000000000..b62071d5d --- /dev/null +++ b/common/zlib/Makefile @@ -0,0 +1,10 @@ +MYSRCPATHS = ../../common/zlib +MYSRCS = deflate.c adler32.c trees.c zutil.c inflate.c inffast.c inftrees.c +MYINCLUDES = -I../../common/zlib +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = -DZ_SOLO -DNO_GZIP -DZLIB_PM3_TUNED +#-DDEBUG -Dverbose=1 + +LIB_A = libz.a + +include ../../Makefile.host diff --git a/tools/fpga_compress/Makefile b/tools/fpga_compress/Makefile index 8798ace1e..86c995924 100644 --- a/tools/fpga_compress/Makefile +++ b/tools/fpga_compress/Makefile @@ -1,80 +1,21 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 +MYSRCPATHS = +MYINCLUDES = -I../../common_fpga +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = +MYSRCS = +MYLIBS = -CC = gcc -CXX = g++ -LD = g++ -RM = rm -f -MV = mv -CP = cp -a - -platform = $(shell uname) - -VPATH = ../../common/zlib -OBJDIR = obj - -# RPi Zero gcc requires -latomic -# but MacOSX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -# doesn't recognize option --as-needed -ifneq ($(platform),Darwin) - LDLIBS += -Wl,--as-needed -latomic -Wl,--no-as-needed -endif - -LIBS = -I../../common/zlib -INCLUDES_CLIENT = -I../../common_fpga $(LIBS) - -CFLAGS += -std=c99 -D_ISOC99_SOURCE -DPRESETS $(INCLUDES_CLIENT) -Wall -Werror -g -O3 - -# Flags to generate temporary dependency files -DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td -# make temporary to final dependency files after successful compilation -POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d - -ZLIBSRCS = deflate.c adler32.c trees.c zutil.c inflate.c inffast.c inftrees.c -ZLIBFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED -#-DDEBUG -Dverbose=1 - -ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o) +ZLIBPATH = ../../common/zlib +MYINCLUDES += -I$(ZLIBPATH) +MYLIBS += $(OBJDIR)/libz.a BINS = fpga_compress -CLEAN = $(BINS) $(DEPENDENCY_FILES) $(ZLIBOBJS) $(OBJDIR)/*.o -# OSX Brew is expecting fpga_compress in client folder, some workaround for now: -ifeq ($(platform),Darwin) -CLEAN += $(foreach bin,$(BINS),../../client/$(bin)) -endif -# need to assign dependancies to build these first... -all: $(BINS) +ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) -all-static: LDLIBS:=-static $(LDLIBS) -all-static: $(BINS) - -fpga_compress: $(OBJDIR)/fpga_compress.o $(ZLIBOBJS) - $(info [=] LD $@) - $(Q)$(LD) $(LDFLAGS) $(ZLIBFLAGS) $^ $(LDLIBS) -o $@ -# OSX Brew is expecting fpga_compress in client folder, some workaround for now: -ifeq ($(platform),Darwin) - $(Q)$(CP) $@ ../../client/ -endif - -clean: - $(Q)$(RM) $(CLEAN) - -.PHONY: all clean - -%.o: %.c -$(OBJDIR)/%.o : %.c $(OBJDIR)/%.d - $(info [-] CC $<) - $(Q)$(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $< - $(Q)$(POSTCOMPILE) - -DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(ZLIBSRCS)) $(OBJDIR)/fpga_compress.d - -$(DEPENDENCY_FILES): ; -.PRECIOUS: $(DEPENDENCY_FILES) - --include $(DEPENDENCY_FILES) +include ../../Makefile.host +fpga_compress: $(OBJDIR)/fpga_compress.o $(MYOBJS) +$(OBJDIR)/libz.a: + $(info [*] MAKE zlib) + $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) OBJDIR=$(ROOT_DIR)$(OBJDIR) BINDIR=$(ROOT_DIR)$(OBJDIR) all diff --git a/tools/fpga_compress/obj/.dummy b/tools/fpga_compress/obj/.dummy deleted file mode 100644 index e69de29bb..000000000 From 8ebad97c3d36659b24ad43f2d35a02fd88f93e74 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 16 Aug 2019 22:32:34 +0200 Subject: [PATCH 042/347] rework mbedtls Makefile, use Makefile.host --- common/mbedtls/Makefile | 65 +++++------------------------------------ 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/common/mbedtls/Makefile b/common/mbedtls/Makefile index a16b2cfd9..52663d67e 100644 --- a/common/mbedtls/Makefile +++ b/common/mbedtls/Makefile @@ -1,11 +1,8 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 - -LIB_A = libmbedtls.a -mbedtls_SOURCES = \ +MYSRCPATHS = +MYINCLUDES = -I. -I.. +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = +MYSRCS = \ aes.c \ asn1parse.c \ asn1write.c \ @@ -49,55 +46,7 @@ mbedtls_SOURCES = \ x509.c \ x509_crl.c \ x509_crt.c -mbedtls_LDFLAGS = \ - -no-undefined \ - -export-symbols-regex '^mbedtls_' \ - -version-info 15:0:11 +LIB_A = libmbedtls.a -CFILES = $(filter %.c, $(mbedtls_SOURCES)) -CMDOBJS = $(CFILES:%.c=%.o) -CLEAN = $(CMDOBJS) - -platform = $(shell uname) - -CC= gcc -CFLAGS= -O2 -Wall -Wno-unused-variable -Wno-unused-function -LDFLAGS= $(SYSLDFLAGS) $(mbedtls_LDFLAGS) -LIBS= $(SYSLIBS) $(MYLIBS) -DEFAULT_INCLUDES = -I. -I.. -DEFS = -DHAVE_STDINT_H - -ifeq ($(platform),Darwin) -AR= /usr/bin/ar rcs -RANLIB= /usr/bin/ranlib -else -AR= ar rcs -RANLIB= ranlib -endif -RM= rm -f -TST= echo - -SYSLDFLAGS= -SYSLIBS= - -MYLIBS= -MYOBJS= - -$(LIB_A): $(CMDOBJS) - $(info [=] AR $@) - $(Q)$(AR) $(LIB_A) $(CMDOBJS) - $(Q)$(RANLIB) $(LIB_A) - -all: $(LIB_A) - -clean: - $(Q)$(RM) $(CLEAN) - $(Q)$(RM) $(LIB_A) - -%.o: %.c - $(info [-] CC $<) - $(Q)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(CFLAGS) -c -o $@ $< $(LIBS) - -.PHONY: all clean - +include ../../Makefile.host From 0115efe190931d1456d33d1fb6c2373d4d8e523f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 16 Aug 2019 21:33:01 +0200 Subject: [PATCH 043/347] isolate reveng, use Makefile.host --- client/Makefile | 42 +++++++++++++++++------------------------- client/reveng/Makefile | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 client/reveng/Makefile diff --git a/client/Makefile b/client/Makefile index 73a1d1250..a4384e3e9 100644 --- a/client/Makefile +++ b/client/Makefile @@ -51,12 +51,13 @@ CBORLIBPATH = ./tinycbor CBORLIB = $(CBORLIBPATH)/tinycbor.a ZLIBPATH = ../common/zlib ZLIB = $(ZLIBPATH)/libz.a -REVENGFLAGS = -DPRESETS -LIBS = -I$(ZLIBPATH) -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) +REVENGPATH = ./reveng +REVENGLIB = $(REVENGPATH)/libreveng.a +LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) CFLAGS ?= -Wall -Werror -g -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: -PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(REVENGFLAGS) $(INCLUDES_CLIENT) +PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT) ifneq (,$(findstring MINGW,$(platform))) PM3CFLAGS += -mno-ms-bitfields endif @@ -253,20 +254,11 @@ ifeq ($(MULTIARCHSRCS), ) CMDSRCS += hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c endif - -REVENGSRCS = reveng/preset.c \ - reveng/reveng.c \ - reveng/cli.c \ - reveng/bmpbit.c \ - reveng/model.c \ - reveng/poly.c - QTGUISRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp guidummy.cpp COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o) CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o) OBJCOBJS = $(OBJCSRCS:%.m=$(OBJDIR)/%.o) -REVENGOBJS = $(REVENGSRCS:%.c=$(OBJDIR)/%.o) MULTIARCHOBJS = $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_NOSIMD.o) \ $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_MMX.o) \ $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_SSE2.o) \ @@ -291,18 +283,18 @@ ifeq "$(SUPPORTS_AVX512)" "True" endif BINS = proxmark3 flasher -CLEAN = $(BINS) $(DEPENDENCY_FILES) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(REVENGOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua reveng/bmptst +CLEAN = $(BINS) $(DEPENDENCY_FILES) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua # need to assign dependancies to build these first... -all: zlib_build lua_build jansson_build mbedtls_build cbor_build $(BINS) +all: lua_build jansson_build mbedtls_build cbor_build zlib_build reveng_build $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) -proxmark3: LDLIBS+=$(ZLIB) $(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(QTLDLIBS) -proxmark3: reveng/bmptst $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(REVENGOBJS) lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua +proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(QTLDLIBS) +proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua $(info [=] LD $@) - $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(REVENGOBJS) $(LDLIBS) -o $@ + $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LDLIBS) -o $@ flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS) $(OBJCOBJS) $(info [=] LD $@) @@ -328,20 +320,17 @@ lualibs/mf_default_keys.lua : default_keys.dic clean: $(Q)$(RM) $(CLEAN) - $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) clean + $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) clean + $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean tarbin: $(BINS) $(info [=] TAR ../proxmark3-$(platform)-bin.tar) $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%) -zlib_build: - $(info [*] MAKE zlib) - $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) all - lua_build: $(info [*] MAKE liblua for $(LUAPLATFORM)) $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) $(LUAPLATFORM) @@ -358,10 +347,13 @@ cbor_build: $(info [*] MAKE tinycbor) $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) all +zlib_build: + $(info [*] MAKE zlib) + $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) all -reveng/bmptst: reveng/bmpbit.c reveng/config.h reveng/reveng.h - $(CC) $(CFLAGS) $(REVENGFLAGS) -DBMPTST -o $@ $< - ( ./$@ && $(TOUCH) $@ ) || ( $(RM) $@ && $(FALSE) ) +reveng_build: + $(info [*] MAKE reveng) + $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) all .PHONY: all clean diff --git a/client/reveng/Makefile b/client/reveng/Makefile new file mode 100644 index 000000000..52fd1bcec --- /dev/null +++ b/client/reveng/Makefile @@ -0,0 +1,36 @@ +# reveng will compile without macros, but these may be useful: +# Add -DBMPMACRO to use bitmap size constant macros (edit config.h) +# Add -DNOFORCE to disable the -F switch +# Add -DPRESETS to compile with preset models (edit config.h) + +MYSRCPATHS = +MYINCLUDES = -I. -I.. +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = -DPRESETS +MYSRCS = \ + bmpbit.c \ + cli.c \ + getopt.c \ + model.c \ + poly.c \ + preset.c \ + reveng.c + +LIB_A = libreveng.a + +TOUCH = touch +FALSE = false + +include ../../Makefile.host + +CLEAN += bmptst + +$(BINDIR)/$(LIB_A): $(BINDIR)/bmptst + +$(BINDIR)/bmptst: bmpbit.c config.h reveng.h + $(info [-] CC $<) + $(Q)$(CC) $(CFLAGS) -DBMPTST -o $@ $< + $(info [=] TEST $@) + $(Q)( ./$@ && $(TOUCH) $@ ) || ( $(RM) $@ && $(FALSE) ) + +.PHONY: all clean From 0449527e2aae99d483405fc18de346fb7613ff9c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 18 Aug 2019 00:09:42 +0200 Subject: [PATCH 044/347] adapt client/Makefile to new mbedtls & zlib way of working, remove unneeded dirs --- client/Makefile | 51 +++++++++++++++++++++++------------- client/obj/.dummy | 0 client/obj/amiitool/.dummy | 0 client/obj/cliparser/.dummy | 0 client/obj/crapto1/.dummy | 0 client/obj/crypto/.dummy | 0 client/obj/emv/.dummy | 0 client/obj/emv/test/.dummy | 0 client/obj/fido/.dummy | 0 client/obj/hardnested/.dummy | 0 client/obj/jansson/.dummy | 0 client/obj/loclass/.dummy | 0 client/obj/mifare/.dummy | 0 client/obj/nonce2key/.dummy | 0 client/obj/reveng/.gitignore | 35 ------------------------- client/platforms/.gitignore | 35 ------------------------- 16 files changed, 33 insertions(+), 88 deletions(-) delete mode 100644 client/obj/.dummy delete mode 100644 client/obj/amiitool/.dummy delete mode 100644 client/obj/cliparser/.dummy delete mode 100644 client/obj/crapto1/.dummy delete mode 100644 client/obj/crypto/.dummy delete mode 100644 client/obj/emv/.dummy delete mode 100644 client/obj/emv/test/.dummy delete mode 100644 client/obj/fido/.dummy delete mode 100644 client/obj/hardnested/.dummy delete mode 100644 client/obj/jansson/.dummy delete mode 100644 client/obj/loclass/.dummy delete mode 100644 client/obj/mifare/.dummy delete mode 100644 client/obj/nonce2key/.dummy delete mode 100644 client/obj/reveng/.gitignore delete mode 100644 client/platforms/.gitignore diff --git a/client/Makefile b/client/Makefile index a4384e3e9..a556a7451 100644 --- a/client/Makefile +++ b/client/Makefile @@ -22,11 +22,14 @@ TAR = tar TARFLAGS ?= -v --ignore-failed-read -r TARFLAGS += -C .. -f RM = rm -f +RMDIR= rm -rf +MKDIR = mkdir -p MV = mv TOUCH = touch FALSE = false platform = $(shell uname) +ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) VPATH = ../common uart OBJDIR = obj @@ -41,18 +44,22 @@ ifneq ($(platform),Darwin) LDLIBS += -Wl,--as-needed -latomic -Wl,--no-as-needed endif +# local libraries LUALIBPATH = ./liblua LUALIB = $(LUALIBPATH)/liblua.a JANSSONLIBPATH = ./jansson JANSSONLIB = $(JANSSONLIBPATH)/libjansson.a -MBEDTLSLIBPATH = ../common/mbedtls -MBEDTLSLIB = $(MBEDTLSLIBPATH)/libmbedtls.a CBORLIBPATH = ./tinycbor CBORLIB = $(CBORLIBPATH)/tinycbor.a -ZLIBPATH = ../common/zlib -ZLIB = $(ZLIBPATH)/libz.a REVENGPATH = ./reveng REVENGLIB = $(REVENGPATH)/libreveng.a + +# common libraries +MBEDTLSLIBPATH = ../common/mbedtls +MBEDTLSLIB = $(OBJDIR)/libmbedtls.a +ZLIBPATH = ../common/zlib +ZLIB = $(OBJDIR)/libz.a + LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) CFLAGS ?= -Wall -Werror -g -O3 @@ -283,10 +290,10 @@ ifeq "$(SUPPORTS_AVX512)" "True" endif BINS = proxmark3 flasher -CLEAN = $(BINS) $(DEPENDENCY_FILES) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua +CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua # need to assign dependancies to build these first... -all: lua_build jansson_build mbedtls_build cbor_build zlib_build reveng_build $(BINS) +all: lua_build jansson_build cbor_build reveng_build mbedtls_build zlib_build $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) @@ -320,17 +327,17 @@ lualibs/mf_default_keys.lua : default_keys.dic clean: $(Q)$(RM) $(CLEAN) + $(Q)$(RMDIR) $(OBJDIR) $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) clean - $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) clean - $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean tarbin: $(BINS) $(info [=] TAR ../proxmark3-$(platform)-bin.tar) $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%) +# local libraries: lua_build: $(info [*] MAKE liblua for $(LUAPLATFORM)) $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) $(LUAPLATFORM) @@ -339,22 +346,23 @@ jansson_build: $(info [*] MAKE jansson) $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) all -mbedtls_build: - $(info [*] MAKE mbedtls) - $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) all - cbor_build: $(info [*] MAKE tinycbor) $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) all -zlib_build: - $(info [*] MAKE zlib) - $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) all - reveng_build: $(info [*] MAKE reveng) $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) all +# common libraries: +mbedtls_build: + $(info [*] MAKE mbedtls) + $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) OBJDIR=$(ROOT_DIR)$(OBJDIR) BINDIR=$(ROOT_DIR)$(OBJDIR) all + +zlib_build: + $(info [*] MAKE zlib) + $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) OBJDIR=$(ROOT_DIR)$(OBJDIR) BINDIR=$(ROOT_DIR)$(OBJDIR) all + .PHONY: all clean # easy printing of MAKE VARIABLES @@ -362,50 +370,58 @@ print-%: ; @echo $* = $($*) $(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%_NOSIMD.d $(info [-] CC(NOSIMD) $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_NOSIMD.Td) $(PM3CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_NOSIMD.Td $(OBJDIR)/$*_NOSIMD.d $(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%_MMX.d $(info [-] CC(MMX) $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_MMX.Td) $(PM3CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_MMX.Td $(OBJDIR)/$*_MMX.d $(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%_SSE2.d $(info [-] CC(SSE2) $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_SSE2.Td) $(PM3CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_SSE2.Td $(OBJDIR)/$*_SSE2.d $(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%_AVX.d $(info [-] CC(AVX) $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_AVX.Td $(OBJDIR)/$*_AVX.d $(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%_AVX2.d $(info [-] CC(AVX2) $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX2.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_AVX2.Td $(OBJDIR)/$*_AVX2.d $(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%_AVX512.d $(info [-] CC(AVX512) $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< $(Q)$(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d - %.o: %.c $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d $(info [-] CC $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $< $(Q)$(POSTCOMPILE) %.o: %.cpp $(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.d $(info [-] CXX $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CXX) $(DEPFLAGS) $(PM3CXXFLAGS) $(QTINCLUDES) -c -o $@ $< $(Q)$(POSTCOMPILE) %.o: %.m $(OBJDIR)/%.o : %.m $(OBJDIR)/%.d $(info [-] CC $<) + $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $< $(Q)$(POSTCOMPILE) @@ -419,4 +435,3 @@ $(DEPENDENCY_FILES): ; .PRECIOUS: $(DEPENDENCY_FILES) -include $(DEPENDENCY_FILES) - diff --git a/client/obj/.dummy b/client/obj/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/amiitool/.dummy b/client/obj/amiitool/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/cliparser/.dummy b/client/obj/cliparser/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/crapto1/.dummy b/client/obj/crapto1/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/crypto/.dummy b/client/obj/crypto/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/emv/.dummy b/client/obj/emv/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/emv/test/.dummy b/client/obj/emv/test/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/fido/.dummy b/client/obj/fido/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/hardnested/.dummy b/client/obj/hardnested/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/jansson/.dummy b/client/obj/jansson/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/loclass/.dummy b/client/obj/loclass/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/mifare/.dummy b/client/obj/mifare/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/nonce2key/.dummy b/client/obj/nonce2key/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/obj/reveng/.gitignore b/client/obj/reveng/.gitignore deleted file mode 100644 index 07669e14a..000000000 --- a/client/obj/reveng/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ -# .gitignore -# don't push these files to the repository - -*.log -*.eml -*.o -*.a -*.d -*.elf -*.s19 -*.map -*.bin -*.dll -*.moc.cpp -*.exe -proxmark -proxmark3 -flasher -version.c -lua -luac - -fpga/* -!fpga/tests -!fpga/fpga_lf.bit -!fpga/fpga_hf.bit -!fpga/*.v -!fpga/Makefile -!fpga/fpga.ucf -!fpga/xst_lf.scr -!fpga/xst_hf.scr -!fpga/go.bat -!fpga/sim.tcl - - diff --git a/client/platforms/.gitignore b/client/platforms/.gitignore deleted file mode 100644 index 07669e14a..000000000 --- a/client/platforms/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ -# .gitignore -# don't push these files to the repository - -*.log -*.eml -*.o -*.a -*.d -*.elf -*.s19 -*.map -*.bin -*.dll -*.moc.cpp -*.exe -proxmark -proxmark3 -flasher -version.c -lua -luac - -fpga/* -!fpga/tests -!fpga/fpga_lf.bit -!fpga/fpga_hf.bit -!fpga/*.v -!fpga/Makefile -!fpga/fpga.ucf -!fpga/xst_lf.scr -!fpga/xst_hf.scr -!fpga/go.bat -!fpga/sim.tcl - - From 589f1e9d3e18c9c56558c92f3120b5a994057ff7 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 18 Aug 2019 00:10:04 +0200 Subject: [PATCH 045/347] client/Makefile: add missing deps --- client/Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/Makefile b/client/Makefile index a556a7451..9f8dacb3d 100644 --- a/client/Makefile +++ b/client/Makefile @@ -293,13 +293,13 @@ BINS = proxmark3 flasher CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua # need to assign dependancies to build these first... -all: lua_build jansson_build cbor_build reveng_build mbedtls_build zlib_build $(BINS) +all: $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(QTLDLIBS) -proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua +proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua $(info [=] LD $@) $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LDLIBS) -o $@ @@ -338,28 +338,28 @@ tarbin: $(BINS) $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%) # local libraries: -lua_build: +$(LUALIB): $(info [*] MAKE liblua for $(LUAPLATFORM)) $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) $(LUAPLATFORM) -jansson_build: +$(JANSSONLIB): $(info [*] MAKE jansson) $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) all -cbor_build: +$(CBORLIB): $(info [*] MAKE tinycbor) $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) all -reveng_build: +$(REVENGLIB): $(info [*] MAKE reveng) $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) all # common libraries: -mbedtls_build: +$(MBEDTLSLIB): $(info [*] MAKE mbedtls) $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) OBJDIR=$(ROOT_DIR)$(OBJDIR) BINDIR=$(ROOT_DIR)$(OBJDIR) all -zlib_build: +$(ZLIB): $(info [*] MAKE zlib) $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) OBJDIR=$(ROOT_DIR)$(OBJDIR) BINDIR=$(ROOT_DIR)$(OBJDIR) all From d773f4ba2e529b743d0d4e3010a27039614bc3d6 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 20 Aug 2019 00:25:18 +0300 Subject: [PATCH 046/347] add matrix build with BTADDON --- .travis.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 17b15fa55..7ccdce078 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,9 +15,18 @@ matrix: include: - os: osx osx_image: xcode11 + env: MAKE_PARAMS='PLATFORM_EXTRAS=' + - os: osx + osx_image: xcode11 + env: MAKE_PARAMS='PLATFORM_EXTRAS=BTADDON' - os: linux dist: xenial sudo: required + env: MAKE_PARAMS='PLATFORM_EXTRAS=' + - os: linux + dist: xenial + sudo: required + env: MAKE_PARAMS='PLATFORM_EXTRAS=BTADDON' addons: apt: @@ -37,19 +46,20 @@ addons: install: if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + brew update; brew info proxmark3; brew options proxmark3; make clean; - make all V=1; + make all V=1 "$MAKE_PARAMS"; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean; - make all V=1; + make all V=1 "$MAKE_PARAMS"; fi script: ## start and run a test script if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - ./pm3test.sh; + ./pm3test.sh; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./pm3test.sh; fi From dd8e12271bd4578c65c8dce5c13d24d57bf4d766 Mon Sep 17 00:00:00 2001 From: soffchen Date: Tue, 20 Aug 2019 12:12:34 +0800 Subject: [PATCH 047/347] Add Proxmark3 rdv3 Easy with AT91SAM7S512 platform --- common_arm/Makefile.hal | 5 +++++ doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md | 1 + 2 files changed, 6 insertions(+) diff --git a/common_arm/Makefile.hal b/common_arm/Makefile.hal index af80bc6ac..794acdc1a 100644 --- a/common_arm/Makefile.hal +++ b/common_arm/Makefile.hal @@ -23,6 +23,8 @@ Known definitions: +----------------------------------------------------------+ | PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | +----------------------------------------------------------+ +| PM3EASY512 | Proxmark3 rdv3 Easy with AT91SAM7S512 | ++----------------------------------------------------------+ | PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 | +----------------------------------------------------------+ | PM3OLD256 | Proxmark3 V1 with AT91SAM7S256 | @@ -73,6 +75,9 @@ else ifeq ($(PLATFORM),PM3EVO) else ifeq ($(PLATFORM),PM3EASY) MCU = AT91SAM7S256 PLTNAME = Proxmark3 rdv3 Easy +else ifeq ($(PLATFORM),PM3EASY512) + MCU = AT91SAM7S512 + PLTNAME = Proxmark3 rdv3 Easy 512 else ifeq ($(PLATFORM),PM3RDV2) MCU = AT91SAM7S512 PLTNAME = Proxmark3 rdv2 diff --git a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md index aea5b5e30..c1ac92fc4 100644 --- a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md +++ b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md @@ -33,6 +33,7 @@ Here are the supported values you can assign to `PLATFORM` in `Makefile.platform | PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | | PM3EVO | Proxmark3 EVO with AT91SAM7S512 | | PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | +| PM3EASY512 | Proxmark3 rdv3 Easy with AT91SAM7S512 | | PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 | | PM3OLD256 | Proxmark3 V1 with AT91SAM7S256 | | PM3OLD512 | Proxmark3 V1 with AT91SAM7S512 | From 88186be47fcc7dfee036a2822137b0116a93e566 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 20 Aug 2019 09:20:50 +0300 Subject: [PATCH 048/347] delete update. for new cores it not needs (slow down aprox 1-2min) --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7ccdce078..501a85fcd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,7 +46,6 @@ addons: install: if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - brew update; brew info proxmark3; brew options proxmark3; make clean; From fea5d882788eb26c84a5572021cfc63eb36342dd Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 20 Aug 2019 14:53:52 +0200 Subject: [PATCH 049/347] add: detect unfused / write once magic tags, from https://github.com/nfc-tools/libnfc/pull/554 --- armsrc/mifarecmd.c | 7 +++++++ client/mifare/mifarehost.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 5e9de52dd..985a787ca 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1955,6 +1955,8 @@ void MifareCIdent() { #define GEN_1A 1 #define GEN_1B 2 #define GEN_2 4 +#define GEN_UNFUSED 5 + // variables uint8_t isGen = 0; uint8_t rec[1] = {0x00}; @@ -1990,6 +1992,11 @@ TEST2: int res = iso14443a_select_card(uid, NULL, &cuid, true, 0, true); if (res == 2) { + if (cuid == 0xAA55C396 ) { + isGen = GEN_UNFUSED; + goto OUT; + } + ReaderTransmit(rats, sizeof(rats), NULL); res = ReaderReceive(buf, par); if (memcmp(buf, "\x09\x78\x00\x91\x02\xDA\xBC\x19\x10\xF0\x05", 11) == 0) { diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index f7c7ce4f2..d22073d02 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -1041,6 +1041,9 @@ void detect_classic_magic(void) { case 4: PrintAndLogEx(SUCCESS, "Answers to magic commands (GEN 2 / CUID): " _GREEN_("YES")); break; + case 5: + PrintAndLogEx(SUCCESS, "Answers to magic commands (Write Once / FUID): " _GREEN_("YES")); + break; default: PrintAndLogEx(INFO, "Answers to magic commands: " _YELLOW_("NO")); break; From bd5a6094e7229f05c70392b43a252ca6436c4c93 Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 20 Aug 2019 15:03:03 +0200 Subject: [PATCH 050/347] Create emv_notes.md converting @merlokk 's emv wiki to doc. --- doc/emv_notes.md | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 doc/emv_notes.md diff --git a/doc/emv_notes.md b/doc/emv_notes.md new file mode 100644 index 000000000..a289d8ea5 --- /dev/null +++ b/doc/emv_notes.md @@ -0,0 +1,141 @@ +# EMV commands + + +### EMV Implemented parts: + +- Get ATR|ATS +- Get AID by PSE (`emv pse`) +- Get AID by appliation list (`emv search`) +- Select application (`emv select`) +- Format PDOL (look at next part) +- Execute GPO (`emv gpo` this step and format PDOL) +- Get records from AFL (`emv readrec`) +- Make SDA (check records from GPO) +- Make DDA (`emv challenge` `emv intauth`) +- Check PIN (`not implemented`) +- Fill CDOL1 and CDOL2 (look at next part) +- Execute AC1 (with CDA support) (`emv genac`) +- Check ARQC (bank part) (`not implemented`) +- Make ARPC (bank part) (`not implemented`) +- Execute external authenticate (`not implemented`) +- Execute AC2 (with CDA support) (`not implemented`) +- Check ARQC cryptogram (`not implemented`) +- Issuer scripts processing (`not implemented`) + +### Working parts of qVSDC: +^[Top](#top) + +- Get ATR|ATS +- Get AID by PSE (`emv pse`) +- Get AID by appliation list (`emv search`) +- Select application (`emv select`) +- Format PDOL (look at next part) +- Execute GPO (`emv gpo` this step and format PDOL) +- Get records from AFL (`emv readrec`) +- Make fDDA (`emv challenge` `emv intauth`) +- External authenticate command (`not implemented`) +- Issuer scripts processing (`not implemented`) + +### `not implemented` parts of EMV +^[Top](#top) + +They can be implemented, but it needs to know issuer's card keys (usually 3DES) and now this parts can be tested only on special test cards. + +### Commands +^[Top](#top) + +All this commands are parts of command `emv exec`. +command `emv exec` executes EMV transaction. it have parameters: +``` + -j, -J, --jload Load transaction parameters from `emv/defparams.json` file. + -f, -F, --forceaid Force search AID. Search AID instead of execute PPSE. + By default: Transaction type - MSD + -v, -V, --qvsdc Transaction type - qVSDC or M/Chip. + -c, -C, --qvsdccda Transaction type - qVSDC or M/Chip plus CDA (SDAD generation). + -x, -X, --vsdc Transaction type - VSDC. + -g, -G, --acgpo VISA. generate AC from GPO. + -w, -W, --wired Send data via contact (iso7816) interface. Contactless interface set by default. +``` +It works for VISA(r) and Mastercard(r) transactions. It may work with other EMV payment system's card (and it works in general cases that is described in EMV). + +### VISA(r) transactions: +^[Top](#top) + +MSD - Magnetic Stripe mode +VSDC - contact transacion +qVSDC - contactless transaction + +### Mastercard(r) transactions +^[Top](#top) + +MSD - Magnetic Stripe mode +M/Chip - contact and contactless transaction + +Different cards have different modes on/of and different behavior in them. So needs to check card in all this modes. +MSD - compatibility mode. Now it work always. But it less secure and in near future it will be slowly) disabled. + +### all commands: +^[Top](#top) + +``` +exec Executes EMV contactless transaction. +pse Execute PPSE. It selects 2PAY.SYS.DDF01 or 1PAY.SYS.DDF01 directory. +search Try to select all applets from applets list and print installed applets. +select Select applet. +gpo Execute GetProcessingOptions. +readrec Read files from card. +genac Generate ApplicationCryptogram. +challenge Generate challenge. +intauth Internal authentication. +scan Scan EMV card and save it contents to json file for emulator. +test Crypto logic test. +list List ISO7816 history +roca Extract public keys and run ROCA test +``` + +All main commands are parts of EMV specification. Commands than not described there: + +`emv scan` - scans card and saves all records to json file. Can be executed with or without tags disassembly. + +`emv roca` - extract public keys from cards (part of `emv scan`) + +`emv test` - test all crypto code from emv part of proxmark. + +### Useful links: +^[Top](#top) + +EMV specifications +http://www.emvco.com/specifications.aspx?id=155 + +Excelent explanation of EMV +http://www.openscdp.org/scripts/emv/index.html + +Fully working terminal written in Ruby. +https://code.google.com/p/ruby-pboc2-lib/source/browse/trunk/lib/pboc.rb + +EMV kernel written in C++ +https://github.com/ntufar/EMV/tree/master/EMV_Library + +C EMV library (part of this library uses proxmark) +https://github.com/lumag/emv-tools + +Resources (keys, country codes, etc): +https://github.com/binaryfoo/emv-bertlv/tree/master/src/main/resources + +### EMV kernels +^[Top](#top) + +POS terminal checks card and selects one of EMV kernels and launches it for EMV transaction. Different kernels have different rules to make EMV transaction. + +This list from: + +EMVco Architecture and General Requirement V2.4 volume A. +EMVco Entry Point specification V2.4 volume B + +- EMVco C-1 Kernel 1 V2.4 for some cards with JCB AIDs and some cards with Visa AIDs +- EMVco C-2 Kernel 2 V2.4 for MasterCards AIDs +- EMVco C-3 Kernel 3 V2.4 for Visa AIDs +- EMVco C-4 Kernel 4 V2.4 for American Express AIDs +- EMVco C-5 Kernel 5 V2.4 for JCB AIDs +- EMVco C-6 Kernel 6 V2.4 for Discover AIDs +- EMVco C-7 Kernel 7 V2.4 for UnionPay AIDs From 1ac5211601b50b82b41737dce0c3a72d9e0374ac Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 20 Aug 2019 15:46:08 +0200 Subject: [PATCH 051/347] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0968b1f06..68ef01492 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ _Note that it also supports other Proxmark3 platforms as well!_ |[PM3 GUI](#pm3-gui)|[Setup and build for Windows](/doc/md/Installation_Instructions/Windows-Installation-Instructions.md)|[Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| |[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) |[Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md)| |[Notes on UART](/doc/uart_notes.md)||[Command Cheat sheet](/doc/cheatsheet.md)| -|[Notes on Frame format](/doc/new_frame_format.md)||| +|[Notes on Frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| |[Notes on external flash](/doc/ext_flash_notes.md)||| |[Notes on Termux / Android](/doc/termux_notes.md)||| |[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||| From 08841481cd0efb9e35b9b920d0b3c1d7819943b9 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 20 Aug 2019 19:38:47 +0300 Subject: [PATCH 052/347] get rid of some commands --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 501a85fcd..8952df259 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,8 +46,6 @@ addons: install: if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - brew info proxmark3; - brew options proxmark3; make clean; make all V=1 "$MAKE_PARAMS"; elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then From 9535ce459e7d2f3d1e913f9d5c30d305d1f68277 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 20 Aug 2019 19:39:24 +0200 Subject: [PATCH 053/347] PLATFORM defs --- common_arm/Makefile.hal | 5 +++++ doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md | 3 +++ 2 files changed, 8 insertions(+) diff --git a/common_arm/Makefile.hal b/common_arm/Makefile.hal index 794acdc1a..411744037 100644 --- a/common_arm/Makefile.hal +++ b/common_arm/Makefile.hal @@ -21,6 +21,8 @@ Known definitions: +----------------------------------------------------------+ | PM3EVO | Proxmark3 EVO with AT91SAM7S512 | +----------------------------------------------------------+ +| PM3V40 | Proxmark3 V4.0 with AT91SAM7S512 | ++----------------------------------------------------------+ | PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | +----------------------------------------------------------+ | PM3EASY512 | Proxmark3 rdv3 Easy with AT91SAM7S512 | @@ -72,6 +74,9 @@ ifeq ($(PLATFORM),PM3RDV4) else ifeq ($(PLATFORM),PM3EVO) MCU = AT91SAM7S512 PLTNAME = Proxmark3 EVO +else ifeq ($(PLATFORM),PM3V40) + MCU = AT91SAM7S512 + PLTNAME = Proxmark3 V4.0 else ifeq ($(PLATFORM),PM3EASY) MCU = AT91SAM7S256 PLTNAME = Proxmark3 rdv3 Easy diff --git a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md index c1ac92fc4..270682696 100644 --- a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md +++ b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md @@ -32,6 +32,7 @@ Here are the supported values you can assign to `PLATFORM` in `Makefile.platform |-----------------|----------------------------------------| | PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | | PM3EVO | Proxmark3 EVO with AT91SAM7S512 | +| PM3V40 | Proxmark3 V4.0 with AT91SAM7S512 | | PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | | PM3EASY512 | Proxmark3 rdv3 Easy with AT91SAM7S512 | | PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 | @@ -40,6 +41,8 @@ Here are the supported values you can assign to `PLATFORM` in `Makefile.platform By default `PLATFORM=PM3RDV4`. +Note that besides `PM3RDV4` and its unique features, all other platforms are equivalent and the MCU version (256 or 512) will be detected automatically during flashing. + Known issues: * 256kb Arm chip devices: The compiled firmware image from this repo may/will be too large for your device. From fdcc885aa945e05edd9dde071c8b2c74201a37e4 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 20 Aug 2019 23:21:18 +0200 Subject: [PATCH 054/347] Use /dev/tty on OSX rather than /dev/cu See https://stackoverflow.com/questions/8632586/macos-whats-the-difference-between-dev-tty-and-dev-cu/8632603 --- include/usart_defs.h | 2 +- proxmark3.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/usart_defs.h b/include/usart_defs.h index 232e80276..cf6630e83 100644 --- a/include/usart_defs.h +++ b/include/usart_defs.h @@ -18,7 +18,7 @@ #if defined (_WIN32) #define SERIAL_PORT_EXAMPLE_H "com3" #elif defined(__APPLE__) -#define SERIAL_PORT_EXAMPLE_H "/dev/cu.usbmodem" +#define SERIAL_PORT_EXAMPLE_H "/dev/tty.usbmodemiceman1" #else #define SERIAL_PORT_EXAMPLE_H "/dev/ttyACM0" #endif diff --git a/proxmark3.sh b/proxmark3.sh index be3cfd690..89e7e960b 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -21,7 +21,7 @@ function wait4proxmark_Linux { function wait4proxmark_macOS { echo >&2 "[=] Waiting for Proxmark3 to appear..." while true; do - PM3=$(find /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) + PM3=$(find /dev/pm3-* /dev/tty.usbmodem* 2>/dev/null | head -1) if [[ $PM3 != "" ]]; then break fi From 4e627f09c017ea3ac22c66933eec3de5a7eb94ea Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 21 Aug 2019 12:52:59 +0200 Subject: [PATCH 055/347] add: proxmark3 -v/--version - for easiness to detect version in offline mode and installs --- client/cmdhw.c | 19 +++++++++++++++++-- client/cmdhw.h | 2 +- client/proxmark3.c | 11 +++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 7fec7a40c..b6cb2bd87 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -493,7 +493,7 @@ static int CmdTune(const char *Cmd) { static int CmdVersion(const char *Cmd) { (void)Cmd; // Cmd is not used so far - pm3_version(true); + pm3_version(true, false); return PM3_SUCCESS; } @@ -617,7 +617,21 @@ int CmdHW(const char *Cmd) { return CmdsParse(CommandTable, Cmd); } -void pm3_version(bool verbose) { +void pm3_version(bool verbose, bool oneliner) { + + if (oneliner) { + char msg[70]; + memset(msg, 0x00, sizeof(msg)); + strcat(msg, "Client: RRG/Iceman compiled with "); +#if defined(__clang__) + strcat(msg + strlen(msg), _YELLOW_("Clang/LLVM "__VERSION__)); +#elif defined(__GNUC__) || defined(__GNUG__) + strcat(msg + strlen(msg), _YELLOW_("GCC "__VERSION__)); +#endif + PrintAndLogEx(NORMAL, "%s", msg); + return; + } + if (!verbose) return; @@ -635,6 +649,7 @@ void pm3_version(bool verbose) { #elif defined(__GNUC__) || defined(__GNUG__) PrintAndLogEx(NORMAL, " compiled with GCC "__VERSION__); #endif + PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 ]"); PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); diff --git a/client/cmdhw.h b/client/cmdhw.h index 1a378e70f..bf40b70a8 100644 --- a/client/cmdhw.h +++ b/client/cmdhw.h @@ -15,6 +15,6 @@ int CmdHW(const char *Cmd); -void pm3_version(bool verbose); +void pm3_version(bool verbose, bool oneliner); #endif diff --git a/client/proxmark3.c b/client/proxmark3.c index de6fe43af..6555ac0f2 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -88,9 +88,9 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { if (session.pm3_present) { // cache Version information now: if (execCommand || script_cmds_file || stdinOnPipe) - pm3_version(false); + pm3_version(false, false); else - pm3_version(true); + pm3_version(true, false); } if (script_cmds_file) { @@ -284,6 +284,7 @@ static void show_help(bool showFullHelp, char *exec_name) { PrintAndLogEx(NORMAL, " -l/--lua execute lua script."); PrintAndLogEx(NORMAL, " -s/--script-file script file with one Proxmark3 command per line"); PrintAndLogEx(NORMAL, " -i/--interactive enter interactive mode after executing the script or the command"); + PrintAndLogEx(NORMAL, " -v/--version print client version"); PrintAndLogEx(NORMAL, "\nsamples:"); PrintAndLogEx(NORMAL, " %s -h\n", exec_name); PrintAndLogEx(NORMAL, " %s -m\n", exec_name); @@ -378,6 +379,12 @@ int main(int argc, char *argv[]) { dumpAllHelp(1); return 0; } + // pritn client version + if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { + pm3_version(true, true); + return 0; + } + // flush output if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--flush") == 0) { From a0f261c1e049b352be9f84dfb1a614477dab50fb Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 21 Aug 2019 14:41:33 +0200 Subject: [PATCH 056/347] chg: moved fileutils from loclass --- client/Makefile | 2 +- client/cmdflashmem.c | 2 +- client/cmdflashmemspiffs.c | 2 +- client/cmdhf14b.c | 2 +- client/cmdhf15.c | 2 +- client/cmdhficlass.c | 2 +- client/cmdhflegic.c | 2 +- client/cmdhfmf.c | 2 +- client/cmdhfmfu.c | 2 +- client/cmdlfhitag.c | 2 +- client/cmdlft55xx.c | 2 +- client/cmdtrace.c | 2 +- client/loclass/fileutils.c | 618 ------------------------------------- client/loclass/fileutils.h | 181 ----------- 14 files changed, 12 insertions(+), 811 deletions(-) delete mode 100644 client/loclass/fileutils.c delete mode 100644 client/loclass/fileutils.h diff --git a/client/Makefile b/client/Makefile index 9f8dacb3d..9711d29ed 100644 --- a/client/Makefile +++ b/client/Makefile @@ -157,7 +157,7 @@ CMDSRCS = crapto1/crapto1.c \ loclass/cipherutils.c \ loclass/ikeys.c \ loclass/elite_crack.c \ - loclass/fileutils.c \ + fileutils.c \ whereami.c \ mifare/mifarehost.c \ parity.c \ diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 6bb6fbc3c..a89d2eae6 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -14,7 +14,7 @@ #include "cmdparser.h" // command_t #include "pmflash.h" -#include "loclass/fileutils.h" //saveFile +#include "fileutils.h" //saveFile #include "comms.h" //getfromdevice #include "cmdflashmemspiffs.h" // spiffs commands diff --git a/client/cmdflashmemspiffs.c b/client/cmdflashmemspiffs.c index f53e17915..5783e2705 100644 --- a/client/cmdflashmemspiffs.c +++ b/client/cmdflashmemspiffs.c @@ -13,7 +13,7 @@ #include "cmdparser.h" // command_t #include "pmflash.h" -#include "loclass/fileutils.h" //saveFile +#include "fileutils.h" //saveFile #include "comms.h" //getfromdevice static int CmdHelp(const char *Cmd); diff --git a/client/cmdhf14b.c b/client/cmdhf14b.c index c5a628835..57f275a31 100644 --- a/client/cmdhf14b.c +++ b/client/cmdhf14b.c @@ -12,7 +12,7 @@ #include "cmdhf14b.h" #include -#include "loclass/fileutils.h" +#include "fileutils.h" #include "cmdparser.h" // command_t #include "comms.h" // clearCommandBuffer diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 2c788087e..eb8cb6f87 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -35,7 +35,7 @@ #include "graph.h" #include "crc16.h" // iso15 crc #include "cmddata.h" // getsamples -#include "loclass/fileutils.h" // savefileEML +#include "fileutils.h" // savefileEML #define FrameSOF Iso15693FrameSOF #define Logic0 Iso15693Logic0 diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 7badc7c86..3cbbd1a67 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -26,7 +26,7 @@ #include "loclass/cipher.h" #include "loclass/ikeys.h" #include "loclass/elite_crack.h" -#include "loclass/fileutils.h" +#include "fileutils.h" #include "protocols.h" diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index af56807b1..fe1f53785 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -17,7 +17,7 @@ #include "cmdtrace.h" #include "crc.h" #include "crc16.h" -#include "loclass/fileutils.h" //saveFile +#include "fileutils.h" //saveFile static int CmdHelp(const char *Cmd); diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index affc53603..aaaeafb99 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -15,7 +15,7 @@ #include "cmdparser.h" // command_t #include "commonutil.h" // ARRAYLEN #include "comms.h" // clearCommandBuffer -#include "loclass/fileutils.h" +#include "fileutils.h" #include "cmdtrace.h" #include "emv/dump.h" #include "mifare/mifaredefault.h" // mifare default key array diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index e2c64a004..23eac5504 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -18,7 +18,7 @@ #include "cmdhfmf.h" #include "cmdhf14a.h" #include "comms.h" -#include "loclass/fileutils.h" +#include "fileutils.h" #include "protocols.h" #define MAX_UL_BLOCKS 0x0F diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index 190b84283..2bcd476ea 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -15,7 +15,7 @@ #include "cmdtrace.h" #include "commonutil.h" #include "hitag.h" -#include "loclass/fileutils.h" // savefile +#include "fileutils.h" // savefile static int CmdHelp(const char *Cmd); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index d5f66496d..3c88a23ea 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -25,7 +25,7 @@ #include "cmddata.h" #include "lfdemod.h" #include "cmdhf14a.h" // for getTagInfo -#include "loclass/fileutils.h" // loadDictionary +#include "fileutils.h" // loadDictionary #include "util_posix.h" diff --git a/client/cmdtrace.c b/client/cmdtrace.c index 15416a8a6..ecb3fc158 100644 --- a/client/cmdtrace.c +++ b/client/cmdtrace.c @@ -16,7 +16,7 @@ #include "parity.h" // oddparity #include "cmdhflist.h" // annotations #include "comms.h" // for sending cmds to device. GetFromBigBuf -#include "loclass/fileutils.h" // for saveFile +#include "fileutils.h" // for saveFile static int CmdHelp(const char *Cmd); diff --git a/client/loclass/fileutils.c b/client/loclass/fileutils.c deleted file mode 100644 index b89925334..000000000 --- a/client/loclass/fileutils.c +++ /dev/null @@ -1,618 +0,0 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - ****************************************************************************/ -#include "fileutils.h" - -#include - -#include "pm3_cmd.h" -#include "commonutil.h" -#include "util.h" - - -#ifndef ON_DEVICE - -#define PATH_MAX_LENGTH 100 - -/** - * @brief checks if a file exists - * @param filename - * @return - */ -int fileExists(const char *filename) { - -#ifdef _WIN32 - struct _stat st; - int result = _stat(filename, &st); -#else - struct stat st; - int result = stat(filename, &st); -#endif - return result == 0; -} - -static char *filenamemcopy(const char *preferredName, const char *suffix) { - if (preferredName == NULL) return NULL; - if (suffix == NULL) return NULL; - char *fileName = (char *) calloc(strlen(preferredName) + strlen(suffix) + 1, sizeof(uint8_t)); - if (fileName == NULL) - return NULL; - strcpy(fileName, preferredName); - if (str_endswith(fileName, suffix)) - return fileName; - strcat(fileName, suffix); - return fileName; -} - -static char *newfilenamemcopy(const char *preferredName, const char *suffix) { - if (preferredName == NULL) return NULL; - if (suffix == NULL) return NULL; - uint16_t preferredNameLen = strlen(preferredName); - if (str_endswith(preferredName, suffix)) - preferredNameLen -= strlen(suffix); - char *fileName = (char *) calloc(preferredNameLen + strlen(suffix) + 1 + 10, sizeof(uint8_t)); // 10: room for filenum to ensure new filename - if (fileName == NULL) { - return NULL; - } - int num = 1; - sprintf(fileName, "%.*s%s", preferredNameLen, preferredName, suffix); - while (fileExists(fileName)) { - sprintf(fileName, "%.*s-%d%s", preferredNameLen, preferredName, num, suffix); - num++; - } - return fileName; -} - -int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen) { - - if (data == NULL) return 1; - char *fileName = newfilenamemcopy(preferredName, suffix); - if (fileName == NULL) return 1; - - /* We should have a valid filename now, e.g. dumpdata-3.bin */ - - /*Opening file for writing in binary mode*/ - FILE *f = fopen(fileName, "wb"); - if (!f) { - PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); - free(fileName); - return PM3_EFILE; - } - fwrite(data, 1, datalen, f); - fflush(f); - fclose(f); - PrintAndLogEx(SUCCESS, "saved %u bytes to binary file " _YELLOW_("%s"), datalen, fileName); - free(fileName); - return PM3_SUCCESS; -} - -int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize) { - - if (data == NULL) return 1; - char *fileName = newfilenamemcopy(preferredName, ".eml"); - if (fileName == NULL) return 1; - - int retval = PM3_SUCCESS; - int blocks = datalen / blocksize; - uint16_t currblock = 1; - - /* We should have a valid filename now, e.g. dumpdata-3.bin */ - - /*Opening file for writing in text mode*/ - FILE *f = fopen(fileName, "w+"); - if (!f) { - PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); - retval = PM3_EFILE; - goto out; - } - - for (size_t i = 0; i < datalen; i++) { - fprintf(f, "%02X", data[i]); - - // no extra line in the end - if ((i + 1) % blocksize == 0 && currblock != blocks) { - fprintf(f, "\n"); - currblock++; - } - } - // left overs - if (datalen % blocksize != 0) { - int index = blocks * blocksize; - for (size_t j = 0; j < datalen % blocksize; j++) { - fprintf(f, "%02X", data[index + j]); - } - } - fflush(f); - fclose(f); - PrintAndLogEx(SUCCESS, "saved %d blocks to text file " _YELLOW_("%s"), blocks, fileName); - -out: - free(fileName); - return retval; -} - -int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen) { - - if (data == NULL) return 1; - char *fileName = newfilenamemcopy(preferredName, ".json"); - if (fileName == NULL) return 1; - - int retval = PM3_SUCCESS; - - json_t *root = json_object(); - JsonSaveStr(root, "Created", "proxmark3"); - switch (ftype) { - case jsfRaw: { - JsonSaveStr(root, "FileType", "raw"); - JsonSaveBufAsHexCompact(root, "raw", data, datalen); - break; - } - case jsfCardMemory: { - JsonSaveStr(root, "FileType", "mfcard"); - for (size_t i = 0; i < (datalen / 16); i++) { - char path[PATH_MAX_LENGTH] = {0}; - sprintf(path, "$.blocks.%zu", i); - JsonSaveBufAsHexCompact(root, path, &data[i * 16], 16); - - if (i == 0) { - JsonSaveBufAsHexCompact(root, "$.Card.UID", &data[0], 4); - JsonSaveBufAsHexCompact(root, "$.Card.SAK", &data[5], 1); - JsonSaveBufAsHexCompact(root, "$.Card.ATQA", &data[6], 2); - } - - if (mfIsSectorTrailer(i)) { - memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.KeyA", mfSectorNum(i)); - JsonSaveBufAsHexCompact(root, path, &data[i * 16], 6); - - memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.KeyB", mfSectorNum(i)); - JsonSaveBufAsHexCompact(root, path, &data[i * 16 + 10], 6); - - memset(path, 0x00, sizeof(path)); - uint8_t *adata = &data[i * 16 + 6]; - sprintf(path, "$.SectorKeys.%d.AccessConditions", mfSectorNum(i)); - JsonSaveBufAsHexCompact(root, path, &data[i * 16 + 6], 4); - - memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 3); - JsonSaveStr(root, path, mfGetAccessConditionsDesc(0, adata)); - - memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 2); - JsonSaveStr(root, path, mfGetAccessConditionsDesc(1, adata)); - - memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 1); - JsonSaveStr(root, path, mfGetAccessConditionsDesc(2, adata)); - - memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i); - JsonSaveStr(root, path, mfGetAccessConditionsDesc(3, adata)); - - memset(path, 0x00, sizeof(path)); - sprintf(path, "$.SectorKeys.%d.AccessConditionsText.UserData", mfSectorNum(i)); - JsonSaveBufAsHexCompact(root, path, &adata[3], 1); - } - } - break; - } - case jsfMfuMemory: { - JsonSaveStr(root, "FileType", "mfu"); - - mfu_dump_t *tmp = (mfu_dump_t *)data; - - uint8_t uid[7] = {0}; - memcpy(uid, tmp->data, 3); - memcpy(uid + 3, tmp->data + 4, 4); - - char path[PATH_MAX_LENGTH] = {0}; - - JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); - JsonSaveBufAsHexCompact(root, "$.Card.Version", tmp->version, sizeof(tmp->version)); - JsonSaveBufAsHexCompact(root, "$.Card.TBO_0", tmp->tbo, sizeof(tmp->tbo)); - JsonSaveBufAsHexCompact(root, "$.Card.TBO_1", tmp->tbo1, sizeof(tmp->tbo1)); - JsonSaveBufAsHexCompact(root, "$.Card.Signature", tmp->signature, sizeof(tmp->signature)); - for (uint8_t i = 0; i < 3; i ++) { - sprintf(path, "$.Card.Counter%d", i); - JsonSaveBufAsHexCompact(root, path, tmp->counter_tearing[i], 3); - sprintf(path, "$.Card.Tearing%d", i); - JsonSaveBufAsHexCompact(root, path, tmp->counter_tearing[i] + 3, 1); - } - - // size of header 56b - size_t len = (datalen - MFU_DUMP_PREFIX_LENGTH) / 4; - - for (size_t i = 0; i < len; i++) { - sprintf(path, "$.blocks.%zu", i); - JsonSaveBufAsHexCompact(root, path, tmp->data + (i * 4), 4); - } - break; - } - case jsfHitag: { - JsonSaveStr(root, "FileType", "hitag"); - uint8_t uid[4] = {0}; - memcpy(uid, data, 4); - - JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); - - for (size_t i = 0; i < (datalen / 4); i++) { - char path[PATH_MAX_LENGTH] = {0}; - sprintf(path, "$.blocks.%zu", i); - JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4); - } - break; - } - } - - int res = json_dump_file(root, fileName, JSON_INDENT(2)); - if (res) { - PrintAndLogEx(FAILED, "error: can't save the file: " _YELLOW_("%s"), fileName); - json_decref(root); - retval = 200; - goto out; - } - PrintAndLogEx(SUCCESS, "saved to json file " _YELLOW_("%s"), fileName); - json_decref(root); - -out: - free(fileName); - return retval; -} - -int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen) { - - if (data == NULL) return 1; - char *fileName = filenamemcopy(preferredName, suffix); - if (fileName == NULL) return 1; - - int retval = PM3_SUCCESS; - - FILE *f = fopen(fileName, "rb"); - if (!f) { - PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); - free(fileName); - return PM3_EFILE; - } - - // get filesize in order to malloc memory - fseek(f, 0, SEEK_END); - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); - - if (fsize <= 0) { - PrintAndLogEx(FAILED, "error, when getting filesize"); - retval = 1; - goto out; - } - - uint8_t *dump = calloc(fsize, sizeof(uint8_t)); - if (!dump) { - PrintAndLogEx(FAILED, "error, cannot allocate memory"); - retval = 2; - goto out; - } - - size_t bytes_read = fread(dump, 1, fsize, f); - - if (bytes_read != fsize) { - PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); - free(dump); - retval = 3; - goto out; - } - - if (bytes_read > maxdatalen) { - PrintAndLogEx(WARNING, "Warning, bytes read exceed calling array limit. Max bytes is %d bytes", maxdatalen); - bytes_read = maxdatalen; - } - - memcpy((data), dump, bytes_read); - free(dump); - - PrintAndLogEx(SUCCESS, "loaded %d bytes from binary file " _YELLOW_("%s"), bytes_read, fileName); - - *datalen = bytes_read; - -out: - fclose(f); - free(fileName); - - return retval; -} - -int loadFileEML(const char *preferredName, void *data, size_t *datalen) { - - if (data == NULL) return 1; - char *fileName = filenamemcopy(preferredName, ".eml"); - if (fileName == NULL) return 1; - - size_t counter = 0; - int retval = PM3_SUCCESS, hexlen = 0; - - FILE *f = fopen(fileName, "r"); - if (!f) { - PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); - retval = PM3_EFILE; - goto out; - } - - // 128 + 2 newline chars + 1 null terminator - char line[131]; - memset(line, 0, sizeof(line)); - uint8_t buf[64] = {0x00}; - - while (!feof(f)) { - - memset(line, 0, sizeof(line)); - - if (fgets(line, sizeof(line), f) == NULL) { - if (feof(f)) - break; - fclose(f); - PrintAndLogEx(FAILED, "File reading error."); - retval = 2; - goto out; - } - - if (line[0] == '#') - continue; - - int res = param_gethex_to_eol(line, 0, buf, sizeof(buf), &hexlen); - if (res == 0 || res == 1) { - memcpy(data + counter, buf, hexlen); - counter += hexlen; - } - } - fclose(f); - PrintAndLogEx(SUCCESS, "loaded %d bytes from text file " _YELLOW_("%s"), counter, fileName); - - if (datalen) - *datalen = counter; - -out: - free(fileName); - return retval; -} - -int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen) { - - if (data == NULL) return 1; - char *fileName = filenamemcopy(preferredName, ".json"); - if (fileName == NULL) return 1; - - *datalen = 0; - json_t *root; - json_error_t error; - - int retval = PM3_SUCCESS; - - root = json_load_file(fileName, 0, &error); - if (!root) { - PrintAndLogEx(ERR, "ERROR: json " _YELLOW_("%s") " error on line %d: %s", fileName, error.line, error.text); - retval = 2; - goto out; - } - - if (!json_is_object(root)) { - PrintAndLogEx(ERR, "ERROR: Invalid json " _YELLOW_("%s") " format. root must be an object.", fileName); - retval = 3; - goto out; - } - - uint8_t *udata = (uint8_t *)data; - char ctype[100] = {0}; - JsonLoadStr(root, "$.FileType", ctype); - - if (!strcmp(ctype, "raw")) { - JsonLoadBufAsHex(root, "$.raw", udata, maxdatalen, datalen); - } - - if (!strcmp(ctype, "mfcard")) { - size_t sptr = 0; - for (int i = 0; i < 256; i++) { - if (sptr + 16 > maxdatalen) { - retval = 5; - goto out; - } - - char path[30] = {0}; - sprintf(path, "$.blocks.%d", i); - - size_t len = 0; - JsonLoadBufAsHex(root, path, &udata[sptr], 16, &len); - if (!len) - break; - - sptr += len; - } - - *datalen = sptr; - } - - if (!strcmp(ctype, "mfu")) { - size_t sptr = 0; - for (int i = 0; i < 256; i++) { - if (sptr + 4 > maxdatalen) { - retval = 5; - goto out; - } - - char path[30] = {0}; - sprintf(path, "$.blocks.%d", i); - - size_t len = 0; - JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len); - if (!len) - break; - - sptr += len; - } - - *datalen = sptr; - } - - if (!strcmp(ctype, "hitag")) { - size_t sptr = 0; - for (size_t i = 0; i < (maxdatalen / 4); i++) { - if (sptr + 4 > maxdatalen) { - retval = 5; - goto out; - } - - char path[30] = {0}; - sprintf(path, "$.blocks.%zu", i); - - size_t len = 0; - JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len); - if (!len) - break; - - sptr += len; - } - - *datalen = sptr; - } - - PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName); -out: - json_decref(root); - free(fileName); - return retval; -} - -int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt) { - - - if (data == NULL) return 1; - char *fileName = filenamemcopy(preferredName, ".dic"); - if (fileName == NULL) return 1; - - // t5577 == 4bytes - // mifare == 6 bytes - // iclass == 8 bytes - // default to 6 bytes. - if (keylen != 4 && keylen != 6 && keylen != 8) { - keylen = 6; - } - - // double up since its chars - keylen <<= 1; - - char line[255]; - - size_t counter = 0; - int retval = PM3_SUCCESS; - - FILE *f = fopen(fileName, "r"); - if (!f) { - PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); - retval = PM3_EFILE; - goto out; - } - - // read file - while (fgets(line, sizeof(line), f)) { - - // add null terminator - line[keylen] = 0; - - // smaller keys than expected is skipped - if (strlen(line) < keylen) - continue; - - // The line start with # is comment, skip - if (line[0] == '#') - continue; - - if (!isxdigit(line[0])) { - PrintAndLogEx(FAILED, "file content error. '%s' must include " _BLUE_("%2d") "HEX symbols", line, keylen); - continue; - } - - uint64_t key = strtoull(line, NULL, 16); - - num_to_bytes(key, keylen >> 1, data + counter); - (*keycnt)++; - memset(line, 0, sizeof(line)); - counter += (keylen >> 1); - } - fclose(f); - PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, fileName); - - if (datalen) - *datalen = counter; -out: - free(fileName); - return retval; -} - -int convertOldMfuDump(uint8_t **dump, size_t *dumplen) { - if (!dump || !dumplen || *dumplen < OLD_MFU_DUMP_PREFIX_LENGTH) - return 1; - // try to check new file format - mfu_dump_t *mfu_dump = (mfu_dump_t *) *dump; - if ((*dumplen - MFU_DUMP_PREFIX_LENGTH) / 4 - 1 == mfu_dump->pages) - return 0; - // convert old format - old_mfu_dump_t *old_mfu_dump = (old_mfu_dump_t *) *dump; - - size_t old_data_len = *dumplen - OLD_MFU_DUMP_PREFIX_LENGTH; - size_t new_dump_len = old_data_len + MFU_DUMP_PREFIX_LENGTH; - - mfu_dump = (mfu_dump_t *) calloc(new_dump_len, sizeof(uint8_t)); - - memcpy(mfu_dump->version, old_mfu_dump->version, 8); - memcpy(mfu_dump->tbo, old_mfu_dump->tbo, 2); - mfu_dump->tbo1[0] = old_mfu_dump->tbo1[0]; - memcpy(mfu_dump->signature, old_mfu_dump->signature, 32); - for (int i = 0; i < 3; i++) - mfu_dump->counter_tearing[i][3] = old_mfu_dump->tearing[i]; - - memcpy(mfu_dump->data, old_mfu_dump->data, old_data_len); - mfu_dump->pages = old_data_len / 4 - 1; - // free old buffer, return new buffer - *dumplen = new_dump_len; - free(*dump); - *dump = (uint8_t *) mfu_dump; - PrintAndLogEx(SUCCESS, "old mfu dump format, was converted on load to " _GREEN_("%d") " pages", mfu_dump->pages + 1); - return PM3_SUCCESS; -} - - -#else //if we're on ARM - -#endif diff --git a/client/loclass/fileutils.h b/client/loclass/fileutils.h deleted file mode 100644 index 74d54000b..000000000 --- a/client/loclass/fileutils.h +++ /dev/null @@ -1,181 +0,0 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - ****************************************************************************/ - -#ifndef FILEUTILS_H -#define FILEUTILS_H - -#ifndef ON_DEVICE - -#include -#include -#include -#include -#include -#include -#include "../ui.h" -#include "../emv/emvjson.h" -#include "mifare/mifare4.h" -#include "cmdhfmfu.h" - -typedef enum { - jsfRaw, - jsfCardMemory, - jsfMfuMemory, - jsfHitag, -// jsf14b, -// jsf15, -// jsfLegic, -// jsfT55xx, -} JSONFileType; - -int fileExists(const char *filename); - -/** - * @brief Utility function to save data to a binary file. This method takes a preferred name, but if that - * file already exists, it tries with another name until it finds something suitable. - * E.g. dumpdata-15.txt - * - * @param preferredName - * @param suffix the file suffix. Including the ".". - * @param data The binary data to write to the file - * @param datalen the length of the data - * @return 0 for ok, 1 for failz - */ -int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen); - -/** - * @brief Utility function to save data to a textfile (EML). This method takes a preferred name, but if that - * file already exists, it tries with another name until it finds something suitable. - * E.g. dumpdata-15.txt - * - * @param preferredName - * @param data The binary data to write to the file - * @param datalen the length of the data - * @param blocksize the length of one row - * @return 0 for ok, 1 for failz -*/ -int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize); - -/** STUB - * @brief Utility function to save JSON data to a file. This method takes a preferred name, but if that - * file already exists, it tries with another name until it finds something suitable. - * E.g. dumpdata-15.json - * - * @param preferredName - * @param ftype type of file. - * @param data The binary data to write to the file - * @param datalen the length of the data - * @return 0 for ok, 1 for failz - */ -int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen); - -/** STUB - * @brief Utility function to load data from a binary file. This method takes a preferred name. - * E.g. dumpdata-15.bin - * - * @param preferredName - * @param suffix the file suffix. Including the ".". - * @param data The data array to store the loaded bytes from file - * @param maxdatalen the number of bytes that your data array has - * @param datalen the number of bytes loaded from file - * @return 0 for ok, 1 for failz -*/ -int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen); - -/** - * @brief Utility function to load data from a textfile (EML). This method takes a preferred name. - * E.g. dumpdata-15.txt - * - * @param preferredName - * @param data The data array to store the loaded bytes from file - * @param datalen the number of bytes loaded from file - * @return 0 for ok, 1 for failz -*/ -int loadFileEML(const char *preferredName, void *data, size_t *datalen); - -/** - * @brief Utility function to load data from a JSON textfile. This method takes a preferred name. - * E.g. dumpdata-15.json - * - * @param preferredName - * @param data The data array to store the loaded bytes from file - * @param maxdatalen maximum size of data array in bytes - * @param datalen the number of bytes loaded from file - * @return 0 for ok, 1 for failz -*/ -int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen); - - -/** - * @brief Utility function to load data from a DICTIONARY textfile. This method takes a preferred name. - * E.g. default_keys.dic - * - * @param preferredName - * @param data The data array to store the loaded bytes from file - * @param maxdatalen maximum size of data array in bytes - * @param datalen the number of bytes loaded from file - * @param keylen the number of bytes a key per row is - * @return 0 for ok, 1 for failz -*/ -int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt); - -/** - * @brief Utility function to check and convert old mfu dump format to new - * - * @param dump pointer to loaded dump to check and convert format - * @param dumplen the number of bytes loaded dump and converted - * @return 0 for ok, 1 for fails -*/ -int convertOldMfuDump(uint8_t **dump, size_t *dumplen); - -#define PrintAndLogEx(level, format, args...) PrintAndLogEx(level, format , ## args) -#else - -/** -* Utility function to print to console. This is used consistently within the library instead -* of printf, but it actually only calls printf. The reason to have this method is to -*make it simple to plug this library into proxmark, which has this function already to -* write also to a logfile. When doing so, just point this function to use PrintAndLog -* @param fmt -*/ -#define PrintAndLogEx(level, format, args...) { } - - - -#endif //ON_DEVICE - -#endif // FILEUTILS_H From 56267ea6235d704f4385599ea7c6bede6bf21df7 Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 21 Aug 2019 14:43:22 +0200 Subject: [PATCH 057/347] readd fileutils --- client/fileutils.c | 618 +++++++++++++++++++++++++++++++++++++++++++++ client/fileutils.h | 181 +++++++++++++ 2 files changed, 799 insertions(+) create mode 100644 client/fileutils.c create mode 100644 client/fileutils.h diff --git a/client/fileutils.c b/client/fileutils.c new file mode 100644 index 000000000..b89925334 --- /dev/null +++ b/client/fileutils.c @@ -0,0 +1,618 @@ +/***************************************************************************** + * WARNING + * + * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. + * + * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL + * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, + * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. + * + * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. + * + ***************************************************************************** + * + * This file is part of loclass. It is a reconstructon of the cipher engine + * used in iClass, and RFID techology. + * + * The implementation is based on the work performed by + * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and + * Milosch Meriac in the paper "Dismantling IClass". + * + * Copyright (C) 2014 Martin Holst Swende + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, or, at your option, any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with loclass. If not, see . + * + * + ****************************************************************************/ +#include "fileutils.h" + +#include + +#include "pm3_cmd.h" +#include "commonutil.h" +#include "util.h" + + +#ifndef ON_DEVICE + +#define PATH_MAX_LENGTH 100 + +/** + * @brief checks if a file exists + * @param filename + * @return + */ +int fileExists(const char *filename) { + +#ifdef _WIN32 + struct _stat st; + int result = _stat(filename, &st); +#else + struct stat st; + int result = stat(filename, &st); +#endif + return result == 0; +} + +static char *filenamemcopy(const char *preferredName, const char *suffix) { + if (preferredName == NULL) return NULL; + if (suffix == NULL) return NULL; + char *fileName = (char *) calloc(strlen(preferredName) + strlen(suffix) + 1, sizeof(uint8_t)); + if (fileName == NULL) + return NULL; + strcpy(fileName, preferredName); + if (str_endswith(fileName, suffix)) + return fileName; + strcat(fileName, suffix); + return fileName; +} + +static char *newfilenamemcopy(const char *preferredName, const char *suffix) { + if (preferredName == NULL) return NULL; + if (suffix == NULL) return NULL; + uint16_t preferredNameLen = strlen(preferredName); + if (str_endswith(preferredName, suffix)) + preferredNameLen -= strlen(suffix); + char *fileName = (char *) calloc(preferredNameLen + strlen(suffix) + 1 + 10, sizeof(uint8_t)); // 10: room for filenum to ensure new filename + if (fileName == NULL) { + return NULL; + } + int num = 1; + sprintf(fileName, "%.*s%s", preferredNameLen, preferredName, suffix); + while (fileExists(fileName)) { + sprintf(fileName, "%.*s-%d%s", preferredNameLen, preferredName, num, suffix); + num++; + } + return fileName; +} + +int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen) { + + if (data == NULL) return 1; + char *fileName = newfilenamemcopy(preferredName, suffix); + if (fileName == NULL) return 1; + + /* We should have a valid filename now, e.g. dumpdata-3.bin */ + + /*Opening file for writing in binary mode*/ + FILE *f = fopen(fileName, "wb"); + if (!f) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + free(fileName); + return PM3_EFILE; + } + fwrite(data, 1, datalen, f); + fflush(f); + fclose(f); + PrintAndLogEx(SUCCESS, "saved %u bytes to binary file " _YELLOW_("%s"), datalen, fileName); + free(fileName); + return PM3_SUCCESS; +} + +int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize) { + + if (data == NULL) return 1; + char *fileName = newfilenamemcopy(preferredName, ".eml"); + if (fileName == NULL) return 1; + + int retval = PM3_SUCCESS; + int blocks = datalen / blocksize; + uint16_t currblock = 1; + + /* We should have a valid filename now, e.g. dumpdata-3.bin */ + + /*Opening file for writing in text mode*/ + FILE *f = fopen(fileName, "w+"); + if (!f) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + retval = PM3_EFILE; + goto out; + } + + for (size_t i = 0; i < datalen; i++) { + fprintf(f, "%02X", data[i]); + + // no extra line in the end + if ((i + 1) % blocksize == 0 && currblock != blocks) { + fprintf(f, "\n"); + currblock++; + } + } + // left overs + if (datalen % blocksize != 0) { + int index = blocks * blocksize; + for (size_t j = 0; j < datalen % blocksize; j++) { + fprintf(f, "%02X", data[index + j]); + } + } + fflush(f); + fclose(f); + PrintAndLogEx(SUCCESS, "saved %d blocks to text file " _YELLOW_("%s"), blocks, fileName); + +out: + free(fileName); + return retval; +} + +int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen) { + + if (data == NULL) return 1; + char *fileName = newfilenamemcopy(preferredName, ".json"); + if (fileName == NULL) return 1; + + int retval = PM3_SUCCESS; + + json_t *root = json_object(); + JsonSaveStr(root, "Created", "proxmark3"); + switch (ftype) { + case jsfRaw: { + JsonSaveStr(root, "FileType", "raw"); + JsonSaveBufAsHexCompact(root, "raw", data, datalen); + break; + } + case jsfCardMemory: { + JsonSaveStr(root, "FileType", "mfcard"); + for (size_t i = 0; i < (datalen / 16); i++) { + char path[PATH_MAX_LENGTH] = {0}; + sprintf(path, "$.blocks.%zu", i); + JsonSaveBufAsHexCompact(root, path, &data[i * 16], 16); + + if (i == 0) { + JsonSaveBufAsHexCompact(root, "$.Card.UID", &data[0], 4); + JsonSaveBufAsHexCompact(root, "$.Card.SAK", &data[5], 1); + JsonSaveBufAsHexCompact(root, "$.Card.ATQA", &data[6], 2); + } + + if (mfIsSectorTrailer(i)) { + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.SectorKeys.%d.KeyA", mfSectorNum(i)); + JsonSaveBufAsHexCompact(root, path, &data[i * 16], 6); + + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.SectorKeys.%d.KeyB", mfSectorNum(i)); + JsonSaveBufAsHexCompact(root, path, &data[i * 16 + 10], 6); + + memset(path, 0x00, sizeof(path)); + uint8_t *adata = &data[i * 16 + 6]; + sprintf(path, "$.SectorKeys.%d.AccessConditions", mfSectorNum(i)); + JsonSaveBufAsHexCompact(root, path, &data[i * 16 + 6], 4); + + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 3); + JsonSaveStr(root, path, mfGetAccessConditionsDesc(0, adata)); + + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 2); + JsonSaveStr(root, path, mfGetAccessConditionsDesc(1, adata)); + + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i - 1); + JsonSaveStr(root, path, mfGetAccessConditionsDesc(2, adata)); + + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.block%zu", mfSectorNum(i), i); + JsonSaveStr(root, path, mfGetAccessConditionsDesc(3, adata)); + + memset(path, 0x00, sizeof(path)); + sprintf(path, "$.SectorKeys.%d.AccessConditionsText.UserData", mfSectorNum(i)); + JsonSaveBufAsHexCompact(root, path, &adata[3], 1); + } + } + break; + } + case jsfMfuMemory: { + JsonSaveStr(root, "FileType", "mfu"); + + mfu_dump_t *tmp = (mfu_dump_t *)data; + + uint8_t uid[7] = {0}; + memcpy(uid, tmp->data, 3); + memcpy(uid + 3, tmp->data + 4, 4); + + char path[PATH_MAX_LENGTH] = {0}; + + JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); + JsonSaveBufAsHexCompact(root, "$.Card.Version", tmp->version, sizeof(tmp->version)); + JsonSaveBufAsHexCompact(root, "$.Card.TBO_0", tmp->tbo, sizeof(tmp->tbo)); + JsonSaveBufAsHexCompact(root, "$.Card.TBO_1", tmp->tbo1, sizeof(tmp->tbo1)); + JsonSaveBufAsHexCompact(root, "$.Card.Signature", tmp->signature, sizeof(tmp->signature)); + for (uint8_t i = 0; i < 3; i ++) { + sprintf(path, "$.Card.Counter%d", i); + JsonSaveBufAsHexCompact(root, path, tmp->counter_tearing[i], 3); + sprintf(path, "$.Card.Tearing%d", i); + JsonSaveBufAsHexCompact(root, path, tmp->counter_tearing[i] + 3, 1); + } + + // size of header 56b + size_t len = (datalen - MFU_DUMP_PREFIX_LENGTH) / 4; + + for (size_t i = 0; i < len; i++) { + sprintf(path, "$.blocks.%zu", i); + JsonSaveBufAsHexCompact(root, path, tmp->data + (i * 4), 4); + } + break; + } + case jsfHitag: { + JsonSaveStr(root, "FileType", "hitag"); + uint8_t uid[4] = {0}; + memcpy(uid, data, 4); + + JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); + + for (size_t i = 0; i < (datalen / 4); i++) { + char path[PATH_MAX_LENGTH] = {0}; + sprintf(path, "$.blocks.%zu", i); + JsonSaveBufAsHexCompact(root, path, data + (i * 4), 4); + } + break; + } + } + + int res = json_dump_file(root, fileName, JSON_INDENT(2)); + if (res) { + PrintAndLogEx(FAILED, "error: can't save the file: " _YELLOW_("%s"), fileName); + json_decref(root); + retval = 200; + goto out; + } + PrintAndLogEx(SUCCESS, "saved to json file " _YELLOW_("%s"), fileName); + json_decref(root); + +out: + free(fileName); + return retval; +} + +int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen) { + + if (data == NULL) return 1; + char *fileName = filenamemcopy(preferredName, suffix); + if (fileName == NULL) return 1; + + int retval = PM3_SUCCESS; + + FILE *f = fopen(fileName, "rb"); + if (!f) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + free(fileName); + return PM3_EFILE; + } + + // get filesize in order to malloc memory + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + fseek(f, 0, SEEK_SET); + + if (fsize <= 0) { + PrintAndLogEx(FAILED, "error, when getting filesize"); + retval = 1; + goto out; + } + + uint8_t *dump = calloc(fsize, sizeof(uint8_t)); + if (!dump) { + PrintAndLogEx(FAILED, "error, cannot allocate memory"); + retval = 2; + goto out; + } + + size_t bytes_read = fread(dump, 1, fsize, f); + + if (bytes_read != fsize) { + PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); + free(dump); + retval = 3; + goto out; + } + + if (bytes_read > maxdatalen) { + PrintAndLogEx(WARNING, "Warning, bytes read exceed calling array limit. Max bytes is %d bytes", maxdatalen); + bytes_read = maxdatalen; + } + + memcpy((data), dump, bytes_read); + free(dump); + + PrintAndLogEx(SUCCESS, "loaded %d bytes from binary file " _YELLOW_("%s"), bytes_read, fileName); + + *datalen = bytes_read; + +out: + fclose(f); + free(fileName); + + return retval; +} + +int loadFileEML(const char *preferredName, void *data, size_t *datalen) { + + if (data == NULL) return 1; + char *fileName = filenamemcopy(preferredName, ".eml"); + if (fileName == NULL) return 1; + + size_t counter = 0; + int retval = PM3_SUCCESS, hexlen = 0; + + FILE *f = fopen(fileName, "r"); + if (!f) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + retval = PM3_EFILE; + goto out; + } + + // 128 + 2 newline chars + 1 null terminator + char line[131]; + memset(line, 0, sizeof(line)); + uint8_t buf[64] = {0x00}; + + while (!feof(f)) { + + memset(line, 0, sizeof(line)); + + if (fgets(line, sizeof(line), f) == NULL) { + if (feof(f)) + break; + fclose(f); + PrintAndLogEx(FAILED, "File reading error."); + retval = 2; + goto out; + } + + if (line[0] == '#') + continue; + + int res = param_gethex_to_eol(line, 0, buf, sizeof(buf), &hexlen); + if (res == 0 || res == 1) { + memcpy(data + counter, buf, hexlen); + counter += hexlen; + } + } + fclose(f); + PrintAndLogEx(SUCCESS, "loaded %d bytes from text file " _YELLOW_("%s"), counter, fileName); + + if (datalen) + *datalen = counter; + +out: + free(fileName); + return retval; +} + +int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen) { + + if (data == NULL) return 1; + char *fileName = filenamemcopy(preferredName, ".json"); + if (fileName == NULL) return 1; + + *datalen = 0; + json_t *root; + json_error_t error; + + int retval = PM3_SUCCESS; + + root = json_load_file(fileName, 0, &error); + if (!root) { + PrintAndLogEx(ERR, "ERROR: json " _YELLOW_("%s") " error on line %d: %s", fileName, error.line, error.text); + retval = 2; + goto out; + } + + if (!json_is_object(root)) { + PrintAndLogEx(ERR, "ERROR: Invalid json " _YELLOW_("%s") " format. root must be an object.", fileName); + retval = 3; + goto out; + } + + uint8_t *udata = (uint8_t *)data; + char ctype[100] = {0}; + JsonLoadStr(root, "$.FileType", ctype); + + if (!strcmp(ctype, "raw")) { + JsonLoadBufAsHex(root, "$.raw", udata, maxdatalen, datalen); + } + + if (!strcmp(ctype, "mfcard")) { + size_t sptr = 0; + for (int i = 0; i < 256; i++) { + if (sptr + 16 > maxdatalen) { + retval = 5; + goto out; + } + + char path[30] = {0}; + sprintf(path, "$.blocks.%d", i); + + size_t len = 0; + JsonLoadBufAsHex(root, path, &udata[sptr], 16, &len); + if (!len) + break; + + sptr += len; + } + + *datalen = sptr; + } + + if (!strcmp(ctype, "mfu")) { + size_t sptr = 0; + for (int i = 0; i < 256; i++) { + if (sptr + 4 > maxdatalen) { + retval = 5; + goto out; + } + + char path[30] = {0}; + sprintf(path, "$.blocks.%d", i); + + size_t len = 0; + JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len); + if (!len) + break; + + sptr += len; + } + + *datalen = sptr; + } + + if (!strcmp(ctype, "hitag")) { + size_t sptr = 0; + for (size_t i = 0; i < (maxdatalen / 4); i++) { + if (sptr + 4 > maxdatalen) { + retval = 5; + goto out; + } + + char path[30] = {0}; + sprintf(path, "$.blocks.%zu", i); + + size_t len = 0; + JsonLoadBufAsHex(root, path, &udata[sptr], 4, &len); + if (!len) + break; + + sptr += len; + } + + *datalen = sptr; + } + + PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName); +out: + json_decref(root); + free(fileName); + return retval; +} + +int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt) { + + + if (data == NULL) return 1; + char *fileName = filenamemcopy(preferredName, ".dic"); + if (fileName == NULL) return 1; + + // t5577 == 4bytes + // mifare == 6 bytes + // iclass == 8 bytes + // default to 6 bytes. + if (keylen != 4 && keylen != 6 && keylen != 8) { + keylen = 6; + } + + // double up since its chars + keylen <<= 1; + + char line[255]; + + size_t counter = 0; + int retval = PM3_SUCCESS; + + FILE *f = fopen(fileName, "r"); + if (!f) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + retval = PM3_EFILE; + goto out; + } + + // read file + while (fgets(line, sizeof(line), f)) { + + // add null terminator + line[keylen] = 0; + + // smaller keys than expected is skipped + if (strlen(line) < keylen) + continue; + + // The line start with # is comment, skip + if (line[0] == '#') + continue; + + if (!isxdigit(line[0])) { + PrintAndLogEx(FAILED, "file content error. '%s' must include " _BLUE_("%2d") "HEX symbols", line, keylen); + continue; + } + + uint64_t key = strtoull(line, NULL, 16); + + num_to_bytes(key, keylen >> 1, data + counter); + (*keycnt)++; + memset(line, 0, sizeof(line)); + counter += (keylen >> 1); + } + fclose(f); + PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, fileName); + + if (datalen) + *datalen = counter; +out: + free(fileName); + return retval; +} + +int convertOldMfuDump(uint8_t **dump, size_t *dumplen) { + if (!dump || !dumplen || *dumplen < OLD_MFU_DUMP_PREFIX_LENGTH) + return 1; + // try to check new file format + mfu_dump_t *mfu_dump = (mfu_dump_t *) *dump; + if ((*dumplen - MFU_DUMP_PREFIX_LENGTH) / 4 - 1 == mfu_dump->pages) + return 0; + // convert old format + old_mfu_dump_t *old_mfu_dump = (old_mfu_dump_t *) *dump; + + size_t old_data_len = *dumplen - OLD_MFU_DUMP_PREFIX_LENGTH; + size_t new_dump_len = old_data_len + MFU_DUMP_PREFIX_LENGTH; + + mfu_dump = (mfu_dump_t *) calloc(new_dump_len, sizeof(uint8_t)); + + memcpy(mfu_dump->version, old_mfu_dump->version, 8); + memcpy(mfu_dump->tbo, old_mfu_dump->tbo, 2); + mfu_dump->tbo1[0] = old_mfu_dump->tbo1[0]; + memcpy(mfu_dump->signature, old_mfu_dump->signature, 32); + for (int i = 0; i < 3; i++) + mfu_dump->counter_tearing[i][3] = old_mfu_dump->tearing[i]; + + memcpy(mfu_dump->data, old_mfu_dump->data, old_data_len); + mfu_dump->pages = old_data_len / 4 - 1; + // free old buffer, return new buffer + *dumplen = new_dump_len; + free(*dump); + *dump = (uint8_t *) mfu_dump; + PrintAndLogEx(SUCCESS, "old mfu dump format, was converted on load to " _GREEN_("%d") " pages", mfu_dump->pages + 1); + return PM3_SUCCESS; +} + + +#else //if we're on ARM + +#endif diff --git a/client/fileutils.h b/client/fileutils.h new file mode 100644 index 000000000..74d54000b --- /dev/null +++ b/client/fileutils.h @@ -0,0 +1,181 @@ +/***************************************************************************** + * WARNING + * + * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. + * + * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL + * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, + * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. + * + * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. + * + ***************************************************************************** + * + * This file is part of loclass. It is a reconstructon of the cipher engine + * used in iClass, and RFID techology. + * + * The implementation is based on the work performed by + * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and + * Milosch Meriac in the paper "Dismantling IClass". + * + * Copyright (C) 2014 Martin Holst Swende + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, or, at your option, any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with loclass. If not, see . + * + * + ****************************************************************************/ + +#ifndef FILEUTILS_H +#define FILEUTILS_H + +#ifndef ON_DEVICE + +#include +#include +#include +#include +#include +#include +#include "../ui.h" +#include "../emv/emvjson.h" +#include "mifare/mifare4.h" +#include "cmdhfmfu.h" + +typedef enum { + jsfRaw, + jsfCardMemory, + jsfMfuMemory, + jsfHitag, +// jsf14b, +// jsf15, +// jsfLegic, +// jsfT55xx, +} JSONFileType; + +int fileExists(const char *filename); + +/** + * @brief Utility function to save data to a binary file. This method takes a preferred name, but if that + * file already exists, it tries with another name until it finds something suitable. + * E.g. dumpdata-15.txt + * + * @param preferredName + * @param suffix the file suffix. Including the ".". + * @param data The binary data to write to the file + * @param datalen the length of the data + * @return 0 for ok, 1 for failz + */ +int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen); + +/** + * @brief Utility function to save data to a textfile (EML). This method takes a preferred name, but if that + * file already exists, it tries with another name until it finds something suitable. + * E.g. dumpdata-15.txt + * + * @param preferredName + * @param data The binary data to write to the file + * @param datalen the length of the data + * @param blocksize the length of one row + * @return 0 for ok, 1 for failz +*/ +int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize); + +/** STUB + * @brief Utility function to save JSON data to a file. This method takes a preferred name, but if that + * file already exists, it tries with another name until it finds something suitable. + * E.g. dumpdata-15.json + * + * @param preferredName + * @param ftype type of file. + * @param data The binary data to write to the file + * @param datalen the length of the data + * @return 0 for ok, 1 for failz + */ +int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen); + +/** STUB + * @brief Utility function to load data from a binary file. This method takes a preferred name. + * E.g. dumpdata-15.bin + * + * @param preferredName + * @param suffix the file suffix. Including the ".". + * @param data The data array to store the loaded bytes from file + * @param maxdatalen the number of bytes that your data array has + * @param datalen the number of bytes loaded from file + * @return 0 for ok, 1 for failz +*/ +int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen); + +/** + * @brief Utility function to load data from a textfile (EML). This method takes a preferred name. + * E.g. dumpdata-15.txt + * + * @param preferredName + * @param data The data array to store the loaded bytes from file + * @param datalen the number of bytes loaded from file + * @return 0 for ok, 1 for failz +*/ +int loadFileEML(const char *preferredName, void *data, size_t *datalen); + +/** + * @brief Utility function to load data from a JSON textfile. This method takes a preferred name. + * E.g. dumpdata-15.json + * + * @param preferredName + * @param data The data array to store the loaded bytes from file + * @param maxdatalen maximum size of data array in bytes + * @param datalen the number of bytes loaded from file + * @return 0 for ok, 1 for failz +*/ +int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen); + + +/** + * @brief Utility function to load data from a DICTIONARY textfile. This method takes a preferred name. + * E.g. default_keys.dic + * + * @param preferredName + * @param data The data array to store the loaded bytes from file + * @param maxdatalen maximum size of data array in bytes + * @param datalen the number of bytes loaded from file + * @param keylen the number of bytes a key per row is + * @return 0 for ok, 1 for failz +*/ +int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt); + +/** + * @brief Utility function to check and convert old mfu dump format to new + * + * @param dump pointer to loaded dump to check and convert format + * @param dumplen the number of bytes loaded dump and converted + * @return 0 for ok, 1 for fails +*/ +int convertOldMfuDump(uint8_t **dump, size_t *dumplen); + +#define PrintAndLogEx(level, format, args...) PrintAndLogEx(level, format , ## args) +#else + +/** +* Utility function to print to console. This is used consistently within the library instead +* of printf, but it actually only calls printf. The reason to have this method is to +*make it simple to plug this library into proxmark, which has this function already to +* write also to a logfile. When doing so, just point this function to use PrintAndLog +* @param fmt +*/ +#define PrintAndLogEx(level, format, args...) { } + + + +#endif //ON_DEVICE + +#endif // FILEUTILS_H From c69d599a3f7cca1eb86c00ef042e840b5a2a0a9d Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 21 Aug 2019 14:49:55 +0200 Subject: [PATCH 058/347] Update protocols.h From https://github.com/Proxmark/proxmark3/pull/855 (@pwpiwi) --- include/protocols.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/protocols.h b/include/protocols.h index 5a1e56f4e..cb38d9c84 100644 --- a/include/protocols.h +++ b/include/protocols.h @@ -542,5 +542,26 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. #define CALYPSO_SAM_SV_DEBIT 0x54 #define CALYPSO_SAM_SV_RELOAD 0x56 +// HITAG1 commands +#define HITAG1_SET_CCNEW 0xC2 // left 5 bits only +#define HITAG1_READ_ID 0x00 // not a real command, consists of 5 bits length, bits partial SN, 8 bits CRC +#define HITAG1_SELECT 0x00 // left 5 bits only, followed by 32 bits SN and 8 bits CRC +#define HITAG1_WRPPAGE 0x80 // left 4 bits only, followed by 8 bits page and 8 bits CRC +#define HITAG1_WRPBLK 0x90 // left 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_WRCPAGE 0xA0 // left 4 bits only, followed by 8 bits page or key information and 8 bits CRC +#define HITAG1_WRCBLK 0xB0 // left 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_RDPPAGE 0xC0 // left 4 bits only, followed by 8 bits page and 8 bits CRC +#define HITAG1_RDPBLK 0xD0 // left 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_RDCPAGE 0xE0 // left 4 bits only, followed by 8 bits page and 8 bits CRC +#define HITAG1_RDCBLK 0xF0 // left 4 bits only, followed by 8 bits block and 8 bits CRC +#define HITAG1_HALT 0x70 // left 4 bits only, followed by 8 bits (dummy) page and 8 bits CRC + +// HITAG2 commands +#define HITAG2_START_AUTH 0xC0 // left 5 bits only +#define HITAG2_READ_PAGE 0xC0 // page number in bits 5 to 3, page number inverted in bit 0 and following 2 bits +#define HITAG2_READ_PAGE_INVERTED 0x44 // page number in bits 5 to 3, page number inverted in bit 0 and following 2 bits +#define HITAG2_WRITE_PAGE 0x82 // page number in bits 5 to 3, page number inverted in bit 0 and following 2 bits +#define HITAG2_HALT 0x00 // left 5 bits only + #endif // PROTOCOLS_H From 3cf64f9f23712830fbeaef2028ca46b9224f1030 Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 21 Aug 2019 16:49:32 +0200 Subject: [PATCH 059/347] fix: some mkdir stuff.. --- Makefile.host | 2 +- fpga/tests/Makefile | 4 ++-- tools/Makefile | 21 +++++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Makefile.host b/Makefile.host index 9ab7ce8ca..e2d3b3f6f 100644 --- a/Makefile.host +++ b/Makefile.host @@ -9,7 +9,7 @@ LD = gcc RM = rm -f MV = mv CP = cp -a -MKDIR = mkdir +MKDIR = mkdir -p CFLAGS ?= -Wall -Werror -O3 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES) diff --git a/fpga/tests/Makefile b/fpga/tests/Makefile index 79ed20816..f2ae6d729 100644 --- a/fpga/tests/Makefile +++ b/fpga/tests/Makefile @@ -5,7 +5,7 @@ # at your option, any later version. See the LICENSE.txt file for the text of # the license. #----------------------------------------------------------------------------- - +MKDIR = mkdir -p TEST_OUTDIR = tb_tmp TB_SOURCES = \ @@ -62,7 +62,7 @@ tb_lf_edge_detect: tb_lf_edge_detect.vvp | test_dir rm -f $(TEST_OUTDIR)/data.* test_dir: - @if [ ! -d $(TEST_OUTDIR) ] ; then mkdir $(TEST_OUTDIR) ; fi + @if [ ! -d $(TEST_OUTDIR) ] ; then $(MKDIR) $(TEST_OUTDIR) ; fi .PHONY: all clean diff --git a/tools/Makefile b/tools/Makefile index 3b1dc1b0f..5f2355f20 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,18 +1,23 @@ +MKDIR = mkdir -p +WGET = wget -N +TAR = tar Jxvf +GIT = git clone + get_craptev1: - wget -N http://crapto1.netgarage.org/craptev1-v1.1.tar.xz - tar Jxvf craptev1-v1.1.tar.xz -C craptev1-v1.1 + $(WGET) http://crapto1.netgarage.org/craptev1-v1.1.tar.xz + $(TAR) craptev1-v1.1.tar.xz -C craptev1-v1.1 get_crapto1: - wget -N http://crapto1.netgarage.org/crapto1-v3.3.tar.xz - tar Jxvf crapto1-v3.3.tar.xz -C crapto1-v3.3 + $(WGET) http://crapto1.netgarage.org/crapto1-v3.3.tar.xz + $(TAR) Jxvf crapto1-v3.3.tar.xz -C crapto1-v3.3 get_nonce_bf: -# git clone https://github.com/J-Run/mf_key_brute.git mf_key_brute - git clone https://github.com/iceman1001/mf_nonce_brute mf_nonce_brute +# $(GIT) https://github.com/J-Run/mf_key_brute.git mf_key_brute + $(GIT) https://github.com/iceman1001/mf_nonce_brute mf_nonce_brute get_xorsearch: - mkdir xorsearch - wget -N https://didierstevens.com/files/software/XORSearch_V1_11_2.zip + $(MKDIR) xorsearch + $(WGET) https://didierstevens.com/files/software/XORSearch_V1_11_2.zip # Mingw # unzzip-big XORSearch_V1_11_2.zip # linux From da313732587fbed698b88022d6d08967be310487 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 21 Aug 2019 20:06:14 +0200 Subject: [PATCH 060/347] non-rdv4 PLATFORM must now use the generic PM3OTHER, simpler --- CHANGELOG.md | 1 + common_arm/Makefile.hal | 69 +++++-------------- .../4_Advanced-compilation-parameters.md | 18 ++--- 3 files changed, 25 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5f7d8d76..b8d19d065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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... ## [unreleased][unreleased] + - Change non-rdv4 PLATFORM must now use the generic PM3OTHER, simpler (@doegox) - Fix reveng integration for all platforms else than WIN32 (@doegox) - Add cheat sheet for easy operations of the Proxmark3 (scund00r) - Chg commands are now in green in the helptext list (@iceman1001) diff --git a/common_arm/Makefile.hal b/common_arm/Makefile.hal index 411744037..22ae385c3 100644 --- a/common_arm/Makefile.hal +++ b/common_arm/Makefile.hal @@ -14,41 +14,29 @@ define KNOWN_PLATFORM_DEFINITIONS Known definitions: -+==========================================================+ -| PLATFORM | DESCRIPTION | -+==========================================================+ -| PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | -+----------------------------------------------------------+ -| PM3EVO | Proxmark3 EVO with AT91SAM7S512 | -+----------------------------------------------------------+ -| PM3V40 | Proxmark3 V4.0 with AT91SAM7S512 | -+----------------------------------------------------------+ -| PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | -+----------------------------------------------------------+ -| PM3EASY512 | Proxmark3 rdv3 Easy with AT91SAM7S512 | -+----------------------------------------------------------+ -| PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 | -+----------------------------------------------------------+ -| PM3OLD256 | Proxmark3 V1 with AT91SAM7S256 | -+----------------------------------------------------------+ -| PM3OLD512 | Proxmark3 V1 with AT91SAM7S512 | -+----------------------------------------------------------+ ++============================================+ +| PLATFORM | DESCRIPTION | ++============================================+ +| PM3RDV4 (def) | Proxmark3 rdv4 | ++--------------------------------------------+ +| PM3OTHER | Proxmark3 Generic target | ++--------------------------------------------+ -+==========================================================+ -| PLATFORM_EXTRAS | DESCRIPTION | -+==========================================================+ -| BTADDON | Proxmark3 rdv4 BT add-on | -+----------------------------------------------------------+ ++============================================+ +| PLATFORM_EXTRAS | DESCRIPTION | ++============================================+ +| BTADDON | Proxmark3 rdv4 BT add-on | ++--------------------------------------------+ endef define HELP_DEFINITIONS Options to define platform, platform extras and/or standalone mode: -(1) Run make with PLATFORM, PLATFORM_EXTRAS and/or STANDALONE as follows: -make PLATFORM=PM3EASY STANDALONE=$(HELP_EXAMPLE_STANDALONE) +(1) Run make with your PLATFORM, PLATFORM_EXTRAS and/or STANDALONE choices as follows: +make PLATFORM=PM3OTHER STANDALONE=$(HELP_EXAMPLE_STANDALONE) -(2) Save a file called Makefile.platform with contents: -PLATFORM=PM3EASY +(2) Save a file called Makefile.platform with contents, e.g.: +PLATFORM=PM3OTHER or if you have a Proxmark 3 RDV4 with the BT add-on: PLATFORM=PM3RDV4 @@ -68,30 +56,10 @@ endef PLTNAME = Unknown Platform ifeq ($(PLATFORM),PM3RDV4) - MCU = AT91SAM7S512 PLATFORM_DEFS = -DWITH_SMARTCARD -DWITH_FLASH PLTNAME = Proxmark3 rdv4 -else ifeq ($(PLATFORM),PM3EVO) - MCU = AT91SAM7S512 - PLTNAME = Proxmark3 EVO -else ifeq ($(PLATFORM),PM3V40) - MCU = AT91SAM7S512 - PLTNAME = Proxmark3 V4.0 -else ifeq ($(PLATFORM),PM3EASY) - MCU = AT91SAM7S256 - PLTNAME = Proxmark3 rdv3 Easy -else ifeq ($(PLATFORM),PM3EASY512) - MCU = AT91SAM7S512 - PLTNAME = Proxmark3 rdv3 Easy 512 -else ifeq ($(PLATFORM),PM3RDV2) - MCU = AT91SAM7S512 - PLTNAME = Proxmark3 rdv2 -else ifeq ($(PLATFORM),PM3OLD256) - MCU = AT91SAM7S256 - PLTNAME = Proxmark3 V1 with AT91SAM7S256 -else ifeq ($(PLATFORM),PM3OLD512) - MCU = AT91SAM7S512 - PLTNAME = Proxmark3 V1 with AT91SAM7S512 +else ifeq ($(PLATFORM),PM3OTHER) + PLTNAME = Proxmark3 Generic target else $(error Invalid or empty PLATFORM: $(PLATFORM). $(KNOWN_DEFINITIONS)) endif @@ -178,7 +146,6 @@ export PLATFORM export PLATFORM_EXTRAS export PLATFORM_EXTRAS_INFO export PLTNAME -export MCU export PLATFORM_DEFS export PLATFORM_DEFS_INFO export PLATFORM_DEFS_INFO_STANDALONE diff --git a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md index 270682696..b4fb4384a 100644 --- a/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md +++ b/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md @@ -19,7 +19,7 @@ These features make it very different from all other devices, there is non other **Recommendation**: if you don't have a RDV4, we strongly recommend your device to have at least a 512kb arm chip, since this repo is on the very edge of 256kb limit. -A firmware built for the RDV4 can still run on the other platforms as it will auto-detect during boot that external SPI and Sim are not present, still it will boot faster if it's tuned to the platform. +A firmware built for the RDV4 can still run on the other platforms as it will auto-detect during boot that external SPI and Sim are not present, still it will boot faster if it's tuned to the platform, which solves USB enumeration issues on some OSes. If you need to tune things and save the configuration, create a file `Makefile.platform` in the root directory of the repository, see `Makefile.platform.sample`. For an up-to-date exhaustive list of options, you can run `make PLATFORM=`. @@ -28,20 +28,14 @@ For an up-to-date exhaustive list of options, you can run `make PLATFORM=`. Here are the supported values you can assign to `PLATFORM` in `Makefile.platform`: -| PLATFORM | DESCRIPTION | -|-----------------|----------------------------------------| -| PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | -| PM3EVO | Proxmark3 EVO with AT91SAM7S512 | -| PM3V40 | Proxmark3 V4.0 with AT91SAM7S512 | -| PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | -| PM3EASY512 | Proxmark3 rdv3 Easy with AT91SAM7S512 | -| PM3RDV2 | Proxmark3 rdv2 with AT91SAM7S512 | -| PM3OLD256 | Proxmark3 V1 with AT91SAM7S256 | -| PM3OLD512 | Proxmark3 V1 with AT91SAM7S512 | +| PLATFORM | DESCRIPTION | +|-----------------|--------------------------| +| PM3RDV4 (def) | Proxmark3 rdv4 | +| PM3OTHER | Proxmark3 generic target | By default `PLATFORM=PM3RDV4`. -Note that besides `PM3RDV4` and its unique features, all other platforms are equivalent and the MCU version (256 or 512) will be detected automatically during flashing. +The MCU version (256 or 512) will be detected automatically during flashing. Known issues: From a95a962651b5dfef5a0692c988af4a45ae34f0bf Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 20 Aug 2019 21:30:43 +0200 Subject: [PATCH 061/347] OSX instructions: developer mode --- ...OS-X-Homebrew-Installation-Instructions.md | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 34b9c3aa5..22868121c 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -1,4 +1,7 @@ -# Homebrew (Mac OS X) +# Homebrew (Mac OS X), automatic installation + +## Install Proxmark3 tools + These instructions comes from @Chrisfu, where we got the proxmark3.rb scriptfile from. For further questions about Mac & Homebrew, contact @Chrisfu (https://github.com/chrisfu/) @@ -8,7 +11,7 @@ For further questions about Mac & Homebrew, contact @Chrisfu (https://github.c 3. Install Proxmark3: `brew install proxmark3` for stable release or `brew install --HEAD proxmark3` for latest non-stable from GitHub. -## Upgrading HomeBrew tap formula +## Upgrade HomeBrew tap formula *This method is useful for those looking to run bleeding-edge versions of RRG/iceman's client. Keep this in mind when attempting to update your HomeBrew tap formula as this procedure could easily cause a build to break if an update is unstable on macOS.* @@ -24,7 +27,7 @@ brew upgrade --fetch-HEAD proxmark3 ## Flash the BOOTROM & FULLIMAGE -With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark3 as you plug it into a USB port. Continue to hold the button until after this step is complete and the `proxmark3-flasher` command outputs "Have a nice day!" +With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark3 as you plug it into a USB port. You can release the button, two of the four LEDs should stay on. You're un bootloader mode, ready for the next step. In case the two LEDs don't stay on when you're releasing the button, you've an old bootloader, start over and keep the button pressed during the whole flashing procedure. ```sh sudo proxmark3-flasher /dev/tty.usbmodemiceman1 -b /usr/local/Cellar/proxmark3/HEAD-/share/firmware/bootrom.elf /usr/local/Cellar/proxmark3/HEAD-/share/firmware/fullimage.elf @@ -50,3 +53,55 @@ For the next steps, please read the following pages: * [Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| + + +# Homebrew (Mac OS X), developer installation + +These instructions will show how to setup the environment on OSX to the point where you'll be able to clone and compile the repo by yourself, as on Linux, Windows, etc. + +1. Install homebrew if you haven't yet already done so: http://brew.sh/ + +2. Install dependencies: + +``` +brew install readline +brew install p7zip +brew install libusb-compat +brew install perl +brew install qt5 +brew install wget +brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc +``` + +## Compile and use the project + +Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). + +To use the compiled client and flasher, the only difference is that the Proxmark3 port is `/dev/tty.usbmodemiceman1`. + +To flash: With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark3 as you plug it into a USB port. You can release the button, two of the four LEDs should stay on. You're un bootloader mode, ready for the next step. In case the two LEDs don't stay on when you're releasing the button, you've an old bootloader, start over and keep the button pressed during the whole flashing procedure. + +In principle, the helper script `flash-all.sh` should auto-detect your port, so you can just try: + +```sh +./flash-all.sh +``` + +If port detection failed, you'll have to call the flasher manually and specify the correct port: + +```sh +client/flasher /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +``` + +Similarly, to run the client, you may try: + +```sh +./proxmark3.sh +``` + +Or, by specifying the port manually: + +```sh +client/proxmark3 /dev/tty.usbmodemiceman1 +``` + From e4222968555c426349a908d174b8dcf5db8e7345 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 21 Aug 2019 20:38:56 +0200 Subject: [PATCH 062/347] removed install.sh, better to stick to the install docs --- install.sh | 68 ------------------------------------------------------ 1 file changed, 68 deletions(-) delete mode 100755 install.sh diff --git a/install.sh b/install.sh deleted file mode 100755 index 8dc3e5317..000000000 --- a/install.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -set -x -# This is for linux ppl and it works on Ubuntu distros. Don't know about Kali. -function installProxmark_Linux { - # install dependencies for Proxmark3 source code. - sudo apt-get install p7zip git build-essential libreadline5 libreadline-dev gcc-arm-none-eabi - sudo apt-get install libusb-0.1-4 libusb-dev libqt4-dev libncurses5-dev perl pkg-config wget - #cleaning up - sudo apt-get install -f -y - sudo apt-get autoremove -y - sudo apt-get autoclean -y - sudo apt-get clean -y - sudo apt-get update - - # Install libcanberragtk in Ubuntu 18.04 - if [[ $(cat /etc/issue | awk '{print $2}') = *"18.04"* ]]; then - apt-get install libcanberra-gtk-module - fi - -# install RDV40 - proxmark3 - git clone https://github.com/RfidResearchGroup/proxmark3.git . - ( - cd proxmark3 || exit 1 - git reset --hard - git clean -dfx - make clean - make -j$(nproc) all - # Copy blacklist rules into /etc/udev/rules.d - # check the Makefile for details - sudo make udev - ) -} -function installProxmark_macOS { - # Install dependencies for Proxmark3 source code. - brew tap nitsky/stm32 - brew install readline libusb p7zip libusb-compat wget qt5 pkgconfig arm-none-eabi-gcc - brew link --force readline - # add moc_location in Qt5Core.pc file. -local qtDir=$(ls /usr/local/Cellar/qt/ 2>/dev/null | head -1) -local qt5Core=$(find /usr -name Qt5Core.pc 2>/dev/null) - ( - export PKG_CONFIG_PATH=/usr/local/Cellar/qt/$qtDir/lib/pkgconfig/ - export QT_PKG_CONFIG_QT5CORE=$qt5Core - chmod 666 $QT_PKG_CONFIG_QT5CORE - echo "moc_location=\${prefix}/bin/moc" >> $QT_PKG_CONFIG_QT5CORE - chmod 444 $QT_PKG_CONFIG_QT5CORE - ) - # install RDV40 - proxmark3 - git clone https://github.com/RfidResearchGroup/proxmark3.git - ( - cd proxmark3 || exit 1 - git reset --hard - git clean -dfx - make clean - make -j$(sysctl -n hw.physicalcpu) - ) - } -# Where is my device? -#dmesg | tail -10 -# Detect OS and install libraries and proxmark3 client -if [[ $(uname | awk '{print toupper($0)}') == "LINUX" ]]; then - echo >&2 "Linux Detected - Updating your system..." - $(installProxmark_Linux) -elif [[ $(uname | awk '{print toupper($0)}') == "DARWIN" ]]; then - echo >&2 "MAC OS X Detected - Updating your system..." - $(installProxmark_macOS) 2>/dev/null -fi -echo >&2 "Done." From 1e97acdf5e8ec5c1c903d88c2037c189ebc9bbe4 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 21 Aug 2019 21:39:21 +0200 Subject: [PATCH 063/347] remove old arm toolchain installation script --- tools/install-gnuarm4.sh | 277 --------------------------------------- 1 file changed, 277 deletions(-) delete mode 100755 tools/install-gnuarm4.sh diff --git a/tools/install-gnuarm4.sh b/tools/install-gnuarm4.sh deleted file mode 100755 index a5d92c5d5..000000000 --- a/tools/install-gnuarm4.sh +++ /dev/null @@ -1,277 +0,0 @@ -#!/bin/bash - -# Some things for you to configure -BINUTILS_VER="2.19.1a" -GCC_VER="4.3.3" -GDB_VER="6.8a" -NEWLIB_VER="1.17.0" -GMP_VER="4.2.4" -MPFR_VER="2.4.2" -INSIGHT_VER="6.8a" - -# Where you want to install the tools -if [ "${1}" = "" ]; then - echo "Syntax: ${0} [download & build directory (default ${PWD})]" - exit 1 -else - DESTDIR="${1}" -fi - -# Where do you want to build the tools. This is where the log files -# will be written (which you can monitor with 'tail' during compilation). -# You can delete this directory after everything is done. -if [ ! "${2}" = "" ]; then - SRCDIR="${2}" -else - SRCDIR="${PWD}" -fi -BUILDDIR=${SRCDIR}/build-gnuarm4 - -# Where to get each of the toolchain components -BINUTILS=http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.bz2 -BINUTILS_TAR=binutils-${BINUTILS_VER}.tar.bz2 -GCCCORE=http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-core-${GCC_VER}.tar.bz2 -GCCCORE_TAR=gcc-core-${GCC_VER}.tar.bz2 -GPP=http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-g++-${GCC_VER}.tar.bz2 -GPP_TAR=gcc-g++-${GCC_VER}.tar.bz2 -NEWLIB=ftp://sources.redhat.com/pub/newlib/newlib-${NEWLIB_VER}.tar.gz -NEWLIB_TAR=newlib-${NEWLIB_VER}.tar.gz -#INSIGHT=ftp://sourceware.org/pub/insight/releases/insight-${INSIGHT_VER}.tar.bz2 -INSIGHT=http://mirrors.kernel.org/sources.redhat.com/insight/releases/insight-${INSIGHT_VER}.tar.bz2 -INSIGHT_TAR=insight-${INSIGHT_VER}.tar.bz2 -#INSIGHT=http://www.mirrorservice.org/sites/sources.redhat.com/pub/insight/releases/insight-${INSIGHT_VER}.tar.bz2 -GDB=http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VER}.tar.bz2 -GDB_TAR=gdb-${GDB_VER}.tar.bz2 -GMP=http://ftp.sunet.se/pub/gnu/gmp/gmp-${GMP_VER}.tar.bz2 -GMP_TAR=gmp-${GMP_VER}.tar.bz2 -MPFR=http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VER}.tar.bz2 -MPFR_TAR=mpfr-${MPFR_VER}.tar.bz2 -GNU_KEYRING_GPG=gnu-keyring.gpg -GNU_KEYRING=ftp://ftp.gnu.org/gnu/${GNU_KEYRING_GPG} - -# Common configuration options (i.e., things to pass to 'configure') -COMMON_CFG="--enable-interwork --target=arm-eabi --program-prefix=arm-none-eabi- --prefix=${DESTDIR} --disable-werror --enable-languages=c,c++ --enable-multilib --disable-shared" - -# Extra configuration options for each toolchain component -BINUTILS_CFG= -GCCCORE_CFG="--disable-nls --disable-threads --with-gcc --with-gnu-ld --with-gnu-as --with-dwarf2 --with-newlib --with-headers=${BUILDDIR}/newlib-${NEWLIB_VER}/newlib/libc/include --disable-libssp --disable-libstdcxx-pch --disable-libmudflap --disable-libgomp -v" -NEWLIB_CFG= -INSIGHT_CFG= -GDB_CFG= - -# Make flags -MAKEFLAGS="-j 4" - -# wget options -# -nv: non-verbose but not too quiet (still print errors/warnings) -# -nc: no-clobber, do not download a file that already exists -# -t 0: retry indefinitely -# -a wget.log: append errors/warnings to wget.log file -# -c continue -#WGET_OPTS="-nv -nc -t 0 -a wget.log" -WGET_OPTS="-c -t 0" - -# Compiler flags for compiling Newlib (-O2 is already hard-coded) -NEWLIB_FLAGS="-march=armv4t -mcpu=arm7tdmi -g" - -# GPG options to avoid polluting the user's keyring -GPG_OPTS="--keyring ${GNU_KEYRING_GPG} --no-default-keyring --homedir ." - -############################################################################ -# End of configuration section. You shouldn't have to modify anything below. -############################################################################ - -if [[ "$USER" != "root" ]]; then - echo "*** Warning! Not running as root!" - echo "Installation may fail if you do not have appropriate permissions!" -fi - -mkdir -p ${BUILDDIR} -cd ${SRCDIR} - -if [[ -f all.downloaded ]]; then - echo Looks like all downloads are complete, skipping downloads -else - wget ${WGET_OPTS} ${GNU_KEYRING} - - # TODO: guess it's better to have a function that "downloads, checks file-presence and signature, and returns true/false" whether the file is ok - # Function will check if file exists (otherwise try to download the file - if failed and file still doesn't exist, complain and exit the script) - # Check if signature file exists (otherwise download the signature file as well - if download fail, warn the user and return function) - # Check the signature. If failed, backup-by-renaming current files, redownload both file & signature, run the function body one more time - if still no success, warn and return from function - - function download_lib { - echo Now downloading $1 - wget ${WGET_OPTS} $2 - } - - function download_signed_lib { - download_lib $1 $2 - wget -N ${WGET_OPTS} $2.sig - gpg $GPG_OPTS --verify $3.sig 2> /dev/null - if [[ $? != 0 ]]; then - echo "Failed signature check for:" $3.sig - exit 1 - fi - } - - # NOTE: If new downloads are added here, please see the IMPORTANT note below - download_signed_lib BINUTILS ${BINUTILS} ${BINUTILS_TAR} || exit 1 - download_signed_lib GCC ${GCCCORE} ${GCCCORE_TAR} || exit 1 - download_signed_lib G++ ${GPP} ${GPP_TAR} || exit 1 - download_lib NEWLIB ${NEWLIB} - # TODO: signature/hash check - download_lib INSIGHT ${INSIGHT} - # TODO: signature/hash check - download_signed_lib GDB ${GDB} ${GDB_TAR} || exit 1 - download_signed_lib GMP ${GMP} ${GMP_TAR} || exit 1 - download_signed_lib MPFR ${MPFR} ${MPFR_TAR} || exit 1 - - # IMPORTANT: Here is the number of .tar. archives downloaded above. Please update if new .tar. are added to download list. - if [[ `ls -1 *.tar.bz2 *.tar.gz | wc -l` != 8 ]]; then - echo "Seems like not all prerequisite files downloaded... Exiting." - exit 1 - else - touch all.downloaded - fi -fi - -cd ${BUILDDIR} -if [[ -f binutils.built ]]; then - echo Looks like BINUTILS was already built. -else - echo Building BINUTILS... - tar -xjf ../`basename ${BINUTILS}` - echo ___________________ > make.log - echo Building binutils... >> make.log - cd `find . -maxdepth 1 -type d -name 'binutils*'` - mkdir gnuarm - cd gnuarm - ../configure ${COMMON_CFG} ${BINUTILS_CFG} >> ../../make.log 2>&1 - make ${MAKEFLAGS} MAKEINFO=`which makeinfo` >> ../../make.log 2>&1 - make install >> ../../make.log 2>&1 - cd ../.. - touch binutils.built -fi - - echo ___________________ >> make.log - echo Adding ${DESTDIR}/bin to PATH >> make.log -export PATH; PATH=${DESTDIR}/bin:$PATH - echo ___________________ >> make.log - -if [[ -f gcc.built ]]; then - echo Looks like GCC was already built. -else - echo Building GCC... - tar -xjf ../`basename ${GCCCORE}` - tar -xjf ../`basename ${GPP}` - tar -xjf ../`basename ${GMP}` - ln -s "${BUILDDIR}/gmp-${GMP_VER}" "${BUILDDIR}/gcc-${GCC_VER}/gmp" - tar -xjf ../`basename ${MPFR}` - ln -s "${BUILDDIR}/mpfr-${MPFR_VER}" "${BUILDDIR}/gcc-${GCC_VER}/mpfr" - tar -xzf ../`basename ${NEWLIB}` - - echo ___________________ >> make.log - -cat << EOF > gcc.patch ---- gcc-4.3.3.orig/gcc/config/arm/t-arm-elf -+++ gcc-4.3.3.mod/gcc/config/arm/t-arm-elf -@@ -33,8 +33,8 @@ - # MULTILIB_DIRNAMES += fpu soft - # MULTILIB_EXCEPTIONS += *mthumb/*mhard-float* - # --# MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork --# MULTILIB_DIRNAMES += normal interwork -+MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork -+MULTILIB_DIRNAMES += normal interwork - # - # MULTILIB_OPTIONS += fno-leading-underscore/fleading-underscore - # MULTILIB_DIRNAMES += elf under -EOF - - echo Patching GCC >> make.log - cd `find . -maxdepth 1 -type d -name 'gcc*'` - patch -p1 < ../gcc.patch - echo Building gcc... >> make.log - mkdir gnuarm - cd gnuarm - ../configure ${COMMON_CFG} ${GCCCORE_CFG} >> ../../make.log 2>&1 - make ${MAKEFLAGS} all-gcc >> ../../make.log 2>&1 - make install >> ../../make.log 2>&1 - cd ../.. - touch gcc.built -fi - -if [[ -f newlib.built ]]; then - echo Looks like NEWLIB was already built. -else - echo Building NEWLIB... - echo ___________________ >> make.log - echo Building newlib... >> make.log - cd `find . -maxdepth 1 -type d -name 'newlib*'` - mkdir gnuarm - cd gnuarm - ../configure ${COMMON_CFG} ${NEWLIB_CFG} >> ../../make.log 2>&1 - - # This line adds our NEWLIB_CFLAGS to the configure.host file in the - # newlib subdirectory. This is the only way I could find to tell Newlib to - # compile itself with the -mmarch=armv4t and -mcpu=arm7tdmi flags. -# sed -i "/^newlib_cflags=/s/=.*\$/=\"${NEWLIB_FLAGS}\"/" ../newlib/configure.host - make ${MAKEFLAGS} >> ../../make.log 2>&1 - make install >> ../../make.log 2>&1 - cd ../.. - touch newlib.built -fi - - echo ___________________ >> make.log - echo "Now that newlib is built, second pass for GCC..." >> make.log - cd `find . -maxdepth 1 -type d -name 'gcc*'` - cd gnuarm - make ${MAKEFLAGS} >> ../../make.log 2>&1 - make install >> ../../make.log 2>&1 - cd ../.. - - -if [[ -f insight.built ]]; then - echo Looks like INSIGHT was already built. -else - echo Building INSIGHT... - tar -xjf ../`basename ${INSIGHT}` - echo ___________________ >> make.log - echo Building insight... >> make.log - cd `find . -maxdepth 1 -type d -name 'insight*'` - mkdir gnuarm - cd gnuarm - ../configure ${COMMON_CFG} ${INSIGHT_CFG} >> ../../make.log 2>&1 - make ${MAKEFLAGS} >> ../../make.log 2>&1 - make install >> ../../make.log 2>&1 - cd ../.. - touch insight.built -fi - -if [[ -f gdb.built ]]; then - echo Looks like GDB was already built. -else - echo Building GDB... - tar -xjf ../`basename ${GDB}` - echo ___________________ >> make.log - echo Building insight... >> make.log - cd `find . -maxdepth 1 -type d -name 'gdb*'` - mkdir gnuarm - cd gnuarm - ../configure ${COMMON_CFG} ${GDB_CFG} >> ../../make.log 2>&1 - make ${MAKEFLAGS} >> ../../make.log 2>&1 - make install >> ../../make.log 2>&1 - cd ../.. - touch gdb.built -fi - -echo ___________________ >> make.log -echo Build complete. >> make.log - -cd ${DESTDIR} -chmod -R a+rX . - -echo Downloaded archives are in ${SRCDIR} -echo build driectory: ${BUILDDIR} -echo set environment variable ARMLIB to ${DESTDIR}/lib/gcc/arm-eabi/4.3.3/interwork for Makefile.linux -exit 0 From fb006909576ea4ad6f25cc326623e4c6aba50d82 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 21 Aug 2019 22:44:28 +0200 Subject: [PATCH 064/347] rename and +x few eml helper scripts --- client/{eml2lower.sh => pm3_eml2lower.sh} | 2 +- client/{eml2UPPER.sh => pm3_eml2upper.sh} | 2 +- client/pm3_mfdread.py | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename client/{eml2lower.sh => pm3_eml2lower.sh} (97%) mode change 100644 => 100755 rename client/{eml2UPPER.sh => pm3_eml2upper.sh} (97%) mode change 100644 => 100755 mode change 100644 => 100755 client/pm3_mfdread.py diff --git a/client/eml2lower.sh b/client/pm3_eml2lower.sh old mode 100644 new mode 100755 similarity index 97% rename from client/eml2lower.sh rename to client/pm3_eml2lower.sh index ddb3354db..086439c3c --- a/client/eml2lower.sh +++ b/client/pm3_eml2lower.sh @@ -1,7 +1,7 @@ #!/bin/bash # Andrei Costin , 2011 -# eml2lower.sh +# pm3_eml2lower.sh # Converts PM3 Mifare Classic emulator EML file to lower case (for easier comparison in some text-comparison tools) # http://www.linuxquestions.org/questions/programming-9/bash-script-parsing-optional-parameters-621728/ diff --git a/client/eml2UPPER.sh b/client/pm3_eml2upper.sh old mode 100644 new mode 100755 similarity index 97% rename from client/eml2UPPER.sh rename to client/pm3_eml2upper.sh index a28ae22a0..73b8646b7 --- a/client/eml2UPPER.sh +++ b/client/pm3_eml2upper.sh @@ -1,7 +1,7 @@ #!/bin/bash # Andrei Costin , 2011 -# eml2UPPER.sh +# pm3_eml2upper.sh # Converts PM3 Mifare Classic emulator EML file to UPPER case (for easier comparison in some text-comparison tools) # http://www.linuxquestions.org/questions/programming-9/bash-script-parsing-optional-parameters-621728/ diff --git a/client/pm3_mfdread.py b/client/pm3_mfdread.py old mode 100644 new mode 100755 From a8ee33baf4138141e76645cfe95c25d0698595f6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 21 Aug 2019 23:17:01 +0200 Subject: [PATCH 065/347] change scripts/ to luascripts/ --- appveyor.yml | 4 ++-- client/cmdhfmfp.c | 2 +- client/cmdscript.c | 4 ++-- client/{scripts => luascripts}/14araw.lua | 0 client/{scripts => luascripts}/Legic_clone.lua | 0 client/{scripts => luascripts}/amiibo.lua | 0 client/{scripts => luascripts}/brutesim.lua | 0 client/{scripts => luascripts}/calc_di.lua | 0 client/{scripts => luascripts}/calc_ev1_it.lua | 0 client/{scripts => luascripts}/calc_mizip.lua | 0 client/{scripts => luascripts}/calypso.lua | 0 client/{scripts => luascripts}/cmdline.lua | 0 client/{scripts => luascripts}/didump.lua | 0 client/{scripts => luascripts}/dumptoemul-mfu.lua | 0 client/{scripts => luascripts}/dumptoemul.lua | 0 client/{scripts => luascripts}/e.lua | 0 client/{scripts => luascripts}/emul2dump.lua | 0 client/{scripts => luascripts}/emul2html.lua | 0 client/{scripts => luascripts}/formatMifare.lua | 0 client/{scripts => luascripts}/hf_read.lua | 0 client/{scripts => luascripts}/htmldump.lua | 0 client/{scripts => luascripts}/iso15_magic.lua | 0 client/{scripts => luascripts}/legic.lua | 0 client/{scripts => luascripts}/legic_buffer2card.lua | 0 client/{scripts => luascripts}/lf_bulk.lua | 0 client/{scripts => luascripts}/mfkeys.lua | 0 client/{scripts => luascripts}/mifare_access.lua | 0 client/{scripts => luascripts}/mifare_autopwn.lua | 0 client/{scripts => luascripts}/mifareplus.lua | 0 client/{scripts => luascripts}/ndef_dump.lua | 0 client/{scripts => luascripts}/ntag_3d.lua | 2 +- client/{scripts => luascripts}/parameters.lua | 0 client/{scripts => luascripts}/read_pwd_mem.lua | 0 client/{scripts => luascripts}/remagic.lua | 0 client/{scripts => luascripts}/test_t55x7.lua | 0 client/{scripts => luascripts}/test_t55x7_ask.lua | 0 client/{scripts => luascripts}/test_t55x7_bi.lua | 0 client/{scripts => luascripts}/test_t55x7_fsk.lua | 0 client/{scripts => luascripts}/test_t55x7_psk.lua | 0 client/{scripts => luascripts}/tnp3clone.lua | 0 client/{scripts => luascripts}/tnp3dump.lua | 0 client/{scripts => luascripts}/tnp3sim.lua | 0 client/{scripts => luascripts}/tracetest.lua | 0 client/{scripts => luascripts}/ufodump.lua | 0 client/{scripts => luascripts}/ul_uid.lua | 0 client/scripting.c | 2 +- client/scripting.h | 2 +- 47 files changed, 8 insertions(+), 8 deletions(-) rename client/{scripts => luascripts}/14araw.lua (100%) rename client/{scripts => luascripts}/Legic_clone.lua (100%) rename client/{scripts => luascripts}/amiibo.lua (100%) rename client/{scripts => luascripts}/brutesim.lua (100%) rename client/{scripts => luascripts}/calc_di.lua (100%) rename client/{scripts => luascripts}/calc_ev1_it.lua (100%) rename client/{scripts => luascripts}/calc_mizip.lua (100%) rename client/{scripts => luascripts}/calypso.lua (100%) rename client/{scripts => luascripts}/cmdline.lua (100%) rename client/{scripts => luascripts}/didump.lua (100%) rename client/{scripts => luascripts}/dumptoemul-mfu.lua (100%) rename client/{scripts => luascripts}/dumptoemul.lua (100%) rename client/{scripts => luascripts}/e.lua (100%) rename client/{scripts => luascripts}/emul2dump.lua (100%) rename client/{scripts => luascripts}/emul2html.lua (100%) rename client/{scripts => luascripts}/formatMifare.lua (100%) rename client/{scripts => luascripts}/hf_read.lua (100%) rename client/{scripts => luascripts}/htmldump.lua (100%) rename client/{scripts => luascripts}/iso15_magic.lua (100%) rename client/{scripts => luascripts}/legic.lua (100%) rename client/{scripts => luascripts}/legic_buffer2card.lua (100%) rename client/{scripts => luascripts}/lf_bulk.lua (100%) rename client/{scripts => luascripts}/mfkeys.lua (100%) rename client/{scripts => luascripts}/mifare_access.lua (100%) rename client/{scripts => luascripts}/mifare_autopwn.lua (100%) rename client/{scripts => luascripts}/mifareplus.lua (100%) rename client/{scripts => luascripts}/ndef_dump.lua (100%) rename client/{scripts => luascripts}/ntag_3d.lua (99%) rename client/{scripts => luascripts}/parameters.lua (100%) rename client/{scripts => luascripts}/read_pwd_mem.lua (100%) rename client/{scripts => luascripts}/remagic.lua (100%) rename client/{scripts => luascripts}/test_t55x7.lua (100%) rename client/{scripts => luascripts}/test_t55x7_ask.lua (100%) rename client/{scripts => luascripts}/test_t55x7_bi.lua (100%) rename client/{scripts => luascripts}/test_t55x7_fsk.lua (100%) rename client/{scripts => luascripts}/test_t55x7_psk.lua (100%) rename client/{scripts => luascripts}/tnp3clone.lua (100%) rename client/{scripts => luascripts}/tnp3dump.lua (100%) rename client/{scripts => luascripts}/tnp3sim.lua (100%) rename client/{scripts => luascripts}/tracetest.lua (100%) rename client/{scripts => luascripts}/ufodump.lua (100%) rename client/{scripts => luascripts}/ul_uid.lua (100%) diff --git a/appveyor.yml b/appveyor.yml index a1276ca1e..a0c261b2b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -151,9 +151,9 @@ build_script: Copy-Item C:\ProxSpace\pm3\bootrom\obj\*.elf C:\ProxSpace\Release\arm - New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\scripts + New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\luascripts - Copy-Item C:\ProxSpace\pm3\client\scripts\*.lua C:\ProxSpace\Release\scripts + Copy-Item C:\ProxSpace\pm3\client\luascripts\*.lua C:\ProxSpace\Release\luascripts New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\hardnested\tables diff --git a/client/cmdhfmfp.c b/client/cmdhfmfp.c index 8c7cfcc5c..58eb5db1a 100644 --- a/client/cmdhfmfp.c +++ b/client/cmdhfmfp.c @@ -86,7 +86,7 @@ static int CmdHFMFPInfo(const char *cmd) { // check SL0 uint8_t data[250] = {0}; int datalen = 0; - // https://github.com/Proxmark/proxmark3/blob/master/client/scripts/mifarePlus.lua#L161 + // https://github.com/Proxmark/proxmark3/blob/master/client/luascripts/mifarePlus.lua#L161 uint8_t cmd[3 + 16] = {0xa8, 0x90, 0x90, 0x00}; int res = ExchangeRAW14a(cmd, sizeof(cmd), false, false, data, sizeof(data), &datalen); if (!res && datalen > 1 && data[0] == 0x09) { diff --git a/client/cmdscript.c b/client/cmdscript.c index 28dd8608f..16539b020 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -77,7 +77,7 @@ static int CmdScriptList(const char *Cmd) { n = scandir(script_directory_path, &namelist, NULL, alphasort); if (n == -1) { - PrintAndLogEx(FAILED, "Couldn't open the scripts-directory"); + PrintAndLogEx(FAILED, "Couldn't open the luascripts-directory"); return 1; } @@ -175,7 +175,7 @@ static command_t CommandTable[] = { */ static int CmdHelp(const char *Cmd) { (void)Cmd; // Cmd is not used so far - PrintAndLogEx(NORMAL, "This is a feature to run Lua-scripts. You can place lua-scripts within the scripts/-folder. "); + PrintAndLogEx(NORMAL, "This is a feature to run Lua-scripts. You can place Lua-scripts within the luascripts/-folder. "); return 0; } diff --git a/client/scripts/14araw.lua b/client/luascripts/14araw.lua similarity index 100% rename from client/scripts/14araw.lua rename to client/luascripts/14araw.lua diff --git a/client/scripts/Legic_clone.lua b/client/luascripts/Legic_clone.lua similarity index 100% rename from client/scripts/Legic_clone.lua rename to client/luascripts/Legic_clone.lua diff --git a/client/scripts/amiibo.lua b/client/luascripts/amiibo.lua similarity index 100% rename from client/scripts/amiibo.lua rename to client/luascripts/amiibo.lua diff --git a/client/scripts/brutesim.lua b/client/luascripts/brutesim.lua similarity index 100% rename from client/scripts/brutesim.lua rename to client/luascripts/brutesim.lua diff --git a/client/scripts/calc_di.lua b/client/luascripts/calc_di.lua similarity index 100% rename from client/scripts/calc_di.lua rename to client/luascripts/calc_di.lua diff --git a/client/scripts/calc_ev1_it.lua b/client/luascripts/calc_ev1_it.lua similarity index 100% rename from client/scripts/calc_ev1_it.lua rename to client/luascripts/calc_ev1_it.lua diff --git a/client/scripts/calc_mizip.lua b/client/luascripts/calc_mizip.lua similarity index 100% rename from client/scripts/calc_mizip.lua rename to client/luascripts/calc_mizip.lua diff --git a/client/scripts/calypso.lua b/client/luascripts/calypso.lua similarity index 100% rename from client/scripts/calypso.lua rename to client/luascripts/calypso.lua diff --git a/client/scripts/cmdline.lua b/client/luascripts/cmdline.lua similarity index 100% rename from client/scripts/cmdline.lua rename to client/luascripts/cmdline.lua diff --git a/client/scripts/didump.lua b/client/luascripts/didump.lua similarity index 100% rename from client/scripts/didump.lua rename to client/luascripts/didump.lua diff --git a/client/scripts/dumptoemul-mfu.lua b/client/luascripts/dumptoemul-mfu.lua similarity index 100% rename from client/scripts/dumptoemul-mfu.lua rename to client/luascripts/dumptoemul-mfu.lua diff --git a/client/scripts/dumptoemul.lua b/client/luascripts/dumptoemul.lua similarity index 100% rename from client/scripts/dumptoemul.lua rename to client/luascripts/dumptoemul.lua diff --git a/client/scripts/e.lua b/client/luascripts/e.lua similarity index 100% rename from client/scripts/e.lua rename to client/luascripts/e.lua diff --git a/client/scripts/emul2dump.lua b/client/luascripts/emul2dump.lua similarity index 100% rename from client/scripts/emul2dump.lua rename to client/luascripts/emul2dump.lua diff --git a/client/scripts/emul2html.lua b/client/luascripts/emul2html.lua similarity index 100% rename from client/scripts/emul2html.lua rename to client/luascripts/emul2html.lua diff --git a/client/scripts/formatMifare.lua b/client/luascripts/formatMifare.lua similarity index 100% rename from client/scripts/formatMifare.lua rename to client/luascripts/formatMifare.lua diff --git a/client/scripts/hf_read.lua b/client/luascripts/hf_read.lua similarity index 100% rename from client/scripts/hf_read.lua rename to client/luascripts/hf_read.lua diff --git a/client/scripts/htmldump.lua b/client/luascripts/htmldump.lua similarity index 100% rename from client/scripts/htmldump.lua rename to client/luascripts/htmldump.lua diff --git a/client/scripts/iso15_magic.lua b/client/luascripts/iso15_magic.lua similarity index 100% rename from client/scripts/iso15_magic.lua rename to client/luascripts/iso15_magic.lua diff --git a/client/scripts/legic.lua b/client/luascripts/legic.lua similarity index 100% rename from client/scripts/legic.lua rename to client/luascripts/legic.lua diff --git a/client/scripts/legic_buffer2card.lua b/client/luascripts/legic_buffer2card.lua similarity index 100% rename from client/scripts/legic_buffer2card.lua rename to client/luascripts/legic_buffer2card.lua diff --git a/client/scripts/lf_bulk.lua b/client/luascripts/lf_bulk.lua similarity index 100% rename from client/scripts/lf_bulk.lua rename to client/luascripts/lf_bulk.lua diff --git a/client/scripts/mfkeys.lua b/client/luascripts/mfkeys.lua similarity index 100% rename from client/scripts/mfkeys.lua rename to client/luascripts/mfkeys.lua diff --git a/client/scripts/mifare_access.lua b/client/luascripts/mifare_access.lua similarity index 100% rename from client/scripts/mifare_access.lua rename to client/luascripts/mifare_access.lua diff --git a/client/scripts/mifare_autopwn.lua b/client/luascripts/mifare_autopwn.lua similarity index 100% rename from client/scripts/mifare_autopwn.lua rename to client/luascripts/mifare_autopwn.lua diff --git a/client/scripts/mifareplus.lua b/client/luascripts/mifareplus.lua similarity index 100% rename from client/scripts/mifareplus.lua rename to client/luascripts/mifareplus.lua diff --git a/client/scripts/ndef_dump.lua b/client/luascripts/ndef_dump.lua similarity index 100% rename from client/scripts/ndef_dump.lua rename to client/luascripts/ndef_dump.lua diff --git a/client/scripts/ntag_3d.lua b/client/luascripts/ntag_3d.lua similarity index 99% rename from client/scripts/ntag_3d.lua rename to client/luascripts/ntag_3d.lua index ff2c68d0f..869590cf2 100644 --- a/client/scripts/ntag_3d.lua +++ b/client/luascripts/ntag_3d.lua @@ -223,7 +223,7 @@ local function configure_magic_ntag(uid) -- -p == set pwd -- -a == set pack args =('-t 12 -u %s -p %08X -a %04X'):format(uid, pwd, pack) - require('../scripts/mfu_magic') + require('mfu_magic') -- Set back args. Not that it's used, just for the karma... args = myargs diff --git a/client/scripts/parameters.lua b/client/luascripts/parameters.lua similarity index 100% rename from client/scripts/parameters.lua rename to client/luascripts/parameters.lua diff --git a/client/scripts/read_pwd_mem.lua b/client/luascripts/read_pwd_mem.lua similarity index 100% rename from client/scripts/read_pwd_mem.lua rename to client/luascripts/read_pwd_mem.lua diff --git a/client/scripts/remagic.lua b/client/luascripts/remagic.lua similarity index 100% rename from client/scripts/remagic.lua rename to client/luascripts/remagic.lua diff --git a/client/scripts/test_t55x7.lua b/client/luascripts/test_t55x7.lua similarity index 100% rename from client/scripts/test_t55x7.lua rename to client/luascripts/test_t55x7.lua diff --git a/client/scripts/test_t55x7_ask.lua b/client/luascripts/test_t55x7_ask.lua similarity index 100% rename from client/scripts/test_t55x7_ask.lua rename to client/luascripts/test_t55x7_ask.lua diff --git a/client/scripts/test_t55x7_bi.lua b/client/luascripts/test_t55x7_bi.lua similarity index 100% rename from client/scripts/test_t55x7_bi.lua rename to client/luascripts/test_t55x7_bi.lua diff --git a/client/scripts/test_t55x7_fsk.lua b/client/luascripts/test_t55x7_fsk.lua similarity index 100% rename from client/scripts/test_t55x7_fsk.lua rename to client/luascripts/test_t55x7_fsk.lua diff --git a/client/scripts/test_t55x7_psk.lua b/client/luascripts/test_t55x7_psk.lua similarity index 100% rename from client/scripts/test_t55x7_psk.lua rename to client/luascripts/test_t55x7_psk.lua diff --git a/client/scripts/tnp3clone.lua b/client/luascripts/tnp3clone.lua similarity index 100% rename from client/scripts/tnp3clone.lua rename to client/luascripts/tnp3clone.lua diff --git a/client/scripts/tnp3dump.lua b/client/luascripts/tnp3dump.lua similarity index 100% rename from client/scripts/tnp3dump.lua rename to client/luascripts/tnp3dump.lua diff --git a/client/scripts/tnp3sim.lua b/client/luascripts/tnp3sim.lua similarity index 100% rename from client/scripts/tnp3sim.lua rename to client/luascripts/tnp3sim.lua diff --git a/client/scripts/tracetest.lua b/client/luascripts/tracetest.lua similarity index 100% rename from client/scripts/tracetest.lua rename to client/luascripts/tracetest.lua diff --git a/client/scripts/ufodump.lua b/client/luascripts/ufodump.lua similarity index 100% rename from client/scripts/ufodump.lua rename to client/luascripts/ufodump.lua diff --git a/client/scripts/ul_uid.lua b/client/luascripts/ul_uid.lua similarity index 100% rename from client/scripts/ul_uid.lua rename to client/luascripts/ul_uid.lua diff --git a/client/scripting.c b/client/scripting.c index 429d96fac..f090efbd7 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1133,7 +1133,7 @@ int set_pm3_libraries(lua_State *L) { //--add to the LUA_PATH (package.path in lua) - // so we can load scripts from the ./scripts/ - directory + // so we can load scripts from the ./luascripts/ - directory char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, get_my_executable_directory()); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); diff --git a/client/scripting.h b/client/scripting.h index 07b07aa67..1a7b5a7e3 100644 --- a/client/scripting.h +++ b/client/scripting.h @@ -15,7 +15,7 @@ //#include #define LUA_LIBRARIES_DIRECTORY "lualibs/" -#define LUA_SCRIPTS_DIRECTORY "scripts/" +#define LUA_SCRIPTS_DIRECTORY "luascripts/" #define LUA_LIBRARIES_WILDCARD "?.lua" /** From 3c6500a1b2b8589478256cafbf06664d2a436646 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 21 Aug 2019 23:50:41 +0200 Subject: [PATCH 066/347] Lua: look for scripts also in ~/.proxmark/{luascripts,lualibs} and /usr/local/share/proxmark3/... --- CHANGELOG.md | 3 +++ client/scripting.c | 63 ++++++++++++++++++++++++++++++++++------------ client/scripting.h | 2 ++ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8d19d065..b8434cc84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ 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... ## [unreleased][unreleased] + + - Add Lua paths: look for scripts also in ~/.proxmark/lua{scripts,libs} and /usr/local/share/proxmark3/lua{scripts,libs} (@doegox) + - Change Lua directory scripts/ to luascript/ (@doegox) - Change non-rdv4 PLATFORM must now use the generic PM3OTHER, simpler (@doegox) - Fix reveng integration for all platforms else than WIN32 (@doegox) - Add cheat sheet for easy operations of the Proxmark3 (scund00r) diff --git a/client/scripting.c b/client/scripting.c index f090efbd7..54ed2aa2c 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1131,21 +1131,52 @@ int set_pm3_libraries(lua_State *L) { //-- remove the global environment table from the stack lua_pop(L, 1); - //--add to the LUA_PATH (package.path in lua) - // so we can load scripts from the ./luascripts/ - directory - char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, get_my_executable_directory()); - strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); - strcat(scripts_path, LUA_LIBRARIES_WILDCARD); - setLuaPath(L, scripts_path); - - //-- Last but not least, add to the LUA_PATH (package.path in lua) - // so we can load libraries from the ./lualib/ - directory - char libraries_path[strlen(get_my_executable_directory()) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, get_my_executable_directory()); - strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); - strcat(libraries_path, LUA_LIBRARIES_WILDCARD); - setLuaPath(L, libraries_path); - return 1; + // so we can load scripts from various places: + { + // from the ./luascripts/ directory + char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, get_my_executable_directory()); + strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_LIBRARIES_WILDCARD); + setLuaPath(L, scripts_path); + // from the ./lualib/ directory + char libraries_path[strlen(get_my_executable_directory()) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, get_my_executable_directory()); + strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_WILDCARD); + setLuaPath(L, libraries_path); + } + char *userpath = getenv("HOME"); + if (userpath != NULL) { + // from the ~/.proxmark3/luascripts/ directory + char scripts_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, userpath); + strcat(scripts_path, LUA_PM3_USER_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_LIBRARIES_WILDCARD); + setLuaPath(L, scripts_path); + // from the ~/.proxmark3/lualib/ directory + char libraries_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, userpath); + strcat(libraries_path, LUA_PM3_USER_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_WILDCARD); + setLuaPath(L, libraries_path); + } + { + // from the /usr/local/share/proxmark3/luascripts/ directory + char scripts_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_LIBRARIES_WILDCARD); + setLuaPath(L, scripts_path); + // from the /usr/local/share/proxmark3/lualib/ directory + char libraries_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, LUA_PM3_SYSTEM_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_WILDCARD); + setLuaPath(L, libraries_path); + return 1; + } } diff --git a/client/scripting.h b/client/scripting.h index 1a7b5a7e3..12d6f1f0b 100644 --- a/client/scripting.h +++ b/client/scripting.h @@ -14,6 +14,8 @@ //#include //#include +#define LUA_PM3_SYSTEM_DIRECTORY "/usr/local/share/proxmark3/" +#define LUA_PM3_USER_DIRECTORY "/.proxmark3/" #define LUA_LIBRARIES_DIRECTORY "lualibs/" #define LUA_SCRIPTS_DIRECTORY "luascripts/" #define LUA_LIBRARIES_WILDCARD "?.lua" From 9ae27cd73cc42d16ffe6eaf95d8c8482764b6f64 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 00:32:15 +0200 Subject: [PATCH 067/347] scripts list / scripts run: look also in the new lua scripts paths --- client/cmdscript.c | 115 ++++++++++++++++++++++++++++++++++----------- client/scripting.c | 4 +- 2 files changed, 89 insertions(+), 30 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 16539b020..f97e8fe9c 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -56,29 +56,13 @@ static bool endsWith(const char *base, const char *str) { return (blen >= slen) && (0 == strcmp(base + blen - slen, str)); } -/** -* Generate a sorted list of available commands, what it does is -* generate a file listing of the script-directory for files -* ending with .lua -*/ -static int CmdScriptList(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - - char const *exedir = get_my_executable_directory(); - if (exedir == NULL) - return 0; - char script_directory_path[strlen(exedir) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; - strcpy(script_directory_path, exedir); - strcpy(script_directory_path, get_my_executable_directory()); - strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - +static int scriptlist(const char *path) { struct dirent **namelist; int n; - n = scandir(script_directory_path, &namelist, NULL, alphasort); + n = scandir(path, &namelist, NULL, alphasort); if (n == -1) { - PrintAndLogEx(FAILED, "Couldn't open the luascripts-directory"); - return 1; + return PM3_EFILE; } for (uint16_t i = 0; i < n; i++) { @@ -87,6 +71,37 @@ static int CmdScriptList(const char *Cmd) { free(namelist[i]); } free(namelist); + return PM3_SUCCESS; +} + +/** +* Generate a sorted list of available commands, what it does is +* generate a file listing of the script-directory for files +* ending with .lua +*/ +static int CmdScriptList(const char *Cmd) { + (void)Cmd; // Cmd is not used so far + + if (get_my_executable_directory() != NULL) { + char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + strcpy(script_directory_path, get_my_executable_directory()); + strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); + scriptlist(script_directory_path); + } + char *userpath = getenv("HOME"); + if (userpath != NULL) { + char script_directory_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + strcpy(script_directory_path, userpath); + strcat(script_directory_path, LUA_PM3_USER_DIRECTORY); + strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); + scriptlist(script_directory_path); + } + { + char script_directory_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + strcpy(script_directory_path, LUA_PM3_SYSTEM_DIRECTORY); + strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); + scriptlist(script_directory_path); + } return 0; } @@ -125,16 +140,60 @@ static int CmdScriptRun(const char *Cmd) { suffix = ".lua"; } - char script_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, get_my_executable_directory()); - strcat(script_path, LUA_SCRIPTS_DIRECTORY); - strcat(script_path, script_name); - strcat(script_path, suffix); + bool found = false; + int error; + if (get_my_executable_directory() != NULL) { + char script_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, get_my_executable_directory()); + strcat(script_path, LUA_SCRIPTS_DIRECTORY); + strcat(script_path, script_name); + strcat(script_path, suffix); + FILE *file; + if ((file = fopen(script_path, "r"))) + { + fclose(file); + PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); + found = true; + error = luaL_loadfile(lua_state, script_path); + } + } + char *userpath = getenv("HOME"); + if ((!found) && (userpath != NULL)) { + char script_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, userpath); + strcat(script_path, LUA_PM3_USER_DIRECTORY); + strcat(script_path, LUA_SCRIPTS_DIRECTORY); + strcat(script_path, script_name); + strcat(script_path, suffix); + FILE *file; + if ((file = fopen(script_path, "r"))) + { + fclose(file); + PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); + found = true; + error = luaL_loadfile(lua_state, script_path); + } + } + if (!found) { + char script_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, LUA_PM3_SYSTEM_DIRECTORY); + strcat(script_path, LUA_SCRIPTS_DIRECTORY); + strcat(script_path, script_name); + strcat(script_path, suffix); + FILE *file; + if ((file = fopen(script_path, "r"))) + { + fclose(file); + PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); + found = true; + error = luaL_loadfile(lua_state, script_path); + } + } + if (!found) { + PrintAndLogEx(FAILED, "Error - can't find script %s%s", script_name, suffix); + return PM3_EFILE; + } - PrintAndLogEx(SUCCESS, "Executing: %s%s, args '%s'\n", script_name, suffix, arguments); - - // run the Lua script - int error = luaL_loadfile(lua_state, script_path); if (!error) { lua_pushstring(lua_state, arguments); lua_setglobal(lua_state, "args"); diff --git a/client/scripting.c b/client/scripting.c index 54ed2aa2c..1c021e591 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1133,7 +1133,7 @@ int set_pm3_libraries(lua_State *L) { //--add to the LUA_PATH (package.path in lua) // so we can load scripts from various places: - { + if (get_my_executable_directory() != NULL) { // from the ./luascripts/ directory char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, get_my_executable_directory()); @@ -1177,6 +1177,6 @@ int set_pm3_libraries(lua_State *L) { strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); - return 1; } + return 1; } From 9a21bf8b2d8a77233f29fdd62a8c23974ee0c069 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 22 Aug 2019 13:26:05 +0300 Subject: [PATCH 068/347] add check arm-none-eabi-gcc and unify install step for linux and macos --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8952df259..0b108b4f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,13 +45,13 @@ addons: taps: RfidResearchGroup/proxmark3 install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - make clean; - make all V=1 "$MAKE_PARAMS"; - elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then - make clean; - make all V=1 "$MAKE_PARAMS"; + if ! arm-none-eabi-gccx -v; then + echo "arm-none-eabi-gcc [ERROR]"; + travis_terminate 1; fi + + make clean; + make all V=1 "$MAKE_PARAMS"; script: ## start and run a test script From 34a389a4ac45ad56c94f439a458efe6f51a228c7 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 22 Aug 2019 13:30:01 +0300 Subject: [PATCH 069/347] small fix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0b108b4f1..ac39433f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,7 @@ addons: taps: RfidResearchGroup/proxmark3 install: - if ! arm-none-eabi-gccx -v; then + if ! arm-none-eabi-gcc -v; then echo "arm-none-eabi-gcc [ERROR]"; travis_terminate 1; fi From 407078d90a9d6ec7b040adbccd662d14db65d2c6 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Thu, 22 Aug 2019 12:49:26 +0200 Subject: [PATCH 070/347] Experimental hardautopwn implementation. --- client/cmdhfmf.c | 425 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 425 insertions(+) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index aaaeafb99..6c5424568 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -166,6 +166,34 @@ static int usage_hf14_hardnested(void) { PrintAndLogEx(NORMAL, " hf mf hardnested 0 A A0A1A2A3A4A5 4 A FFFFFFFFFFFF"); return 0; } +static int usage_hf14_hardautopwn(void) { + PrintAndLogEx(NORMAL, "Usage:"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn [k] "); + PrintAndLogEx(NORMAL, " [d] [f] [s] [t] [i]"); + PrintAndLogEx(NORMAL, " (card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K)"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Options:"); + PrintAndLogEx(NORMAL, " h this help"); + PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); + PrintAndLogEx(NORMAL, " d write keys to binary file"); + PrintAndLogEx(NORMAL, " f keys to test (speed up the cracking, if some keys are known)"); + PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards)"); + PrintAndLogEx(NORMAL, " t tests?"); + PrintAndLogEx(NORMAL, " i set type of SIMD instructions. Without this flag programs autodetect it."); + PrintAndLogEx(NORMAL, " i 5 = AVX512"); + PrintAndLogEx(NORMAL, " i 2 = AVX2"); + PrintAndLogEx(NORMAL, " i a = AVX"); + PrintAndLogEx(NORMAL, " i s = SSE2"); + PrintAndLogEx(NORMAL, " i m = MMX"); + PrintAndLogEx(NORMAL, " i n = none (use CPU regular instruction set)"); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn b 0 A FFFFFFFFFFFF 1 d"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn 0 A FFFFFFFFFFFF 1 d f default_keys.dic"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn 0 A FFFFFFFFFFFF 4 A f nonces.bin w s"); + PrintAndLogEx(NORMAL, ""); + return 0; +} static int usage_hf14_chk(void) { PrintAndLogEx(NORMAL, "Usage: hf mf chk [h] |<*card memory> [t|d] [] []"); PrintAndLogEx(NORMAL, "Options:"); @@ -1530,6 +1558,402 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { return 0; } + +static int CmdHF14AMfHardAuto(const char *Cmd) { + uint8_t blockNo = 0; + uint8_t keyType = 0; + uint8_t *keyBlock, *p; + uint8_t sectorsCnt = 1; + uint8_t key[6] = {0, 0, 0, 0, 0, 0}; + uint8_t trgkey[6] = {0, 0, 0, 0, 0, 0}; + uint8_t cmdp = 0; + uint64_t key64 = 0; + char filename[FILE_PATH_SIZE] = {0}, *fptr; + char ctmp; + + keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); + if (keyBlock == NULL) return 1; + + for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) + num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); + + bool slow = false; + bool nonce_file_read = false; + bool nonce_file_write = false; + bool createDumpFile = false; + bool know_target_key = false; + int tests = 0; + + ctmp = tolower(param_getchar(Cmd, 0)); + if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf14_hardautopwn(); + + + while ((ctmp = param_getchar(Cmd, cmdp))) { + switch (tolower(ctmp)) { + case 'h': + return usage_hf14_hardautopwn(); + case 'f': + if (param_getstr(Cmd, cmdp +1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { + PrintAndLogEx(FAILED, "Filename too long"); + } + cmdp ++; + break; + case 'd': + createDumpFile = true; + break; + case '*': + // sectors + switch (param_getchar(Cmd, cmdp + 1)) { + case '0': + sectorsCnt = MIFARE_MINI_MAXSECTOR; + break; + case '1': + sectorsCnt = MIFARE_1K_MAXSECTOR; + break; + case '2': + sectorsCnt = MIFARE_2K_MAXSECTOR; + break; + case '4': + sectorsCnt = MIFARE_4K_MAXSECTOR; + break; + default: + sectorsCnt = MIFARE_1K_MAXSECTOR; + } + cmdp ++; + break; + case 'k': + // Get the known block number + if (param_getchar(Cmd, cmdp + 1) == 0x00) { + PrintAndLogEx(WARNING, "Block number is missing"); + return 1; + } + blockNo = param_get8(Cmd, cmdp + 1); + // Get the knonwn block type + ctmp = tolower(param_getchar(Cmd, cmdp + 2)); + if (ctmp != 'a' && ctmp != 'b') { + PrintAndLogEx(WARNING, "Key type must be A or B"); + return 1; + } + if (ctmp != 'a') { + keyType = 1; + } + // Get the known block key + if (param_gethex(Cmd, cmdp + 3, key, 12)) { + PrintAndLogEx(WARNING, "Key must include 12 HEX symbols"); + return 1; + } + know_target_key = true; + cmdp += 3; + case 's': + slow = true; + break; + case 'i': + SetSIMDInstr(SIMD_AUTO); + ctmp = tolower(param_getchar(Cmd, cmdp + 1)); + switch (ctmp) { + case '5': + SetSIMDInstr(SIMD_AVX512); + break; + case '2': + SetSIMDInstr(SIMD_AVX2); + break; + case 'a': + SetSIMDInstr(SIMD_AVX); + break; + case 's': + SetSIMDInstr(SIMD_SSE2); + break; + case 'm': + SetSIMDInstr(SIMD_MMX); + break; + case 'n': + SetSIMDInstr(SIMD_NONE); + break; + default: + PrintAndLogEx(WARNING, "Unknown SIMD type. %c", ctmp); + return 1; + } + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", ctmp); + usage_hf14_hardnested(); + return 1; + } + cmdp++; + } + + // Print parameters + PrintAndLogEx(NORMAL, "Used Parameters:"); + PrintAndLogEx(NORMAL, "\t[+] Dumping the found keys: %d", createDumpFile); + PrintAndLogEx(NORMAL, "\t[+] Card sectors: %d", sectorsCnt); + PrintAndLogEx(NORMAL, "\t[+] Key supplied: %d", know_target_key); + PrintAndLogEx(NORMAL, "\t[+] Known block: %d", blockNo); + PrintAndLogEx(NORMAL, "\t[+] Keytype: %c", keyType ? 'B' : 'A'); + PrintAndLogEx(NORMAL, "\t[+] Kown key: 0x%02x%02x%02x%02x%02x%02x", key[0], key[1], key[2], key[3], key[4], key[5]); + PrintAndLogEx(NORMAL, "\t[+] Dictionary: %s", filename); + + + if (know_target_key) { + // check if we can authenticate to sector + if (mfCheckKeys(blockNo, keyType, true, 1, key, &key64) != PM3_SUCCESS) { + PrintAndLogEx(WARNING, "Key is wrong. Can't authenticate to block:%3d key type:%c", blockNo, keyType ? 'B' : 'A'); + return 3; + } + } else { + PrintAndLogEx(WARNING, "No known key was supplied, if no usable key is found in the dictionary, then this attack will fail!"); + } + + + // General stuff + // Add check for the hardnested attack!! + uint64_t foundkey = 0; + int16_t isOK = 0; + + // Bruteforce stuff + FILE* f; + sector_t *e_sector = calloc(sectorsCnt, sizeof(sector_t)); + uint8_t arr[80]; + uint8_t tmpKey[6]; + char buf[13] = {0}; + int i, i2, keycnt = 0;; + int current_sector_i, current_key_type_i, default_keys_i, found_keys_i; + uint32_t keyitems = ARRAYLEN(g_mifare_default_keys); + + + // Clear the datastructures + for (i=0; i<80; i++) { + arr[i] = 0; + } + for (i=0; i 0xffffffffffff has been inserted for unknown keys.", fptr); + } + + free(e_sector); + + DropField(); + if (isOK) { + switch (isOK) { + case 1 : + PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); + break; + case 2 : + PrintAndLogEx(NORMAL, "Button pressed. Aborted.\n"); + break; + default : + break; + } + return 2; + } + + + return 0; +} + /* static int randInRange(int min, int max) { return min + (int)(rand() / (double)(RAND_MAX) * (max - min + 1)); @@ -3638,6 +4062,7 @@ static command_t CommandTable[] = { {"darkside", CmdHF14AMfDarkside, IfPm3Iso14443a, "Darkside attack. read parity error messages."}, {"nested", CmdHF14AMfNested, IfPm3Iso14443a, "Nested attack. Test nested authentication"}, {"hardnested", CmdHF14AMfNestedHard, AlwaysAvailable, "Nested attack for hardened Mifare cards"}, + {"hardautopwn", CmdHF14AMfHardAuto, AlwaysAvailable, "Nested attack for hardened Mifare cards that breaks all sector keys autmatically"}, {"keybrute", CmdHF14AMfKeyBrute, IfPm3Iso14443a, "J_Run's 2nd phase of multiple sector nested authentication key recovery"}, {"nack", CmdHf14AMfNack, IfPm3Iso14443a, "Test for Mifare NACK bug"}, {"chk", CmdHF14AMfChk, IfPm3Iso14443a, "Check keys"}, From abb69e2dc9fe7a7e114955b6543e35f396718735 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Thu, 22 Aug 2019 14:55:06 +0200 Subject: [PATCH 071/347] Further improved the hardautopwn feature. --- client/cmdhfmf.c | 162 ++++++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 71 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 6c5424568..c68daa9f3 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -168,17 +168,16 @@ static int usage_hf14_hardnested(void) { } static int usage_hf14_hardautopwn(void) { PrintAndLogEx(NORMAL, "Usage:"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn [k] "); - PrintAndLogEx(NORMAL, " [d] [f] [s] [t] [i]"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn [k] "); + PrintAndLogEx(NORMAL, " * [d] [f] [s] [t] [i]"); PrintAndLogEx(NORMAL, " (card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); + PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); PrintAndLogEx(NORMAL, " d write keys to binary file"); PrintAndLogEx(NORMAL, " f keys to test (speed up the cracking, if some keys are known)"); PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards)"); - PrintAndLogEx(NORMAL, " t tests?"); PrintAndLogEx(NORMAL, " i set type of SIMD instructions. Without this flag programs autodetect it."); PrintAndLogEx(NORMAL, " i 5 = AVX512"); PrintAndLogEx(NORMAL, " i 2 = AVX2"); @@ -188,9 +187,9 @@ static int usage_hf14_hardautopwn(void) { PrintAndLogEx(NORMAL, " i n = none (use CPU regular instruction set)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn b 0 A FFFFFFFFFFFF 1 d"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn 0 A FFFFFFFFFFFF 1 d f default_keys.dic"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn 0 A FFFFFFFFFFFF 4 A f nonces.bin w s"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF d"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF * 1 d f default_keys.dic"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF * 4 s i 5"); PrintAndLogEx(NORMAL, ""); return 0; } @@ -1560,22 +1559,45 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { static int CmdHF14AMfHardAuto(const char *Cmd) { + /* + Author: Matthias Konrath + Company: Trustworks GmbH + Email: m.konrath@trustworks.at + */ + uint8_t blockNo = 0; uint8_t keyType = 0; uint8_t *keyBlock, *p; - uint8_t sectorsCnt = 1; + uint8_t sectorsCnt = MIFARE_1K_MAXSECTOR; + sector_t *e_sector; + uint8_t arr[80]; uint8_t key[6] = {0, 0, 0, 0, 0, 0}; - uint8_t trgkey[6] = {0, 0, 0, 0, 0, 0}; - uint8_t cmdp = 0; + uint8_t tmpKey[6]; uint64_t key64 = 0; - char filename[FILE_PATH_SIZE] = {0}, *fptr; - char ctmp; + + uint64_t t1; + uint8_t foundKeysDictionary = 0; + uint8_t foundKeysReuse = 0; + uint8_t foundKeysHardnested = 0; keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); if (keyBlock == NULL) return 1; for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); + + FILE* f; + char buf[13] = {0}; + char filename[FILE_PATH_SIZE] = {0}, *fptr; + uint8_t cmdp = 0; + char ctmp; + + uint64_t foundkey = 0; + int16_t isOK = 0; + + int i, i2, keycnt = 0;; + int current_sector_i, current_key_type_i, default_keys_i, found_keys_i; + uint32_t keyitems = ARRAYLEN(g_mifare_default_keys); bool slow = false; bool nonce_file_read = false; @@ -1624,7 +1646,7 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { case 'k': // Get the known block number if (param_getchar(Cmd, cmdp + 1) == 0x00) { - PrintAndLogEx(WARNING, "Block number is missing"); + PrintAndLogEx(WARNING, "Sector number is missing"); return 1; } blockNo = param_get8(Cmd, cmdp + 1); @@ -1685,42 +1707,27 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { // Print parameters PrintAndLogEx(NORMAL, "Used Parameters:"); - PrintAndLogEx(NORMAL, "\t[+] Dumping the found keys: %d", createDumpFile); - PrintAndLogEx(NORMAL, "\t[+] Card sectors: %d", sectorsCnt); - PrintAndLogEx(NORMAL, "\t[+] Key supplied: %d", know_target_key); - PrintAndLogEx(NORMAL, "\t[+] Known block: %d", blockNo); - PrintAndLogEx(NORMAL, "\t[+] Keytype: %c", keyType ? 'B' : 'A'); - PrintAndLogEx(NORMAL, "\t[+] Kown key: 0x%02x%02x%02x%02x%02x%02x", key[0], key[1], key[2], key[3], key[4], key[5]); - PrintAndLogEx(NORMAL, "\t[+] Dictionary: %s", filename); + PrintAndLogEx(NORMAL, "[+] Dumping the found keys: %s", createDumpFile ? "True" : "False"); + PrintAndLogEx(NORMAL, "[+] Card sectors: %d", sectorsCnt); + PrintAndLogEx(NORMAL, "[+] Key supplied: %s", know_target_key ? "True" : "False"); + PrintAndLogEx(NORMAL, "[+] Known sector: %d", blockNo); + PrintAndLogEx(NORMAL, "[+] Keytype: %c", keyType ? 'B' : 'A'); + PrintAndLogEx(NORMAL, "[+] Kown key: 0x%02x%02x%02x%02x%02x%02x", key[0], key[1], key[2], key[3], key[4], key[5]); + PrintAndLogEx(NORMAL, "[+] Dictionary: %s", filename); + e_sector = calloc(sectorsCnt, sizeof(sector_t)); if (know_target_key) { // check if we can authenticate to sector if (mfCheckKeys(blockNo, keyType, true, 1, key, &key64) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Key is wrong. Can't authenticate to block:%3d key type:%c", blockNo, keyType ? 'B' : 'A'); + PrintAndLogEx(WARNING, "Key is wrong. Can't authenticate to sector:%3d key type:%c", blockNo, keyType ? 'B' : 'A'); + free(e_sector); return 3; } } else { PrintAndLogEx(WARNING, "No known key was supplied, if no usable key is found in the dictionary, then this attack will fail!"); } - - // General stuff - // Add check for the hardnested attack!! - uint64_t foundkey = 0; - int16_t isOK = 0; - - // Bruteforce stuff - FILE* f; - sector_t *e_sector = calloc(sectorsCnt, sizeof(sector_t)); - uint8_t arr[80]; - uint8_t tmpKey[6]; - char buf[13] = {0}; - int i, i2, keycnt = 0;; - int current_sector_i, current_key_type_i, default_keys_i, found_keys_i; - uint32_t keyitems = ARRAYLEN(g_mifare_default_keys); - - // Clear the datastructures for (i=0; i<80; i++) { arr[i] = 0; @@ -1737,6 +1744,7 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { f = fopen(filename, "r"); if (!f) { PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); + free(e_sector); return 1; } @@ -1760,6 +1768,7 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { PrintAndLogEx(FAILED, "Cannot allocate memory for default keys"); free(keyBlock); fclose(f); + free(e_sector); return 2; } keyBlock = p; @@ -1774,8 +1783,9 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { PrintAndLogEx(SUCCESS, "Loaded %2d keys from " _YELLOW_("%s"), keycnt, filename); } + t1 = msclock(); - // If no key is supplied by the user brute force with the dictionary + // If no key is supplied by the user, brute force with the dictionary if (know_target_key == false) { for (current_sector_i=0; current_sector_i < sectorsCnt; current_sector_i++) { for (current_key_type_i=0; current_key_type_i < 2; current_key_type_i++) { @@ -1786,7 +1796,8 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { } if (mfCheckKeys(current_sector_i*4, current_key_type_i, true, 1, tmpKey, &key64) == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "[ KEY ENUM ] Valid KEY FOUND: block:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(SUCCESS, "Jackpot, we found a key! Now let the fun begin!"); + PrintAndLogEx(SUCCESS, "[Dictio. KEYS] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); @@ -1797,6 +1808,7 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { know_target_key = true; blockNo = current_sector_i; keyType = current_key_type_i; + foundKeysDictionary++; // Exit the loop current_sector_i = sectorsCnt; @@ -1809,17 +1821,17 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { } } - // Set the user defined key + // Set the user defined / bruteforced key if (know_target_key) { e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); arr[blockNo + (keyType * sectorsCnt)] = 1; } else { PrintAndLogEx(FAILED, "No usable key was found!"); - return 1; + free(e_sector); + return 1; } - - // Iterate over each sector and key + // Iterate over each sector and key(A/B) for (current_sector_i=0; current_sector_i < sectorsCnt; current_sector_i++) { for (current_key_type_i=0; current_key_type_i < 2; current_key_type_i++) { @@ -1827,29 +1839,29 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { // Try the found keys if (foundkey == 0) { - for (found_keys_i=0; found_keys_i < current_sector_i; found_keys_i++) { + for (found_keys_i=0; found_keys_i < sectorsCnt; found_keys_i++) { // Iterate over the keys if (arr[found_keys_i + (current_key_type_i * sectorsCnt)] == 1) { num_to_bytes(e_sector[found_keys_i].Key[current_key_type_i], 6, tmpKey); if (mfCheckKeys(current_sector_i*4, current_key_type_i, true, 1, tmpKey, &key64) == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "[FOUND KEYS %c] Valid KEY FOUND: block:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), - current_key_type_i ? 'B' : 'A', + PrintAndLogEx(SUCCESS, "[REUSED KEYS] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); foundkey = bytes_to_num(tmpKey, 6); + foundKeysReuse++; break; } } if (arr[found_keys_i + (((current_key_type_i+1)%2) * sectorsCnt)] == 1) { num_to_bytes(e_sector[found_keys_i].Key[(current_key_type_i+1)%2], 6, tmpKey); if (mfCheckKeys(current_sector_i*4, current_key_type_i, true, 1, tmpKey, &key64) == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "[FOUND KEYS %c] Valid KEY FOUND: block:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), - (current_key_type_i+1)%2 ? 'B' : 'A', + PrintAndLogEx(SUCCESS, "[REUSED KEYS] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); foundkey = bytes_to_num(tmpKey, 6); + foundKeysReuse++; break; } } @@ -1864,29 +1876,48 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { } if (mfCheckKeys(current_sector_i*4, current_key_type_i, true, 1, tmpKey, &key64) == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "[DEFAULT KEYS] Valid KEY FOUND: block:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(SUCCESS, "[Dictio. KEYS] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); foundkey = bytes_to_num(tmpKey, 6); + foundKeysDictionary++; break; } } } // Bruteforce with hardnested if (foundkey == 0) { - PrintAndLogEx(SUCCESS, "[ BRUTEFORCE ] block no:%3d, target key type:%c, Slow: %s, Tests: %d ", + PrintAndLogEx(SUCCESS, "[ BRUTEFORCE ] sector no:%3d, target key type:%c, Slow: %s, Tests: %d ", current_sector_i, current_key_type_i ? 'B' : 'A', slow ? "Yes" : "No", tests); - isOK = mfnestedhard(blockNo, keyType, key, current_sector_i*4, current_key_type_i, know_target_key ? trgkey : NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey, filename); + isOK = mfnestedhard(blockNo, keyType, key, current_sector_i*4, current_key_type_i, NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey, NULL); + + DropField(); + if (isOK) { + switch (isOK) { + case 1 : + PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); + break; + case 2 : + PrintAndLogEx(NORMAL, "Button pressed. Aborted.\n"); + break; + default : + break; + } + free(e_sector); + return 2; + } + num_to_bytes(foundkey, 6, tmpKey); - PrintAndLogEx(SUCCESS, "[CRACKED KEY] Valid KEY FOUND: block:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(SUCCESS, "[CRACKED KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); + foundKeysHardnested++; } // Add the key if (foundkey != 0) { @@ -1908,8 +1939,10 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { if (createDumpFile) { fptr = GenerateFilename("hf-mf-", "-key.bin"); - if (fptr == NULL) + if (fptr == NULL) { + free(e_sector); return 1; + } FILE *fkeys = fopen(fptr, "wb"); if (fkeys == NULL) { @@ -1933,24 +1966,11 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { PrintAndLogEx(SUCCESS, "Found keys have been dumped to " _YELLOW_("%s")" --> 0xffffffffffff has been inserted for unknown keys.", fptr); } + t1 = msclock() - t1; + PrintAndLogEx(SUCCESS, "Key statistics: Dictionary: " _GREEN_("%d") ", Reuse: " _YELLOW_("%d") ", Bruteforce: " _MAGENTA_("%d") ", Total: " _YELLOW_("%d"), foundKeysDictionary, foundKeysReuse, foundKeysHardnested, sectorsCnt*2); + PrintAndLogEx(SUCCESS, "Required time for the hardautopwn attack: " _YELLOW_("%.0f") " seconds\n", (float)t1 / 1000.0); + free(e_sector); - - DropField(); - if (isOK) { - switch (isOK) { - case 1 : - PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); - break; - case 2 : - PrintAndLogEx(NORMAL, "Button pressed. Aborted.\n"); - break; - default : - break; - } - return 2; - } - - return 0; } From ab38130c3e5869ea1013e59bf7cfaeda872a7b6f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 22 Aug 2019 17:44:08 +0200 Subject: [PATCH 072/347] chg: some more checks in pathing --- client/cmdscript.c | 8 +++++--- client/scripting.c | 29 ++++++++++++++++------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index f97e8fe9c..e506b1a37 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -142,9 +142,11 @@ static int CmdScriptRun(const char *Cmd) { bool found = false; int error; - if (get_my_executable_directory() != NULL) { - char script_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, get_my_executable_directory()); + const char* exec_path = get_my_executable_directory(); + + if (exec_path != NULL) { + char script_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, exec_path); strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); diff --git a/client/scripting.c b/client/scripting.c index 1c021e591..a823df8d7 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1133,38 +1133,41 @@ int set_pm3_libraries(lua_State *L) { //--add to the LUA_PATH (package.path in lua) // so we can load scripts from various places: - if (get_my_executable_directory() != NULL) { + const char *exec_path = get_my_executable_directory(); + if (exec_path != NULL) { // from the ./luascripts/ directory - char scripts_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, get_my_executable_directory()); + char scripts_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, exec_path); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ./lualib/ directory - char libraries_path[strlen(get_my_executable_directory()) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, get_my_executable_directory()); + char libraries_path[strlen(exec_path) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, exec_path); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - char *userpath = getenv("HOME"); - if (userpath != NULL) { + char *user_path = getenv("HOME"); + if (user_path != NULL) { // from the ~/.proxmark3/luascripts/ directory - char scripts_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, userpath); + char scripts_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, user_path); strcat(scripts_path, LUA_PM3_USER_DIRECTORY); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); - // from the ~/.proxmark3/lualib/ directory - char libraries_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, userpath); + + // from the ~/.proxmark3/lualib/ directory + char libraries_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, user_path); strcat(libraries_path, LUA_PM3_USER_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - { + + if (strlen(LUA_PM3_SYSTEM_DIRECTORY) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { // from the /usr/local/share/proxmark3/luascripts/ directory char scripts_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY); From 595b8a1885c131b3d3d9dbe79aa27518592e47b6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 19:36:20 +0200 Subject: [PATCH 073/347] introduce PREFIX for pm3 system directory and move to common.h --- client/cmdscript.c | 16 ++++++++-------- client/scripting.c | 18 +++++++++--------- client/scripting.h | 2 -- include/common.h | 6 ++++++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index e506b1a37..9fdc3c0af 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -90,15 +90,15 @@ static int CmdScriptList(const char *Cmd) { } char *userpath = getenv("HOME"); if (userpath != NULL) { - char script_directory_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + char script_directory_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; strcpy(script_directory_path, userpath); - strcat(script_directory_path, LUA_PM3_USER_DIRECTORY); + strcat(script_directory_path, PM3_USER_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); scriptlist(script_directory_path); } { - char script_directory_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; - strcpy(script_directory_path, LUA_PM3_SYSTEM_DIRECTORY); + char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; + strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); scriptlist(script_directory_path); } @@ -161,9 +161,9 @@ static int CmdScriptRun(const char *Cmd) { } char *userpath = getenv("HOME"); if ((!found) && (userpath != NULL)) { - char script_path[strlen(userpath) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + char script_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; strcpy(script_path, userpath); - strcat(script_path, LUA_PM3_USER_DIRECTORY); + strcat(script_path, PM3_USER_DIRECTORY); strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); @@ -177,8 +177,8 @@ static int CmdScriptRun(const char *Cmd) { } } if (!found) { - char script_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, LUA_PM3_SYSTEM_DIRECTORY); + char script_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; + strcpy(script_path, PM3_SYSTEM_DIRECTORY); strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); diff --git a/client/scripting.c b/client/scripting.c index a823df8d7..1f6c61ff8 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1151,32 +1151,32 @@ int set_pm3_libraries(lua_State *L) { char *user_path = getenv("HOME"); if (user_path != NULL) { // from the ~/.proxmark3/luascripts/ directory - char scripts_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, user_path); - strcat(scripts_path, LUA_PM3_USER_DIRECTORY); + strcat(scripts_path, PM3_USER_DIRECTORY); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ~/.proxmark3/lualib/ directory - char libraries_path[strlen(user_path) + strlen(LUA_PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, user_path); - strcat(libraries_path, LUA_PM3_USER_DIRECTORY); + strcat(libraries_path, PM3_USER_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - if (strlen(LUA_PM3_SYSTEM_DIRECTORY) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { + if (strlen(PM3_SYSTEM_DIRECTORY) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { // from the /usr/local/share/proxmark3/luascripts/ directory - char scripts_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, LUA_PM3_SYSTEM_DIRECTORY); + char scripts_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, PM3_SYSTEM_DIRECTORY); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the /usr/local/share/proxmark3/lualib/ directory - char libraries_path[strlen(LUA_PM3_SYSTEM_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, LUA_PM3_SYSTEM_DIRECTORY); + char libraries_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, PM3_SYSTEM_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); diff --git a/client/scripting.h b/client/scripting.h index 12d6f1f0b..1a7b5a7e3 100644 --- a/client/scripting.h +++ b/client/scripting.h @@ -14,8 +14,6 @@ //#include //#include -#define LUA_PM3_SYSTEM_DIRECTORY "/usr/local/share/proxmark3/" -#define LUA_PM3_USER_DIRECTORY "/.proxmark3/" #define LUA_LIBRARIES_DIRECTORY "lualibs/" #define LUA_SCRIPTS_DIRECTORY "luascripts/" #define LUA_LIBRARIES_WILDCARD "?.lua" diff --git a/include/common.h b/include/common.h index f427cb221..d70bc484f 100644 --- a/include/common.h +++ b/include/common.h @@ -16,6 +16,12 @@ #include #include +#ifndef PREFIX +# define PREFIX "/usr/local/" +#endif +#define PM3_SYSTEM_DIRECTORY PREFIX "share/proxmark3/" +#define PM3_USER_DIRECTORY "/.proxmark3/" + #define PACKED __attribute__((packed)) // debug From 40b6956a22e4cf957259efe88c7a39f919aea3c6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 19:53:23 +0200 Subject: [PATCH 074/347] script list: print dir tree --- client/cmdscript.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 9fdc3c0af..90cd65532 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -56,18 +56,21 @@ static bool endsWith(const char *base, const char *str) { return (blen >= slen) && (0 == strcmp(base + blen - slen, str)); } -static int scriptlist(const char *path) { +static int scriptlist(const char *path, bool last) { struct dirent **namelist; int n; n = scandir(path, &namelist, NULL, alphasort); if (n == -1) { + PrintAndLogEx(NORMAL, "%s── %s => NOT FOUND", last ? "└" : "├", path); return PM3_EFILE; } + PrintAndLogEx(NORMAL, "%s── %s", last ? "└" : "├", path); for (uint16_t i = 0; i < n; i++) { - if (str_ends_with(namelist[i]->d_name, ".lua")) - PrintAndLogEx(NORMAL, "%-21s", namelist[i]->d_name); + if (str_ends_with(namelist[i]->d_name, ".lua")) { + PrintAndLogEx(NORMAL, "%s   %s── %-21s", last ? " ":"│", i == n-1 ? "└" : "├", namelist[i]->d_name); + } free(namelist[i]); } free(namelist); @@ -86,7 +89,7 @@ static int CmdScriptList(const char *Cmd) { char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; strcpy(script_directory_path, get_my_executable_directory()); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path); + scriptlist(script_directory_path, false); } char *userpath = getenv("HOME"); if (userpath != NULL) { @@ -94,13 +97,13 @@ static int CmdScriptList(const char *Cmd) { strcpy(script_directory_path, userpath); strcat(script_directory_path, PM3_USER_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path); + scriptlist(script_directory_path, false); } { char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY); strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path); + scriptlist(script_directory_path, true); } return 0; } From 9825f521b45d84bb5d27022c791ae33bfba68f76 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 21:05:45 +0200 Subject: [PATCH 075/347] Fix clang issue where generated .d are sometimes newer than .o --- Makefile.host | 4 +++- client/Makefile | 14 +++++++------- client/reveng/Makefile | 3 --- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Makefile.host b/Makefile.host index e2d3b3f6f..5bf662d9a 100644 --- a/Makefile.host +++ b/Makefile.host @@ -10,6 +10,8 @@ RM = rm -f MV = mv CP = cp -a MKDIR = mkdir -p +TOUCH = touch +FALSE = false CFLAGS ?= -Wall -Werror -O3 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES) @@ -31,7 +33,7 @@ vpath %.c $(MYSRCPATHS) # Flags to generate temporary dependency files DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td # make temporary to final dependency files after successful compilation -POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d +POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d && $(TOUCH) $@ BINDIR := . OBJDIR := obj diff --git a/client/Makefile b/client/Makefile index 9711d29ed..e54e708e6 100644 --- a/client/Makefile +++ b/client/Makefile @@ -128,7 +128,7 @@ endif # Flags to generate temporary dependency files DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td # make temporary to final dependency files after successful compilation -POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d +POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d && $(TOUCH) $@ CORESRCS = uart_posix.c \ uart_win32.c \ @@ -372,37 +372,37 @@ $(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%_NOSIMD.d $(info [-] CC(NOSIMD) $<) $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_NOSIMD.Td) $(PM3CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_NOSIMD.Td $(OBJDIR)/$*_NOSIMD.d + $(Q)$(MV) -f $(OBJDIR)/$*_NOSIMD.Td $(OBJDIR)/$*_NOSIMD.d && $(TOUCH) $@ $(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%_MMX.d $(info [-] CC(MMX) $<) $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_MMX.Td) $(PM3CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_MMX.Td $(OBJDIR)/$*_MMX.d + $(Q)$(MV) -f $(OBJDIR)/$*_MMX.Td $(OBJDIR)/$*_MMX.d && $(TOUCH) $@ $(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%_SSE2.d $(info [-] CC(SSE2) $<) $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_SSE2.Td) $(PM3CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_SSE2.Td $(OBJDIR)/$*_SSE2.d + $(Q)$(MV) -f $(OBJDIR)/$*_SSE2.Td $(OBJDIR)/$*_SSE2.d && $(TOUCH) $@ $(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%_AVX.d $(info [-] CC(AVX) $<) $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_AVX.Td $(OBJDIR)/$*_AVX.d + $(Q)$(MV) -f $(OBJDIR)/$*_AVX.Td $(OBJDIR)/$*_AVX.d && $(TOUCH) $@ $(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%_AVX2.d $(info [-] CC(AVX2) $<) $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX2.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_AVX2.Td $(OBJDIR)/$*_AVX2.d + $(Q)$(MV) -f $(OBJDIR)/$*_AVX2.Td $(OBJDIR)/$*_AVX2.d && $(TOUCH) $@ $(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%_AVX512.d $(info [-] CC(AVX512) $<) $(Q)$(MKDIR) $(dir $@) $(Q)$(CC) $(DEPFLAGS:%.Td=%_AVX512.Td) $(PM3CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $< - $(Q)$(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d + $(Q)$(MV) -f $(OBJDIR)/$*_AVX512.Td $(OBJDIR)/$*_AVX512.d && $(TOUCH) $@ %.o: %.c $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d diff --git a/client/reveng/Makefile b/client/reveng/Makefile index 52fd1bcec..c29538fa5 100644 --- a/client/reveng/Makefile +++ b/client/reveng/Makefile @@ -18,9 +18,6 @@ MYSRCS = \ LIB_A = libreveng.a -TOUCH = touch -FALSE = false - include ../../Makefile.host CLEAN += bmptst From 72392ab305a7bdee029279818c4f913bc9747f47 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 21:18:14 +0200 Subject: [PATCH 076/347] fileutils: fix rel path to includes --- client/fileutils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/fileutils.h b/client/fileutils.h index 74d54000b..79b053fc2 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -46,8 +46,8 @@ #include #include #include -#include "../ui.h" -#include "../emv/emvjson.h" +#include "ui.h" +#include "emv/emvjson.h" #include "mifare/mifare4.h" #include "cmdhfmfu.h" From 915c200ebcd8903652ef7b867e0f89568ac00529 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 21:18:37 +0200 Subject: [PATCH 077/347] luascript: use fileExists --- client/cmdscript.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 90cd65532..eb7979a00 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -26,6 +26,7 @@ #include "lauxlib.h" #include "proxmark3.h" #include "ui.h" +#include "fileutils.h" #ifdef _WIN32 #include "scandir.h" @@ -153,10 +154,8 @@ static int CmdScriptRun(const char *Cmd) { strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); - FILE *file; - if ((file = fopen(script_path, "r"))) + if (fileExists(script_path)) { - fclose(file); PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); found = true; error = luaL_loadfile(lua_state, script_path); @@ -170,10 +169,8 @@ static int CmdScriptRun(const char *Cmd) { strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); - FILE *file; - if ((file = fopen(script_path, "r"))) + if (fileExists(script_path)) { - fclose(file); PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); found = true; error = luaL_loadfile(lua_state, script_path); @@ -185,10 +182,8 @@ static int CmdScriptRun(const char *Cmd) { strcat(script_path, LUA_SCRIPTS_DIRECTORY); strcat(script_path, script_name); strcat(script_path, suffix); - FILE *file; - if ((file = fopen(script_path, "r"))) + if (fileExists(script_path)) { - fclose(file); PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); found = true; error = luaL_loadfile(lua_state, script_path); From 23044c00d065c3d04fa42f402d52ac49362c80b1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 22:16:33 +0200 Subject: [PATCH 078/347] rename and move dict files --- .gitignore | 2 +- client/Makefile | 7 ++++--- client/cmdflashmem.c | 6 +++--- client/cmdhficlass.c | 8 ++++---- client/cmdlft55xx.c | 2 +- .../iclass_default_keys.dic} | 0 .../mfc_default_keys.dic} | 2 +- .../{bmp_sort_keys.dic => mfc_keys_bmp_sorted.dic} | 0 ...bpm_sort_keys.dic => mfc_keys_icbmp_sorted.dic} | 0 ...mrzd_sort_keys.dic => mfc_keys_mrzd_sorted.dic} | 0 .../mfulc_default_keys.dic} | 0 .../t55xx_default_pwds.dic} | 0 client/luascripts/{mfkeys.lua => mfckeys.lua} | 10 +++++----- client/scripting.c | 2 +- doc/cheatsheet.md | 14 +++++++------- .../2_Configuration-and-Verification.md | 6 +++--- 16 files changed, 30 insertions(+), 29 deletions(-) rename client/{default_iclass_keys.dic => dictionaries/iclass_default_keys.dic} (100%) rename client/{default_keys.dic => dictionaries/mfc_default_keys.dic} (99%) rename client/dictionaries/{bmp_sort_keys.dic => mfc_keys_bmp_sorted.dic} (100%) rename client/dictionaries/{icbpm_sort_keys.dic => mfc_keys_icbmp_sorted.dic} (100%) rename client/dictionaries/{mrzd_sort_keys.dic => mfc_keys_mrzd_sorted.dic} (100%) rename client/{default_ultralight_keys.dic => dictionaries/mfulc_default_keys.dic} (100%) rename client/{default_pwd.dic => dictionaries/t55xx_default_pwds.dic} (100%) rename client/luascripts/{mfkeys.lua => mfckeys.lua} (96%) diff --git a/.gitignore b/.gitignore index f61e85eb9..5b45564b3 100644 --- a/.gitignore +++ b/.gitignore @@ -71,7 +71,7 @@ tools/jtag_openocd/openocd_configuration ppls patches/* *- Copy.* -client/lualibs/mf_default_keys.lua +client/lualibs/mfc_default_keys.lua client/lualibs/pm3_cmd.lua # recompiled fpga_version_info.c diff --git a/client/Makefile b/client/Makefile index e54e708e6..f33c1ae9e 100644 --- a/client/Makefile +++ b/client/Makefile @@ -32,6 +32,7 @@ platform = $(shell uname) ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) VPATH = ../common uart +vpath %.dic dictionaries OBJDIR = obj LDLIBS ?= -L/usr/local/lib @@ -290,7 +291,7 @@ ifeq "$(SUPPORTS_AVX512)" "True" endif BINS = proxmark3 flasher -CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua +CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua # need to assign dependancies to build these first... all: $(BINS) @@ -299,7 +300,7 @@ all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(QTLDLIBS) -proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) lualibs/pm3_cmd.lua lualibs/mf_default_keys.lua +proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua $(info [=] LD $@) $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LDLIBS) -o $@ @@ -321,7 +322,7 @@ lualibs/pm3_cmd.lua: ../include/pm3_cmd.h $(info [=] GEN $@) $(Q)awk -f pm3_cmd_h2lua.awk $^ > $@ -lualibs/mf_default_keys.lua : default_keys.dic +lualibs/mfc_default_keys.lua : mfc_default_keys.dic $(info [=] GEN $@) $(Q)awk -f default_keys_dic2lua.awk $^ > $@ diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index a89d2eae6..905e6c6c8 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -59,9 +59,9 @@ static int usage_flashmem_load(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " mem load f myfile"); // upload file myfile at default offset 0 PrintAndLogEx(NORMAL, " mem load f myfile o 1024"); // upload file myfile at offset 1024 - PrintAndLogEx(NORMAL, " mem load f default_keys m"); - PrintAndLogEx(NORMAL, " mem load f default_pwd t"); - PrintAndLogEx(NORMAL, " mem load f default_iclass_keys i"); + PrintAndLogEx(NORMAL, " mem load f dictionaries/mfc_default_keys m"); + PrintAndLogEx(NORMAL, " mem load f dictionaries/t55xx_default_pwds t"); + PrintAndLogEx(NORMAL, " mem load f dictionaries/iclass_default_keys i"); return PM3_SUCCESS; } static int usage_flashmem_dump(void) { diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 3cbbd1a67..4b815355b 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -244,8 +244,8 @@ static int usage_hf_iclass_chk(void) { PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, " c credit key (if not use, default is debit)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf iclass chk f default_iclass_keys.dic"); - PrintAndLogEx(NORMAL, " hf iclass chk f default_iclass_keys.dic e"); + PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic"); + PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic e"); return 0; } static int usage_hf_iclass_lookup(void) { @@ -260,8 +260,8 @@ static int usage_hf_iclass_lookup(void) { PrintAndLogEx(NORMAL, " r raw"); PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f default_iclass_keys.dic"); - PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f default_iclass_keys.dic e"); + PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic"); + PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic e"); return 0; } static int usage_hf_iclass_permutekey(void) { diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 3c88a23ea..058645320 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -206,7 +206,7 @@ static int usage_t55xx_chk() { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf t55xx chk m"); - PrintAndLogEx(NORMAL, " lf t55xx chk i default_pwd.dic"); + PrintAndLogEx(NORMAL, " lf t55xx chk i dictionaries/t55xx_default_pwds.dic"); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } diff --git a/client/default_iclass_keys.dic b/client/dictionaries/iclass_default_keys.dic similarity index 100% rename from client/default_iclass_keys.dic rename to client/dictionaries/iclass_default_keys.dic diff --git a/client/default_keys.dic b/client/dictionaries/mfc_default_keys.dic similarity index 99% rename from client/default_keys.dic rename to client/dictionaries/mfc_default_keys.dic index 54c355de4..c33736806 100644 --- a/client/default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -22,7 +22,7 @@ a0478cc39091, # d2ece8b9395e, //lib # -# more Keys from mf_default_keys.lua +# more Keys from mfc_default_keys.lua 000000000001, 000000000002, 00000000000a, diff --git a/client/dictionaries/bmp_sort_keys.dic b/client/dictionaries/mfc_keys_bmp_sorted.dic similarity index 100% rename from client/dictionaries/bmp_sort_keys.dic rename to client/dictionaries/mfc_keys_bmp_sorted.dic diff --git a/client/dictionaries/icbpm_sort_keys.dic b/client/dictionaries/mfc_keys_icbmp_sorted.dic similarity index 100% rename from client/dictionaries/icbpm_sort_keys.dic rename to client/dictionaries/mfc_keys_icbmp_sorted.dic diff --git a/client/dictionaries/mrzd_sort_keys.dic b/client/dictionaries/mfc_keys_mrzd_sorted.dic similarity index 100% rename from client/dictionaries/mrzd_sort_keys.dic rename to client/dictionaries/mfc_keys_mrzd_sorted.dic diff --git a/client/default_ultralight_keys.dic b/client/dictionaries/mfulc_default_keys.dic similarity index 100% rename from client/default_ultralight_keys.dic rename to client/dictionaries/mfulc_default_keys.dic diff --git a/client/default_pwd.dic b/client/dictionaries/t55xx_default_pwds.dic similarity index 100% rename from client/default_pwd.dic rename to client/dictionaries/t55xx_default_pwds.dic diff --git a/client/luascripts/mfkeys.lua b/client/luascripts/mfckeys.lua similarity index 96% rename from client/luascripts/mfkeys.lua rename to client/luascripts/mfckeys.lua index f15bb6d5e..128967c37 100644 --- a/client/luascripts/mfkeys.lua +++ b/client/luascripts/mfckeys.lua @@ -9,7 +9,7 @@ Copyright (C) 2013 m h swende --]] local cmds = require('commands') -local keylist = require('mf_default_keys') +local keylist = require('mfc_default_keys') local lib14a = require('read14a') local getopt = require('getopt') local utils = require('utils') @@ -19,9 +19,9 @@ author = "Holiman" version = 'v1.0.1' desc = ("This script implements Mifare check keys.\ It utilises a large list of default keys (currently %d keys).\ -If you want to add more, just put them inside /lualibs/mf_default_keys.lua\n"):format(#keylist) +If you want to add more, just put them inside /lualibs/mfc_default_keys.lua\n"):format(#keylist) example = [[ - 1. script run mfkeys + 1. script run mfckeys ]] usage = [[ Arguments: @@ -54,7 +54,7 @@ end -- waits for answer from pm3 device local function checkCommand(response) if not response then - print("Timeout while waiting for response. Increase TIMEOUT in mfkeys.lua to wait longer") + print("Timeout while waiting for response. Increase TIMEOUT in mfckeys.lua to wait longer") return nil, "Timeout while waiting for device to respond" end @@ -230,7 +230,7 @@ local function perform_check(numsectors) local end_time = os.time() print('') - print('[+] mfkeys - Checkkey execution time: '..os.difftime(end_time, start_time)..' sec') + print('[+] mfckeys - Checkkey execution time: '..os.difftime(end_time, start_time)..' sec') core.fast_push_mode(false) diff --git a/client/scripting.c b/client/scripting.c index 1f6c61ff8..596b535fa 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -50,7 +50,7 @@ static int l_clearCommandBuffer(lua_State *L) { } /** - * Enable / Disable fast push mode for lua scripts like mfkeys + * Enable / Disable fast push mode for lua scripts like mfckeys * The following params expected: * *@brief l_fast_push_mode diff --git a/doc/cheatsheet.md b/doc/cheatsheet.md index f143438c4..75c554e94 100644 --- a/doc/cheatsheet.md +++ b/doc/cheatsheet.md @@ -166,7 +166,7 @@ p : EPURSE m : macs e : elite -pm3 --> hf iclass lookup u 010a0ffff7ff12e0 p feffffffffffffff m 66348979153c41b9 f default_iclass_keys.dic e +pm3 --> hf iclass lookup u 010a0ffff7ff12e0 p feffffffffffffff m 66348979153c41b9 f dictionaries/iclass_default_keys.dic e ``` ## Mifare @@ -181,7 +181,7 @@ Options card memory : 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K d : write keys to binary file -pm3 --> hf mf chk *1 ? d default_keys.dic +pm3 --> hf mf chk *1 ? d dictionaries/mfc_default_keys.dic ``` Check for default keys from local memory @@ -254,7 +254,7 @@ pm3 --> hf mf sim u 353c2aa6 Simulate Mifare Sequence ``` -pm3 --> hf mf chk *1 ? d default_keys.dic +pm3 --> hf mf chk *1 ? d dictionaries/mfc_default_keys.dic pm3 --> hf mf dump 1 pm3 --> script run dumptoemul -i dumpdata.bin pm3 --> hf mf eload 353C2AA6 @@ -263,7 +263,7 @@ pm3 --> hf mf sim u 353c2aa6 Clone Mifare 1K Sequence ``` -pm3 --> hf mf chk *1 ? d default_keys.dic +pm3 --> hf mf chk *1 ? d dictionaries/mfc_default_keys.dic pm3 --> hf mf dump pm3 --> hf mf restore 1 u 4A6CE843 k hf-mf-A29558E4-key.bin f hf-mf-A29558E4-data.bin ``` @@ -512,9 +512,9 @@ m : upload 6 bytes keys (mifare key dictionary) i : upload 8 bytes keys (iClass key dictionary) t : upload 4 bytes keys (pwd dictionary) -pm3 --> mem load f default_keys m -pm3 --> mem load f default_pwd t -pm3 --> mem load f default_iclass_keys i +pm3 --> mem load f dictionaries/mfc_default_keys m +pm3 --> mem load f dictionaries/t55xx_default_pwds t +pm3 --> mem load f dictionaries/iclass_default_keys i ``` ## Sim Module diff --git a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md index 0d3665f37..84f64821c 100644 --- a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md +++ b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md @@ -1,9 +1,9 @@ ### First things on your RDV40 You will need to run these commands to make sure your rdv4 is prepared ``` -pm3 --> mem load f default_keys m -pm3 --> mem load f default_pwd t -pm3 --> mem load f default_iclass_keys i +pm3 --> mem load f dictionaries/mfc_default_keys m +pm3 --> mem load f dictionaries/t55xx_default_pwds t +pm3 --> mem load f dictionaries/iclass_default_keys i pm3 --> lf t55xx deviceconfig a 29 b 17 c 15 d 47 e 15 p pm3 --> lf t55xx deviceconfig r 1 a 31 b 20 c 18 d 50 e 15 p pm3 --> lf t55xx deviceconfig r 2 a 31 b 20 c 18 d 40 e 15 p From 77c86099cc19a9ae974dc8b3984c6031b24df248 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 22:58:16 +0200 Subject: [PATCH 079/347] clean and uniformise dic files --- client/dictionaries/iclass_default_keys.dic | 15 +- client/dictionaries/mfc_default_keys.dic | 1584 ++++++------- client/dictionaries/mfc_keys_bmp_sorted.dic | 2000 ++++++++-------- client/dictionaries/mfc_keys_icbmp_sorted.dic | 2001 ++++++++--------- client/dictionaries/mfc_keys_mrzd_sorted.dic | 114 +- client/dictionaries/mfulc_default_keys.dic | 3 +- client/dictionaries/t55xx_default_pwds.dic | 222 +- 7 files changed, 2970 insertions(+), 2969 deletions(-) diff --git a/client/dictionaries/iclass_default_keys.dic b/client/dictionaries/iclass_default_keys.dic index 829ba521e..22e1ee653 100644 --- a/client/dictionaries/iclass_default_keys.dic +++ b/client/dictionaries/iclass_default_keys.dic @@ -2,10 +2,11 @@ # iClass Default Keys # -- iceman fork version -- # -- contribute to this list, sharing is caring -- -AEA684A6DAB23278 -- AA1 -7665544332211000 -- key1/Kc from PicoPass 2k documentation -0123456789ABCDEF -- SAGEM -5b7c62c491c11b39 -- from loclass demo file. -F0E1D2C3B4A59687 -- Kd from PicoPass 2k documentation -5CBCF1DA45D5FB4F -- PicoPass Default Exchange Key -31ad7ebd2f282168 -- From HID multiclassSE reader +# +AEA684A6DAB23278 # AA1 +7665544332211000 # key1/Kc from PicoPass 2k documentation +0123456789ABCDEF # SAGEM +5b7c62c491c11b39 # from loclass demo file. +F0E1D2C3B4A59687 # Kd from PicoPass 2k documentation +5CBCF1DA45D5FB4F # PicoPass Default Exchange Key +31ad7ebd2f282168 # From HID multiclassSE reader diff --git a/client/dictionaries/mfc_default_keys.dic b/client/dictionaries/mfc_default_keys.dic index c33736806..4b1430c2f 100644 --- a/client/dictionaries/mfc_default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -3,922 +3,922 @@ # -- iceman fork version -- # -- contribute to this list, sharing is caring -- # -ffffffffffff,//Defaultkey(firstkeyusedbyprogramifnouserdefinedkey) -000000000000,//Blankkey -a0a1a2a3a4a5,//NFCForumMADkey -b0b1b2b3b4b5, -c0c1c2c3c4c5, -d0d1d2d3d4d5, -aabbccddeeff, -4d3a99c351dd, -1a982c7e459a, -d3f7d3f7d3f7,// key A Wien -5a1b85fce20a,// key B Wien -714c5c886e97, -587ee5f9350f, -a0478cc39091, -533cb6c723f6, -8fd0a4f256e9, +ffffffffffff # Defaultkey(firstkeyusedbyprogramifnouserdefinedkey) +000000000000 # Blankkey +a0a1a2a3a4a5 # NFCForumMADkey +b0b1b2b3b4b5 +c0c1c2c3c4c5 +d0d1d2d3d4d5 +aabbccddeeff +4d3a99c351dd +1a982c7e459a +d3f7d3f7d3f7 # key A Wien +5a1b85fce20a # key B Wien +714c5c886e97 +587ee5f9350f +a0478cc39091 +533cb6c723f6 +8fd0a4f256e9 # -d2ece8b9395e, //lib +d2ece8b9395e # lib # # more Keys from mfc_default_keys.lua -000000000001, -000000000002, -00000000000a, -00000000000b, -00000ffe2488,--VästtrafikenKeyB -010203040506, -0123456789ab, -0297927c0f77,--VästtrafikenKeyA -100000000000, -111111111111, -123456789abc, -12f2ee3478c1, -14d446e33363, -1999a3554a55, -200000000000, -222222222222, -26940b21ff5d,--RKFSLKeyA -27dd91f1fcf1, -2BA9621E0A36,--DirectoryandeventlogKeyB -333333333333, -33f974b42769, -34d1df9934c5, -434f4d4d4f41,--RKFJOJOGROUPKeyA -434f4d4d4f42,--RKFJOJOGROUPKeyB -43ab19ef5c31, -444444444444, -47524f555041,--RKFJOJOGROUPKeyA -47524f555042,--RKFJOJOGROUPKeyB -4AF9D7ADEBE4,--DirectoryandeventlogKeyA -4b0b20107ccb,--TNP3xxx -505249564141,--RKFJOJOPRIVAKeyA -505249564142,--RKFJOJOPRIVAKeyB -505249565441, -505249565442, -54726176656c,--VästtrafikenKeyA -555555555555, -55f5a5dd38c9, -569369c5a0e5,--kiev -5c598c9c58b5,--RKFSLKeyB -632193be1c3c,--kiev -644672bd4afe,--kiev -666666666666, -722bfcc5375f,--RKFRejskortDanmarkKeyA -776974687573,--VästtrafikenKeyB -777777777777, -888888888888, -8fe644038790,--kiev -999999999999, -99c636334433, -9de89e070277,--kiev -a00000000000, -a053a292a4af, -a64598a77478,--RKFSLKeyA -a94133013401, -aaaaaaaaaaaa, -abcdef123456,--Keyfromladyada.net -b00000000000, -b127c6f41436, -b5ff67cba951,--kiev -bbbbbbbbbbbb, -bd493a3962b6, -c934fe34d934, -cccccccccccc, -dddddddddddd, -e4d2770a89be,--RKFSLKeyB -ee0042f88840,--VästtrafikenKeyB -eeeeeeeeeeee, -eff603e1efe9,--kiev -f14ee7cae863,--kiev -f1a97341a9fc, -f1d83f964314,--RKFRejskortDanmarkKeyB -fc00018778f7,--VästtrafikenKeyA, RKFÖstgötaTrafikenKeyA -44ab09010845,-- hotel system -85fed980ea5a,-- hotel system -314B49474956 --VIGIK1 A -564c505f4d41 --VIGIK1 B -ba5b895da162 --VIGIK1 B +000000000001 +000000000002 +00000000000a +00000000000b +00000ffe2488 # VästtrafikenKeyB +010203040506 +0123456789ab +0297927c0f77 # VästtrafikenKeyA +100000000000 +111111111111 +123456789abc +12f2ee3478c1 +14d446e33363 +1999a3554a55 +200000000000 +222222222222 +26940b21ff5d # RKFSLKeyA +27dd91f1fcf1 +2BA9621E0A36 # DirectoryandeventlogKeyB +333333333333 +33f974b42769 +34d1df9934c5 +434f4d4d4f41 # RKFJOJOGROUPKeyA +434f4d4d4f42 # RKFJOJOGROUPKeyB +43ab19ef5c31 +444444444444 +47524f555041 # RKFJOJOGROUPKeyA +47524f555042 # RKFJOJOGROUPKeyB +4AF9D7ADEBE4 # DirectoryandeventlogKeyA +4b0b20107ccb # TNP3xxx +505249564141 # RKFJOJOPRIVAKeyA +505249564142 # RKFJOJOPRIVAKeyB +505249565441 +505249565442 +54726176656c # VästtrafikenKeyA +555555555555 +55f5a5dd38c9 +569369c5a0e5 # kiev +5c598c9c58b5 # RKFSLKeyB +632193be1c3c # kiev +644672bd4afe # kiev +666666666666 +722bfcc5375f # RKFRejskortDanmarkKeyA +776974687573 # VästtrafikenKeyB +777777777777 +888888888888 +8fe644038790 # kiev +999999999999 +99c636334433 +9de89e070277 # kiev +a00000000000 +a053a292a4af +a64598a77478 # RKFSLKeyA +a94133013401 +aaaaaaaaaaaa +abcdef123456 # Keyfromladyada.net +b00000000000 +b127c6f41436 +b5ff67cba951 # kiev +bbbbbbbbbbbb +bd493a3962b6 +c934fe34d934 +cccccccccccc +dddddddddddd +e4d2770a89be # RKFSLKeyB +ee0042f88840 # VästtrafikenKeyB +eeeeeeeeeeee +eff603e1efe9 # kiev +f14ee7cae863 # kiev +f1a97341a9fc +f1d83f964314 # RKFRejskortDanmarkKeyB +fc00018778f7 # VästtrafikenKeyA, RKFÖstgötaTrafikenKeyA +44ab09010845 # hotel system +85fed980ea5a # hotel system +314B49474956 # VIGIK1 A +564c505f4d41 # VIGIK1 B +ba5b895da162 # VIGIK1 B # Vigik mystery Keys Mifare 1k EV1 (S50) -5c8ff9990da2, 16 A -75ccb59c9bed, 17 A -d01afeeb890a, 16 B -4b791bea7bcc, 17 B +5c8ff9990da2 # 16 A +75ccb59c9bed # 17 A +d01afeeb890a # 16 B +4b791bea7bcc # 17 B # -4143414F5250, -a9b43414F585,--Tehran Railway -1FB235AC1388,--Tehran Railway +4143414F5250 +a9b43414F585 # Tehran Railway +1FB235AC1388 # Tehran Railway # -# Data from: http://irq5.io/2013/04/13/decoding-bcard-conference-badges/ -f4a9ef2afc6d,--BCARD KeyB +# Data from http://irq5.io/2013/04/13/decoding-bcard-conference-badges/ +f4a9ef2afc6d # BCARD KeyB # -# Data from: ... -89eac97f8c2a // S0 B -43c7600dee6b // S4 A -0120bf672a64 // S6 A -fb0b20df1f34 // S6 B +# Data from ... +89eac97f8c2a # S0 B +43c7600dee6b # S4 A +0120bf672a64 # S6 A +fb0b20df1f34 # S6 B # -a9f953def0a3, +a9f953def0a3 # # Here be BIP keys... -3A42F33AF429, -1FC235AC1309, -6338A371C0ED, -243F160918D1, -F124C2578AD0, -9AFC42372AF1, -32AC3B90AC13, -682D401ABB09, -4AD1E273EAF1, -067DB45454A9, -E2C42591368A, -15FC4C7613FE, -2A3C347A1200, -68D30288910A, -16F3D5AB1139, -F59A36A2546D, -937A4FFF3011, -64E3C10394C2, -35C3D2CAEE88, -B736412614AF, -693143F10368, -324F5DF65310, -A3F97428DD01, -643FB6DE2217, -63F17A449AF0, -82F435DEDF01, -C4652C54261C, -0263DE1278F3, -D49E2826664F, -51284C3686A6, -3DF14C8000A1, -6A470D54127C, +3A42F33AF429 +1FC235AC1309 +6338A371C0ED +243F160918D1 +F124C2578AD0 +9AFC42372AF1 +32AC3B90AC13 +682D401ABB09 +4AD1E273EAF1 +067DB45454A9 +E2C42591368A +15FC4C7613FE +2A3C347A1200 +68D30288910A +16F3D5AB1139 +F59A36A2546D +937A4FFF3011 +64E3C10394C2 +35C3D2CAEE88 +B736412614AF +693143F10368 +324F5DF65310 +A3F97428DD01 +643FB6DE2217 +63F17A449AF0 +82F435DEDF01 +C4652C54261C +0263DE1278F3 +D49E2826664F +51284C3686A6 +3DF14C8000A1 +6A470D54127C # -# Data from: http://pastebin.com/AK9Bftpw -48ffe71294a0, -- Länstrafiken i Västerbotten -e3429281efc1, -- Länstrafiken i Västerbotten -16f21a82ec84, -- Länstrafiken i Västerbotten -460722122510, -- Länstrafiken i Västerbotten +# Data from http://pastebin.com/AK9Bftpw +48ffe71294a0 # Länstrafiken i Västerbotten +e3429281efc1 # Länstrafiken i Västerbotten +16f21a82ec84 # Länstrafiken i Västerbotten +460722122510 # Länstrafiken i Västerbotten # # 3dprinter -AAFB06045877, --EPI Envisionte# 3dprinter +AAFB06045877 # EPI Envisionte# 3dprinter # # gym -3e65e4fb65b3, --Fysiken A -25094df6f148, --Fysiken B -a05dbd98e0fc, -- CleverFit +3e65e4fb65b3 # Fysiken A +25094df6f148 # Fysiken B +a05dbd98e0fc # CleverFit # -d3b595e9dd63, -- Hotel KeyCard -afbecd121004, -- Hotel KeyCard -6471a5ef2d1a, -- SimonsVoss +d3b595e9dd63 # Hotel KeyCard +afbecd121004 # Hotel KeyCard +6471a5ef2d1a # SimonsVoss # # 24-7 -D21762B2DE3B, -0E83A374B513, -1F1FFE000000, -A10F303FC879, -1322285230b8, -0C71BCFB7E72, -C3C88C6340B8, -F101622750B7, -1F107328DC8D, -710732200D34, -7C335FB121B5, -B39AE17435DC, +D21762B2DE3B +0E83A374B513 +1F1FFE000000 +A10F303FC879 +1322285230b8 +0C71BCFB7E72 +C3C88C6340B8 +F101622750B7 +1F107328DC8D +710732200D34 +7C335FB121B5 +B39AE17435DC # # -454841585443, -- key A +454841585443 # key A # -# Data from: http://pastebin.com/gQ6nk38G -D39BB83F5297, -85675B200017, -528C9DFFE28C, -C82EC29E3235, -3E3554AF0E12, -491CDCFB7752, -22C1BAE1AACD, -5F146716E373, -740E9A4F9AAF, -AC0E24C75527, -97184D136233, -E444D53D359F, -17758856B182, -A8966C7CC54B, -C6AD00254562, -AE3FF4EEA0DB, -5EB8F884C8D1, -FEE470A4CB58, -75D8690F21B6, -871B8C085997, -97D1101F18B0, -75EDE6A84460, -DF27A8F1CB8E, -B0C9DD55DD4D, +# Data from http://pastebin.com/gQ6nk38G +D39BB83F5297 +85675B200017 +528C9DFFE28C +C82EC29E3235 +3E3554AF0E12 +491CDCFB7752 +22C1BAE1AACD +5F146716E373 +740E9A4F9AAF +AC0E24C75527 +97184D136233 +E444D53D359F +17758856B182 +A8966C7CC54B +C6AD00254562 +AE3FF4EEA0DB +5EB8F884C8D1 +FEE470A4CB58 +75D8690F21B6 +871B8C085997 +97D1101F18B0 +75EDE6A84460 +DF27A8F1CB8E +B0C9DD55DD4D # -# Data from: http://bit.ly/1bdSbJl -A0B0C0D0E0F0, -A1B1C1D1E1F1, +# Data from http://bit.ly/1bdSbJl +A0B0C0D0E0F0 +A1B1C1D1E1F1 # -# Data from: msk social -2735fc181807, -2aba9519f574, -84fd7f7a12b6, -186d8c4b93f9, -3a4bba8adaf0, -8765b17968a2, -40ead80721ce, -0db5e6523f7c, -51119dae5216, -83e3549ce42d, -136bdb246cac, -7de02a7f6025, -bf23a53c1f63, -cb9a1f2d7368, -c7c0adb3284f, -9f131d8c2057, -67362d90f973, -6202a38f69e2, -100533b89331, -653a87594079, -d8a274b2e026, -b20b83cb145c, -9afa6cb4fc3d, +# Data from msk social +2735fc181807 +2aba9519f574 +84fd7f7a12b6 +186d8c4b93f9 +3a4bba8adaf0 +8765b17968a2 +40ead80721ce +0db5e6523f7c +51119dae5216 +83e3549ce42d +136bdb246cac +7de02a7f6025 +bf23a53c1f63 +cb9a1f2d7368 +c7c0adb3284f +9f131d8c2057 +67362d90f973 +6202a38f69e2 +100533b89331 +653a87594079 +d8a274b2e026 +b20b83cb145c +9afa6cb4fc3d # # Data from http://pastebin.com/RRJUEDCM -0d258fe90296, -e55a3ca71826, -a4f204203f56, -eeb420209d0c, -911e52fd7ce4, -752fbb5b7b45, -66b03aca6ee9, -48734389edc3, -17193709adf4, -1acc3189578c, -c2b7ec7d4eb1, -369a4663acd2, +0d258fe90296 +e55a3ca71826 +a4f204203f56 +eeb420209d0c +911e52fd7ce4 +752fbb5b7b45 +66b03aca6ee9 +48734389edc3 +17193709adf4 +1acc3189578c +c2b7ec7d4eb1 +369a4663acd2 # # Data from https://github.com/zhangjingye03/zxcardumper # zxcard Key A/B -668770666644, -003003003003, +668770666644 +003003003003 # -# Data from: http://phreakerclub.com/forum/showthread.php?p=41266 -26973ea74321, -71f3a315ad26, -51044efb5aab, -ac70ca327a04, -eb0a8ff88ade, +# Data from http://phreakerclub.com/forum/showthread.php?p=41266 +26973ea74321 +71f3a315ad26 +51044efb5aab +ac70ca327a04 +eb0a8ff88ade # -# Data from: https://github.com/RadioWar/NFCGUI -44dd5a385aaf, -21a600056cb0, -b1aca33180a5, -dd61eb6bce22, -1565a172770f, -3e84d2612e2a, -f23442436765, -79674f96c771, -87df99d496cb, -c5132c8980bc, -a21680c27773, -f26e21edcee2, -675557ecc92e, -f4396e468114, -6db17c16b35b, -4186562a5bb2, -2feae851c199, -db1a3338b2eb, -157b10d84c6b, -a643f952ea57, -df37dcb6afb3, -4c32baf326e0, -91ce16c07ac5, -3c5d1c2bcd18, -c3f19ec592a2, -f72a29005459, -185fa3438949, -321a695bd266, -d327083a60a7, -45635ef66ef3, -5481986d2d62, -cba6ae869ad5, -645a166b1eeb, -a7abbc77cc9e, -f792c4c76a5c, -bfb6796a11db, +# Data from https://github.com/RadioWar/NFCGUI +44dd5a385aaf +21a600056cb0 +b1aca33180a5 +dd61eb6bce22 +1565a172770f +3e84d2612e2a +f23442436765 +79674f96c771 +87df99d496cb +c5132c8980bc +a21680c27773 +f26e21edcee2 +675557ecc92e +f4396e468114 +6db17c16b35b +4186562a5bb2 +2feae851c199 +db1a3338b2eb +157b10d84c6b +a643f952ea57 +df37dcb6afb3 +4c32baf326e0 +91ce16c07ac5 +3c5d1c2bcd18 +c3f19ec592a2 +f72a29005459 +185fa3438949 +321a695bd266 +d327083a60a7 +45635ef66ef3 +5481986d2d62 +cba6ae869ad5 +645a166b1eeb +a7abbc77cc9e +f792c4c76a5c +bfb6796a11db # # Data from Salto A/B -6A1987C40A21, -7F33625BC129, +6A1987C40A21 +7F33625BC129 # # Data from forum -2338b4913111, +2338b4913111 # # Data from stoye -cb779c50e1bd, -a27d3804c259, -003cc420001a, -f9861526130f, -381ece050fbd, -a57186bdd2b9, -48c739e21a04, -36abf5874ed7, -649d2abbbd20, -bbe8fffcf363, -ab4e7045e97d, -340e40f81cd8, -e4f65c0ef32c, -d2a597d76936, -a920f32fe93a, -86afd95200f7, -9b832a9881ff, -26643965b16e, -0c669993c776, -b468d1991af9, -d9a37831dce5, -2fc1f32f51b1, -0ffbf65b5a14, -c5cfe06d9ea3, -c0dece673829, +cb779c50e1bd +a27d3804c259 +003cc420001a +f9861526130f +381ece050fbd +a57186bdd2b9 +48c739e21a04 +36abf5874ed7 +649d2abbbd20 +bbe8fffcf363 +ab4e7045e97d +340e40f81cd8 +e4f65c0ef32c +d2a597d76936 +a920f32fe93a +86afd95200f7 +9b832a9881ff +26643965b16e +0c669993c776 +b468d1991af9 +d9a37831dce5 +2fc1f32f51b1 +0ffbf65b5a14 +c5cfe06d9ea3 +c0dece673829 # -a56c2df9a26d, +a56c2df9a26d # -# Data from: https://pastebin.com/vbwast74 +# Data from https://pastebin.com/vbwast74 # -68d3f7307c89, -568c9083f71c,--Smart Rider. Western Australian Public Transport Cards +68d3f7307c89 +568c9083f71c # Smart Rider. Western Australian Public Transport Cards # Vigik Keys # Various sources : # * https://github.com/DumpDos/Vigik # * http://newffr.com/viewtopic.php?&forum=235&topic=11559 # * Own dumps -021209197591, // BTCINO UNDETERMINED SPREAKD 0x01->0x13 key -2ef720f2af76, -414c41524f4e, -424c41524f4e, -4a6352684677, -bf1f4424af76, -536653644c65, +021209197591 # BTCINO UNDETERMINED SPREAKD 0x01->0x13 key +2ef720f2af76 +414c41524f4e +424c41524f4e +4a6352684677 +bf1f4424af76 +536653644c65 # # Intratone Cogelec # Data from http://bouzdeck.com/rfid/32-cloning-a-mifare-classic-1k-tag.html -484558414354, -a22ae129c013, -49fae4e3849f, -38fcf33072e0, -8ad5517b4b18, -509359f131b1, -6c78928e1317, -aa0720018738, -a6cac2886412, -62d0c424ed8e, -e64a986a5d94, -8fa1d601d0a2, -89347350bd36, -66d2b7dc39ef, -6bc1e1ae547d, -22729a9bd40f, +484558414354 +a22ae129c013 +49fae4e3849f +38fcf33072e0 +8ad5517b4b18 +509359f131b1 +6c78928e1317 +aa0720018738 +a6cac2886412 +62d0c424ed8e +e64a986a5d94 +8fa1d601d0a2 +89347350bd36 +66d2b7dc39ef +6bc1e1ae547d +22729a9bd40f # # Data from https://dfir.lu/blog/cloning-a-mifare-classic-1k-tag.html -925b158f796f, -fad63ecb5891, -bba840ba1c57, -cc6b3b3cd263, -6245e47352e6, -8ed41e8b8056, -2dd39a54e1f3, -6d4c5b3658d2, -1877ed29435a, -52264716efde, -961c0db4a7ed, -703140fd6d86, -157c9a513fa5, -e2a5dc8e066f, +925b158f796f +fad63ecb5891 +bba840ba1c57 +cc6b3b3cd263 +6245e47352e6 +8ed41e8b8056 +2dd39a54e1f3 +6d4c5b3658d2 +1877ed29435a +52264716efde +961c0db4a7ed +703140fd6d86 +157c9a513fa5 +e2a5dc8e066f # # Data from a oyster card -374bf468607f, -bfc8e353af63, -15cafd6159f6, -62efd80ab715, -987a7f7f1a35, -c4104fa3c526, -4c961f23e6be, -67546972bc69, -f4cd5d4c13ff, -94414c1a07dc, -16551d52fd20, -9cb290282f7d, -77a84170b574, -ed646c83a4f3, -e703589db50b, -513c85d06cde, -95093f0b2e22, -543b01b27a95, -c6d375b99972, -ee4cc572b40e, -5106ca7e4a69, -c96bd1ce607f, -167a1be102e0, -a8d0d850a606, -a2abb693ce34, -7b296c40c486, -91f93a5564c9, -e10623e7a016, -b725f9cbf183, +374bf468607f +bfc8e353af63 +15cafd6159f6 +62efd80ab715 +987a7f7f1a35 +c4104fa3c526 +4c961f23e6be +67546972bc69 +f4cd5d4c13ff +94414c1a07dc +16551d52fd20 +9cb290282f7d +77a84170b574 +ed646c83a4f3 +e703589db50b +513c85d06cde +95093f0b2e22 +543b01b27a95 +c6d375b99972 +ee4cc572b40e +5106ca7e4a69 +c96bd1ce607f +167a1be102e0 +a8d0d850a606 +a2abb693ce34 +7b296c40c486 +91f93a5564c9 +e10623e7a016 +b725f9cbf183 # # Data from FDi tag -8829da9daf76, +8829da9daf76 # # Data from GitHub issue -0A7932DC7E65, -11428B5BCE06, -11428B5BCE07, -11428B5BCE08, -11428B5BCE09, -11428B5BCE0A, -11428B5BCE0F, -18971D893494, -25D60050BF6E, -3FA7217EC575, -44F0B5FBE344, -7B296F353C6B, -8553263F4FF0, -8E5D33A6ED51, -9F42971E8322, -C620318EF179, -D4FE03CE5B06, -D4FE03CE5B07, -D4FE03CE5B08, -D4FE03CE5B09, -D4FE03CE5B0A, -D4FE03CE5B0F, -E241E8AFCBAF, +0A7932DC7E65 +11428B5BCE06 +11428B5BCE07 +11428B5BCE08 +11428B5BCE09 +11428B5BCE0A +11428B5BCE0F +18971D893494 +25D60050BF6E +3FA7217EC575 +44F0B5FBE344 +7B296F353C6B +8553263F4FF0 +8E5D33A6ED51 +9F42971E8322 +C620318EF179 +D4FE03CE5B06 +D4FE03CE5B07 +D4FE03CE5B08 +D4FE03CE5B09 +D4FE03CE5B0A +D4FE03CE5B0F +E241E8AFCBAF # # Data from forum post -123F8888F322, -050908080008, +123F8888F322 +050908080008 # # Data from hoist -4f9f59c9c875, +4f9f59c9c875 # # Data from pastebin -66f3ed00fed7, -f7a39753d018, +66f3ed00fed7 +f7a39753d018 # # Data from https://pastebin.com/Z7pEeZif -386B4D634A65, -666E564F4A44, -564777315276, -476242304C53, -6A696B646631, -4D3248735131, -425A73484166, -57784A533069, -345547514B4D, -4C6B69723461, -4E4175623670, -4D5076656D58, -686A736A356E, -484A57696F4A, -6F4B6D644178, -744E326B3441, -70564650584F, -584F66326877, -6D4E334B6C48, -6A676C315142, -77494C526339, -623055724556, -356D46474348, -4E32336C6E38, -57734F6F6974, -436A46587552, -5544564E6E67, -6F506F493353, -31646241686C, -77646B633657, +386B4D634A65 +666E564F4A44 +564777315276 +476242304C53 +6A696B646631 +4D3248735131 +425A73484166 +57784A533069 +345547514B4D +4C6B69723461 +4E4175623670 +4D5076656D58 +686A736A356E +484A57696F4A +6F4B6D644178 +744E326B3441 +70564650584F +584F66326877 +6D4E334B6C48 +6A676C315142 +77494C526339 +623055724556 +356D46474348 +4E32336C6E38 +57734F6F6974 +436A46587552 +5544564E6E67 +6F506F493353 +31646241686C +77646B633657 # # Data from TransPert -2031d1e57a3b, -53c11f90822a, -9189449ea24e, +2031d1e57a3b +53c11f90822a +9189449ea24e # # data from Github -410b9b40b872, -2cb1a90071c8, +410b9b40b872 +2cb1a90071c8 # # data from -8697389ACA26, -1AB23CD45EF6, -013889343891, +8697389ACA26 +1AB23CD45EF6 +013889343891 # # -0000000018de, -16ddcb6b3f24, +0000000018de +16ddcb6b3f24 # # Data from https://pastebin.com/vwDRZW7d -EC0A9B1A9E06,--Vingcard Mifare 4k Staff card -6C94E1CED026,--Vingcard Mifare 4k Staff card -0F230695923F,--Vingcard Mifare 4k Staff card -0000014B5C31,--Vingcard Mifare 4k Staff card +EC0A9B1A9E06 # Vingcard Mifare 4k Staff card +6C94E1CED026 # Vingcard Mifare 4k Staff card +0F230695923F # Vingcard Mifare 4k Staff card +0000014B5C31 # Vingcard Mifare 4k Staff card # -BEDB604CC9D1, -B8A1F613CF3D, -B578F38A5C61, +BEDB604CC9D1 +B8A1F613CF3D +B578F38A5C61 B66AC040203A 6D0B6A2A0003 -2E641D99AD5B -AD4FB33388BF, -69FB7B7CD8EE, -2A6D9205E7CA, -2a2c13cc242a, -27FBC86A00D0, -01FA3FC68349, +2E641D99AD5B +AD4FB33388BF +69FB7B7CD8EE +2A6D9205E7CA +2a2c13cc242a +27FBC86A00D0 +01FA3FC68349 # -6D44B5AAF464,--Smart Rider. Western Australian Public Transport Cards -1717E34A7A8A,--Smart Rider. Western Australian Public Transport Cards +6D44B5AAF464 # Smart Rider. Western Australian Public Transport Cards +1717E34A7A8A # Smart Rider. Western Australian Public Transport Cards # -6B6579737472,--RFIDeas +6B6579737472 # RFIDeas # -484944204953,--HID MIFARE Classic 1k Key -204752454154,--HID MIFARE Classic 1k Key -3B7E4FD575AD,--HID MIFARE SO -11496F97752A,--HID MIFARE SO +484944204953 # HID MIFARE Classic 1k Key +204752454154 # HID MIFARE Classic 1k Key +3B7E4FD575AD # HID MIFARE SO +11496F97752A # HID MIFARE SO # -415A54454B4D,--Luxeo/Aztek cashless vending +415A54454B4D # Luxeo/Aztek cashless vending # -321958042333,--BQT +321958042333 # BQT # -160A91D29A9C,--Aperio KEY_A Sector 1, 12, 13, 14, 15 Data Start 0 Length 48 +160A91D29A9C # Aperio KEY_A Sector 1, 12, 13, 14, 15 Data Start 0 Length 48 # -b7bf0c13066e,--Gallagher +b7bf0c13066e # Gallagher # # Boston, MA, USA Transit - MBTA Charlie Card -3060206f5b0a,-- charlie -5ec39b022f2b,-- charlie -3a09594c8587,-- charlie -f1b9f5669cc8,-- charlie -f662248e7e89,-- charlie -62387b8d250d,-- charlie -f238d78ff48f,-- charlie -9dc282d46217,-- charlie -afd0ba94d624,-- charlie -92ee4dc87191,-- charlie -b35a0e4acc09,-- charlie -756ef55e2507,-- charlie -447ab7fd5a6b,-- charlie -932b9cb730ef,-- charlie -1f1a0a111b5b,-- charlie -ad9e0a1ca2f7,-- charlie -d58023ba2bdc,-- charlie -62ced42a6d87,-- charlie -2548a443df28,-- charlie -2ed3b15e7c0f,-- charlie +3060206f5b0a # charlie +5ec39b022f2b # charlie +3a09594c8587 # charlie +f1b9f5669cc8 # charlie +f662248e7e89 # charlie +62387b8d250d # charlie +f238d78ff48f # charlie +9dc282d46217 # charlie +afd0ba94d624 # charlie +92ee4dc87191 # charlie +b35a0e4acc09 # charlie +756ef55e2507 # charlie +447ab7fd5a6b # charlie +932b9cb730ef # charlie +1f1a0a111b5b # charlie +ad9e0a1ca2f7 # charlie +d58023ba2bdc # charlie +62ced42a6d87 # charlie +2548a443df28 # charlie +2ed3b15e7c0f # charlie # -60012e9ba3fa, +60012e9ba3fa # -de1fcbec764b, -81bfbe8cacba, -bff123126c9b, -2f47741062a0, -b4166b0a27ea, -a170d9b59f95, -400bc9be8976, -d80511fc2ab4, -1fcef3005bcf, -bb467463acd6, -e67c8010502d, -ff58ba1b4478, +de1fcbec764b +81bfbe8cacba +bff123126c9b +2f47741062a0 +b4166b0a27ea +a170d9b59f95 +400bc9be8976 +d80511fc2ab4 +1fcef3005bcf +bb467463acd6 +e67c8010502d +ff58ba1b4478 # Data from https://pastebin.com/Kz8xp4ev -fbf225dc5d58, +fbf225dc5d58 # # Data https://pastebin.com/BEm6bdAE # vingcard.txt -4708111c8604, -3d50d902ea48, -96a301bce267, -6700f10fec09, -7a09cc1db70a, -560f7cff2d81, -66b31e64ca4b, -9e53491f685b, -3a09911d860c, -8a036920ac0c, -361f69d2c462, -d9bcde7fc489, -0c03a720f208, -6018522fac02, +4708111c8604 +3d50d902ea48 +96a301bce267 +6700f10fec09 +7a09cc1db70a +560f7cff2d81 +66b31e64ca4b +9e53491f685b +3a09911d860c +8a036920ac0c +361f69d2c462 +d9bcde7fc489 +0c03a720f208 +6018522fac02 # # Data from https://pastebin.com/4t2yFMgt # Mifare technische Universität Graz TUG -D58660D1ACDE, -50A11381502C, -C01FC822C6E5, -0854BF31111E, +D58660D1ACDE +50A11381502C +C01FC822C6E5 +0854BF31111E # More keys: -8a19d40cf2b5, -ae8587108640, +8a19d40cf2b5 +ae8587108640 135b88a94b8b, SafLock standalone door locks. # # Russian Troika card -08B386463229, -0E8F64340BA4, -0F1C63013DBA, -2AA05ED1856F, -2B7F3253FAC5, -69A32F1C2F19, -73068F118C13, -9BECDF3D9273, -A73F5DC1D333, -A82607B01C0D, -AE3D65A3DAD4, -CD4C61C26E3D, -D3EAFB5DF46D, -E35173494A81, -FBC2793D540B, -5125974CD391, -ECF751084A80, -7545DF809202, -AB16584C972A, -7A38E3511A38, -C8454C154CB5, -04C297B91308, -EFCB0E689DB3, -07894FFEC1D6, -FBA88F109B32, -2FE3CB83EA43, -B90DE525CEB6, -1CC219E9FEC1, -A74332F74994, -764CD061F1E6, -8F79C4FD8A01, -CD64E567ABCD, -CE26ECB95252, -ABA208516740, -9868925175BA, -16A27AF45407, -372CC880F216, -3EBCE0925B2F, -73E5B9D9D3A4, -0DB520C78C1C, -70D901648CB9, -C11F4597EFB5, -B39D19A280DF, -403D706BA880, -7038CD25C408, -6B02733BB6EC, -EAAC88E5DC99, -4ACEC1205D75, -2910989B6880, -31C7610DE3B0, -5EFBAECEF46B, -F8493407799D, -6B8BD9860763, -D3A297DC2698, +08B386463229 +0E8F64340BA4 +0F1C63013DBA +2AA05ED1856F +2B7F3253FAC5 +69A32F1C2F19 +73068F118C13 +9BECDF3D9273 +A73F5DC1D333 +A82607B01C0D +AE3D65A3DAD4 +CD4C61C26E3D +D3EAFB5DF46D +E35173494A81 +FBC2793D540B +5125974CD391 +ECF751084A80 +7545DF809202 +AB16584C972A +7A38E3511A38 +C8454C154CB5 +04C297B91308 +EFCB0E689DB3 +07894FFEC1D6 +FBA88F109B32 +2FE3CB83EA43 +B90DE525CEB6 +1CC219E9FEC1 +A74332F74994 +764CD061F1E6 +8F79C4FD8A01 +CD64E567ABCD +CE26ECB95252 +ABA208516740 +9868925175BA +16A27AF45407 +372CC880F216 +3EBCE0925B2F +73E5B9D9D3A4 +0DB520C78C1C +70D901648CB9 +C11F4597EFB5 +B39D19A280DF +403D706BA880 +7038CD25C408 +6B02733BB6EC +EAAC88E5DC99 +4ACEC1205D75 +2910989B6880 +31C7610DE3B0 +5EFBAECEF46B +F8493407799D +6B8BD9860763 +D3A297DC2698 # # Keys from MifareClassicTool project -044CE1872BC3, -045CECA15535, -0BE5FAC8B06A, -0CE7CD2CC72B, -0EB23CC8110B, -0F01CEFF2742, -0F318130ED18, -114D6BE9440C, -18E3A02B5EFF, -19FC84A3784B, -1B61B2E78C75, -22052B480D11, -3367BFAA91DB, -3A8A139C20B4, -42E9B54E51AB, -46D78E850A7E, -4B609876BBA3, -518DC6EEA089, -6B07877E2C5C, -7259FA0197C6, -72F96BDD3714, -7413B599C4EA, -77DABC9825E1, -7A396F0D633D, -7A86AA203788, -8791B2CCB5C4, -8A8D88151A00, -8C97CD7A0E56, -8E26E45E7D65, -9D993C5D4EF4, -9EA3387A63C1, -A3FAA6DAFF67, -A7141147D430, -AAFB06045877, -ACFFFFFFFFFF, -AFCEF64C9913, -B27ADDFB64B0, -B81F2B0C2F66, -B9F8A7D83978, -BAFF3053B496, -BB52F8CCE07F, -BC2D1791DEC1, -BC4580B7F20B, -C65D4EAA645B, -C76BF71A2509, -D5524F591EED, -E328A1C7156D, -E4821A377B75, -E56AC127DD45, -EA0FD73CB149, -FC0001877BF7, -FD8705E721B0, -00ada2cd516d, +044CE1872BC3 +045CECA15535 +0BE5FAC8B06A +0CE7CD2CC72B +0EB23CC8110B +0F01CEFF2742 +0F318130ED18 +114D6BE9440C +18E3A02B5EFF +19FC84A3784B +1B61B2E78C75 +22052B480D11 +3367BFAA91DB +3A8A139C20B4 +42E9B54E51AB +46D78E850A7E +4B609876BBA3 +518DC6EEA089 +6B07877E2C5C +7259FA0197C6 +72F96BDD3714 +7413B599C4EA +77DABC9825E1 +7A396F0D633D +7A86AA203788 +8791B2CCB5C4 +8A8D88151A00 +8C97CD7A0E56 +8E26E45E7D65 +9D993C5D4EF4 +9EA3387A63C1 +A3FAA6DAFF67 +A7141147D430 +AAFB06045877 +ACFFFFFFFFFF +AFCEF64C9913 +B27ADDFB64B0 +B81F2B0C2F66 +B9F8A7D83978 +BAFF3053B496 +BB52F8CCE07F +BC2D1791DEC1 +BC4580B7F20B +C65D4EAA645B +C76BF71A2509 +D5524F591EED +E328A1C7156D +E4821A377B75 +E56AC127DD45 +EA0FD73CB149 +FC0001877BF7 +FD8705E721B0 +00ada2cd516d # # D3F7D3F7D3F7 ## -237a4d0d9119, -0ed7846c2bc9, -FFFFD06F83E3, -FFFFAE82366C, -F89C86B2A961, -F83466888612, -ED3A7EFBFF56, -E96246531342, -E1DD284379D4, -DFED39FFBB76, -DB5181C92CBE, -CFC738403AB0, -BCFE01BCFE01, -BA28CFD15EE8, -B0699AD03D17, -AABBCC660429, -A4EF6C3BB692, -A2B2C9D187FB, -9B1DD7C030A1, -9AEDF9931EC1, -8F9B229047AC, -872B71F9D15A, -833FBD3CFE51, -5D293AFC8D7E, -5554AAA96321, -474249437569, -435330666666, -1A2B3C4D5E6F, -123456ABCDEF, -83BAB5ACAD62, -64E2283FCF5E, -64A2EE93B12B, -46868F6D5677, -40E5EA1EFC00, -37D4DCA92451, -2012053082AD, -2011092119F1, -200306202033, -1795902DBAF9, -17505586EF02, -022FE48B3072, -013940233313, +237a4d0d9119 +0ed7846c2bc9 +FFFFD06F83E3 +FFFFAE82366C +F89C86B2A961 +F83466888612 +ED3A7EFBFF56 +E96246531342 +E1DD284379D4 +DFED39FFBB76 +DB5181C92CBE +CFC738403AB0 +BCFE01BCFE01 +BA28CFD15EE8 +B0699AD03D17 +AABBCC660429 +A4EF6C3BB692 +A2B2C9D187FB +9B1DD7C030A1 +9AEDF9931EC1 +8F9B229047AC +872B71F9D15A +833FBD3CFE51 +5D293AFC8D7E +5554AAA96321 +474249437569 +435330666666 +1A2B3C4D5E6F +123456ABCDEF +83BAB5ACAD62 +64E2283FCF5E +64A2EE93B12B +46868F6D5677 +40E5EA1EFC00 +37D4DCA92451 +2012053082AD +2011092119F1 +200306202033 +1795902DBAF9 +17505586EF02 +022FE48B3072 +013940233313 # # Hotel Adina -9EBC3EB37130, +9EBC3EB37130 # -# mostlikely diverised individual keys. -# data from: https://github.com/korsehindi/proxmark3/commit/24fdbfa9a1d5c996aaa5c192bc07e4ab28db4c5c -491CDC863104, -A2F63A485632, -98631ED2B229, -19F1FFE02563, -563A22C01FC8, -- Argentina -43CA22C13091, -- Argentina -25094DF2C1BD, -- Argentina +# most likely diversed individual keys. +# data from https://github.com/korsehindi/proxmark3/commit/24fdbfa9a1d5c996aaa5c192bc07e4ab28db4c5c +491CDC863104 +A2F63A485632 +98631ED2B229 +19F1FFE02563 +563A22C01FC8 # Argentina +43CA22C13091 # Argentina +25094DF2C1BD # Argentina # # OMNITEC.ES HOTEL TIMECARD / MAINTENANCECARD -AFBECD120454, +AFBECD120454 # # OMNITEC.ES HOTEL EMERGENCYCARD -842146108088, +842146108088 # # TAPCARD PUBLIC TRANSPORT LA # -EA1B88DF0A76, -D1991E71E2C5, -05F89678CFCF, -D31463A7AB6D, -C38197C36420, -772219470B38, -1C1532A6F1BC, -FA38F70215AD, -E907470D31CC, -160F4B7AB806, -1D28C58BBE8A, -B3830B95CA34, -6A0E215D1EEB, -E41E6199318F, -C4F271F5F0B3, -1E352F9E19E5, -0E0E8C6D8EB6, -C342F825B01B, -CB911A1A1929, -E65B66089AFC, -B81846F06EDF, -37FC71221B46, -880C09CFA23C, -6476FA0746E7, -419A13811554, -2C60E904539C, -4ECCA6236400, -10F2BBAA4D1C, -4857DD68ECD9, -C6A76CB2F3B5, -E3AD9E9BA5D4, -6C9EC046C1A4, +EA1B88DF0A76 +D1991E71E2C5 +05F89678CFCF +D31463A7AB6D +C38197C36420 +772219470B38 +1C1532A6F1BC +FA38F70215AD +E907470D31CC +160F4B7AB806 +1D28C58BBE8A +B3830B95CA34 +6A0E215D1EEB +E41E6199318F +C4F271F5F0B3 +1E352F9E19E5 +0E0E8C6D8EB6 +C342F825B01B +CB911A1A1929 +E65B66089AFC +B81846F06EDF +37FC71221B46 +880C09CFA23C +6476FA0746E7 +419A13811554 +2C60E904539C +4ECCA6236400 +10F2BBAA4D1C +4857DD68ECD9 +C6A76CB2F3B5 +E3AD9E9BA5D4 +6C9EC046C1A4 # # ROC HIGHSCHOOL ACCESSCARD # -B021669B44BB, -B18CDCDE52B7, -A22647F422AE, -B268F7C9CA63, -A37A30004AC9, -B3630C9F11C8, -A4CDFF3B1848, -B42C4DFD7A90, -A541538F1416, -B5F454568271, -A6C028A12FBB, -B6323F550F54, -A7D71AC06DC2, -B7C344A36D88, -A844F4F52385, -B8457ACC5F5D, -A9A4045DCE77, -B9B8B7B6B5B3, -AA4D051954AC, -BA729428E808, -AB28A44AD5F5, -BB320A757099, -AC45AD2D620D, -BCF5A6B5E13F, -AD5645062534, -BDF837787A71, -AE43F36C1A9A, -BE7C4F6C7A9A, -5EC7938F140A, -82D58AA49CCB, +B021669B44BB +B18CDCDE52B7 +A22647F422AE +B268F7C9CA63 +A37A30004AC9 +B3630C9F11C8 +A4CDFF3B1848 +B42C4DFD7A90 +A541538F1416 +B5F454568271 +A6C028A12FBB +B6323F550F54 +A7D71AC06DC2 +B7C344A36D88 +A844F4F52385 +B8457ACC5F5D +A9A4045DCE77 +B9B8B7B6B5B3 +AA4D051954AC +BA729428E808 +AB28A44AD5F5 +BB320A757099 +AC45AD2D620D +BCF5A6B5E13F +AD5645062534 +BDF837787A71 +AE43F36C1A9A +BE7C4F6C7A9A +5EC7938F140A +82D58AA49CCB # -# MELONCARD +# MELONCARD # -323334353637, +323334353637 # # -CEE3632EEFF5, -827ED62B31A7, -03EA4053C6ED, -C0BEEFEC850B, -F57F410E18FF, -0AF7DB99AEE4, -A7FB4824ACBF, -207FFED492FD, -1CFA22DBDFC3, -30FFB6B056F5, -39CF885474DD, -00F0BD116D70, -4CFF128FA3EF, -10F3BEBC01DF, +CEE3632EEFF5 +827ED62B31A7 +03EA4053C6ED +C0BEEFEC850B +F57F410E18FF +0AF7DB99AEE4 +A7FB4824ACBF +207FFED492FD +1CFA22DBDFC3 +30FFB6B056F5 +39CF885474DD +00F0BD116D70 +4CFF128FA3EF +10F3BEBC01DF # # Transportes Insular La Palma # -0172066b2f03, -0000085f0000, -1a80b93f7107, -70172066b2f0, -b1a80c94f710, -0b0172066b2f, -0f1a81c95071, -f0f0172066b2, -1131a81d9507, -2f130172066b, -71171a82d951, -b2f170172066, -1711b1a82e96, -6b2f1b017206, -62711f1a83e9, -66b2f1f01720, -97271231a83f, -066b2f230172, -f97371271a84, -2066b2f27017, -50983712b1a8, -72066b2f2b01, -850984712f1a, -172066b2f2f0, -a85198481331, -0172066b2f33, -1a8619858137, -70172066b2f3, -b1a862985913, -3b0172066b2f, -3f1a87298691, -f3f0172066b2, +0172066b2f03 +0000085f0000 +1a80b93f7107 +70172066b2f0 +b1a80c94f710 +0b0172066b2f +0f1a81c95071 +f0f0172066b2 +1131a81d9507 +2f130172066b +71171a82d951 +b2f170172066 +1711b1a82e96 +6b2f1b017206 +62711f1a83e9 +66b2f1f01720 +97271231a83f +066b2f230172 +f97371271a84 +2066b2f27017 +50983712b1a8 +72066b2f2b01 +850984712f1a +172066b2f2f0 +a85198481331 +0172066b2f33 +1a8619858137 +70172066b2f3 +b1a862985913 +3b0172066b2f +3f1a87298691 +f3f0172066b2 # # Tehran ezpay # diff --git a/client/dictionaries/mfc_keys_bmp_sorted.dic b/client/dictionaries/mfc_keys_bmp_sorted.dic index 0f8acdcf3..85ab141e0 100644 --- a/client/dictionaries/mfc_keys_bmp_sorted.dic +++ b/client/dictionaries/mfc_keys_bmp_sorted.dic @@ -1,1000 +1,1000 @@ -002DE0301481, -004173272D18, -0058A4884CA5, -00BAC32761D8, -00BB79731B00, -00E8C85DB172, -02096124DA70, -024988BC4D5E, -0271B7C4B015, -028137A705DB, -02827C286AB4, -02C10DA600D0, -0340643D5E27, -037A5DA4682B, -037AC43CBD9D, -037B9B8AA219, -037EE3DE21B7, -0380A9A3CBDE, -03D10A75B56A, -03E8CD22E691, -04109ED8EA79, -04361330B35C, -043D8B66D569, -045E5588845C, -048DE5148DE7, -0490921D0194, -04B717BD92EB, -04D49C76623B, -051518B3301E, -0529E8827A52, -052B16064085, -05DC4016B500, -06124317A9A6, -06147D199266, -0670AEB833CE, -0686A9E6D6E0, -06A34E5E6639, -06B78AD0C4BB, -0710E7818AB8, -07121B8C633A, -07176713C0ED, -0793533A5087, -081D1B1C3110, -0849495E1CCA, -09429512046E, -0966C3B28E04, -098A92C3660A, -098B48278122, -099672009EEA, -0A7632943926, -0AEE126549DA, -0B3B8C2833BC, -0B733C13E2C9, -0B764247D00E, -0BE811559D69, -0C208AD4E4B3, -0C270BC0BDDC, -0C5D782CB183, -0C82C94EB11B, -0CCDE948878A, -0CCE39820AAE, -0CDE3E716B32, -0CE06C96DB4C, -0CE87813E389, -0D3385CEA152, -0D5C5B8BCC5B, -0DB0A87AB882, -0DE247593B93, -0E0AD1796003, -0E62E6CAC3D3, -106E2D6E55E6, -1096A7830C82, -11549C141AD9, -116A92C793D6, -116C31526819, -11C68052AAE9, -1234B5BE8E78, -1268C7D104E1, -12A21B5671A8, -13359D5AE9A5, -1426EC62BB6C, -144489B1056E, -14A22C112090, -14C9BBB5361B, -14EB6286AC57, -14EE72B27223, -153BB53ACE71, -157B03405B38, -15A45083D24E, -15DACCE8D5EC, -16124677BBC5, -16373A44D5D7, -1663659384DC, -167828B6105C, -16B25A453093, -1706B1BE25C7, -171B15888483, -17BC8EED9A0C, -17C6299D5A37, -17E9C4C416EB, -1804087C7166, -1841CC4E3E79, -18AB05761CC5, -18ADAAC2B08B, -18E566417E5C, -191390328752, -1A47959E7DB4, -1A9A970CC370, -1B095E78BB33, -1B1717043D2B, -1B1A054566D9, -1B4654AE9454, -1B9CD1ED3420, -1B9E00780953, -1BB6A9CE71E2, -1C1250A36A13, -1C2316079532, -1C2855ED7A10, -1CD1AE73CA8C, -1CD3D4E690B7, -1D0322005969, -1D09B23EB116, -1D67A32045ED, -1D89D900968A, -1DAE8D2CEA5C, -1E1873799CD7, -1E60CE7C5179, -1E6A67909B8D, -1E8516585792, -1EB0864E9134, -1ECE3D04A020, -2009828E4A21, -200A6A3AA65D, -20188A599582, -20267CB20256, -20628CA7D92D, -2077C980EB2E, -2089B5D68B27, -209481EC6256, -20B6691C64B1, -20CC5A00C677, -211473555436, -2170E9D0D448, -219529A90EDD, -21A5B6481B7D, -224A308017D1, -227D16EA455A, -22A1245CA266, -22A95CB798DC, -230E26964171, -231173B68E46, -2332BB9A2452, -234323BC2992, -234E50256146, -235C9338D5B6, -23789D9ADD0D, -23997DD240AB, -23A5BA53AD4D, -23BB58853461, -24CAD4153036, -24CE79506842, -25228ED714BC, -257377227B34, -2584287A0174, -2616192EEB22, -265C03B50877, -26D641E834DC, -27073B57132B, -279060E3DEE9, -284BA0A0A29C, -285C6604C5B4, -28B20331245A, -28D042242A83, -28DDD4C3E9C4, -292C2CCD157E, -299ABB519354, -2A41BE015C1D, -2A4A55052A51, -2A94CBCD7A6E, -2AB6536187C7, -2B2D2DC3D319, -2BD607CA70B2, -2C6C7957EB3E, -2C9E9E4D0895, -2D2A97DD45E3, -2D41850A8AA6, -2DAC030D1AB9, -2E12426D8847, -2E25AD1D6D8D, -2E2E85E0E6C9, -2E4340CC1C63, -2E6803BE2E11, -2EB24B573DCD, -2EC6450A47C7, -2ECDA9A5EA96, -2EDE1C155023, -302D5D37342B, -303645E47667, -303B30A460E8, -3048EBB8A18E, -30BD652BED24, -30CCE5ECB397, -310241E1CB36, -312670228372, -319E8895EAB5, -31E3A933BC4A, -3250D2E661DA, -32560224418D, -32589E221D10, -326657A8E9C0, -329AC7C59311, -32A091B89995, -3312C094BD20, -336C8CBA5AE2, -34240649314A, -3493D84E6317, -349A347186D7, -349BEAC5210E, -34A939B49EDC, -34CC7E36C8C4, -34D71347877E, -34DC25B4D0CE, -35895EB472C4, -358A6A398211, -360A08C66042, -36306A9CA571, -37284428A250, -377EC8A78B8D, -37BD90A68613, -37E602347133, -382DE6AB2D1A, -385D498B5390, -38B67589E47D, -393CCCCCDA4A, -39682B3E10B5, -397619525709, -39A83A32909B, -3A5834C46513, -3A70C7A4BCE4, -3A818D01E093, -3AA5AC1CDC21, -3AAE07339954, -3B4497052B42, -3B784087DB2D, -3B86A20C16EA, -3B8E321AB1B4, -3BC4A3099B0D, -3BC741376E71, -3C4C95D0A0C7, -3C84B55A5E54, -3C888A88C59D, -3D5C8240B2D2, -3DB004172BE7, -3E23271C1C15, -3E3188294ED1, -3E84144A770E, -3EA227893101, -3EB914E70076, -3EE6D4A85643, -40DABA780B41, -4119340759A2, -415210E0C6BB, -416D21717779, -41B1839829A9, -4201A36DE766, -4261A795D5A7, -42AA0B29626E, -430265958BEB, -4317C5C16EAD, -431D799E0C89, -4342794AD7BB, -4387ADE263DB, -43982124C310, -4436CB060568, -44449507B736, -44E858C82975, -459BC12982B1, -45AE5DDA9830, -45C414CDC347, -45CE4E504C06, -461744C8EABD, -46D012CA3BEC, -47170BD112B6, -47C43D5DD234, -47CD4AC26271, -47D410D1C7C4, -4808C5AD0115, -485BEEDBC293, -486001404A80, -488CCC60B70A, -49204E3CA169, -495657C78147, -4970714D53D9, -4AA715A0BBB4, -4B9901AEC16E, -4BE0B912A5A3, -4CBC34D10D83, -4CD3ACABC6A3, -4CE00134DE1E, -4CEB27151C49, -4D02A3D7CE48, -4D13683C7960, -4D1A263BA48B, -4D23919463A3, -4D9763C083D9, -4DAC8EE52C68, -4DCB89C7B2E6, -4DD9D9B637C4, -4DE6CB63A920, -4DEBA10CC85D, -4E232A8C2E30, -4E2879A411E7, -4EA7B0BED74B, -4EB8761372EA, -4EC2B23135AB, -4EC71DB088DE, -4EC9AB4B5519, -50179E461EE6, -50265ED9D468, -5047DC2975BE, -508357498162, -508BE54D326E, -510A8C52AAC4, -511335CC92CD, -518229589A81, -5184D04315D7, -51B4AE31B246, -526EDB918BEE, -529CE44BEBCC, -52A843082BB3, -52AE9A909674, -5313E9079489, -532DE5E7E0E9, -535508AA6C91, -53691569B669, -540A5B789761, -547B86E57596, -54C649075B57, -552249203848, -55430B5318E9, -5570D22DC66B, -55710879E113, -55D2E4AC0446, -56207539825A, -564664475726, -566441C5C28C, -56A7930913C3, -56C944B04618, -56D455A8BBEA, -5726991C8C28, -5726AA3BE37B, -573314090BA5, -577C31903867, -577C528E786C, -57AD9604ED24, -580C377283C7, -587329CE3EBE, -587C34557B36, -58B11E803B58, -5902E4DCC95D, -5A060A64C535, -5A36898CA7C5, -5A4740D952EC, -5A6ED7966868, -5A99578CAA13, -5AAD6814E68B, -5B065568048A, -5B6CE0B3AD0A, -5B70E0B11758, -5B926E3751EB, -5B9CA63C4267, -5BDC1391B289, -5C1D3898D537, -5C34B8E4A456, -5C36456EA1E5, -5C43A75C65A0, -5C5752328A47, -5C9D20250D74, -5CBA3CEE351A, -5CD5E98A2864, -5CE0EB9C01B6, -5D384E6A4145, -5D9DB8445155, -5DE8717BB640, -5E1A4EE98748, -5E45A227B391, -5E8E50B3048B, -5EB0EA0A9412, -6032C47B7676, -60E0C84ADDEE, -612A447A2149, -612D81821854, -616B820EAD01, -616D75A4A022, -61DE2B085AC9, -62312EC272A0, -6232C5262CC6, -62B7C7C9B0D0, -62C531C6E29C, -63E6AAAB4433, -644ABCC3DD12, -64AE7BEA1784, -6515B38077D6, -65972038CC25, -65E120DE5E55, -66141DDE8320, -66718BD91332, -668082242328, -668920AEE063, -6696C4332D46, -66C9880D1DC2, -67150CB11E95, -671737BA0054, -673551D0A99E, -676D682C4336, -678B98AA2E86, -6847808E63EE, -6887A122AA62, -6888C514DEAD, -688BD5B7B4E9, -68A99E258692, -68C312391560, -68C9D33E3735, -6900A069E3D7, -690155BE8D8E, -69174742042D, -69B9CE233517, -6A0B123D7595, -6AB8E2B49E25, -6ABD4C4A72D9, -6B1CC539A1B2, -6B30B6B0925D, -6B638C1C950D, -6BAAAB1D4589, -6BAD01EBE736, -6BB4ED5E1682, -6CA178E036DA, -6CE210B529C4, -6D23D505D2B1, -6D3CBD12BC6D, -6D83563EB521, -6D98AB9CCC71, -6E3D7366E78C, -6E5582237608, -6E6602904925, -6E77B8EB6444, -6E978A7B16C6, -6EEC05EB651C, -70284824B26C, -702CDACE0C14, -704E1B85BED8, -70BB123776D6, -70CCC3A2D7C0, -716A747CB931, -7173E199A420, -71BC9C9E31E4, -71CAEEA3B771, -71D8BA423D55, -72253C7DD951, -7260377CD286, -7280858E8B20, -72913BDAB647, -72B5B87BBC6E, -72C83B1D098A, -72DA8050A38E, -735C2AB60A97, -736B602A93D9, -738D7833E7DE, -73E7B22D6E54, -74133B1E2DED, -74A929877793, -74E3670C045A, -7531E3E2A41C, -7542A9B65EB4, -7564993C91C7, -760ED0AB626E, -762E0E021E38, -763D7E6BB40E, -764B38E2903D, -768016001C8D, -76A616C3D42C, -76AE99D9A294, -76BAAA710D25, -76E3B23696BC, -77322DD2E184, -77B40902B6D9, -77C0AC14972D, -77C1CE0E7674, -77D7B7E2C8BA, -78279397A68E, -7836593AB838, -783859EB51A6, -78CCDB50C193, -7932684154AE, -79604362370E, -796630ED27B3, -799E4E270953, -79A00573947A, -79B798D66B01, -7A0455D0A7EC, -7A33D19B7248, -7B0A8AE18817, -7B0BA045AB35, -7B0DE8504D57, -7B21781EC649, -7B7224C1AB79, -7B90C2BA9B23, -7BB90D382672, -7BBC9DC92836, -7C09DC408C47, -7C418B493454, -7C491D518242, -7C7A86CC727C, -7CE836EBD228, -7D49042C530D, -7E5744EC286C, -7E680A48C383, -7EC45CCEC35A, -7EDADA19EB57, -8005BD088847, -8022E705B640, -8031E3565825, -80499BAA5959, -807466CCBAB5, -810518578380, -810D24CB13CC, -812B02C34A64, -8163A5DDE1CD, -8186CE2B363E, -81DE6062B9D7, -822017D8929A, -8247C78188C5, -8270D538D5E8, -82D8E8DDE296, -831207CA6E8A, -83378A077357, -83A05B477535, -840160379EEE, -84044BAB78A7, -84366C6D7781, -8442CC9AA777, -8470AAD30447, -8498740493BB, -84A35A698E93, -84ABDE484425, -84B24DBB9A67, -84B723B2A237, -852BEB133D74, -854501E98239, -854A0ED2E77D, -85A066D39785, -8619557091AA, -86228C3742A4, -8637BB3BA795, -8642D9310B46, -86538085966D, -86EE9C410811, -870A042C1B34, -873B47C457E6, -873CE44DDC6B, -874D123262E7, -87513C960770, -877641436923, -878A091B74B7, -87927467808B, -88C2E39B5990, -88D252AC1A8A, -891EDA20BDEA, -89267DEE07ED, -892CB89ACCC6, -8A2423E9D100, -8A6BC2E3811B, -8A8EB5771EE9, -8A906B4B3211, -8AB21B524C5C, -8AB823BDC2AE, -8AC3B2ADE77B, -8AC4317D049B, -8ACD6B86EC44, -8AD966CA3B4D, -8B0A3B3DCDD4, -8B1B6C705C1A, -8B1C75E27153, -8B2A5E0332A1, -8B6216E412DB, -8B7CCA9DB004, -8B9999AE9703, -8BABAD9A65C6, -8C32D0AE3DB7, -8C99807368A5, -8CC1133D7D5B, -8CD2C872187A, -8D0563B86DD4, -8D43D81E37B4, -8D96A800B21A, -8D97B475C957, -8DA62EC0C524, -8DACA1BC0636, -8DE3B131D728, -8E55316D3B3D, -8EE497C9A869, -90210DDAB57D, -9026977EB8A6, -903AA4305025, -9083158A49A1, -9092D12E7967, -90D8713352D1, -911E097A27A9, -9140EC087241, -918A67D05479, -919B1D357E91, -9210BBA2AB26, -9224B6555E30, -9226D4D1236A, -922E7955CC67, -929CC86B1B26, -929E1556110E, -9302DEB79C5A, -9384841B4702, -93B4BD1CB47C, -93D985D55712, -940B37939AC6, -94673AE73823, -947A8147E0AE, -94CD6A4B6391, -94CEEAC5A8D7, -95ABD3A7C631, -95E1C233EDE2, -9607AE17AD09, -960C98566E52, -96435BD1D29B, -965D66E19245, -965D72659982, -9695167B4149, -96D0C3996714, -97274C21BD6C, -973186B345BB, -973A28C983A3, -979686C51AB6, -97992CE2DD31, -97E9D0C89DA8, -97EB8A44C49D, -98314DC363C5, -9860DC044565, -988D023C15A5, -9917BDA7B4D7, -9996A233442A, -9A2132B5B625, -9A694755A978, -9A7911ECC275, -9AA1E6CE588C, -9ABCCD2AE7C7, -9B39A60D3841, -9C0630361CC5, -9C4E19AB64B1, -9CE96BADE4D8, -9D442B28BD11, -9D4C35AE1A08, -9E02910C691A, -9E46407C9024, -9E74D104ACEA, -9EDD416A7912, -A026642D13AD, -A12908B38536, -A16EE9666D5A, -A199132A4043, -A1AEC2B58BBA, -A1BE42A15EDE, -A1D0844C2C63, -A1E0103A1879, -A253602B9445, -A2B019B46CB9, -A2BBCC3B546C, -A2C325A73A9C, -A2CB60E815A0, -A314B97C1A6A, -A3647146C335, -A3A580799BB4, -A3D30CC8EB97, -A402B5137D86, -A42158CC74B5, -A435DD64AD17, -A4693D21013B, -A479A91EED49, -A4B30D146A01, -A5142D626200, -A54056E87CBB, -A57DBD287491, -A588C918E327, -A593071D4758, -A5CC0EE7B9E3, -A6375E98A5B5, -A666347B3B4B, -A6A203994202, -A6BAE1A1520D, -A6E9885AA49D, -A705087E89A8, -A7072D4324C7, -A745AD7D6789, -A750456E7C5E, -A783A8774651, -A787C822020C, -A78BB575EAC5, -A7905680A254, -A805534D84E9, -A86C2595A1C3, -A89903B6ADDB, -A9182707A219, -A9391782A846, -A96B08E3A50B, -A98DEB0733C9, -A9C37CE71D23, -AA2D69C757D9, -AA4E4558A9EE, -AA6C835C9124, -AAC0C35C43EB, -AB30CB2CB354, -AB6191DB240A, -AB8953D3560C, -ABBB521319E6, -AC47461358D7, -AC58C25A1559, -AC7D4B201D92, -AD061A23287D, -AD105D52DB36, -AD4EA84D7185, -AD5038D15490, -AD97523144B2, -ADB24E78784B, -ADCBD453B232, -AE516A187825, -AE52116C234C, -AE817239CAB5, -AEA5A5A0E46B, -AECC93678543, -B0452769A83C, -B04D71906C60, -B0805C191424, -B09172DDBE43, -B13AE369390C, -B14080E570D1, -B1419B62772C, -B14775DEA2E2, -B188BA649EA1, -B1BB0DB95C67, -B1BB19BDD424, -B1E8B5054DAD, -B1EBB537CC0D, -B2174092CDC5, -B2554CC8AD6E, -B2C5A2E88304, -B312E56ED250, -B37B48D8C1C5, -B39C699CD208, -B3B121208E34, -B3C3C6E4395B, -B410B958C3B8, -B4204546A74E, -B45171C5A67D, -B4B103E693ED, -B4DACABCAB07, -B506567A2B84, -B51083D5C2BD, -B54D7674CB90, -B570E5EA1DA3, -B598984AD584, -B5D7E1135821, -B60D053A36D9, -B63957593E23, -B64558CAC0C9, -B68175BCA864, -B6CD1A3EC5BC, -B72468A7710D, -B75176C82A8B, -B7AA0CA5D94A, -B7B9D7E523B8, -B808D87AB75C, -B93A6432E51A, -B941A9D99B6C, -B9DA40920237, -BA6C2E10086A, -BA7384AB949E, -BA8DEEE045E8, -BADC2149EC42, -BB1924266B36, -BB41640E6340, -BBB475DB2B03, -BBD4C4699719, -BC0B2C897267, -BC7BEE6B71C4, -BC8B21AD8802, -BCA2D8118631, -BCB7A7006400, -BCBC6637499B, -BCBD2B8BE4B3, -BD213E28C568, -BD32E4EC7080, -BD401D63C3E9, -BD463C3693A4, -BD749E85586A, -BD7CA11B9551, -BD96355CBE36, -BD9E6EB7B524, -BDADE6111218, -BDB576D1E88C, -BDB5DC09C522, -BE19C75D6B7E, -BE5B3ED935AC, -BEA20C972E70, -BEEB4A159B37, -C01E8740DE38, -C0411C28857D, -C045544AD1E4, -C04660B76831, -C0C4CA21B876, -C0E0E092C8B4, -C0EE394D3D95, -C14601C6B411, -C16EBAE928B2, -C189A791A85B, -C1ACDB8C1890, -C1C55A7A99EA, -C1D72A47755A, -C1D8B91D65AA, -C1E6149B386D, -C22D8E2B1E37, -C23E999B6298, -C314E31A670D, -C3D275A9B8C7, -C3EE19B61C89, -C427B93DC2ED, -C443EEC4330D, -C477B966D328, -C4C6CAE4784C, -C55875BCB82C, -C581CA998910, -C5ABC0A455C5, -C5BE33E6B1E2, -C629E0D34581, -C65194543D6B, -C67B8E869D90, -C6BC3B9CCB41, -C7034BC581A6, -C748500B6947, -C757C15E9E0D, -C798A8465ACB, -C7B6702AC17B, -C849133B7CCC, -C870C98A4E91, -C90B7AD266D3, -C90D996C3A2D, -C953797CCE61, -C9639352EEC8, -C983685AA86B, -C9CCA6D095A3, -C9CE81D47EDB, -C9D449AD9970, -CA0D9CCC4C38, -CA277AC09859, -CA56EB045188, -CAB92B865BAD, -CAE8572C2657, -CB1CE185575C, -CB2ECC3D9C22, -CB642A081A89, -CBBAD2DA0EC5, -CC1B5BD45315, -CC2C02300D34, -CC559969D0CC, -CC5646BD7AEB, -CC6A93BD93D1, -CC726DD08765, -CCBBAB6504A4, -CCC1EA3E27B8, -CD16EAB946E9, -CDB4EEE02E14, -CDC21E1E1EC7, -CE09B3870EA2, -CE5AA0C8B5A8, -CE63DE29E069, -D0368B24CA49, -D0489010A72C, -D075379A21A6, -D09893B4EE04, -D0A7A2787570, -D0B8C06C02E4, -D106E94A4C3B, -D11E7D1BBEEA, -D12B25B8DDE2, -D1972D6CE2C3, -D1B91D224946, -D2752E53679D, -D35B2B75CC52, -D40E935117A2, -D4C37528DC05, -D4C818A5455E, -D4CD56DB8AEB, -D5190BD5CED6, -D55E5AA3406D, -D576E9D856D9, -D5E444E9D82D, -D61A3231790D, -D669B3AE1E11, -D6C075899D06, -D6C3503456C4, -D7AC70A05A0C, -D80A37B6D7ED, -D82E6938C58C, -D85E51344EB6, -D8809EB9BA7D, -D8913C2D48E9, -D9109460D912, -D94E36427E20, -D97E55B1816A, -D99425130C1A, -D99C3222A190, -D9A207103ED7, -D9C70CC5818A, -DA3379D12773, -DA705702248C, -DA818C56CE43, -DAE1888DCC0B, -DBA0A2DCA8E0, -DBD9799E15B1, -DC242193D7E3, -DCB5AC62946C, -DCB75AEC61A0, -DD6E0587A821, -DD7B1A7C6A82, -DDA22A189095, -DDDAE53AA711, -DDE7304E78B6, -DE1B4DA681B9, -DEAC67E2D7C1, -DEB7D7E4C62B, -E127434AB3B7, -E1ACC6742AB7, -E1E59574ADBC, -E1EA6BAA03D9, -E222553A59A2, -E2230B8E84C9, -E33E807EC3BA, -E341574B2E32, -E42868808B70, -E43562C624B0, -E43D54DC3511, -E466090D2123, -E47069DA0C44, -E49DD6062901, -E4ACA0ADBA0D, -E4B976AD6687, -E526BB7888DB, -E53354B71B10, -E57581CE8617, -E61A1DA5A60E, -E6293BDA5EDC, -E64C2A07CA9B, -E6600C4D6A44, -E6655B6425DC, -E6BADC631036, -E70143BE0091, -E75E07A010D1, -E76962E3B8B4, -E8028A6DCC90, -E80C5E3E8227, -E8779E40450E, -E8A9E2D87D36, -E8B5A0BDD993, -E933DA9735C4, -E93A2E63189D, -E9447637E40D, -E94836269887, -E94D82A564BA, -E98DC3B561B5, -E9EB2DE57AE9, -EA490920877D, -EA4C494C9353, -EA9B1695DD91, -EAD0E31A6834, -EB16B6462B66, -EB276C9AB68D, -EB3C9732C3BA, -EB44DDC408CE, -EB8536C958B2, -EBC825C186B3, -EC1A55BB58EB, -EC2B12107313, -EC8CB5758097, -ECD4C42EA3D1, -ED22B7115435, -ED2CE17A590C, -ED65A9B6469C, -ED6748113E0D, -ED8CEB8B7102, -EDCE0890472D, -EDD4A2EA7493, -EE17C426D25E, -EE487A4C806E, -EE5931913A8D, -EED56840AEBA, +002DE0301481 +004173272D18 +0058A4884CA5 +00BAC32761D8 +00BB79731B00 +00E8C85DB172 +02096124DA70 +024988BC4D5E +0271B7C4B015 +028137A705DB +02827C286AB4 +02C10DA600D0 +0340643D5E27 +037A5DA4682B +037AC43CBD9D +037B9B8AA219 +037EE3DE21B7 +0380A9A3CBDE +03D10A75B56A +03E8CD22E691 +04109ED8EA79 +04361330B35C +043D8B66D569 +045E5588845C +048DE5148DE7 +0490921D0194 +04B717BD92EB +04D49C76623B +051518B3301E +0529E8827A52 +052B16064085 +05DC4016B500 +06124317A9A6 +06147D199266 +0670AEB833CE +0686A9E6D6E0 +06A34E5E6639 +06B78AD0C4BB +0710E7818AB8 +07121B8C633A +07176713C0ED +0793533A5087 +081D1B1C3110 +0849495E1CCA +09429512046E +0966C3B28E04 +098A92C3660A +098B48278122 +099672009EEA +0A7632943926 +0AEE126549DA +0B3B8C2833BC +0B733C13E2C9 +0B764247D00E +0BE811559D69 +0C208AD4E4B3 +0C270BC0BDDC +0C5D782CB183 +0C82C94EB11B +0CCDE948878A +0CCE39820AAE +0CDE3E716B32 +0CE06C96DB4C +0CE87813E389 +0D3385CEA152 +0D5C5B8BCC5B +0DB0A87AB882 +0DE247593B93 +0E0AD1796003 +0E62E6CAC3D3 +106E2D6E55E6 +1096A7830C82 +11549C141AD9 +116A92C793D6 +116C31526819 +11C68052AAE9 +1234B5BE8E78 +1268C7D104E1 +12A21B5671A8 +13359D5AE9A5 +1426EC62BB6C +144489B1056E +14A22C112090 +14C9BBB5361B +14EB6286AC57 +14EE72B27223 +153BB53ACE71 +157B03405B38 +15A45083D24E +15DACCE8D5EC +16124677BBC5 +16373A44D5D7 +1663659384DC +167828B6105C +16B25A453093 +1706B1BE25C7 +171B15888483 +17BC8EED9A0C +17C6299D5A37 +17E9C4C416EB +1804087C7166 +1841CC4E3E79 +18AB05761CC5 +18ADAAC2B08B +18E566417E5C +191390328752 +1A47959E7DB4 +1A9A970CC370 +1B095E78BB33 +1B1717043D2B +1B1A054566D9 +1B4654AE9454 +1B9CD1ED3420 +1B9E00780953 +1BB6A9CE71E2 +1C1250A36A13 +1C2316079532 +1C2855ED7A10 +1CD1AE73CA8C +1CD3D4E690B7 +1D0322005969 +1D09B23EB116 +1D67A32045ED +1D89D900968A +1DAE8D2CEA5C +1E1873799CD7 +1E60CE7C5179 +1E6A67909B8D +1E8516585792 +1EB0864E9134 +1ECE3D04A020 +2009828E4A21 +200A6A3AA65D +20188A599582 +20267CB20256 +20628CA7D92D +2077C980EB2E +2089B5D68B27 +209481EC6256 +20B6691C64B1 +20CC5A00C677 +211473555436 +2170E9D0D448 +219529A90EDD +21A5B6481B7D +224A308017D1 +227D16EA455A +22A1245CA266 +22A95CB798DC +230E26964171 +231173B68E46 +2332BB9A2452 +234323BC2992 +234E50256146 +235C9338D5B6 +23789D9ADD0D +23997DD240AB +23A5BA53AD4D +23BB58853461 +24CAD4153036 +24CE79506842 +25228ED714BC +257377227B34 +2584287A0174 +2616192EEB22 +265C03B50877 +26D641E834DC +27073B57132B +279060E3DEE9 +284BA0A0A29C +285C6604C5B4 +28B20331245A +28D042242A83 +28DDD4C3E9C4 +292C2CCD157E +299ABB519354 +2A41BE015C1D +2A4A55052A51 +2A94CBCD7A6E +2AB6536187C7 +2B2D2DC3D319 +2BD607CA70B2 +2C6C7957EB3E +2C9E9E4D0895 +2D2A97DD45E3 +2D41850A8AA6 +2DAC030D1AB9 +2E12426D8847 +2E25AD1D6D8D +2E2E85E0E6C9 +2E4340CC1C63 +2E6803BE2E11 +2EB24B573DCD +2EC6450A47C7 +2ECDA9A5EA96 +2EDE1C155023 +302D5D37342B +303645E47667 +303B30A460E8 +3048EBB8A18E +30BD652BED24 +30CCE5ECB397 +310241E1CB36 +312670228372 +319E8895EAB5 +31E3A933BC4A +3250D2E661DA +32560224418D +32589E221D10 +326657A8E9C0 +329AC7C59311 +32A091B89995 +3312C094BD20 +336C8CBA5AE2 +34240649314A +3493D84E6317 +349A347186D7 +349BEAC5210E +34A939B49EDC +34CC7E36C8C4 +34D71347877E +34DC25B4D0CE +35895EB472C4 +358A6A398211 +360A08C66042 +36306A9CA571 +37284428A250 +377EC8A78B8D +37BD90A68613 +37E602347133 +382DE6AB2D1A +385D498B5390 +38B67589E47D +393CCCCCDA4A +39682B3E10B5 +397619525709 +39A83A32909B +3A5834C46513 +3A70C7A4BCE4 +3A818D01E093 +3AA5AC1CDC21 +3AAE07339954 +3B4497052B42 +3B784087DB2D +3B86A20C16EA +3B8E321AB1B4 +3BC4A3099B0D +3BC741376E71 +3C4C95D0A0C7 +3C84B55A5E54 +3C888A88C59D +3D5C8240B2D2 +3DB004172BE7 +3E23271C1C15 +3E3188294ED1 +3E84144A770E +3EA227893101 +3EB914E70076 +3EE6D4A85643 +40DABA780B41 +4119340759A2 +415210E0C6BB +416D21717779 +41B1839829A9 +4201A36DE766 +4261A795D5A7 +42AA0B29626E +430265958BEB +4317C5C16EAD +431D799E0C89 +4342794AD7BB +4387ADE263DB +43982124C310 +4436CB060568 +44449507B736 +44E858C82975 +459BC12982B1 +45AE5DDA9830 +45C414CDC347 +45CE4E504C06 +461744C8EABD +46D012CA3BEC +47170BD112B6 +47C43D5DD234 +47CD4AC26271 +47D410D1C7C4 +4808C5AD0115 +485BEEDBC293 +486001404A80 +488CCC60B70A +49204E3CA169 +495657C78147 +4970714D53D9 +4AA715A0BBB4 +4B9901AEC16E +4BE0B912A5A3 +4CBC34D10D83 +4CD3ACABC6A3 +4CE00134DE1E +4CEB27151C49 +4D02A3D7CE48 +4D13683C7960 +4D1A263BA48B +4D23919463A3 +4D9763C083D9 +4DAC8EE52C68 +4DCB89C7B2E6 +4DD9D9B637C4 +4DE6CB63A920 +4DEBA10CC85D +4E232A8C2E30 +4E2879A411E7 +4EA7B0BED74B +4EB8761372EA +4EC2B23135AB +4EC71DB088DE +4EC9AB4B5519 +50179E461EE6 +50265ED9D468 +5047DC2975BE +508357498162 +508BE54D326E +510A8C52AAC4 +511335CC92CD +518229589A81 +5184D04315D7 +51B4AE31B246 +526EDB918BEE +529CE44BEBCC +52A843082BB3 +52AE9A909674 +5313E9079489 +532DE5E7E0E9 +535508AA6C91 +53691569B669 +540A5B789761 +547B86E57596 +54C649075B57 +552249203848 +55430B5318E9 +5570D22DC66B +55710879E113 +55D2E4AC0446 +56207539825A +564664475726 +566441C5C28C +56A7930913C3 +56C944B04618 +56D455A8BBEA +5726991C8C28 +5726AA3BE37B +573314090BA5 +577C31903867 +577C528E786C +57AD9604ED24 +580C377283C7 +587329CE3EBE +587C34557B36 +58B11E803B58 +5902E4DCC95D +5A060A64C535 +5A36898CA7C5 +5A4740D952EC +5A6ED7966868 +5A99578CAA13 +5AAD6814E68B +5B065568048A +5B6CE0B3AD0A +5B70E0B11758 +5B926E3751EB +5B9CA63C4267 +5BDC1391B289 +5C1D3898D537 +5C34B8E4A456 +5C36456EA1E5 +5C43A75C65A0 +5C5752328A47 +5C9D20250D74 +5CBA3CEE351A +5CD5E98A2864 +5CE0EB9C01B6 +5D384E6A4145 +5D9DB8445155 +5DE8717BB640 +5E1A4EE98748 +5E45A227B391 +5E8E50B3048B +5EB0EA0A9412 +6032C47B7676 +60E0C84ADDEE +612A447A2149 +612D81821854 +616B820EAD01 +616D75A4A022 +61DE2B085AC9 +62312EC272A0 +6232C5262CC6 +62B7C7C9B0D0 +62C531C6E29C +63E6AAAB4433 +644ABCC3DD12 +64AE7BEA1784 +6515B38077D6 +65972038CC25 +65E120DE5E55 +66141DDE8320 +66718BD91332 +668082242328 +668920AEE063 +6696C4332D46 +66C9880D1DC2 +67150CB11E95 +671737BA0054 +673551D0A99E +676D682C4336 +678B98AA2E86 +6847808E63EE +6887A122AA62 +6888C514DEAD +688BD5B7B4E9 +68A99E258692 +68C312391560 +68C9D33E3735 +6900A069E3D7 +690155BE8D8E +69174742042D +69B9CE233517 +6A0B123D7595 +6AB8E2B49E25 +6ABD4C4A72D9 +6B1CC539A1B2 +6B30B6B0925D +6B638C1C950D +6BAAAB1D4589 +6BAD01EBE736 +6BB4ED5E1682 +6CA178E036DA +6CE210B529C4 +6D23D505D2B1 +6D3CBD12BC6D +6D83563EB521 +6D98AB9CCC71 +6E3D7366E78C +6E5582237608 +6E6602904925 +6E77B8EB6444 +6E978A7B16C6 +6EEC05EB651C +70284824B26C +702CDACE0C14 +704E1B85BED8 +70BB123776D6 +70CCC3A2D7C0 +716A747CB931 +7173E199A420 +71BC9C9E31E4 +71CAEEA3B771 +71D8BA423D55 +72253C7DD951 +7260377CD286 +7280858E8B20 +72913BDAB647 +72B5B87BBC6E +72C83B1D098A +72DA8050A38E +735C2AB60A97 +736B602A93D9 +738D7833E7DE +73E7B22D6E54 +74133B1E2DED +74A929877793 +74E3670C045A +7531E3E2A41C +7542A9B65EB4 +7564993C91C7 +760ED0AB626E +762E0E021E38 +763D7E6BB40E +764B38E2903D +768016001C8D +76A616C3D42C +76AE99D9A294 +76BAAA710D25 +76E3B23696BC +77322DD2E184 +77B40902B6D9 +77C0AC14972D +77C1CE0E7674 +77D7B7E2C8BA +78279397A68E +7836593AB838 +783859EB51A6 +78CCDB50C193 +7932684154AE +79604362370E +796630ED27B3 +799E4E270953 +79A00573947A +79B798D66B01 +7A0455D0A7EC +7A33D19B7248 +7B0A8AE18817 +7B0BA045AB35 +7B0DE8504D57 +7B21781EC649 +7B7224C1AB79 +7B90C2BA9B23 +7BB90D382672 +7BBC9DC92836 +7C09DC408C47 +7C418B493454 +7C491D518242 +7C7A86CC727C +7CE836EBD228 +7D49042C530D +7E5744EC286C +7E680A48C383 +7EC45CCEC35A +7EDADA19EB57 +8005BD088847 +8022E705B640 +8031E3565825 +80499BAA5959 +807466CCBAB5 +810518578380 +810D24CB13CC +812B02C34A64 +8163A5DDE1CD +8186CE2B363E +81DE6062B9D7 +822017D8929A +8247C78188C5 +8270D538D5E8 +82D8E8DDE296 +831207CA6E8A +83378A077357 +83A05B477535 +840160379EEE +84044BAB78A7 +84366C6D7781 +8442CC9AA777 +8470AAD30447 +8498740493BB +84A35A698E93 +84ABDE484425 +84B24DBB9A67 +84B723B2A237 +852BEB133D74 +854501E98239 +854A0ED2E77D +85A066D39785 +8619557091AA +86228C3742A4 +8637BB3BA795 +8642D9310B46 +86538085966D +86EE9C410811 +870A042C1B34 +873B47C457E6 +873CE44DDC6B +874D123262E7 +87513C960770 +877641436923 +878A091B74B7 +87927467808B +88C2E39B5990 +88D252AC1A8A +891EDA20BDEA +89267DEE07ED +892CB89ACCC6 +8A2423E9D100 +8A6BC2E3811B +8A8EB5771EE9 +8A906B4B3211 +8AB21B524C5C +8AB823BDC2AE +8AC3B2ADE77B +8AC4317D049B +8ACD6B86EC44 +8AD966CA3B4D +8B0A3B3DCDD4 +8B1B6C705C1A +8B1C75E27153 +8B2A5E0332A1 +8B6216E412DB +8B7CCA9DB004 +8B9999AE9703 +8BABAD9A65C6 +8C32D0AE3DB7 +8C99807368A5 +8CC1133D7D5B +8CD2C872187A +8D0563B86DD4 +8D43D81E37B4 +8D96A800B21A +8D97B475C957 +8DA62EC0C524 +8DACA1BC0636 +8DE3B131D728 +8E55316D3B3D +8EE497C9A869 +90210DDAB57D +9026977EB8A6 +903AA4305025 +9083158A49A1 +9092D12E7967 +90D8713352D1 +911E097A27A9 +9140EC087241 +918A67D05479 +919B1D357E91 +9210BBA2AB26 +9224B6555E30 +9226D4D1236A +922E7955CC67 +929CC86B1B26 +929E1556110E +9302DEB79C5A +9384841B4702 +93B4BD1CB47C +93D985D55712 +940B37939AC6 +94673AE73823 +947A8147E0AE +94CD6A4B6391 +94CEEAC5A8D7 +95ABD3A7C631 +95E1C233EDE2 +9607AE17AD09 +960C98566E52 +96435BD1D29B +965D66E19245 +965D72659982 +9695167B4149 +96D0C3996714 +97274C21BD6C +973186B345BB +973A28C983A3 +979686C51AB6 +97992CE2DD31 +97E9D0C89DA8 +97EB8A44C49D +98314DC363C5 +9860DC044565 +988D023C15A5 +9917BDA7B4D7 +9996A233442A +9A2132B5B625 +9A694755A978 +9A7911ECC275 +9AA1E6CE588C +9ABCCD2AE7C7 +9B39A60D3841 +9C0630361CC5 +9C4E19AB64B1 +9CE96BADE4D8 +9D442B28BD11 +9D4C35AE1A08 +9E02910C691A +9E46407C9024 +9E74D104ACEA +9EDD416A7912 +A026642D13AD +A12908B38536 +A16EE9666D5A +A199132A4043 +A1AEC2B58BBA +A1BE42A15EDE +A1D0844C2C63 +A1E0103A1879 +A253602B9445 +A2B019B46CB9 +A2BBCC3B546C +A2C325A73A9C +A2CB60E815A0 +A314B97C1A6A +A3647146C335 +A3A580799BB4 +A3D30CC8EB97 +A402B5137D86 +A42158CC74B5 +A435DD64AD17 +A4693D21013B +A479A91EED49 +A4B30D146A01 +A5142D626200 +A54056E87CBB +A57DBD287491 +A588C918E327 +A593071D4758 +A5CC0EE7B9E3 +A6375E98A5B5 +A666347B3B4B +A6A203994202 +A6BAE1A1520D +A6E9885AA49D +A705087E89A8 +A7072D4324C7 +A745AD7D6789 +A750456E7C5E +A783A8774651 +A787C822020C +A78BB575EAC5 +A7905680A254 +A805534D84E9 +A86C2595A1C3 +A89903B6ADDB +A9182707A219 +A9391782A846 +A96B08E3A50B +A98DEB0733C9 +A9C37CE71D23 +AA2D69C757D9 +AA4E4558A9EE +AA6C835C9124 +AAC0C35C43EB +AB30CB2CB354 +AB6191DB240A +AB8953D3560C +ABBB521319E6 +AC47461358D7 +AC58C25A1559 +AC7D4B201D92 +AD061A23287D +AD105D52DB36 +AD4EA84D7185 +AD5038D15490 +AD97523144B2 +ADB24E78784B +ADCBD453B232 +AE516A187825 +AE52116C234C +AE817239CAB5 +AEA5A5A0E46B +AECC93678543 +B0452769A83C +B04D71906C60 +B0805C191424 +B09172DDBE43 +B13AE369390C +B14080E570D1 +B1419B62772C +B14775DEA2E2 +B188BA649EA1 +B1BB0DB95C67 +B1BB19BDD424 +B1E8B5054DAD +B1EBB537CC0D +B2174092CDC5 +B2554CC8AD6E +B2C5A2E88304 +B312E56ED250 +B37B48D8C1C5 +B39C699CD208 +B3B121208E34 +B3C3C6E4395B +B410B958C3B8 +B4204546A74E +B45171C5A67D +B4B103E693ED +B4DACABCAB07 +B506567A2B84 +B51083D5C2BD +B54D7674CB90 +B570E5EA1DA3 +B598984AD584 +B5D7E1135821 +B60D053A36D9 +B63957593E23 +B64558CAC0C9 +B68175BCA864 +B6CD1A3EC5BC +B72468A7710D +B75176C82A8B +B7AA0CA5D94A +B7B9D7E523B8 +B808D87AB75C +B93A6432E51A +B941A9D99B6C +B9DA40920237 +BA6C2E10086A +BA7384AB949E +BA8DEEE045E8 +BADC2149EC42 +BB1924266B36 +BB41640E6340 +BBB475DB2B03 +BBD4C4699719 +BC0B2C897267 +BC7BEE6B71C4 +BC8B21AD8802 +BCA2D8118631 +BCB7A7006400 +BCBC6637499B +BCBD2B8BE4B3 +BD213E28C568 +BD32E4EC7080 +BD401D63C3E9 +BD463C3693A4 +BD749E85586A +BD7CA11B9551 +BD96355CBE36 +BD9E6EB7B524 +BDADE6111218 +BDB576D1E88C +BDB5DC09C522 +BE19C75D6B7E +BE5B3ED935AC +BEA20C972E70 +BEEB4A159B37 +C01E8740DE38 +C0411C28857D +C045544AD1E4 +C04660B76831 +C0C4CA21B876 +C0E0E092C8B4 +C0EE394D3D95 +C14601C6B411 +C16EBAE928B2 +C189A791A85B +C1ACDB8C1890 +C1C55A7A99EA +C1D72A47755A +C1D8B91D65AA +C1E6149B386D +C22D8E2B1E37 +C23E999B6298 +C314E31A670D +C3D275A9B8C7 +C3EE19B61C89 +C427B93DC2ED +C443EEC4330D +C477B966D328 +C4C6CAE4784C +C55875BCB82C +C581CA998910 +C5ABC0A455C5 +C5BE33E6B1E2 +C629E0D34581 +C65194543D6B +C67B8E869D90 +C6BC3B9CCB41 +C7034BC581A6 +C748500B6947 +C757C15E9E0D +C798A8465ACB +C7B6702AC17B +C849133B7CCC +C870C98A4E91 +C90B7AD266D3 +C90D996C3A2D +C953797CCE61 +C9639352EEC8 +C983685AA86B +C9CCA6D095A3 +C9CE81D47EDB +C9D449AD9970 +CA0D9CCC4C38 +CA277AC09859 +CA56EB045188 +CAB92B865BAD +CAE8572C2657 +CB1CE185575C +CB2ECC3D9C22 +CB642A081A89 +CBBAD2DA0EC5 +CC1B5BD45315 +CC2C02300D34 +CC559969D0CC +CC5646BD7AEB +CC6A93BD93D1 +CC726DD08765 +CCBBAB6504A4 +CCC1EA3E27B8 +CD16EAB946E9 +CDB4EEE02E14 +CDC21E1E1EC7 +CE09B3870EA2 +CE5AA0C8B5A8 +CE63DE29E069 +D0368B24CA49 +D0489010A72C +D075379A21A6 +D09893B4EE04 +D0A7A2787570 +D0B8C06C02E4 +D106E94A4C3B +D11E7D1BBEEA +D12B25B8DDE2 +D1972D6CE2C3 +D1B91D224946 +D2752E53679D +D35B2B75CC52 +D40E935117A2 +D4C37528DC05 +D4C818A5455E +D4CD56DB8AEB +D5190BD5CED6 +D55E5AA3406D +D576E9D856D9 +D5E444E9D82D +D61A3231790D +D669B3AE1E11 +D6C075899D06 +D6C3503456C4 +D7AC70A05A0C +D80A37B6D7ED +D82E6938C58C +D85E51344EB6 +D8809EB9BA7D +D8913C2D48E9 +D9109460D912 +D94E36427E20 +D97E55B1816A +D99425130C1A +D99C3222A190 +D9A207103ED7 +D9C70CC5818A +DA3379D12773 +DA705702248C +DA818C56CE43 +DAE1888DCC0B +DBA0A2DCA8E0 +DBD9799E15B1 +DC242193D7E3 +DCB5AC62946C +DCB75AEC61A0 +DD6E0587A821 +DD7B1A7C6A82 +DDA22A189095 +DDDAE53AA711 +DDE7304E78B6 +DE1B4DA681B9 +DEAC67E2D7C1 +DEB7D7E4C62B +E127434AB3B7 +E1ACC6742AB7 +E1E59574ADBC +E1EA6BAA03D9 +E222553A59A2 +E2230B8E84C9 +E33E807EC3BA +E341574B2E32 +E42868808B70 +E43562C624B0 +E43D54DC3511 +E466090D2123 +E47069DA0C44 +E49DD6062901 +E4ACA0ADBA0D +E4B976AD6687 +E526BB7888DB +E53354B71B10 +E57581CE8617 +E61A1DA5A60E +E6293BDA5EDC +E64C2A07CA9B +E6600C4D6A44 +E6655B6425DC +E6BADC631036 +E70143BE0091 +E75E07A010D1 +E76962E3B8B4 +E8028A6DCC90 +E80C5E3E8227 +E8779E40450E +E8A9E2D87D36 +E8B5A0BDD993 +E933DA9735C4 +E93A2E63189D +E9447637E40D +E94836269887 +E94D82A564BA +E98DC3B561B5 +E9EB2DE57AE9 +EA490920877D +EA4C494C9353 +EA9B1695DD91 +EAD0E31A6834 +EB16B6462B66 +EB276C9AB68D +EB3C9732C3BA +EB44DDC408CE +EB8536C958B2 +EBC825C186B3 +EC1A55BB58EB +EC2B12107313 +EC8CB5758097 +ECD4C42EA3D1 +ED22B7115435 +ED2CE17A590C +ED65A9B6469C +ED6748113E0D +ED8CEB8B7102 +EDCE0890472D +EDD4A2EA7493 +EE17C426D25E +EE487A4C806E +EE5931913A8D +EED56840AEBA diff --git a/client/dictionaries/mfc_keys_icbmp_sorted.dic b/client/dictionaries/mfc_keys_icbmp_sorted.dic index b4a635d44..2fe3c0235 100644 --- a/client/dictionaries/mfc_keys_icbmp_sorted.dic +++ b/client/dictionaries/mfc_keys_icbmp_sorted.dic @@ -1,1001 +1,1000 @@ - -00383D96411D, -005307DB7853, -009A4C4C6C49, -00C447B8A2D2, -01124119AB54, -0117BAE4D8D9, -018861488381, -0267B4922681, -02974B9786C9, -02A46AC9233A, -02BED876BD48, -02D8A7729ED3, -02EB32B92D30, -03C34821DE9A, -03D87397E9A8, -042CDEE5D0BA, -044ED79417E1, -04524659496E, -04602A40C037, -048451A79DA1, -0490AD0C9283, -04E16965C142, -05138E278443, -052B99EC186E, -056D4B5D2915, -0578E317C419, -05865124E5CA, -0599E014139E, -05DB68DB9364, -066C127C208D, -06966B31A285, -06B577E0E480, -071B57D258CE, -072B300309C9, -0759955331EE, -0769855EEC13, -079B8DA54DB1, -082B68A67491, -0832E4783600, -08506533E741, -0853A982D793, -08629D1DD0D6, -087C0CDA3B46, -08AE4ECD7CE3, -0965220D2ECE, -09A14A80754E, -09ACEA48DD0D, -09DB8EE5458C, -09E6CB76C080, -0A44A754B592, -0A7328887DC2, -0A906663EE1C, -0AB08938E3DA, -0AD8AD0739A6, -0B00220EAE75, -0B1960681E79, -0B31815E6A7C, -0B3690D4B122, -0BB8414CB6EA, -0BEC525E3463, -0C296648344D, -0CB6CC83AC45, -0CCAD03DDBC6, -0D6C26AB25CD, -0DC9143735D1, -0DE8A36CBBCC, -0E175033BD77, -0E6478123917, -0E7D4AC83133, -0E8420B04083, -0EA607E1C4E3, -105743704432, -107A6AB6B305, -110BB6D5539D, -1114A47CC39A, -116AA873ACC8, -120616C6208E, -120C83C06317, -12343D71106C, -123A082E2AEA, -12E50BE60524, -133DC845505E, -138153A4351A, -1395C108B6B6, -1428C04BAAD1, -147D93848C70, -14A353C60820, -1504C1846399, -1523A1E39D03, -1532A2511A8B, -157308368E8E, -16065CC411E0, -1637D8ACA71E, -1639134699C7, -167358BB268E, -168DE72B3B5A, -16A05D5C31C3, -16B4442EAE97, -17197B247A4A, -1774DB1A8CA1, -17820DAA47B2, -1782BEDBD347, -17B561AA82B4, -17C548CBC3A6, -17DA5C873BC5, -18025130661E, -184B95B4E3C6, -18A3196D364B, -18A97BD26818, -18BE810A83DD, -18C3AC2A7E90, -194D4E1DE89D, -196E279BE9A9, -1A2C8D855336, -1A3A76ED470A, -1A55D4849951, -1A9872D00EC9, -1ACD5433BBDD, -1ADC527D5BDA, -1AE29C8CD672, -1B14CAC3D0C2, -1B20A6E1D06B, -1B30A7825B23, -1B3E45AEE657, -1B75E7B007DB, -1B9DABDEBAE0, -1BAB19D01495, -1BD3119E0363, -1BDA0D87A575, -1CD38D77090B, -1D12BBB575B1, -1E1A0DB8729C, -1E2DE60A477A, -1E3C71643766, -1E6ED46CE258, -1EE60A4A8D22, -200D45263629, -2013899194BB, -206CE78E0C6C, -20B51C977E54, -2142B57D369D, -2172D827D3E2, -2178ED80D581, -21B4BE97AE07, -21B91A26133A, -21C7650673CD, -220D815D366A, -22C2176E1CD6, -22C3AB41B123, -233D7B324CEE, -2340CBD61A71, -2348251AD23E, -2381B8214025, -23BAE8DA1AC5, -23C317B8D6DA, -243A41574A39, -248EA5E91987, -2491457885A7, -255A9E590BCC, -257192699E32, -25892216C620, -2595E5B1DE76, -25AE69DED1B4, -25BA8775B3C4, -25D967D4DD35, -25DB996D56ED, -25EE21CDE4B9, -2625E408276B, -26B744C673DB, -26C6D38B8257, -26D787613684, -27689527E201, -27743B5A5736, -27D1635ED1B3, -27D5B8D2642E, -28035CA5B300, -2812EB6A427C, -28133B46730A, -281499DD16A0, -281DD9E6C98E, -2870E08CEDBA, -28B8685B1B22, -28C3D17E4DEC, -2953C63E9E58, -295D3C9A8B28, -297B74853CAA, -29ACACC2828E, -29EA97BC4A6B, -29EB3CA1C0DE, -2A079CC2AD37, -2A27E0602400, -2A45A0D8D6EE, -2A47CDD3A322, -2A4C4DB1D71D, -2AA82B4B6711, -2ABD68BDC5A3, -2AE7BDB10CB4, -2B051C90BE82, -2B490231E063, -2BAB94372644, -2C03252C10E7, -2C3EE5E98804, -2CB671E6365D, -2CC55B46705B, -2CD09D3C0A1B, -2CECBC323E31, -2D302827C9B4, -2D716C9C467B, -2D8856109732, -2E15681A4355, -2E79209B9519, -2EEE063290C1, -301C9AA3DECA, -30C520D6A2B9, -30D6324910AB, -3113AADC9D6B, -3124ACA5491C, -315AD0D6E6D2, -31A16DAC864D, -31EC44581294, -32DE3CD81C24, -32E532232C29, -33256E443128, -33293485AD61, -33305B0365AA, -3343B72BAA71, -3372C9C5D4AE, -33754E0D1687, -33A444334869, -33B54345C32E, -34002AAEE45D, -343C556CEE59, -3444DDE6D7E5, -345B62452538, -3495A04A9270, -34EB673C863B, -35123500C1EA, -353A7167576B, -3599856810B2, -35E7DE9899EE, -35EDABB506D8, -36C54912D10E, -36CA0101B6DC, -36D268442846, -373E5827E0B8, -376D6C446746, -37E2EAE635B5, -381B0A70E135, -3862B259DC71, -386676C44A13, -3905679DEEC4, -39070618BB17, -394181105544, -395D38815892, -39A00E856381, -39C0E2ED99B5, -3A1E82E2CDB7, -3A5D13E05B6A, -3A6DE2081CDD, -3A8498924010, -3A9D49E8BEB2, -3AD0EE1031A9, -3B052E65D40A, -3B4986981212, -3B4C51ACC53D, -3B99486097C6, -3BB36BC22CE4, -3BB4B3025B79, -3BBB7BD8D7B7, -3C09C971D835, -3C4A12E7A107, -3C633B3474DD, -3CB9E31D6022, -3CD344A7EB21, -3CD8C6705954, -3CE887B9D091, -3D5EA1C71953, -3D89120EB993, -3D9C3245AE76, -3DED9D496478, -3E0913A96E74, -3E34909990B5, -3E7DD7953DDD, -3EEB33434C1A, -4015D16B5C1C, -401C81A72C56, -40E7B8D60242, -41016C0CB8DE, -4124864B0D40, -415BAA0CAB15, -418184DBB4A0, -419513740558, -4195EE7238CC, -41B727883B27, -41BC44A8C3C6, -41DDC3A48EEA, -420445087613, -42068108DE36, -4245921D73CA, -42A959953C45, -430E67734C18, -4314D9D03B95, -43166BCA83EB, -43400A093A7E, -434CE764DE91, -43595AC786EE, -438099331C1E, -43814087A7B5, -438C3CD95B58, -43B3E895B281, -44074C461042, -444D37149B20, -44A04DAA30CB, -4537282554C5, -4584EACB6087, -45DB3799C150, -45E599AE38EA, -462305611C4A, -4636195CDA2D, -46752993E2E9, -4684316440D6, -46C7246C1958, -4751A5274848, -4761E34CB054, -476388408D8E, -478947735B45, -47AD81972D5B, -47C23398EA52, -47E9D4D4BE35, -4812AEC4B01A, -48276645A4EA, -48644467A214, -489C783B3514, -48C860AA4B74, -495C6639575B, -49681C20A00D, -49E8249DD677, -49E93C110AA1, -4A24470C19C5, -4A4755BC4A2A, -4A4D5E3A9011, -4A65D627625C, -4A6B36C5BCCC, -4AB725ED89B5, -4B39E3923D0D, -4B59316C10E0, -4C275C8BB2DA, -4C2E9455D296, -4C44DB1D0C3A, -4C67059B0006, -4CA30E1A298A, -4CA74DAC7C01, -4CB212D72D57, -4CD3B228EBB4, -4CE1972E090C, -4CEE1794E0EA, -4D06DBCA167E, -4D2CC85EB338, -4D40BC7A44DB, -4D769DA515D3, -4D79C95DAD2D, -4DBAC8ECE167, -4E3CB839E87D, -4E3D548E1267, -4E8250E29617, -4E94C7962769, -5038884E4178, -505B5A8EB20A, -50642C36DA00, -5083664D8C09, -50B77DA96DE2, -511E269A9BAE, -51798AEAAE9E, -51ED5833AB6D, -525335E4CD34, -5261CDDA279E, -526E55542A54, -529C16A720AB, -52A230B1C50E, -52AADA374811, -52D20D6E3E35, -534BB4A6984E, -5352CCC3DCD2, -540B15E8019D, -54AA2915E815, -558DB8891A90, -55A691710B48, -55D1E91B1D35, -55D95774E9A0, -563C6B96D59D, -567032E13B54, -56741B108D22, -57029D991123, -5714E9D33034, -5734CD8A65DA, -5785EE00049E, -57B8B111491D, -57CC9D0AA32B, -57D7D4D746DA, -583C936DCB4B, -586B470A43B3, -5876E1D34183, -58B6AE62DB88, -58C35C8BC9AB, -597E98000ED4, -59DB4DBB5D7A, -5A150653E624, -5A211CE57C4B, -5A6272CDBE9C, -5ACB8043C10C, -5B41CEBC2213, -5B59BCC4321E, -5BA03479BB8C, -5BC64C42281C, -5C9B1A8E31CD, -5C9BD0AC1DB1, -5D223E990AD8, -5D8C3A5C5761, -5DA57EACA38C, -5E41DD5D1154, -5E6ABB51EC75, -5E7CC04C3A58, -5E810C48C8D8, -5E8943D9A836, -5ED616273468, -60100DD0E023, -6033A1C0E431, -6088A566CC60, -60B20ADA0471, -60B8411D876E, -60C742D8D9C0, -6135433CC5EA, -6153ADD80A15, -61718ED2C94D, -6175241B035A, -61780BCB0C57, -61B701698050, -61C4E56629A3, -61D59C284952, -61E57B490A55, -622E5E0812D7, -6251CE7E547A, -62953A89B137, -62D6EAA06CD6, -630228659A47, -632931BE8EC7, -63539BB89DEE, -636CB69BB10C, -63783393E20D, -639DB16995B7, -63AA2A5B076C, -63B636458E94, -6443E64DCC4B, -64695084C575, -6493D06D5710, -649B302A97C5, -64B8632B54D4, -654BACB21C3B, -65A3D5823819, -65DEDABD1B34, -6608944EE186, -665B8B24C20D, -6685D0BE19E0, -66933A9E7982, -674C7BB59A16, -675E35EE359E, -67AA98E362C9, -67D47C1B6425, -67DE22850162, -67E8B986B2A7, -681EA28BA6CD, -6828B52B6507, -6874E54471E8, -6879B1CA44A3, -68C00A810D41, -68C9E8AA5C3E, -697A8ED07418, -69B5357A617A, -6A7B3A7B6735, -6AA40421D23C, -6AB676B4DB9D, -6B00420BE41C, -6B0B7B967871, -6B9D041136B4, -6BB1A14768A8, -6BCAE24D9700, -6C0458728774, -6C57CBD51995, -6C5E10B86CDE, -6CA491A8C7B8, -6CBC25C1DA2E, -6CD430D99958, -6CEC27647CC0, -6D4D29CEB9B5, -6D6E9A6B725D, -6D801AC74572, -6D97408C6D60, -6DDE6E871C64, -6DEA848B6195, -6E05B5C44A54, -6E751666AE9A, -6E7DBCDA05B3, -7004BA1763ED, -7016ECD01559, -7076D48D5E49, -7091621EA016, -709311997549, -70984C14D3DB, -70D73BE22CDD, -70D9461C5E90, -712BC18422CB, -712E6CAA74A4, -7164042BA89E, -7175E14A4D62, -718B39561350, -718BDA352E28, -719B1418323E, -71A8D54D82B3, -71DC30168C27, -7221E016597B, -7234CC6BD65D, -727A80DD5296, -72B393D6E8A9, -732C9BE4DDBA, -736B4A835B2B, -73EA81968900, -740AB5126199, -741A31054E6B, -74498C1D4B3D, -745276053CB6, -74684B0B4B1D, -74772915E24C, -74A24BE33BE2, -74A778236D5A, -74AA58008A31, -74C27A96CB3A, -754AD5773746, -756C15E54212, -759403A563D8, -759D2130312B, -75A0E10D8C84, -75A807E46B96, -75E454785C6C, -76078A25C088, -76140285B768, -763D835BD5ED, -767C33468C72, -76962C07EC9E, -76984E62CCE4, -769AE4646931, -76E5DA67A1EC, -7708D5CAD58B, -77383BAA4D90, -7789E646A556, -779A248E098C, -77DB71037644, -77E0A57DD456, -7853D464E2A4, -78EA6EB04463, -7909427EC8B9, -7910A31ECD19, -79271963B6E8, -793D98517D33, -79B7A4C58DE0, -79B9148761B3, -7A2893B75AD1, -7A4C61A1B48D, -7A7469B69C6A, -7AA84B1A527D, -7B00211CA416, -7B118EABC7BB, -7B1D9A2E22AA, -7B583D350740, -7B9D3A6BD061, -7C2DAC2CC775, -7C4CBBD2DDE1, -7CD52B5B8E77, -7D412100532B, -7D46C149DAD9, -7D4CA630E229, -7DAC0E83D335, -7DC935E220A0, -7DCA66BACA13, -7E30778792D2, -7E43C3BAB3CB, -7E475BA186E6, -7EE2A624851A, -80CED5362B2C, -80D2CC78E10B, -80D62251E20C, -816875D55ED1, -81950D0517AC, -81B519418C3E, -8211571B9D16, -823C7CC6E06A, -826DD63B9032, -827303C574B5, -82C5ADED4B81, -82E344329D34, -83588E140165, -835D33B48113, -8384148AE52D, -8394B57153D6, -83A0184757C0, -83D86835B48B, -8502EE9A7E85, -852C2B72659D, -8534A6CE0911, -85ABD94CD7A9, -85DA8099CD7E, -85E0B6B26945, -864CA2A6BE93, -868A33A44447, -86EDEABCC357, -87DDD5A188EE, -8830379B50B7, -883803A3360C, -883DA78EC87D, -88482A12C2C6, -888EBD3DB945, -88D026793359, -88DD4B7C5991, -8931DC3733D4, -894D8E2DCDEE, -897B845C2680, -89B638BD909E, -89D2C28BE578, -8A1869848D1A, -8A39D09508C9, -8ACCC7290C8C, -8AD8B41EC218, -8B028B7E6D60, -8B6A95C7D2E2, -8BA1226EBA21, -8BD586B21ABC, -8C0EA504B635, -8CA939DC6DE4, -8CAE5D688443, -8CEC639E64DC, -8DECE0DD29DE, -8E0EC762E883, -8E958D8B8C52, -8EB64D710C88, -8ED4A17717D9, -8EE9D9C03A0D, -9014E1430AEB, -90965DEBC8B9, -90E56E616DDD, -912CD8E04437, -912E33563E1B, -918048032247, -919402EC39CB, -91D28E2B126D, -9216EEE5B677, -9232215296B2, -925A070E9096, -925A5521D48D, -92CC200886A2, -932035869655, -937144459949, -93B260DBC70A, -94552B863E37, -95327A0A3600, -954275CDD7E0, -957E6EE3EB55, -95B920CACC84, -96382E1C8E12, -964E8E5338BD, -96706C8D6ECC, -96759A0D5566, -96D5213C5DDB, -97300764797A, -973BDDBE7434, -974838AE17A0, -9752A6B316D5, -97926543783B, -97EB373096CA, -982D6054B83D, -989D127BD496, -98A54AD58A43, -98A92128364C, -98CD5AA2A4DB, -98E8C543688E, -99207A00AA4A, -99243E754CB8, -9925893ABAC7, -9937553A965E, -9976E6ADE0C9, -9982E3E6A4A0, -9984C1A3229E, -99C487AB85EC, -99E2A19C9673, -9A05EBE41D7D, -9A138D1A5CB7, -9A179148B824, -9A6EC0A9ECB8, -9A720CBD7BB1, -9AB22BBDDD87, -9AC43B5A06D8, -9AD8150BE648, -9AD97423190D, -9B4ADDDEB749, -9B7603341727, -9C45237377BE, -9D090AE1A15E, -9D59641E40A5, -9DA4528CEB8C, -9DA728164176, -9DAC62A346B7, -9E0E9D983B9A, -9E5271763D3D, -9EE95586D024, -9EEE39E00CBB, -A04671256EE2, -A091485B4B5D, -A1B5577ED36E, -A1EB280E3901, -A2789E1DD888, -A293A90AE72C, -A309E3AEBDB9, -A3196E77B072, -A31E72DCC826, -A34DEA01690E, -A36031D6ECB2, -A38044A3E18E, -A421D7A04C4B, -A424C686CA39, -A44590A779A5, -A47AD3895C63, -A5041E8B8E22, -A50DC0830AA5, -A52B8929D665, -A5BCBA6BE592, -A61D5137E6B3, -A6344C0418DC, -A690A817B9D9, -A7E3B3459240, -A81E6D3C8E11, -A8C0BE436685, -A8DE205120A8, -A91E2BE6C308, -A9258D6B06B5, -A992B5E070C1, -AAC6E3205D48, -AB101546634E, -AB6EE0761ACA, -AB9BCA200547, -AC4BC5B2D3C0, -AC7A0B47B03E, -AC88B26AC1D0, -ACAEB3456AD9, -ACB906631D8A, -ACE07B45C0C5, -AD1992AE37CA, -AD5586744A60, -AD674E4ADB79, -ADA093B06831, -AE7C3AE5334A, -AE9EB8CAB2C3, -AEAE9E5CE65D, -B002D1BDC29B, -B0463E703098, -B063B209BB20, -B0788BE3BAA4, -B0C3B3299090, -B128298D9073, -B160677E7035, -B19D3D57176A, -B1CCDB7999B9, -B231AA398B90, -B250E9590215, -B28BE0D819ED, -B292C9554CBA, -B2D8485C2460, -B31763D9D0DE, -B328014DDD6A, -B378C424C9E2, -B3D8C03C78E0, -B41D18E3B980, -B46824B972E9, -B50383A32302, -B509D631967C, -B56CA847A7C3, -B56EC9A20D28, -B5B763215C82, -B6550EAC573A, -B66060201705, -B6614EBEAAA2, -B6A18CBD4DA6, -B6ABB62E437E, -B6C6558E58CA, -B7009204D512, -B71D5B22B1C2, -B7392DD1E497, -B7709ED7CE60, -B7A26320A491, -B7A9DA22E9C6, -B7DEC863369D, -B7E9A91174CB, -B8178A34E2DC, -B83092098A7D, -B84C50E56DEC, -B89BD135E935, -B8E87380D361, -B9485A9648C6, -B9ED829C22AE, -BA227EE91818, -BA7BBD9683B1, -BA8224EA7A80, -BA84C974B356, -BAD293A45C8A, -BB850C7E4934, -BBC1256810A4, -BC1CD369549E, -BC5C76E5909C, -BC66E9270049, -BC6AB08B03CC, -BC74CA2C2B06, -BC7C64828C1D, -BCCC3A719013, -BD06E96EB7D7, -BD196D0A74E0, -BE02790E84AC, -BE1266314B9D, -BE518C742B74, -BE5695316117, -BE5D8EBA120D, -BE8286DA7D12, -BE9CE00EE4DD, -C003962B3462, -C0067E095049, -C015A21E0146, -C03BC03AD437, -C06CE7D57A0D, -C07EE1E10B56, -C0885A29251E, -C198163ABECE, -C1EB7337A035, -C225479C7064, -C2740E1665A8, -C27924128A00, -C2A701656B8B, -C2C30D21C53E, -C2CBB2ACD38D, -C38D19A9C8D1, -C3B1BB7E7492, -C3BA2438A981, -C3CD74758DE2, -C4033B3BB1D7, -C404D280640E, -C4467DE80B2D, -C46A048C88DD, -C52877867C05, -C56D005E258E, -C56D052D5533, -C5BB2CCCB9C3, -C5C272694A1E, -C6121BC4A29C, -C65EEAE02433, -C661C4AE1DD1, -C76C94B495CA, -C7BD49777A79, -C7CD131E9B60, -C7E35D6294BA, -C8E173DB04CC, -C95855AE08E8, -C98147E69033, -C99A004E6133, -C9E893C4090B, -CA119C79A197, -CA309D2CBC41, -CA4BAA390BC4, -CA92DD257E21, -CA968EBEB9C7, -CADED0C50AC4, -CB18774EA550, -CB1999D19E10, -CB75C1BAE669, -CC2517AB2346, -CC2AC1AD29CA, -CD11359C7A90, -CD14C8553CB9, -CD333295BBE2, -CD3DB8C27E5C, -CDA811AD5055, -CDABDCA23986, -CDCA8BD7B002, -CE0456AB0DCE, -CE58AE1C51E9, -CE76E8A600DC, -CE95875316C8, -CEB105E65289, -CEB651752D4C, -CEE02D97E5BD, -D023DB35ED05, -D0BE546CC06B, -D0CE7EB0D379, -D10329D366C8, -D15C004DBC8D, -D16E6B668254, -D1CEEC977644, -D1DC0E1CC09E, -D2550925679B, -D28B2D42DE1A, -D2926519AC09, -D313116A45B4, -D3DC10453857, -D431C8C73BDC, -D4C67846791C, -D5629384CE7D, -D5ABE7180600, -D62A4A0E57C2, -D660CE9E3080, -D66AE9282140, -D6A91C14AC47, -D6E23B4E75C6, -D726C4979654, -D76DE12943B4, -D7A405AD9E4E, -D7BD3AE48E93, -D7D49700BBCC, -D7E8A5089E7A, -D84C81EE910D, -D8545199A949, -D86243C1380E, -D88A12EB3622, -D89B5EA419C1, -D8A3690B0115, -D94646A4C65B, -D982B4846A96, -DA303BADB013, -DAD9A48A8C33, -DAEB5D63920B, -DB01A99DD94C, -DB22BB7D6818, -DB37160CBB4B, -DB7E3687E450, -DC7697E37A9B, -DCC44C4E9269, -DCCE477E785E, -DD68DE9CDA5A, -DE1B08C6D94B, -DE41BBD7E68D, -DE6E04AE4475, -DE8CD4277A9E, -DEA8098D6E51, -DEB2BEE8858A, -DEB550958AD9, -E045E6309471, -E0E21213C611, -E0E457054B62, -E1097C69DA4A, -E1EA831EA514, -E20716902884, -E2C9CB14C06C, -E33B66EA2705, -E34C5B12BABA, -E38A1C654E82, -E3905BA54194, -E3E3919444CA, -E4450EC1010C, -E49A03306224, -E5100AC4C6C3, -E5124DB665A6, -E5491B5E3DD6, -E5BE9C989A29, -E5C3A9A27D3E, -E65111EB1E40, -E65792427D4C, -E7004C5EA94A, -E705087DECBB, -E7CB93E68155, -E81512343BAD, -E8428C8B0740, -E859EBC22318, -E87267A508DB, -E886AE7D1BE0, -E8B008239600, -E8C4B4A4E482, -E8D53410B736, -E902964DA28D, -E9203D5BD2DA, -E9526CACA8B2, -E9C11D763BEC, -EA3BDAA4E498, -EA61AC8B4969, -EA8E8ADC26B9, -EB5588EAE5E8, -EBA964C07075, -EC71B679D3AA, -ECB4019ADD97, -ED14D0A14B0C, -ED296C79266C, -EDBA3C943EA8, -EDC7CEBD4000, -EDE2747DA6C3, -EE3029556CEB, -EE49610E6121, -EEB704D69BCA, -EED69A391464, +00383D96411D +005307DB7853 +009A4C4C6C49 +00C447B8A2D2 +01124119AB54 +0117BAE4D8D9 +018861488381 +0267B4922681 +02974B9786C9 +02A46AC9233A +02BED876BD48 +02D8A7729ED3 +02EB32B92D30 +03C34821DE9A +03D87397E9A8 +042CDEE5D0BA +044ED79417E1 +04524659496E +04602A40C037 +048451A79DA1 +0490AD0C9283 +04E16965C142 +05138E278443 +052B99EC186E +056D4B5D2915 +0578E317C419 +05865124E5CA +0599E014139E +05DB68DB9364 +066C127C208D +06966B31A285 +06B577E0E480 +071B57D258CE +072B300309C9 +0759955331EE +0769855EEC13 +079B8DA54DB1 +082B68A67491 +0832E4783600 +08506533E741 +0853A982D793 +08629D1DD0D6 +087C0CDA3B46 +08AE4ECD7CE3 +0965220D2ECE +09A14A80754E +09ACEA48DD0D +09DB8EE5458C +09E6CB76C080 +0A44A754B592 +0A7328887DC2 +0A906663EE1C +0AB08938E3DA +0AD8AD0739A6 +0B00220EAE75 +0B1960681E79 +0B31815E6A7C +0B3690D4B122 +0BB8414CB6EA +0BEC525E3463 +0C296648344D +0CB6CC83AC45 +0CCAD03DDBC6 +0D6C26AB25CD +0DC9143735D1 +0DE8A36CBBCC +0E175033BD77 +0E6478123917 +0E7D4AC83133 +0E8420B04083 +0EA607E1C4E3 +105743704432 +107A6AB6B305 +110BB6D5539D +1114A47CC39A +116AA873ACC8 +120616C6208E +120C83C06317 +12343D71106C +123A082E2AEA +12E50BE60524 +133DC845505E +138153A4351A +1395C108B6B6 +1428C04BAAD1 +147D93848C70 +14A353C60820 +1504C1846399 +1523A1E39D03 +1532A2511A8B +157308368E8E +16065CC411E0 +1637D8ACA71E +1639134699C7 +167358BB268E +168DE72B3B5A +16A05D5C31C3 +16B4442EAE97 +17197B247A4A +1774DB1A8CA1 +17820DAA47B2 +1782BEDBD347 +17B561AA82B4 +17C548CBC3A6 +17DA5C873BC5 +18025130661E +184B95B4E3C6 +18A3196D364B +18A97BD26818 +18BE810A83DD +18C3AC2A7E90 +194D4E1DE89D +196E279BE9A9 +1A2C8D855336 +1A3A76ED470A +1A55D4849951 +1A9872D00EC9 +1ACD5433BBDD +1ADC527D5BDA +1AE29C8CD672 +1B14CAC3D0C2 +1B20A6E1D06B +1B30A7825B23 +1B3E45AEE657 +1B75E7B007DB +1B9DABDEBAE0 +1BAB19D01495 +1BD3119E0363 +1BDA0D87A575 +1CD38D77090B +1D12BBB575B1 +1E1A0DB8729C +1E2DE60A477A +1E3C71643766 +1E6ED46CE258 +1EE60A4A8D22 +200D45263629 +2013899194BB +206CE78E0C6C +20B51C977E54 +2142B57D369D +2172D827D3E2 +2178ED80D581 +21B4BE97AE07 +21B91A26133A +21C7650673CD +220D815D366A +22C2176E1CD6 +22C3AB41B123 +233D7B324CEE +2340CBD61A71 +2348251AD23E +2381B8214025 +23BAE8DA1AC5 +23C317B8D6DA +243A41574A39 +248EA5E91987 +2491457885A7 +255A9E590BCC +257192699E32 +25892216C620 +2595E5B1DE76 +25AE69DED1B4 +25BA8775B3C4 +25D967D4DD35 +25DB996D56ED +25EE21CDE4B9 +2625E408276B +26B744C673DB +26C6D38B8257 +26D787613684 +27689527E201 +27743B5A5736 +27D1635ED1B3 +27D5B8D2642E +28035CA5B300 +2812EB6A427C +28133B46730A +281499DD16A0 +281DD9E6C98E +2870E08CEDBA +28B8685B1B22 +28C3D17E4DEC +2953C63E9E58 +295D3C9A8B28 +297B74853CAA +29ACACC2828E +29EA97BC4A6B +29EB3CA1C0DE +2A079CC2AD37 +2A27E0602400 +2A45A0D8D6EE +2A47CDD3A322 +2A4C4DB1D71D +2AA82B4B6711 +2ABD68BDC5A3 +2AE7BDB10CB4 +2B051C90BE82 +2B490231E063 +2BAB94372644 +2C03252C10E7 +2C3EE5E98804 +2CB671E6365D +2CC55B46705B +2CD09D3C0A1B +2CECBC323E31 +2D302827C9B4 +2D716C9C467B +2D8856109732 +2E15681A4355 +2E79209B9519 +2EEE063290C1 +301C9AA3DECA +30C520D6A2B9 +30D6324910AB +3113AADC9D6B +3124ACA5491C +315AD0D6E6D2 +31A16DAC864D +31EC44581294 +32DE3CD81C24 +32E532232C29 +33256E443128 +33293485AD61 +33305B0365AA +3343B72BAA71 +3372C9C5D4AE +33754E0D1687 +33A444334869 +33B54345C32E +34002AAEE45D +343C556CEE59 +3444DDE6D7E5 +345B62452538 +3495A04A9270 +34EB673C863B +35123500C1EA +353A7167576B +3599856810B2 +35E7DE9899EE +35EDABB506D8 +36C54912D10E +36CA0101B6DC +36D268442846 +373E5827E0B8 +376D6C446746 +37E2EAE635B5 +381B0A70E135 +3862B259DC71 +386676C44A13 +3905679DEEC4 +39070618BB17 +394181105544 +395D38815892 +39A00E856381 +39C0E2ED99B5 +3A1E82E2CDB7 +3A5D13E05B6A +3A6DE2081CDD +3A8498924010 +3A9D49E8BEB2 +3AD0EE1031A9 +3B052E65D40A +3B4986981212 +3B4C51ACC53D +3B99486097C6 +3BB36BC22CE4 +3BB4B3025B79 +3BBB7BD8D7B7 +3C09C971D835 +3C4A12E7A107 +3C633B3474DD +3CB9E31D6022 +3CD344A7EB21 +3CD8C6705954 +3CE887B9D091 +3D5EA1C71953 +3D89120EB993 +3D9C3245AE76 +3DED9D496478 +3E0913A96E74 +3E34909990B5 +3E7DD7953DDD +3EEB33434C1A +4015D16B5C1C +401C81A72C56 +40E7B8D60242 +41016C0CB8DE +4124864B0D40 +415BAA0CAB15 +418184DBB4A0 +419513740558 +4195EE7238CC +41B727883B27 +41BC44A8C3C6 +41DDC3A48EEA +420445087613 +42068108DE36 +4245921D73CA +42A959953C45 +430E67734C18 +4314D9D03B95 +43166BCA83EB +43400A093A7E +434CE764DE91 +43595AC786EE +438099331C1E +43814087A7B5 +438C3CD95B58 +43B3E895B281 +44074C461042 +444D37149B20 +44A04DAA30CB +4537282554C5 +4584EACB6087 +45DB3799C150 +45E599AE38EA +462305611C4A +4636195CDA2D +46752993E2E9 +4684316440D6 +46C7246C1958 +4751A5274848 +4761E34CB054 +476388408D8E +478947735B45 +47AD81972D5B +47C23398EA52 +47E9D4D4BE35 +4812AEC4B01A +48276645A4EA +48644467A214 +489C783B3514 +48C860AA4B74 +495C6639575B +49681C20A00D +49E8249DD677 +49E93C110AA1 +4A24470C19C5 +4A4755BC4A2A +4A4D5E3A9011 +4A65D627625C +4A6B36C5BCCC +4AB725ED89B5 +4B39E3923D0D +4B59316C10E0 +4C275C8BB2DA +4C2E9455D296 +4C44DB1D0C3A +4C67059B0006 +4CA30E1A298A +4CA74DAC7C01 +4CB212D72D57 +4CD3B228EBB4 +4CE1972E090C +4CEE1794E0EA +4D06DBCA167E +4D2CC85EB338 +4D40BC7A44DB +4D769DA515D3 +4D79C95DAD2D +4DBAC8ECE167 +4E3CB839E87D +4E3D548E1267 +4E8250E29617 +4E94C7962769 +5038884E4178 +505B5A8EB20A +50642C36DA00 +5083664D8C09 +50B77DA96DE2 +511E269A9BAE +51798AEAAE9E +51ED5833AB6D +525335E4CD34 +5261CDDA279E +526E55542A54 +529C16A720AB +52A230B1C50E +52AADA374811 +52D20D6E3E35 +534BB4A6984E +5352CCC3DCD2 +540B15E8019D +54AA2915E815 +558DB8891A90 +55A691710B48 +55D1E91B1D35 +55D95774E9A0 +563C6B96D59D +567032E13B54 +56741B108D22 +57029D991123 +5714E9D33034 +5734CD8A65DA +5785EE00049E +57B8B111491D +57CC9D0AA32B +57D7D4D746DA +583C936DCB4B +586B470A43B3 +5876E1D34183 +58B6AE62DB88 +58C35C8BC9AB +597E98000ED4 +59DB4DBB5D7A +5A150653E624 +5A211CE57C4B +5A6272CDBE9C +5ACB8043C10C +5B41CEBC2213 +5B59BCC4321E +5BA03479BB8C +5BC64C42281C +5C9B1A8E31CD +5C9BD0AC1DB1 +5D223E990AD8 +5D8C3A5C5761 +5DA57EACA38C +5E41DD5D1154 +5E6ABB51EC75 +5E7CC04C3A58 +5E810C48C8D8 +5E8943D9A836 +5ED616273468 +60100DD0E023 +6033A1C0E431 +6088A566CC60 +60B20ADA0471 +60B8411D876E +60C742D8D9C0 +6135433CC5EA +6153ADD80A15 +61718ED2C94D +6175241B035A +61780BCB0C57 +61B701698050 +61C4E56629A3 +61D59C284952 +61E57B490A55 +622E5E0812D7 +6251CE7E547A +62953A89B137 +62D6EAA06CD6 +630228659A47 +632931BE8EC7 +63539BB89DEE +636CB69BB10C +63783393E20D +639DB16995B7 +63AA2A5B076C +63B636458E94 +6443E64DCC4B +64695084C575 +6493D06D5710 +649B302A97C5 +64B8632B54D4 +654BACB21C3B +65A3D5823819 +65DEDABD1B34 +6608944EE186 +665B8B24C20D +6685D0BE19E0 +66933A9E7982 +674C7BB59A16 +675E35EE359E +67AA98E362C9 +67D47C1B6425 +67DE22850162 +67E8B986B2A7 +681EA28BA6CD +6828B52B6507 +6874E54471E8 +6879B1CA44A3 +68C00A810D41 +68C9E8AA5C3E +697A8ED07418 +69B5357A617A +6A7B3A7B6735 +6AA40421D23C +6AB676B4DB9D +6B00420BE41C +6B0B7B967871 +6B9D041136B4 +6BB1A14768A8 +6BCAE24D9700 +6C0458728774 +6C57CBD51995 +6C5E10B86CDE +6CA491A8C7B8 +6CBC25C1DA2E +6CD430D99958 +6CEC27647CC0 +6D4D29CEB9B5 +6D6E9A6B725D +6D801AC74572 +6D97408C6D60 +6DDE6E871C64 +6DEA848B6195 +6E05B5C44A54 +6E751666AE9A +6E7DBCDA05B3 +7004BA1763ED +7016ECD01559 +7076D48D5E49 +7091621EA016 +709311997549 +70984C14D3DB +70D73BE22CDD +70D9461C5E90 +712BC18422CB +712E6CAA74A4 +7164042BA89E +7175E14A4D62 +718B39561350 +718BDA352E28 +719B1418323E +71A8D54D82B3 +71DC30168C27 +7221E016597B +7234CC6BD65D +727A80DD5296 +72B393D6E8A9 +732C9BE4DDBA +736B4A835B2B +73EA81968900 +740AB5126199 +741A31054E6B +74498C1D4B3D +745276053CB6 +74684B0B4B1D +74772915E24C +74A24BE33BE2 +74A778236D5A +74AA58008A31 +74C27A96CB3A +754AD5773746 +756C15E54212 +759403A563D8 +759D2130312B +75A0E10D8C84 +75A807E46B96 +75E454785C6C +76078A25C088 +76140285B768 +763D835BD5ED +767C33468C72 +76962C07EC9E +76984E62CCE4 +769AE4646931 +76E5DA67A1EC +7708D5CAD58B +77383BAA4D90 +7789E646A556 +779A248E098C +77DB71037644 +77E0A57DD456 +7853D464E2A4 +78EA6EB04463 +7909427EC8B9 +7910A31ECD19 +79271963B6E8 +793D98517D33 +79B7A4C58DE0 +79B9148761B3 +7A2893B75AD1 +7A4C61A1B48D +7A7469B69C6A +7AA84B1A527D +7B00211CA416 +7B118EABC7BB +7B1D9A2E22AA +7B583D350740 +7B9D3A6BD061 +7C2DAC2CC775 +7C4CBBD2DDE1 +7CD52B5B8E77 +7D412100532B +7D46C149DAD9 +7D4CA630E229 +7DAC0E83D335 +7DC935E220A0 +7DCA66BACA13 +7E30778792D2 +7E43C3BAB3CB +7E475BA186E6 +7EE2A624851A +80CED5362B2C +80D2CC78E10B +80D62251E20C +816875D55ED1 +81950D0517AC +81B519418C3E +8211571B9D16 +823C7CC6E06A +826DD63B9032 +827303C574B5 +82C5ADED4B81 +82E344329D34 +83588E140165 +835D33B48113 +8384148AE52D +8394B57153D6 +83A0184757C0 +83D86835B48B +8502EE9A7E85 +852C2B72659D +8534A6CE0911 +85ABD94CD7A9 +85DA8099CD7E +85E0B6B26945 +864CA2A6BE93 +868A33A44447 +86EDEABCC357 +87DDD5A188EE +8830379B50B7 +883803A3360C +883DA78EC87D +88482A12C2C6 +888EBD3DB945 +88D026793359 +88DD4B7C5991 +8931DC3733D4 +894D8E2DCDEE +897B845C2680 +89B638BD909E +89D2C28BE578 +8A1869848D1A +8A39D09508C9 +8ACCC7290C8C +8AD8B41EC218 +8B028B7E6D60 +8B6A95C7D2E2 +8BA1226EBA21 +8BD586B21ABC +8C0EA504B635 +8CA939DC6DE4 +8CAE5D688443 +8CEC639E64DC +8DECE0DD29DE +8E0EC762E883 +8E958D8B8C52 +8EB64D710C88 +8ED4A17717D9 +8EE9D9C03A0D +9014E1430AEB +90965DEBC8B9 +90E56E616DDD +912CD8E04437 +912E33563E1B +918048032247 +919402EC39CB +91D28E2B126D +9216EEE5B677 +9232215296B2 +925A070E9096 +925A5521D48D +92CC200886A2 +932035869655 +937144459949 +93B260DBC70A +94552B863E37 +95327A0A3600 +954275CDD7E0 +957E6EE3EB55 +95B920CACC84 +96382E1C8E12 +964E8E5338BD +96706C8D6ECC +96759A0D5566 +96D5213C5DDB +97300764797A +973BDDBE7434 +974838AE17A0 +9752A6B316D5 +97926543783B +97EB373096CA +982D6054B83D +989D127BD496 +98A54AD58A43 +98A92128364C +98CD5AA2A4DB +98E8C543688E +99207A00AA4A +99243E754CB8 +9925893ABAC7 +9937553A965E +9976E6ADE0C9 +9982E3E6A4A0 +9984C1A3229E +99C487AB85EC +99E2A19C9673 +9A05EBE41D7D +9A138D1A5CB7 +9A179148B824 +9A6EC0A9ECB8 +9A720CBD7BB1 +9AB22BBDDD87 +9AC43B5A06D8 +9AD8150BE648 +9AD97423190D +9B4ADDDEB749 +9B7603341727 +9C45237377BE +9D090AE1A15E +9D59641E40A5 +9DA4528CEB8C +9DA728164176 +9DAC62A346B7 +9E0E9D983B9A +9E5271763D3D +9EE95586D024 +9EEE39E00CBB +A04671256EE2 +A091485B4B5D +A1B5577ED36E +A1EB280E3901 +A2789E1DD888 +A293A90AE72C +A309E3AEBDB9 +A3196E77B072 +A31E72DCC826 +A34DEA01690E +A36031D6ECB2 +A38044A3E18E +A421D7A04C4B +A424C686CA39 +A44590A779A5 +A47AD3895C63 +A5041E8B8E22 +A50DC0830AA5 +A52B8929D665 +A5BCBA6BE592 +A61D5137E6B3 +A6344C0418DC +A690A817B9D9 +A7E3B3459240 +A81E6D3C8E11 +A8C0BE436685 +A8DE205120A8 +A91E2BE6C308 +A9258D6B06B5 +A992B5E070C1 +AAC6E3205D48 +AB101546634E +AB6EE0761ACA +AB9BCA200547 +AC4BC5B2D3C0 +AC7A0B47B03E +AC88B26AC1D0 +ACAEB3456AD9 +ACB906631D8A +ACE07B45C0C5 +AD1992AE37CA +AD5586744A60 +AD674E4ADB79 +ADA093B06831 +AE7C3AE5334A +AE9EB8CAB2C3 +AEAE9E5CE65D +B002D1BDC29B +B0463E703098 +B063B209BB20 +B0788BE3BAA4 +B0C3B3299090 +B128298D9073 +B160677E7035 +B19D3D57176A +B1CCDB7999B9 +B231AA398B90 +B250E9590215 +B28BE0D819ED +B292C9554CBA +B2D8485C2460 +B31763D9D0DE +B328014DDD6A +B378C424C9E2 +B3D8C03C78E0 +B41D18E3B980 +B46824B972E9 +B50383A32302 +B509D631967C +B56CA847A7C3 +B56EC9A20D28 +B5B763215C82 +B6550EAC573A +B66060201705 +B6614EBEAAA2 +B6A18CBD4DA6 +B6ABB62E437E +B6C6558E58CA +B7009204D512 +B71D5B22B1C2 +B7392DD1E497 +B7709ED7CE60 +B7A26320A491 +B7A9DA22E9C6 +B7DEC863369D +B7E9A91174CB +B8178A34E2DC +B83092098A7D +B84C50E56DEC +B89BD135E935 +B8E87380D361 +B9485A9648C6 +B9ED829C22AE +BA227EE91818 +BA7BBD9683B1 +BA8224EA7A80 +BA84C974B356 +BAD293A45C8A +BB850C7E4934 +BBC1256810A4 +BC1CD369549E +BC5C76E5909C +BC66E9270049 +BC6AB08B03CC +BC74CA2C2B06 +BC7C64828C1D +BCCC3A719013 +BD06E96EB7D7 +BD196D0A74E0 +BE02790E84AC +BE1266314B9D +BE518C742B74 +BE5695316117 +BE5D8EBA120D +BE8286DA7D12 +BE9CE00EE4DD +C003962B3462 +C0067E095049 +C015A21E0146 +C03BC03AD437 +C06CE7D57A0D +C07EE1E10B56 +C0885A29251E +C198163ABECE +C1EB7337A035 +C225479C7064 +C2740E1665A8 +C27924128A00 +C2A701656B8B +C2C30D21C53E +C2CBB2ACD38D +C38D19A9C8D1 +C3B1BB7E7492 +C3BA2438A981 +C3CD74758DE2 +C4033B3BB1D7 +C404D280640E +C4467DE80B2D +C46A048C88DD +C52877867C05 +C56D005E258E +C56D052D5533 +C5BB2CCCB9C3 +C5C272694A1E +C6121BC4A29C +C65EEAE02433 +C661C4AE1DD1 +C76C94B495CA +C7BD49777A79 +C7CD131E9B60 +C7E35D6294BA +C8E173DB04CC +C95855AE08E8 +C98147E69033 +C99A004E6133 +C9E893C4090B +CA119C79A197 +CA309D2CBC41 +CA4BAA390BC4 +CA92DD257E21 +CA968EBEB9C7 +CADED0C50AC4 +CB18774EA550 +CB1999D19E10 +CB75C1BAE669 +CC2517AB2346 +CC2AC1AD29CA +CD11359C7A90 +CD14C8553CB9 +CD333295BBE2 +CD3DB8C27E5C +CDA811AD5055 +CDABDCA23986 +CDCA8BD7B002 +CE0456AB0DCE +CE58AE1C51E9 +CE76E8A600DC +CE95875316C8 +CEB105E65289 +CEB651752D4C +CEE02D97E5BD +D023DB35ED05 +D0BE546CC06B +D0CE7EB0D379 +D10329D366C8 +D15C004DBC8D +D16E6B668254 +D1CEEC977644 +D1DC0E1CC09E +D2550925679B +D28B2D42DE1A +D2926519AC09 +D313116A45B4 +D3DC10453857 +D431C8C73BDC +D4C67846791C +D5629384CE7D +D5ABE7180600 +D62A4A0E57C2 +D660CE9E3080 +D66AE9282140 +D6A91C14AC47 +D6E23B4E75C6 +D726C4979654 +D76DE12943B4 +D7A405AD9E4E +D7BD3AE48E93 +D7D49700BBCC +D7E8A5089E7A +D84C81EE910D +D8545199A949 +D86243C1380E +D88A12EB3622 +D89B5EA419C1 +D8A3690B0115 +D94646A4C65B +D982B4846A96 +DA303BADB013 +DAD9A48A8C33 +DAEB5D63920B +DB01A99DD94C +DB22BB7D6818 +DB37160CBB4B +DB7E3687E450 +DC7697E37A9B +DCC44C4E9269 +DCCE477E785E +DD68DE9CDA5A +DE1B08C6D94B +DE41BBD7E68D +DE6E04AE4475 +DE8CD4277A9E +DEA8098D6E51 +DEB2BEE8858A +DEB550958AD9 +E045E6309471 +E0E21213C611 +E0E457054B62 +E1097C69DA4A +E1EA831EA514 +E20716902884 +E2C9CB14C06C +E33B66EA2705 +E34C5B12BABA +E38A1C654E82 +E3905BA54194 +E3E3919444CA +E4450EC1010C +E49A03306224 +E5100AC4C6C3 +E5124DB665A6 +E5491B5E3DD6 +E5BE9C989A29 +E5C3A9A27D3E +E65111EB1E40 +E65792427D4C +E7004C5EA94A +E705087DECBB +E7CB93E68155 +E81512343BAD +E8428C8B0740 +E859EBC22318 +E87267A508DB +E886AE7D1BE0 +E8B008239600 +E8C4B4A4E482 +E8D53410B736 +E902964DA28D +E9203D5BD2DA +E9526CACA8B2 +E9C11D763BEC +EA3BDAA4E498 +EA61AC8B4969 +EA8E8ADC26B9 +EB5588EAE5E8 +EBA964C07075 +EC71B679D3AA +ECB4019ADD97 +ED14D0A14B0C +ED296C79266C +EDBA3C943EA8 +EDC7CEBD4000 +EDE2747DA6C3 +EE3029556CEB +EE49610E6121 +EEB704D69BCA +EED69A391464 diff --git a/client/dictionaries/mfc_keys_mrzd_sorted.dic b/client/dictionaries/mfc_keys_mrzd_sorted.dic index 025f1b995..f2ebafc10 100644 --- a/client/dictionaries/mfc_keys_mrzd_sorted.dic +++ b/client/dictionaries/mfc_keys_mrzd_sorted.dic @@ -1,57 +1,57 @@ -010203040506, -013940233313, -022FE48B3072, -123456789ABC, -123456ABCDEF, -17505586EF02, -1795902DBAF9, -1A2B3C4D5E6F, -1A982C7E459A, -200306202033, -2011092119F1, -2012053082AD, -37D4DCA92451, -40E5EA1EFC00, -435330666666, -46868F6D5677, -474249437569, -4D3A99C351DD, -533CB6C723F6, -5554AAA96321, -587EE5F9350F, -5A1B85FCE20A, -5D293AFC8D7E, -64A2EE93B12B, -64E2283FCF5E, -714C5C886E97, -833FBD3CFE51, -83BAB5ACAD62, -872B71F9D15A, -8F9B229047AC, -8FD0A4F256E9, -9AEDF9931EC1, -9B1DD7C030A1, -A0478CC39091, -A0A1A2A3A4A5, -A2B2C9D187FB, -A4EF6C3BB692, -AABBCC660429, -AABBCCDDEEFF, -ABCDEF123456, -B0699AD03D17, -B0B1B2B3B4B5, -BA28CFD15EE8, -BCFE01BCFE01, -C0C1C2C3C4C5, -CFC738403AB0, -D0D1D2D3D4D5, -D3F7D3F7D3F7, -DB5181C92CBE, -DFED39FFBB76, -E1DD284379D4, -E96246531342, -ED3A7EFBFF56, -F83466888612, -F89C86B2A961, -FFFFAE82366C, -FFFFD06F83E3, +010203040506 +013940233313 +022FE48B3072 +123456789ABC +123456ABCDEF +17505586EF02 +1795902DBAF9 +1A2B3C4D5E6F +1A982C7E459A +200306202033 +2011092119F1 +2012053082AD +37D4DCA92451 +40E5EA1EFC00 +435330666666 +46868F6D5677 +474249437569 +4D3A99C351DD +533CB6C723F6 +5554AAA96321 +587EE5F9350F +5A1B85FCE20A +5D293AFC8D7E +64A2EE93B12B +64E2283FCF5E +714C5C886E97 +833FBD3CFE51 +83BAB5ACAD62 +872B71F9D15A +8F9B229047AC +8FD0A4F256E9 +9AEDF9931EC1 +9B1DD7C030A1 +A0478CC39091 +A0A1A2A3A4A5 +A2B2C9D187FB +A4EF6C3BB692 +AABBCC660429 +AABBCCDDEEFF +ABCDEF123456 +B0699AD03D17 +B0B1B2B3B4B5 +BA28CFD15EE8 +BCFE01BCFE01 +C0C1C2C3C4C5 +CFC738403AB0 +D0D1D2D3D4D5 +D3F7D3F7D3F7 +DB5181C92CBE +DFED39FFBB76 +E1DD284379D4 +E96246531342 +ED3A7EFBFF56 +F83466888612 +F89C86B2A961 +FFFFAE82366C +FFFFD06F83E3 diff --git a/client/dictionaries/mfulc_default_keys.dic b/client/dictionaries/mfulc_default_keys.dic index 3c0c01acd..51b4b9365 100644 --- a/client/dictionaries/mfulc_default_keys.dic +++ b/client/dictionaries/mfulc_default_keys.dic @@ -2,4 +2,5 @@ # Mifare Ultralight Default Keys # -- iceman fork version -- # -- contribute to this list, sharing is caring -- -425245414B4D454946594F5543414E21 -- Sample Key (BREAKMEIFYOUCAN!) +# +425245414B4D454946594F5543414E21 # Sample Key (BREAKMEIFYOUCAN!) diff --git a/client/dictionaries/t55xx_default_pwds.dic b/client/dictionaries/t55xx_default_pwds.dic index aa2b23719..511be26d1 100644 --- a/client/dictionaries/t55xx_default_pwds.dic +++ b/client/dictionaries/t55xx_default_pwds.dic @@ -1,123 +1,123 @@ # known cloners # ref. http://www.proxmark.org/forum/viewtopic.php?id=2022 -51243648, -000D8787, -19920427, -65857569, //chinese "handheld RFID writer" blue cloner from circa 2013 (also sold by xfpga.com) +51243648 +000D8787 +19920427 +65857569 //chinese "handheld RFID writer" blue cloner from circa 2013 (also sold by xfpga.com) # ref. http://kazus.ru/forums/showpost.php?p=1045937&postcount=77 -05D73B9F, +05D73B9F # ref. http://www.proxmark.org/forum/viewtopic.php?= -89A69E60, +89A69E60 # ref lock -314159E0, +314159E0 # ref. http://www.proxmark.org/forum/viewtopic.php?pid=28115#p28115 -AA55BBBB, +AA55BBBB # ref. http://www.proxmark.org/forum/viewtopic.php?pid=33376#p33376 -A5B4C3D2, -# ref. http://www.proxmark.org/forum/viewtopic.php?pid=30379#p30379 -1C0B5848, -# http://www.proxmark.org/forum/viewtopic.php?pid=35075#p35075 -00434343, -44B44CAE, -88661858, +A5B4C3D2 +# ref. http://www.proxmark.org/forum/viewtopic.php?pid=30379#p30379 +1C0B5848 +# ref. http://www.proxmark.org/forum/viewtopic.php?pid=35075#p35075 +00434343 +44B44CAE +88661858 # paxton bullit? -575F4F4B, +575F4F4B # -50520901, +50520901 # Default pwd, simple: -00000000, -11111111, -22222222, -33333333, -44444444, -55555555, -66666666, -77777777, -88888888, -99999999, -AAAAAAAA, -BBBBBBBB, -CCCCCCCC, -DDDDDDDD, -EEEEEEEE, -FFFFFFFF, -a0a1a2a3, -b0b1b2b3, -aabbccdd, -bbccddee, -ccddeeff, -50415353, -00000001, -00000002, -0000000a, -0000000b, -01020304, -02030405, -03040506, -04050607, -05060708, -06070809, -0708090A, -08090A0B, -090A0B0C, -0A0B0C0D, -0B0C0D0E, -0C0D0E0F, -01234567, -12345678, -10000000, -20000000, -30000000, -40000000, -50000000, -60000000, -70000000, -80000000, -90000000, -A0000000, -B0000000, -C0000000, -D0000000, -E0000000, -F0000000, -10101010, -01010101, -11223344, -22334455, -33445566, -44556677, -55667788, -66778899, -778899AA, -8899AABB, -99AABBCC, -AABBCCDD, -BBCCDDEE, -CCDDEEFF, -0CB7E7FC, //rfidler? -FABADA11, //china? +00000000 +11111111 +22222222 +33333333 +44444444 +55555555 +66666666 +77777777 +88888888 +99999999 +AAAAAAAA +BBBBBBBB +CCCCCCCC +DDDDDDDD +EEEEEEEE +FFFFFFFF +a0a1a2a3 +b0b1b2b3 +aabbccdd +bbccddee +ccddeeff +50415353 +00000001 +00000002 +0000000a +0000000b +01020304 +02030405 +03040506 +04050607 +05060708 +06070809 +0708090A +08090A0B +090A0B0C +0A0B0C0D +0B0C0D0E +0C0D0E0F +01234567 +12345678 +10000000 +20000000 +30000000 +40000000 +50000000 +60000000 +70000000 +80000000 +90000000 +A0000000 +B0000000 +C0000000 +D0000000 +E0000000 +F0000000 +10101010 +01010101 +11223344 +22334455 +33445566 +44556677 +55667788 +66778899 +778899AA +8899AABB +99AABBCC +AABBCCDD +BBCCDDEE +CCDDEEFF +0CB7E7FC # rfidler? +FABADA11 # china? # 20 most common len==8 -87654321, -12341234, -69696969, -12121212, -12344321, -1234ABCD, -11112222, -13131313, -10041004, +87654321 +12341234 +69696969 +12121212 +12344321 +1234ABCD +11112222 +13131313 +10041004 # -31415926, //pii -abcd1234, -20002000, -19721972, -aa55aa55, // amiboo -55aa55aa, // rev amiboo -4f271149, // seeds ul-ev1 -07d7bb0b, // seeds ul-ev1 -9636ef8f, // seeds ul-ev1 -b5f44686, // seeds ul-ev1 -9E3779B9, // TEA -C6EF3720, // TEA -7854794A, // xbox tea constant :) -F1EA5EED, // burtle +31415926 # pii +abcd1234 +20002000 +19721972 +aa55aa55 # amiboo +55aa55aa # rev amiboo +4f271149 # seeds ul-ev1 +07d7bb0b # seeds ul-ev1 +9636ef8f # seeds ul-ev1 +b5f44686 # seeds ul-ev1 +9E3779B9 # TEA +C6EF3720 # TEA +7854794A # xbox tea constant :) +F1EA5EED # burtle From e8efeacc57340f5ee72479931fb6148b9693c8f9 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 23:06:18 +0200 Subject: [PATCH 080/347] remove ON_DEVICE from fileutils --- client/fileutils.c | 7 ------- client/fileutils.h | 18 ------------------ 2 files changed, 25 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index b89925334..1bbcd890c 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -42,9 +42,6 @@ #include "commonutil.h" #include "util.h" - -#ifndef ON_DEVICE - #define PATH_MAX_LENGTH 100 /** @@ -612,7 +609,3 @@ int convertOldMfuDump(uint8_t **dump, size_t *dumplen) { return PM3_SUCCESS; } - -#else //if we're on ARM - -#endif diff --git a/client/fileutils.h b/client/fileutils.h index 79b053fc2..f5e51f470 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -38,8 +38,6 @@ #ifndef FILEUTILS_H #define FILEUTILS_H -#ifndef ON_DEVICE - #include #include #include @@ -162,20 +160,4 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u */ int convertOldMfuDump(uint8_t **dump, size_t *dumplen); -#define PrintAndLogEx(level, format, args...) PrintAndLogEx(level, format , ## args) -#else - -/** -* Utility function to print to console. This is used consistently within the library instead -* of printf, but it actually only calls printf. The reason to have this method is to -*make it simple to plug this library into proxmark, which has this function already to -* write also to a logfile. When doing so, just point this function to use PrintAndLog -* @param fmt -*/ -#define PrintAndLogEx(level, format, args...) { } - - - -#endif //ON_DEVICE - #endif // FILEUTILS_H From 3ebc00854ba9cb6a6abbf62e38239c6cd56ae445 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 22 Aug 2019 23:55:37 +0200 Subject: [PATCH 081/347] Add searchAndList & searchFile in fileutils --- client/cmdscript.c | 135 +++------------------------------------------ client/fileutils.c | 96 ++++++++++++++++++++++++++++++++ client/fileutils.h | 3 + 3 files changed, 107 insertions(+), 127 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index eb7979a00..8a748b8ab 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -8,10 +8,6 @@ // Some lua scripting glue to proxmark core. //----------------------------------------------------------------------------- -// this define is needed for scandir/alphasort to work -#define _GNU_SOURCE - -#include #include #include @@ -28,56 +24,8 @@ #include "ui.h" #include "fileutils.h" -#ifdef _WIN32 -#include "scandir.h" -#endif - static int CmdHelp(const char *Cmd); -static int str_ends_with(const char *str, const char *suffix) { - - if (str == NULL || suffix == NULL) - return 0; - - size_t str_len = strlen(str); - size_t suffix_len = strlen(suffix); - - if (suffix_len > str_len) - return 0; - - return 0 == strncmp(str + str_len - suffix_len, suffix, suffix_len); -} - -/** - * Utility to check the ending of a string (used to check file suffix) - */ -static bool endsWith(const char *base, const char *str) { - int blen = strlen(base); - int slen = strlen(str); - return (blen >= slen) && (0 == strcmp(base + blen - slen, str)); -} - -static int scriptlist(const char *path, bool last) { - struct dirent **namelist; - int n; - - n = scandir(path, &namelist, NULL, alphasort); - if (n == -1) { - PrintAndLogEx(NORMAL, "%s── %s => NOT FOUND", last ? "└" : "├", path); - return PM3_EFILE; - } - - PrintAndLogEx(NORMAL, "%s── %s", last ? "└" : "├", path); - for (uint16_t i = 0; i < n; i++) { - if (str_ends_with(namelist[i]->d_name, ".lua")) { - PrintAndLogEx(NORMAL, "%s   %s── %-21s", last ? " ":"│", i == n-1 ? "└" : "├", namelist[i]->d_name); - } - free(namelist[i]); - } - free(namelist); - return PM3_SUCCESS; -} - /** * Generate a sorted list of available commands, what it does is * generate a file listing of the script-directory for files @@ -85,28 +33,7 @@ static int scriptlist(const char *path, bool last) { */ static int CmdScriptList(const char *Cmd) { (void)Cmd; // Cmd is not used so far - - if (get_my_executable_directory() != NULL) { - char script_directory_path[strlen(get_my_executable_directory()) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; - strcpy(script_directory_path, get_my_executable_directory()); - strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path, false); - } - char *userpath = getenv("HOME"); - if (userpath != NULL) { - char script_directory_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; - strcpy(script_directory_path, userpath); - strcat(script_directory_path, PM3_USER_DIRECTORY); - strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path, false); - } - { - char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + 1]; - strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY); - strcat(script_directory_path, LUA_SCRIPTS_DIRECTORY); - scriptlist(script_directory_path, true); - } - return 0; + return searchAndList(LUA_SCRIPTS_DIRECTORY, ".lua"); } /** @@ -139,61 +66,15 @@ static int CmdScriptRun(const char *Cmd) { int arg_len = 0; sscanf(Cmd, "%127s%n %255[^\n\r]%n", script_name, &name_len, arguments, &arg_len); - const char *suffix = ""; - if (!endsWith(script_name, ".lua")) { - suffix = ".lua"; - } - - bool found = false; - int error; - const char* exec_path = get_my_executable_directory(); - - if (exec_path != NULL) { - char script_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, exec_path); - strcat(script_path, LUA_SCRIPTS_DIRECTORY); - strcat(script_path, script_name); - strcat(script_path, suffix); - if (fileExists(script_path)) - { - PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); - found = true; - error = luaL_loadfile(lua_state, script_path); - } - } - char *userpath = getenv("HOME"); - if ((!found) && (userpath != NULL)) { - char script_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, userpath); - strcat(script_path, PM3_USER_DIRECTORY); - strcat(script_path, LUA_SCRIPTS_DIRECTORY); - strcat(script_path, script_name); - strcat(script_path, suffix); - if (fileExists(script_path)) - { - PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); - found = true; - error = luaL_loadfile(lua_state, script_path); - } - } - if (!found) { - char script_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(script_name) + strlen(suffix) + 1]; - strcpy(script_path, PM3_SYSTEM_DIRECTORY); - strcat(script_path, LUA_SCRIPTS_DIRECTORY); - strcat(script_path, script_name); - strcat(script_path, suffix); - if (fileExists(script_path)) - { - PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); - found = true; - error = luaL_loadfile(lua_state, script_path); - } - } - if (!found) { - PrintAndLogEx(FAILED, "Error - can't find script %s%s", script_name, suffix); + char *script_path = searchFile(LUA_SCRIPTS_DIRECTORY, ".lua", script_name); + if (script_path == NULL) { + PrintAndLogEx(FAILED, "Error - can't find script %s", script_name); return PM3_EFILE; } - + int error; + PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); + error = luaL_loadfile(lua_state, script_path); + free(script_path); if (!error) { lua_pushstring(lua_state, arguments); lua_setglobal(lua_state, "args"); diff --git a/client/fileutils.c b/client/fileutils.c index 1bbcd890c..403f7fc27 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -34,13 +34,21 @@ * * ****************************************************************************/ + +// this define is needed for scandir/alphasort to work +#define _GNU_SOURCE #include "fileutils.h" +#include #include #include "pm3_cmd.h" #include "commonutil.h" +#include "proxmark3.h" #include "util.h" +#ifdef _WIN32 +#include "scandir.h" +#endif #define PATH_MAX_LENGTH 100 @@ -609,3 +617,91 @@ int convertOldMfuDump(uint8_t **dump, size_t *dumplen) { return PM3_SUCCESS; } +static int filelist(const char *path, const char *ext, bool last) { + struct dirent **namelist; + int n; + + n = scandir(path, &namelist, NULL, alphasort); + if (n == -1) { + PrintAndLogEx(NORMAL, "%s── %s => NOT FOUND", last ? "└" : "├", path); + return PM3_EFILE; + } + + PrintAndLogEx(NORMAL, "%s── %s", last ? "└" : "├", path); + for (uint16_t i = 0; i < n; i++) { + if (((ext == NULL) && (namelist[i]->d_name[0] != '.')) || (str_endswith(namelist[i]->d_name, ext))) { + PrintAndLogEx(NORMAL, "%s   %s── %-21s", last ? " ":"│", i == n-1 ? "└" : "├", namelist[i]->d_name); + } + free(namelist[i]); + } + free(namelist); + return PM3_SUCCESS; +} + +int searchAndList(const char *pm3dir, const char *ext) { + if (get_my_executable_directory() != NULL) { + char script_directory_path[strlen(get_my_executable_directory()) + strlen(pm3dir) + 1]; + strcpy(script_directory_path, get_my_executable_directory()); + strcat(script_directory_path, pm3dir); + filelist(script_directory_path, ext, false); + } + char *userpath = getenv("HOME"); + if (userpath != NULL) { + char script_directory_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + 1]; + strcpy(script_directory_path, userpath); + strcat(script_directory_path, PM3_USER_DIRECTORY); + strcat(script_directory_path, pm3dir); + filelist(script_directory_path, ext, false); + } + { + char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(pm3dir) + 1]; + strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY); + strcat(script_directory_path, pm3dir); + filelist(script_directory_path, ext, true); + } + return PM3_SUCCESS; +} + +char *searchFile(const char *pm3dir, const char *ext, const char *filename) { + const char *suffix = ""; + if (!str_endswith(filename, ext)) { + suffix = ext; + } + const char *exec_path = get_my_executable_directory(); + if (exec_path != NULL) { + char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); + strcpy(path, exec_path); + strcat(path, pm3dir); + strcat(path, filename); + strcat(path, suffix); + if (fileExists(path)) + return path; + else + free(path); + } + char *user_path = getenv("HOME"); + if (user_path != NULL) { + char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); + strcpy(path, user_path); + strcat(path, PM3_USER_DIRECTORY); + strcat(path, pm3dir); + strcat(path, filename); + strcat(path, suffix); + if (fileExists(path)) + return path; + else + free(path); + } + { + char *path = malloc(strlen(PM3_SYSTEM_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); + strcpy(path, PM3_SYSTEM_DIRECTORY); + strcat(path, pm3dir); + strcat(path, filename); + strcat(path, suffix); + if (fileExists(path)) + return path; + else + free(path); + } + return NULL; +} diff --git a/client/fileutils.h b/client/fileutils.h index f5e51f470..99c3c4d1d 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -160,4 +160,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u */ int convertOldMfuDump(uint8_t **dump, size_t *dumplen); +int searchAndList(const char *pm3dir, const char *ext); +char *searchFile(const char *pm3dir, const char *ext, const char *filename); + #endif // FILEUTILS_H From 440c05cdfa46145229cabdd479a0647c1451140e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 00:08:19 +0200 Subject: [PATCH 082/347] searchFile accepts also explicit absolute or relative path --- client/fileutils.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/fileutils.c b/client/fileutils.c index 403f7fc27..7500ea8dd 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -667,6 +667,22 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) { if (!str_endswith(filename, ext)) { suffix = ext; } + + // explicit absolute (/) or relative path (./) => try only to match it directly + if (((strlen(filename) > 1) && (filename[0] == '/')) || + ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) + { + char *path = malloc(strlen(filename) + strlen(suffix) + 1); + strcpy(path, filename); + strcat(path, suffix); + if (fileExists(path)) + return path; + else + free(path); + return NULL; + } + // else + // try pm3 dirs in current workdir (dev mode) const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); @@ -679,6 +695,7 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) { else free(path); } + // try pm3 dirs in user .proxmark3 (user mode) char *user_path = getenv("HOME"); if (user_path != NULL) { char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); @@ -692,6 +709,7 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) { else free(path); } + // try pm3 dirs in pm3 installation dir (install mode) { char *path = malloc(strlen(PM3_SYSTEM_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); strcpy(path, PM3_SYSTEM_DIRECTORY); From 4b2b103e80ffec00722262427dd2b79733a5ad24 Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 23 Aug 2019 15:23:55 +0200 Subject: [PATCH 083/347] Update mfc_default_keys.dic data from forum, --- client/dictionaries/mfc_default_keys.dic | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/client/dictionaries/mfc_default_keys.dic b/client/dictionaries/mfc_default_keys.dic index 4b1430c2f..ff63a0a83 100644 --- a/client/dictionaries/mfc_default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -964,3 +964,21 @@ DFE73BE48AC6 # B069D0D03D17 000131B93F28 +# +# From the DFW Area, TX, USA +# +a506370e7c0f +26396f2042e7 +70758fdd31e0 +9f9d8eeddcce +06ff5f03aa1a +4098653289d3 +904735f00f9e +b4c36c79da8d +68f9a1f0b424 +5a85536395b3 +7dd399d4e897 +ef4c5a7ac6fc +b47058139187 +8268046cd154 +67cc03b7d577 From 87cbf3aa70cc974810467435c2a7ef6988c960df Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Fri, 23 Aug 2019 17:17:17 +0200 Subject: [PATCH 084/347] Improved the reliability, speed and redability. Ready for a pull mr. iceman ;) --- client/cmdhfmf.c | 479 ++++++++++++++++++--------------------------- client/fileutils.c | 30 +++ client/fileutils.h | 11 ++ 3 files changed, 233 insertions(+), 287 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index c68daa9f3..e968548b6 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -169,15 +169,16 @@ static int usage_hf14_hardnested(void) { static int usage_hf14_hardautopwn(void) { PrintAndLogEx(NORMAL, "Usage:"); PrintAndLogEx(NORMAL, " hf mf hardautopwn [k] "); - PrintAndLogEx(NORMAL, " * [d] [f] [s] [t] [i]"); + PrintAndLogEx(NORMAL, " * [d] [f] [s] [i] [l]"); PrintAndLogEx(NORMAL, " (card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); PrintAndLogEx(NORMAL, " d write keys to binary file"); - PrintAndLogEx(NORMAL, " f keys to test (speed up the cracking, if some keys are known)"); + PrintAndLogEx(NORMAL, " f .dic dictionary file for key discovery (the file has to end in .dic)"); PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards)"); + PrintAndLogEx(NORMAL, " l legacy mode (use the slow mfchk for the key enumeration)"); PrintAndLogEx(NORMAL, " i set type of SIMD instructions. Without this flag programs autodetect it."); PrintAndLogEx(NORMAL, " i 5 = AVX512"); PrintAndLogEx(NORMAL, " i 2 = AVX2"); @@ -187,9 +188,12 @@ static int usage_hf14_hardautopwn(void) { PrintAndLogEx(NORMAL, " i n = none (use CPU regular instruction set)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn d"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn * 1 d f default_keys"); PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF d"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF * 1 d f default_keys.dic"); + PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF * 1 d f default_keys"); PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF * 4 s i 5"); + PrintAndLogEx(NORMAL, ""); return 0; } @@ -1559,57 +1563,44 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { static int CmdHF14AMfHardAuto(const char *Cmd) { - /* - Author: Matthias Konrath - Company: Trustworks GmbH - Email: m.konrath@trustworks.at - */ - uint8_t blockNo = 0; uint8_t keyType = 0; - uint8_t *keyBlock, *p; + uint8_t *keyBlock; uint8_t sectorsCnt = MIFARE_1K_MAXSECTOR; sector_t *e_sector; - uint8_t arr[80]; - uint8_t key[6] = {0, 0, 0, 0, 0, 0}; - uint8_t tmpKey[6]; + uint8_t key[6] = {0}; + uint8_t tmpKey[6] = {0}; uint64_t key64 = 0; + uint16_t keycnt = 0; + size_t datalen = 0; + uint32_t chunksize; - uint64_t t1; + uint64_t t1; // For the timier uint8_t foundKeysDictionary = 0; - uint8_t foundKeysReuse = 0; + uint8_t foundKeysReused = 0; uint8_t foundKeysHardnested = 0; - keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); - if (keyBlock == NULL) return 1; - - for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) - num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); - - FILE* f; - char buf[13] = {0}; - char filename[FILE_PATH_SIZE] = {0}, *fptr; + char filename[FILE_PATH_SIZE] = {0}; uint8_t cmdp = 0; char ctmp; uint64_t foundkey = 0; int16_t isOK = 0; - int i, i2, keycnt = 0;; - int current_sector_i, current_key_type_i, default_keys_i, found_keys_i; - uint32_t keyitems = ARRAYLEN(g_mifare_default_keys); + int i, i2, i3; // Loop counter + int current_sector_i = 0, current_key_type_i = 0; bool slow = false; bool nonce_file_read = false; bool nonce_file_write = false; bool createDumpFile = false; bool know_target_key = false; - int tests = 0; + bool legacy_mfchk = false; + bool firstChunk = 0, lastChunk = 0; ctmp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf14_hardautopwn(); - while ((ctmp = param_getchar(Cmd, cmdp))) { switch (tolower(ctmp)) { case 'h': @@ -1623,24 +1614,12 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { case 'd': createDumpFile = true; break; + case 'l': + legacy_mfchk = true; + break; case '*': - // sectors - switch (param_getchar(Cmd, cmdp + 1)) { - case '0': - sectorsCnt = MIFARE_MINI_MAXSECTOR; - break; - case '1': - sectorsCnt = MIFARE_1K_MAXSECTOR; - break; - case '2': - sectorsCnt = MIFARE_2K_MAXSECTOR; - break; - case '4': - sectorsCnt = MIFARE_4K_MAXSECTOR; - break; - default: - sectorsCnt = MIFARE_1K_MAXSECTOR; - } + // Get the number of sectors + sectorsCnt = NumOfSectors(param_getchar(Cmd, cmdp + 1)); cmdp ++; break; case 'k': @@ -1707,31 +1686,22 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { // Print parameters PrintAndLogEx(NORMAL, "Used Parameters:"); - PrintAndLogEx(NORMAL, "[+] Dumping the found keys: %s", createDumpFile ? "True" : "False"); - PrintAndLogEx(NORMAL, "[+] Card sectors: %d", sectorsCnt); - PrintAndLogEx(NORMAL, "[+] Key supplied: %s", know_target_key ? "True" : "False"); - PrintAndLogEx(NORMAL, "[+] Known sector: %d", blockNo); - PrintAndLogEx(NORMAL, "[+] Keytype: %c", keyType ? 'B' : 'A'); - PrintAndLogEx(NORMAL, "[+] Kown key: 0x%02x%02x%02x%02x%02x%02x", key[0], key[1], key[2], key[3], key[4], key[5]); - PrintAndLogEx(NORMAL, "[+] Dictionary: %s", filename); - - e_sector = calloc(sectorsCnt, sizeof(sector_t)); - - if (know_target_key) { - // check if we can authenticate to sector - if (mfCheckKeys(blockNo, keyType, true, 1, key, &key64) != PM3_SUCCESS) { - PrintAndLogEx(WARNING, "Key is wrong. Can't authenticate to sector:%3d key type:%c", blockNo, keyType ? 'B' : 'A'); - free(e_sector); - return 3; - } - } else { + PrintAndLogEx(SUCCESS, "Dumping the found keys: %s", createDumpFile ? "True" : "False"); + PrintAndLogEx(SUCCESS, "Card sectors: %d", sectorsCnt); + PrintAndLogEx(SUCCESS, "Key supplied: %s", know_target_key ? "True" : "False"); + PrintAndLogEx(SUCCESS, "Known sector: %d", blockNo); + PrintAndLogEx(SUCCESS, "Keytype: %c", keyType ? 'B' : 'A'); + PrintAndLogEx(SUCCESS, "Kown key: 0x%02x%02x%02x%02x%02x%02x", key[0], key[1], key[2], key[3], key[4], key[5]); + PrintAndLogEx(SUCCESS, "Dictionary: %s", filename); + PrintAndLogEx(SUCCESS, "Legacy mode (mfchk): %s", legacy_mfchk ? "True" : "False"); + PrintAndLogEx(WARNING, "Starting attack!"); + if (know_target_key == false) PrintAndLogEx(WARNING, "No known key was supplied, if no usable key is found in the dictionary, then this attack will fail!"); - } - - // Clear the datastructures - for (i=0; i<80; i++) { - arr[i] = 0; - } + + // Create the key storage stucture + e_sector = calloc(sectorsCnt, sizeof(sector_t)); + if (e_sector == NULL) return PM3_EMALLOC; + // Clear the key storage datastructure for (i=0; i (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : keycnt; + firstChunk = true; lastChunk = false; + for (uint8_t strategy = 1; strategy < 3; strategy++) { + PrintAndLogEx(SUCCESS, "Running strategy %u", strategy); + // main keychunk loop + for (i = 0; i < keycnt; i += chunksize) { + + if (kbd_enter_pressed()) { + PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); + i = keycnt; strategy = 3; break; // Exit the loop + } + uint32_t size = ((keycnt - i) > chunksize) ? chunksize : keycnt - i; + // last chunk? + if (size == keycnt - i) + lastChunk = true; + int res = mfCheckKeys_fast(sectorsCnt, firstChunk, lastChunk, strategy, size, keyBlock + (i * 6), e_sector, false); + if (firstChunk) + firstChunk = false; + // all keys, aborted + if (res == 0 || res == 2) { + i = keycnt; strategy = 3; break; // Exit the loop + } + } // end chunks of keys + firstChunk = true; + lastChunk = false; + } // end strategy } - // Set the user defined / bruteforced key + // Check if at least one key was recovered + for (i=0; i 0xffffffffffff has been inserted for unknown keys.", fptr); + PrintAndLogEx(SUCCESS, "\nDumping the found keys:"); + createKeyDump(sectorsCnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); } - + // Generate and show statistics t1 = msclock() - t1; - PrintAndLogEx(SUCCESS, "Key statistics: Dictionary: " _GREEN_("%d") ", Reuse: " _YELLOW_("%d") ", Bruteforce: " _MAGENTA_("%d") ", Total: " _YELLOW_("%d"), foundKeysDictionary, foundKeysReuse, foundKeysHardnested, sectorsCnt*2); + PrintAndLogEx(SUCCESS, "Keys statistics (total: %d):" + "\n\t(*) Broken with hardnested attack: " _MAGENTA_("%d") + "\n\t(*) Reused keys: " _YELLOW_("%d") + "\n\t(*) Discovered with the dictionary: " _YELLOW_("%d") + , sectorsCnt*2, foundKeysHardnested, foundKeysReused, foundKeysDictionary); PrintAndLogEx(SUCCESS, "Required time for the hardautopwn attack: " _YELLOW_("%.0f") " seconds\n", (float)t1 / 1000.0); free(e_sector); + free(keyBlock); return 0; } @@ -2007,7 +1936,6 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { char filename[FILE_PATH_SIZE] = {0}; char buf[13]; char *fptr; - uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t *keyBlock, *p; uint8_t sectorsCnt = 1; int i, keycnt = 0; @@ -2218,30 +2146,7 @@ out: if (createDumpFile) { fptr = GenerateFilename("hf-mf-", "-key.bin"); - if (fptr == NULL) - return 1; - - FILE *fkeys = fopen(fptr, "wb"); - if (fkeys == NULL) { - PrintAndLogEx(WARNING, "Could not create file " _YELLOW_("%s"), fptr); - free(keyBlock); - free(e_sector); - return 1; - } - PrintAndLogEx(SUCCESS, "Printing keys to binary file " _YELLOW_("%s")"...", fptr); - - for (i = 0; i < sectorsCnt; i++) { - num_to_bytes(e_sector[i].Key[0], 6, tempkey); - fwrite(tempkey, 1, 6, fkeys); - } - - for (i = 0; i < sectorsCnt; i++) { - num_to_bytes(e_sector[i].Key[1], 6, tempkey); - fwrite(tempkey, 1, 6, fkeys); - } - - fclose(fkeys); - PrintAndLogEx(SUCCESS, "Found keys have been dumped to " _YELLOW_("%s")" --> 0xffffffffffff has been inserted for unknown keys.", fptr); + createKeyDump(sectorsCnt, e_sector, fptr); } } diff --git a/client/fileutils.c b/client/fileutils.c index b89925334..124a51edc 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -293,6 +293,36 @@ out: return retval; } +int createKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char* fptr) { + uint8_t tmpKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + int i; + + if (fptr == NULL) { + return 1; + } + + FILE *fkeys = fopen(fptr, "wb"); + if (fkeys == NULL) { + PrintAndLogEx(WARNING, "Could not create file " _YELLOW_("%s"), fptr); + return 1; + } + PrintAndLogEx(SUCCESS, "Printing keys to binary file " _YELLOW_("%s")"...", fptr); + + for (i = 0; i < sectorsCnt; i++) { + num_to_bytes(e_sector[i].Key[0], 6, tmpKey); + fwrite(tmpKey, 1, 6, fkeys); + } + + for (i = 0; i < sectorsCnt; i++) { + num_to_bytes(e_sector[i].Key[1], 6, tmpKey); + fwrite(tmpKey, 1, 6, fkeys); + } + + fclose(fkeys); + PrintAndLogEx(SUCCESS, "Found keys have been dumped to " _YELLOW_("%s")" --> 0xffffffffffff has been inserted for unknown keys.", fptr); + return 0; +} + int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen) { if (data == NULL) return 1; diff --git a/client/fileutils.h b/client/fileutils.h index 74d54000b..61b7b0468 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -49,6 +49,7 @@ #include "../ui.h" #include "../emv/emvjson.h" #include "mifare/mifare4.h" +#include "mifare/mifarehost.h" #include "cmdhfmfu.h" typedef enum { @@ -103,6 +104,16 @@ int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t */ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen); +/** + * @brief Utility function to save a keydump. + * + * @param sectorsCnt the used sectors + * @param e_sector the keys in question + * @param fptr string pointer to the filename + * @return 0 for ok, 1 for failz + */ +int createKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char* fptr); + /** STUB * @brief Utility function to load data from a binary file. This method takes a preferred name. * E.g. dumpdata-15.bin From c709ee7c1067978d5286861c33108befdffeefae Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 20:55:50 +0200 Subject: [PATCH 085/347] rework PREFIX for future make install --- client/fileutils.c | 8 ++++---- client/scripting.c | 10 +++++----- .../Mac-OS-X-Homebrew-Installation-Instructions.md | 7 +------ include/common.h | 10 +++++++--- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 7500ea8dd..6556a9a1b 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -654,8 +654,8 @@ int searchAndList(const char *pm3dir, const char *ext) { filelist(script_directory_path, ext, false); } { - char script_directory_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(pm3dir) + 1]; - strcpy(script_directory_path, PM3_SYSTEM_DIRECTORY); + char script_directory_path[strlen(PM3_SHARE_PATH) + strlen(pm3dir) + 1]; + strcpy(script_directory_path, PM3_SHARE_PATH); strcat(script_directory_path, pm3dir); filelist(script_directory_path, ext, true); } @@ -711,8 +711,8 @@ char *searchFile(const char *pm3dir, const char *ext, const char *filename) { } // try pm3 dirs in pm3 installation dir (install mode) { - char *path = malloc(strlen(PM3_SYSTEM_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); - strcpy(path, PM3_SYSTEM_DIRECTORY); + char *path = malloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); + strcpy(path, PM3_SHARE_PATH); strcat(path, pm3dir); strcat(path, filename); strcat(path, suffix); diff --git a/client/scripting.c b/client/scripting.c index 596b535fa..664b0080f 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1167,16 +1167,16 @@ int set_pm3_libraries(lua_State *L) { setLuaPath(L, libraries_path); } - if (strlen(PM3_SYSTEM_DIRECTORY) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { + if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { // from the /usr/local/share/proxmark3/luascripts/ directory - char scripts_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, PM3_SYSTEM_DIRECTORY); + char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, PM3_SHARE_PATH); strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the /usr/local/share/proxmark3/lualib/ directory - char libraries_path[strlen(PM3_SYSTEM_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, PM3_SYSTEM_DIRECTORY); + char libraries_path[strlen(PM3_SHARE_PATH) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, PM3_SHARE_PATH); strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 22868121c..fd336104d 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -64,12 +64,7 @@ These instructions will show how to setup the environment on OSX to the point wh 2. Install dependencies: ``` -brew install readline -brew install p7zip -brew install libusb-compat -brew install perl -brew install qt5 -brew install wget +brew install readline p7zip libusb-compat perl qt5 wget brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc ``` diff --git a/include/common.h b/include/common.h index d70bc484f..fc1d688f0 100644 --- a/include/common.h +++ b/include/common.h @@ -16,10 +16,14 @@ #include #include -#ifndef PREFIX -# define PREFIX "/usr/local/" +// brew prefixes are a bit weird so we've to split bin & share to be prepared: +#ifndef PM3_BIN_PATH +# define PM3_BIN_PATH "/usr/local/bin/" #endif -#define PM3_SYSTEM_DIRECTORY PREFIX "share/proxmark3/" +#ifndef PM3_SHARE_PATH +# define PM3_SHARE_PATH "/usr/local/share/proxmark3/" +#endif +// PM3_USER_DIRECTORY will be expanded as if with a "~" upfront, e.g. ~/.proxmark3/ #define PM3_USER_DIRECTORY "/.proxmark3/" #define PACKED __attribute__((packed)) From e0cdb5d7a7308b17aa936db51aaf999e4d7fda77 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 21:07:20 +0200 Subject: [PATCH 086/347] makefile: allow override of install paths --- Makefile.host | 6 ++++++ client/Makefile | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Makefile.host b/Makefile.host index 5bf662d9a..3220f7add 100644 --- a/Makefile.host +++ b/Makefile.host @@ -15,6 +15,12 @@ FALSE = false CFLAGS ?= -Wall -Werror -O3 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES) +ifneq (,$(PM3_BIN_PATH)) + CFLAGS += -DPM3_BIN_PATH=\"$(PM3_BIN_PATH)\" +endif +ifneq (,$(PM3_SHARE_PATH)) + CFLAGS += -DPM3_SHARE_PATH=\"$(PM3_SHARE_PATH)\" +endif platform = $(shell uname) diff --git a/client/Makefile b/client/Makefile index f33c1ae9e..d9e43d445 100644 --- a/client/Makefile +++ b/client/Makefile @@ -66,6 +66,12 @@ INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) CFLAGS ?= -Wall -Werror -g -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT) +ifneq (,$(PM3_BIN_PATH)) + PM3CFLAGS += -DPM3_BIN_PATH=\"$(PM3_BIN_PATH)\" +endif +ifneq (,$(PM3_SHARE_PATH)) + PM3CFLAGS += -DPM3_SHARE_PATH=\"$(PM3_SHARE_PATH)\" +endif ifneq (,$(findstring MINGW,$(platform))) PM3CFLAGS += -mno-ms-bitfields endif From 31e430744bb0948e73596aa5d4c42612857661b0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 21:49:58 +0200 Subject: [PATCH 087/347] searchFile: use filenamemcopy --- client/fileutils.c | 45 ++++++++++++++++++++++----------------------- client/fileutils.h | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 6556a9a1b..426ee3b6e 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -662,64 +662,63 @@ int searchAndList(const char *pm3dir, const char *ext) { return PM3_SUCCESS; } -char *searchFile(const char *pm3dir, const char *ext, const char *filename) { - const char *suffix = ""; - if (!str_endswith(filename, ext)) { - suffix = ext; - } +char *searchFile(const char *pm3dir, const char *suffix, const char *preferredName) { + char *filename = filenamemcopy(preferredName, suffix); + if (filename == NULL) return NULL; // explicit absolute (/) or relative path (./) => try only to match it directly if (((strlen(filename) > 1) && (filename[0] == '/')) || ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) { - char *path = malloc(strlen(filename) + strlen(suffix) + 1); - strcpy(path, filename); - strcat(path, suffix); - if (fileExists(path)) - return path; + if (fileExists(filename)) + return filename; else - free(path); + free(filename); return NULL; } // else // try pm3 dirs in current workdir (dev mode) const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { - char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); + char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1); strcpy(path, exec_path); strcat(path, pm3dir); strcat(path, filename); - strcat(path, suffix); - if (fileExists(path)) + if (fileExists(path)) { + free(filename); return path; - else + } else { free(path); + } } // try pm3 dirs in user .proxmark3 (user mode) char *user_path = getenv("HOME"); if (user_path != NULL) { - char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); + char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1); strcpy(path, user_path); strcat(path, PM3_USER_DIRECTORY); strcat(path, pm3dir); strcat(path, filename); - strcat(path, suffix); - if (fileExists(path)) + if (fileExists(path)) { + free(filename); return path; - else + } else { free(path); + } } // try pm3 dirs in pm3 installation dir (install mode) { - char *path = malloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + strlen(suffix) + 1); + char *path = malloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1); strcpy(path, PM3_SHARE_PATH); strcat(path, pm3dir); strcat(path, filename); - strcat(path, suffix); - if (fileExists(path)) + if (fileExists(path)) { + free(filename); return path; - else + } else { free(path); + } } + free(filename); return NULL; } diff --git a/client/fileutils.h b/client/fileutils.h index 99c3c4d1d..ed36d3771 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -161,6 +161,6 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u int convertOldMfuDump(uint8_t **dump, size_t *dumplen); int searchAndList(const char *pm3dir, const char *ext); -char *searchFile(const char *pm3dir, const char *ext, const char *filename); +char *searchFile(const char *pm3dir, const char *suffix, const char *preferredName); #endif // FILEUTILS_H From 34a0fdb9d69fe67e14afcabfb83f6e5642f94752 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 22:07:45 +0200 Subject: [PATCH 088/347] reorganize lua script dir defs --- client/cmdscript.c | 4 ++-- client/scripting.c | 26 +++++++++++++------------- client/scripting.h | 2 -- include/common.h | 4 ++++ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 8a748b8ab..889259922 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -33,7 +33,7 @@ static int CmdHelp(const char *Cmd); */ static int CmdScriptList(const char *Cmd) { (void)Cmd; // Cmd is not used so far - return searchAndList(LUA_SCRIPTS_DIRECTORY, ".lua"); + return searchAndList(LUA_SCRIPTS_SUBDIR, ".lua"); } /** @@ -66,7 +66,7 @@ static int CmdScriptRun(const char *Cmd) { int arg_len = 0; sscanf(Cmd, "%127s%n %255[^\n\r]%n", script_name, &name_len, arguments, &arg_len); - char *script_path = searchFile(LUA_SCRIPTS_DIRECTORY, ".lua", script_name); + char *script_path = searchFile(LUA_SCRIPTS_SUBDIR, ".lua", script_name); if (script_path == NULL) { PrintAndLogEx(FAILED, "Error - can't find script %s", script_name); return PM3_EFILE; diff --git a/client/scripting.c b/client/scripting.c index 664b0080f..dc3051207 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1136,48 +1136,48 @@ int set_pm3_libraries(lua_State *L) { const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { // from the ./luascripts/ directory - char scripts_path[strlen(exec_path) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(exec_path) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, exec_path); - strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ./lualib/ directory - char libraries_path[strlen(exec_path) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(exec_path) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, exec_path); - strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } char *user_path = getenv("HOME"); if (user_path != NULL) { // from the ~/.proxmark3/luascripts/ directory - char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, user_path); strcat(scripts_path, PM3_USER_DIRECTORY); - strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the ~/.proxmark3/lualib/ directory - char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, user_path); strcat(libraries_path, PM3_USER_DIRECTORY); - strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_DIRECTORY) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { + if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_SUBDIR) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { // from the /usr/local/share/proxmark3/luascripts/ directory - char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, PM3_SHARE_PATH); - strcat(scripts_path, LUA_SCRIPTS_DIRECTORY); + strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); // from the /usr/local/share/proxmark3/lualib/ directory - char libraries_path[strlen(PM3_SHARE_PATH) + strlen(LUA_LIBRARIES_DIRECTORY) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + char libraries_path[strlen(PM3_SHARE_PATH) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, PM3_SHARE_PATH); - strcat(libraries_path, LUA_LIBRARIES_DIRECTORY); + strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } diff --git a/client/scripting.h b/client/scripting.h index 1a7b5a7e3..b23ce3a9a 100644 --- a/client/scripting.h +++ b/client/scripting.h @@ -14,8 +14,6 @@ //#include //#include -#define LUA_LIBRARIES_DIRECTORY "lualibs/" -#define LUA_SCRIPTS_DIRECTORY "luascripts/" #define LUA_LIBRARIES_WILDCARD "?.lua" /** diff --git a/include/common.h b/include/common.h index fc1d688f0..580170b31 100644 --- a/include/common.h +++ b/include/common.h @@ -26,6 +26,10 @@ // PM3_USER_DIRECTORY will be expanded as if with a "~" upfront, e.g. ~/.proxmark3/ #define PM3_USER_DIRECTORY "/.proxmark3/" +// PM3 subdirectories: +#define LUA_LIBRARIES_SUBDIR "lualibs/" +#define LUA_SCRIPTS_SUBDIR "luascripts/" + #define PACKED __attribute__((packed)) // debug From 8c26e07ceb7cd15a605cc46d825609edb0c16ab9 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 22:08:36 +0200 Subject: [PATCH 089/347] use searchFile to find dictionaries --- client/fileutils.c | 2 +- include/common.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/fileutils.c b/client/fileutils.c index 426ee3b6e..8e9ceb228 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -523,7 +523,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u if (data == NULL) return 1; - char *fileName = filenamemcopy(preferredName, ".dic"); + char *fileName = searchFile(DICTIONARIES_SUBDIR, ".dic", preferredName); if (fileName == NULL) return 1; // t5577 == 4bytes diff --git a/include/common.h b/include/common.h index 580170b31..a2850ef32 100644 --- a/include/common.h +++ b/include/common.h @@ -27,6 +27,7 @@ #define PM3_USER_DIRECTORY "/.proxmark3/" // PM3 subdirectories: +#define DICTIONARIES_SUBDIR "dictionaries/" #define LUA_LIBRARIES_SUBDIR "lualibs/" #define LUA_SCRIPTS_SUBDIR "luascripts/" From 4b95be1b3925825e573cd302a1391df4431aae7f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 22:09:54 +0200 Subject: [PATCH 090/347] searchFile: search also implicit relative path --- client/fileutils.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/fileutils.c b/client/fileutils.c index 8e9ceb228..86835babd 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -677,6 +677,12 @@ char *searchFile(const char *pm3dir, const char *suffix, const char *preferredNa return NULL; } // else + + // try implicit relative path + { + if (fileExists(filename)) + return filename; + } // try pm3 dirs in current workdir (dev mode) const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { From b09849c91b85df25b46c6ed64a879e662542a56b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 23:07:05 +0200 Subject: [PATCH 091/347] pull filenamemcopy out of searchFile --- client/cmdscript.c | 11 ++++++++--- client/fileutils.c | 43 +++++++++++++++++++++++++++---------------- client/fileutils.h | 3 ++- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 889259922..37778d52e 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -59,18 +59,23 @@ static int CmdScriptRun(const char *Cmd) { //Add the 'bit' library set_bit_library(lua_state); - char script_name[128] = {0}; + char preferredName[128] = {0}; char arguments[256] = {0}; int name_len = 0; int arg_len = 0; - sscanf(Cmd, "%127s%n %255[^\n\r]%n", script_name, &name_len, arguments, &arg_len); + sscanf(Cmd, "%127s%n %255[^\n\r]%n", preferredName, &name_len, arguments, &arg_len); + + char *script_name = filenamemcopy(preferredName, ".lua"); + if (script_name == NULL) return PM3_EMALLOC; + char *script_path = searchFile(LUA_SCRIPTS_SUBDIR, script_name); - char *script_path = searchFile(LUA_SCRIPTS_SUBDIR, ".lua", script_name); if (script_path == NULL) { PrintAndLogEx(FAILED, "Error - can't find script %s", script_name); + free(script_name); return PM3_EFILE; } + free(script_name); int error; PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); error = luaL_loadfile(lua_state, script_path); diff --git a/client/fileutils.c b/client/fileutils.c index 86835babd..52fd1539f 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -69,7 +69,7 @@ int fileExists(const char *filename) { return result == 0; } -static char *filenamemcopy(const char *preferredName, const char *suffix) { +char *filenamemcopy(const char *preferredName, const char *suffix) { if (preferredName == NULL) return NULL; if (suffix == NULL) return NULL; char *fileName = (char *) calloc(strlen(preferredName) + strlen(suffix) + 1, sizeof(uint8_t)); @@ -521,11 +521,16 @@ out: int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt) { - - if (data == NULL) return 1; - char *fileName = searchFile(DICTIONARIES_SUBDIR, ".dic", preferredName); - if (fileName == NULL) return 1; - + if (data == NULL) return PM3_ESOFT; + char *fileName = filenamemcopy(preferredName, ".dic"); + if (fileName == NULL) return PM3_EMALLOC; + char *path = searchFile(DICTIONARIES_SUBDIR, fileName); + if (path == NULL) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + free(fileName); + return PM3_EFILE; + } + free(fileName); // t5577 == 4bytes // mifare == 6 bytes // iclass == 8 bytes @@ -542,9 +547,9 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u size_t counter = 0; int retval = PM3_SUCCESS; - FILE *f = fopen(fileName, "r"); + FILE *f = fopen(path, "r"); if (!f) { - PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path); retval = PM3_EFILE; goto out; } @@ -576,12 +581,12 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u counter += (keylen >> 1); } fclose(f); - PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, fileName); + PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, path); if (datalen) *datalen = counter; out: - free(fileName); + free(path); return retval; } @@ -662,19 +667,18 @@ int searchAndList(const char *pm3dir, const char *ext) { return PM3_SUCCESS; } -char *searchFile(const char *pm3dir, const char *suffix, const char *preferredName) { - char *filename = filenamemcopy(preferredName, suffix); - if (filename == NULL) return NULL; - +char *searchFile(const char *pm3dir, const char *searchname) { // explicit absolute (/) or relative path (./) => try only to match it directly + char *filename = malloc(strlen(searchname) + 1); + if (filename == NULL) return NULL; + strcpy(filename, searchname); if (((strlen(filename) > 1) && (filename[0] == '/')) || ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) { if (fileExists(filename)) return filename; else - free(filename); - return NULL; + goto out; } // else @@ -687,6 +691,8 @@ char *searchFile(const char *pm3dir, const char *suffix, const char *preferredNa const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1); + if (path == NULL) + goto out; strcpy(path, exec_path); strcat(path, pm3dir); strcat(path, filename); @@ -701,6 +707,8 @@ char *searchFile(const char *pm3dir, const char *suffix, const char *preferredNa char *user_path = getenv("HOME"); if (user_path != NULL) { char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1); + if (path == NULL) + goto out; strcpy(path, user_path); strcat(path, PM3_USER_DIRECTORY); strcat(path, pm3dir); @@ -715,6 +723,8 @@ char *searchFile(const char *pm3dir, const char *suffix, const char *preferredNa // try pm3 dirs in pm3 installation dir (install mode) { char *path = malloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1); + if (path == NULL) + goto out; strcpy(path, PM3_SHARE_PATH); strcat(path, pm3dir); strcat(path, filename); @@ -725,6 +735,7 @@ char *searchFile(const char *pm3dir, const char *suffix, const char *preferredNa free(path); } } +out: free(filename); return NULL; } diff --git a/client/fileutils.h b/client/fileutils.h index ed36d3771..bb229efb5 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -160,7 +160,8 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u */ int convertOldMfuDump(uint8_t **dump, size_t *dumplen); +char *filenamemcopy(const char *preferredName, const char *suffix); int searchAndList(const char *pm3dir, const char *ext); -char *searchFile(const char *pm3dir, const char *suffix, const char *preferredName); +char *searchFile(const char *pm3dir, const char *searchname); #endif // FILEUTILS_H From 9d05628c3cb87a06cc0458909c4d3a7eb3f22745 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 23 Aug 2019 23:21:20 +0200 Subject: [PATCH 092/347] mem load: update examples --- client/cmdflashmem.c | 6 +++--- doc/cheatsheet.md | 6 +++--- doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 905e6c6c8..7f1fa103e 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -59,9 +59,9 @@ static int usage_flashmem_load(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " mem load f myfile"); // upload file myfile at default offset 0 PrintAndLogEx(NORMAL, " mem load f myfile o 1024"); // upload file myfile at offset 1024 - PrintAndLogEx(NORMAL, " mem load f dictionaries/mfc_default_keys m"); - PrintAndLogEx(NORMAL, " mem load f dictionaries/t55xx_default_pwds t"); - PrintAndLogEx(NORMAL, " mem load f dictionaries/iclass_default_keys i"); + PrintAndLogEx(NORMAL, " mem load f mfc_default_keys m"); + PrintAndLogEx(NORMAL, " mem load f t55xx_default_pwds t"); + PrintAndLogEx(NORMAL, " mem load f iclass_default_keys i"); return PM3_SUCCESS; } static int usage_flashmem_dump(void) { diff --git a/doc/cheatsheet.md b/doc/cheatsheet.md index 75c554e94..02628a9bc 100644 --- a/doc/cheatsheet.md +++ b/doc/cheatsheet.md @@ -512,9 +512,9 @@ m : upload 6 bytes keys (mifare key dictionary) i : upload 8 bytes keys (iClass key dictionary) t : upload 4 bytes keys (pwd dictionary) -pm3 --> mem load f dictionaries/mfc_default_keys m -pm3 --> mem load f dictionaries/t55xx_default_pwds t -pm3 --> mem load f dictionaries/iclass_default_keys i +pm3 --> mem load f mfc_default_keys m +pm3 --> mem load f t55xx_default_pwds t +pm3 --> mem load f iclass_default_keys i ``` ## Sim Module diff --git a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md index 84f64821c..8b5244cf6 100644 --- a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md +++ b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md @@ -1,9 +1,9 @@ ### First things on your RDV40 You will need to run these commands to make sure your rdv4 is prepared ``` -pm3 --> mem load f dictionaries/mfc_default_keys m -pm3 --> mem load f dictionaries/t55xx_default_pwds t -pm3 --> mem load f dictionaries/iclass_default_keys i +pm3 --> mem load f mfc_default_keys m +pm3 --> mem load f t55xx_default_pwds t +pm3 --> mem load f iclass_default_keys i pm3 --> lf t55xx deviceconfig a 29 b 17 c 15 d 47 e 15 p pm3 --> lf t55xx deviceconfig r 1 a 31 b 20 c 18 d 50 e 15 p pm3 --> lf t55xx deviceconfig r 2 a 31 b 20 c 18 d 40 e 15 p From c6145a81c2f628c88e26a5637e91b83e76aac5b9 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 24 Aug 2019 05:08:03 +0200 Subject: [PATCH 093/347] chg: iclass commands --- client/cmdhficlass.c | 179 ++++++++++++++++++++++++++----------------- 1 file changed, 108 insertions(+), 71 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 4b815355b..51bc323fc 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -60,14 +60,14 @@ static int usage_hf_iclass_sim(void) { PrintAndLogEx(NORMAL, " hf iclass eload 'tagdump.bin'"); PrintAndLogEx(NORMAL, " hf iclass sim 3"); PrintAndLogEx(NORMAL, " hf iclass sim 4"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_eload(void) { PrintAndLogEx(NORMAL, "Loads iclass tag-dump into emulator memory on device"); PrintAndLogEx(NORMAL, "Usage: hf iclass eload f "); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass eload f iclass_tagdump-aa162d30f8ff12f1.bin"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_decrypt(void) { PrintAndLogEx(NORMAL, "This is simple implementation, it tries to decrypt every block after block 6."); @@ -80,7 +80,7 @@ static int usage_hf_iclass_decrypt(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "S hf iclass decrypt f tagdump_12312342343.bin"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_encrypt(void) { PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside"); @@ -91,7 +91,7 @@ static int usage_hf_iclass_encrypt(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass encrypt 0102030405060708"); PrintAndLogEx(NORMAL, ""); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_dump(void) { PrintAndLogEx(NORMAL, "Usage: hf iclass dump f k c [e|r|v]\n"); @@ -107,23 +107,23 @@ static int usage_hf_iclass_dump(void) { PrintAndLogEx(NORMAL, " hf iclass dump k 001122334455667B"); PrintAndLogEx(NORMAL, " hf iclass dump k AAAAAAAAAAAAAAAA c 001122334455667B"); PrintAndLogEx(NORMAL, " hf iclass dump k AAAAAAAAAAAAAAAA e"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_clone(void) { PrintAndLogEx(NORMAL, "Usage: hf iclass clone f b l k c e|r"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " f : specify a filename to clone from"); - PrintAndLogEx(NORMAL, " b : The first block to clone as 2 hex symbols"); - PrintAndLogEx(NORMAL, " l : Set the Data to write as 16 hex symbols"); - PrintAndLogEx(NORMAL, " k : Access Key as 16 hex symbols or 1 hex to select key from memory"); - PrintAndLogEx(NORMAL, " c : If 'c' is specified, the key set is assumed to be the credit key\n"); - PrintAndLogEx(NORMAL, " e : If 'e' is specified, elite computations applied to key"); - PrintAndLogEx(NORMAL, " r : If 'r' is specified, no computations applied to key"); + PrintAndLogEx(NORMAL, " f : specify a filename to clone from"); + PrintAndLogEx(NORMAL, " b : The first block to clone as 2 hex symbols"); + PrintAndLogEx(NORMAL, " l : Set the Data to write as 16 hex symbols"); + PrintAndLogEx(NORMAL, " k : Access Key as 16 hex symbols or 1 hex to select key from memory"); + PrintAndLogEx(NORMAL, " c : If 'c' is specified, the key set is assumed to be the credit key\n"); + PrintAndLogEx(NORMAL, " e : If 'e' is specified, elite computations applied to key"); + PrintAndLogEx(NORMAL, " r : If 'r' is specified, no computations applied to key"); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass clone f iclass_tagdump-121345.bin b 06 l 1A k 1122334455667788 e"); PrintAndLogEx(NORMAL, " hf iclass clone f iclass_tagdump-121345.bin b 05 l 19 k 0"); PrintAndLogEx(NORMAL, " hf iclass clone f iclass_tagdump-121345.bin b 06 l 19 k 0 e"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_writeblock(void) { PrintAndLogEx(NORMAL, "Usage: hf iclass writeblk b d k [c|e|r|v]\n"); @@ -138,7 +138,7 @@ static int usage_hf_iclass_writeblock(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass writeblk b 0A d AAAAAAAAAAAAAAAA k 001122334455667B"); PrintAndLogEx(NORMAL, " hf iclass writeblk b 1B d AAAAAAAAAAAAAAAA k 001122334455667B c"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_readblock(void) { PrintAndLogEx(NORMAL, "Usage: hf iclass readblk b k [c|e|r|v]\n"); @@ -153,11 +153,11 @@ static int usage_hf_iclass_readblock(void) { PrintAndLogEx(NORMAL, " hf iclass readblk b 06 k 0011223344556677"); PrintAndLogEx(NORMAL, " hf iclass readblk b 1B k 0011223344556677 c"); PrintAndLogEx(NORMAL, " hf iclass readblk b 0A k 0"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_readtagfile() { PrintAndLogEx(NORMAL, "Usage: hf iclass readtagfile [startblock] [endblock]"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_calc_newkey(void) { PrintAndLogEx(NORMAL, "Calculate new key for updating\n"); @@ -173,24 +173,24 @@ static int usage_hf_iclass_calc_newkey(void) { PrintAndLogEx(NORMAL, " std key to e key read csn : hf iclass calcnewkey o 1122334455667788 n 2233445566778899 e"); PrintAndLogEx(NORMAL, " std to std read csn : hf iclass calcnewkey o 1122334455667788 n 2233445566778899"); PrintAndLogEx(NORMAL, "\nNOTE: * = required\n"); - return 0; + return PM3_SUCCESS;; } static int usage_hf_iclass_managekeys(void) { PrintAndLogEx(NORMAL, "HELP : Manage iClass Keys in client memory:\n"); PrintAndLogEx(NORMAL, "Usage: hf iclass managekeys n [keynbr] k [key] f [filename] s l p\n"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " n : specify the keyNbr to set in memory"); - PrintAndLogEx(NORMAL, " k : set a key in memory"); - PrintAndLogEx(NORMAL, " f : specify a filename to use with load or save operations"); - PrintAndLogEx(NORMAL, " s : save keys in memory to file specified by filename"); - PrintAndLogEx(NORMAL, " l : load keys to memory from file specified by filename"); - PrintAndLogEx(NORMAL, " p : print keys loaded into memory\n"); + PrintAndLogEx(NORMAL, " n : specify the keyNbr to set in memory"); + PrintAndLogEx(NORMAL, " k : set a key in memory"); + PrintAndLogEx(NORMAL, " f : specify a filename to use with load or save operations"); + PrintAndLogEx(NORMAL, " s : save keys in memory to file specified by filename"); + PrintAndLogEx(NORMAL, " l : load keys to memory from file specified by filename"); + PrintAndLogEx(NORMAL, " p : print keys loaded into memory\n"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " set key : hf iclass managekeys n 0 k 1122334455667788"); - PrintAndLogEx(NORMAL, " save key file: hf iclass managekeys f mykeys.bin s"); - PrintAndLogEx(NORMAL, " load key file: hf iclass managekeys f mykeys.bin l"); - PrintAndLogEx(NORMAL, " print keys : hf iclass managekeys p\n"); - return 0; + PrintAndLogEx(NORMAL, " set key : hf iclass managekeys n 0 k 1122334455667788"); + PrintAndLogEx(NORMAL, " save key file : hf iclass managekeys f mykeys.bin s"); + PrintAndLogEx(NORMAL, " load key file : hf iclass managekeys f mykeys.bin l"); + PrintAndLogEx(NORMAL, " print keys : hf iclass managekeys p\n"); + return PM3_SUCCESS; } static int usage_hf_iclass_reader(void) { PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until Enter or the pm3 button is pressed\n"); @@ -200,7 +200,7 @@ static int usage_hf_iclass_reader(void) { PrintAndLogEx(NORMAL, " 1 read only 1 tag"); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass reader 1"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_replay(void) { PrintAndLogEx(NORMAL, "Replay a collected mac message"); @@ -210,29 +210,29 @@ static int usage_hf_iclass_replay(void) { PrintAndLogEx(NORMAL, " Mac bytes to replay (8 hexsymbols)"); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass replay 00112233"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_sniff(void) { PrintAndLogEx(NORMAL, "Sniff the communication between reader and tag"); PrintAndLogEx(NORMAL, "Usage: hf iclass sniff [h]"); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass sniff"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_loclass(void) { PrintAndLogEx(NORMAL, "Usage: hf iclass loclass [options]"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, "h Show this help"); - PrintAndLogEx(NORMAL, "t Perform self-test"); - PrintAndLogEx(NORMAL, "f Bruteforce iclass dumpfile"); - PrintAndLogEx(NORMAL, " An iclass dumpfile is assumed to consist of an arbitrary number of"); - PrintAndLogEx(NORMAL, " malicious CSNs, and their protocol responses"); - PrintAndLogEx(NORMAL, " The binary format of the file is expected to be as follows: "); - PrintAndLogEx(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); - PrintAndLogEx(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); - PrintAndLogEx(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); - PrintAndLogEx(NORMAL, " ... totalling N*24 bytes"); - return 0; + PrintAndLogEx(NORMAL, " h Show this help"); + PrintAndLogEx(NORMAL, " t Perform self-test"); + PrintAndLogEx(NORMAL, " f Bruteforce iclass dumpfile"); + PrintAndLogEx(NORMAL, " An iclass dumpfile is assumed to consist of an arbitrary number of"); + PrintAndLogEx(NORMAL, " malicious CSNs, and their protocol responses"); + PrintAndLogEx(NORMAL, " The binary format of the file is expected to be as follows: "); + PrintAndLogEx(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); + PrintAndLogEx(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); + PrintAndLogEx(NORMAL, " <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>"); + PrintAndLogEx(NORMAL, " ... totalling N*24 bytes"); + return PM3_SUCCESS; } static int usage_hf_iclass_chk(void) { PrintAndLogEx(NORMAL, "Checkkeys loads a dictionary text file with 8byte hex keys to test authenticating against a iClass tag"); @@ -246,7 +246,7 @@ static int usage_hf_iclass_chk(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic"); PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic e"); - return 0; + return PM3_SUCCESS;; } static int usage_hf_iclass_lookup(void) { PrintAndLogEx(NORMAL, "Lookup keys takes some sniffed trace data and tries to verify what key was used against a dictionary file"); @@ -262,7 +262,7 @@ static int usage_hf_iclass_lookup(void) { PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic"); PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic e"); - return 0; + return PM3_SUCCESS; } static int usage_hf_iclass_permutekey(void) { PrintAndLogEx(NORMAL, "Permute function from 'heart of darkness' paper."); @@ -276,7 +276,7 @@ static int usage_hf_iclass_permutekey(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf iclass permute r 0123456789abcdef"); - return 0; + return PM3_SUCCESS; } /* @@ -860,6 +860,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { } saveFile(outfilename, ".bin", decrypted, fsize); + saveFileEML(outfilename, decrypted, fsize, 8); printIclassDumpContents(decrypted, 1, (fsize / 8), fsize); free(decrypted); return PM3_SUCCESS; @@ -1511,6 +1512,7 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, } //data read is stored in: resp.data.asBytes[0-15] PrintAndLogEx(NORMAL, "block %02X: %s\n", blockno, sprint_hex(resp.data.asBytes, 8)); + // should decrypt it if file is accessable. return 1; } @@ -1583,6 +1585,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { if (!auth) PrintAndLogEx(FAILED, "warning: no authentication used with read, only a few specific blocks can be read accurately without authentication."); + return ReadBlock(KEY, blockno, keyType, elite, rawkey, verbose, auth); } @@ -1856,7 +1859,7 @@ static int loadKeys(char *filename) { memcpy(iClass_Key_Table[i], dump + (i * 8), 8); free(dump); - PrintAndLogEx(SUCCESS, "%u keys loaded", i); + PrintAndLogEx(SUCCESS, "Loaded " _GREEN_("%2d") "keys from %s", i, filename); return PM3_SUCCESS; } @@ -1879,8 +1882,12 @@ static int saveKeys(char *filename) { static int printKeys(void) { PrintAndLogEx(NORMAL, ""); - for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) - PrintAndLogEx(NORMAL, "%u: %s", i, sprint_hex(iClass_Key_Table[i], 8)); + for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) { + if ( memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) + PrintAndLogEx(NORMAL, "%u: %s", i, sprint_hex(iClass_Key_Table[i], 8)); + else + PrintAndLogEx(NORMAL, "%u: "_YELLOW_("%s"), i, sprint_hex(iClass_Key_Table[i], 8)); + } PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -1963,14 +1970,13 @@ static int CmdHFiClassManageKeys(const char *Cmd) { switch (operation) { case 3: memcpy(iClass_Key_Table[keyNbr], KEY, 8); - return 1; + return PM3_SUCCESS; case 4: return printKeys(); case 5: return loadKeys(filename); case 6: return saveKeys(filename); - break; } return PM3_SUCCESS; } @@ -2010,7 +2016,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { case 'f': fileNameLen = param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)); if (fileNameLen < 1) { - PrintAndLogEx(WARNING, "no filename found after f"); + PrintAndLogEx(WARNING, _RED_("no filename found after f")); errors = true; } cmdp += 2; @@ -2048,29 +2054,29 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { if (!got_csn) { PrintAndLogEx(WARNING, "can't select card, aborting..."); - return 1; + return PM3_ESOFT; } // load keys into keyblock int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); if (res > 0) { free(keyBlock); - return 1; + return PM3_EFILE; } pre = calloc(keycnt, sizeof(iclass_premac_t)); if (!pre) { free(keyBlock); - return 1; + return PM3_EMALLOC; } PrintAndLogEx(SUCCESS, "Generating diversified keys, MAC"); if (use_elite) - PrintAndLogEx(SUCCESS, "Using elite algo"); + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("elite algo")); if (use_raw) - PrintAndLogEx(SUCCESS, "Using raw mode"); + PrintAndLogEx(SUCCESS, "Using " _YELLOW_(" raw mode")); - PrintAndLogEx(SUCCESS, "Searching for %s key", (use_credit_key) ? "CREDIT" : "DEBIT"); + PrintAndLogEx(SUCCESS, "Searching for " _YELLOW_("%s") "key", (use_credit_key) ? "CREDIT" : "DEBIT"); PrintAndLogEx(SUCCESS, "Tag info"); PrintAndLogEx(SUCCESS, "CSN | %s", sprint_hex(CSN, sizeof(CSN))); PrintAndLogEx(SUCCESS, "CCNR | %s", sprint_hex(CCNR, sizeof(CCNR))); @@ -2078,7 +2084,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { if (res > 0) { free(keyBlock); free(pre); - return 1; + return PM3_ESOFT; } //PrintPreCalcMac(keyBlock, keycnt, pre); @@ -2090,8 +2096,11 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { // fast push mode conn.block_after_ACK = true; + // keep track of position of found key + uint8_t found_offset = 0; + uint32_t key_offset = 0; // main keychunk loop - for (uint32_t i = 0; i < keycnt; i += chunksize) { + for (uint32_t key_offset = 0; key_offset < keycnt; key_offset += chunksize) { uint64_t t2 = msclock(); uint8_t timeout = 0; @@ -2101,10 +2110,10 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { goto out; } - uint32_t keys = ((keycnt - i) > chunksize) ? chunksize : keycnt - i; + uint32_t keys = ((keycnt - key_offset) > chunksize) ? chunksize : keycnt - key_offset; // last chunk? - if (keys == keycnt - i) { + if (keys == keycnt - key_offset) { lastChunk = true; // Disable fast mode on last command conn.block_after_ACK = false; @@ -2116,7 +2125,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { flags |= (use_credit_key << 16); clearCommandBuffer(); - SendCommandOLD(CMD_HF_ICLASS_CHKKEYS, flags, keys, 0, pre + i, 4 * keys); + SendCommandOLD(CMD_HF_ICLASS_CHKKEYS, flags, keys, 0, pre + key_offset, 4 * keys); PacketResponseNG resp; while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { @@ -2129,7 +2138,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { } } - uint8_t found = resp.oldarg[1] & 0xFF; + found_offset = resp.oldarg[1] & 0xFF; uint8_t isOK = resp.oldarg[0] & 0xFF; t2 = msclock() - t2; @@ -2138,18 +2147,18 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { found_debit = true; PrintAndLogEx(NORMAL, "\n[-] Chunk [%d/%d]: %.1fs [%s] found key %s (index %u)" - , i + , key_offset , keycnt , (float)(t2 / 1000.0) , (use_credit_key) ? "credit" : "debit" - , sprint_hex(keyBlock + (i + found) * 8, 8) - , found + , sprint_hex(keyBlock + (key_offset + found_offset) * 8, 8) + , found_offset ); break; } case 0: { PrintAndLogEx(NORMAL, "\n[-] Chunk [%d/%d] : %.1fs [%s]" - , i + , key_offset , keycnt , (float)(t2 / 1000.0) , (use_credit_key) ? "credit" : "debit" @@ -2174,8 +2183,22 @@ out: t1 = msclock() - t1; PrintAndLogEx(SUCCESS, "\nTime in iclass checkkeys: %.0f seconds\n", (float)t1 / 1000.0); - DropField(); + + // add to managekeys + if ( found_debit ) { + for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) { + // simple check for preexistences + if ( memcmp(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8) == 0 ) break; + + if ( memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) { + memcpy(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8); + PrintAndLogEx(SUCCESS, "Added found key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")" to view", i); + break; + } + } + } + free(pre); free(keyBlock); return PM3_SUCCESS; @@ -2322,11 +2345,25 @@ static int CmdHFiClassLookUp(const char *Cmd) { // binsearch item = (iclass_prekey_t *) bsearch(&lookup, prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32); - if (item != NULL) - PrintAndLogEx(SUCCESS, "\n[debit] found key %s", sprint_hex(item->key, 8)); t1 = msclock() - t1; PrintAndLogEx(NORMAL, "\nTime in iclass : %.0f seconds\n", (float)t1 / 1000.0); + + // foudn + if (item != NULL) { + PrintAndLogEx(SUCCESS, "\n[debit] found key %s", sprint_hex(item->key, 8)); + for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) { + // simple check for preexistences + if ( memcmp(item->key, iClass_Key_Table[i], 8) == 0 ) break; + + if ( memcmp(iClass_Key_Table[i] , "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) { + memcpy(iClass_Key_Table[i], item->key, 8); + PrintAndLogEx(SUCCESS, "Added found key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")"to view", i); + break; + } + } + } + free(prekey); free(keyBlock); PrintAndLogEx(NORMAL, ""); @@ -2379,7 +2416,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { memset(buf, 0, sizeof(buf)); } fclose(f); - PrintAndLogEx(SUCCESS, "Loaded " _GREEN_("%2d") " keys from %s", *keycnt, filename); + PrintAndLogEx(SUCCESS, "Loaded " _GREEN_("%2d") "keys from %s", *keycnt, filename); return PM3_SUCCESS; } From 7ab7d68a26d3b31d72b33a04e58793f27f2ac94d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 24 Aug 2019 07:15:21 +0200 Subject: [PATCH 094/347] calloc in fileutils --- client/fileutils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 52fd1539f..31e48601d 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -669,7 +669,7 @@ int searchAndList(const char *pm3dir, const char *ext) { char *searchFile(const char *pm3dir, const char *searchname) { // explicit absolute (/) or relative path (./) => try only to match it directly - char *filename = malloc(strlen(searchname) + 1); + char *filename = calloc(strlen(searchname) + 1, sizeof(char)); if (filename == NULL) return NULL; strcpy(filename, searchname); if (((strlen(filename) > 1) && (filename[0] == '/')) || @@ -690,7 +690,7 @@ char *searchFile(const char *pm3dir, const char *searchname) { // try pm3 dirs in current workdir (dev mode) const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { - char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1); + char *path = calloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; strcpy(path, exec_path); @@ -706,7 +706,7 @@ char *searchFile(const char *pm3dir, const char *searchname) { // try pm3 dirs in user .proxmark3 (user mode) char *user_path = getenv("HOME"); if (user_path != NULL) { - char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1); + char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; strcpy(path, user_path); @@ -722,7 +722,7 @@ char *searchFile(const char *pm3dir, const char *searchname) { } // try pm3 dirs in pm3 installation dir (install mode) { - char *path = malloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1); + char *path = calloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; strcpy(path, PM3_SHARE_PATH); From ec174a72328efa7beeef03a85543fdff7cdacc26 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 24 Aug 2019 07:51:24 +0200 Subject: [PATCH 095/347] better searchFile api --- client/cmdscript.c | 13 ++++------- client/fileutils.c | 58 ++++++++++++++++++++++++++++++---------------- client/fileutils.h | 3 +-- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 37778d52e..318cc1dd4 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -66,16 +66,11 @@ static int CmdScriptRun(const char *Cmd) { int arg_len = 0; sscanf(Cmd, "%127s%n %255[^\n\r]%n", preferredName, &name_len, arguments, &arg_len); - char *script_name = filenamemcopy(preferredName, ".lua"); - if (script_name == NULL) return PM3_EMALLOC; - char *script_path = searchFile(LUA_SCRIPTS_SUBDIR, script_name); + char *script_path; + int res = searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua"); + if (res != PM3_SUCCESS) + return res; - if (script_path == NULL) { - PrintAndLogEx(FAILED, "Error - can't find script %s", script_name); - free(script_name); - return PM3_EFILE; - } - free(script_name); int error; PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); error = luaL_loadfile(lua_state, script_path); diff --git a/client/fileutils.c b/client/fileutils.c index 31e48601d..622bb88de 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -69,7 +69,7 @@ int fileExists(const char *filename) { return result == 0; } -char *filenamemcopy(const char *preferredName, const char *suffix) { +static char *filenamemcopy(const char *preferredName, const char *suffix) { if (preferredName == NULL) return NULL; if (suffix == NULL) return NULL; char *fileName = (char *) calloc(strlen(preferredName) + strlen(suffix) + 1, sizeof(uint8_t)); @@ -522,15 +522,10 @@ out: int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt) { if (data == NULL) return PM3_ESOFT; - char *fileName = filenamemcopy(preferredName, ".dic"); - if (fileName == NULL) return PM3_EMALLOC; - char *path = searchFile(DICTIONARIES_SUBDIR, fileName); - if (path == NULL) { - PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", fileName); - free(fileName); + char *path; + if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic") != PM3_SUCCESS) return PM3_EFILE; - } - free(fileName); + // t5577 == 4bytes // mifare == 6 bytes // iclass == 8 bytes @@ -667,25 +662,31 @@ int searchAndList(const char *pm3dir, const char *ext) { return PM3_SUCCESS; } -char *searchFile(const char *pm3dir, const char *searchname) { +static int searchFinalFile(char **foundpath, const char *pm3dir, const char *searchname) { + if ((foundpath == NULL)||(pm3dir == NULL)||(searchname == NULL)) return PM3_ESOFT; // explicit absolute (/) or relative path (./) => try only to match it directly char *filename = calloc(strlen(searchname) + 1, sizeof(char)); - if (filename == NULL) return NULL; + if (filename == NULL) return PM3_EMALLOC; strcpy(filename, searchname); if (((strlen(filename) > 1) && (filename[0] == '/')) || ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) { - if (fileExists(filename)) - return filename; - else + if (fileExists(filename)) { + *foundpath = filename; + return PM3_SUCCESS; + } + else { goto out; + } } // else // try implicit relative path { - if (fileExists(filename)) - return filename; + if (fileExists(filename)) { + *foundpath = filename; + return PM3_SUCCESS; + } } // try pm3 dirs in current workdir (dev mode) const char *exec_path = get_my_executable_directory(); @@ -698,7 +699,8 @@ char *searchFile(const char *pm3dir, const char *searchname) { strcat(path, filename); if (fileExists(path)) { free(filename); - return path; + *foundpath = path; + return PM3_SUCCESS; } else { free(path); } @@ -715,7 +717,8 @@ char *searchFile(const char *pm3dir, const char *searchname) { strcat(path, filename); if (fileExists(path)) { free(filename); - return path; + *foundpath = path; + return PM3_SUCCESS; } else { free(path); } @@ -730,12 +733,27 @@ char *searchFile(const char *pm3dir, const char *searchname) { strcat(path, filename); if (fileExists(path)) { free(filename); - return path; + *foundpath = path; + return PM3_SUCCESS; } else { free(path); } } out: free(filename); - return NULL; + return PM3_EFILE; +} + +int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix) { + char *filename = filenamemcopy(searchname, suffix); + if (filename == NULL) return PM3_EMALLOC; + int res = searchFinalFile(foundpath, pm3dir, filename); + if (res != PM3_SUCCESS) { + if (res == PM3_EFILE) + PrintAndLogEx(FAILED, "Error - can't find %s", filename); + free(filename); + return res; + } + free(filename); + return PM3_SUCCESS; } diff --git a/client/fileutils.h b/client/fileutils.h index bb229efb5..1e912a899 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -160,8 +160,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u */ int convertOldMfuDump(uint8_t **dump, size_t *dumplen); -char *filenamemcopy(const char *preferredName, const char *suffix); int searchAndList(const char *pm3dir, const char *ext); -char *searchFile(const char *pm3dir, const char *searchname); +int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix); #endif // FILEUTILS_H From f9d8d56317a455b55fe994533458fa1d80e41caa Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 24 Aug 2019 13:16:28 +0200 Subject: [PATCH 096/347] add iclass json dump format --- client/fileutils.c | 34 ++++++++++++++++++++++++++++++++++ client/fileutils.h | 1 + 2 files changed, 35 insertions(+) diff --git a/client/fileutils.c b/client/fileutils.c index 622bb88de..83744cc6f 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -281,6 +281,19 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s } break; } + case jsfIclass: { + JsonSaveStr(root, "FileType", "iclass"); + uint8_t uid[8] = {0}; + memcpy(uid, data, 8); + JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); + + for (size_t i = 0; i < (datalen / 8 ); i++) { + char path[PATH_MAX_LENGTH] = {0}; + sprintf(path, "$blocks.%zu", i); + JsonSaveBufAsHexCompact(root, path, data + (i * 8), 8); + } + break; + } } int res = json_dump_file(root, fileName, JSON_INDENT(2)); @@ -512,6 +525,27 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ *datalen = sptr; } + if (!strcmp(ctype, "iclass")) { + size_t sptr = 0; + for (size_t i = 0; i < (maxdatalen / 8); i++) { + if (sptr + 8 > maxdatalen) { + retval = 5; + goto out; + } + + char path[30] = {0}; + sprintf(path, "$.blocks.%zu", i); + + size_t len = 0; + JsonLoadBufAsHex(root, path, &udata[sptr], 8, &len); + if (!len) + break; + + sptr += len; + } + *datalen = sptr; + } + PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName); out: json_decref(root); diff --git a/client/fileutils.h b/client/fileutils.h index 1e912a899..d23472867 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -54,6 +54,7 @@ typedef enum { jsfCardMemory, jsfMfuMemory, jsfHitag, + jsfIclass, // jsf14b, // jsf15, // jsfLegic, From 7dbb5427eaf0b92d49be89ffed341d4fb5f46324 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Sat, 24 Aug 2019 18:11:03 +0200 Subject: [PATCH 097/347] Transformation from hardautopwn to autopwn, now are all the mifare classic attacks automated. --- client/cmdhfmf.c | 397 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 271 insertions(+), 126 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index e968548b6..460089151 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -166,20 +166,24 @@ static int usage_hf14_hardnested(void) { PrintAndLogEx(NORMAL, " hf mf hardnested 0 A A0A1A2A3A4A5 4 A FFFFFFFFFFFF"); return 0; } -static int usage_hf14_hardautopwn(void) { +static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, "Usage:"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn [k] "); - PrintAndLogEx(NORMAL, " * [d] [f] [s] [i] [l]"); + PrintAndLogEx(NORMAL, " hf mf autopwn [k] "); + PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l]"); PrintAndLogEx(NORMAL, " (card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K)"); PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Description:"); + PrintAndLogEx(NORMAL, " This command is used to automate the attack process on mifare classic nfc cards."); + PrintAndLogEx(NORMAL, " The program tries to identify the prng type and then automatically attack it with the best algorithm."); + PrintAndLogEx(NORMAL, " If all the sector keys are broken, they will be dumped to a file."); + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); - PrintAndLogEx(NORMAL, " d write keys to binary file"); PrintAndLogEx(NORMAL, " f .dic dictionary file for key discovery (the file has to end in .dic)"); - PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards)"); + PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards) for hardnested"); PrintAndLogEx(NORMAL, " l legacy mode (use the slow mfchk for the key enumeration)"); - PrintAndLogEx(NORMAL, " i set type of SIMD instructions. Without this flag programs autodetect it."); + PrintAndLogEx(NORMAL, " i set type of SIMD instructions. Without this flag programs autodetect it. (for hardnested)"); PrintAndLogEx(NORMAL, " i 5 = AVX512"); PrintAndLogEx(NORMAL, " i 2 = AVX2"); PrintAndLogEx(NORMAL, " i a = AVX"); @@ -188,13 +192,11 @@ static int usage_hf14_hardautopwn(void) { PrintAndLogEx(NORMAL, " i n = none (use CPU regular instruction set)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn d"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn * 1 d f default_keys"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF d"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF * 1 d f default_keys"); - PrintAndLogEx(NORMAL, " hf mf hardautopwn k 0 A FFFFFFFFFFFF * 4 s i 5"); - - PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, " hf mf autopwn"); + PrintAndLogEx(NORMAL, " hf mf autopwn * 1 f default_keys"); + PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF"); + PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 1 f default_keys"); + PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 4 i 5"); return 0; } static int usage_hf14_chk(void) { @@ -1562,58 +1564,52 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { } -static int CmdHF14AMfHardAuto(const char *Cmd) { +static int CmdHF14AMfAutoPWN(const char *Cmd) { + // Nested and Hardnested parameter uint8_t blockNo = 0; uint8_t keyType = 0; - uint8_t *keyBlock; - uint8_t sectorsCnt = MIFARE_1K_MAXSECTOR; - sector_t *e_sector; uint8_t key[6] = {0}; - uint8_t tmpKey[6] = {0}; uint64_t key64 = 0; + // Attack key storage variables + uint8_t *keyBlock; uint16_t keycnt = 0; + sector_t *e_sector; + uint8_t sectorsCnt = MIFARE_1K_MAXSECTOR; + uint8_t tmpKey[6] = {0}; size_t datalen = 0; - uint32_t chunksize; - - uint64_t t1; // For the timier - uint8_t foundKeysDictionary = 0; - uint8_t foundKeysReused = 0; - uint8_t foundKeysHardnested = 0; - + // For the timier + uint64_t t1; + // Parameters and dictionary file char filename[FILE_PATH_SIZE] = {0}; uint8_t cmdp = 0; char ctmp; - + // Nested and Hardnested returned status uint64_t foundkey = 0; int16_t isOK = 0; - - int i, i2, i3; // Loop counter + // Loop counter + int i, i2, i3; int current_sector_i = 0, current_key_type_i = 0; - + // Settings bool slow = false; bool nonce_file_read = false; bool nonce_file_write = false; - bool createDumpFile = false; bool know_target_key = false; bool legacy_mfchk = false; - bool firstChunk = 0, lastChunk = 0; + bool prng_type = false; + bool calibrate = true; + // Parse the options given by the user ctmp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf14_hardautopwn(); - while ((ctmp = param_getchar(Cmd, cmdp))) { switch (tolower(ctmp)) { case 'h': - return usage_hf14_hardautopwn(); + return usage_hf14_autopwn(); case 'f': if (param_getstr(Cmd, cmdp +1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "Filename too long"); } cmdp ++; break; - case 'd': - createDumpFile = true; - break; case 'l': legacy_mfchk = true; break; @@ -1684,20 +1680,6 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { cmdp++; } - // Print parameters - PrintAndLogEx(NORMAL, "Used Parameters:"); - PrintAndLogEx(SUCCESS, "Dumping the found keys: %s", createDumpFile ? "True" : "False"); - PrintAndLogEx(SUCCESS, "Card sectors: %d", sectorsCnt); - PrintAndLogEx(SUCCESS, "Key supplied: %s", know_target_key ? "True" : "False"); - PrintAndLogEx(SUCCESS, "Known sector: %d", blockNo); - PrintAndLogEx(SUCCESS, "Keytype: %c", keyType ? 'B' : 'A'); - PrintAndLogEx(SUCCESS, "Kown key: 0x%02x%02x%02x%02x%02x%02x", key[0], key[1], key[2], key[3], key[4], key[5]); - PrintAndLogEx(SUCCESS, "Dictionary: %s", filename); - PrintAndLogEx(SUCCESS, "Legacy mode (mfchk): %s", legacy_mfchk ? "True" : "False"); - PrintAndLogEx(WARNING, "Starting attack!"); - if (know_target_key == false) - PrintAndLogEx(WARNING, "No known key was supplied, if no usable key is found in the dictionary, then this attack will fail!"); - // Create the key storage stucture e_sector = calloc(sectorsCnt, sizeof(sector_t)); if (e_sector == NULL) return PM3_EMALLOC; @@ -1709,9 +1691,74 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { } } + // Get the card prng type (weak=true / hard=false) + prng_type = detect_classic_prng(); + + // Print operating parameters + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Card sectors .. " _YELLOW_("%d"), sectorsCnt); + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Key supplied .. " _YELLOW_("%s"), know_target_key ? "True" : "False"); + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Known sector .. " _YELLOW_("%d"), blockNo); + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Keytype ....... " _YELLOW_("%c"), keyType ? 'B' : 'A'); + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Kown key ...... " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), key[0], key[1], key[2], key[3], key[4], key[5]); + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Card PRNG ..... " _YELLOW_("%s"), prng_type ? "WEAK" : "HARD"); + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Dictionary .... " _YELLOW_("%s"), strlen(filename) ? filename : "NONE"); + PrintAndLogEx(SUCCESS, "[ SETTINGS ] Legacy mode ... " _YELLOW_("%s"), legacy_mfchk ? "True" : "False"); + PrintAndLogEx(WARNING, "Starting attack!"); + + // Check the user supplied key + if (know_target_key == false) + PrintAndLogEx(WARNING, "No known key was supplied, the following attacks might fail!"); + else { + if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used to the nested / hardnested attack: Sector:" + _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + blockNo, + keyType ? 'B' : 'A', + key[0], key[1], key[2], key[3], key[4], key[5]); + + // Store the key for the nested / hardnested attack (if supplied by the user) + e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); + e_sector[blockNo].foundKey[keyType] = 3; + } else { + know_target_key = false; + PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + blockNo, + keyType ? 'B' : 'A', + key[0], key[1], key[2], key[3], key[4], key[5]); + PrintAndLogEx(WARNING, "Let's see if just the sector or keytype are not correct, and then we also give the dictionary a try ;)"); + } + // Check if the user supplied key is used by other sectors + for (i=0; i just be nice and correct it ;) + if (know_target_key == false) { + num_to_bytes(e_sector[i].Key[i2], 6, key); + know_target_key = true; + blockNo = i; keyType = i2; + PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used to the nested / hardnested attack: Sector:" + _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + blockNo, + keyType ? 'B' : 'A', + key[0], key[1], key[2], key[3], key[4], key[5]); + } + } + } + } + } + } + // Load the dictionary if (strlen(filename) != 0) { - keyBlock = calloc(6 * 1000, sizeof(uint8_t)); + keyBlock = calloc(6 * 2000, sizeof(uint8_t)); loadFileDICTIONARY(filename, keyBlock, &datalen, 6, &keycnt); } else { keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); @@ -1726,6 +1773,7 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { // Start the timer t1 = msclock(); + // Use the dictionary to find sector keys on the card PrintAndLogEx(SUCCESS, "Enumerating the card keys with the dictionary!"); if (legacy_mfchk) { // Check all the sectors @@ -1735,7 +1783,7 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { if (e_sector[i].foundKey[i2] == 0) { for (i3=0; i3 (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : keycnt; - firstChunk = true; lastChunk = false; + int chunksize = keycnt > (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : keycnt; + bool firstChunk = true, lastChunk = false; for (uint8_t strategy = 1; strategy < 3; strategy++) { PrintAndLogEx(SUCCESS, "Running strategy %u", strategy); // main keychunk loop @@ -1774,45 +1822,82 @@ static int CmdHF14AMfHardAuto(const char *Cmd) { } // end strategy } - // Check if at least one key was recovered + // Analyse the dictionary attack for (i=0; i The fast check --> mfCheckKeys_fast(sectorsCnt, true, true, 2, 1, tmpKey, e_sector, false); + // Returns false keys, so we just stick to the slower mfchk. for (i=0; i try hardnested instead!"); + goto tryHardnested; + break; + case -4 : //key not found + calibrate = false; + PrintAndLogEx(FAILED, "Nested attack failed --> try hardnested instead!"); + goto tryHardnested; + break; + case -5 : + calibrate = false; + e_sector[current_sector_i].Key[current_key_type_i] = bytes_to_num(tmpKey, 6); + e_sector[current_sector_i].foundKey[current_key_type_i] = 5; break; default : + PrintAndLogEx(ERR, "unknown Error.\n"); + return 1; break; } - free(e_sector); - return 2; - } + } else { + tryHardnested: // If the nested attack failes then we try the hardnested attack + PrintAndLogEx(SUCCESS, "[ HARDNESTED ] Sector no:%3d, target key type:%c, Slow: %s", + current_sector_i, + current_key_type_i ? 'B' : 'A', + slow ? "Yes" : "No"); - // Copy the found key to the tmpKey variale (for the following print statement, and the mfCheckKeys above) - num_to_bytes(foundkey, 6, tmpKey); - e_sector[current_sector_i].Key[current_key_type_i] = foundkey; - e_sector[current_sector_i].foundKey[current_key_type_i] = 1; - PrintAndLogEx(SUCCESS, "[HARDNE. KEYS] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), - current_sector_i, - current_key_type_i ? 'B' : 'A', - tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); - foundKeysHardnested++; + isOK = mfnestedhard(FirstBlockOfSector(blockNo), keyType, key, FirstBlockOfSector(current_sector_i), current_key_type_i, NULL, nonce_file_read, nonce_file_write, slow, 0, &foundkey, NULL); + DropField(); + if (isOK) { + switch (isOK) { + case 1 : + PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); + break; + case 2 : + PrintAndLogEx(NORMAL, "Button pressed. Aborted.\n"); + break; + default : + break; + } + free(e_sector); + return 2; + } + + // Copy the found key to the tmpKey variale (for the following print statement, and the mfCheckKeys above) + num_to_bytes(foundkey, 6, tmpKey); + e_sector[current_sector_i].Key[current_key_type_i] = foundkey; + e_sector[current_sector_i].foundKey[current_key_type_i] = 6; + } + // Check if the key was found + if (e_sector[current_sector_i].foundKey[current_key_type_i] != 0) { + PrintAndLogEx(SUCCESS, "[BROCKEN KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + current_sector_i, + current_key_type_i ? 'B' : 'A', + tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); + } else { + PrintAndLogEx(FAILED, "[BROCKEN KEY] Valid KEY NOT FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + current_sector_i, + current_key_type_i ? 'B' : 'A', + tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); + } } } } } + // Show the results to the user + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "Found KEYS:"); printKeyTable(sectorsCnt, e_sector); - // Create a dumpfile - if (createDumpFile) { - PrintAndLogEx(SUCCESS, "\nDumping the found keys:"); - createKeyDump(sectorsCnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); - } + PrintAndLogEx(SUCCESS, "[ INFO ] Key res types:"); + PrintAndLogEx(SUCCESS, " 1: Dictionary"); + PrintAndLogEx(SUCCESS, " 2: Darkside attack"); + PrintAndLogEx(SUCCESS, " 3: User supplied"); + PrintAndLogEx(SUCCESS, " 4: Reused"); + PrintAndLogEx(SUCCESS, " 5: Nested"); + PrintAndLogEx(SUCCESS, " 6: Hardnested"); + // Generate and show statistics t1 = msclock() - t1; - PrintAndLogEx(SUCCESS, "Keys statistics (total: %d):" - "\n\t(*) Broken with hardnested attack: " _MAGENTA_("%d") - "\n\t(*) Reused keys: " _YELLOW_("%d") - "\n\t(*) Discovered with the dictionary: " _YELLOW_("%d") - , sectorsCnt*2, foundKeysHardnested, foundKeysReused, foundKeysDictionary); - PrintAndLogEx(SUCCESS, "Required time for the hardautopwn attack: " _YELLOW_("%.0f") " seconds\n", (float)t1 / 1000.0); + PrintAndLogEx(SUCCESS, "Required time for the autopwn attack: " _YELLOW_("%.0f") " seconds", (float)t1 / 1000.0); + + // Create a dumpfile if all keys are known + for (current_sector_i=0; current_sector_i < sectorsCnt; current_sector_i++) { + for (current_key_type_i=0; current_key_type_i < 2; current_key_type_i++) { + // If the key is already known, just skip it + if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { + PrintAndLogEx(FAILED, "Not all keys were discovered --> no dump file will be created!"); + goto notAllKeysFound; + } + } + } + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "All keys were discovered, dumping them now:"); + createKeyDump(sectorsCnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); + notAllKeysFound: free(e_sector); - free(keyBlock); return 0; } @@ -3987,7 +4132,7 @@ static command_t CommandTable[] = { {"darkside", CmdHF14AMfDarkside, IfPm3Iso14443a, "Darkside attack. read parity error messages."}, {"nested", CmdHF14AMfNested, IfPm3Iso14443a, "Nested attack. Test nested authentication"}, {"hardnested", CmdHF14AMfNestedHard, AlwaysAvailable, "Nested attack for hardened Mifare cards"}, - {"hardautopwn", CmdHF14AMfHardAuto, AlwaysAvailable, "Nested attack for hardened Mifare cards that breaks all sector keys autmatically"}, + {"autopwn", CmdHF14AMfAutoPWN, AlwaysAvailable, "Automatic attack tool, to extrackt the nfc keys (with dicrionaries, nested and hardnested attacks)"}, {"keybrute", CmdHF14AMfKeyBrute, IfPm3Iso14443a, "J_Run's 2nd phase of multiple sector nested authentication key recovery"}, {"nack", CmdHf14AMfNack, IfPm3Iso14443a, "Test for Mifare NACK bug"}, {"chk", CmdHF14AMfChk, IfPm3Iso14443a, "Check keys"}, From bd01b7bd96859abf5b9f6035e0a81ff1ba407af3 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Sun, 25 Aug 2019 11:13:53 +0200 Subject: [PATCH 098/347] Now the keys are transfered to the simulator memory and the whole card gets dumped at the end. --- client/cmdhfmf.c | 111 ++++++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 39 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 460089151..473d4b297 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -169,13 +169,13 @@ static int usage_hf14_hardnested(void) { static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, "Usage:"); PrintAndLogEx(NORMAL, " hf mf autopwn [k] "); - PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l]"); + PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l] [t] [d]"); PrintAndLogEx(NORMAL, " (card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Description:"); PrintAndLogEx(NORMAL, " This command is used to automate the attack process on mifare classic nfc cards."); PrintAndLogEx(NORMAL, " The program tries to identify the prng type and then automatically attack it with the best algorithm."); - PrintAndLogEx(NORMAL, " If all the sector keys are broken, they will be dumped to a file."); + PrintAndLogEx(NORMAL, " After the program is done, the keys and card data is dumped."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); @@ -1575,6 +1575,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { uint16_t keycnt = 0; sector_t *e_sector; uint8_t sectorsCnt = MIFARE_1K_MAXSECTOR; + int blockCnt = MIFARE_1K_MAXBLOCK; uint8_t tmpKey[6] = {0}; size_t datalen = 0; // For the timier @@ -1589,6 +1590,11 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Loop counter int i, i2, i3; int current_sector_i = 0, current_key_type_i = 0; + // Dumping and transfere to simulater memory + uint8_t block[16] = {0x00}; + uint8_t *dump; + int bytes; + char* fnameptr = filename; // Settings bool slow = false; bool nonce_file_read = false; @@ -1616,6 +1622,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { case '*': // Get the number of sectors sectorsCnt = NumOfSectors(param_getchar(Cmd, cmdp + 1)); + blockCnt = NumOfBlocks(param_getchar(Cmd, cmdp + 1)); cmdp ++; break; case 'k': @@ -1695,14 +1702,14 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { prng_type = detect_classic_prng(); // Print operating parameters - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Card sectors .. " _YELLOW_("%d"), sectorsCnt); - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Key supplied .. " _YELLOW_("%s"), know_target_key ? "True" : "False"); - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Known sector .. " _YELLOW_("%d"), blockNo); - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Keytype ....... " _YELLOW_("%c"), keyType ? 'B' : 'A'); - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Kown key ...... " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), key[0], key[1], key[2], key[3], key[4], key[5]); - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Card PRNG ..... " _YELLOW_("%s"), prng_type ? "WEAK" : "HARD"); - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Dictionary .... " _YELLOW_("%s"), strlen(filename) ? filename : "NONE"); - PrintAndLogEx(SUCCESS, "[ SETTINGS ] Legacy mode ... " _YELLOW_("%s"), legacy_mfchk ? "True" : "False"); + PrintAndLogEx(INFO, "[ SETTINGS ] Card sectors .. " _YELLOW_("%d"), sectorsCnt); + PrintAndLogEx(INFO, "[ SETTINGS ] Key supplied .. " _YELLOW_("%s"), know_target_key ? "True" : "False"); + PrintAndLogEx(INFO, "[ SETTINGS ] Known sector .. " _YELLOW_("%d"), blockNo); + PrintAndLogEx(INFO, "[ SETTINGS ] Keytype ....... " _YELLOW_("%c"), keyType ? 'B' : 'A'); + PrintAndLogEx(INFO, "[ SETTINGS ] Kown key ...... " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), key[0], key[1], key[2], key[3], key[4], key[5]); + PrintAndLogEx(INFO, "[ SETTINGS ] Card PRNG ..... " _YELLOW_("%s"), prng_type ? "WEAK" : "HARD"); + PrintAndLogEx(INFO, "[ SETTINGS ] Dictionary .... " _YELLOW_("%s"), strlen(filename) ? filename : "NONE"); + PrintAndLogEx(INFO, "[ SETTINGS ] Legacy mode ... " _YELLOW_("%s"), legacy_mfchk ? "True" : "False"); PrintAndLogEx(WARNING, "Starting attack!"); // Check the user supplied key @@ -1710,7 +1717,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(WARNING, "No known key was supplied, the following attacks might fail!"); else { if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used to the nested / hardnested attack: Sector:" + PrintAndLogEx(INFO, "[ SETTINGS ] The following key will be used to the nested / hardnested attack: Sector:" _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), blockNo, keyType ? 'B' : 'A', @@ -1774,7 +1781,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { t1 = msclock(); // Use the dictionary to find sector keys on the card - PrintAndLogEx(SUCCESS, "Enumerating the card keys with the dictionary!"); + PrintAndLogEx(INFO, "Enumerating the card keys with the dictionary!"); if (legacy_mfchk) { // Check all the sectors for (i=0; i (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : keycnt; bool firstChunk = true, lastChunk = false; for (uint8_t strategy = 1; strategy < 3; strategy++) { - PrintAndLogEx(SUCCESS, "Running strategy %u", strategy); + PrintAndLogEx(INFO, "Running strategy %u", strategy); // main keychunk loop for (i = 0; i < keycnt; i += chunksize) { @@ -1851,7 +1858,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (know_target_key == false) { // Check if the darkside attack can be used if (prng_type) { - PrintAndLogEx(WARNING, "No key was found ... time to go to the dark side ;)"); + PrintAndLogEx(INFO, "No key was found ... time to go to the dark side ;)"); int isOK = mfDarkside(FirstBlockOfSector(blockNo), keyType, &key64); switch (isOK) { case -1 : @@ -1933,7 +1940,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Use the nested / hardnested attack if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { if (prng_type) { - PrintAndLogEx(SUCCESS, "[ NESTED ] Sector no:%3d, target key type:%c", + PrintAndLogEx(INFO, "[ NESTED ] Sector no:%3d, target key type:%c", current_sector_i, current_key_type_i ? 'B' : 'A'); @@ -1969,7 +1976,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } } else { tryHardnested: // If the nested attack failes then we try the hardnested attack - PrintAndLogEx(SUCCESS, "[ HARDNESTED ] Sector no:%3d, target key type:%c, Slow: %s", + PrintAndLogEx(INFO, "[ HARDNESTED ] Sector no:%3d, target key type:%c, Slow: %s", current_sector_i, current_key_type_i ? 'B' : 'A', slow ? "Yes" : "No"); @@ -1998,12 +2005,12 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } // Check if the key was found if (e_sector[current_sector_i].foundKey[current_key_type_i] != 0) { - PrintAndLogEx(SUCCESS, "[BROCKEN KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(SUCCESS, "[BROCKEN KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); } else { - PrintAndLogEx(FAILED, "[BROCKEN KEY] Valid KEY NOT FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(FAILED, "[BROCKEN KEY] Valid KEY NOT FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmpKey[0], tmpKey[1], tmpKey[2], tmpKey[3], tmpKey[4], tmpKey[5]); @@ -2015,35 +2022,61 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Show the results to the user PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(SUCCESS, "Found KEYS:"); + PrintAndLogEx(INFO, "Found KEYS:"); printKeyTable(sectorsCnt, e_sector); - PrintAndLogEx(SUCCESS, "[ INFO ] Key res types:"); - PrintAndLogEx(SUCCESS, " 1: Dictionary"); - PrintAndLogEx(SUCCESS, " 2: Darkside attack"); - PrintAndLogEx(SUCCESS, " 3: User supplied"); - PrintAndLogEx(SUCCESS, " 4: Reused"); - PrintAndLogEx(SUCCESS, " 5: Nested"); - PrintAndLogEx(SUCCESS, " 6: Hardnested"); + PrintAndLogEx(INFO, "[ INFO ] Key res types:"); + PrintAndLogEx(INFO, " 1: Dictionary"); + PrintAndLogEx(INFO, " 2: Darkside attack"); + PrintAndLogEx(INFO, " 3: User supplied"); + PrintAndLogEx(INFO, " 4: Reused"); + PrintAndLogEx(INFO, " 5: Nested"); + PrintAndLogEx(INFO, " 6: Hardnested"); // Generate and show statistics t1 = msclock() - t1; - PrintAndLogEx(SUCCESS, "Required time for the autopwn attack: " _YELLOW_("%.0f") " seconds", (float)t1 / 1000.0); + PrintAndLogEx(INFO, "Required time for the autopwn attack: " _YELLOW_("%.0f") " seconds", (float)t1 / 1000.0); - // Create a dumpfile if all keys are known - for (current_sector_i=0; current_sector_i < sectorsCnt; current_sector_i++) { - for (current_key_type_i=0; current_key_type_i < 2; current_key_type_i++) { - // If the key is already known, just skip it - if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { - PrintAndLogEx(FAILED, "Not all keys were discovered --> no dump file will be created!"); - goto notAllKeysFound; - } - } - } + // Transfere the found keys to the simulator and dump the keys and card data PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(SUCCESS, "All keys were discovered, dumping them now:"); + PrintAndLogEx(INFO, "Dumping the keys:"); createKeyDump(sectorsCnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); - notAllKeysFound: + PrintAndLogEx(SUCCESS, "Transfering the found keys to the simulator memory"); + for (current_sector_i=0; current_sector_i < sectorsCnt; current_sector_i++) { + mfEmlGetMem(block, current_sector_i, 1); + if (e_sector[current_sector_i].foundKey[0]) + num_to_bytes(e_sector[current_sector_i].Key[0], 6, block); + if (e_sector[current_sector_i].foundKey[1]) + num_to_bytes(e_sector[current_sector_i].Key[1], 6, block + 10); + mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1); + } + + clearCommandBuffer(); + SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, sectorsCnt, 0, 0, NULL, 0); + + bytes = blockCnt * MFBLOCK_SIZE; + dump = calloc(bytes, sizeof(uint8_t)); + if (!dump) { + PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + return PM3_EMALLOC; + } + memset(dump, 0, bytes); + + PrintAndLogEx(INFO, "Downloading the card content from emulator memory"); + if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) { + PrintAndLogEx(WARNING, "Fail, transfer from device time-out"); + free(dump); + return PM3_ETIMEOUT; + } + + fnameptr += sprintf(fnameptr, "hf-mf-"); + FillFileNameByUID(fnameptr, dump, "-dump", 4); + + saveFile(filename, ".bin", dump, bytes); + saveFileEML(filename, dump, bytes, MFBLOCK_SIZE); + saveFileJSON(filename, jsfCardMemory, dump, bytes); + free(dump); + free(e_sector); return 0; } From 47b2c5ddc62b28ef366843fc5cb3d0b0e127f2c8 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Sun, 25 Aug 2019 11:16:10 +0200 Subject: [PATCH 099/347] Removed old command options. --- client/cmdhfmf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 473d4b297..067cdb212 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -169,7 +169,7 @@ static int usage_hf14_hardnested(void) { static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, "Usage:"); PrintAndLogEx(NORMAL, " hf mf autopwn [k] "); - PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l] [t] [d]"); + PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l]"); PrintAndLogEx(NORMAL, " (card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Description:"); From 13641771baefae4b0cb8b176dcdcbe1549b4279c Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Sun, 25 Aug 2019 22:24:52 +0200 Subject: [PATCH 100/347] Improved help message, implementation of a verbose option (to reduce the output), corrected some spelling mistakes and cleaned up variable names. --- client/cmdhfmf.c | 206 ++++++++++++++++++++++++++--------------------- 1 file changed, 112 insertions(+), 94 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 067cdb212..4cd1a02a7 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -169,8 +169,7 @@ static int usage_hf14_hardnested(void) { static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, "Usage:"); PrintAndLogEx(NORMAL, " hf mf autopwn [k] "); - PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l]"); - PrintAndLogEx(NORMAL, " (card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K)"); + PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l] [v]"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Description:"); PrintAndLogEx(NORMAL, " This command is used to automate the attack process on mifare classic nfc cards."); @@ -182,7 +181,13 @@ static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); PrintAndLogEx(NORMAL, " f .dic dictionary file for key discovery (the file has to end in .dic)"); PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards) for hardnested"); + PrintAndLogEx(NORMAL, " v verbose output (statistcs)"); PrintAndLogEx(NORMAL, " l legacy mode (use the slow mfchk for the key enumeration)"); + PrintAndLogEx(NORMAL, " * all sectors based on card memory, other values then below defaults to 1k"); + PrintAndLogEx(NORMAL, " * 0 = MINI(320 bytes)"); + PrintAndLogEx(NORMAL, " * 1 = 1K"); + PrintAndLogEx(NORMAL, " * 2 = 2K"); + PrintAndLogEx(NORMAL, " * 4 = 4K"); PrintAndLogEx(NORMAL, " i set type of SIMD instructions. Without this flag programs autodetect it. (for hardnested)"); PrintAndLogEx(NORMAL, " i 5 = AVX512"); PrintAndLogEx(NORMAL, " i 2 = AVX2"); @@ -1570,14 +1575,16 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { uint8_t keyType = 0; uint8_t key[6] = {0}; uint64_t key64 = 0; + bool calibrate = true; // Attack key storage variables uint8_t *keyBlock; uint16_t keycnt = 0; - sector_t *e_sector; + sector_t *eSector; uint8_t sectorsCnt = MIFARE_1K_MAXSECTOR; int blockCnt = MIFARE_1K_MAXBLOCK; uint8_t tmpKey[6] = {0}; size_t datalen = 0; + bool knowTargetKey = false; // For the timier uint64_t t1; // Parameters and dictionary file @@ -1597,12 +1604,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { char* fnameptr = filename; // Settings bool slow = false; - bool nonce_file_read = false; - bool nonce_file_write = false; - bool know_target_key = false; bool legacy_mfchk = false; bool prng_type = false; - bool calibrate = true; + bool verbose = false; // Parse the options given by the user ctmp = tolower(param_getchar(Cmd, 0)); @@ -1619,6 +1623,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { case 'l': legacy_mfchk = true; break; + case 'v': + verbose = true; + break; case '*': // Get the number of sectors sectorsCnt = NumOfSectors(param_getchar(Cmd, cmdp + 1)); @@ -1646,7 +1653,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(WARNING, "Key must include 12 HEX symbols"); return 1; } - know_target_key = true; + knowTargetKey = true; cmdp += 3; case 's': slow = true; @@ -1688,13 +1695,13 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } // Create the key storage stucture - e_sector = calloc(sectorsCnt, sizeof(sector_t)); - if (e_sector == NULL) return PM3_EMALLOC; + eSector = calloc(sectorsCnt, sizeof(sector_t)); + if (eSector == NULL) return PM3_EMALLOC; // Clear the key storage datastructure for (i=0; i just be nice and correct it ;) - if (know_target_key == false) { - num_to_bytes(e_sector[i].Key[i2], 6, key); - know_target_key = true; + if (knowTargetKey == false) { + num_to_bytes(eSector[i].Key[i2], 6, key); + knowTargetKey = true; blockNo = i; keyType = i2; - PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used to the nested / hardnested attack: Sector:" + PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used for the nested / hardnested attack: sector:" _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), blockNo, keyType ? 'B' : 'A', @@ -1769,7 +1777,10 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { loadFileDICTIONARY(filename, keyBlock, &datalen, 6, &keycnt); } else { keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); - if (keyBlock == NULL) return 1; + if (keyBlock == NULL) { + free(eSector); + return 1; + } for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) { num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); @@ -1787,12 +1798,12 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { for (i=0; i The fast check --> mfCheckKeys_fast(sectorsCnt, true, true, 2, 1, tmpKey, e_sector, false); + // The fast check --> mfCheckKeys_fast(sectorsCnt, true, true, 2, 1, tmpKey, eSector, false); // Returns false keys, so we just stick to the slower mfchk. for (i=0; i try hardnested instead!"); goto tryHardnested; break; @@ -1966,11 +1979,12 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { break; case -5 : calibrate = false; - e_sector[current_sector_i].Key[current_key_type_i] = bytes_to_num(tmpKey, 6); - e_sector[current_sector_i].foundKey[current_key_type_i] = 5; + eSector[current_sector_i].Key[current_key_type_i] = bytes_to_num(tmpKey, 6); + eSector[current_sector_i].foundKey[current_key_type_i] = 5; break; default : PrintAndLogEx(ERR, "unknown Error.\n"); + free(eSector); return 1; break; } @@ -1981,30 +1995,30 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { current_key_type_i ? 'B' : 'A', slow ? "Yes" : "No"); - isOK = mfnestedhard(FirstBlockOfSector(blockNo), keyType, key, FirstBlockOfSector(current_sector_i), current_key_type_i, NULL, nonce_file_read, nonce_file_write, slow, 0, &foundkey, NULL); + isOK = mfnestedhard(FirstBlockOfSector(blockNo), keyType, key, FirstBlockOfSector(current_sector_i), current_key_type_i, NULL, false, false, slow, 0, &foundkey, NULL); DropField(); if (isOK) { switch (isOK) { case 1 : - PrintAndLogEx(ERR, "Error: No response from Proxmark3.\n"); + PrintAndLogEx(ERR, "\nError: No response from Proxmark3."); break; case 2 : - PrintAndLogEx(NORMAL, "Button pressed. Aborted.\n"); + PrintAndLogEx(NORMAL, "\nButton pressed. Aborted."); break; default : break; } - free(e_sector); + free(eSector); return 2; } // Copy the found key to the tmpKey variale (for the following print statement, and the mfCheckKeys above) num_to_bytes(foundkey, 6, tmpKey); - e_sector[current_sector_i].Key[current_key_type_i] = foundkey; - e_sector[current_sector_i].foundKey[current_key_type_i] = 6; + eSector[current_sector_i].Key[current_key_type_i] = foundkey; + eSector[current_sector_i].foundKey[current_key_type_i] = 6; } // Check if the key was found - if (e_sector[current_sector_i].foundKey[current_key_type_i] != 0) { + if (eSector[current_sector_i].foundKey[current_key_type_i] != 0) { PrintAndLogEx(SUCCESS, "[BROCKEN KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', @@ -2022,32 +2036,30 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Show the results to the user PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "Found KEYS:"); - printKeyTable(sectorsCnt, e_sector); - PrintAndLogEx(INFO, "[ INFO ] Key res types:"); - PrintAndLogEx(INFO, " 1: Dictionary"); - PrintAndLogEx(INFO, " 2: Darkside attack"); - PrintAndLogEx(INFO, " 3: User supplied"); - PrintAndLogEx(INFO, " 4: Reused"); - PrintAndLogEx(INFO, " 5: Nested"); - PrintAndLogEx(INFO, " 6: Hardnested"); + PrintAndLogEx(INFO, "Found Keys:"); + printKeyTable(sectorsCnt, eSector); + if (verbose) { + PrintAndLogEx(INFO, "[ INFO ] Key res types:"); + PrintAndLogEx(INFO, " 1: Dictionary"); + PrintAndLogEx(INFO, " 2: Darkside attack"); + PrintAndLogEx(INFO, " 3: User supplied"); + PrintAndLogEx(INFO, " 4: Reused"); + PrintAndLogEx(INFO, " 5: Nested"); + PrintAndLogEx(INFO, " 6: Hardnested"); + } - // Generate and show statistics - t1 = msclock() - t1; - PrintAndLogEx(INFO, "Required time for the autopwn attack: " _YELLOW_("%.0f") " seconds", (float)t1 / 1000.0); - // Transfere the found keys to the simulator and dump the keys and card data PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "Dumping the keys:"); - createKeyDump(sectorsCnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); + createKeyDump(sectorsCnt, eSector, GenerateFilename("hf-mf-", "-key.bin")); PrintAndLogEx(SUCCESS, "Transfering the found keys to the simulator memory"); for (current_sector_i=0; current_sector_i < sectorsCnt; current_sector_i++) { mfEmlGetMem(block, current_sector_i, 1); - if (e_sector[current_sector_i].foundKey[0]) - num_to_bytes(e_sector[current_sector_i].Key[0], 6, block); - if (e_sector[current_sector_i].foundKey[1]) - num_to_bytes(e_sector[current_sector_i].Key[1], 6, block + 10); + if (eSector[current_sector_i].foundKey[0]) + num_to_bytes(eSector[current_sector_i].Key[0], 6, block); + if (eSector[current_sector_i].foundKey[1]) + num_to_bytes(eSector[current_sector_i].Key[1], 6, block + 10); mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1); } @@ -2058,6 +2070,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { dump = calloc(bytes, sizeof(uint8_t)); if (!dump) { PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + free(eSector); return PM3_EMALLOC; } memset(dump, 0, bytes); @@ -2065,6 +2078,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(INFO, "Downloading the card content from emulator memory"); if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) { PrintAndLogEx(WARNING, "Fail, transfer from device time-out"); + free(eSector); free(dump); return PM3_ETIMEOUT; } @@ -2075,9 +2089,13 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { saveFile(filename, ".bin", dump, bytes); saveFileEML(filename, dump, bytes, MFBLOCK_SIZE); saveFileJSON(filename, jsfCardMemory, dump, bytes); - free(dump); - free(e_sector); + // Generate and show statistics + t1 = msclock() - t1; + PrintAndLogEx(INFO, "Required time for the autopwn attack: " _YELLOW_("%.0f") " seconds", (float)t1 / 1000.0); + + free(dump); + free(eSector); return 0; } From ccb85067d52dbb031bd58f99b4b760edaeb8a1df Mon Sep 17 00:00:00 2001 From: Iceman Date: Mon, 26 Aug 2019 09:12:26 +0200 Subject: [PATCH 101/347] Update README.md --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 68ef01492..9bf18de1a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# RRG / Iceman repo, dedicated to Proxmark3 RDV4.0 +# RRG / Iceman repo - Proxmark3 RDV4.0 and other Proxmark3 platforms. -This repo is based on iceman fork for Proxmark3. It is dedicated to bringing the most out of the new features for Proxmark3 RDV4.0 new hardware and design. +This repo is based on iceman fork for Proxmark3. It supports other Proxmark3 platforms as well. -_Note that it also supports other Proxmark3 platforms as well!_ +It is dedicated to bringing the most out of the new features for Proxmark3 RDV4.0 new hardware and design. | Releases | Linux & OSX CI | Windows CI | @@ -28,6 +28,9 @@ _Note that it also supports other Proxmark3 platforms as well!_ |[Developing standalone mode](/armsrc/Standalone/readme.md)|[Wiki about standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) || |[Donations](#Donations)||| +## Support on other Proxmark3 platforms +In order to build this repo for other Proxmark3 platforms we urge you to read [Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md) + ## What has changed? On the hardware side: From 2e4c7f4f8d7ed4fbb3e4b5a489716903c3bce828 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 26 Aug 2019 10:52:07 +0200 Subject: [PATCH 102/347] chg: reuse code --- client/loclass/cipherutils.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index 80364d4e1..52ac82f94 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -160,19 +160,7 @@ void printarr(const char *name, uint8_t *arr, int len) { } void printvar(const char *name, uint8_t *arr, int len) { -/* - int cx, i; - size_t outsize = 40 + strlen(name) + len * 2; - char *output = calloc(outsize, sizeof(char)); - cx = snprintf(output, outsize, "%s = ", name); - for (i = 0; i < len; i++) { - cx += snprintf(output + cx, outsize - cx, "%02x", *(arr + i)); //2 bytes per byte - } - PrintAndLogEx(NORMAL, output); - free(output); - */ PrintAndLogEx(NORMAL, "%s = " _YELLOW_("%s"), name, sprint_hex(arr, len) ); - } void printarr_human_readable(const char *title, uint8_t *arr, int len) { From 2edee59837f0903c5db1a7ceb3e7addcd910e87c Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Mon, 26 Aug 2019 12:27:40 +0200 Subject: [PATCH 103/347] Changed the variable names, added aditional dictionary size checks, fixed a corner case with the key transferes. --- client/cmdhfmf.c | 204 +++++++++++++++++++++++++---------------------- 1 file changed, 107 insertions(+), 97 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 4cd1a02a7..1fb2d48ff 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -179,7 +179,7 @@ static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); - PrintAndLogEx(NORMAL, " f .dic dictionary file for key discovery (the file has to end in .dic)"); + PrintAndLogEx(NORMAL, " f .dic dictionary file for key discovery (the file has to end in .dic) max 2000 entries allowed"); PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards) for hardnested"); PrintAndLogEx(NORMAL, " v verbose output (statistcs)"); PrintAndLogEx(NORMAL, " l legacy mode (use the slow mfchk for the key enumeration)"); @@ -1578,13 +1578,13 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { bool calibrate = true; // Attack key storage variables uint8_t *keyBlock; - uint16_t keycnt = 0; - sector_t *eSector; - uint8_t sectorsCnt = MIFARE_1K_MAXSECTOR; - int blockCnt = MIFARE_1K_MAXBLOCK; - uint8_t tmpKey[6] = {0}; - size_t datalen = 0; - bool knowTargetKey = false; + uint16_t key_cnt = 0; + sector_t *e_sector; + uint8_t sectors_cnt = MIFARE_1K_MAXSECTOR; + int block_cnt = MIFARE_1K_MAXBLOCK; + uint8_t tmp_key[6] = {0}; + size_t data_length = 0; + bool know_target_key = false; // For the timier uint64_t t1; // Parameters and dictionary file @@ -1607,6 +1607,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { bool legacy_mfchk = false; bool prng_type = false; bool verbose = false; + int max_dictionary_size = 2000; // Parse the options given by the user ctmp = tolower(param_getchar(Cmd, 0)); @@ -1628,8 +1629,8 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { break; case '*': // Get the number of sectors - sectorsCnt = NumOfSectors(param_getchar(Cmd, cmdp + 1)); - blockCnt = NumOfBlocks(param_getchar(Cmd, cmdp + 1)); + sectors_cnt = NumOfSectors(param_getchar(Cmd, cmdp + 1)); + block_cnt = NumOfBlocks(param_getchar(Cmd, cmdp + 1)); cmdp ++; break; case 'k': @@ -1653,7 +1654,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(WARNING, "Key must include 12 HEX symbols"); return 1; } - knowTargetKey = true; + know_target_key = true; cmdp += 3; case 's': slow = true; @@ -1695,13 +1696,13 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } // Create the key storage stucture - eSector = calloc(sectorsCnt, sizeof(sector_t)); - if (eSector == NULL) return PM3_EMALLOC; + e_sector = calloc(sectors_cnt, sizeof(sector_t)); + if (e_sector == NULL) return PM3_EMALLOC; // Clear the key storage datastructure - for (i=0; i just be nice and correct it ;) - if (knowTargetKey == false) { - num_to_bytes(eSector[i].Key[i2], 6, key); - knowTargetKey = true; + if (know_target_key == false) { + num_to_bytes(e_sector[i].Key[i2], 6, key); + know_target_key = true; blockNo = i; keyType = i2; PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used for the nested / hardnested attack: sector:" _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), @@ -1773,19 +1774,26 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Load the dictionary if (strlen(filename) != 0) { - keyBlock = calloc(6 * 2000, sizeof(uint8_t)); - loadFileDICTIONARY(filename, keyBlock, &datalen, 6, &keycnt); + keyBlock = calloc(6 * max_dictionary_size, sizeof(uint8_t)); + loadFileDICTIONARY(filename, keyBlock, &data_length, 6, &key_cnt); + if ((data_length / 6) > max_dictionary_size) { + // This is not a good solution (loadFileDICTIONARY needs a maxdatalen)! + PrintAndLogEx(FAILED, "The loaded dictionary is too large: %d (allowed: %d)", data_length, max_dictionary_size); + free(keyBlock); // This won't work too well, because data on the stack is already overflown !!! + free(e_sector); + return 1; + } } else { keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); if (keyBlock == NULL) { - free(eSector); + free(e_sector); return 1; } for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) { num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); } - keycnt = ARRAYLEN(g_mifare_default_keys); + key_cnt = ARRAYLEN(g_mifare_default_keys); } // Start the timer @@ -1795,15 +1803,15 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(INFO, "Enumerating the card keys with the dictionary!"); if (legacy_mfchk) { // Check all the sectors - for (i=0; i (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : keycnt; + int chunksize = key_cnt > (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : key_cnt; bool firstChunk = true, lastChunk = false; for (uint8_t strategy = 1; strategy < 3; strategy++) { PrintAndLogEx(INFO, "Running strategy %u", strategy); // main keychunk loop - for (i = 0; i < keycnt; i += chunksize) { + for (i = 0; i < key_cnt; i += chunksize) { if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); - i = keycnt; strategy = 3; break; // Exit the loop + i = key_cnt; strategy = 3; break; // Exit the loop } - uint32_t size = ((keycnt - i) > chunksize) ? chunksize : keycnt - i; + uint32_t size = ((key_cnt - i) > chunksize) ? chunksize : key_cnt - i; // last chunk? - if (size == keycnt - i) + if (size == key_cnt - i) lastChunk = true; - int res = mfCheckKeys_fast(sectorsCnt, firstChunk, lastChunk, strategy, size, keyBlock + (i * 6), eSector, false); + int res = mfCheckKeys_fast(sectors_cnt, firstChunk, lastChunk, strategy, size, keyBlock + (i * 6), e_sector, false); if (firstChunk) firstChunk = false; // all keys, aborted if (res == 0 || res == 2) { - i = keycnt; strategy = 3; break; // Exit the loop + i = key_cnt; strategy = 3; break; // Exit the loop } } // end chunks of keys firstChunk = true; @@ -1841,19 +1849,19 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } // Analyse the dictionary attack - for (i=0; i The fast check --> mfCheckKeys_fast(sectorsCnt, true, true, 2, 1, tmpKey, eSector, false); + if (bytes_to_num(tmp_key, 6) != 0) { + // The fast check --> mfCheckKeys_fast(sectors_cnt, true, true, 2, 1, tmp_key, e_sector, false); // Returns false keys, so we just stick to the slower mfchk. - for (i=0; i Date: Mon, 26 Aug 2019 12:50:10 +0200 Subject: [PATCH 104/347] typo --- tools/analyzesize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/analyzesize.py b/tools/analyzesize.py index 4a5211c67..889222c01 100755 --- a/tools/analyzesize.py +++ b/tools/analyzesize.py @@ -16,7 +16,7 @@ except FileNotFoundError: db = dict() if len(sys.argv) < 3: - print("Usage: analazysize.py ") + print("Usage: analyzesize.py ") exit(-1) action, name = sys.argv[1:3] currentdata = subprocess.run(["arm-none-eabi-size","armsrc/obj/fullimage.stage1.elf"], stdout=subprocess.PIPE).stdout From 4ddc3d61d5250b6691603e949b784b7b76a104b4 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 13:03:11 +0200 Subject: [PATCH 105/347] hf mf chk/fchk: load dic with searchFile and fail when errors in args --- client/cmdhfmf.c | 74 ++++++++++++++++++++++++++++++---------------- client/fileutils.h | 2 +- doc/cheatsheet.md | 6 ++-- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index aaaeafb99..b2e4b9855 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -179,10 +179,10 @@ static int usage_hf14_chk(void) { PrintAndLogEx(NORMAL, " t write keys to emulator memory\n"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf mf chk 0 A 1234567890ab -- target block 0, Key A using key 1234567890ab"); - PrintAndLogEx(NORMAL, " hf mf chk 0 A default_keys.dic -- target block 0, Key A using default dictionary file"); - PrintAndLogEx(NORMAL, " hf mf chk *1 ? t -- target all blocks, all keys, 1K, write to emulator memory"); - PrintAndLogEx(NORMAL, " hf mf chk *1 ? d -- target all blocks, all keys, 1K, write to file"); + PrintAndLogEx(NORMAL, " hf mf chk 0 A 1234567890ab -- target block 0, Key A using key 1234567890ab"); + PrintAndLogEx(NORMAL, " hf mf chk 0 A mfc_default_keys.dic -- target block 0, Key A using default dictionary file"); + PrintAndLogEx(NORMAL, " hf mf chk *1 ? t -- target all blocks, all keys, 1K, write to emulator memory"); + PrintAndLogEx(NORMAL, " hf mf chk *1 ? d -- target all blocks, all keys, 1K, write to file"); return 0; } static int usage_hf14_chk_fast(void) { @@ -200,12 +200,12 @@ static int usage_hf14_chk_fast(void) { PrintAndLogEx(NORMAL, " m use dictionary from flashmemory\n"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf mf fchk 1 1234567890ab -- target 1K using key 1234567890ab"); - PrintAndLogEx(NORMAL, " hf mf fchk 1 default_keys.dic -- target 1K using default dictionary file"); - PrintAndLogEx(NORMAL, " hf mf fchk 1 t -- target 1K, write to emulator memory"); - PrintAndLogEx(NORMAL, " hf mf fchk 1 d -- target 1K, write to file"); + PrintAndLogEx(NORMAL, " hf mf fchk 1 1234567890ab -- target 1K using key 1234567890ab"); + PrintAndLogEx(NORMAL, " hf mf fchk 1 mfc_default_keys.dic -- target 1K using default dictionary file"); + PrintAndLogEx(NORMAL, " hf mf fchk 1 t -- target 1K, write to emulator memory"); + PrintAndLogEx(NORMAL, " hf mf fchk 1 d -- target 1K, write to file"); if (IfPm3Flash()) - PrintAndLogEx(NORMAL, " hf mf fchk 1 m -- target 1K, use dictionary from flashmemory"); + PrintAndLogEx(NORMAL, " hf mf fchk 1 m -- target 1K, use dictionary from flashmemory"); return 0; } static int usage_hf14_keybrute(void) { @@ -1575,7 +1575,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { sector_t *e_sector = NULL; keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); - if (keyBlock == NULL) return 1; + if (keyBlock == NULL) return PM3_EMALLOC; for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); @@ -1615,7 +1615,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { if (!p) { PrintAndLogEx(FAILED, "Cannot allocate memory for Keys"); free(keyBlock); - return 2; + return PM3_EMALLOC; } keyBlock = p; } @@ -1629,14 +1629,24 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { // May be a dic file if (param_getstr(Cmd, i, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "Filename too long"); - continue; + free(keyBlock); + return PM3_EINVARG; } - f = fopen(filename, "r"); - if (!f) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); - continue; + char *dict_path; + int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic"); + if (res != PM3_SUCCESS) { + free(keyBlock); + return res; } + f = fopen(dict_path, "r"); + if (!f) { + PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", dict_path); + free(dict_path); + free(keyBlock); + return PM3_EFILE; + } + free(dict_path); // read file while (fgets(buf, sizeof(buf), f)) { @@ -1649,7 +1659,9 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { if (!isxdigit(buf[0])) { PrintAndLogEx(FAILED, "File content error. '" _YELLOW_("%s")"' must include 12 HEX symbols", buf); - continue; + free(keyBlock); + fclose(f); + return PM3_EFILE; } buf[12] = 0; @@ -1659,7 +1671,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { PrintAndLogEx(FAILED, "Cannot allocate memory for default keys"); free(keyBlock); fclose(f); - return 2; + return PM3_EMALLOC; } keyBlock = p; } @@ -1686,7 +1698,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { e_sector = calloc(sectorsCnt, sizeof(sector_t)); if (e_sector == NULL) { free(keyBlock); - return 1; + return PM3_EMALLOC; } uint32_t chunksize = keycnt > (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : keycnt; @@ -1894,14 +1906,24 @@ static int CmdHF14AMfChk(const char *Cmd) { // May be a dic file if (param_getstr(Cmd, i, filename, sizeof(filename)) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "File name too long"); - continue; + free(keyBlock); + return PM3_EINVARG; } - f = fopen(filename, "r"); - if (!f) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); - continue; + char *dict_path; + int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic"); + if (res != PM3_SUCCESS) { + free(keyBlock); + return PM3_EFILE; } + f = fopen(dict_path, "r"); + if (!f) { + PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", dict_path); + free(dict_path); + free(keyBlock); + return PM3_EFILE; + } + free(dict_path); // load keys from dictionary file while (fgets(buf, sizeof(buf), f)) { @@ -1915,7 +1937,9 @@ static int CmdHF14AMfChk(const char *Cmd) { // codesmell, only checks first char? if (!isxdigit(buf[0])) { PrintAndLogEx(FAILED, "File content error. '" _YELLOW_("%s")"' must include 12 HEX symbols", buf); - continue; + free(keyBlock); + fclose(f); + return PM3_EFILE; } buf[12] = 0; diff --git a/client/fileutils.h b/client/fileutils.h index d23472867..eea3329c5 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -141,7 +141,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ /** * @brief Utility function to load data from a DICTIONARY textfile. This method takes a preferred name. - * E.g. default_keys.dic + * E.g. mfc_default_keys.dic * * @param preferredName * @param data The data array to store the loaded bytes from file diff --git a/doc/cheatsheet.md b/doc/cheatsheet.md index 02628a9bc..dbd48d548 100644 --- a/doc/cheatsheet.md +++ b/doc/cheatsheet.md @@ -181,7 +181,7 @@ Options card memory : 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K d : write keys to binary file -pm3 --> hf mf chk *1 ? d dictionaries/mfc_default_keys.dic +pm3 --> hf mf chk *1 ? d mfc_default_keys ``` Check for default keys from local memory @@ -254,7 +254,7 @@ pm3 --> hf mf sim u 353c2aa6 Simulate Mifare Sequence ``` -pm3 --> hf mf chk *1 ? d dictionaries/mfc_default_keys.dic +pm3 --> hf mf chk *1 ? d mfc_default_keys pm3 --> hf mf dump 1 pm3 --> script run dumptoemul -i dumpdata.bin pm3 --> hf mf eload 353C2AA6 @@ -263,7 +263,7 @@ pm3 --> hf mf sim u 353c2aa6 Clone Mifare 1K Sequence ``` -pm3 --> hf mf chk *1 ? d dictionaries/mfc_default_keys.dic +pm3 --> hf mf chk *1 ? d mfc_default_keys pm3 --> hf mf dump pm3 --> hf mf restore 1 u 4A6CE843 k hf-mf-A29558E4-key.bin f hf-mf-A29558E4-data.bin ``` From 2a1e6dff80f9ea96d4fb260a0f8fe6f2683f590e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 13:36:37 +0200 Subject: [PATCH 106/347] hf iclass chk/lookup: load dic with searchFile and fail when errors in args --- client/cmdhficlass.c | 48 ++++++++++++++++------------ doc/cheatsheet.md | 74 ++++++++++++++++++++++---------------------- 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 51bc323fc..862dad13c 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -244,8 +244,8 @@ static int usage_hf_iclass_chk(void) { PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, " c credit key (if not use, default is debit)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic"); - PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic e"); + PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys"); + PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys e"); return PM3_SUCCESS;; } static int usage_hf_iclass_lookup(void) { @@ -260,8 +260,8 @@ static int usage_hf_iclass_lookup(void) { PrintAndLogEx(NORMAL, " r raw"); PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic"); - PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic e"); + PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys"); + PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys e"); return PM3_SUCCESS; } static int usage_hf_iclass_permutekey(void) { @@ -2059,9 +2059,9 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { // load keys into keyblock int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); - if (res > 0) { + if (res != PM3_SUCCESS) { free(keyBlock); - return PM3_EFILE; + return res; } pre = calloc(keycnt, sizeof(iclass_premac_t)); @@ -2312,33 +2312,33 @@ static int CmdHFiClassLookUp(const char *Cmd) { PrintAndLogEx(SUCCESS, "MAC_TAG | %s", sprint_hex(MAC_TAG, sizeof(MAC_TAG))); int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); - if (res > 0) { + if (res != PM3_SUCCESS) { free(keyBlock); - return 1; + return res; } //iclass_prekey_t prekey = calloc(keycnt, sizeof(iclass_prekey_t)); if (!prekey) { free(keyBlock); - return 1; + return PM3_EMALLOC; } - PrintAndLogEx(FAILED, "Generating diversified keys and MAC"); + PrintAndLogEx(INFO, "Generating diversified keys and MAC"); res = GenerateFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, prekey); - if (res > 0) { + if (res != PM3_SUCCESS) { free(keyBlock); free(prekey); - return 1; + return PM3_ESOFT; } - PrintAndLogEx(FAILED, "Sorting"); + PrintAndLogEx(INFO, "Sorting"); // sort mac list. qsort(prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32); //PrintPreCalc(prekey, keycnt); - PrintAndLogEx(FAILED, "Searching"); + PrintAndLogEx(INFO, "Searching"); iclass_prekey_t *item; iclass_prekey_t lookup; memcpy(lookup.mac, MAC_TAG, 4); @@ -2377,10 +2377,19 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { uint8_t *p; int keyitems = 0; - if (!(f = fopen(filename, "r"))) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); - return 1; + + char *dict_path; + int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic"); + if (res != PM3_SUCCESS) { + return res; } + f = fopen(dict_path, "r"); + if (!f) { + PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", dict_path); + free(dict_path); + return PM3_EFILE; + } + free(dict_path); while (fgets(buf, sizeof(buf), f)) { if (strlen(buf) < 16 || buf[15] == '\n') @@ -2396,7 +2405,8 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { // doesn't this only test first char only? if (!isxdigit(buf[0])) { PrintAndLogEx(ERR, "file content error. '%s' must include 16 HEX symbols", buf); - continue; + fclose(f); + return PM3_EFILE; } // null terminator (skip the rest of the line) @@ -2406,7 +2416,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { if (!p) { PrintAndLogEx(ERR, "cannot allocate memory for default keys"); fclose(f); - return 2; + return PM3_EMALLOC; } *keys = p; diff --git a/doc/cheatsheet.md b/doc/cheatsheet.md index dbd48d548..670ae1979 100644 --- a/doc/cheatsheet.md +++ b/doc/cheatsheet.md @@ -46,7 +46,7 @@ Reverse permute iClass master key ``` Options --- -r reverse permuted key +r reverse permuted key pm3 --> hf iclass permute r 3F90EBF0910F7B6F ``` @@ -166,7 +166,7 @@ p : EPURSE m : macs e : elite -pm3 --> hf iclass lookup u 010a0ffff7ff12e0 p feffffffffffffff m 66348979153c41b9 f dictionaries/iclass_default_keys.dic e +pm3 --> hf iclass lookup u 010a0ffff7ff12e0 p feffffffffffffff m 66348979153c41b9 f iclass_default_keys e ``` ## Mifare @@ -188,7 +188,7 @@ Check for default keys from local memory ``` Options --- -card memory : 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K +card memory : 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K m : use dictionary from flashmemory pm3 --> hf mf fchk 1 m @@ -245,7 +245,7 @@ pm3 --> hf mf eload 353C2AA6 pm3 --> hf mf eload 1 353C2AA6 ``` -Simulate Mifare +Simulate Mifare ``` u : (Optional) UID 4,7 or 10 bytes. If not specified, the UID 4B from emulator memory will be used @@ -285,10 +285,10 @@ Convert Site & Facility code to Wiegand ``` Options --- - -OEM : OEM number / site code -FC : facility code -CN : card number + +OEM : OEM number / site code +FC : facility code +CN : card number pm3 --> lf hid wiegand 0 56 150 ``` @@ -376,7 +376,7 @@ pm3 --> lf hitag 26 pm3 --> lf hitag 21 4D494B52 ``` -Sniff Hitag traffic +Sniff Hitag traffic ``` pm3 --> lf hitag sniff pm3 --> lf hitag list @@ -384,7 +384,7 @@ pm3 --> lf hitag list Simulate Hitag ``` -pm3 --> lf hitag sim c378181c_a8f7.ht2 +pm3 --> lf hitag sim c378181c_a8f7.ht2 ``` Write to Hitag block @@ -405,7 +405,7 @@ pm3 --> lf hitag writer 24 499602D2 1 00000000 Simulate Hitag2 sequence ``` pm3 --> lf hitag reader 21 56713368 -pm3 --> lf hitag sim c378181c_a8f7.ht2 +pm3 --> lf hitag sim c378181c_a8f7.ht2 ``` ## T55XX @@ -432,16 +432,16 @@ Set timings to default ``` Options --- -p : persist to flashmemory -z : Set default t55x7 timings (use p to save if required) +p : persist to flashmemory +z : Set default t55x7 timings (use p to save if required) pm3 --> lf t55xx deviceconfig z p ``` Write to T55xx block ``` -b : block number to write. Between 0-7 -d : 4 bytes of data to write (8 hex characters) +b : block number to write. Between 0-7 +d : 4 bytes of data to write (8 hex characters) pm3 --> lf t55xx wr b 0 d 00081040 ``` @@ -506,11 +506,11 @@ Load default keys into memory ``` Options --- -o : offset in memory -f : file name -m : upload 6 bytes keys (mifare key dictionary) -i : upload 8 bytes keys (iClass key dictionary) -t : upload 4 bytes keys (pwd dictionary) +o : offset in memory +f : file name +m : upload 6 bytes keys (mifare key dictionary) +i : upload 8 bytes keys (iClass key dictionary) +t : upload 4 bytes keys (pwd dictionary) pm3 --> mem load f mfc_default_keys m pm3 --> mem load f t55xx_default_pwds t @@ -522,7 +522,7 @@ pm3 --> mem load f iclass_default_keys i Upgrade Sim Module firmware ``` -pm3 --> sc upgrade f ../tools/simmodule/SIM011.BIN +pm3 --> sc upgrade f ../tools/simmodule/SIM011.BIN ``` ## Smart Card @@ -542,26 +542,26 @@ Set clock speed ``` Options --- -c : clockspeed (0 = 16MHz, 1=8MHz, 2=4MHz) - -pm3 --> sc setclock c 2 +c : clockspeed (0 = 16MHz, 1=8MHz, 2=4MHz) + +pm3 --> sc setclock c 2 ``` Send raw hex data ``` Options ---- -r : do not read response -a : active smartcard without select (reset sc module) -s : active smartcard with select (get ATR) -t : executes TLV decoder if it possible -0 : use protocol T=0 -d : bytes to send - -pm3 --> sc raw s 0 d 00a404000e315041592e5359532e4444463031 : 1PAY.SYS.DDF01 PPSE directory with get ATR -pm3 --> sc raw 0 d 00a404000e325041592e5359532e4444463031 : 2PAY.SYS.DDF01 PPSE directory -pm3 --> sc raw 0 t d 00a4040007a0000000041010 : Mastercard -pm3 --> sc raw 0 t d 00a4040007a0000000031010 : Visa +--- +r : do not read response +a : active smartcard without select (reset sc module) +s : active smartcard with select (get ATR) +t : executes TLV decoder if it possible +0 : use protocol T=0 +d : bytes to send + +pm3 --> sc raw s 0 d 00a404000e315041592e5359532e4444463031 : 1PAY.SYS.DDF01 PPSE directory with get ATR +pm3 --> sc raw 0 d 00a404000e325041592e5359532e4444463031 : 2PAY.SYS.DDF01 PPSE directory +pm3 --> sc raw 0 t d 00a4040007a0000000041010 : Mastercard +pm3 --> sc raw 0 t d 00a4040007a0000000031010 : Visa ```` Bruteforce SPI @@ -570,6 +570,6 @@ Options --- t : executes TLV decoder if it possible -pm3 --> sc brute +pm3 --> sc brute pm3 --> sc brute t ``` From 6ac9d2f0fbf5c20da4b22db6698f9e22c9ea006a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 13:46:53 +0200 Subject: [PATCH 107/347] lf t55xx chk: load dic with searchFile --- client/cmdlft55xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 058645320..80954dddb 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -206,7 +206,7 @@ static int usage_t55xx_chk() { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf t55xx chk m"); - PrintAndLogEx(NORMAL, " lf t55xx chk i dictionaries/t55xx_default_pwds.dic"); + PrintAndLogEx(NORMAL, " lf t55xx chk i t55xx_default_pwds"); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } From 7076df0e18455e21bb037abd89d039348934c235 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 13:53:23 +0200 Subject: [PATCH 108/347] hf mf chk/fchk: don't stop on line errors when parsing dict --- client/cmdhfmf.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index b2e4b9855..afb369de3 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1659,9 +1659,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { if (!isxdigit(buf[0])) { PrintAndLogEx(FAILED, "File content error. '" _YELLOW_("%s")"' must include 12 HEX symbols", buf); - free(keyBlock); - fclose(f); - return PM3_EFILE; + continue; } buf[12] = 0; @@ -1937,9 +1935,7 @@ static int CmdHF14AMfChk(const char *Cmd) { // codesmell, only checks first char? if (!isxdigit(buf[0])) { PrintAndLogEx(FAILED, "File content error. '" _YELLOW_("%s")"' must include 12 HEX symbols", buf); - free(keyBlock); - fclose(f); - return PM3_EFILE; + continue; } buf[12] = 0; From 1628ac8e6217a3dcf2690e885202bba077ca7023 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 13:55:42 +0200 Subject: [PATCH 109/347] revert temporarily hf iclass chk/lookup 2a1e6dff --- client/cmdhficlass.c | 48 ++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 862dad13c..51bc323fc 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -244,8 +244,8 @@ static int usage_hf_iclass_chk(void) { PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, " c credit key (if not use, default is debit)"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys"); - PrintAndLogEx(NORMAL, " hf iclass chk f iclass_default_keys e"); + PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic"); + PrintAndLogEx(NORMAL, " hf iclass chk f dictionaries/iclass_default_keys.dic e"); return PM3_SUCCESS;; } static int usage_hf_iclass_lookup(void) { @@ -260,8 +260,8 @@ static int usage_hf_iclass_lookup(void) { PrintAndLogEx(NORMAL, " r raw"); PrintAndLogEx(NORMAL, " e elite"); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys"); - PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f iclass_default_keys e"); + PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic"); + PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f dictionaries/iclass_default_keys.dic e"); return PM3_SUCCESS; } static int usage_hf_iclass_permutekey(void) { @@ -2059,9 +2059,9 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { // load keys into keyblock int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); - if (res != PM3_SUCCESS) { + if (res > 0) { free(keyBlock); - return res; + return PM3_EFILE; } pre = calloc(keycnt, sizeof(iclass_premac_t)); @@ -2312,33 +2312,33 @@ static int CmdHFiClassLookUp(const char *Cmd) { PrintAndLogEx(SUCCESS, "MAC_TAG | %s", sprint_hex(MAC_TAG, sizeof(MAC_TAG))); int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); - if (res != PM3_SUCCESS) { + if (res > 0) { free(keyBlock); - return res; + return 1; } //iclass_prekey_t prekey = calloc(keycnt, sizeof(iclass_prekey_t)); if (!prekey) { free(keyBlock); - return PM3_EMALLOC; + return 1; } - PrintAndLogEx(INFO, "Generating diversified keys and MAC"); + PrintAndLogEx(FAILED, "Generating diversified keys and MAC"); res = GenerateFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, prekey); - if (res != PM3_SUCCESS) { + if (res > 0) { free(keyBlock); free(prekey); - return PM3_ESOFT; + return 1; } - PrintAndLogEx(INFO, "Sorting"); + PrintAndLogEx(FAILED, "Sorting"); // sort mac list. qsort(prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32); //PrintPreCalc(prekey, keycnt); - PrintAndLogEx(INFO, "Searching"); + PrintAndLogEx(FAILED, "Searching"); iclass_prekey_t *item; iclass_prekey_t lookup; memcpy(lookup.mac, MAC_TAG, 4); @@ -2377,19 +2377,10 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { uint8_t *p; int keyitems = 0; - - char *dict_path; - int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic"); - if (res != PM3_SUCCESS) { - return res; + if (!(f = fopen(filename, "r"))) { + PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); + return 1; } - f = fopen(dict_path, "r"); - if (!f) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", dict_path); - free(dict_path); - return PM3_EFILE; - } - free(dict_path); while (fgets(buf, sizeof(buf), f)) { if (strlen(buf) < 16 || buf[15] == '\n') @@ -2405,8 +2396,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { // doesn't this only test first char only? if (!isxdigit(buf[0])) { PrintAndLogEx(ERR, "file content error. '%s' must include 16 HEX symbols", buf); - fclose(f); - return PM3_EFILE; + continue; } // null terminator (skip the rest of the line) @@ -2416,7 +2406,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { if (!p) { PrintAndLogEx(ERR, "cannot allocate memory for default keys"); fclose(f); - return PM3_EMALLOC; + return 2; } *keys = p; From 236c2eb1d067f93a9df1608ac8ecd41d18f9b69a Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Mon, 26 Aug 2019 14:29:21 +0200 Subject: [PATCH 110/347] Changed createKeyDump to a less generic name (createMfcKeyDump). --- client/cmdhfmf.c | 31 +++---------------------------- client/fileutils.c | 2 +- client/fileutils.h | 2 +- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 1fb2d48ff..33f29f4d5 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2059,7 +2059,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Transfere the found keys to the simulator and dump the keys and card data PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "Dumping the keys:"); - createKeyDump(sectors_cnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); + createMfcKeyDump(sectors_cnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); PrintAndLogEx(SUCCESS, "Transfering the found keys to the simulator memory (Cmd Error: 04 can occour, but this shouldn't be a problem)"); for (current_sector_i=0; current_sector_i < sectors_cnt; current_sector_i++) { @@ -2352,7 +2352,7 @@ out: if (createDumpFile) { fptr = GenerateFilename("hf-mf-", "-key.bin"); - createKeyDump(sectorsCnt, e_sector, fptr); + createMfcKeyDump(sectorsCnt, e_sector, fptr); } } @@ -2378,7 +2378,6 @@ static int CmdHF14AMfChk(const char *Cmd) { uint8_t keyType = 0; uint32_t keyitems = ARRAYLEN(g_mifare_default_keys); uint64_t key64 = 0; - uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; char *fptr; int clen = 0; int transferToEml = 0; @@ -2633,31 +2632,7 @@ out: if (createDumpFile) { fptr = GenerateFilename("hf-mf-", "-key.bin"); - if (fptr == NULL) { - free(keyBlock); - free(e_sector); - return PM3_EFILE; - } - - FILE *fkeys = fopen(fptr, "wb"); - if (fkeys == NULL) { - PrintAndLogEx(WARNING, "Could not create file " _YELLOW_("%s"), fptr); - free(keyBlock); - free(e_sector); - return PM3_EFILE; - } - PrintAndLogEx(INFO, "Printing keys to binary file " _YELLOW_("%s")"...", fptr); - - for (i = 0; i < SectorsCnt; i++) { - num_to_bytes(e_sector[i].Key[0], 6, tempkey); - fwrite(tempkey, 1, 6, fkeys); - } - for (i = 0; i < SectorsCnt; i++) { - num_to_bytes(e_sector[i].Key[1], 6, tempkey); - fwrite(tempkey, 1, 6, fkeys); - } - fclose(fkeys); - PrintAndLogEx(SUCCESS, "Found keys have been dumped to file " _YELLOW_("%s")". 0xffffffffffff has been inserted for unknown keys.", fptr); + createMfcKeyDump(SectorsCnt, e_sector, fptr); } free(keyBlock); diff --git a/client/fileutils.c b/client/fileutils.c index 124a51edc..3128fd451 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -293,7 +293,7 @@ out: return retval; } -int createKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char* fptr) { +int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char* fptr) { uint8_t tmpKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; int i; diff --git a/client/fileutils.h b/client/fileutils.h index 61b7b0468..c0dad645b 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -112,7 +112,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s * @param fptr string pointer to the filename * @return 0 for ok, 1 for failz */ -int createKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char* fptr); +int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char* fptr); /** STUB * @brief Utility function to load data from a binary file. This method takes a preferred name. From 917d76bcc1b3f3868387ec3602903abf32622d64 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Mon, 26 Aug 2019 14:58:24 +0200 Subject: [PATCH 111/347] Added changelog message for the autopwn feature. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8434cc84..253d981f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ 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... ## [unreleased][unreleased] - + - Add autopwn command to break mifare classic cards completely automatic (breaks all sector keys and dumps them and the card content) - Add Lua paths: look for scripts also in ~/.proxmark/lua{scripts,libs} and /usr/local/share/proxmark3/lua{scripts,libs} (@doegox) - Change Lua directory scripts/ to luascript/ (@doegox) - Change non-rdv4 PLATFORM must now use the generic PM3OTHER, simpler (@doegox) From bdd6ef98b5d4608fc413fe02e856646aba287b60 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 20:34:16 +0200 Subject: [PATCH 112/347] fix autopwn help --- client/cmdhfmf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 003fa0cf2..a1fe25457 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1689,7 +1689,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", ctmp); - usage_hf14_hardnested(); + usage_hf14_autopwn(); return 1; } cmdp++; From 1368595be11f8f035ea331b56457c4646b1251e3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 20:37:33 +0200 Subject: [PATCH 113/347] hf mf nested: swap loops for faster results (try harder to break keyA first) --- client/cmdhfmf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index a1fe25457..d3199c429 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1243,9 +1243,9 @@ static int CmdHF14AMfNested(const char *Cmd) { // int iterations = 0; bool calibrate = true; - for (int i = 0; i < MIFARE_SECTOR_RETRY; i++) { + for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) { for (uint8_t sectorNo = 0; sectorNo < SectorsCnt; ++sectorNo) { - for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) { + for (int i = 0; i < MIFARE_SECTOR_RETRY; i++) { if (e_sector[sectorNo].foundKey[trgKeyType]) continue; From d838c816014fe947803c2fdb5cf7a92f470d6247 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 20:57:23 +0200 Subject: [PATCH 114/347] hf mf attacks: rewordings --- client/cmdhfmf.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index d3199c429..26fffaf42 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -41,7 +41,7 @@ static int CmdHelp(const char *Cmd); static int usage_hf14_ice(void) { - PrintAndLogEx(NORMAL, "Usage: hf mf ice [l] [f] "); + PrintAndLogEx(NORMAL, "Usage: hf mf ice [l ] [f ]"); PrintAndLogEx(NORMAL, " h this help"); PrintAndLogEx(NORMAL, " l nonces to be collected"); PrintAndLogEx(NORMAL, " f save nonces to instead of hf-mf--nonces.bin"); @@ -53,7 +53,7 @@ static int usage_hf14_ice(void) { } static int usage_hf14_dump(void) { - PrintAndLogEx(NORMAL, "Usage: hf mf dump [card memory] k f "); + PrintAndLogEx(NORMAL, "Usage: hf mf dump [card memory] [k ] [f ]"); PrintAndLogEx(NORMAL, " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K"); PrintAndLogEx(NORMAL, " k : key filename, if no given, UID will be used as filename"); PrintAndLogEx(NORMAL, " f : data filename, if no given, UID will be used as filename"); @@ -65,7 +65,7 @@ static int usage_hf14_dump(void) { } static int usage_hf14_mifare(void) { - PrintAndLogEx(NORMAL, "Usage: hf mf darkside [h] "); + PrintAndLogEx(NORMAL, "Usage: hf mf darkside "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); PrintAndLogEx(NORMAL, " (Optional) target other block"); @@ -77,7 +77,7 @@ static int usage_hf14_mifare(void) { return 0; } static int usage_hf14_mfsim(void) { - PrintAndLogEx(NORMAL, "Usage: hf mf sim [h] u n [i] [x] [e] [v]"); + PrintAndLogEx(NORMAL, "Usage: hf mf sim [u ] [n ] [t] [a ] [s ] [i] [x] [e] [v]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); PrintAndLogEx(NORMAL, " u (Optional) UID 4,7 or 10bytes. If not specified, the UID 4b/7b from emulator memory will be used"); @@ -169,26 +169,26 @@ static int usage_hf14_hardnested(void) { static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, "Usage:"); PrintAndLogEx(NORMAL, " hf mf autopwn [k] "); - PrintAndLogEx(NORMAL, " [*] [f] .dic [s] [i] [l] [v]"); + PrintAndLogEx(NORMAL, " [* ] [f [.dic]] [s] [i ] [l] [v]"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Description:"); - PrintAndLogEx(NORMAL, " This command is used to automate the attack process on mifare classic nfc cards."); + PrintAndLogEx(NORMAL, " This command is used to automate the attack process on mifare classic cards."); PrintAndLogEx(NORMAL, " The program tries to identify the prng type and then automatically attack it with the best algorithm."); - PrintAndLogEx(NORMAL, " After the program is done, the keys and card data is dumped."); + PrintAndLogEx(NORMAL, " At the end, the keys and card data are dumped."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); - PrintAndLogEx(NORMAL, " f .dic dictionary file for key discovery (the file has to end in .dic) max 2000 entries allowed"); - PrintAndLogEx(NORMAL, " s slower acquisition (required by some non standard cards) for hardnested"); - PrintAndLogEx(NORMAL, " v verbose output (statistcs)"); + PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); + PrintAndLogEx(NORMAL, " f [.dic] dictionary file for key discovery (the file has to end in .dic, max 2000 entries allowed)"); + PrintAndLogEx(NORMAL, " s slower acquisition for hardnested (required by some non standard cards)"); + PrintAndLogEx(NORMAL, " v verbose output (statistics)"); PrintAndLogEx(NORMAL, " l legacy mode (use the slow mfchk for the key enumeration)"); - PrintAndLogEx(NORMAL, " * all sectors based on card memory, other values then below defaults to 1k"); + PrintAndLogEx(NORMAL, " * all sectors based on card memory. Default: 1K"); PrintAndLogEx(NORMAL, " * 0 = MINI(320 bytes)"); PrintAndLogEx(NORMAL, " * 1 = 1K"); PrintAndLogEx(NORMAL, " * 2 = 2K"); PrintAndLogEx(NORMAL, " * 4 = 4K"); - PrintAndLogEx(NORMAL, " i set type of SIMD instructions. Without this flag programs autodetect it. (for hardnested)"); + PrintAndLogEx(NORMAL, " i set type of SIMD instructions for hardnested. Default: autodetection."); PrintAndLogEx(NORMAL, " i 5 = AVX512"); PrintAndLogEx(NORMAL, " i 2 = AVX2"); PrintAndLogEx(NORMAL, " i a = AVX"); @@ -198,9 +198,9 @@ static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " hf mf autopwn"); - PrintAndLogEx(NORMAL, " hf mf autopwn * 1 f default_keys"); + PrintAndLogEx(NORMAL, " hf mf autopwn * 1 f mfc_default_keys"); PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF"); - PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 1 f default_keys"); + PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 1 f mfc_default_keys"); PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 4 i 5"); return 0; } @@ -2027,12 +2027,12 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } // Check if the key was found if (e_sector[current_sector_i].foundKey[current_key_type_i] != 0) { - PrintAndLogEx(SUCCESS, "[BROCKEN KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(SUCCESS, "[TESTING KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmp_key[0], tmp_key[1], tmp_key[2], tmp_key[3], tmp_key[4], tmp_key[5]); } else { - PrintAndLogEx(FAILED, "[BROCKEN KEY] Valid KEY NOT FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(FAILED, "[TESTING KEY] Valid KEY NOT FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), current_sector_i, current_key_type_i ? 'B' : 'A', tmp_key[0], tmp_key[1], tmp_key[2], tmp_key[3], tmp_key[4], tmp_key[5]); From 9c677e045e04224e00b036a15f407f34ff607b79 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 22:21:23 +0200 Subject: [PATCH 115/347] mf autopwn: try nested harder before hardnested; typos --- client/cmdhfmf.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 26fffaf42..32aa03c73 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1858,7 +1858,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { i2 ? 'B' : 'A', tmp_key[0], tmp_key[1], tmp_key[2], tmp_key[3], tmp_key[4], tmp_key[5]); - // Store vaild credentials for the nested / hardnested attack if none exist + // Store valid credentials for the nested / hardnested attack if none exist if (know_target_key == false) { num_to_bytes(e_sector[i].Key[i2], 6, key); know_target_key = true; @@ -1901,9 +1901,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { break; } num_to_bytes(key64, 6, key); - // Check if the darkside key is vaild + // Check if the darkside key is valid if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) != PM3_SUCCESS) { - PrintAndLogEx(FAILED, "The key generated by the darkside attack is not vaild!" + PrintAndLogEx(FAILED, "The key generated by the darkside attack is not valid!" _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), blockNo, keyType ? 'B' : 'A', @@ -1924,6 +1924,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { free(keyBlock); // Clear the needed variables num_to_bytes(0, 6, tmp_key); + bool nested_failed = false; // Iterate over each sector and key(A/B) for (current_sector_i=0; current_sector_i < sectors_cnt; current_sector_i++) { @@ -1958,7 +1959,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Use the nested / hardnested attack if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { - if (prng_type) { + if (prng_type && (! nested_failed)) { + uint8_t retries = 0; +tryNested: PrintAndLogEx(INFO, "[ NESTED ] Sector no:%3d, target key type:%c", current_sector_i, current_key_type_i ? 'B' : 'A'); @@ -1982,8 +1985,15 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { break; case -4 : //key not found calibrate = false; - PrintAndLogEx(FAILED, "Nested attack failed --> try hardnested instead!"); - goto tryHardnested; + // this can happen on some old cards, it's worth trying some more before switching to slower hardnested + if (retries++ < MIFARE_SECTOR_RETRY) { + PrintAndLogEx(FAILED, "Nested attack failed, trying again (%i/%i)", retries, MIFARE_SECTOR_RETRY); + goto tryNested; + } else { + PrintAndLogEx(FAILED, "Nested attack failed, moving to hardnested"); + nested_failed = true; + goto tryHardnested; + } break; case -5 : calibrate = false; @@ -1997,7 +2007,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { break; } } else { - tryHardnested: // If the nested attack failes then we try the hardnested attack +tryHardnested: // If the nested attack fails then we try the hardnested attack PrintAndLogEx(INFO, "[ HARDNESTED ] Sector no:%3d, target key type:%c, Slow: %s", current_sector_i, current_key_type_i ? 'B' : 'A', @@ -2061,7 +2071,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(INFO, "Dumping the keys:"); createMfcKeyDump(sectors_cnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); - PrintAndLogEx(SUCCESS, "Transfering the found keys to the simulator memory (Cmd Error: 04 can occour, but this shouldn't be a problem)"); + PrintAndLogEx(SUCCESS, "Transferring the found keys to the simulator memory (Cmd Error: 04 can occur, but this shouldn't be a problem)"); for (current_sector_i=0; current_sector_i < sectors_cnt; current_sector_i++) { mfEmlGetMem(block, current_sector_i, 1); if (e_sector[current_sector_i].foundKey[0]) From 16a7cfd7b2066c46ba2a6e527e4721677127a596 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 26 Aug 2019 22:28:39 +0200 Subject: [PATCH 116/347] make style (excepted cmdhficlass...) --- armsrc/mifarecmd.c | 6 +- armsrc/pcf7931.c | 3 +- client/cmdhfmf.c | 176 +++++++++++++++------------- client/fileutils.c | 18 ++- client/fileutils.h | 2 +- client/loclass/cipherutils.c | 2 +- client/loclass/elite_crack.c | 20 ++-- client/scripting.c | 4 +- tools/fpga_compress/fpga_compress.c | 4 +- 9 files changed, 120 insertions(+), 115 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 985a787ca..63cf1128d 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1992,9 +1992,9 @@ TEST2: int res = iso14443a_select_card(uid, NULL, &cuid, true, 0, true); if (res == 2) { - if (cuid == 0xAA55C396 ) { - isGen = GEN_UNFUSED; - goto OUT; + if (cuid == 0xAA55C396) { + isGen = GEN_UNFUSED; + goto OUT; } ReaderTransmit(rats, sizeof(rats), NULL); diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index 9f1283b8c..82865b311 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -232,8 +232,7 @@ void ReadPCF7931() { } Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors); - for (i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { print_result("got consecutive blocks", tmp_blocks[i], 16); } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 32aa03c73..0783f5d3f 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1601,7 +1601,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { uint8_t block[16] = {0x00}; uint8_t *dump; int bytes; - char* fnameptr = filename; + char *fnameptr = filename; // Settings bool slow = false; bool legacy_mfchk = false; @@ -1616,7 +1616,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { case 'h': return usage_hf14_autopwn(); case 'f': - if (param_getstr(Cmd, cmdp +1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { + if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "Filename too long"); } cmdp ++; @@ -1699,8 +1699,8 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { e_sector = calloc(sectors_cnt, sizeof(sector_t)); if (e_sector == NULL) return PM3_EMALLOC; // Clear the key storage datastructure - for (i=0; i just be nice and correct it ;) if (know_target_key == false) { num_to_bytes(e_sector[i].Key[i2], 6, key); know_target_key = true; - blockNo = i; keyType = i2; + blockNo = i; + keyType = i2; PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used for the nested / hardnested attack: sector:" - _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), - blockNo, - keyType ? 'B' : 'A', - key[0], key[1], key[2], key[3], key[4], key[5]); + _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + blockNo, + keyType ? 'B' : 'A', + key[0], key[1], key[2], key[3], key[4], key[5]); } - } + } } } } @@ -1793,24 +1794,25 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) { num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); } - key_cnt = ARRAYLEN(g_mifare_default_keys); - } - + key_cnt = ARRAYLEN(g_mifare_default_keys); + } + // Start the timer t1 = msclock(); // Use the dictionary to find sector keys on the card PrintAndLogEx(INFO, "Enumerating the card keys with the dictionary!"); if (legacy_mfchk) { - // Check all the sectors - for (i=0; i (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : key_cnt; bool firstChunk = true, lastChunk = false; @@ -1829,7 +1832,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); - i = key_cnt; strategy = 3; break; // Exit the loop + i = key_cnt; + strategy = 3; + break; // Exit the loop } uint32_t size = ((key_cnt - i) > chunksize) ? chunksize : key_cnt - i; // last chunk? @@ -1840,7 +1845,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { firstChunk = false; // all keys, aborted if (res == 0 || res == 2) { - i = key_cnt; strategy = 3; break; // Exit the loop + i = key_cnt; + strategy = 3; + break; // Exit the loop } } // end chunks of keys firstChunk = true; @@ -1849,25 +1856,26 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } // Analyse the dictionary attack - for (i=0; i The fast check --> mfCheckKeys_fast(sectors_cnt, true, true, 2, 1, tmp_key, e_sector, false); // Returns false keys, so we just stick to the slower mfchk. - for (i=0; id_name[0] != '.')) || (str_endswith(namelist[i]->d_name, ext))) { - PrintAndLogEx(NORMAL, "%s   %s── %-21s", last ? " ":"│", i == n-1 ? "└" : "├", namelist[i]->d_name); + PrintAndLogEx(NORMAL, "%s   %s── %-21s", last ? " " : "│", i == n - 1 ? "└" : "├", namelist[i]->d_name); } free(namelist[i]); } @@ -727,19 +727,17 @@ int searchAndList(const char *pm3dir, const char *ext) { } static int searchFinalFile(char **foundpath, const char *pm3dir, const char *searchname) { - if ((foundpath == NULL)||(pm3dir == NULL)||(searchname == NULL)) return PM3_ESOFT; + if ((foundpath == NULL) || (pm3dir == NULL) || (searchname == NULL)) return PM3_ESOFT; // explicit absolute (/) or relative path (./) => try only to match it directly char *filename = calloc(strlen(searchname) + 1, sizeof(char)); if (filename == NULL) return PM3_EMALLOC; strcpy(filename, searchname); if (((strlen(filename) > 1) && (filename[0] == '/')) || - ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) - { + ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) { if (fileExists(filename)) { *foundpath = filename; return PM3_SUCCESS; - } - else { + } else { goto out; } } diff --git a/client/fileutils.h b/client/fileutils.h index 25fe0a885..03a47112e 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -111,7 +111,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s * @param fptr string pointer to the filename * @return 0 for ok, 1 for failz */ -int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char* fptr); +int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char *fptr); /** STUB * @brief Utility function to load data from a binary file. This method takes a preferred name. diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index 52ac82f94..ee440fb73 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -160,7 +160,7 @@ void printarr(const char *name, uint8_t *arr, int len) { } void printvar(const char *name, uint8_t *arr, int len) { - PrintAndLogEx(NORMAL, "%s = " _YELLOW_("%s"), name, sprint_hex(arr, len) ); + PrintAndLogEx(NORMAL, "%s = " _YELLOW_("%s"), name, sprint_hex(arr, len)); } void printarr_human_readable(const char *title, uint8_t *arr, int len) { diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index 74ebfe608..69b17c50f 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -479,7 +479,7 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[]) { return 1; } else { PrintAndLogEx(NORMAL, "\n"); - PrintAndLogEx(SUCCESS, _GREEN_("Key verified ok!") ); + PrintAndLogEx(SUCCESS, _GREEN_("Key verified ok!")); } return 0; } @@ -502,18 +502,18 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { for (i = 0 ; i * itemsize < dumpsize ; i++) { memcpy(attack, dump + i * itemsize, itemsize); errors += bruteforceItem(*attack, keytable); - if ( errors ) - break; + if (errors) + break; } free(attack); t1 = msclock() - t1; PrintAndLogEx(SUCCESS, "time: %" PRIu64 " seconds", t1 / 1000); - - if ( errors ) { - PrintAndLogEx(ERR, "loclass exiting. Try run " _YELLOW_("`hf iclass sim 2`") "again and collect new data"); - return 1; - } + + if (errors) { + PrintAndLogEx(ERR, "loclass exiting. Try run " _YELLOW_("`hf iclass sim 2`") "again and collect new data"); + return 1; + } // Pick out the first 16 bytes of the keytable. // The keytable is now in 16-bit ints, where the upper 8 bits @@ -526,8 +526,8 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { if (!(keytable[i] & CRACKED)) { PrintAndLogEx(WARNING, "Warning: we are missing byte %d, custom key calculation will fail...", i); - return 1; - } + return 1; + } } errors += calculateMasterKey(first16bytes, NULL); return errors; diff --git a/client/scripting.c b/client/scripting.c index dc3051207..5a3eaed61 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1158,7 +1158,7 @@ int set_pm3_libraries(lua_State *L) { strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); - // from the ~/.proxmark3/lualib/ directory + // from the ~/.proxmark3/lualib/ directory char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, user_path); strcat(libraries_path, PM3_USER_DIRECTORY); @@ -1167,7 +1167,7 @@ int set_pm3_libraries(lua_State *L) { setLuaPath(L, libraries_path); } - if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_SUBDIR) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0 ) { + if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_SUBDIR) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0) { // from the /usr/local/share/proxmark3/luascripts/ directory char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, PM3_SHARE_PATH); diff --git a/tools/fpga_compress/fpga_compress.c b/tools/fpga_compress/fpga_compress.c index bac6a1670..54d2438d2 100644 --- a/tools/fpga_compress/fpga_compress.c +++ b/tools/fpga_compress/fpga_compress.c @@ -337,8 +337,8 @@ static int FpgaGatherVersion(FILE *infile, char *infile_name, char *dst, int len for (uint16_t i = 0; i < fpga_info_len; i++) { char c = (char)fgetc(infile); if (i < sizeof(tempstr)) { - if ( c == '/' ) c = '-'; - if ( c == ' ' ) c = '0'; + if (c == '/') c = '-'; + if (c == ' ') c = '0'; tempstr[i] = c; } } From 1e648088b1ed45b864ea566e9b9107d0670ec246 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Mon, 26 Aug 2019 21:24:29 +0200 Subject: [PATCH 117/347] Improved the help message of the autopwn command. --- client/cmdhfmf.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 0783f5d3f..af2db10ab 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -173,8 +173,7 @@ static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Description:"); PrintAndLogEx(NORMAL, " This command is used to automate the attack process on mifare classic cards."); - PrintAndLogEx(NORMAL, " The program tries to identify the prng type and then automatically attack it with the best algorithm."); - PrintAndLogEx(NORMAL, " At the end, the keys and card data are dumped."); + PrintAndLogEx(NORMAL, " It uses the darkside, nested and hardnested attack to extract the keys and card content."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); @@ -197,11 +196,10 @@ static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, " i n = none (use CPU regular instruction set)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf mf autopwn"); - PrintAndLogEx(NORMAL, " hf mf autopwn * 1 f mfc_default_keys"); - PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF"); - PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 1 f mfc_default_keys"); - PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 4 i 5"); + PrintAndLogEx(NORMAL, " hf mf autopwn -- attack a mifare classic card with the default keys"); + PrintAndLogEx(NORMAL, " hf mf autopwn * 1 f mfc_default_keys -- attack a mifare classic card (size 1K) with the default dictionary"); + PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF -- attack a mifare classic card with the known key 'FFFFFFFFFFFF' for sector 0 and key type A"); + PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 1 f mfc_default_keys -- this command combines the two above (reduce the need for nested / hardnested attacks, by using a dictionary)"); return 0; } static int usage_hf14_chk(void) { From 48d3802d3595dc223ee19f95074aca7cd8bdc27c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 27 Aug 2019 10:51:52 +0200 Subject: [PATCH 118/347] chg: optimization of iclass mac calculations on deviceside (@pwpiwi) see https://github.com/Proxmark/proxmark3/pull/861 chg: some textual --- CHANGELOG.md | 3 +- armsrc/frozen.c | 2 +- armsrc/optimized_cipher.c | 209 ++++++++++++++++++++--------------- armsrc/optimized_cipher.h | 2 +- client/loclass/elite_crack.c | 2 +- 5 files changed, 125 insertions(+), 93 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 253d981f7..e3db619fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ 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... ## [unreleased][unreleased] - - Add autopwn command to break mifare classic cards completely automatic (breaks all sector keys and dumps them and the card content) + - Chg optimization of iclass mac calculations on deviceside (@pwpiwi) + - Add 'hf mf autopwn' - Autopwn function for Mifare Classic, extract all keys and dump card memory (@matthiaskonrath) - Add Lua paths: look for scripts also in ~/.proxmark/lua{scripts,libs} and /usr/local/share/proxmark3/lua{scripts,libs} (@doegox) - Change Lua directory scripts/ to luascript/ (@doegox) - Change non-rdv4 PLATFORM must now use the generic PM3OTHER, simpler (@doegox) diff --git a/armsrc/frozen.c b/armsrc/frozen.c index 220f51d6c..a43300319 100644 --- a/armsrc/frozen.c +++ b/armsrc/frozen.c @@ -44,7 +44,7 @@ int cs_win_snprintf(char *str, size_t size, const char *format, ...); int cs_win_vsnprintf(char *str, size_t size, const char *format, va_list ap); #if _MSC_VER >= 1700 -#include +#include "stdint.h" #else typedef _int64 int64_t; typedef unsigned _int64 uint64_t; diff --git a/armsrc/optimized_cipher.c b/armsrc/optimized_cipher.c index 4894bf6bc..b03facf93 100644 --- a/armsrc/optimized_cipher.c +++ b/armsrc/optimized_cipher.c @@ -60,11 +60,59 @@ -- MHS 2015 **/ +/** + + The runtime of opt_doTagMAC_2() with the MHS optimized version was 403 microseconds on Proxmark3. + This was still to slow for some newer readers which didn't want to wait that long. + + Further optimizations to speedup the MAC calculations: + * Optimized opt_Tt logic + * Look up table for opt_select + * Removing many unnecessary bit maskings (& 0x1) + * updating state in place instead of alternating use of a second state structure + * remove the necessity to reverse bits of input and output bytes + + opt_doTagMAC_2() now completes in 270 microseconds. + + -- piwi 2019 +**/ + #include "optimized_cipher.h" -#define opt_T(s) (0x1 & ((s->t >> 15) ^ (s->t >> 14)^ (s->t >> 10)^ (s->t >> 8)^ (s->t >> 5)^ (s->t >> 4)^ (s->t >> 1)^ s->t)) +static const uint8_t opt_select_LUT[256] = { + 00, 03, 02, 01, 02, 03, 00, 01, 04, 07, 07, 04, 06, 07, 05, 04, + 01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04, + 06, 05, 04, 07, 04, 05, 06, 07, 06, 05, 05, 06, 04, 05, 07, 06, + 07, 04, 05, 06, 04, 05, 06, 07, 07, 04, 04, 07, 04, 05, 07, 06, + 06, 05, 04, 07, 04, 05, 06, 07, 02, 01, 01, 02, 00, 01, 03, 02, + 03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06, + 00, 03, 02, 01, 02, 03, 00, 01, 00, 03, 03, 00, 02, 03, 01, 00, + 05, 06, 07, 04, 06, 07, 04, 05, 05, 06, 06, 05, 06, 07, 05, 04, + 02, 01, 00, 03, 00, 01, 02, 03, 06, 05, 05, 06, 04, 05, 07, 06, + 03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06, + 02, 01, 00, 03, 00, 01, 02, 03, 02, 01, 01, 02, 00, 01, 03, 02, + 03, 00, 01, 02, 00, 01, 02, 03, 03, 00, 00, 03, 00, 01, 03, 02, + 04, 07, 06, 05, 06, 07, 04, 05, 00, 03, 03, 00, 02, 03, 01, 00, + 01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04, + 04, 07, 06, 05, 06, 07, 04, 05, 04, 07, 07, 04, 06, 07, 05, 04, + 01, 02, 03, 00, 02, 03, 00, 01, 01, 02, 02, 01, 02, 03, 01, 00 +}; -#define opt_B(s) (((s->b >> 6) ^ (s->b >> 5) ^ (s->b >> 4) ^ (s->b)) & 0x1) +/********************** the table above has been generated with this code: ******** +#include "util.h" +static void init_opt_select_LUT(void) { + for (int r = 0; r < 256; r++) { + uint8_t r_ls2 = r << 2; + uint8_t r_and_ls2 = r & r_ls2; + uint8_t r_or_ls2 = r | r_ls2; + uint8_t z0 = (r_and_ls2 >> 5) ^ ((r & ~r_ls2) >> 4) ^ ( r_or_ls2 >> 3); + uint8_t z1 = (r_or_ls2 >> 6) ^ ( r_or_ls2 >> 1) ^ (r >> 5) ^ r; + uint8_t z2 = ((r & ~r_ls2) >> 4) ^ (r_and_ls2 >> 3) ^ r; + opt_select_LUT[r] = (z0 & 4) | (z1 & 2) | (z2 & 1); + } + print_result("", opt_select_LUT, 256); +} +***********************************************************************************/ #define opt__select(x,y,r) (4 & (((r & (r << 2)) >> 5) ^ ((r & ~(r << 2)) >> 4) ^ ( (r | r << 2) >> 3)))\ |(2 & (((r | r << 2) >> 6) ^ ( (r | r << 2) >> 1) ^ (r >> 5) ^ r ^ ((x^y) << 1)))\ @@ -74,9 +122,6 @@ * Some background on the expression above can be found here... uint8_t xopt__select(bool x, bool y, uint8_t r) { - uint8_t r_ls2 = r << 2; - uint8_t r_and_ls2 = r & r_ls2; - uint8_t r_or_ls2 = r | r_ls2; //r: r0 r1 r2 r3 r4 r5 r6 r7 //r_ls2: r2 r3 r4 r5 r6 r7 0 0 @@ -96,82 +141,95 @@ uint8_t xopt__select(bool x, bool y, uint8_t r) } */ -void opt_successor(const uint8_t *k, State *s, bool y, State *successor) { - uint8_t Tt = 1 & opt_T(s); +static void opt_successor(const uint8_t *k, State *s, uint8_t y) { +// #define opt_T(s) (0x1 & ((s->t >> 15) ^ (s->t >> 14) ^ (s->t >> 10) ^ (s->t >> 8) ^ (s->t >> 5) ^ (s->t >> 4)^ (s->t >> 1) ^ s->t)) + // uint8_t Tt = opt_T(s); + uint16_t Tt = s->t & 0xc533; + Tt = Tt ^ (Tt >> 1); + Tt = Tt ^ (Tt >> 4); + Tt = Tt ^ (Tt >> 10); + Tt = Tt ^ (Tt >> 8); - successor->t = (s->t >> 1); - successor->t |= (Tt ^ (s->r >> 7 & 0x1) ^ (s->r >> 3 & 0x1)) << 15; + s->t = (s->t >> 1); + s->t |= (Tt ^ (s->r >> 7) ^ (s->r >> 3)) << 15; - successor->b = s->b >> 1; - successor->b |= (opt_B(s) ^ (s->r & 0x1)) << 7; + uint8_t opt_B = s->b; + opt_B ^= s->b >> 6; + opt_B ^= s->b >> 5; + opt_B ^= s->b >> 4; - successor->r = (k[opt__select(Tt, y, s->r)] ^ successor->b) + s->l ; - successor->l = successor->r + s->r; + s->b = s->b >> 1; + s->b |= (opt_B ^ s->r) << 7; + + uint8_t opt_select = opt_select_LUT[s->r] & 0x04; + opt_select |= (opt_select_LUT[s->r] ^ ((Tt ^ y) << 1)) & 0x02; + opt_select |= (opt_select_LUT[s->r] ^ Tt) & 0x01; + + uint8_t r = s->r; + s->r = (k[opt_select] ^ s->b) + s->l ; + s->l = s->r + r; } -void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) { - State x2; +static void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) { for (int i = 0; i < length; i++) { uint8_t head; - head = 1 & (in[i] >> 7); - opt_successor(k, s, head, &x2); + head = in[i]; + opt_successor(k, s, head); - head = 1 & (in[i] >> 6); - opt_successor(k, &x2, head, s); + head >>= 1; + opt_successor(k, s, head); - head = 1 & (in[i] >> 5); - opt_successor(k, s, head, &x2); + head >>= 1; + opt_successor(k, s, head); - head = 1 & (in[i] >> 4); - opt_successor(k, &x2, head, s); + head >>= 1; + opt_successor(k, s, head); - head = 1 & (in[i] >> 3); - opt_successor(k, s, head, &x2); + head >>= 1; + opt_successor(k, s, head); - head = 1 & (in[i] >> 2); - opt_successor(k, &x2, head, s); + head >>= 1; + opt_successor(k, s, head); - head = 1 & (in[i] >> 1); - opt_successor(k, s, head, &x2); + head >>= 1; + opt_successor(k, s, head); - head = 1 & in[i]; - opt_successor(k, &x2, head, s); + head >>= 1; + opt_successor(k, s, head); } - //For tag MAC, an additional 32 zeroes if (add32Zeroes) { for (int i = 0; i < 16; i++) { - opt_successor(k, s, 0, &x2); - opt_successor(k, &x2, 0, s); + opt_successor(k, s, 0); + opt_successor(k, s, 0); } } } -void opt_output(const uint8_t *k, State *s, uint8_t *buffer) { - State temp = {0, 0, 0, 0}; +static void opt_output(const uint8_t *k, State *s, uint8_t *buffer) { for (uint8_t times = 0; times < 4; times++) { uint8_t bout = 0; - bout |= (s->r & 0x4) << 5; - opt_successor(k, s, 0, &temp); - bout |= (temp.r & 0x4) << 4; - opt_successor(k, &temp, 0, s); - bout |= (s->r & 0x4) << 3; - opt_successor(k, s, 0, &temp); - bout |= (temp.r & 0x4) << 2; - opt_successor(k, &temp, 0, s); - bout |= (s->r & 0x4) << 1; - opt_successor(k, s, 0, &temp); - bout |= (temp.r & 0x4) ; - opt_successor(k, &temp, 0, s); + bout |= (s->r & 0x4) >> 2; + opt_successor(k, s, 0); bout |= (s->r & 0x4) >> 1; - opt_successor(k, s, 0, &temp); - bout |= (temp.r & 0x4) >> 2; - opt_successor(k, &temp, 0, s); + opt_successor(k, s, 0); + bout |= (s->r & 0x4); + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 1; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 2; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 3; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 4; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 5; + opt_successor(k, s, 0); buffer[times] = bout; } } -void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) { +static void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) { State _init = { ((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l ((k[0] ^ 0x4c) + 0x21) & 0xFF,// r @@ -183,45 +241,25 @@ void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) { opt_output(k, &_init, out); } -uint8_t rev_byte(uint8_t b) { - b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; - b = (b & 0xCC) >> 2 | (b & 0x33) << 2; - b = (b & 0xAA) >> 1 | (b & 0x55) << 1; - return b; -} - -void opt_reverse_arraybytecpy(uint8_t *dest, uint8_t *src, size_t len) { - uint8_t i; - for (i = 0; i < len ; i++) - dest[i] = rev_byte(src[i]); -} - void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) { - static uint8_t cc_nr[12]; - opt_reverse_arraybytecpy(cc_nr, cc_nr_p, 12); uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0}; - opt_MAC(div_key_p, cc_nr, dest); - //The output MAC must also be reversed - opt_reverse_arraybytecpy(mac, dest, 4); + opt_MAC(div_key_p, cc_nr_p, dest); + memcpy(mac, dest, 4); return; } + void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) { - static uint8_t cc_nr[8 + 4 + 4]; - opt_reverse_arraybytecpy(cc_nr, cc_p, 12); State _init = { ((div_key_p[0] ^ 0x4c) + 0xEC) & 0xFF,// l ((div_key_p[0] ^ 0x4c) + 0x21) & 0xFF,// r 0x4c, // b 0xE012 // t }; - opt_suc(div_key_p, &_init, cc_nr, 12, true); - uint8_t dest [] = {0, 0, 0, 0}; - opt_output(div_key_p, &_init, dest); - //The output MAC must also be reversed - opt_reverse_arraybytecpy(mac, dest, 4); + opt_suc(div_key_p, &_init, cc_p, 12, true); + opt_output(div_key_p, &_init, mac); return; - } + /** * The tag MAC can be divided (both can, but no point in dividing the reader mac) into * two functions, since the first 8 bytes are known, we can pre-calculate the state @@ -231,17 +269,16 @@ void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) { * @return the cipher state */ State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) { - static uint8_t cc_nr[8]; - opt_reverse_arraybytecpy(cc_nr, cc_p, 8); State _init = { ((div_key_p[0] ^ 0x4c) + 0xEC) & 0xFF,// l ((div_key_p[0] ^ 0x4c) + 0x21) & 0xFF,// r 0x4c, // b 0xE012 // t }; - opt_suc(div_key_p, &_init, cc_nr, 8, false); + opt_suc(div_key_p, &_init, cc_p, 8, false); return _init; } + /** * The second part of the tag MAC calculation, since the CC is already calculated into the state, * this function is fed only the NR, and internally feeds the remaining 32 0-bits to generate the tag @@ -252,13 +289,7 @@ State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) { * @param div_key_p - the key to use */ void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p) { - static uint8_t _nr[4]; - opt_reverse_arraybytecpy(_nr, nr, 4); - opt_suc(div_key_p, &_init, _nr, 4, true); - - uint8_t dest [] = {0, 0, 0, 0}; - opt_output(div_key_p, &_init, dest); - //The output MAC must also be reversed - opt_reverse_arraybytecpy(mac, dest, 4); + opt_suc(div_key_p, &_init, nr, 4, true); + opt_output(div_key_p, &_init, mac); return; } diff --git a/armsrc/optimized_cipher.h b/armsrc/optimized_cipher.h index 893297ddd..c6df25ab8 100644 --- a/armsrc/optimized_cipher.h +++ b/armsrc/optimized_cipher.h @@ -2,7 +2,7 @@ #define OPTIMIZED_CIPHER_H #include "common.h" - +#include "string.h" /** * Definition 1 (Cipher state). A cipher state of iClass s is an element of F 40/2 * consisting of the following four components: diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index 69b17c50f..adf87fb89 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -475,7 +475,7 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[]) { memcpy(master_key, key64, 8); if (memcmp(z_0, result, 4) != 0) { - PrintAndLogEx(WARNING, "Failed to verify calculated master key (k_cus)! Something is wrong."); + PrintAndLogEx(WARNING, _RED_("Failed to verify") "calculated master key (k_cus)! Something is wrong."); return 1; } else { PrintAndLogEx(NORMAL, "\n"); From 703329faca57d8f115ab94d8c31dbe02b321508b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 27 Aug 2019 11:08:03 +0200 Subject: [PATCH 119/347] chg: add used known key to found list :) --- client/cmdhfmf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index af2db10ab..d2004d142 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -751,7 +751,12 @@ static uint8_t NumBlocksPerSector(uint8_t sectorNo) { return 16; } } - +static uint8_t GetSectorFromBlockNo(uint8_t blockNo) { + if ( blockNo < 128 ) + return blockNo / 4; + else + return 32 + ((128 - blockNo) / 16); +} static int CmdHF14AMfDump(const char *Cmd) { uint64_t t1 = msclock(); @@ -1222,6 +1227,10 @@ static int CmdHF14AMfNested(const char *Cmd) { e_sector = calloc(SectorsCnt, sizeof(sector_t)); if (e_sector == NULL) return PM3_EMALLOC; + // add our known key + e_sector[GetSectorFromBlockNo(blockNo)].foundKey[keyType] = 1; + e_sector[GetSectorFromBlockNo(blockNo)].Key[keyType] = key64; + //test current key and additional standard keys first // add parameter key memcpy(keyBlock + (ARRAYLEN(g_mifare_default_keys) * 6), key, 6); From 13aa4ee6ab9fd761e2704b4b8e6565588557f562 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 27 Aug 2019 17:15:42 +0200 Subject: [PATCH 120/347] fix: cleaning up 'hf mf autopwn' - reused the fix from below aswell. Add: 'hf mf dump' rename filenames (@mohemiv) see https://github.com/RfidResearchGroup/proxmark3/pull/360 --- client/cmdhfmf.c | 294 ++++++++++++++++++++++++----------------------- 1 file changed, 153 insertions(+), 141 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index d2004d142..030da5a8d 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -172,21 +172,21 @@ static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, " [* ] [f [.dic]] [s] [i ] [l] [v]"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Description:"); - PrintAndLogEx(NORMAL, " This command is used to automate the attack process on mifare classic cards."); + PrintAndLogEx(NORMAL, " This command automates the key recovery process on Mifare classic cards."); PrintAndLogEx(NORMAL, " It uses the darkside, nested and hardnested attack to extract the keys and card content."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " k if a known key for a block is supplied"); - PrintAndLogEx(NORMAL, " f [.dic] dictionary file for key discovery (the file has to end in .dic, max 2000 entries allowed)"); + PrintAndLogEx(NORMAL, " k known key is supplied"); + PrintAndLogEx(NORMAL, " f [.dic] key dictionary file"); PrintAndLogEx(NORMAL, " s slower acquisition for hardnested (required by some non standard cards)"); PrintAndLogEx(NORMAL, " v verbose output (statistics)"); - PrintAndLogEx(NORMAL, " l legacy mode (use the slow mfchk for the key enumeration)"); - PrintAndLogEx(NORMAL, " * all sectors based on card memory. Default: 1K"); + PrintAndLogEx(NORMAL, " l legacy mode (use the slow 'mf chk' for the key enumeration)"); + PrintAndLogEx(NORMAL, " * all sectors based on card memory"); PrintAndLogEx(NORMAL, " * 0 = MINI(320 bytes)"); - PrintAndLogEx(NORMAL, " * 1 = 1K"); - PrintAndLogEx(NORMAL, " * 2 = 2K"); - PrintAndLogEx(NORMAL, " * 4 = 4K"); + PrintAndLogEx(NORMAL, " * 1 = 1k (default)"); + PrintAndLogEx(NORMAL, " * 2 = 2k"); + PrintAndLogEx(NORMAL, " * 4 = 4k"); PrintAndLogEx(NORMAL, " i set type of SIMD instructions for hardnested. Default: autodetection."); PrintAndLogEx(NORMAL, " i 5 = AVX512"); PrintAndLogEx(NORMAL, " i 2 = AVX2"); @@ -196,9 +196,9 @@ static int usage_hf14_autopwn(void) { PrintAndLogEx(NORMAL, " i n = none (use CPU regular instruction set)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf mf autopwn -- attack a mifare classic card with the default keys"); - PrintAndLogEx(NORMAL, " hf mf autopwn * 1 f mfc_default_keys -- attack a mifare classic card (size 1K) with the default dictionary"); - PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF -- attack a mifare classic card with the known key 'FFFFFFFFFFFF' for sector 0 and key type A"); + PrintAndLogEx(NORMAL, " hf mf autopwn -- target Mifare classic card with default keys"); + PrintAndLogEx(NORMAL, " hf mf autopwn * 1 f mfc_default_keys -- target Mifare classic card (size 1k) with default dictionary"); + PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF -- target Mifare classic card with Sector0 typeA with known key 'FFFFFFFFFFFF'"); PrintAndLogEx(NORMAL, " hf mf autopwn k 0 A FFFFFFFFFFFF * 1 f mfc_default_keys -- this command combines the two above (reduce the need for nested / hardnested attacks, by using a dictionary)"); return 0; } @@ -963,9 +963,11 @@ static int CmdHF14AMfDump(const char *Cmd) { PrintAndLogEx(SUCCESS, "\nSucceded in dumping all blocks"); if (strlen(dataFilename) < 1) { - fptr = dataFilename; - fptr += sprintf(fptr, "hf-mf-"); - FillFileNameByUID(fptr, (uint8_t *)carddata, "-data", 4); + fptr = GenerateFilename("hf-mf-", "-data"); + if (fptr == NULL) + return PM3_ESOFT; + + strcpy(dataFilename, fptr); } uint16_t bytes = 16 * (FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1)); @@ -1575,7 +1577,6 @@ static int CmdHF14AMfNestedHard(const char *Cmd) { return 0; } - static int CmdHF14AMfAutoPWN(const char *Cmd) { // Nested and Hardnested parameter uint8_t blockNo = 0; @@ -1601,8 +1602,6 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Nested and Hardnested returned status uint64_t foundkey = 0; int16_t isOK = 0; - // Loop counter - int i, i2, i3; int current_sector_i = 0, current_key_type_i = 0; // Dumping and transfere to simulater memory uint8_t block[16] = {0x00}; @@ -1644,14 +1643,14 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Get the known block number if (param_getchar(Cmd, cmdp + 1) == 0x00) { PrintAndLogEx(WARNING, "Sector number is missing"); - return 1; + return PM3_EINVARG; } blockNo = param_get8(Cmd, cmdp + 1); // Get the knonwn block type ctmp = tolower(param_getchar(Cmd, cmdp + 2)); if (ctmp != 'a' && ctmp != 'b') { PrintAndLogEx(WARNING, "Key type must be A or B"); - return 1; + return PM3_EINVARG; } if (ctmp != 'a') { keyType = 1; @@ -1659,7 +1658,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Get the known block key if (param_gethex(Cmd, cmdp + 3, key, 12)) { PrintAndLogEx(WARNING, "Key must include 12 HEX symbols"); - return 1; + return PM3_EINVARG; } know_target_key = true; cmdp += 3; @@ -1690,14 +1689,13 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { break; default: PrintAndLogEx(WARNING, "Unknown SIMD type. %c", ctmp); - return 1; + return PM3_EINVARG; } cmdp += 2; break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", ctmp); - usage_hf14_autopwn(); - return 1; + return usage_hf14_autopwn(); } cmdp++; } @@ -1705,74 +1703,82 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Create the key storage stucture e_sector = calloc(sectors_cnt, sizeof(sector_t)); if (e_sector == NULL) return PM3_EMALLOC; - // Clear the key storage datastructure - for (i = 0; i < sectors_cnt; i++) { - for (i2 = 0; i2 < 2; i2++) { - e_sector[i].Key[i2] = 0; - e_sector[i].foundKey[i2] = 0; + + // clear the key storage + for (int i = 0; i < sectors_cnt; i++) { + for (int j = 0; j < 2; j++) { + e_sector[i].Key[j] = 0; + e_sector[i].foundKey[j] = 0; } } - // Get the card prng type (weak=true / hard=false) + // card prng type (weak=true / hard=false) prng_type = detect_classic_prng(); - // Print operating parameters + // print parameters if (verbose) { - PrintAndLogEx(INFO, "[ SETTINGS ] Card sectors .. " _YELLOW_("%d"), sectors_cnt); - PrintAndLogEx(INFO, "[ SETTINGS ] Key supplied .. " _YELLOW_("%s"), know_target_key ? "True" : "False"); - PrintAndLogEx(INFO, "[ SETTINGS ] Known sector .. " _YELLOW_("%d"), blockNo); - PrintAndLogEx(INFO, "[ SETTINGS ] Keytype ....... " _YELLOW_("%c"), keyType ? 'B' : 'A'); - PrintAndLogEx(INFO, "[ SETTINGS ] Kown key ...... " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), key[0], key[1], key[2], key[3], key[4], key[5]); - PrintAndLogEx(INFO, "[ SETTINGS ] Card PRNG ..... " _YELLOW_("%s"), prng_type ? "WEAK" : "HARD"); - PrintAndLogEx(INFO, "[ SETTINGS ] Dictionary .... " _YELLOW_("%s"), strlen(filename) ? filename : "NONE"); - PrintAndLogEx(INFO, "[ SETTINGS ] Legacy mode ... " _YELLOW_("%s"), legacy_mfchk ? "True" : "False"); + PrintAndLogEx(INFO, " card sectors .. " _YELLOW_("%d"), sectors_cnt); + PrintAndLogEx(INFO, " key supplied .. " _YELLOW_("%s"), know_target_key ? "True" : "False"); + PrintAndLogEx(INFO, " known sector .. " _YELLOW_("%d"), blockNo); + PrintAndLogEx(INFO, " keytype ....... " _YELLOW_("%c"), keyType ? 'B' : 'A'); + PrintAndLogEx(INFO, " known key ..... " _YELLOW_("%s"), sprint_hex(key, sizeof(key))); + PrintAndLogEx(INFO, " card PRNG ..... " _YELLOW_("%s"), prng_type ? "WEAK" : "HARD"); + PrintAndLogEx(INFO, " dictionary .... " _YELLOW_("%s"), strlen(filename) ? filename : "NONE"); + PrintAndLogEx(INFO, " legacy mode ... " _YELLOW_("%s"), legacy_mfchk ? "True" : "False"); } - // Check the user supplied key + // Start the timer + t1 = msclock(); + + // check the user supplied key if (know_target_key == false) - PrintAndLogEx(WARNING, "No known key was supplied, the following attacks might fail!"); + PrintAndLogEx(WARNING, "No known key was supplied, key recovery might fail"); else { if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) == PM3_SUCCESS) { - PrintAndLogEx(INFO, "[ SETTINGS ] The following key will be used for the nested / hardnested attack: sector:" - _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(INFO, "Using key for the nested / hardnested | sector:" + _RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), blockNo, keyType ? 'B' : 'A', - key[0], key[1], key[2], key[3], key[4], key[5]); + sprint_hex(key, sizeof(key)) + ); // Store the key for the nested / hardnested attack (if supplied by the user) e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); e_sector[blockNo].foundKey[keyType] = 3; } else { know_target_key = false; - PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("%s"), blockNo, keyType ? 'B' : 'A', - key[0], key[1], key[2], key[3], key[4], key[5]); - PrintAndLogEx(WARNING, "Let's see if just the sector or key type are not correct, and then we also give the dictionary a try ;)"); + sprint_hex(key, sizeof(key)) + ); + PrintAndLogEx(WARNING, "Falling back to dictionary"); } // Check if the user supplied key is used by other sectors - for (i = 0; i < sectors_cnt; i++) { - for (i2 = 0; i2 < 2; i2++) { - if (e_sector[i].foundKey[i2] == 0) { - if (mfCheckKeys(FirstBlockOfSector(i), i2, true, 1, key, &key64) == PM3_SUCCESS) { - e_sector[i].Key[i2] = bytes_to_num(key, 6); - e_sector[i].foundKey[i2] = 4; - PrintAndLogEx(SUCCESS, "[ REUSED KEY ] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + for (int i = 0; i < sectors_cnt; i++) { + for (int j = 0; j < 2; j++) { + if (e_sector[i].foundKey[j] == 0) { + if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, key, &key64) == PM3_SUCCESS) { + e_sector[i].Key[j] = bytes_to_num(key, 6); + e_sector[i].foundKey[j] = 4; + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), i, - i2 ? 'B' : 'A', - key[0], key[1], key[2], key[3], key[4], key[5]); + j ? 'B' : 'A', + sprint_hex(key, sizeof(key)) + ); // If the user supplied secctor / keytype was wrong --> just be nice and correct it ;) if (know_target_key == false) { - num_to_bytes(e_sector[i].Key[i2], 6, key); + num_to_bytes(e_sector[i].Key[j], 6, key); know_target_key = true; blockNo = i; - keyType = i2; - PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used for the nested / hardnested attack: sector:" - _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + keyType = j; + PrintAndLogEx(SUCCESS, "using key nested / hardnested attack: sector:" + _RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), blockNo, keyType ? 'B' : 'A', - key[0], key[1], key[2], key[3], key[4], key[5]); + sprint_hex(key, sizeof(key)) + ); } } } @@ -1786,16 +1792,17 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { loadFileDICTIONARY(filename, keyBlock, &data_length, 6, &key_cnt); if ((data_length / 6) > max_dictionary_size) { // This is not a good solution (loadFileDICTIONARY needs a maxdatalen)! - PrintAndLogEx(FAILED, "The loaded dictionary is too large: %d (allowed: %d)", data_length, max_dictionary_size); - free(keyBlock); // This won't work too well, because data on the stack is already overflown !!! + // loadfiledictionary will reallocate to correct size. + PrintAndLogEx(FAILED, "Dictionary is too large: %d (allowed: %d)", data_length, max_dictionary_size); + free(keyBlock); free(e_sector); - return 1; + return PM3_EMALLOC; } } else { keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); if (keyBlock == NULL) { free(e_sector); - return 1; + return PM3_EMALLOC; } for (int cnt = 0; cnt < ARRAYLEN(g_mifare_default_keys); cnt++) { @@ -1804,23 +1811,21 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { key_cnt = ARRAYLEN(g_mifare_default_keys); } - // Start the timer - t1 = msclock(); - // Use the dictionary to find sector keys on the card - PrintAndLogEx(INFO, "Enumerating the card keys with the dictionary!"); + PrintAndLogEx(INFO, "Enter dictionary run..."); + if (legacy_mfchk) { // Check all the sectors - for (i = 0; i < sectors_cnt; i++) { - for (i2 = 0; i2 < 2; i2++) { + for (int i = 0; i < sectors_cnt; i++) { + for (int j = 0; j < 2; j++) { // Check if the key is known - if (e_sector[i].foundKey[i2] == 0) { - for (i3 = 0; i3 < key_cnt; i3++) { + if (e_sector[i].foundKey[j] == 0) { + for (int k = 0; k < key_cnt; k++) { printf("."); fflush(stdout); - if (mfCheckKeys(FirstBlockOfSector(i), i2, true, 1, (keyBlock + (6 * i3)), &key64) == PM3_SUCCESS) { - e_sector[i].Key[i2] = bytes_to_num((keyBlock + (6 * i3)), 6); - e_sector[i].foundKey[i2] = 1; + if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, (keyBlock + (6 * k)), &key64) == PM3_SUCCESS) { + e_sector[i].Key[j] = bytes_to_num((keyBlock + (6 * k)), 6); + e_sector[i].foundKey[j] = 1; break; } } @@ -1835,7 +1840,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { for (uint8_t strategy = 1; strategy < 3; strategy++) { PrintAndLogEx(INFO, "Running strategy %u", strategy); // main keychunk loop - for (i = 0; i < key_cnt; i += chunksize) { + for (int i = 0; i < key_cnt; i += chunksize) { if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard!\n"); @@ -1847,6 +1852,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // last chunk? if (size == key_cnt - i) lastChunk = true; + int res = mfCheckKeys_fast(sectors_cnt, firstChunk, lastChunk, strategy, size, keyBlock + (i * 6), e_sector, false); if (firstChunk) firstChunk = false; @@ -1863,26 +1869,28 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } // Analyse the dictionary attack - for (i = 0; i < sectors_cnt; i++) { - for (i2 = 0; i2 < 2; i2++) { - if (e_sector[i].foundKey[i2] == 1) { - num_to_bytes(e_sector[i].Key[i2], 6, tmp_key); - PrintAndLogEx(SUCCESS, "[ DICT. KEY ] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + for (int i = 0; i < sectors_cnt; i++) { + for (int j = 0; j < 2; j++) { + if (e_sector[i].foundKey[j] == 1) { + num_to_bytes(e_sector[i].Key[j], 6, tmp_key); + PrintAndLogEx(SUCCESS, "Found valid key: sector:%3d key type:%c key: " _YELLOW_("%s"), i, - i2 ? 'B' : 'A', - tmp_key[0], tmp_key[1], tmp_key[2], tmp_key[3], tmp_key[4], tmp_key[5]); + j ? 'B' : 'A', + sprint_hex(tmp_key, sizeof(tmp_key)) + ); // Store valid credentials for the nested / hardnested attack if none exist if (know_target_key == false) { - num_to_bytes(e_sector[i].Key[i2], 6, key); + num_to_bytes(e_sector[i].Key[j], 6, key); know_target_key = true; blockNo = i; - keyType = i2; - PrintAndLogEx(SUCCESS, "[ SETTINGS ] The following key will be used for the nested / hardnested attack: sector:" - _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + keyType = j; + PrintAndLogEx(SUCCESS, "Using key nested / hardnested attack: sector:" + _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("%s"), blockNo, keyType ? 'B' : 'A', - key[0], key[1], key[2], key[3], key[4], key[5]); + sprint_hex(key, sizeof(key)) + ); } } } @@ -1892,7 +1900,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (know_target_key == false) { // Check if the darkside attack can be used if (prng_type) { - PrintAndLogEx(INFO, "No key was found ... time to go to the dark side ;)"); + PrintAndLogEx(INFO, "Enter darkside run..."); int isOK = mfDarkside(FirstBlockOfSector(blockNo), keyType, &key64); switch (isOK) { case -1 : @@ -1919,10 +1927,11 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Check if the darkside key is valid if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) != PM3_SUCCESS) { PrintAndLogEx(FAILED, "The key generated by the darkside attack is not valid!" - _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("0x%02x%02x%02x%02x%02x%02x"), + _RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), blockNo, keyType ? 'B' : 'A', - key[0], key[1], key[2], key[3], key[4], key[5]); + sprint_hex(key, sizeof(key)) + ); goto noValidKeyFound; } // Store the keys @@ -1933,7 +1942,7 @@ noValidKeyFound: PrintAndLogEx(FAILED, "No usable key was found!"); free(keyBlock); free(e_sector); - return 1; + return PM3_ESOFT; } } free(keyBlock); @@ -1952,19 +1961,21 @@ noValidKeyFound: if (bytes_to_num(tmp_key, 6) != 0) { // The fast check --> mfCheckKeys_fast(sectors_cnt, true, true, 2, 1, tmp_key, e_sector, false); // Returns false keys, so we just stick to the slower mfchk. - for (i = 0; i < sectors_cnt; i++) { - for (i2 = 0; i2 < 2; i2++) { + for (int i = 0; i < sectors_cnt; i++) { + for (int j = 0; j < 2; j++) { // Check if the sector key is already broken - if (e_sector[i].foundKey[i2] == 0) { - // Check if the key works - if (mfCheckKeys(FirstBlockOfSector(i), i2, true, 1, tmp_key, &key64) == PM3_SUCCESS) { - e_sector[i].Key[i2] = bytes_to_num(tmp_key, 6); - e_sector[i].foundKey[i2] = 4; - PrintAndLogEx(SUCCESS, "[ REUSED KEY ] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), - i, - i2 ? 'B' : 'A', - tmp_key[0], tmp_key[1], tmp_key[2], tmp_key[3], tmp_key[4], tmp_key[5]); - } + if (e_sector[i].foundKey[j]) + continue; + + // Check if the key works + if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, tmp_key, &key64) == PM3_SUCCESS) { + e_sector[i].Key[j] = bytes_to_num(tmp_key, 6); + e_sector[i].foundKey[j] = 4; + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), + i, + j ? 'B' : 'A', + sprint_hex(tmp_key, sizeof(tmp_key)) + ); } } } @@ -1977,7 +1988,7 @@ noValidKeyFound: if (prng_type && (! nested_failed)) { uint8_t retries = 0; tryNested: - PrintAndLogEx(INFO, "[ NESTED ] Sector no:%3d, target key type:%c", + PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c", current_sector_i, current_key_type_i ? 'B' : 'A'); @@ -1986,18 +1997,15 @@ tryNested: case -1 : PrintAndLogEx(ERR, "\nError: No response from Proxmark3."); free(e_sector); - return 1; - break; + return PM3_ESOFT; case -2 : PrintAndLogEx(WARNING, "\nButton pressed. Aborted."); free(e_sector); - return 1; - break; + return PM3_ESOFT; case -3 : PrintAndLogEx(FAILED, "Tag isn't vulnerable to Nested Attack (PRNG is probably not predictable)."); - PrintAndLogEx(FAILED, "Nested attack failed --> try hardnested instead!"); + PrintAndLogEx(FAILED, "Nested attack failed --> try hardnested"); goto tryHardnested; - break; case -4 : //key not found calibrate = false; // this can happen on some old cards, it's worth trying some more before switching to slower hardnested @@ -2018,12 +2026,11 @@ tryNested: default : PrintAndLogEx(ERR, "unknown Error.\n"); free(e_sector); - return 1; - break; + return PM3_ESOFT; } } else { tryHardnested: // If the nested attack fails then we try the hardnested attack - PrintAndLogEx(INFO, "[ HARDNESTED ] Sector no:%3d, target key type:%c, Slow: %s", + PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c, Slow: %s", current_sector_i, current_key_type_i ? 'B' : 'A', slow ? "Yes" : "No"); @@ -2042,7 +2049,7 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack break; } free(e_sector); - return 2; + return PM3_ESOFT; } // Copy the found key to the tmp_key variale (for the following print statement, and the mfCheckKeys above) @@ -2051,16 +2058,12 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack e_sector[current_sector_i].foundKey[current_key_type_i] = 6; } // Check if the key was found - if (e_sector[current_sector_i].foundKey[current_key_type_i] != 0) { - PrintAndLogEx(SUCCESS, "[TESTING KEY] Valid KEY FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), + if (e_sector[current_sector_i].foundKey[current_key_type_i]) { + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), current_sector_i, current_key_type_i ? 'B' : 'A', - tmp_key[0], tmp_key[1], tmp_key[2], tmp_key[3], tmp_key[4], tmp_key[5]); - } else { - PrintAndLogEx(FAILED, "[TESTING KEY] Valid KEY NOT FOUND: sector:%3d key type:%c key: " _YELLOW_("0x%02x%02x%02x%02x%02x%02x"), - current_sector_i, - current_key_type_i ? 'B' : 'A', - tmp_key[0], tmp_key[1], tmp_key[2], tmp_key[3], tmp_key[4], tmp_key[5]); + sprint_hex(tmp_key, sizeof(tmp_key)) + ); } } } @@ -2072,39 +2075,43 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack PrintAndLogEx(INFO, "Found Keys:"); printKeyTable(sectors_cnt, e_sector); if (verbose) { - PrintAndLogEx(INFO, "[ INFO ] Key res types:"); - PrintAndLogEx(INFO, " 1: Dictionary"); - PrintAndLogEx(INFO, " 2: Darkside attack"); - PrintAndLogEx(INFO, " 3: User supplied"); - PrintAndLogEx(INFO, " 4: Reused"); - PrintAndLogEx(INFO, " 5: Nested"); - PrintAndLogEx(INFO, " 6: Hardnested"); + PrintAndLogEx(INFO, " Key res types:"); + PrintAndLogEx(INFO, " 1: Dictionary"); + PrintAndLogEx(INFO, " 2: Darkside attack"); + PrintAndLogEx(INFO, " 3: User supplied"); + PrintAndLogEx(INFO, " 4: Reused"); + PrintAndLogEx(INFO, " 5: Nested"); + PrintAndLogEx(INFO, " 6: Hardnested"); } - // Transfere the found keys to the simulator and dump the keys and card data - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "Dumping the keys:"); + PrintAndLogEx(INFO, "\nSaving keys"); + createMfcKeyDump(sectors_cnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); - PrintAndLogEx(SUCCESS, "Transferring the found keys to the simulator memory (Cmd Error: 04 can occur, but this shouldn't be a problem)"); + PrintAndLogEx(SUCCESS, "Transferring keys to simulator memory (Cmd Error: 04 can occur)"); + for (current_sector_i = 0; current_sector_i < sectors_cnt; current_sector_i++) { mfEmlGetMem(block, current_sector_i, 1); if (e_sector[current_sector_i].foundKey[0]) num_to_bytes(e_sector[current_sector_i].Key[0], 6, block); if (e_sector[current_sector_i].foundKey[1]) num_to_bytes(e_sector[current_sector_i].Key[1], 6, block + 10); + mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1); } + // using ecfill trick, keys already in emulator mem, load data using Key A clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, sectors_cnt, 0, 0, NULL, 0); + + // using ecfill trick, keys already in emulator mem, load data using Key B clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, sectors_cnt, 1, 0, NULL, 0); bytes = block_cnt * MFBLOCK_SIZE; dump = calloc(bytes, sizeof(uint8_t)); if (!dump) { - PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); + PrintAndLogEx(ERR, "Fail, cannot allocate memory"); free(e_sector); return PM3_EMALLOC; } @@ -2112,26 +2119,31 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack PrintAndLogEx(INFO, "Downloading the card content from emulator memory"); if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) { - PrintAndLogEx(WARNING, "Fail, transfer from device time-out"); + PrintAndLogEx(ERR, "Fail, transfer from device time-out"); free(e_sector); free(dump); return PM3_ETIMEOUT; } - fnameptr += sprintf(fnameptr, "hf-mf-"); - FillFileNameByUID(fnameptr, dump, "-dump", 4); - + fnameptr = GenerateFilename("hf-mf-", "-data"); + if (fnameptr == NULL) { + free(dump); + free(e_sector); + return PM3_ESOFT; + } + strcpy(filename, fnameptr); + saveFile(filename, ".bin", dump, bytes); saveFileEML(filename, dump, bytes, MFBLOCK_SIZE); saveFileJSON(filename, jsfCardMemory, dump, bytes); // Generate and show statistics t1 = msclock() - t1; - PrintAndLogEx(INFO, "Required time for the autopwn attack: " _YELLOW_("%.0f") " seconds", (float)t1 / 1000.0); + PrintAndLogEx(INFO, "Autopwn execution time: " _YELLOW_("%.0f") " seconds", (float)t1 / 1000.0); free(dump); free(e_sector); - return 0; + return PM3_SUCCESS; } /* From d88b76bedab0362b26f0bc36a635b6fba05679d8 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 27 Aug 2019 17:28:08 +0200 Subject: [PATCH 121/347] partial make style --- armsrc/optimized_cipher.c | 154 +++++++++++++++++++------------------- client/cmdhfmf.c | 84 ++++++++++----------- 2 files changed, 119 insertions(+), 119 deletions(-) diff --git a/armsrc/optimized_cipher.c b/armsrc/optimized_cipher.c index b03facf93..a54aebc61 100644 --- a/armsrc/optimized_cipher.c +++ b/armsrc/optimized_cipher.c @@ -71,7 +71,7 @@ * Removing many unnecessary bit maskings (& 0x1) * updating state in place instead of alternating use of a second state structure * remove the necessity to reverse bits of input and output bytes - + opt_doTagMAC_2() now completes in 270 microseconds. -- piwi 2019 @@ -80,22 +80,22 @@ #include "optimized_cipher.h" static const uint8_t opt_select_LUT[256] = { - 00, 03, 02, 01, 02, 03, 00, 01, 04, 07, 07, 04, 06, 07, 05, 04, - 01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04, - 06, 05, 04, 07, 04, 05, 06, 07, 06, 05, 05, 06, 04, 05, 07, 06, - 07, 04, 05, 06, 04, 05, 06, 07, 07, 04, 04, 07, 04, 05, 07, 06, - 06, 05, 04, 07, 04, 05, 06, 07, 02, 01, 01, 02, 00, 01, 03, 02, - 03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06, - 00, 03, 02, 01, 02, 03, 00, 01, 00, 03, 03, 00, 02, 03, 01, 00, - 05, 06, 07, 04, 06, 07, 04, 05, 05, 06, 06, 05, 06, 07, 05, 04, - 02, 01, 00, 03, 00, 01, 02, 03, 06, 05, 05, 06, 04, 05, 07, 06, - 03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06, - 02, 01, 00, 03, 00, 01, 02, 03, 02, 01, 01, 02, 00, 01, 03, 02, - 03, 00, 01, 02, 00, 01, 02, 03, 03, 00, 00, 03, 00, 01, 03, 02, - 04, 07, 06, 05, 06, 07, 04, 05, 00, 03, 03, 00, 02, 03, 01, 00, - 01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04, - 04, 07, 06, 05, 06, 07, 04, 05, 04, 07, 07, 04, 06, 07, 05, 04, - 01, 02, 03, 00, 02, 03, 00, 01, 01, 02, 02, 01, 02, 03, 01, 00 + 00, 03, 02, 01, 02, 03, 00, 01, 04, 07, 07, 04, 06, 07, 05, 04, + 01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04, + 06, 05, 04, 07, 04, 05, 06, 07, 06, 05, 05, 06, 04, 05, 07, 06, + 07, 04, 05, 06, 04, 05, 06, 07, 07, 04, 04, 07, 04, 05, 07, 06, + 06, 05, 04, 07, 04, 05, 06, 07, 02, 01, 01, 02, 00, 01, 03, 02, + 03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06, + 00, 03, 02, 01, 02, 03, 00, 01, 00, 03, 03, 00, 02, 03, 01, 00, + 05, 06, 07, 04, 06, 07, 04, 05, 05, 06, 06, 05, 06, 07, 05, 04, + 02, 01, 00, 03, 00, 01, 02, 03, 06, 05, 05, 06, 04, 05, 07, 06, + 03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06, + 02, 01, 00, 03, 00, 01, 02, 03, 02, 01, 01, 02, 00, 01, 03, 02, + 03, 00, 01, 02, 00, 01, 02, 03, 03, 00, 00, 03, 00, 01, 03, 02, + 04, 07, 06, 05, 06, 07, 04, 05, 00, 03, 03, 00, 02, 03, 01, 00, + 01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04, + 04, 07, 06, 05, 06, 07, 04, 05, 04, 07, 07, 04, 06, 07, 05, 04, + 01, 02, 03, 00, 02, 03, 00, 01, 01, 02, 02, 01, 02, 03, 01, 00 }; /********************** the table above has been generated with this code: ******** @@ -143,65 +143,65 @@ uint8_t xopt__select(bool x, bool y, uint8_t r) static void opt_successor(const uint8_t *k, State *s, uint8_t y) { // #define opt_T(s) (0x1 & ((s->t >> 15) ^ (s->t >> 14) ^ (s->t >> 10) ^ (s->t >> 8) ^ (s->t >> 5) ^ (s->t >> 4)^ (s->t >> 1) ^ s->t)) - // uint8_t Tt = opt_T(s); - uint16_t Tt = s->t & 0xc533; - Tt = Tt ^ (Tt >> 1); - Tt = Tt ^ (Tt >> 4); - Tt = Tt ^ (Tt >> 10); - Tt = Tt ^ (Tt >> 8); + // uint8_t Tt = opt_T(s); + uint16_t Tt = s->t & 0xc533; + Tt = Tt ^ (Tt >> 1); + Tt = Tt ^ (Tt >> 4); + Tt = Tt ^ (Tt >> 10); + Tt = Tt ^ (Tt >> 8); - s->t = (s->t >> 1); - s->t |= (Tt ^ (s->r >> 7) ^ (s->r >> 3)) << 15; + s->t = (s->t >> 1); + s->t |= (Tt ^ (s->r >> 7) ^ (s->r >> 3)) << 15; - uint8_t opt_B = s->b; - opt_B ^= s->b >> 6; - opt_B ^= s->b >> 5; - opt_B ^= s->b >> 4; + uint8_t opt_B = s->b; + opt_B ^= s->b >> 6; + opt_B ^= s->b >> 5; + opt_B ^= s->b >> 4; - s->b = s->b >> 1; - s->b |= (opt_B ^ s->r) << 7; + s->b = s->b >> 1; + s->b |= (opt_B ^ s->r) << 7; - uint8_t opt_select = opt_select_LUT[s->r] & 0x04; - opt_select |= (opt_select_LUT[s->r] ^ ((Tt ^ y) << 1)) & 0x02; - opt_select |= (opt_select_LUT[s->r] ^ Tt) & 0x01; + uint8_t opt_select = opt_select_LUT[s->r] & 0x04; + opt_select |= (opt_select_LUT[s->r] ^ ((Tt ^ y) << 1)) & 0x02; + opt_select |= (opt_select_LUT[s->r] ^ Tt) & 0x01; - uint8_t r = s->r; - s->r = (k[opt_select] ^ s->b) + s->l ; - s->l = s->r + r; + uint8_t r = s->r; + s->r = (k[opt_select] ^ s->b) + s->l ; + s->l = s->r + r; } static void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) { for (int i = 0; i < length; i++) { uint8_t head; - head = in[i]; - opt_successor(k, s, head); + head = in[i]; + opt_successor(k, s, head); - head >>= 1; - opt_successor(k, s, head); + head >>= 1; + opt_successor(k, s, head); - head >>= 1; - opt_successor(k, s, head); + head >>= 1; + opt_successor(k, s, head); - head >>= 1; - opt_successor(k, s, head); + head >>= 1; + opt_successor(k, s, head); - head >>= 1; - opt_successor(k, s, head); + head >>= 1; + opt_successor(k, s, head); - head >>= 1; - opt_successor(k, s, head); + head >>= 1; + opt_successor(k, s, head); - head >>= 1; - opt_successor(k, s, head); + head >>= 1; + opt_successor(k, s, head); - head >>= 1; - opt_successor(k, s, head); + head >>= 1; + opt_successor(k, s, head); } //For tag MAC, an additional 32 zeroes if (add32Zeroes) { for (int i = 0; i < 16; i++) { - opt_successor(k, s, 0); - opt_successor(k, s, 0); + opt_successor(k, s, 0); + opt_successor(k, s, 0); } } } @@ -209,22 +209,22 @@ static void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, boo static void opt_output(const uint8_t *k, State *s, uint8_t *buffer) { for (uint8_t times = 0; times < 4; times++) { uint8_t bout = 0; - bout |= (s->r & 0x4) >> 2; - opt_successor(k, s, 0); + bout |= (s->r & 0x4) >> 2; + opt_successor(k, s, 0); bout |= (s->r & 0x4) >> 1; - opt_successor(k, s, 0); - bout |= (s->r & 0x4); - opt_successor(k, s, 0); - bout |= (s->r & 0x4) << 1; - opt_successor(k, s, 0); - bout |= (s->r & 0x4) << 2; - opt_successor(k, s, 0); - bout |= (s->r & 0x4) << 3; - opt_successor(k, s, 0); - bout |= (s->r & 0x4) << 4; - opt_successor(k, s, 0); - bout |= (s->r & 0x4) << 5; - opt_successor(k, s, 0); + opt_successor(k, s, 0); + bout |= (s->r & 0x4); + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 1; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 2; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 3; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 4; + opt_successor(k, s, 0); + bout |= (s->r & 0x4) << 5; + opt_successor(k, s, 0); buffer[times] = bout; } } @@ -243,8 +243,8 @@ static void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) { void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) { uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0}; - opt_MAC(div_key_p, cc_nr_p, dest); - memcpy(mac, dest, 4); + opt_MAC(div_key_p, cc_nr_p, dest); + memcpy(mac, dest, 4); return; } @@ -255,8 +255,8 @@ void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) { 0x4c, // b 0xE012 // t }; - opt_suc(div_key_p, &_init, cc_p, 12, true); - opt_output(div_key_p, &_init, mac); + opt_suc(div_key_p, &_init, cc_p, 12, true); + opt_output(div_key_p, &_init, mac); return; } @@ -275,7 +275,7 @@ State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) { 0x4c, // b 0xE012 // t }; - opt_suc(div_key_p, &_init, cc_p, 8, false); + opt_suc(div_key_p, &_init, cc_p, 8, false); return _init; } @@ -289,7 +289,7 @@ State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) { * @param div_key_p - the key to use */ void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p) { - opt_suc(div_key_p, &_init, nr, 4, true); - opt_output(div_key_p, &_init, mac); + opt_suc(div_key_p, &_init, nr, 4, true); + opt_output(div_key_p, &_init, mac); return; } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 030da5a8d..82aba722e 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -752,10 +752,10 @@ static uint8_t NumBlocksPerSector(uint8_t sectorNo) { } } static uint8_t GetSectorFromBlockNo(uint8_t blockNo) { - if ( blockNo < 128 ) - return blockNo / 4; - else - return 32 + ((128 - blockNo) / 16); + if (blockNo < 128) + return blockNo / 4; + else + return 32 + ((128 - blockNo) / 16); } static int CmdHF14AMfDump(const char *Cmd) { @@ -963,11 +963,11 @@ static int CmdHF14AMfDump(const char *Cmd) { PrintAndLogEx(SUCCESS, "\nSucceded in dumping all blocks"); if (strlen(dataFilename) < 1) { - fptr = GenerateFilename("hf-mf-", "-data"); - if (fptr == NULL) - return PM3_ESOFT; + fptr = GenerateFilename("hf-mf-", "-data"); + if (fptr == NULL) + return PM3_ESOFT; - strcpy(dataFilename, fptr); + strcpy(dataFilename, fptr); } uint16_t bytes = 16 * (FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1)); @@ -1229,9 +1229,9 @@ static int CmdHF14AMfNested(const char *Cmd) { e_sector = calloc(SectorsCnt, sizeof(sector_t)); if (e_sector == NULL) return PM3_EMALLOC; - // add our known key - e_sector[GetSectorFromBlockNo(blockNo)].foundKey[keyType] = 1; - e_sector[GetSectorFromBlockNo(blockNo)].Key[keyType] = key64; + // add our known key + e_sector[GetSectorFromBlockNo(blockNo)].foundKey[keyType] = 1; + e_sector[GetSectorFromBlockNo(blockNo)].Key[keyType] = key64; //test current key and additional standard keys first // add parameter key @@ -1703,7 +1703,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Create the key storage stucture e_sector = calloc(sectors_cnt, sizeof(sector_t)); if (e_sector == NULL) return PM3_EMALLOC; - + // clear the key storage for (int i = 0; i < sectors_cnt; i++) { for (int j = 0; j < 2; j++) { @@ -1740,7 +1740,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { blockNo, keyType ? 'B' : 'A', sprint_hex(key, sizeof(key)) - ); + ); // Store the key for the nested / hardnested attack (if supplied by the user) e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); @@ -1751,7 +1751,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { blockNo, keyType ? 'B' : 'A', sprint_hex(key, sizeof(key)) - ); + ); PrintAndLogEx(WARNING, "Falling back to dictionary"); } // Check if the user supplied key is used by other sectors @@ -1765,7 +1765,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { i, j ? 'B' : 'A', sprint_hex(key, sizeof(key)) - ); + ); // If the user supplied secctor / keytype was wrong --> just be nice and correct it ;) if (know_target_key == false) { @@ -1778,7 +1778,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { blockNo, keyType ? 'B' : 'A', sprint_hex(key, sizeof(key)) - ); + ); } } } @@ -1792,7 +1792,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { loadFileDICTIONARY(filename, keyBlock, &data_length, 6, &key_cnt); if ((data_length / 6) > max_dictionary_size) { // This is not a good solution (loadFileDICTIONARY needs a maxdatalen)! - // loadfiledictionary will reallocate to correct size. + // loadfiledictionary will reallocate to correct size. PrintAndLogEx(FAILED, "Dictionary is too large: %d (allowed: %d)", data_length, max_dictionary_size); free(keyBlock); free(e_sector); @@ -1813,7 +1813,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Use the dictionary to find sector keys on the card PrintAndLogEx(INFO, "Enter dictionary run..."); - + if (legacy_mfchk) { // Check all the sectors for (int i = 0; i < sectors_cnt; i++) { @@ -1877,7 +1877,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { i, j ? 'B' : 'A', sprint_hex(tmp_key, sizeof(tmp_key)) - ); + ); // Store valid credentials for the nested / hardnested attack if none exist if (know_target_key == false) { @@ -1890,7 +1890,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { blockNo, keyType ? 'B' : 'A', sprint_hex(key, sizeof(key)) - ); + ); } } } @@ -1931,7 +1931,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { blockNo, keyType ? 'B' : 'A', sprint_hex(key, sizeof(key)) - ); + ); goto noValidKeyFound; } // Store the keys @@ -1965,17 +1965,17 @@ noValidKeyFound: for (int j = 0; j < 2; j++) { // Check if the sector key is already broken if (e_sector[i].foundKey[j]) - continue; - - // Check if the key works - if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, tmp_key, &key64) == PM3_SUCCESS) { - e_sector[i].Key[j] = bytes_to_num(tmp_key, 6); - e_sector[i].foundKey[j] = 4; - PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), - i, - j ? 'B' : 'A', - sprint_hex(tmp_key, sizeof(tmp_key)) - ); + continue; + + // Check if the key works + if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, tmp_key, &key64) == PM3_SUCCESS) { + e_sector[i].Key[j] = bytes_to_num(tmp_key, 6); + e_sector[i].foundKey[j] = 4; + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), + i, + j ? 'B' : 'A', + sprint_hex(tmp_key, sizeof(tmp_key)) + ); } } } @@ -2063,7 +2063,7 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack current_sector_i, current_key_type_i ? 'B' : 'A', sprint_hex(tmp_key, sizeof(tmp_key)) - ); + ); } } } @@ -2089,7 +2089,7 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack createMfcKeyDump(sectors_cnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); PrintAndLogEx(SUCCESS, "Transferring keys to simulator memory (Cmd Error: 04 can occur)"); - + for (current_sector_i = 0; current_sector_i < sectors_cnt; current_sector_i++) { mfEmlGetMem(block, current_sector_i, 1); if (e_sector[current_sector_i].foundKey[0]) @@ -2100,11 +2100,11 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1); } - // using ecfill trick, keys already in emulator mem, load data using Key A + // using ecfill trick, keys already in emulator mem, load data using Key A clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, sectors_cnt, 0, 0, NULL, 0); - // using ecfill trick, keys already in emulator mem, load data using Key B + // using ecfill trick, keys already in emulator mem, load data using Key B clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, sectors_cnt, 1, 0, NULL, 0); @@ -2126,13 +2126,13 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack } fnameptr = GenerateFilename("hf-mf-", "-data"); - if (fnameptr == NULL) { - free(dump); - free(e_sector); - return PM3_ESOFT; + if (fnameptr == NULL) { + free(dump); + free(e_sector); + return PM3_ESOFT; } - strcpy(filename, fnameptr); - + strcpy(filename, fnameptr); + saveFile(filename, ".bin", dump, bytes); saveFileEML(filename, dump, bytes, MFBLOCK_SIZE); saveFileJSON(filename, jsfCardMemory, dump, bytes); From 02c1657594ef0091e652648ad59c7b208e3ee805 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Tue, 27 Aug 2019 19:17:52 +0200 Subject: [PATCH 122/347] Added some found keys to the dictionary. --- client/dictionaries/mfc_default_keys.dic | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/client/dictionaries/mfc_default_keys.dic b/client/dictionaries/mfc_default_keys.dic index ff63a0a83..924f75488 100644 --- a/client/dictionaries/mfc_default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -982,3 +982,36 @@ ef4c5a7ac6fc b47058139187 8268046cd154 67cc03b7d577 +# +# From the HTL Mödling, NÖ, AT +# +a5524645cd91 +d964406e67b4 +99858a49c119 +7b7e752b6a2d +c27d999912ea +66a163ba82b4 +4c60f4b15ba8 +# +# CAFE + CO, AT +# +35d850d10a24 +4b511f4d28dd +e45230e7a9e8 +535f47d35e39 +fb6c88b7e279 +# +# Metro Card, AT +# +223C3427108A +# +# Unknown, AT +# +23d4cdff8da3 +e6849fcc324b +12fd3a94df0e +# +# Unknown, AT +# +0b83797a9c64 +39ad2963d3d1 From c9a02adc70945d8879bdbfcdf800d66861360719 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Tue, 27 Aug 2019 19:45:37 +0200 Subject: [PATCH 123/347] Added the read B key with known A key feature, and minor changes to the UI (alignment). --- client/cmdhfmf.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 82aba722e..d122837e3 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1873,7 +1873,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { for (int j = 0; j < 2; j++) { if (e_sector[i].foundKey[j] == 1) { num_to_bytes(e_sector[i].Key[j], 6, tmp_key); - PrintAndLogEx(SUCCESS, "Found valid key: sector:%3d key type:%c key: " _YELLOW_("%s"), + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), i, j ? 'B' : 'A', sprint_hex(tmp_key, sizeof(tmp_key)) @@ -1983,6 +1983,43 @@ noValidKeyFound: // Clear the last found key num_to_bytes(0, 6, tmp_key); + if (current_key_type_i == 1) { + if (e_sector[current_sector_i].foundKey[0] && !e_sector[current_sector_i].foundKey[1]) { + PrintAndLogEx(INFO, "Reading B key: sector: %3d", current_sector_i); + uint8_t sectrail = (FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1); + + mf_readblock_t payload; + payload.blockno = sectrail; + payload.keytype = 0; + + num_to_bytes(e_sector[current_sector_i].Key[0], 6, payload.key); // KEY A + + clearCommandBuffer(); + SendCommandNG(CMD_HF_MIFARE_READBL, (uint8_t *)&payload, sizeof(mf_readblock_t)); + + PacketResponseNG resp; + if (!WaitForResponseTimeout(CMD_HF_MIFARE_READBL, &resp, 1500)) continue; + + if (resp.status != PM3_SUCCESS) continue; + + uint8_t *data = resp.data.asBytes; + key64 = bytes_to_num(data + 10, 6); + if (verbose){ + num_to_bytes(key64, 6, tmp_key); + PrintAndLogEx(INFO, "Discovered key: sector: %3d key type: %c key: " _YELLOW_("%s"), + current_sector_i, + current_key_type_i ? 'B' : 'A', + sprint_hex(tmp_key, sizeof(tmp_key)) + ); + } + if (key64) { + e_sector[current_sector_i].foundKey[current_key_type_i] = 7; + e_sector[current_sector_i].Key[current_key_type_i] = key64; + num_to_bytes(key64, 6, tmp_key); + } + } + } + // Use the nested / hardnested attack if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { if (prng_type && (! nested_failed)) { @@ -2082,6 +2119,7 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack PrintAndLogEx(INFO, " 4: Reused"); PrintAndLogEx(INFO, " 5: Nested"); PrintAndLogEx(INFO, " 6: Hardnested"); + PrintAndLogEx(INFO, " 7: Read B key with A key"); } PrintAndLogEx(INFO, "\nSaving keys"); From 42d58cbced52b093de0f6376e180204d3ddf0fb7 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Tue, 27 Aug 2019 19:55:45 +0200 Subject: [PATCH 124/347] fixed the read B key features error handling. --- client/cmdhfmf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index d122837e3..2f738af2c 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1998,9 +1998,9 @@ noValidKeyFound: SendCommandNG(CMD_HF_MIFARE_READBL, (uint8_t *)&payload, sizeof(mf_readblock_t)); PacketResponseNG resp; - if (!WaitForResponseTimeout(CMD_HF_MIFARE_READBL, &resp, 1500)) continue; + if (!WaitForResponseTimeout(CMD_HF_MIFARE_READBL, &resp, 1500)) goto skipReadBKey; - if (resp.status != PM3_SUCCESS) continue; + if (resp.status != PM3_SUCCESS) goto skipReadBKey; uint8_t *data = resp.data.asBytes; key64 = bytes_to_num(data + 10, 6); @@ -2021,6 +2021,7 @@ noValidKeyFound: } // Use the nested / hardnested attack +skipReadBKey: if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { if (prng_type && (! nested_failed)) { uint8_t retries = 0; From a0c2de5602442110a73078a153280730fbc5c760 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Tue, 27 Aug 2019 20:28:28 +0200 Subject: [PATCH 125/347] Added an key found message to the read b key with a key feature. --- client/cmdhfmf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 2f738af2c..99d6afd97 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2016,6 +2016,11 @@ noValidKeyFound: e_sector[current_sector_i].foundKey[current_key_type_i] = 7; e_sector[current_sector_i].Key[current_key_type_i] = key64; num_to_bytes(key64, 6, tmp_key); + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), + current_sector_i, + current_key_type_i ? 'B' : 'A', + sprint_hex(tmp_key, sizeof(tmp_key)) + ); } } } From a64aa99b74c78ee38aa1a7e2a8823dfc15de9fa5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 27 Aug 2019 21:19:44 +0200 Subject: [PATCH 126/347] remove tabs --- armsrc/optimized_cipher.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/armsrc/optimized_cipher.c b/armsrc/optimized_cipher.c index a54aebc61..0f762a8d6 100644 --- a/armsrc/optimized_cipher.c +++ b/armsrc/optimized_cipher.c @@ -101,16 +101,16 @@ static const uint8_t opt_select_LUT[256] = { /********************** the table above has been generated with this code: ******** #include "util.h" static void init_opt_select_LUT(void) { - for (int r = 0; r < 256; r++) { - uint8_t r_ls2 = r << 2; - uint8_t r_and_ls2 = r & r_ls2; - uint8_t r_or_ls2 = r | r_ls2; - uint8_t z0 = (r_and_ls2 >> 5) ^ ((r & ~r_ls2) >> 4) ^ ( r_or_ls2 >> 3); - uint8_t z1 = (r_or_ls2 >> 6) ^ ( r_or_ls2 >> 1) ^ (r >> 5) ^ r; - uint8_t z2 = ((r & ~r_ls2) >> 4) ^ (r_and_ls2 >> 3) ^ r; - opt_select_LUT[r] = (z0 & 4) | (z1 & 2) | (z2 & 1); - } - print_result("", opt_select_LUT, 256); + for (int r = 0; r < 256; r++) { + uint8_t r_ls2 = r << 2; + uint8_t r_and_ls2 = r & r_ls2; + uint8_t r_or_ls2 = r | r_ls2; + uint8_t z0 = (r_and_ls2 >> 5) ^ ((r & ~r_ls2) >> 4) ^ ( r_or_ls2 >> 3); + uint8_t z1 = (r_or_ls2 >> 6) ^ ( r_or_ls2 >> 1) ^ (r >> 5) ^ r; + uint8_t z2 = ((r & ~r_ls2) >> 4) ^ (r_and_ls2 >> 3) ^ r; + opt_select_LUT[r] = (z0 & 4) | (z1 & 2) | (z2 & 1); + } + print_result("", opt_select_LUT, 256); } ***********************************************************************************/ From 4b8c80ec33dd48eba9e7cc8edad4f0b311332a79 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 27 Aug 2019 21:56:03 +0200 Subject: [PATCH 127/347] return values.. --- client/loclass/cipher.c | 7 +++---- client/loclass/cipher.h | 1 + client/loclass/cipherutils.c | 11 +++++++---- client/loclass/cipherutils.h | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/client/loclass/cipher.c b/client/loclass/cipher.c index 931f0c845..13f686b51 100644 --- a/client/loclass/cipher.c +++ b/client/loclass/cipher.c @@ -226,8 +226,8 @@ void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) { reverse_arraybytes(dest, sizeof(dest)); memcpy(mac, dest, 4); //free(cc_nr); - return; } + void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_key_p, uint8_t mac[4]) { uint8_t *address_data; uint8_t div_key[8]; @@ -245,7 +245,6 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke reverse_arraybytes(dest, sizeof(dest)); memcpy(mac, dest, 4); free(address_data); - return; } #ifndef ON_DEVICE @@ -267,8 +266,8 @@ int testMAC() { PrintAndLogEx(FAILED, "FAILED: MAC calculation failed:"); printarr(" Calculated_MAC", calculated_mac, 4); printarr(" Correct_MAC ", correct_MAC, 4); - return 1; + return PM3_ESOFT; } - return 0; + return PM3_SUCCESS; } #endif diff --git a/client/loclass/cipher.h b/client/loclass/cipher.h index b79dc47cd..7b1257aa5 100644 --- a/client/loclass/cipher.h +++ b/client/loclass/cipher.h @@ -39,6 +39,7 @@ #ifndef CIPHER_H #define CIPHER_H #include +#include "pm3_cmd.h" void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]); void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_key_p, uint8_t mac[4]); diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index ee440fb73..b50268697 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -127,18 +127,21 @@ uint64_t x_bytes_to_num(uint8_t *src, size_t len) { } return num; } + uint8_t reversebytes(uint8_t b) { b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; b = (b & 0xCC) >> 2 | (b & 0x33) << 2; b = (b & 0xAA) >> 1 | (b & 0x55) << 1; return b; } + void reverse_arraybytes(uint8_t *arr, size_t len) { uint8_t i; for (i = 0; i < len ; i++) { arr[i] = reversebytes(arr[i]); } } + void reverse_arraycopy(uint8_t *arr, uint8_t *dest, size_t len) { uint8_t i; for (i = 0; i < len ; i++) { @@ -202,9 +205,9 @@ static int testBitStream() { for (i = 0 ; i < ARRAYLEN(input) ; i++) { PrintAndLogEx(NORMAL, " IN %02x, OUT %02x", input[i], output[i]); } - return 1; + return PM3_ESOFT; } - return 0; + return PM3_SUCCESS; } static int testReversedBitstream() { @@ -232,9 +235,9 @@ static int testReversedBitstream() { for (i = 0 ; i < ARRAYLEN(input) ; i++) { PrintAndLogEx(NORMAL, " IN %02x, MIDDLE: %02x, OUT %02x", input[i], reverse[i], output[i]); } - return 1; + return PM3_ESOFT; } - return 0; + return PM3_SUCCESS; } diff --git a/client/loclass/cipherutils.h b/client/loclass/cipherutils.h index 70438d33b..6c90326a6 100644 --- a/client/loclass/cipherutils.h +++ b/client/loclass/cipherutils.h @@ -41,6 +41,7 @@ #include #include #include +#include "pm3_cmd.h" typedef struct { uint8_t *buffer; From 4fe7c7c9fa276120553679268db5489cb31ffb27 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 27 Aug 2019 23:17:02 +0200 Subject: [PATCH 128/347] remove utf8 dashes --- client/cmdhf14a.c | 2 +- client/emv/emv_tags.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 8aea8db6c..b21e8dbd7 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -133,7 +133,7 @@ static const manufactureName manufactureMapping[] = { { 0x61, "Wearlinks Technology Inc. China" }, { 0x62, "Userstar Information Systems Co., Ltd Taiwan" }, { 0x63, "Pragmatic Printing Ltd. UK" }, - { 0x64, "Associacao do Laboratorio de Sistemas Integraveis Tecnologico – LSI-TEC Brazil" }, + { 0x64, "Associacao do Laboratorio de Sistemas Integraveis Tecnologico - LSI-TEC Brazil" }, { 0x65, "Tendyron Corporation China" }, { 0x66, "MUTO Smart Co., Ltd. Korea" }, { 0x67, "ON Semiconductor USA" }, diff --git a/client/emv/emv_tags.c b/client/emv/emv_tags.c index 72c1fe78e..296dcdf82 100644 --- a/client/emv/emv_tags.c +++ b/client/emv/emv_tags.c @@ -401,11 +401,11 @@ static const struct emv_tag emv_tags[] = { { 0xdf811b, "Kernel Configuration", EMV_TAG_GENERIC, NULL }, { 0xdf811c, "Max Lifetime of Torn Transaction Log Record", EMV_TAG_GENERIC, NULL }, { 0xdf811d, "Max Number of Torn Transaction Log Records", EMV_TAG_GENERIC, NULL }, - { 0xdf811e, "Mag-stripe CVM Capability – CVM Required", EMV_TAG_GENERIC, NULL }, + { 0xdf811e, "Mag-stripe CVM Capability - CVM Required", EMV_TAG_GENERIC, NULL }, { 0xdf811f, "Security Capability", EMV_TAG_GENERIC, NULL }, - { 0xdf8120, "Terminal Action Code – Default", EMV_TAG_GENERIC, NULL }, - { 0xdf8121, "Terminal Action Code – Denial", EMV_TAG_GENERIC, NULL }, - { 0xdf8122, "Terminal Action Code – Online", EMV_TAG_GENERIC, NULL }, + { 0xdf8120, "Terminal Action Code - Default", EMV_TAG_GENERIC, NULL }, + { 0xdf8121, "Terminal Action Code - Denial", EMV_TAG_GENERIC, NULL }, + { 0xdf8122, "Terminal Action Code - Online", EMV_TAG_GENERIC, NULL }, { 0xdf8123, "Reader Contactless Floor Limit", EMV_TAG_GENERIC, NULL }, { 0xdf8124, "Reader Contactless Transaction Limit (No On-device CVM)", EMV_TAG_GENERIC, NULL }, { 0xdf8125, "Reader Contactless Transaction Limit (On-device CVM)", EMV_TAG_GENERIC, NULL }, @@ -415,7 +415,7 @@ static const struct emv_tag emv_tags[] = { { 0xdf8129, "Outcome Parameter Set", EMV_TAG_GENERIC, NULL }, { 0xdf812a, "DD Card (Track1)", EMV_TAG_GENERIC, NULL }, { 0xdf812b, "DD Card (Track2)", EMV_TAG_GENERIC, NULL }, - { 0xdf812c, "Mag-stripe CVM Capability – No CVM Required", EMV_TAG_GENERIC, NULL }, + { 0xdf812c, "Mag-stripe CVM Capability - No CVM Required", EMV_TAG_GENERIC, NULL }, { 0xdf812d, "Message Hold Time", EMV_TAG_GENERIC, NULL }, { 0xff8101, "Torn Record", EMV_TAG_GENERIC, NULL }, From 254beefda2b3a466293edf9ae98bc1402f43a070 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 28 Aug 2019 00:03:27 +0200 Subject: [PATCH 129/347] Fix mingw utf8->cp850 support --- client/Makefile | 2 +- client/proxmark3.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/Makefile b/client/Makefile index d9e43d445..fc7fa520b 100644 --- a/client/Makefile +++ b/client/Makefile @@ -73,7 +73,7 @@ ifneq (,$(PM3_SHARE_PATH)) PM3CFLAGS += -DPM3_SHARE_PATH=\"$(PM3_SHARE_PATH)\" endif ifneq (,$(findstring MINGW,$(platform))) - PM3CFLAGS += -mno-ms-bitfields + PM3CFLAGS += -mno-ms-bitfields -fexec-charset=cp850 endif CXXFLAGS ?= -Wall -Werror -O3 PM3CXXFLAGS = $(CXXFLAGS) -I../include diff --git a/client/proxmark3.c b/client/proxmark3.c index 6555ac0f2..6a23f4804 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -31,7 +31,7 @@ static void showBanner(void) { PrintAndLogEx(NORMAL, "\n"); -#if defined(__linux__) || (__APPLE__) +#if defined(__linux__) || (__APPLE__) || (_WIN32) PrintAndLogEx(NORMAL, _BLUE_("██████╗ ███╗ ███╗ ████╗ ") " ...iceman fork"); PrintAndLogEx(NORMAL, _BLUE_("██╔══██╗████╗ ████║ ══█║") " ...dedicated to " _BLUE_("RDV40")); PrintAndLogEx(NORMAL, _BLUE_("██████╔╝██╔████╔██║ ████╔╝")); From 225b18d5fc048d08807b4928c5a2a2448de752ab Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 09:34:46 +0200 Subject: [PATCH 130/347] Implemented a function to safely load dictionaries. --- client/cmdhfmf.c | 17 ++++------- client/cmdlft55xx.c | 3 +- client/fileutils.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ client/fileutils.h | 12 +++++++- 4 files changed, 91 insertions(+), 14 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 99d6afd97..87fa500a8 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1591,7 +1591,6 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { uint8_t sectors_cnt = MIFARE_1K_MAXSECTOR; int block_cnt = MIFARE_1K_MAXBLOCK; uint8_t tmp_key[6] = {0}; - size_t data_length = 0; bool know_target_key = false; // For the timier uint64_t t1; @@ -1613,7 +1612,6 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { bool legacy_mfchk = false; bool prng_type = false; bool verbose = false; - int max_dictionary_size = 2000; // Parse the options given by the user ctmp = tolower(param_getchar(Cmd, 0)); @@ -1788,17 +1786,14 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Load the dictionary if (strlen(filename) != 0) { - keyBlock = calloc(6 * max_dictionary_size, sizeof(uint8_t)); - loadFileDICTIONARY(filename, keyBlock, &data_length, 6, &key_cnt); - if ((data_length / 6) > max_dictionary_size) { - // This is not a good solution (loadFileDICTIONARY needs a maxdatalen)! - // loadfiledictionary will reallocate to correct size. - PrintAndLogEx(FAILED, "Dictionary is too large: %d (allowed: %d)", data_length, max_dictionary_size); - free(keyBlock); - free(e_sector); - return PM3_EMALLOC; + int res = loadFileDICTIONARY_safe(filename, &keyBlock, 6, &key_cnt); + if (res != PM3_SUCCESS || key_cnt <= 0) { + PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)"); + free(keyBlock); // free the memory, just in case an allocation happened + goto useDefaultKeys; } } else { +useDefaultKeys: keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); if (keyBlock == NULL) { free(e_sector); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 80954dddb..3802beab9 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2127,7 +2127,6 @@ static int CmdT55xxChkPwds(const char *Cmd) { if (use_pwd_file) { uint16_t keycount = 0; - size_t datalen = 0; // TODO, a way of reallocating memory if file was larger keyBlock = calloc(4 * 200, sizeof(uint8_t)); @@ -2136,7 +2135,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { return PM3_ESOFT; } - int res = loadFileDICTIONARY(filename, keyBlock, &datalen, 4, &keycount); + int res = loadFileDICTIONARY_safe(filename, &keyBlock, 4, &keycount); if (res || keycount == 0) { PrintAndLogEx(WARNING, "No keys found in file"); free(keyBlock); diff --git a/client/fileutils.c b/client/fileutils.c index 15c6efec6..ff2dc510f 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -649,6 +649,79 @@ out: return retval; } +int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t keylen, uint16_t *keycnt) { + + int block_size = 512; + int allocation_size = block_size; + size_t counter = 0; + int retval = PM3_SUCCESS; + char *path; + if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic") != PM3_SUCCESS) + return PM3_EFILE; + + // t5577 == 4bytes + // mifare == 6 bytes + // iclass == 8 bytes + // default to 6 bytes. + if (keylen != 4 && keylen != 6 && keylen != 8) { + keylen = 6; + } + + // double up since its chars + keylen <<= 1; + + char line[255]; + + // allocate some space for the dictionary + *data = (uint8_t*) malloc(keylen * allocation_size * sizeof(uint8_t)); + if (*data == NULL) return PM3_EFILE; + + FILE *f = fopen(path, "r"); + if (!f) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path); + retval = PM3_EFILE; + goto out; } + + // read file + while (fgets(line, sizeof(line), f)) { + // check if we have enough space (if not allocate more) + if ((*keycnt) >= allocation_size) { + allocation_size += block_size; + *data = (uint8_t*) realloc((void*) *data, keylen * allocation_size * sizeof(uint8_t)); + if (*data == NULL) return PM3_EFILE; + } + + // add null terminator + line[keylen] = 0; + + // smaller keys than expected is skipped + if (strlen(line) < keylen) + continue; + + // The line start with # is comment, skip + if (line[0] == '#') + continue; + + if (!isxdigit(line[0])) { + PrintAndLogEx(FAILED, "file content error. '%s' must include " _BLUE_("%2d") "HEX symbols", line, keylen); + continue; + } + + uint64_t key = strtoull(line, NULL, 16); + + num_to_bytes(key, keylen >> 1, *data + counter); + (*keycnt)++; + memset(line, 0, sizeof(line)); + counter += (keylen >> 1); + } + fclose(f); + PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, path); + +out: + free(path); + return retval; +} + int convertOldMfuDump(uint8_t **dump, size_t *dumplen) { if (!dump || !dumplen || *dumplen < OLD_MFU_DUMP_PREFIX_LENGTH) return 1; diff --git a/client/fileutils.h b/client/fileutils.h index 03a47112e..b2c16c282 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -149,7 +149,6 @@ int loadFileEML(const char *preferredName, void *data, size_t *datalen); */ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen); - /** * @brief Utility function to load data from a DICTIONARY textfile. This method takes a preferred name. * E.g. mfc_default_keys.dic @@ -163,6 +162,17 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ */ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt); +/** + * @brief Utility function to load data from a DICTIONARY safely into a textfile. This method takes a preferred name. + * E.g. mfc_default_keys.dic + * + * @param preferredName + * @param data The data array to store the loaded bytes from file + * @param keylen the number of bytes a key per row is + * @return 0 for ok, 1 for failz +*/ +int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t keylen, uint16_t *keycnt); + /** * @brief Utility function to check and convert old mfu dump format to new * From 9dc3c39a95c0d06abfd5524339060c220ba56fba Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 09:45:11 +0200 Subject: [PATCH 131/347] Added additional checks to the from load dictionary returned data points. --- client/cmdhfmf.c | 6 +++--- client/cmdlft55xx.c | 11 ++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 87fa500a8..66aca7421 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1585,7 +1585,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { uint64_t key64 = 0; bool calibrate = true; // Attack key storage variables - uint8_t *keyBlock; + uint8_t *keyBlock = NULL; uint16_t key_cnt = 0; sector_t *e_sector; uint8_t sectors_cnt = MIFARE_1K_MAXSECTOR; @@ -1787,9 +1787,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Load the dictionary if (strlen(filename) != 0) { int res = loadFileDICTIONARY_safe(filename, &keyBlock, 6, &key_cnt); - if (res != PM3_SUCCESS || key_cnt <= 0) { + if (res != PM3_SUCCESS || key_cnt <= 0 || keyBlock == NULL) { PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)"); - free(keyBlock); // free the memory, just in case an allocation happened + if (keyBlock != NULL) free(keyBlock); goto useDefaultKeys; } } else { diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 3802beab9..f256a5ee3 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2128,17 +2128,10 @@ static int CmdT55xxChkPwds(const char *Cmd) { if (use_pwd_file) { uint16_t keycount = 0; - // TODO, a way of reallocating memory if file was larger - keyBlock = calloc(4 * 200, sizeof(uint8_t)); - if (keyBlock == NULL) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); - return PM3_ESOFT; - } - int res = loadFileDICTIONARY_safe(filename, &keyBlock, 4, &keycount); - if (res || keycount == 0) { + if (res || keycount == 0 || keyBlock == NULL) { PrintAndLogEx(WARNING, "No keys found in file"); - free(keyBlock); + if (keyBlock != NULL) free(keyBlock); return PM3_ESOFT; } From ae7b0de2c9965156c3bb692cf627c3a428792430 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 09:49:21 +0200 Subject: [PATCH 132/347] Fixed a typo and added and improved the checks for the returned data of loadFileDICTIONARY_safe. --- client/cmdlft55xx.c | 2 +- client/fileutils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index f256a5ee3..48baea594 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2129,7 +2129,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { uint16_t keycount = 0; int res = loadFileDICTIONARY_safe(filename, &keyBlock, 4, &keycount); - if (res || keycount == 0 || keyBlock == NULL) { + if (res || keycount <= 0 || keyBlock == NULL) { PrintAndLogEx(WARNING, "No keys found in file"); if (keyBlock != NULL) free(keyBlock); return PM3_ESOFT; diff --git a/client/fileutils.h b/client/fileutils.h index b2c16c282..1428c0d8c 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -163,7 +163,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt); /** - * @brief Utility function to load data from a DICTIONARY safely into a textfile. This method takes a preferred name. + * @brief Utility function to load data safely from a DICTIONARY textfile. This method takes a preferred name. * E.g. mfc_default_keys.dic * * @param preferredName From 1ce10cfea6da4d278c93203e7318f17a9d6bfaf5 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 10:09:01 +0200 Subject: [PATCH 133/347] Added additional checks (loadFileDICTIONARY_safe). --- client/cmdlft55xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 48baea594..f17c8e192 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2129,7 +2129,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { uint16_t keycount = 0; int res = loadFileDICTIONARY_safe(filename, &keyBlock, 4, &keycount); - if (res || keycount <= 0 || keyBlock == NULL) { + if (res != PM3_SUCCESS || keycount <= 0 || keyBlock == NULL) { PrintAndLogEx(WARNING, "No keys found in file"); if (keyBlock != NULL) free(keyBlock); return PM3_ESOFT; From 7eb79732ff862ab7cb33db55259ec457c349590d Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 10:38:56 +0200 Subject: [PATCH 134/347] Added security features to the loadFileDICTIONARY_safe function (memset after a realloc). --- client/fileutils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index ff2dc510f..787ce0cfb 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -673,7 +673,7 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k char line[255]; // allocate some space for the dictionary - *data = (uint8_t*) malloc(keylen * allocation_size * sizeof(uint8_t)); + *data = (uint8_t*) calloc(keylen * allocation_size, sizeof(uint8_t)); if (*data == NULL) return PM3_EFILE; FILE *f = fopen(path, "r"); @@ -688,7 +688,12 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k if ((*keycnt) >= allocation_size) { allocation_size += block_size; *data = (uint8_t*) realloc((void*) *data, keylen * allocation_size * sizeof(uint8_t)); - if (*data == NULL) return PM3_EFILE; + if (*data == NULL) { + return PM3_EFILE; + } else { + // zero the new memeory (safety first) + memset(*data + counter, 0, block_size); + } } // add null terminator From e259b26d60b281ad5d25aaa63b34e4611c5d434b Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 10:45:45 +0200 Subject: [PATCH 135/347] Streamlined the naming conventen and types. --- client/cmdhfmf.c | 6 +++++- client/cmdlft55xx.c | 2 +- client/fileutils.c | 14 +++++++------- client/fileutils.h | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 66aca7421..11aded711 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1786,7 +1786,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Load the dictionary if (strlen(filename) != 0) { - int res = loadFileDICTIONARY_safe(filename, &keyBlock, 6, &key_cnt); + int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 6, &key_cnt); if (res != PM3_SUCCESS || key_cnt <= 0 || keyBlock == NULL) { PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)"); if (keyBlock != NULL) free(keyBlock); @@ -1806,6 +1806,10 @@ useDefaultKeys: key_cnt = ARRAYLEN(g_mifare_default_keys); } + for (int k = 0; k < key_cnt; k++) { + PrintAndLogEx(SUCCESS, "ID: %d KEY: %s", k, sprint_hex((keyBlock + (6 * k)), sizeof(key))); + } + // Use the dictionary to find sector keys on the card PrintAndLogEx(INFO, "Enter dictionary run..."); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index f17c8e192..965a5db0b 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2128,7 +2128,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { if (use_pwd_file) { uint16_t keycount = 0; - int res = loadFileDICTIONARY_safe(filename, &keyBlock, 4, &keycount); + int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 4, &keycount); if (res != PM3_SUCCESS || keycount <= 0 || keyBlock == NULL) { PrintAndLogEx(WARNING, "No keys found in file"); if (keyBlock != NULL) free(keyBlock); diff --git a/client/fileutils.c b/client/fileutils.c index 787ce0cfb..1b2073ed2 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -649,7 +649,7 @@ out: return retval; } -int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t keylen, uint16_t *keycnt) { +int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt) { int block_size = 512; int allocation_size = block_size; @@ -673,8 +673,8 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k char line[255]; // allocate some space for the dictionary - *data = (uint8_t*) calloc(keylen * allocation_size, sizeof(uint8_t)); - if (*data == NULL) return PM3_EFILE; + *pdata = calloc(keylen * allocation_size, sizeof(uint8_t)); + if (*pdata == NULL) return PM3_EFILE; FILE *f = fopen(path, "r"); if (!f) { @@ -687,12 +687,12 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k // check if we have enough space (if not allocate more) if ((*keycnt) >= allocation_size) { allocation_size += block_size; - *data = (uint8_t*) realloc((void*) *data, keylen * allocation_size * sizeof(uint8_t)); - if (*data == NULL) { + *pdata = realloc(*pdata, keylen * allocation_size * sizeof(uint8_t)); + if (*pdata == NULL) { return PM3_EFILE; } else { // zero the new memeory (safety first) - memset(*data + counter, 0, block_size); + memset(*pdata + counter, 0, block_size); } } @@ -714,7 +714,7 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k uint64_t key = strtoull(line, NULL, 16); - num_to_bytes(key, keylen >> 1, *data + counter); + num_to_bytes(key, keylen >> 1, *pdata + counter); (*keycnt)++; memset(line, 0, sizeof(line)); counter += (keylen >> 1); diff --git a/client/fileutils.h b/client/fileutils.h index 1428c0d8c..d6392c6b1 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -171,7 +171,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u * @param keylen the number of bytes a key per row is * @return 0 for ok, 1 for failz */ -int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t keylen, uint16_t *keycnt); +int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt); /** * @brief Utility function to check and convert old mfu dump format to new From 7237a9638b16d89ca481febec7d197f86b9bdf02 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 11:19:54 +0200 Subject: [PATCH 136/347] Removed debugging stuff. --- client/cmdhfmf.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 11aded711..0b7727031 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1806,10 +1806,6 @@ useDefaultKeys: key_cnt = ARRAYLEN(g_mifare_default_keys); } - for (int k = 0; k < key_cnt; k++) { - PrintAndLogEx(SUCCESS, "ID: %d KEY: %s", k, sprint_hex((keyBlock + (6 * k)), sizeof(key))); - } - // Use the dictionary to find sector keys on the card PrintAndLogEx(INFO, "Enter dictionary run..."); From 2290b2bd880df92d730493955230889c3835f64c Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 11:30:30 +0200 Subject: [PATCH 137/347] Fixed the description of the loadFileDICTIONARY_safe function. --- client/fileutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/fileutils.h b/client/fileutils.h index d6392c6b1..113cac222 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -167,7 +167,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u * E.g. mfc_default_keys.dic * * @param preferredName - * @param data The data array to store the loaded bytes from file + * @param pdata A pointer to a pointer (for reverencing the loaded dictionary) * @param keylen the number of bytes a key per row is * @return 0 for ok, 1 for failz */ From 5167507a831fb411844aab99ba8888b20e416209 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 12:14:40 +0200 Subject: [PATCH 138/347] Fixed the loadFileDICTIONARY_safe memset alignment. Thanks to @doegox for pointing that out. --- client/fileutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 1b2073ed2..500bb7ef8 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -691,8 +691,8 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key if (*pdata == NULL) { return PM3_EFILE; } else { - // zero the new memeory (safety first) - memset(*pdata + counter, 0, block_size); + // zero the new memory (safety first) + memset(*pdata + allocation_size - block_size, 0, block_size); } } From 6c76e2ed5b99da876572572fc1937fde16bfb22d Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 14:20:52 +0200 Subject: [PATCH 139/347] Restyled to the autopwn command output. --- client/cmdhfmf.c | 66 ++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 0b7727031..ff0324b34 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1733,8 +1733,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(WARNING, "No known key was supplied, key recovery might fail"); else { if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) == PM3_SUCCESS) { - PrintAndLogEx(INFO, "Using key for the nested / hardnested | sector:" - _RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), + PrintAndLogEx(INFO, "Using valid key: sector: %3d key type: %c key: " _YELLOW_("%s") "(used for nested / hardnested attack)", blockNo, keyType ? 'B' : 'A', sprint_hex(key, sizeof(key)) @@ -1745,7 +1744,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { e_sector[blockNo].foundKey[keyType] = 3; } else { know_target_key = false; - PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("%s"), + PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), blockNo, keyType ? 'B' : 'A', sprint_hex(key, sizeof(key)) @@ -1759,11 +1758,6 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, key, &key64) == PM3_SUCCESS) { e_sector[i].Key[j] = bytes_to_num(key, 6); e_sector[i].foundKey[j] = 4; - PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), - i, - j ? 'B' : 'A', - sprint_hex(key, sizeof(key)) - ); // If the user supplied secctor / keytype was wrong --> just be nice and correct it ;) if (know_target_key == false) { @@ -1771,10 +1765,15 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { know_target_key = true; blockNo = i; keyType = j; - PrintAndLogEx(SUCCESS, "using key nested / hardnested attack: sector:" - _RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), - blockNo, - keyType ? 'B' : 'A', + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s") "(used for nested / hardnested attack)", + i, + j ? 'B' : 'A', + sprint_hex(key, sizeof(key)) + ); + } else { + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), + i, + j ? 'B' : 'A', sprint_hex(key, sizeof(key)) ); } @@ -1807,7 +1806,7 @@ useDefaultKeys: } // Use the dictionary to find sector keys on the card - PrintAndLogEx(INFO, "Enter dictionary run..."); + PrintAndLogEx(INFO, _YELLOW_("======================= START DICTIONARY ATTACK =======================")); if (legacy_mfchk) { // Check all the sectors @@ -1862,17 +1861,15 @@ useDefaultKeys: lastChunk = false; } // end strategy } + PrintAndLogEx(INFO, _YELLOW_("======================= STOP DICTIONARY ATTACK =======================")); + // Analyse the dictionary attack for (int i = 0; i < sectors_cnt; i++) { for (int j = 0; j < 2; j++) { if (e_sector[i].foundKey[j] == 1) { num_to_bytes(e_sector[i].Key[j], 6, tmp_key); - PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), - i, - j ? 'B' : 'A', - sprint_hex(tmp_key, sizeof(tmp_key)) - ); + // Store valid credentials for the nested / hardnested attack if none exist if (know_target_key == false) { @@ -1880,11 +1877,16 @@ useDefaultKeys: know_target_key = true; blockNo = i; keyType = j; - PrintAndLogEx(SUCCESS, "Using key nested / hardnested attack: sector:" - _RED_("%3d") " key type:"_RED_("%c") " key: " _RED_("%s"), - blockNo, - keyType ? 'B' : 'A', - sprint_hex(key, sizeof(key)) + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s") "(used for nested / hardnested attack)", + i, + j ? 'B' : 'A', + sprint_hex(tmp_key, sizeof(tmp_key)) + ); + } else { + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), + i, + j ? 'B' : 'A', + sprint_hex(tmp_key, sizeof(tmp_key)) ); } } @@ -1895,8 +1897,9 @@ useDefaultKeys: if (know_target_key == false) { // Check if the darkside attack can be used if (prng_type) { - PrintAndLogEx(INFO, "Enter darkside run..."); + PrintAndLogEx(INFO, _YELLOW_("======================= START DARKSIDE ATTACK =======================")); int isOK = mfDarkside(FirstBlockOfSector(blockNo), keyType, &key64); + PrintAndLogEx(INFO, _YELLOW_("======================= STOP DARKSIDE ATTACK =======================")); switch (isOK) { case -1 : PrintAndLogEx(WARNING, "\nButton pressed. Aborted."); @@ -1932,6 +1935,11 @@ useDefaultKeys: // Store the keys e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); e_sector[blockNo].foundKey[keyType] = 2; + PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s") "(used for nested / hardnested attack)", + blockNo, + keyType ? 'B' : 'A', + sprint_hex(key, sizeof(key)) + ); } else { noValidKeyFound: PrintAndLogEx(FAILED, "No usable key was found!"); @@ -1980,7 +1988,10 @@ noValidKeyFound: if (current_key_type_i == 1) { if (e_sector[current_sector_i].foundKey[0] && !e_sector[current_sector_i].foundKey[1]) { - PrintAndLogEx(INFO, "Reading B key: sector: %3d", current_sector_i); + PrintAndLogEx(INFO, "Reading B key: sector: %3d key type: %c key: ?? ?? ?? ?? ?? ??", + current_sector_i, + current_key_type_i ? 'B' : 'A' + ); uint8_t sectrail = (FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1); mf_readblock_t payload; @@ -2026,6 +2037,7 @@ skipReadBKey: if (prng_type && (! nested_failed)) { uint8_t retries = 0; tryNested: + PrintAndLogEx(INFO, _YELLOW_("======================= START NESTED ATTACK =======================")); PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c", current_sector_i, current_key_type_i ? 'B' : 'A'); @@ -2066,8 +2078,10 @@ tryNested: free(e_sector); return PM3_ESOFT; } + PrintAndLogEx(INFO, _YELLOW_("======================= STOP NESTED ATTACK =======================")); } else { tryHardnested: // If the nested attack fails then we try the hardnested attack + PrintAndLogEx(INFO, _YELLOW_("======================= START HARDNESTED ATTACK =======================")); PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c, Slow: %s", current_sector_i, current_key_type_i ? 'B' : 'A', @@ -2094,6 +2108,8 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack num_to_bytes(foundkey, 6, tmp_key); e_sector[current_sector_i].Key[current_key_type_i] = foundkey; e_sector[current_sector_i].foundKey[current_key_type_i] = 6; + + PrintAndLogEx(INFO, _YELLOW_("======================= STOP HARDNESTED ATTACK =======================")); } // Check if the key was found if (e_sector[current_sector_i].foundKey[current_key_type_i]) { From 2e29b361c540609976f6ad2f3d25e4ec14094937 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 15:57:21 +0200 Subject: [PATCH 140/347] Restyled the autopwn command output according to @doegox --- client/cmdhfmf.c | 85 +++++++++++++++++++++++++++++++----------------- client/cmdhfmf.h | 1 + 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index ff0324b34..66c50758f 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1741,7 +1741,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Store the key for the nested / hardnested attack (if supplied by the user) e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); - e_sector[blockNo].foundKey[keyType] = 3; + e_sector[blockNo].foundKey[keyType] = 'U'; } else { know_target_key = false; PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), @@ -1757,7 +1757,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (e_sector[i].foundKey[j] == 0) { if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, key, &key64) == PM3_SUCCESS) { e_sector[i].Key[j] = bytes_to_num(key, 6); - e_sector[i].foundKey[j] = 4; + e_sector[i].foundKey[j] = 'U'; // If the user supplied secctor / keytype was wrong --> just be nice and correct it ;) if (know_target_key == false) { @@ -1819,7 +1819,7 @@ useDefaultKeys: fflush(stdout); if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, (keyBlock + (6 * k)), &key64) == PM3_SUCCESS) { e_sector[i].Key[j] = bytes_to_num((keyBlock + (6 * k)), 6); - e_sector[i].foundKey[j] = 1; + e_sector[i].foundKey[j] = 'D'; break; } } @@ -1868,6 +1868,7 @@ useDefaultKeys: for (int i = 0; i < sectors_cnt; i++) { for (int j = 0; j < 2; j++) { if (e_sector[i].foundKey[j] == 1) { + e_sector[i].foundKey[j] = 'D'; num_to_bytes(e_sector[i].Key[j], 6, tmp_key); @@ -1934,7 +1935,7 @@ useDefaultKeys: } // Store the keys e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); - e_sector[blockNo].foundKey[keyType] = 2; + e_sector[blockNo].foundKey[keyType] = 'S'; PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s") "(used for nested / hardnested attack)", blockNo, keyType ? 'B' : 'A', @@ -1973,7 +1974,7 @@ noValidKeyFound: // Check if the key works if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, tmp_key, &key64) == PM3_SUCCESS) { e_sector[i].Key[j] = bytes_to_num(tmp_key, 6); - e_sector[i].foundKey[j] = 4; + e_sector[i].foundKey[j] = 'R'; PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), i, j ? 'B' : 'A', @@ -1988,7 +1989,7 @@ noValidKeyFound: if (current_key_type_i == 1) { if (e_sector[current_sector_i].foundKey[0] && !e_sector[current_sector_i].foundKey[1]) { - PrintAndLogEx(INFO, "Reading B key: sector: %3d key type: %c key: ?? ?? ?? ?? ?? ??", + PrintAndLogEx(INFO, "Reading B key: sector: %3d key type: %c", current_sector_i, current_key_type_i ? 'B' : 'A' ); @@ -2010,16 +2011,8 @@ noValidKeyFound: uint8_t *data = resp.data.asBytes; key64 = bytes_to_num(data + 10, 6); - if (verbose){ - num_to_bytes(key64, 6, tmp_key); - PrintAndLogEx(INFO, "Discovered key: sector: %3d key type: %c key: " _YELLOW_("%s"), - current_sector_i, - current_key_type_i ? 'B' : 'A', - sprint_hex(tmp_key, sizeof(tmp_key)) - ); - } if (key64) { - e_sector[current_sector_i].foundKey[current_key_type_i] = 7; + e_sector[current_sector_i].foundKey[current_key_type_i] = 'A'; e_sector[current_sector_i].Key[current_key_type_i] = key64; num_to_bytes(key64, 6, tmp_key); PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), @@ -2027,6 +2020,11 @@ noValidKeyFound: current_key_type_i ? 'B' : 'A', sprint_hex(tmp_key, sizeof(tmp_key)) ); + } else { + PrintAndLogEx(WARNING, "Unknown B key: sector: %3d key type: %c (reading the B key was not possible, maybe due to insufficient access rights) ", + current_sector_i, + current_key_type_i ? 'B' : 'A' + ); } } } @@ -2036,8 +2034,9 @@ skipReadBKey: if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { if (prng_type && (! nested_failed)) { uint8_t retries = 0; -tryNested: PrintAndLogEx(INFO, _YELLOW_("======================= START NESTED ATTACK =======================")); + +tryNested: PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c", current_sector_i, current_key_type_i ? 'B' : 'A'); @@ -2071,7 +2070,7 @@ tryNested: case -5 : calibrate = false; e_sector[current_sector_i].Key[current_key_type_i] = bytes_to_num(tmp_key, 6); - e_sector[current_sector_i].foundKey[current_key_type_i] = 5; + e_sector[current_sector_i].foundKey[current_key_type_i] = 'N'; break; default : PrintAndLogEx(ERR, "unknown Error.\n"); @@ -2107,7 +2106,7 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack // Copy the found key to the tmp_key variale (for the following print statement, and the mfCheckKeys above) num_to_bytes(foundkey, 6, tmp_key); e_sector[current_sector_i].Key[current_key_type_i] = foundkey; - e_sector[current_sector_i].foundKey[current_key_type_i] = 6; + e_sector[current_sector_i].foundKey[current_key_type_i] = 'H'; PrintAndLogEx(INFO, _YELLOW_("======================= STOP HARDNESTED ATTACK =======================")); } @@ -2127,20 +2126,9 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack // Show the results to the user PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "Found Keys:"); - printKeyTable(sectors_cnt, e_sector); - if (verbose) { - PrintAndLogEx(INFO, " Key res types:"); - PrintAndLogEx(INFO, " 1: Dictionary"); - PrintAndLogEx(INFO, " 2: Darkside attack"); - PrintAndLogEx(INFO, " 3: User supplied"); - PrintAndLogEx(INFO, " 4: Reused"); - PrintAndLogEx(INFO, " 5: Nested"); - PrintAndLogEx(INFO, " 6: Hardnested"); - PrintAndLogEx(INFO, " 7: Read B key with A key"); - } + printKeyTableAutopwn(sectors_cnt, e_sector); PrintAndLogEx(INFO, "\nSaving keys"); - createMfcKeyDump(sectors_cnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); PrintAndLogEx(SUCCESS, "Transferring keys to simulator memory (Cmd Error: 04 can occur)"); @@ -3198,6 +3186,43 @@ void printKeyTable(uint8_t sectorscnt, sector_t *e_sector) { PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); } +void printKeyTableAutopwn(uint8_t sectorscnt, sector_t *e_sector) { + char strA[12 + 1] = {0}; + char strB[12 + 1] = {0}; + PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); + PrintAndLogEx(NORMAL, "|sec|key A |res|key B |res|"); + PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); + for (uint8_t i = 0; i < sectorscnt; ++i) { + + snprintf(strA, sizeof(strA), "------------"); + snprintf(strB, sizeof(strB), "------------"); + + if (e_sector[i].foundKey[0]) + snprintf(strA, sizeof(strA), "%012" PRIx64, e_sector[i].Key[0]); + + if (e_sector[i].foundKey[1]) + snprintf(strB, sizeof(strB), "%012" PRIx64, e_sector[i].Key[1]); + + + PrintAndLogEx(NORMAL, "|%03d| %s | " _YELLOW_("%c")"| %s | " _YELLOW_("%c")"|" + , i + , strA, e_sector[i].foundKey[0] + , strB, e_sector[i].foundKey[1] + ); + } + PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); + PrintAndLogEx(NORMAL, "( " + _YELLOW_("D") ":Dictionary / " + _YELLOW_("S") ":darkSide / " + _YELLOW_("U") ":User / " + _YELLOW_("R") ":Reused / " + _YELLOW_("N") ":Nested / " + _YELLOW_("H") ":Hardnested / " + _YELLOW_("A") ":keyA " + ")" + ); +} + // EMULATOR COMMANDS static int CmdHF14AMfEGet(const char *Cmd) { char c = tolower(param_getchar(Cmd, 0)); diff --git a/client/cmdhfmf.h b/client/cmdhfmf.h index 55997bd87..e9970cfb2 100644 --- a/client/cmdhfmf.h +++ b/client/cmdhfmf.h @@ -22,5 +22,6 @@ int CmdHF14AMfDbg(const char *Cmd); // used by cmd hf mfu dbg void showSectorTable(void); void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose); void printKeyTable(uint8_t sectorscnt, sector_t *e_sector); +void printKeyTableAutopwn(uint8_t sectorscnt, sector_t *e_sector); void printKeyTable_fast(uint8_t sectorscnt, icesector_t *e_sector, uint64_t bar, uint64_t foo); #endif From e4159b7cb3f5ae57d62aeb8cb9c43648ed8f7582 Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 18:39:01 +0200 Subject: [PATCH 141/347] Cleaned up the ouput to be as minimalistic as possible. Now the verbose flag output is realy verbose. --- client/cmdhfmf.c | 127 +++++++++++++++++++++++++---------------------- client/cmdhfmf.h | 1 - 2 files changed, 67 insertions(+), 61 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 66c50758f..aed756278 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1715,6 +1715,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // print parameters if (verbose) { + PrintAndLogEx(INFO, _YELLOW_("======================= SETTINGS =======================")); PrintAndLogEx(INFO, " card sectors .. " _YELLOW_("%d"), sectors_cnt); PrintAndLogEx(INFO, " key supplied .. " _YELLOW_("%s"), know_target_key ? "True" : "False"); PrintAndLogEx(INFO, " known sector .. " _YELLOW_("%d"), blockNo); @@ -1723,6 +1724,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(INFO, " card PRNG ..... " _YELLOW_("%s"), prng_type ? "WEAK" : "HARD"); PrintAndLogEx(INFO, " dictionary .... " _YELLOW_("%s"), strlen(filename) ? filename : "NONE"); PrintAndLogEx(INFO, " legacy mode ... " _YELLOW_("%s"), legacy_mfchk ? "True" : "False"); + PrintAndLogEx(INFO, _YELLOW_("======================= SETTINGS =======================")); } // Start the timer @@ -1732,6 +1734,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (know_target_key == false) PrintAndLogEx(WARNING, "No known key was supplied, key recovery might fail"); else { + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= START KNOWN KEY ATTACK =======================")); if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) == PM3_SUCCESS) { PrintAndLogEx(INFO, "Using valid key: sector: %3d key type: %c key: " _YELLOW_("%s") "(used for nested / hardnested attack)", blockNo, @@ -1781,6 +1784,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } } } + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP KNOWN KEY ATTACK =======================")); } // Load the dictionary @@ -1806,7 +1810,7 @@ useDefaultKeys: } // Use the dictionary to find sector keys on the card - PrintAndLogEx(INFO, _YELLOW_("======================= START DICTIONARY ATTACK =======================")); + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= START DICTIONARY ATTACK =======================")); if (legacy_mfchk) { // Check all the sectors @@ -1861,7 +1865,7 @@ useDefaultKeys: lastChunk = false; } // end strategy } - PrintAndLogEx(INFO, _YELLOW_("======================= STOP DICTIONARY ATTACK =======================")); + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP DICTIONARY ATTACK =======================")); // Analyse the dictionary attack @@ -1898,9 +1902,9 @@ useDefaultKeys: if (know_target_key == false) { // Check if the darkside attack can be used if (prng_type) { - PrintAndLogEx(INFO, _YELLOW_("======================= START DARKSIDE ATTACK =======================")); + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= START DARKSIDE ATTACK =======================")); int isOK = mfDarkside(FirstBlockOfSector(blockNo), keyType, &key64); - PrintAndLogEx(INFO, _YELLOW_("======================= STOP DARKSIDE ATTACK =======================")); + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP DARKSIDE ATTACK =======================")); switch (isOK) { case -1 : PrintAndLogEx(WARNING, "\nButton pressed. Aborted."); @@ -1989,10 +1993,12 @@ noValidKeyFound: if (current_key_type_i == 1) { if (e_sector[current_sector_i].foundKey[0] && !e_sector[current_sector_i].foundKey[1]) { - PrintAndLogEx(INFO, "Reading B key: sector: %3d key type: %c", - current_sector_i, - current_key_type_i ? 'B' : 'A' - ); + if (verbose) { + PrintAndLogEx(INFO, _YELLOW_("======================= START READ B KEY ATTACK =======================")); + PrintAndLogEx(INFO, "Reading B key: sector: %3d key type: %c", + current_sector_i, + current_key_type_i ? 'B' : 'A'); + } uint8_t sectrail = (FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1); mf_readblock_t payload; @@ -2021,11 +2027,12 @@ noValidKeyFound: sprint_hex(tmp_key, sizeof(tmp_key)) ); } else { - PrintAndLogEx(WARNING, "Unknown B key: sector: %3d key type: %c (reading the B key was not possible, maybe due to insufficient access rights) ", + if (verbose) PrintAndLogEx(WARNING, "Unknown B key: sector: %3d key type: %c (reading the B key was not possible, maybe due to insufficient access rights) ", current_sector_i, current_key_type_i ? 'B' : 'A' ); } + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP READ B KEY ATTACK =======================")); } } @@ -2034,13 +2041,13 @@ skipReadBKey: if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) { if (prng_type && (! nested_failed)) { uint8_t retries = 0; - PrintAndLogEx(INFO, _YELLOW_("======================= START NESTED ATTACK =======================")); - + if (verbose) { + PrintAndLogEx(INFO, _YELLOW_("======================= START NESTED ATTACK =======================")); + PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c", + current_sector_i, + current_key_type_i ? 'B' : 'A'); + } tryNested: - PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c", - current_sector_i, - current_key_type_i ? 'B' : 'A'); - isOK = mfnested(FirstBlockOfSector(blockNo), keyType, key, FirstBlockOfSector(current_sector_i), current_key_type_i, tmp_key, calibrate); switch (isOK) { case -1 : @@ -2077,14 +2084,16 @@ tryNested: free(e_sector); return PM3_ESOFT; } - PrintAndLogEx(INFO, _YELLOW_("======================= STOP NESTED ATTACK =======================")); + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP NESTED ATTACK =======================")); } else { tryHardnested: // If the nested attack fails then we try the hardnested attack - PrintAndLogEx(INFO, _YELLOW_("======================= START HARDNESTED ATTACK =======================")); - PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c, Slow: %s", - current_sector_i, - current_key_type_i ? 'B' : 'A', - slow ? "Yes" : "No"); + if (verbose) { + PrintAndLogEx(INFO, _YELLOW_("======================= START HARDNESTED ATTACK =======================")); + PrintAndLogEx(INFO, "Sector no: %3d, target key type: %c, Slow: %s", + current_sector_i, + current_key_type_i ? 'B' : 'A', + slow ? "Yes" : "No"); + } isOK = mfnestedhard(FirstBlockOfSector(blockNo), keyType, key, FirstBlockOfSector(current_sector_i), current_key_type_i, NULL, false, false, slow, 0, &foundkey, NULL); DropField(); @@ -2108,7 +2117,7 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack e_sector[current_sector_i].Key[current_key_type_i] = foundkey; e_sector[current_sector_i].foundKey[current_key_type_i] = 'H'; - PrintAndLogEx(INFO, _YELLOW_("======================= STOP HARDNESTED ATTACK =======================")); + if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP HARDNESTED ATTACK =======================")); } // Check if the key was found if (e_sector[current_sector_i].foundKey[current_key_type_i]) { @@ -2126,8 +2135,43 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack // Show the results to the user PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "Found Keys:"); - printKeyTableAutopwn(sectors_cnt, e_sector); + char strA[12 + 1] = {0}; + char strB[12 + 1] = {0}; + PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); + PrintAndLogEx(NORMAL, "|sec|key A |res|key B |res|"); + PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); + for (uint8_t i = 0; i < sectors_cnt; ++i) { + + snprintf(strA, sizeof(strA), "------------"); + snprintf(strB, sizeof(strB), "------------"); + + if (e_sector[i].foundKey[0]) + snprintf(strA, sizeof(strA), "%012" PRIx64, e_sector[i].Key[0]); + + if (e_sector[i].foundKey[1]) + snprintf(strB, sizeof(strB), "%012" PRIx64, e_sector[i].Key[1]); + + + PrintAndLogEx(NORMAL, "|%03d| %s | " _YELLOW_("%c")"| %s | " _YELLOW_("%c")"|" + , i + , strA, e_sector[i].foundKey[0] + , strB, e_sector[i].foundKey[1] + ); + } + PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); + PrintAndLogEx(NORMAL, "( " + _YELLOW_("D") ":Dictionary / " + _YELLOW_("S") ":darkSide / " + _YELLOW_("U") ":User / " + _YELLOW_("R") ":Reused / " + _YELLOW_("N") ":Nested / " + _YELLOW_("H") ":Hardnested / " + _YELLOW_("A") ":keyA " + ")" + ); + + // Dump the keys PrintAndLogEx(INFO, "\nSaving keys"); createMfcKeyDump(sectors_cnt, e_sector, GenerateFilename("hf-mf-", "-key.bin")); @@ -3186,43 +3230,6 @@ void printKeyTable(uint8_t sectorscnt, sector_t *e_sector) { PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); } -void printKeyTableAutopwn(uint8_t sectorscnt, sector_t *e_sector) { - char strA[12 + 1] = {0}; - char strB[12 + 1] = {0}; - PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); - PrintAndLogEx(NORMAL, "|sec|key A |res|key B |res|"); - PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); - for (uint8_t i = 0; i < sectorscnt; ++i) { - - snprintf(strA, sizeof(strA), "------------"); - snprintf(strB, sizeof(strB), "------------"); - - if (e_sector[i].foundKey[0]) - snprintf(strA, sizeof(strA), "%012" PRIx64, e_sector[i].Key[0]); - - if (e_sector[i].foundKey[1]) - snprintf(strB, sizeof(strB), "%012" PRIx64, e_sector[i].Key[1]); - - - PrintAndLogEx(NORMAL, "|%03d| %s | " _YELLOW_("%c")"| %s | " _YELLOW_("%c")"|" - , i - , strA, e_sector[i].foundKey[0] - , strB, e_sector[i].foundKey[1] - ); - } - PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); - PrintAndLogEx(NORMAL, "( " - _YELLOW_("D") ":Dictionary / " - _YELLOW_("S") ":darkSide / " - _YELLOW_("U") ":User / " - _YELLOW_("R") ":Reused / " - _YELLOW_("N") ":Nested / " - _YELLOW_("H") ":Hardnested / " - _YELLOW_("A") ":keyA " - ")" - ); -} - // EMULATOR COMMANDS static int CmdHF14AMfEGet(const char *Cmd) { char c = tolower(param_getchar(Cmd, 0)); diff --git a/client/cmdhfmf.h b/client/cmdhfmf.h index e9970cfb2..55997bd87 100644 --- a/client/cmdhfmf.h +++ b/client/cmdhfmf.h @@ -22,6 +22,5 @@ int CmdHF14AMfDbg(const char *Cmd); // used by cmd hf mfu dbg void showSectorTable(void); void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose); void printKeyTable(uint8_t sectorscnt, sector_t *e_sector); -void printKeyTableAutopwn(uint8_t sectorscnt, sector_t *e_sector); void printKeyTable_fast(uint8_t sectorscnt, icesector_t *e_sector, uint64_t bar, uint64_t foo); #endif From cbca61f6ba3e0e301c07abed6cd405150a230661 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 28 Aug 2019 19:25:15 +0200 Subject: [PATCH 142/347] searchAndList: hide temptative repo path --- client/fileutils.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 500bb7ef8..31e0aeed5 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -759,13 +759,14 @@ int convertOldMfuDump(uint8_t **dump, size_t *dumplen) { return PM3_SUCCESS; } -static int filelist(const char *path, const char *ext, bool last) { +static int filelist(const char *path, const char *ext, bool last, bool tentative) { struct dirent **namelist; int n; n = scandir(path, &namelist, NULL, alphasort); if (n == -1) { - PrintAndLogEx(NORMAL, "%s── %s => NOT FOUND", last ? "└" : "├", path); + if (!tentative) + PrintAndLogEx(NORMAL, "%s── %s", last ? "└" : "├", path); return PM3_EFILE; } @@ -781,25 +782,29 @@ static int filelist(const char *path, const char *ext, bool last) { } int searchAndList(const char *pm3dir, const char *ext) { + // display in same order as searched by searchFile + // try pm3 dirs in current workdir (dev mode) if (get_my_executable_directory() != NULL) { char script_directory_path[strlen(get_my_executable_directory()) + strlen(pm3dir) + 1]; strcpy(script_directory_path, get_my_executable_directory()); strcat(script_directory_path, pm3dir); - filelist(script_directory_path, ext, false); + filelist(script_directory_path, ext, false, true); } + // try pm3 dirs in user .proxmark3 (user mode) char *userpath = getenv("HOME"); if (userpath != NULL) { char script_directory_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + 1]; strcpy(script_directory_path, userpath); strcat(script_directory_path, PM3_USER_DIRECTORY); strcat(script_directory_path, pm3dir); - filelist(script_directory_path, ext, false); + filelist(script_directory_path, ext, false, false); } + // try pm3 dirs in pm3 installation dir (install mode) { char script_directory_path[strlen(PM3_SHARE_PATH) + strlen(pm3dir) + 1]; strcpy(script_directory_path, PM3_SHARE_PATH); strcat(script_directory_path, pm3dir); - filelist(script_directory_path, ext, true); + filelist(script_directory_path, ext, true, false); } return PM3_SUCCESS; } From 94f6a402e8d457130d6654953527d490e48a4671 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:12:18 +0200 Subject: [PATCH 143/347] chg. prep for eload.. --- include/pm3_cmd.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 035e85405..dc48bd110 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -229,6 +229,10 @@ typedef struct { uint8_t key[6]; } PACKED mf_readblock_t; +typedef struct { + uint8_t sectorcnt; + uint8_t keytype; +} PACKED mfc_eload_t; // For the bootloader #define CMD_DEVICE_INFO 0x0000 From f3ab9632f058618720f006e8095639ef2ecc89ef Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:12:32 +0200 Subject: [PATCH 144/347] return values --- client/mifare/mifarehost.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index d22073d02..54de89046 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -209,7 +209,8 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk, // initialize storage for found keys icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t)); if (tmp == NULL) - return 1; + return PM3_EMALLOC; + memcpy(tmp, resp.data.asBytes, sectorsCnt * sizeof(icesector_t)); for (int i = 0; i < sectorsCnt; i++) { @@ -227,11 +228,11 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk, free(tmp); if (curr_keys == sectorsCnt * 2) - return 0; + return PM3_SUCCESS; if (lastChunk) - return 1; + return PM3_ESOFT; } - return 1; + return PM3_ESOFT; } // PM3 imp of J-Run mf_key_brute (part 2) From ad3fe38b45fe808fdb9fa9c6d888da3975f32d51 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:15:32 +0200 Subject: [PATCH 145/347] fix: loaddictionary_save, now with correct mem clear. --- client/fileutils.c | 68 +++++++++++++++++++++++++--------------------- client/fileutils.h | 7 +++++ 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 31e0aeed5..c3c9f5acc 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -283,9 +283,9 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s } case jsfIclass: { JsonSaveStr(root, "FileType", "iclass"); - uint8_t uid[8] = {0}; - memcpy(uid, data, 8); - JsonSaveBufAsHexCompact(root, "$.Card.UID", uid, sizeof(uid)); + uint8_t csn[8] = {0}; + memcpy(csn, data, 8); + JsonSaveBufAsHexCompact(root, "$.Card.CSN", csn, sizeof(csn)); for (size_t i = 0; i < (datalen / 8); i++) { char path[PATH_MAX_LENGTH] = {0}; @@ -316,13 +316,13 @@ int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char *fptr) { int i; if (fptr == NULL) { - return 1; + return PM3_EINVARG; } FILE *fkeys = fopen(fptr, "wb"); if (fkeys == NULL) { PrintAndLogEx(WARNING, "Could not create file " _YELLOW_("%s"), fptr); - return 1; + return PM3_EFILE; } PrintAndLogEx(SUCCESS, "Printing keys to binary file " _YELLOW_("%s")"...", fptr); @@ -338,14 +338,14 @@ int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char *fptr) { fclose(fkeys); PrintAndLogEx(SUCCESS, "Found keys have been dumped to " _YELLOW_("%s")" --> 0xffffffffffff has been inserted for unknown keys.", fptr); - return 0; + return PM3_SUCCESS; } int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen) { if (data == NULL) return 1; char *fileName = filenamemcopy(preferredName, suffix); - if (fileName == NULL) return 1; + if (fileName == NULL) return PM3_EINVARG; int retval = PM3_SUCCESS; @@ -363,23 +363,24 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m if (fsize <= 0) { PrintAndLogEx(FAILED, "error, when getting filesize"); - retval = 1; + retval = PM3_EFILE; goto out; } uint8_t *dump = calloc(fsize, sizeof(uint8_t)); if (!dump) { PrintAndLogEx(FAILED, "error, cannot allocate memory"); - retval = 2; + retval = PM3_EMALLOC; goto out; } size_t bytes_read = fread(dump, 1, fsize, f); + fclose(f); if (bytes_read != fsize) { PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); free(dump); - retval = 3; + retval = PM3_EFILE; goto out; } @@ -396,9 +397,7 @@ int loadFile(const char *preferredName, const char *suffix, void *data, size_t m *datalen = bytes_read; out: - fclose(f); free(fileName); - return retval; } @@ -432,7 +431,7 @@ int loadFileEML(const char *preferredName, void *data, size_t *datalen) { break; fclose(f); PrintAndLogEx(FAILED, "File reading error."); - retval = 2; + retval = PM3_EFILE; goto out; } @@ -471,13 +470,13 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ root = json_load_file(fileName, 0, &error); if (!root) { PrintAndLogEx(ERR, "ERROR: json " _YELLOW_("%s") " error on line %d: %s", fileName, error.line, error.text); - retval = 2; + retval = PM3_ESOFT; goto out; } if (!json_is_object(root)) { PrintAndLogEx(ERR, "ERROR: Invalid json " _YELLOW_("%s") " format. root must be an object.", fileName); - retval = 3; + retval = PM3_ESOFT; goto out; } @@ -493,7 +492,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ size_t sptr = 0; for (int i = 0; i < 256; i++) { if (sptr + 16 > maxdatalen) { - retval = 5; + retval = PM3_EMALLOC; goto out; } @@ -515,7 +514,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ size_t sptr = 0; for (int i = 0; i < 256; i++) { if (sptr + 4 > maxdatalen) { - retval = 5; + retval = PM3_EMALLOC; goto out; } @@ -537,7 +536,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ size_t sptr = 0; for (size_t i = 0; i < (maxdatalen / 4); i++) { if (sptr + 4 > maxdatalen) { - retval = 5; + retval = PM3_EMALLOC; goto out; } @@ -559,7 +558,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ size_t sptr = 0; for (size_t i = 0; i < (maxdatalen / 8); i++) { if (sptr + 8 > maxdatalen) { - retval = 5; + retval = PM3_EMALLOC; goto out; } @@ -651,10 +650,8 @@ out: int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt) { - int block_size = 512; - int allocation_size = block_size; - size_t counter = 0; int retval = PM3_SUCCESS; + char *path; if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic") != PM3_SUCCESS) return PM3_EFILE; @@ -667,14 +664,20 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key keylen = 6; } + size_t mem_size; + size_t block_size = 10 * keylen; + // double up since its chars keylen <<= 1; char line[255]; // allocate some space for the dictionary - *pdata = calloc(keylen * allocation_size, sizeof(uint8_t)); - if (*pdata == NULL) return PM3_EFILE; + *pdata = calloc( block_size , sizeof(uint8_t)); + if (*pdata == NULL) + return PM3_EFILE; + + mem_size = block_size; FILE *f = fopen(path, "r"); if (!f) { @@ -684,15 +687,17 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key // read file while (fgets(line, sizeof(line), f)) { + // check if we have enough space (if not allocate more) - if ((*keycnt) >= allocation_size) { - allocation_size += block_size; - *pdata = realloc(*pdata, keylen * allocation_size * sizeof(uint8_t)); + if ( (*keycnt * (keylen >> 1) ) >= mem_size ) { + + mem_size += block_size; + *pdata = realloc(*pdata, mem_size); + if (*pdata == NULL) { return PM3_EFILE; } else { - // zero the new memory (safety first) - memset(*pdata + allocation_size - block_size, 0, block_size); + memset(*pdata + (mem_size - block_size), 0, block_size); } } @@ -714,10 +719,11 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key uint64_t key = strtoull(line, NULL, 16); - num_to_bytes(key, keylen >> 1, *pdata + counter); + num_to_bytes(key, keylen >> 1, *pdata + (*keycnt * (keylen >> 1)) ); + (*keycnt)++; + memset(line, 0, sizeof(line)); - counter += (keylen >> 1); } fclose(f); PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from dictionary file " _YELLOW_("%s"), *keycnt, path); diff --git a/client/fileutils.h b/client/fileutils.h index 113cac222..7bfc7c138 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -62,6 +62,13 @@ typedef enum { // jsfT55xx, } JSONFileType; +typedef enum { + BIN = 0, + EML, + JSON, + DICTIONARY, +} DumpFileType_t; + int fileExists(const char *filename); /** From 8d9751ebe42fc2912e86c01109e417e1ead5a09f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:16:09 +0200 Subject: [PATCH 146/347] fix: uint cant be negative.. --- client/cmdlft55xx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 965a5db0b..46cc3e017 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2129,9 +2129,11 @@ static int CmdT55xxChkPwds(const char *Cmd) { uint16_t keycount = 0; int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 4, &keycount); - if (res != PM3_SUCCESS || keycount <= 0 || keyBlock == NULL) { + if (res != PM3_SUCCESS || keycount == 0 || keyBlock == NULL) { PrintAndLogEx(WARNING, "No keys found in file"); - if (keyBlock != NULL) free(keyBlock); + if (keyBlock != NULL) + free(keyBlock); + return PM3_ESOFT; } From 117ebf0beb618732e797dd3752638bc9e5c1ed6b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:21:27 +0200 Subject: [PATCH 147/347] chg: 'hf mf ecfill' - now uses NG format. chg: 'hf mf eload' - now uses NG format. chg: 'hf mf fchk m' - now uses ecfill trick, if fchk got all keys, it will dump the card directly. sample: hf mf fchk 1 m (must have dictionaries uploaded to device) if all keys are found, you can now run hf mf esave to get a complete dump. --- client/cmdhfmf.c | 160 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 119 insertions(+), 41 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 0b7727031..cc435cb07 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -751,12 +751,56 @@ static uint8_t NumBlocksPerSector(uint8_t sectorNo) { return 16; } } + static uint8_t GetSectorFromBlockNo(uint8_t blockNo) { if (blockNo < 128) return blockNo / 4; else return 32 + ((128 - blockNo) / 16); } + +static char GetFormatFromSector(uint8_t sectorNo) { + switch (sectorNo) { + case MIFARE_MINI_MAXSECTOR: + return '0'; + case MIFARE_1K_MAXSECTOR: + return '1'; + case MIFARE_2K_MAXSECTOR: + return '2'; + case MIFARE_4K_MAXSECTOR: + return '4'; + default : + return ' '; + } +} + +static int FastDumpWithEcFill(uint8_t numsectors){ + PacketResponseNG resp; + + mfc_eload_t payload; + payload.sectorcnt = numsectors; + payload.keytype = 0; + + // ecfill key A + clearCommandBuffer(); + SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); + + int res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000); + if ( res != PM3_SUCCESS) { + } + + // ecfill key B + payload.keytype = 1; + + clearCommandBuffer(); + SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); + res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000); + if ( res != PM3_SUCCESS) { + + } + return PM3_SUCCESS; +} + static int CmdHF14AMfDump(const char *Cmd) { uint64_t t1 = msclock(); @@ -1242,7 +1286,12 @@ static int CmdHF14AMfNested(const char *Cmd) { } PrintAndLogEx(SUCCESS, "Testing known keys. Sector count=%d", SectorsCnt); - mfCheckKeys_fast(SectorsCnt, true, true, 1, ARRAYLEN(g_mifare_default_keys) + 1, keyBlock, e_sector, false); + int res = mfCheckKeys_fast(SectorsCnt, true, true, 1, ARRAYLEN(g_mifare_default_keys) + 1, keyBlock, e_sector, false); + if ( res == PM3_SUCCESS ) { + // all keys found + PrintAndLogEx(SUCCESS, "Fast check found all keys"); + goto jumptoend; + } uint64_t t2 = msclock() - t1; PrintAndLogEx(SUCCESS, "Time to check %d known keys: %.0f seconds\n", ARRAYLEN(g_mifare_default_keys), (float)t2 / 1000.0); @@ -1329,6 +1378,7 @@ static int CmdHF14AMfNested(const char *Cmd) { } } +jumptoend: //print them printKeyTable(SectorsCnt, e_sector); @@ -1612,56 +1662,69 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { bool legacy_mfchk = false; bool prng_type = false; bool verbose = false; + bool has_filename = false; + bool errors = false; // Parse the options given by the user - ctmp = tolower(param_getchar(Cmd, 0)); - while ((ctmp = param_getchar(Cmd, cmdp))) { + while ( (ctmp = param_getchar(Cmd, cmdp)) && !errors ) { switch (tolower(ctmp)) { case 'h': return usage_hf14_autopwn(); case 'f': if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "Filename too long"); + errors = true; + } else { + has_filename = true; } - cmdp ++; + cmdp += 2; break; case 'l': legacy_mfchk = true; + cmdp++; break; case 'v': verbose = true; + cmdp++; break; case '*': // Get the number of sectors sectors_cnt = NumOfSectors(param_getchar(Cmd, cmdp + 1)); block_cnt = NumOfBlocks(param_getchar(Cmd, cmdp + 1)); - cmdp ++; + cmdp += 2; break; case 'k': // Get the known block number if (param_getchar(Cmd, cmdp + 1) == 0x00) { - PrintAndLogEx(WARNING, "Sector number is missing"); - return PM3_EINVARG; + errors = true; + break; } + blockNo = param_get8(Cmd, cmdp + 1); + // Get the knonwn block type ctmp = tolower(param_getchar(Cmd, cmdp + 2)); if (ctmp != 'a' && ctmp != 'b') { PrintAndLogEx(WARNING, "Key type must be A or B"); - return PM3_EINVARG; + errors = true; + break; } + if (ctmp != 'a') { keyType = 1; } + // Get the known block key if (param_gethex(Cmd, cmdp + 3, key, 12)) { PrintAndLogEx(WARNING, "Key must include 12 HEX symbols"); + errors = true; return PM3_EINVARG; } know_target_key = true; cmdp += 3; case 's': slow = true; + cmdp++; break; case 'i': SetSIMDInstr(SIMD_AUTO); @@ -1695,7 +1758,10 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", ctmp); return usage_hf14_autopwn(); } - cmdp++; + } + + if ( errors ) { + return usage_hf14_autopwn(); } // Create the key storage stucture @@ -1732,6 +1798,8 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (know_target_key == false) PrintAndLogEx(WARNING, "No known key was supplied, key recovery might fail"); else { + + PrintAndLogEx(INFO, "Validating known key"); if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) == PM3_SUCCESS) { PrintAndLogEx(INFO, "Using key for the nested / hardnested | sector:" _RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), @@ -1741,7 +1809,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { ); // Store the key for the nested / hardnested attack (if supplied by the user) - e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); + e_sector[blockNo].Key[keyType] = key64; e_sector[blockNo].foundKey[keyType] = 3; } else { know_target_key = false; @@ -1752,6 +1820,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { ); PrintAndLogEx(WARNING, "Falling back to dictionary"); } + // Check if the user supplied key is used by other sectors for (int i = 0; i < sectors_cnt; i++) { for (int j = 0; j < 2; j++) { @@ -1759,7 +1828,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, key, &key64) == PM3_SUCCESS) { e_sector[i].Key[j] = bytes_to_num(key, 6); e_sector[i].foundKey[j] = 4; - PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), + PrintAndLogEx(SUCCESS, "target sector:%3u key type: %c -- found valid key [" _YELLOW_("%s") "]", i, j ? 'B' : 'A', sprint_hex(key, sizeof(key)) @@ -1784,16 +1853,21 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } } + bool load_success = true; // Load the dictionary - if (strlen(filename) != 0) { + if (has_filename) { int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 6, &key_cnt); - if (res != PM3_SUCCESS || key_cnt <= 0 || keyBlock == NULL) { + if (res != PM3_SUCCESS || key_cnt == 0 || keyBlock == NULL) { PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)"); - if (keyBlock != NULL) free(keyBlock); - goto useDefaultKeys; + if (keyBlock != NULL) + free(keyBlock); + + load_success = false; } - } else { -useDefaultKeys: + + } + + if ( has_filename == false || load_success == false ) { keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); if (keyBlock == NULL) { free(e_sector); @@ -1804,6 +1878,7 @@ useDefaultKeys: num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); } key_cnt = ARRAYLEN(g_mifare_default_keys); + PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from hardcoded default array", key_cnt); } // Use the dictionary to find sector keys on the card @@ -1830,8 +1905,10 @@ useDefaultKeys: printf("\n"); fflush(stdout); } else { + int chunksize = key_cnt > (PM3_CMD_DATA_SIZE / 6) ? (PM3_CMD_DATA_SIZE / 6) : key_cnt; bool firstChunk = true, lastChunk = false; + for (uint8_t strategy = 1; strategy < 3; strategy++) { PrintAndLogEx(INFO, "Running strategy %u", strategy); // main keychunk loop @@ -1852,7 +1929,7 @@ useDefaultKeys: if (firstChunk) firstChunk = false; // all keys, aborted - if (res == 0 || res == 2) { + if (res == PM3_SUCCESS) { i = key_cnt; strategy = 3; break; // Exit the loop @@ -1866,9 +1943,9 @@ useDefaultKeys: // Analyse the dictionary attack for (int i = 0; i < sectors_cnt; i++) { for (int j = 0; j < 2; j++) { - if (e_sector[i].foundKey[j] == 1) { + if (e_sector[i].foundKey[j] > 0) { num_to_bytes(e_sector[i].Key[j], 6, tmp_key); - PrintAndLogEx(SUCCESS, "Found valid key: sector: %3d key type: %c key: " _YELLOW_("%s"), + PrintAndLogEx(SUCCESS, "target sector:%3u key type: %c -- found valid key [" _YELLOW_("%s") "]", i, j ? 'B' : 'A', sprint_hex(tmp_key, sizeof(tmp_key)) @@ -1918,19 +1995,9 @@ useDefaultKeys: PrintAndLogEx(SUCCESS, "\nFound valid key: %012" PRIx64 "\n", key64); break; } - num_to_bytes(key64, 6, key); - // Check if the darkside key is valid - if (mfCheckKeys(FirstBlockOfSector(blockNo), keyType, true, 1, key, &key64) != PM3_SUCCESS) { - PrintAndLogEx(FAILED, "The key generated by the darkside attack is not valid!" - _RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), - blockNo, - keyType ? 'B' : 'A', - sprint_hex(key, sizeof(key)) - ); - goto noValidKeyFound; - } + // Store the keys - e_sector[blockNo].Key[keyType] = bytes_to_num(key, 6); + e_sector[blockNo].Key[keyType] = key64; e_sector[blockNo].foundKey[keyType] = 2; } else { noValidKeyFound: @@ -1940,6 +2007,7 @@ noValidKeyFound: return PM3_ESOFT; } } + free(keyBlock); // Clear the needed variables num_to_bytes(0, 6, tmp_key); @@ -2139,13 +2207,8 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1); } - // using ecfill trick, keys already in emulator mem, load data using Key A - clearCommandBuffer(); - SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, sectors_cnt, 0, 0, NULL, 0); - - // using ecfill trick, keys already in emulator mem, load data using Key B - clearCommandBuffer(); - SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, sectors_cnt, 1, 0, NULL, 0); + // use ecfill trick + FastDumpWithEcFill(sectors_cnt); bytes = block_cnt * MFBLOCK_SIZE; dump = calloc(bytes, sizeof(uint8_t)); @@ -2388,7 +2451,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { firstChunk = false; // all keys, aborted - if (res == 0 || res == 2) + if (res == PM3_SUCCESS || res == 2) goto out; } // end chunks of keys firstChunk = true; @@ -2416,6 +2479,13 @@ out: printKeyTable(sectorsCnt, e_sector); + if ( use_flashmemory && found_keys == (sectorsCnt << 1) ) { + PrintAndLogEx(SUCCESS, "Card dumped aswell. run " _YELLOW_("`%s %c`"), + "hf mf esave", + GetFormatFromSector(sectorsCnt) + ); + } + if (transferToEml) { // fast push mode conn.block_after_ACK = true; @@ -2434,6 +2504,10 @@ out: mfEmlSetMem(block, blockno, 1); } PrintAndLogEx(SUCCESS, "Found keys have been transferred to the emulator memory"); + + if ( found_keys == (sectorsCnt << 1) ) { + FastDumpWithEcFill(sectorsCnt); + } } if (createDumpFile) { @@ -3411,8 +3485,12 @@ static int CmdHF14AMfECFill(const char *Cmd) { } PrintAndLogEx(NORMAL, "--params: numSectors: %d, keyType: %c\n", numSectors, (keyType == 0) ? 'A' : 'B'); + + mfc_eload_t payload; + payload.sectorcnt = numSectors; + payload.keytype = keyType; clearCommandBuffer(); - SendCommandMIX(CMD_HF_MIFARE_EML_LOAD, numSectors, keyType, 0, NULL, 0); + SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); return PM3_SUCCESS; } From 28d703d6df0f839b33992cab4c3e0233be81596a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:21:52 +0200 Subject: [PATCH 148/347] chg: eload NG --- armsrc/appmain.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index b593c826b..13aa6bc84 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1134,7 +1134,8 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_MIFARE_EML_LOAD: { - MifareECardLoad(packet->oldarg[0], packet->oldarg[1]); + mfc_eload_t *payload = (mfc_eload_t *) packet->data.asBytes; + MifareECardLoadExt(payload->sectorcnt, payload->keytype); break; } // Work with "magic Chinese" card From 501182ca06b6c58bbd9bf1565331bfe3ed0448d2 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:23:31 +0200 Subject: [PATCH 149/347] chg: ecload NG, fchk use ecfill trick --- armsrc/mifarecmd.c | 89 +++++++++++++++++++++++++++++----------------- armsrc/mifarecmd.h | 3 +- 2 files changed, 59 insertions(+), 33 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 63cf1128d..17570e680 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1342,8 +1342,6 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da for (uint16_t i = s_point; i < keyCount; ++i) { - //if ( i % 100 == 0) Dbprintf("ChkKeys_fast: sector %d | checking %d | %d found | s_point %d", s, i, foundkeys, s_point); - // Allow button press / usb cmd to interrupt device if (BUTTON_PRESS() && !data_available()) { goto OUT; @@ -1525,6 +1523,33 @@ OUT: FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); BigBuf_free(); BigBuf_Clear_ext(false); + + // special trick ecfill + if (use_flashmem && foundkeys == allkeys) { + + uint8_t block[16] = {0}; + for (int i = 0; i < sectorcnt; i++) { + + uint8_t blockno; + if (i < 32) { + blockno = (i * 4) ^ 0x3; + } else { + blockno = (32 * 4 + (i - 32) * 16) ^ 0xF; + } + // get ST + emlGetMem(block, blockno, 1); + + memcpy(block, k_sector[i].keyA, 6); + memcpy(block + 10, k_sector[i].keyB, 6); + + emlSetMem_xt(block, blockno, 1, sizeof(block)); + } + int oldbg = DBGLEVEL; + DBGLEVEL = DBG_NONE; + MifareECardLoad(sectorcnt, 0); + MifareECardLoad(sectorcnt, 1); + DBGLEVEL = oldbg; + } } else { // partial/none keys found reply_mix(CMD_ACK, foundkeys, 0, 0, 0, 0); @@ -1669,10 +1694,15 @@ void MifareEMemGet(uint8_t blockno, uint8_t blockcnt) { // Load a card into the emulator memory // //----------------------------------------------------------------------------- -int MifareECardLoad(uint32_t arg0, uint32_t arg1) { +int MifareECardLoadExt(uint8_t numSectors, uint8_t keyType) { + int retval = MifareECardLoad(numSectors, keyType); + reply_ng(CMD_HF_MIFARE_EML_LOAD, retval, NULL, 0); + return retval; +} + +int MifareECardLoad(uint8_t numSectors, uint8_t keyType) { + uint32_t cuid = 0; - uint8_t numSectors = arg0; - uint8_t keyType = arg1; struct Crypto1State mpcs = {0, 0}; struct Crypto1State *pcs; pcs = &mpcs; @@ -1683,42 +1713,40 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) { uint8_t uid[10] = {0x00}; LED_A_ON(); - LED_B_OFF(); - LED_C_OFF(); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); clear_trace(); set_tracing(true); - bool isOK = true; + int retval; if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { - isOK = false; - if (DBGLEVEL >= 1) Dbprintf("Can't select card"); + retval = PM3_ESOFT; + if (DBGLEVEL > DBG_ERROR) Dbprintf("Can't select card"); + goto out; } - for (uint8_t sectorNo = 0; isOK && sectorNo < numSectors; sectorNo++) { + for (uint8_t sectorNo = 0; sectorNo < numSectors; sectorNo++) { uint64_t ui64Key = emlGetKey(sectorNo, keyType); if (sectorNo == 0) { - if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) { - if (DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth error", sectorNo); + if (mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) { + if (DBGLEVEL > DBG_ERROR) Dbprintf("Sector[%2d]. Auth error", sectorNo); break; } } else { - if (isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_NESTED)) { - isOK = false; - if (DBGLEVEL >= 1) Dbprintf("Sector[%2d]. Auth nested error", sectorNo); - break; + if (mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_NESTED)) { + retval = PM3_ESOFT; + if (DBGLEVEL > DBG_ERROR) Dbprintf("Sector[%2d]. Auth nested error", sectorNo); + goto out; } } - for (uint8_t blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) { - if (isOK && mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf)) { - isOK = false; - if (DBGLEVEL >= 1) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo); + for (uint8_t blockNo = 0; blockNo < NumBlocksPerSector(sectorNo); blockNo++) { + if (mifare_classic_readblock(pcs, cuid, FirstBlockOfSector(sectorNo) + blockNo, dataoutbuf)) { + retval = PM3_ESOFT; + if (DBGLEVEL > DBG_ERROR) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo); break; } - if (isOK) { if (blockNo < NumBlocksPerSector(sectorNo) - 1) { emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1); } else { // sector trailer, keep the keys, set only the AC @@ -1729,22 +1757,19 @@ int MifareECardLoad(uint32_t arg0, uint32_t arg1) { } } - } - - if (mifare_classic_halt(pcs, cuid)) - if (DBGLEVEL >= 1) + if (mifare_classic_halt(pcs, cuid)) { + if (DBGLEVEL > DBG_ERROR) Dbprintf("Halt error"); + } - // ----------------------------- crypto1 destroy + if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished"); + +out: crypto1_destroy(pcs); - FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); - - if (DBGLEVEL >= 2) DbpString("EMUL FILL SECTORS FINISHED"); - set_tracing(false); - return (isOK) ? PM3_SUCCESS : PM3_EUNDEF; + return retval; } diff --git a/armsrc/mifarecmd.h b/armsrc/mifarecmd.h index 445b04130..d563e37a8 100644 --- a/armsrc/mifarecmd.h +++ b/armsrc/mifarecmd.h @@ -31,7 +31,8 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da void MifareEMemClr(void); void MifareEMemSet(uint8_t blockno, uint8_t blockcnt, uint8_t blockwidth, uint8_t *datain); void MifareEMemGet(uint8_t blockno, uint8_t blockcnt); -int MifareECardLoad(uint32_t arg0, uint32_t arg1); +int MifareECardLoad(uint8_t sectorcnt, uint8_t keytype); +int MifareECardLoadExt(uint8_t numSectors, uint8_t keyType); void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); // Work with "magic Chinese" card void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain); From 03867018f1098deb12edcd96b7241f243cc7e084 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 28 Aug 2019 21:29:08 +0200 Subject: [PATCH 150/347] chg: iclass fixes. better timings, to get 280us vs 330us (default) time before card response. --- armsrc/iclass.c | 57 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index c8504e5ed..b550158cc 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -55,7 +55,13 @@ #include "protocols.h" #include "ticks.h" -static int timeout = 4096; +static int g_wait = 300; +static int timeout = 2900; +static uint32_t time_rdr = 0; +static uint32_t time_delta = 0; +static uint32_t time_delta_wait = 0; +static uint32_t time_response = 0; + static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay); int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf); @@ -151,7 +157,7 @@ typedef struct { static tUartIc Uart; static void OnError(uint8_t reason) { - reply_old(CMD_ACK, 0, reason, 0, 0, 0); + reply_mix(CMD_ACK, 0, reason, 0, 0, 0); switch_off(); } @@ -160,10 +166,12 @@ static void uart_reset(void) { Uart.synced = false; Uart.frame = false; } + static void uart_init(uint8_t *data) { Uart.buf = data; uart_reset(); } + static void uart_bit(uint8_t bit) { static uint8_t buf = 0xff; static uint8_t n_buf; @@ -1427,7 +1435,6 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { uint32_t time_0 = GetCountSspClk(); uint32_t t2r_stime = 0, t2r_etime = 0; uint32_t r2t_stime, r2t_etime = 0; - LED_A_ON(); bool buttonPressed = false; @@ -1717,6 +1724,8 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int bool firstpart = true; uint8_t sendbyte; + time_rdr = 0; + FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD); AT91C_BASE_SSC->SSC_THR = 0x00; @@ -1755,6 +1764,8 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int } } + time_rdr = GetCountSspClk(); + if (samples) { if (wait) *samples = (c + *wait) << 3; @@ -1827,7 +1838,7 @@ void ReaderTransmitIClass(uint8_t *frame, int len) { // If a response is captured return TRUE // If it takes too long return FALSE //----------------------------------------------------------------------------- -static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) { +static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *wait) { // buffer needs to be 512 bytes // maxLen is not used... @@ -1837,13 +1848,16 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, // Setup UART/DEMOD to receive DemodIcInit(receivedResponse); - if (elapsed) *elapsed = 0; - // Set FPGA mode to "reader listen mode", no modulation (listen // only, since we are receiving, not transmitting). FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN); - SpinDelayUs(320); //310 Tout= 330us (iso15603-2) (330/21.3) take consideration for clock increments. + time_delta = GetCountSspClk() - time_rdr; + + SpinDelayUs(g_wait); //310 Tout= 330us (iso15603-2) (330/21.3) take consideration for clock increments. + time_delta_wait = GetCountSspClk() - time_rdr - time_delta; + + uint32_t foo = GetCountSspClk(); // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; (void)b; @@ -1861,15 +1875,16 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, } // keep tx buffer in a defined state anyway. +/* if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { AT91C_BASE_SSC->SSC_THR = 0x00; - // To make use of exact timing of next command from reader!! - if (elapsed)(*elapsed)++; } - +*/ // Wait for byte be become available in rx holding register if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { - if (c >= timeout) return false; + + if ( GetCountSspClk() - foo > timeout) return false; +// if (c >= timeout) return false; c++; @@ -1881,25 +1896,28 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, if (ManchesterDecoding_iclass(b & 0x0f)) { if (samples) *samples = c << 3; + + time_response = GetCountSspClk() - foo; return true; } } } + return false; } int ReaderReceiveIClass(uint8_t *receivedAnswer) { int samples = 0; - if (!GetIClassAnswer(receivedAnswer, 0, &samples, NULL)) - return false; + if (GetIClassAnswer(receivedAnswer, 0, &samples, NULL) == false) + return 0; rsamples += samples; LogTrace(receivedAnswer, Demod.len, rsamples, rsamples, NULL, false); if (samples == 0) - return false; + return 0; return Demod.len; } @@ -1924,7 +1942,7 @@ void setupIclassReader() { // Now give it time to spin up. // Signal field is on with the appropriate LED FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD); - SpinDelay(300); + SpinDelay(500); StartCountSspClk(); @@ -1936,13 +1954,20 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re ReaderTransmitIClass(command, cmdsize); + //iceman - if received size is bigger than expected, we smash the stack here // since its called with fixed sized arrays + + // update/write commadn takes 4ms to 15ms before responding + if ( command[0] == ICLASS_CMD_UPDATE ) + g_wait = 15000; + uint8_t got_n = ReaderReceiveIClass(resp); // 0xBB is the internal debug separator byte.. if (expected_size != got_n || (resp[0] == 0xBB || resp[7] == 0xBB || resp[2] == 0xBB)) { //try again + SpinDelayUs(400); continue; } @@ -2396,8 +2421,6 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { if (isOK) goto out; - SpinDelayUs(400); //iClass (iso15693-2) should timeout after 330us. - // Auth Sequence MUST begin with reading e-purse. (block2) // Card selected, now read e-purse (cc) (block2) (only 8 bytes no CRC) ReaderTransmitIClass(readcheck_cc, sizeof(readcheck_cc)); From d2d58db98528ace9b5bddb912f5baa98b5fd5a31 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 28 Aug 2019 21:15:11 +0200 Subject: [PATCH 151/347] Move history and logfile to ~/.proxmark3 --- client/fileutils.c | 2 ++ client/proxmark3.c | 15 ++++++++--- client/proxmark3.h | 2 ++ client/ui.c | 65 ++++++++++++++++++++++++++++++++++++++++------ client/ui.h | 3 ++- 5 files changed, 74 insertions(+), 13 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index c3c9f5acc..72771f900 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -896,6 +896,8 @@ out: } int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix) { + if (foundpath == NULL) + return PM3_EINVARG; char *filename = filenamemcopy(searchname, suffix); if (filename == NULL) return PM3_EMALLOC; int res = searchFinalFile(foundpath, pm3dir, filename); diff --git a/client/proxmark3.c b/client/proxmark3.c index 6a23f4804..913f3735f 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -102,8 +102,13 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { PrintAndLogEx(ERR, "could not open " _YELLOW_("%s") "...", script_cmds_file); } - read_history(".history"); - + char *my_history_path = NULL; + if (searchHomeFilePath(&my_history_path, PROXHISTORY, true) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "could not create $HOME/" PROXHISTORY ", no history will be recorded"); + my_history_path = NULL; + } else { + read_history(my_history_path); + } // loops every time enter is pressed... while (1) { bool printprompt = false; @@ -220,8 +225,10 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { if (sf) fclose(sf); - write_history(".history"); - + if (my_history_path) { + write_history(my_history_path); + free(my_history_path); + } if (cmd) { free(cmd); cmd = NULL; diff --git a/client/proxmark3.h b/client/proxmark3.h index 6d245da10..3da261c31 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -18,6 +18,8 @@ #define PROXPROMPT_USB "[usb] pm3 --> " #define PROXPROMPT_FPC "[fpc] pm3 --> " #define PROXPROMPT_OFFLINE "[offline] pm3 --> " +#define PROXHISTORY "history.txt" +#define PROXLOG "log_%Y%m%d.txt" #ifdef __cplusplus extern "C" { diff --git a/client/ui.c b/client/ui.c index 9927fd6d6..86f32e2bd 100644 --- a/client/ui.c +++ b/client/ui.c @@ -24,6 +24,9 @@ #include #include #include "util.h" +#include "proxmark3.h" // PROXLOG +#include "fileutils.h" +#include "pm3_cmd.h" session_arg_t session; @@ -36,9 +39,45 @@ bool GridLocked = false; bool showDemod = true; pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER; -static const char *logfilename = "proxmark3.log"; + static void fPrintAndLog(FILE *stream, const char *fmt, ...); +// needed by flasher, so let's put it here instead of fileutils.c +int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) { + if (foundpath == NULL) + return PM3_EINVARG; + char *user_path = getenv("HOME"); + if (user_path == NULL) + return PM3_EFILE; + char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1, sizeof(char)); + if (path == NULL) + return PM3_EMALLOC; + strcpy(path, user_path); + strcat(path, PM3_USER_DIRECTORY); + +#ifdef _WIN32 + struct _stat st; + int result = _stat(path, &st); +#else + struct stat st; + int result = stat(path, &st); +#endif + if ((result != 0) && create_home) { + if (mkdir(path, 0700)) { + free(path); + return PM3_EFILE; + } + } + if (filename == NULL) { + *foundpath = path; + return PM3_SUCCESS; + } + path = realloc(path, (strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(filename) + 1) * sizeof(char)); + strcat(path, filename); + *foundpath = path; + return PM3_SUCCESS; +} + void PrintAndLogOptions(const char *str[][2], size_t size, size_t space) { char buff[2000] = "Options:\n"; char format[2000] = ""; @@ -166,10 +205,24 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { pthread_mutex_lock(&print_lock); if (logging && !logfile) { - logfile = fopen(logfilename, "a"); - if (!logfile) { - fprintf(stderr, "Can't open logfile, logging disabled!\n"); + char *my_logfile_path = NULL; + char filename[40]; + struct tm *timenow; + time_t now = time(NULL); + timenow = gmtime(&now); + strftime(filename, sizeof(filename), PROXLOG, timenow); + if (searchHomeFilePath(&my_logfile_path, filename, true) != PM3_SUCCESS) { + fprintf(stderr, "Could not create $HOME/.proxmark3/%s, no log will be recorded\n", filename); + my_logfile_path = NULL; logging = 0; + } else { + logfile = fopen(my_logfile_path, "a"); + if (logfile == NULL) { + fprintf(stderr, "Can't open logfile %s, logging disabled!\n", my_logfile_path); + logging = 0; + } + printf("Session is logged into %s\n", my_logfile_path); + free(my_logfile_path); } } @@ -228,10 +281,6 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { pthread_mutex_unlock(&print_lock); } -void SetLogFilename(char *fn) { - logfilename = fn; -} - void SetFlushAfterWrite(bool value) { flushAfterWrite = value; } diff --git a/client/ui.h b/client/ui.h index 648dce4c4..7e00ab52b 100644 --- a/client/ui.h +++ b/client/ui.h @@ -39,7 +39,6 @@ void ShowGraphWindow(void); void RepaintGraphWindow(void); void PrintAndLogOptions(const char *str[][2], size_t size, size_t space); void PrintAndLogEx(logLevel_t level, const char *fmt, ...); -void SetLogFilename(char *fn); void SetFlushAfterWrite(bool value); void memcpy_filter_ansi(void *dest, const void *src, size_t n, bool filter); @@ -49,6 +48,8 @@ extern uint32_t CursorCPos, CursorDPos; extern bool GridLocked; extern bool showDemod; +int searchHomeFilePath(char **foundpath, const char *filename, bool create_home); + extern pthread_mutex_t print_lock; void iceIIR_Butterworth(int *data, const size_t len); From 11c7db352349d4d88ded9b6446dcdd275018c4d2 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 28 Aug 2019 23:07:23 +0200 Subject: [PATCH 152/347] Get ~/.proxmark3 working on Mingw --- client/ui.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/client/ui.c b/client/ui.c index 86f32e2bd..e6edb4369 100644 --- a/client/ui.c +++ b/client/ui.c @@ -27,7 +27,10 @@ #include "proxmark3.h" // PROXLOG #include "fileutils.h" #include "pm3_cmd.h" - +#ifdef _WIN32 +# include // _mkdir +#endif +#include session_arg_t session; double CursorScaleFactor = 1; @@ -55,15 +58,16 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) strcpy(path, user_path); strcat(path, PM3_USER_DIRECTORY); -#ifdef _WIN32 - struct _stat st; - int result = _stat(path, &st); -#else +// Mingw: _stat fails on mangled HOME path /pm3 => C:\ProxSpace\pm3, while stat works fine struct stat st; int result = stat(path, &st); -#endif if ((result != 0) && create_home) { + +#ifdef _WIN32 + if (_mkdir(path)) { +#else if (mkdir(path, 0700)) { +#endif free(path); return PM3_EFILE; } From 37243a47294c7e74e5f708e4de2368857c6e903a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 28 Aug 2019 23:09:59 +0200 Subject: [PATCH 153/347] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3db619fd..f7dc5d6a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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... ## [unreleased][unreleased] + - Chg history and logfile are now saved into $HOME/.proxmark3/ (@doegox) - Chg optimization of iclass mac calculations on deviceside (@pwpiwi) - Add 'hf mf autopwn' - Autopwn function for Mifare Classic, extract all keys and dump card memory (@matthiaskonrath) - Add Lua paths: look for scripts also in ~/.proxmark/lua{scripts,libs} and /usr/local/share/proxmark3/lua{scripts,libs} (@doegox) From aa77f7298c18c22dda15673d518093b6f0f0e55e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 28 Aug 2019 23:28:28 +0200 Subject: [PATCH 154/347] Fix buffer allocation for showing compiler version --- client/cmdhw.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index b6cb2bd87..68a5390c6 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -619,15 +619,18 @@ int CmdHW(const char *Cmd) { void pm3_version(bool verbose, bool oneliner) { - if (oneliner) { - char msg[70]; - memset(msg, 0x00, sizeof(msg)); - strcat(msg, "Client: RRG/Iceman compiled with "); +#define PM3CLIENTONELINER "Client: RRG/Iceman compiled with " #if defined(__clang__) - strcat(msg + strlen(msg), _YELLOW_("Clang/LLVM "__VERSION__)); +# define PM3CLIENTCOMPILER "Clang/LLVM " #elif defined(__GNUC__) || defined(__GNUG__) - strcat(msg + strlen(msg), _YELLOW_("GCC "__VERSION__)); +# define PM3CLIENTCOMPILER "GCC " #endif + + if (oneliner) { + char msg[sizeof(PM3CLIENTONELINER)+sizeof(PM3CLIENTCOMPILER)+sizeof(__VERSION__)]; + memset(msg, 0x00, sizeof(msg)); + strcat(msg, PM3CLIENTONELINER); + strcat(msg + strlen(msg), _YELLOW_(PM3CLIENTCOMPILER __VERSION__)); PrintAndLogEx(NORMAL, "%s", msg); return; } @@ -644,12 +647,7 @@ void pm3_version(bool verbose, bool oneliner) { PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? -#if defined(__clang__) - PrintAndLogEx(NORMAL, " compiled with Clang/LLVM "__VERSION__); -#elif defined(__GNUC__) || defined(__GNUG__) - PrintAndLogEx(NORMAL, " compiled with GCC "__VERSION__); -#endif - + PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__); PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 ]"); PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); From 430c53a7ac0985526188ea02798a2c69ffd8a23d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 28 Aug 2019 23:51:52 +0200 Subject: [PATCH 155/347] Fix buffer allocation again, just getting rid of it --- client/cmdhw.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 68a5390c6..1d65f5d1d 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -619,7 +619,6 @@ int CmdHW(const char *Cmd) { void pm3_version(bool verbose, bool oneliner) { -#define PM3CLIENTONELINER "Client: RRG/Iceman compiled with " #if defined(__clang__) # define PM3CLIENTCOMPILER "Clang/LLVM " #elif defined(__GNUC__) || defined(__GNUG__) @@ -627,11 +626,7 @@ void pm3_version(bool verbose, bool oneliner) { #endif if (oneliner) { - char msg[sizeof(PM3CLIENTONELINER)+sizeof(PM3CLIENTCOMPILER)+sizeof(__VERSION__)]; - memset(msg, 0x00, sizeof(msg)); - strcat(msg, PM3CLIENTONELINER); - strcat(msg + strlen(msg), _YELLOW_(PM3CLIENTCOMPILER __VERSION__)); - PrintAndLogEx(NORMAL, "%s", msg); + PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__)); return; } From 199c1b3c9bba1a5ba6833d252b8a9274b66e38e6 Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Thu, 29 Aug 2019 02:38:35 +0300 Subject: [PATCH 156/347] Appveyour (#369) appveyour fix --- appveyor.yml | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a0c261b2b..a0a4b18a9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -76,10 +76,64 @@ clone_script: Write-Host "Update msys2 packages..." -NoNewLine $env:Path = "C:\ProxSpace\msys2\usr\bin;C:\ProxSpace\msys2\mingw32\bin;C:\ProxSpace\gcc-arm-none-eabi\bin;$env:Path" + + Function ExecUpdate($Name, $Cmd, $ErrorLine) { - C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null 1> msys1.txt 2>&1 + #--- begin Job + + $Job = Start-Job -Name "$Name" -ScriptBlock { + $env:Path = "C:\ProxSpace\msys\bin;$env:Path" + Set-Location $using:PWD - C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null 1> msys1.txt 2>&1 + $sb=[scriptblock]::Create("$using:Cmd") + #execute scriptblock + $Cond=&$sb + + return $Cond + } + + #--- end Job + + $JobTime=[System.Environment]::TickCount + while($true) { + Receive-Job -Job $Job -Keep -OutVariable Res 2>&1 6>&1 | Out-Null + + if ($Res -is "String" -and $Res -like "*$ErrorLine*"){ + Write-host "Exit by stop phrase" + break + } + + if ($Res -is [Object]){ + [bool]$needexit = $false + ForEach($line in $Res){ + if ($line -like "*$ErrorLine*"){ + Write-host "Exit by stop phrase [obj]" + $needexit = $true + break + } + } + if ($needexit) { + break + } + } + + if(Wait-Job $Job -Timeout 5){ + Write-host "Exit by end job" + break + } + + if ([System.Environment]::TickCount-$JobTime -gt 600000) { + Write-host "Exit by timeout" + break + } + } + + Remove-Job -Force $Job + } + + ExecUpdate "update1" "C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null" "terminate?MSYS2" + + ExecUpdate "update2" "C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null" "terminate?MSYS2" Write-Host "[ OK ]" -ForegroundColor Green install: From 3683cd88c66e4889935009c38d65faf4d3eed17e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 07:45:09 +0200 Subject: [PATCH 157/347] chg: 'hw version' - simple os detection. --- client/cmdhw.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 1d65f5d1d..fe6dc2b4d 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -625,8 +625,55 @@ void pm3_version(bool verbose, bool oneliner) { # define PM3CLIENTCOMPILER "GCC " #endif +#if defined(__APPLE__) || defined(__MACH__) +#ifndef PM3HOSTOS +# define PM3HOSTOS "OS X" +#endif + +#elif defined(_MINGW_) +#ifndef PM3HOSTOS +# define PM3HOSTOS "MingW" +#endif + +#elif defined(__LINUX__) +#ifndef PM3HOSTOS +# define PM3HOSTOS "linux" +#endif + +#elif defined(__FreeBSd__) +#ifndef PM3HOSTOS +# define PM3HOSTOS "FreeBSD" +#endif + +#elif defined(__NetBSD__) +#ifndef PM3HOSTOS +# define PM3HOSTOS "NetBSD" +#endif + +#elif defined(__OpenBSD__) +#ifndef PM3HOSTOS +# define PM3HOSTOS "OpenBSD" +#endif + +#elif defined(_WIN32) | defined(__WIN32__) +#ifndef PM3HOSTOS +# define PM3HOSTOS "Windows (32b)" +#endif + +#elif defined(_WIN64) | defined(__WIN64__) +#ifndef PM3HOSTOS +# define PM3HOSTOS "Windows (64b)" +#endif + +#elif defined(__ANDROID__) || defined(ANDROID) +#ifndef PM3HOSTOS +# define PM3HOSTOS "Android" +#endif +#endif + + if (oneliner) { - PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__)); + PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__) " on " _YELLOW_(PM3HOSTOS)); return; } @@ -642,7 +689,7 @@ void pm3_version(bool verbose, bool oneliner) { PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? - PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__); + PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__ " on " PM3HOSTOS); PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 ]"); PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); From 979f3aba2eb24a6c9c66d6cd2b2c8a425834a2ca Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 07:47:17 +0200 Subject: [PATCH 158/347] chg: 'hf iclass chk' chg: 'hf iclass lookup' - use fileutils load dictionary instead. chg: 'hf iclass encrypt' - start w change to allow for key parameter --- client/cmdhficlass.c | 401 ++++++++++++++++++++++--------------------- client/cmdhficlass.h | 6 +- 2 files changed, 204 insertions(+), 203 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 51bc323fc..30b2a0560 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -76,20 +76,25 @@ static int usage_hf_iclass_decrypt(void) { PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside"); PrintAndLogEx(NORMAL, "in the working directory. The file should be 16 bytes binary data"); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: hf iclass decrypt f "); + PrintAndLogEx(NORMAL, "Usage: hf iclass decrypt f k "); + PrintAndLogEx(NORMAL, " options"); + PrintAndLogEx(NORMAL, " f filename of dump"); + PrintAndLogEx(NORMAL, " k 16 bytes hex"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, "S hf iclass decrypt f tagdump_12312342343.bin"); + PrintAndLogEx(NORMAL, "S hf iclass decrypt f tagdump_1.bin"); + PrintAndLogEx(NORMAL, "S hf iclass decrypt f tagdump_1.bin k 000102030405060708090a0b0c0d0e0f"); return PM3_SUCCESS; } static int usage_hf_iclass_encrypt(void) { PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside"); PrintAndLogEx(NORMAL, "in the working directory. The file should be 16 bytes binary data"); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: hf iclass encrypt "); + PrintAndLogEx(NORMAL, "Usage: hf iclass encrypt d k "); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " hf iclass encrypt 0102030405060708"); + PrintAndLogEx(NORMAL, " hf iclass encrypt d 0102030405060708"); + PrintAndLogEx(NORMAL, " hf iclass encrypt d 0102030405060708 k 00112233445566778899AABBCCDDEEFF"); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -541,11 +546,11 @@ static int CmdHFiClassSim(const char *Cmd) { tries++; if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard."); - return 0; + return PM3_EOPABORTED; } if (tries > 20) { PrintAndLogEx(WARNING, "\ntimeout while waiting for reply."); - return 0; + return PM3_ETIMEOUT; } } uint8_t num_mac = resp.oldarg[1]; @@ -559,7 +564,7 @@ static int CmdHFiClassSim(const char *Cmd) { uint8_t *dump = calloc(datalen, sizeof(uint8_t)); if (!dump) { PrintAndLogEx(WARNING, "Failed to allocate memory"); - return 2; + return PM3_EMALLOC; } memset(dump, 0, datalen);//<-- Need zeroes for the EPURSE - field (offical) @@ -590,11 +595,11 @@ static int CmdHFiClassSim(const char *Cmd) { tries++; if (kbd_enter_pressed()) { PrintAndLogEx(WARNING, "\naborted via keyboard."); - return 0; + return PM3_EOPABORTED; } if (tries > 20) { PrintAndLogEx(WARNING, "\ntimeout while waiting for reply."); - return 0; + return PM3_ETIMEOUT; } } uint8_t num_mac = resp.oldarg[1]; @@ -608,7 +613,7 @@ static int CmdHFiClassSim(const char *Cmd) { uint8_t *dump = calloc(datalen, sizeof(uint8_t)); if (!dump) { PrintAndLogEx(WARNING, "Failed to allocate memory"); - return 2; + return PM3_EMALLOC; } #define MAC_ITEM_SIZE 24 @@ -681,54 +686,85 @@ static int CmdHFiClassReader_Replay(const char *Cmd) { static int CmdHFiClassELoad(const char *Cmd) { - char ctmp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf_iclass_eload(); - - if (ctmp != 'f') return usage_hf_iclass_eload(); - - //File handling and reading - char filename[FILE_PATH_SIZE]; - - if (param_getstr(Cmd, 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { + DumpFileType_t dftype = BIN; + char filename[FILE_PATH_SIZE] = {0}; + bool errors = false; + uint8_t cmdp = 0; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_hf_iclass_eload(); + case 'f': + if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "Filename too long"); - return 1; + errors = true; + break; + } + cmdp += 2; + break; + case 'j': + dftype = JSON; + cmdp++; + break; + case 'e': + dftype = EML; + cmdp++; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } - FILE *f = fopen(filename, "rb"); - if (!f) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); + //Validations + if (errors || cmdp == 0) { + usage_hf_iclass_eload(); + return PM3_EINVARG; + } + + + uint8_t *dump = calloc(2048, sizeof(uint8_t)); + if (!dump) { + PrintAndLogEx(ERR, "error, cannot allocate memory "); + return PM3_EMALLOC; + } + + size_t bytes_read = 2048; + int res = 0; + + switch ( dftype ) { + case BIN: { + res = loadFile(filename, ".bin", (void*)&dump, 2048, &bytes_read); + break; + } + case EML: { + res = loadFileEML(filename, dump, &bytes_read); + break; + } + case JSON: { + res = loadFileJSON(filename, dump, 2048, &bytes_read); + break; + } + default: + PrintAndLogEx(ERR, "No dictionary loaded"); + return PM3_ESOFT; + } + + if ( res != PM3_SUCCESS ) { + free(dump); return PM3_EFILE; } - // get filesize in order to malloc memory - fseek(f, 0, SEEK_END); - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); - - if (fsize <= 0) { - PrintAndLogEx(ERR, "error, when getting filesize"); - fclose(f); - return 1; + uint8_t *newdump = realloc(dump, bytes_read); + if (newdump == NULL) { + free(dump); + return PM3_EMALLOC; + } else { + dump = newdump; } - uint8_t *dump = calloc(fsize, sizeof(uint8_t)); - if (!dump) { - PrintAndLogEx(ERR, "error, cannot allocate memory "); - fclose(f); - return 1; - } - - size_t bytes_read = fread(dump, 1, fsize, f); - fclose(f); - printIclassDumpInfo(dump); - //Validate - - if (bytes_read < fsize) { - PrintAndLogEx(ERR, "error, could only read %d bytes (should be %d)", bytes_read, fsize); - free(dump); - return 1; - } // fast push mode conn.block_after_ACK = true; @@ -754,26 +790,23 @@ static int CmdHFiClassELoad(const char *Cmd) { return PM3_SUCCESS; } -static int readKeyfile(const char *filename, size_t len, uint8_t *buffer) { - FILE *f = fopen(filename, "rb"); - if (!f) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); +static int readKeyfile(const char *filename, size_t len, uint8_t **buffer) { + + char *path; + int res = searchFile(&path, PM3_USER_DIRECTORY, filename, ".bin"); + if (res != PM3_SUCCESS) { + PrintAndLogEx(INFO, "res: %d Curr path:: %s", res, path); return PM3_EFILE; } - fseek(f, 0, SEEK_END); - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); - size_t bytes_read = fread(buffer, 1, len, f); - fclose(f); - if (fsize != len) { - PrintAndLogEx(WARNING, "Warning, file size is %d, expected %d", fsize, len); - return 1; - } + size_t datalen = 0; + res = loadFile(path, ".bin", (void*)*buffer, len, &datalen); + if ( res != PM3_SUCCESS ) + return res; - if (bytes_read != len) { - PrintAndLogEx(WARNING, "Warning, could only read %d bytes, expected %d", bytes_read, len); - return 1; + if (datalen != len) { + PrintAndLogEx(ERR, "ERROR, Wrong filesize. Got %d bytes, expected %d", datalen, len); + return PM3_EFILE; } return PM3_SUCCESS; } @@ -784,7 +817,9 @@ static int CmdHFiClassDecrypt(const char *Cmd) { if (strlen(Cmd) < 1 || opt == 'h') return usage_hf_iclass_decrypt(); uint8_t key[16] = { 0 }; - if (readKeyfile("iclass_decryptionkey.bin", 16, key)) return usage_hf_iclass_decrypt(); + uint8_t *keyptr = key; + if (readKeyfile("iclass_decryptionkey", sizeof(key), &keyptr) != PM3_SUCCESS) + return usage_hf_iclass_decrypt(); PrintAndLogEx(SUCCESS, "decryption key loaded from file"); @@ -861,41 +896,69 @@ static int CmdHFiClassDecrypt(const char *Cmd) { saveFile(outfilename, ".bin", decrypted, fsize); saveFileEML(outfilename, decrypted, fsize, 8); + saveFileJSON(outfilename, jsfIclass, decrypted, fsize); + printIclassDumpContents(decrypted, 1, (fsize / 8), fsize); free(decrypted); return PM3_SUCCESS; } -static int iClassEncryptBlkData(uint8_t *blkData) { - uint8_t key[16] = { 0 }; - if (readKeyfile("iclass_decryptionkey.bin", 16, key)) { - usage_hf_iclass_encrypt(); - return 1; - } - PrintAndLogEx(SUCCESS, "decryption file found"); - uint8_t encryptedData[16]; - uint8_t *encrypted = encryptedData; +static void iClassEncryptBlkData(uint8_t *blk_data, uint8_t *key) { + uint8_t encrypted_data[16]; + uint8_t *encrypted = encrypted_data; mbedtls_des3_context ctx; mbedtls_des3_set2key_enc(&ctx, key); - - mbedtls_des3_crypt_ecb(&ctx, blkData, encrypted); - memcpy(blkData, encrypted, 8); - return 1; + mbedtls_des3_crypt_ecb(&ctx, blk_data, encrypted); + memcpy(blk_data, encrypted, 8); } static int CmdHFiClassEncryptBlk(const char *Cmd) { - uint8_t blkData[8] = {0}; - char opt = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) < 1 || opt == 'h') return usage_hf_iclass_encrypt(); + bool errors = false; + bool have_key = false; + uint8_t blk_data[8] = {0}; + uint8_t key[16] = {0}; + uint8_t *keyptr = key; + uint8_t cmdp = 0; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_hf_iclass_encrypt(); + case 'd': //get the bytes to encrypt - if (param_gethex(Cmd, 0, blkData, 16)) { - PrintAndLogEx(NORMAL, "BlockData must include 16 HEX symbols"); - return 0; + if (param_gethex(Cmd, cmdp + 1, blk_data, 16) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Block data must include 16 HEX symbols"); + errors = true;; + } + cmdp += 2; + break; + case 'k': + if (param_gethex(Cmd, cmdp + 1, key, 32) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Transport key must include 32 HEX symbols"); + errors = true;; + } + have_key = true; + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } - if (!iClassEncryptBlkData(blkData)) return 0; - printvar("encrypted block", blkData, 8); + if (errors || cmdp < 1) return usage_hf_iclass_encrypt(); + + if ( have_key == false ) { + if (readKeyfile("./iclass_decryptionkey", sizeof(key), &keyptr) != PM3_SUCCESS) { + return usage_hf_iclass_encrypt(); + } + PrintAndLogEx(SUCCESS, "Loaded transport key from decryption file"); + } + + iClassEncryptBlkData(blk_data, key); + + printvar("encrypted block", blk_data, 8); return PM3_SUCCESS; } @@ -1593,7 +1656,7 @@ static int CmdHFiClass_loclass(const char *Cmd) { char opt = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) < 1 || opt == 'h') - usage_hf_iclass_loclass(); + return usage_hf_iclass_loclass(); if (opt == 'f') { char fileName[FILE_PATH_SIZE] = {0}; @@ -1601,7 +1664,7 @@ static int CmdHFiClass_loclass(const char *Cmd) { return bruteforceFileNoKeys(fileName); } else { PrintAndLogEx(WARNING, "You must specify a filename"); - return 0; + return PM3_EFILE; } } else if (opt == 't') { int errors = testCipherUtils(); @@ -2001,10 +2064,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { char filename[FILE_PATH_SIZE] = {0}; uint8_t fileNameLen = 0; - - uint8_t *keyBlock = NULL; iclass_premac_t *pre = NULL; - int keycnt = 0; // time uint64_t t1 = msclock(); @@ -2042,35 +2102,36 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { if (errors) return usage_hf_iclass_chk(); + uint8_t *keyBlock = NULL; + uint16_t keycount = 0; + + // load keys + int res = loadFileDICTIONARY_safe(filename, (void**)&keyBlock, 8, &keycount); + if (res != PM3_SUCCESS || keycount == 0) { + free(keyBlock); + return res; + } + // Get CSN / UID and CCNR PrintAndLogEx(SUCCESS, "Reading tag CSN"); for (uint8_t i = 0; i < 10 && !got_csn; i++) { - if (select_only(CSN, CCNR, false, false)) { - got_csn = true; - } else { + got_csn = select_only(CSN, CCNR, false, false); + if ( got_csn == false ) PrintAndLogEx(WARNING, "one more try\n"); } - } - if (!got_csn) { - PrintAndLogEx(WARNING, "can't select card, aborting..."); + if ( got_csn == false ) { + PrintAndLogEx(WARNING, "Tried 10 times. Can't select card, aborting..."); return PM3_ESOFT; } - // load keys into keyblock - int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); - if (res > 0) { - free(keyBlock); - return PM3_EFILE; - } - - pre = calloc(keycnt, sizeof(iclass_premac_t)); + pre = calloc(keycount, sizeof(iclass_premac_t)); if (!pre) { free(keyBlock); return PM3_EMALLOC; } - PrintAndLogEx(SUCCESS, "Generating diversified keys, MAC"); + PrintAndLogEx(SUCCESS, "Generating diversified keys"); if (use_elite) PrintAndLogEx(SUCCESS, "Using " _YELLOW_("elite algo")); if (use_raw) @@ -2080,17 +2141,13 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { PrintAndLogEx(SUCCESS, "Tag info"); PrintAndLogEx(SUCCESS, "CSN | %s", sprint_hex(CSN, sizeof(CSN))); PrintAndLogEx(SUCCESS, "CCNR | %s", sprint_hex(CCNR, sizeof(CCNR))); - res = GenerateMacFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, pre); - if (res > 0) { - free(keyBlock); - free(pre); - return PM3_ESOFT; - } + + GenerateMacFrom(CSN, CCNR, use_raw, use_elite, keyBlock, keycount, pre); //PrintPreCalcMac(keyBlock, keycnt, pre); // max 42 keys inside USB_COMMAND. 512/4 = 103 mac - uint32_t chunksize = keycnt > (PM3_CMD_DATA_SIZE / 4) ? (PM3_CMD_DATA_SIZE / 4) : keycnt; + uint32_t chunksize = keycount > (PM3_CMD_DATA_SIZE / 4) ? (PM3_CMD_DATA_SIZE / 4) : keycount; bool lastChunk = false; // fast push mode @@ -2100,7 +2157,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { uint8_t found_offset = 0; uint32_t key_offset = 0; // main keychunk loop - for (uint32_t key_offset = 0; key_offset < keycnt; key_offset += chunksize) { + for (uint32_t key_offset = 0; key_offset < keycount; key_offset += chunksize) { uint64_t t2 = msclock(); uint8_t timeout = 0; @@ -2110,10 +2167,10 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { goto out; } - uint32_t keys = ((keycnt - key_offset) > chunksize) ? chunksize : keycnt - key_offset; + uint32_t keys = ((keycount - key_offset) > chunksize) ? chunksize : keycount - key_offset; // last chunk? - if (keys == keycnt - key_offset) { + if (keys == keycount - key_offset) { lastChunk = true; // Disable fast mode on last command conn.block_after_ACK = false; @@ -2146,20 +2203,20 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { case 1: { found_debit = true; - PrintAndLogEx(NORMAL, "\n[-] Chunk [%d/%d]: %.1fs [%s] found key %s (index %u)" + PrintAndLogEx(NORMAL, "\n[-] Chunk [%d/%d]: %.1fs [%s] idx [%u] - found key "_YELLOW_("%s") , key_offset - , keycnt + , keycount , (float)(t2 / 1000.0) , (use_credit_key) ? "credit" : "debit" - , sprint_hex(keyBlock + (key_offset + found_offset) * 8, 8) , found_offset + , sprint_hex(keyBlock + (key_offset + found_offset) * 8, 8) ); break; } case 0: { PrintAndLogEx(NORMAL, "\n[-] Chunk [%d/%d] : %.1fs [%s]" , key_offset - , keycnt + , keycount , (float)(t2 / 1000.0) , (use_credit_key) ? "credit" : "debit" ); @@ -2193,7 +2250,7 @@ out: if ( memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) { memcpy(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8); - PrintAndLogEx(SUCCESS, "Added found key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")" to view", i); + PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")" to view", i); break; } } @@ -2235,12 +2292,9 @@ static int CmdHFiClassLookUp(const char *Cmd) { uint8_t cmdp = 0x00; char filename[FILE_PATH_SIZE] = {0}; - uint8_t fileNameLen = 0; - uint8_t *keyBlock = NULL; iclass_prekey_t *prekey = NULL; - int keycnt = 0, len = 0; - + int len = 0; // if empty string if (strlen(Cmd) == 0) errors = true; // time @@ -2251,8 +2305,7 @@ static int CmdHFiClassLookUp(const char *Cmd) { case 'h': return usage_hf_iclass_lookup(); case 'f': - fileNameLen = param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)); - if (fileNameLen < 1) { + if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) < 1 ) { PrintAndLogEx(WARNING, "No filename found after f"); errors = true; } @@ -2311,54 +2364,54 @@ static int CmdHFiClassLookUp(const char *Cmd) { PrintAndLogEx(SUCCESS, "CCNR | %s", sprint_hex(CCNR, sizeof(CCNR))); PrintAndLogEx(SUCCESS, "MAC_TAG | %s", sprint_hex(MAC_TAG, sizeof(MAC_TAG))); - int res = LoadDictionaryKeyFile(filename, &keyBlock, &keycnt); - if (res > 0) { + uint8_t *keyBlock = NULL; + uint16_t keycount = 0; + + // load keys + int res = loadFileDICTIONARY_safe(filename, (void**)&keyBlock, 8, &keycount); + if (res != PM3_SUCCESS || keycount == 0) { free(keyBlock); - return 1; + return res; } + //iclass_prekey_t - prekey = calloc(keycnt, sizeof(iclass_prekey_t)); + prekey = calloc(keycount, sizeof(iclass_prekey_t)); if (!prekey) { free(keyBlock); - return 1; + return PM3_EMALLOC; } - PrintAndLogEx(FAILED, "Generating diversified keys and MAC"); - res = GenerateFromKeyFile(CSN, CCNR, use_raw, use_elite, keyBlock, keycnt, prekey); - if (res > 0) { - free(keyBlock); - free(prekey); - return 1; - } + PrintAndLogEx(INFO, "Generating diversified keys"); + GenerateMacKeyFrom(CSN, CCNR, use_raw, use_elite, keyBlock, keycount, prekey); - PrintAndLogEx(FAILED, "Sorting"); + PrintAndLogEx(INFO, "Sorting"); // sort mac list. - qsort(prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32); + qsort(prekey, keycount, sizeof(iclass_prekey_t), cmp_uint32); //PrintPreCalc(prekey, keycnt); - PrintAndLogEx(FAILED, "Searching"); + PrintAndLogEx(INFO, "Searching"); iclass_prekey_t *item; iclass_prekey_t lookup; memcpy(lookup.mac, MAC_TAG, 4); // binsearch - item = (iclass_prekey_t *) bsearch(&lookup, prekey, keycnt, sizeof(iclass_prekey_t), cmp_uint32); + item = (iclass_prekey_t *) bsearch(&lookup, prekey, keycount, sizeof(iclass_prekey_t), cmp_uint32); t1 = msclock() - t1; PrintAndLogEx(NORMAL, "\nTime in iclass : %.0f seconds\n", (float)t1 / 1000.0); // foudn if (item != NULL) { - PrintAndLogEx(SUCCESS, "\n[debit] found key %s", sprint_hex(item->key, 8)); + PrintAndLogEx(SUCCESS, "[debit] found key " _YELLOW_("%s"), sprint_hex(item->key, 8)); for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) { // simple check for preexistences if ( memcmp(item->key, iClass_Key_Table[i], 8) == 0 ) break; if ( memcmp(iClass_Key_Table[i] , "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) { memcpy(iClass_Key_Table[i], item->key, 8); - PrintAndLogEx(SUCCESS, "Added found key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")"to view", i); + PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")"to view", i); break; } } @@ -2370,58 +2423,8 @@ static int CmdHFiClassLookUp(const char *Cmd) { return PM3_SUCCESS; } -int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) { - - char buf[17]; - FILE *f; - uint8_t *p; - int keyitems = 0; - - if (!(f = fopen(filename, "r"))) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); - return 1; - } - - while (fgets(buf, sizeof(buf), f)) { - if (strlen(buf) < 16 || buf[15] == '\n') - continue; - - //goto next line - while (fgetc(f) != '\n' && !feof(f)) {}; - - //The line start with # is comment, skip - if (buf[0] == '#') - continue; - - // doesn't this only test first char only? - if (!isxdigit(buf[0])) { - PrintAndLogEx(ERR, "file content error. '%s' must include 16 HEX symbols", buf); - continue; - } - - // null terminator (skip the rest of the line) - buf[16] = 0; - - p = realloc(*keys, 8 * (keyitems += 64)); - if (!p) { - PrintAndLogEx(ERR, "cannot allocate memory for default keys"); - fclose(f); - return 2; - } - *keys = p; - - memset(*keys + 8 * (*keycnt), 0, 8); - num_to_bytes(strtoull(buf, NULL, 16), 8, *keys + 8 * (*keycnt)); - (*keycnt)++; - memset(buf, 0, sizeof(buf)); - } - fclose(f); - PrintAndLogEx(SUCCESS, "Loaded " _GREEN_("%2d") "keys from %s", *keycnt, filename); - return PM3_SUCCESS; -} - // precalc diversified keys and their MAC -int GenerateMacFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_premac_t *list) { +void GenerateMacFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_premac_t *list) { uint8_t key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -2436,10 +2439,9 @@ int GenerateMacFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_e doMAC(CCNR, div_key, list[i].mac); } - return PM3_SUCCESS; } -int GenerateFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_prekey_t *list) { +void GenerateMacKeyFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_prekey_t *list) { uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -2456,7 +2458,6 @@ int GenerateFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elit // generate MAC doMAC(CCNR, div_key, list[i].mac); } - return PM3_SUCCESS; } // print diversified keys diff --git a/client/cmdhficlass.h b/client/cmdhficlass.h index 9f2b5caac..73304d4d0 100644 --- a/client/cmdhficlass.h +++ b/client/cmdhficlass.h @@ -12,6 +12,7 @@ #define CMDHFICLASS_H__ #include "common.h" +#include "fileutils.h" typedef struct iclass_block { uint8_t d[8]; @@ -32,9 +33,8 @@ int readIclass(bool loop, bool verbose); void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t endblock, size_t filesize); void HFiClassCalcDivKey(uint8_t *CSN, uint8_t *KEY, uint8_t *div_key, bool elite); -int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt); -int GenerateMacFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_premac_t *list); -int GenerateFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_prekey_t *list); +void GenerateMacFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_premac_t *list); +void GenerateMacKeyFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_prekey_t *list); void PrintPreCalcMac(uint8_t *keys, int keycnt, iclass_premac_t *pre_list); void PrintPreCalc(iclass_prekey_t *list, int itemcnt); #endif From 6e54adcb7cf1a53148816f689a70fdd0e0ec2a24 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 09:53:28 +0200 Subject: [PATCH 159/347] fix: 'hw version' - identifing os on unknown.. --- client/cmdhw.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index fe6dc2b4d..4ef55dab9 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -627,53 +627,58 @@ void pm3_version(bool verbose, bool oneliner) { #if defined(__APPLE__) || defined(__MACH__) #ifndef PM3HOSTOS -# define PM3HOSTOS "OS X" +# define PM3HOSTOS "on OS X" #endif #elif defined(_MINGW_) #ifndef PM3HOSTOS -# define PM3HOSTOS "MingW" +# define PM3HOSTOS "on MingW" #endif #elif defined(__LINUX__) #ifndef PM3HOSTOS -# define PM3HOSTOS "linux" +# define PM3HOSTOS "on linux" #endif #elif defined(__FreeBSd__) #ifndef PM3HOSTOS -# define PM3HOSTOS "FreeBSD" +# define PM3HOSTOS "on FreeBSD" #endif #elif defined(__NetBSD__) #ifndef PM3HOSTOS -# define PM3HOSTOS "NetBSD" +# define PM3HOSTOS "on NetBSD" #endif #elif defined(__OpenBSD__) #ifndef PM3HOSTOS -# define PM3HOSTOS "OpenBSD" +# define PM3HOSTOS "on OpenBSD" #endif #elif defined(_WIN32) | defined(__WIN32__) #ifndef PM3HOSTOS -# define PM3HOSTOS "Windows (32b)" +# define PM3HOSTOS "on Windows (32b)" #endif #elif defined(_WIN64) | defined(__WIN64__) #ifndef PM3HOSTOS -# define PM3HOSTOS "Windows (64b)" +# define PM3HOSTOS "on Windows (64b)" #endif #elif defined(__ANDROID__) || defined(ANDROID) #ifndef PM3HOSTOS -# define PM3HOSTOS "Android" +# define PM3HOSTOS "on Android" #endif #endif +#ifndef PM3HOSTOS +# define PM3HOSTOS "" +#endif + + if (oneliner) { - PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__) " on " _YELLOW_(PM3HOSTOS)); + PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__) " %s", _YELLOW_(PM3HOSTOS)); return; } From fcd9b42dca5fa3023ccfaa98a6f4929a8dddcd54 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 29 Aug 2019 10:07:40 +0200 Subject: [PATCH 160/347] reintroduce _stat on mingw, needed to strip path --- client/ui.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/client/ui.c b/client/ui.c index e6edb4369..5e33c7eaf 100644 --- a/client/ui.c +++ b/client/ui.c @@ -58,9 +58,21 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) strcpy(path, user_path); strcat(path, PM3_USER_DIRECTORY); -// Mingw: _stat fails on mangled HOME path /pm3 => C:\ProxSpace\pm3, while stat works fine + int result; +#ifdef _WIN32 + struct _stat st; + // Mingw _stat fails if path ends with /, so let's use a stripped path + if (path[strlen(path)-1]=='/') { + path[strlen(path)-1]='\0'; + result = _stat(path, &st); + path[strlen(path)]='/'; + } else { + result = _stat(path, &st); + } +#else struct stat st; - int result = stat(path, &st); + result = stat(path, &st); +#endif if ((result != 0) && create_home) { #ifdef _WIN32 @@ -216,7 +228,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { timenow = gmtime(&now); strftime(filename, sizeof(filename), PROXLOG, timenow); if (searchHomeFilePath(&my_logfile_path, filename, true) != PM3_SUCCESS) { - fprintf(stderr, "Could not create $HOME/.proxmark3/%s, no log will be recorded\n", filename); + fprintf(stderr, "Could not create $HOME" PM3_USER_DIRECTORY "%s, no log will be recorded\n", filename); my_logfile_path = NULL; logging = 0; } else { @@ -224,8 +236,9 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { if (logfile == NULL) { fprintf(stderr, "Can't open logfile %s, logging disabled!\n", my_logfile_path); logging = 0; + } else { + printf("Session is logged into %s\n", my_logfile_path); } - printf("Session is logged into %s\n", my_logfile_path); free(my_logfile_path); } } From b10edbaddc1b0239afaabf4aabcce66510a377cc Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 29 Aug 2019 10:31:37 +0200 Subject: [PATCH 161/347] user dir: rework err msgs --- client/proxmark3.c | 2 +- client/ui.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 913f3735f..cb3444ad7 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -104,7 +104,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { char *my_history_path = NULL; if (searchHomeFilePath(&my_history_path, PROXHISTORY, true) != PM3_SUCCESS) { - PrintAndLogEx(ERR, "could not create $HOME/" PROXHISTORY ", no history will be recorded"); + PrintAndLogEx(ERR, "No history will be recorded"); my_history_path = NULL; } else { read_history(my_history_path); diff --git a/client/ui.c b/client/ui.c index 5e33c7eaf..dfd0c2b04 100644 --- a/client/ui.c +++ b/client/ui.c @@ -50,8 +50,10 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) if (foundpath == NULL) return PM3_EINVARG; char *user_path = getenv("HOME"); - if (user_path == NULL) + if (user_path == NULL) { + fprintf(stderr, "Could not retrieve $HOME from the environment\n"); return PM3_EFILE; + } char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1, sizeof(char)); if (path == NULL) return PM3_EMALLOC; @@ -80,6 +82,7 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) #else if (mkdir(path, 0700)) { #endif + fprintf(stderr, "Could not create user directory %s\n", path); free(path); return PM3_EFILE; } @@ -228,7 +231,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { timenow = gmtime(&now); strftime(filename, sizeof(filename), PROXLOG, timenow); if (searchHomeFilePath(&my_logfile_path, filename, true) != PM3_SUCCESS) { - fprintf(stderr, "Could not create $HOME" PM3_USER_DIRECTORY "%s, no log will be recorded\n", filename); + fprintf(stderr, "Logging disabled!\n\n"); my_logfile_path = NULL; logging = 0; } else { From c3c5011e1dbccf3736ed0a7abd0b4a3467b102cd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 10:36:48 +0200 Subject: [PATCH 162/347] textual --- client/cmdhw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 4ef55dab9..3817de3c8 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -694,7 +694,7 @@ void pm3_version(bool verbose, bool oneliner) { PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? - PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__ " on " PM3HOSTOS); + PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS); PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 ]"); PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); From 74f96be6bebb9dc01c00343d9ce3043fc4a13542 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 10:46:57 +0200 Subject: [PATCH 163/347] textual --- client/cmdhw.c | 20 ++++++++++---------- client/ui.c | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index 3817de3c8..ac7d4cbd0 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -627,47 +627,47 @@ void pm3_version(bool verbose, bool oneliner) { #if defined(__APPLE__) || defined(__MACH__) #ifndef PM3HOSTOS -# define PM3HOSTOS "on OS X" +# define PM3HOSTOS " on OS X" #endif #elif defined(_MINGW_) #ifndef PM3HOSTOS -# define PM3HOSTOS "on MingW" +# define PM3HOSTOS " on MingW" #endif #elif defined(__LINUX__) #ifndef PM3HOSTOS -# define PM3HOSTOS "on linux" +# define PM3HOSTOS " on linux" #endif #elif defined(__FreeBSd__) #ifndef PM3HOSTOS -# define PM3HOSTOS "on FreeBSD" +# define PM3HOSTOS " on FreeBSD" #endif #elif defined(__NetBSD__) #ifndef PM3HOSTOS -# define PM3HOSTOS "on NetBSD" +# define PM3HOSTOS " on NetBSD" #endif #elif defined(__OpenBSD__) #ifndef PM3HOSTOS -# define PM3HOSTOS "on OpenBSD" +# define PM3HOSTOS " on OpenBSD" #endif #elif defined(_WIN32) | defined(__WIN32__) #ifndef PM3HOSTOS -# define PM3HOSTOS "on Windows (32b)" +# define PM3HOSTOS " on Windows (32b)" #endif #elif defined(_WIN64) | defined(__WIN64__) #ifndef PM3HOSTOS -# define PM3HOSTOS "on Windows (64b)" +# define PM3HOSTOS " on Windows (64b)" #endif #elif defined(__ANDROID__) || defined(ANDROID) #ifndef PM3HOSTOS -# define PM3HOSTOS "on Android" +# define PM3HOSTOS " on Android" #endif #endif @@ -678,7 +678,7 @@ void pm3_version(bool verbose, bool oneliner) { if (oneliner) { - PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__) " %s", _YELLOW_(PM3HOSTOS)); + PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS)); return; } diff --git a/client/ui.c b/client/ui.c index dfd0c2b04..6f177078d 100644 --- a/client/ui.c +++ b/client/ui.c @@ -231,16 +231,16 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { timenow = gmtime(&now); strftime(filename, sizeof(filename), PROXLOG, timenow); if (searchHomeFilePath(&my_logfile_path, filename, true) != PM3_SUCCESS) { - fprintf(stderr, "Logging disabled!\n\n"); + fprintf(stderr, "[-] Logging disabled!\n\n"); my_logfile_path = NULL; logging = 0; } else { logfile = fopen(my_logfile_path, "a"); if (logfile == NULL) { - fprintf(stderr, "Can't open logfile %s, logging disabled!\n", my_logfile_path); + fprintf(stderr, "[-] Can't open logfile %s, logging disabled!\n", my_logfile_path); logging = 0; } else { - printf("Session is logged into %s\n", my_logfile_path); + printf("[=] Session log %s\n", my_logfile_path); } free(my_logfile_path); } From 0d6a29197b81e8568d94b8633c4b33e47022dd89 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 29 Aug 2019 11:10:54 +0200 Subject: [PATCH 164/347] rework OS/ARCH info --- client/cmdhw.c | 93 ++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/client/cmdhw.c b/client/cmdhw.c index ac7d4cbd0..c81efda9e 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -619,66 +619,61 @@ int CmdHW(const char *Cmd) { void pm3_version(bool verbose, bool oneliner) { -#if defined(__clang__) +#if defined(__MINGW64__) +# define PM3CLIENTCOMPILER "MinGW-w64 " +#elif defined(__MINGW32__) +# define PM3CLIENTCOMPILER "MinGW " +#elif defined(__clang__) # define PM3CLIENTCOMPILER "Clang/LLVM " #elif defined(__GNUC__) || defined(__GNUG__) # define PM3CLIENTCOMPILER "GCC " +#else +# define PM3CLIENTCOMPILER "unknown compiler " #endif #if defined(__APPLE__) || defined(__MACH__) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on OS X" -#endif - -#elif defined(_MINGW_) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on MingW" -#endif - -#elif defined(__LINUX__) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on linux" -#endif - -#elif defined(__FreeBSd__) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on FreeBSD" -#endif - -#elif defined(__NetBSD__) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on NetBSD" -#endif - -#elif defined(__OpenBSD__) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on OpenBSD" -#endif - -#elif defined(_WIN32) | defined(__WIN32__) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on Windows (32b)" -#endif - -#elif defined(_WIN64) | defined(__WIN64__) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on Windows (64b)" -#endif - +# define PM3HOSTOS " OS:OSX" #elif defined(__ANDROID__) || defined(ANDROID) -#ifndef PM3HOSTOS -# define PM3HOSTOS " on Android" -#endif +// must be tested before __linux__ +# define PM3HOSTOS " OS:Android" +#elif defined(__linux__) +# define PM3HOSTOS " OS:Linux" +#elif defined(__FreeBSD__) +# define PM3HOSTOS " OS:FreeBSD" +#elif defined(__NetBSD__) +# define PM3HOSTOS " OS:NetBSD" +#elif defined(__OpenBSD__) +# define PM3HOSTOS " OS:OpenBSD" +#elif defined(__CYGWIN__) +# define PM3HOSTOS " OS:Cygwin" +#elif defined(_WIN64) | defined(__WIN64__) +// must be tested before _WIN32 +# define PM3HOSTOS " OS:Windows (64b)" +#elif defined(_WIN32) | defined(__WIN32__) +# define PM3HOSTOS " OS:Windows (32b)" +#else +# define PM3HOSTOS " OS:unknown" #endif -#ifndef PM3HOSTOS -# define PM3HOSTOS "" +#if defined(__x86_64__) +# define PM3HOSTARCH " ARCH:x86_64" +#elif defined(__i386__) +# define PM3HOSTARCH " ARCH:x86" +#elif defined(__aarch64__) +# define PM3HOSTARCH " ARCH:aarch64" +#elif defined(__arm__) +# define PM3HOSTARCH " ARCH:arm" +#elif defined(__powerpc64__) +# define PM3HOSTARCH " ARCH:powerpc64" +#elif defined(__mips__) +# define PM3HOSTARCH " ARCH:mips" +#else +# define PM3HOSTARCH " ARCH:unknown" #endif - - if (oneliner) { - PrintAndLogEx(NORMAL, "Client: RRG/Iceman compiled with " _YELLOW_(PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS)); + // For "proxmark3 -v", simple printf, avoid logging + printf("Client: RRG/Iceman compiled with " PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS PM3HOSTARCH "\n"); return; } @@ -694,7 +689,7 @@ void pm3_version(bool verbose, bool oneliner) { PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? - PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS); + PrintAndLogEx(NORMAL, " compiled with " PM3CLIENTCOMPILER __VERSION__ PM3HOSTOS PM3HOSTARCH); PrintAndLogEx(NORMAL, "\n [ PROXMARK RDV4 ]"); PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); From f0d73dc3d1907efcc6c9b39b099663aa6c2b71e0 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 14:17:39 +0200 Subject: [PATCH 165/347] chg: 'hf iclass decrypt' - now takes transport key as param. also search for key / dump. Also saves decrypted to bin/eml/json_decref chg: 'hf iclass encrypt' - now takes transport key as param. --- client/cmdhficlass.c | 154 ++++++++++++++++++++----------------------- client/fileutils.c | 53 ++++++++++++++- client/fileutils.h | 16 ++++- 3 files changed, 136 insertions(+), 87 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 30b2a0560..efb70c69c 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -790,75 +790,61 @@ static int CmdHFiClassELoad(const char *Cmd) { return PM3_SUCCESS; } -static int readKeyfile(const char *filename, size_t len, uint8_t **buffer) { - - char *path; - int res = searchFile(&path, PM3_USER_DIRECTORY, filename, ".bin"); - if (res != PM3_SUCCESS) { - PrintAndLogEx(INFO, "res: %d Curr path:: %s", res, path); - return PM3_EFILE; - } - - size_t datalen = 0; - res = loadFile(path, ".bin", (void*)*buffer, len, &datalen); - if ( res != PM3_SUCCESS ) - return res; - - if (datalen != len) { - PrintAndLogEx(ERR, "ERROR, Wrong filesize. Got %d bytes, expected %d", datalen, len); - return PM3_EFILE; - } - return PM3_SUCCESS; -} +#define ICLASS_DECRYPTION_BIN "iclass_decryptionkey.bin" static int CmdHFiClassDecrypt(const char *Cmd) { - - char opt = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) < 1 || opt == 'h') return usage_hf_iclass_decrypt(); - - uint8_t key[16] = { 0 }; - uint8_t *keyptr = key; - if (readKeyfile("iclass_decryptionkey", sizeof(key), &keyptr) != PM3_SUCCESS) - return usage_hf_iclass_decrypt(); - - PrintAndLogEx(SUCCESS, "decryption key loaded from file"); - - //Open the tagdump-file - FILE *f; + + bool errors = false; + bool have_key = false; + uint8_t cmdp = 0; + + size_t keylen = 0; + uint8_t key[32] = {0}; + uint8_t *keyptr = NULL; + + size_t decryptedlen = 0; + uint8_t *decrypted = NULL; char filename[FILE_PATH_SIZE]; - if (opt == 'f' && param_getstr(Cmd, 1, filename, sizeof(filename)) > 0) { - f = fopen(filename, "rb"); - if (!f) { - PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); - return PM3_EFILE; + + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_hf_iclass_decrypt(); + case 'f': + if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename) ) == 0){ + errors = true; + break; + } + + if ( loadFile_safe(filename, "", (void**)&decrypted, &decryptedlen) != PM3_SUCCESS ) { + errors = true; + break; + } + cmdp += 2; + break; + case 'k': + if (param_gethex(Cmd, cmdp + 1, key, 32)) { + PrintAndLogEx(ERR, "Transport key must include 32 HEX symbols"); + errors = true; + } + have_key = true; + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'\n", param_getchar(Cmd, cmdp)); + errors = true; + break; } - } else { - return usage_hf_iclass_decrypt(); } - fseek(f, 0, SEEK_END); - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); + if (errors || cmdp < 1) return usage_hf_iclass_decrypt(); - if (fsize <= 0) { - PrintAndLogEx(ERR, "error, when getting filesize"); - fclose(f); - return 2; - } - - uint8_t *decrypted = calloc(fsize, sizeof(uint8_t)); - if (!decrypted) { - PrintAndLogEx(WARNING, "Failed to allocate memory"); - fclose(f); - return 1; - } - - size_t bytes_read = fread(decrypted, 1, fsize, f); - fclose(f); - if (bytes_read == 0) { - PrintAndLogEx(ERR, "file reading error"); - free(decrypted); - return 3; + if ( have_key == false ) { + int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void**)&keyptr, &keylen); + if (res != PM3_SUCCESS) + return PM3_EINVARG; + + memcpy(key, keyptr, sizeof(key)); } picopass_hdr *hdr = (picopass_hdr *)decrypted; @@ -870,13 +856,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { uint8_t app_areas = 2; uint8_t max_blk = 31; getMemConfig(mem, chip, &max_blk, &app_areas, &kb); - - //Use the first block (CSN) for filename - char outfilename[FILE_PATH_SIZE] = {0}; - snprintf(outfilename, FILE_PATH_SIZE, "iclass_tagdump-%02x%02x%02x%02x%02x%02x%02x%02x-decrypted", - hdr->csn[0], hdr->csn[1], hdr->csn[2], hdr->csn[3], - hdr->csn[4], hdr->csn[5], hdr->csn[6], hdr->csn[7]); - + // tripledes mbedtls_des3_context ctx; mbedtls_des3_set2key_dec(&ctx, key); @@ -894,12 +874,18 @@ static int CmdHFiClassDecrypt(const char *Cmd) { } } - saveFile(outfilename, ".bin", decrypted, fsize); - saveFileEML(outfilename, decrypted, fsize, 8); - saveFileJSON(outfilename, jsfIclass, decrypted, fsize); + //Use the first block (CSN) for filename + char *fptr = calloc(42, sizeof(uint8_t)); + strcat(fptr, "hf-iclass-"); + FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn) ); + + saveFile(fptr, ".bin", decrypted, decryptedlen); + saveFileEML(fptr, decrypted, decryptedlen, 8); + saveFileJSON(fptr, jsfIclass, decrypted, decryptedlen); - printIclassDumpContents(decrypted, 1, (fsize / 8), fsize); + printIclassDumpContents(decrypted, 1, (decryptedlen / 8), decryptedlen); free(decrypted); + free(fptr); return PM3_SUCCESS; } @@ -917,7 +903,7 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { bool have_key = false; uint8_t blk_data[8] = {0}; uint8_t key[16] = {0}; - uint8_t *keyptr = key; + uint8_t *keyptr = NULL; uint8_t cmdp = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -925,17 +911,16 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { case 'h': return usage_hf_iclass_encrypt(); case 'd': - //get the bytes to encrypt - if (param_gethex(Cmd, cmdp + 1, blk_data, 16) != PM3_SUCCESS) { + if (param_gethex(Cmd, cmdp + 1, blk_data, 16)) { PrintAndLogEx(ERR, "Block data must include 16 HEX symbols"); - errors = true;; + errors = true; } cmdp += 2; break; case 'k': - if (param_gethex(Cmd, cmdp + 1, key, 32) != PM3_SUCCESS) { + if (param_gethex(Cmd, cmdp + 1, key, 32)) { PrintAndLogEx(ERR, "Transport key must include 32 HEX symbols"); - errors = true;; + errors = true; } have_key = true; cmdp += 2; @@ -950,10 +935,12 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { if (errors || cmdp < 1) return usage_hf_iclass_encrypt(); if ( have_key == false ) { - if (readKeyfile("./iclass_decryptionkey", sizeof(key), &keyptr) != PM3_SUCCESS) { - return usage_hf_iclass_encrypt(); - } - PrintAndLogEx(SUCCESS, "Loaded transport key from decryption file"); + size_t keylen = 0; + int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void**)&keyptr, &keylen); + if (res != PM3_SUCCESS) + return PM3_EINVARG; + + memcpy(key, keyptr, sizeof(key)); } iClassEncryptBlkData(blk_data, key); @@ -1283,6 +1270,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { PrintAndLogEx(SUCCESS, "saving dump file - %d blocks read", gotBytes / 8); saveFile(filename, ".bin", tag_data, gotBytes); saveFileEML(filename, tag_data, gotBytes, 8); + saveFileJSON(filename, jsfIclass, tag_data, gotBytes); return 1; } diff --git a/client/fileutils.c b/client/fileutils.c index 72771f900..1a6b40e53 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -50,7 +50,7 @@ #include "scandir.h" #endif -#define PATH_MAX_LENGTH 100 +#define PATH_MAX_LENGTH 200 /** * @brief checks if a file exists @@ -289,7 +289,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s for (size_t i = 0; i < (datalen / 8); i++) { char path[PATH_MAX_LENGTH] = {0}; - sprintf(path, "$blocks.%zu", i); + sprintf(path, "$.blocks.%zu", i); JsonSaveBufAsHexCompact(root, path, data + (i * 8), 8); } break; @@ -341,6 +341,7 @@ int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char *fptr) { return PM3_SUCCESS; } + int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen) { if (data == NULL) return 1; @@ -401,6 +402,54 @@ out: return retval; } +int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, size_t *datalen) { + + char *path; + int res = searchFile(&path, "", preferredName, suffix); + if (res != PM3_SUCCESS) { + PrintAndLogEx(INFO, "res: %d Curr path:: %s", res, path); + return PM3_EFILE; + } + + int retval = PM3_SUCCESS; + + FILE *f = fopen(path, "rb"); + if (!f) { + PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path); + return PM3_EFILE; + } + + // get filesize in order to malloc memory + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + fseek(f, 0, SEEK_SET); + + if (fsize <= 0) { + PrintAndLogEx(FAILED, "error, when getting filesize"); + return PM3_EFILE; + } + + *pdata = calloc(fsize, sizeof(uint8_t)); + if (!pdata) { + PrintAndLogEx(FAILED, "error, cannot allocate memory"); + return PM3_EMALLOC; + } + + size_t bytes_read = fread(*pdata, 1, fsize, f); + + fclose(f); + + if (bytes_read != fsize) { + PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); + return PM3_EFILE; + } + + *datalen = bytes_read; + + PrintAndLogEx(SUCCESS, "loaded %d bytes from binary file " _YELLOW_("%s"), bytes_read, preferredName); + return retval; +} + int loadFileEML(const char *preferredName, void *data, size_t *datalen) { if (data == NULL) return 1; diff --git a/client/fileutils.h b/client/fileutils.h index 7bfc7c138..d7fdb13a3 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -120,7 +120,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s */ int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char *fptr); -/** STUB +/** * @brief Utility function to load data from a binary file. This method takes a preferred name. * E.g. dumpdata-15.bin * @@ -129,10 +129,22 @@ int createMfcKeyDump(uint8_t sectorsCnt, sector_t *e_sector, char *fptr); * @param data The data array to store the loaded bytes from file * @param maxdatalen the number of bytes that your data array has * @param datalen the number of bytes loaded from file - * @return 0 for ok, 1 for failz + * @return PM3_SUCCESS for ok, PM3_E* for failz */ int loadFile(const char *preferredName, const char *suffix, void *data, size_t maxdatalen, size_t *datalen); + +/** + * @brief Utility function to load data from a binary file. This method takes a preferred name. + * E.g. dumpdata-15.bin, tries to search for it, and allocated memory. + * + * @param preferredName + * @param suffix the file suffix. Including the ".". + * @param data The data array to store the loaded bytes from file + * @param datalen the number of bytes loaded from file + * @return PM3_SUCCESS for ok, PM3_E* for failz +*/ +int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, size_t *datalen); /** * @brief Utility function to load data from a textfile (EML). This method takes a preferred name. * E.g. dumpdata-15.txt From 00f82304e2298e2f2e742421e6893eff3e0da4e2 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 14:33:09 +0200 Subject: [PATCH 166/347] chg: 'hf iclass loclass t' - now uses loadfile_safe --- client/cmdhficlass.c | 12 +++++++----- client/loclass/elite_crack.c | 35 ++++++----------------------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index efb70c69c..52c3ff21c 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -811,7 +811,8 @@ static int CmdHFiClassDecrypt(const char *Cmd) { case 'h': return usage_hf_iclass_decrypt(); case 'f': - if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename) ) == 0){ + if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename) ) == 0) { + PrintAndLogEx(WARNING, "no filename found after f"); errors = true; break; } @@ -1261,9 +1262,10 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { printIclassDumpContents(tag_data, 1, (gotBytes / 8), gotBytes); if (filename[0] == 0) { - snprintf(filename, FILE_PATH_SIZE, "iclass_tagdump-%02x%02x%02x%02x%02x%02x%02x%02x", - tag_data[0], tag_data[1], tag_data[2], tag_data[3], - tag_data[4], tag_data[5], tag_data[6], tag_data[7]); + + //Use the first block (CSN) for filename + strcat(filename, "hf-iclass-"); + FillFileNameByUID(filename, tag_data, "-data", 8 ); } // save the dump to .bin file @@ -1271,7 +1273,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { saveFile(filename, ".bin", tag_data, gotBytes); saveFileEML(filename, tag_data, gotBytes, 8); saveFileJSON(filename, jsfIclass, tag_data, gotBytes); - return 1; + return PM3_SUCCESS; } static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool rawkey, bool verbose) { diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index adf87fb89..735e3c3df 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -540,37 +540,14 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) { * @return */ int bruteforceFile(const char *filename, uint16_t keytable[]) { - FILE *f = fopen(filename, "rb"); - if (!f) { - PrintAndLogEx(WARNING, "Failed to read from file " _YELLOW_("%s"), filename); - return 1; + + size_t dumplen = 0; + uint8_t *dump = NULL; + if ( loadFile_safe(filename, "", (void**)&dump, &dumplen) != PM3_SUCCESS ) { + return PM3_EFILE; } - fseek(f, 0, SEEK_END); - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); - - if (fsize <= 0) { - PrintAndLogEx(ERR, "Error, when getting filesize"); - fclose(f); - return 1; - } - - uint8_t *dump = calloc(fsize, sizeof(uint8_t)); - if (!dump) { - PrintAndLogEx(WARNING, "Failed to allocate memory"); - fclose(f); - return 2; - } - size_t bytes_read = fread(dump, 1, fsize, f); - - fclose(f); - - if (bytes_read < fsize) { - PrintAndLogEx(WARNING, "Warning: could only read %d bytes (should be %d)", bytes_read, fsize); - } - - uint8_t res = bruteforceDump(dump, fsize, keytable); + uint8_t res = bruteforceDump(dump, dumplen, keytable); free(dump); return res; } From d3124d7f4b72d64a69d5c213ebaff9e9230ecd03 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 29 Aug 2019 15:55:30 +0300 Subject: [PATCH 167/347] needs to off v=1 option because of too long log in appveyour --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a0a4b18a9..b8e3636f2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -167,7 +167,7 @@ build_script: #make - bash -c -i 'pwd;make clean;make all V=1' + bash -c -i 'pwd;make clean;make all' #some checks From f3a63767ed22d34afc6e914f9ee6e2351b93a6f1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 15:55:52 +0200 Subject: [PATCH 168/347] chg: 'hf iclass loclass t' - now uses loadfile_safe. However the iclass_key.bin and iclass_dump.bin must be in the new folder structure --- client/cmdhficlass.c | 4 +-- client/loclass/elite_crack.c | 47 +++++++++++++++--------------------- client/loclass/ikeys.c | 38 ++++++++++------------------- 3 files changed, 34 insertions(+), 55 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 52c3ff21c..bd937fe17 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1662,7 +1662,7 @@ static int CmdHFiClass_loclass(const char *Cmd) { errors += doKeyTests(0); errors += testElite(); if (errors) PrintAndLogEx(ERR, "There were errors!!!"); - return errors; + return PM3_ESOFT; } return PM3_SUCCESS; } @@ -1971,7 +1971,7 @@ static int CmdHFiClassManageKeys(const char *Cmd) { case 'n': keyNbr = param_get8(Cmd, cmdp + 1); if (keyNbr >= ICLASS_KEYS_MAX) { - PrintAndLogEx(ERR, "Invalid block number, MAX is "_YELLOW_("%d"), ICLASS_KEYS_MAX); + PrintAndLogEx(ERR, "Invalid block number, MAX is " _YELLOW_("%d"), ICLASS_KEYS_MAX); errors = true; } cmdp += 2; diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index 735e3c3df..bc474fc21 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -569,39 +569,30 @@ int bruteforceFileNoKeys(const char *filename) { // TEST CODE BELOW // ---------------------------------------------------------------------------- static int _testBruteforce() { - int errors = 0; - if (true) { - // First test - PrintAndLogEx(INFO, "Testing crack from dumpfile..."); - /** - Expected values for the dumpfile: - High Security Key Table + PrintAndLogEx(INFO, "Testing crack from dumpfile..."); - 00 F1 35 59 A1 0D 5A 26 7F 18 60 0B 96 8A C0 25 C1 - 10 BF A1 3B B0 FF 85 28 75 F2 1F C6 8F 0E 74 8F 21 - 20 14 7A 55 16 C8 A9 7D B3 13 0C 5D C9 31 8D A9 B2 - 30 A3 56 83 0F 55 7E DE 45 71 21 D2 6D C1 57 1C 9C - 40 78 2F 64 51 42 7B 64 30 FA 26 51 76 D3 E0 FB B6 - 50 31 9F BF 2F 7E 4F 94 B4 BD 4F 75 91 E3 1B EB 42 - 60 3F 88 6F B8 6C 2C 93 0D 69 2C D5 20 3C C1 61 95 - 70 43 08 A0 2F FE B3 26 D7 98 0B 34 7B 47 70 A0 AB + /** + Expected values for the dumpfile: + High Security Key Table - **** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 **** - **/ - uint16_t keytable[128] = {0}; + 00 F1 35 59 A1 0D 5A 26 7F 18 60 0B 96 8A C0 25 C1 + 10 BF A1 3B B0 FF 85 28 75 F2 1F C6 8F 0E 74 8F 21 + 20 14 7A 55 16 C8 A9 7D B3 13 0C 5D C9 31 8D A9 B2 + 30 A3 56 83 0F 55 7E DE 45 71 21 D2 6D C1 57 1C 9C + 40 78 2F 64 51 42 7B 64 30 FA 26 51 76 D3 E0 FB B6 + 50 31 9F BF 2F 7E 4F 94 B4 BD 4F 75 91 E3 1B EB 42 + 60 3F 88 6F B8 6C 2C 93 0D 69 2C D5 20 3C C1 61 95 + 70 43 08 A0 2F FE B3 26 D7 98 0B 34 7B 47 70 A0 AB - //Test a few variants - if (fileExists("iclass_dump.bin")) { - errors |= bruteforceFile("iclass_dump.bin", keytable); - } else if (fileExists("loclass/iclass_dump.bin")) { - errors |= bruteforceFile("loclass/iclass_dump.bin", keytable); - } else if (fileExists("client/loclass/iclass_dump.bin")) { - errors |= bruteforceFile("client/loclass/iclass_dump.bin", keytable); - } else { - PrintAndLogEx(ERR, "Error: The file " _YELLOW_("iclass_dump.bin") "was not found!"); - } + **** The 64-bit HS Custom Key Value = 5B7C62C491C11B39 **** + **/ + uint16_t keytable[128] = {0}; + int errors = bruteforceFile("iclass_dump.bin", keytable); + if (errors) { + PrintAndLogEx(ERR, "Error: The file " _YELLOW_("iclass_dump.bin") "was not found!"); } + return errors; } diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index 53f7848de..f53f80221 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -654,33 +654,21 @@ static int doTestsWithKnownInputs() { return errors; } -static bool readKeyFile(uint8_t key[8]) { - bool retval = false; - //Test a few variants - char filename[30] = {0}; +static bool readKeyFile(uint8_t* key, size_t keylen) { - if (fileExists("iclass_key.bin")) { - sprintf(filename, "%s.bin", "iclass_key"); - } else if (fileExists("loclass/iclass_key.bin")) { - sprintf(filename, "%s.bin", "loclass/iclass_key"); - } else if (fileExists("client/loclass/iclass_key.bin")) { - sprintf(filename, "%s.bin", "client/loclass/iclass_key"); + size_t len = 0; + uint8_t *keyptr = NULL; + if ( loadFile_safe("iclass_key.bin", "", (void**)&keyptr, &len) != PM3_SUCCESS ) { + return false; } - - if (strlen(filename) == 0) - return retval; - - FILE *f = fopen(filename, "rb"); - if (!f) - return retval; - - size_t bytes_read = fread(key, sizeof(uint8_t), 8, f); - if (bytes_read == 8) - retval = true; - - fclose(f); - return retval; + + if ( keylen != len ) { + return false; + } + + memcpy(key, keyptr, keylen ); + return true; } int doKeyTests(uint8_t debuglevel) { @@ -688,7 +676,7 @@ int doKeyTests(uint8_t debuglevel) { PrintAndLogEx(INFO, "Checking if the master key is present (iclass_key.bin)..."); uint8_t key[8] = {0}; - if (!readKeyFile(key)) { + if (readKeyFile(key, sizeof(key)) == false) { PrintAndLogEx(FAILED, "Master key not present, will not be able to do all testcases"); } else { From 6529c9616fbb238feb2513eae817c747501d5507 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 16:56:22 +0200 Subject: [PATCH 169/347] chg: remove termcap and use pkg-config for ncurses (@ZeroChaos-) --- client/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Makefile b/client/Makefile index fc7fa520b..1ca87678a 100644 --- a/client/Makefile +++ b/client/Makefile @@ -90,7 +90,7 @@ else LIBS := -I/usr/local/opt/readline/include $(LIBS) else LUALIB += -ldl - LDLIBS += -ltermcap -lncurses + LDLIBS += $(shell pkg-config --libs ncurses 2>/dev/null) LUAPLATFORM = linux endif endif From 420ef35c5c07b9f522d83968ad6884960805d473 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 17:01:33 +0200 Subject: [PATCH 170/347] textual --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7dc5d6a9..999d08676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ 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... ## [unreleased][unreleased] + - Chg remove deprecated termcap, use ncurses instead (@ZeroChaos-) + - Chg 'hf iclass encrypt' - now takes transport key as param. (@iceman1001) + - Chg 'hf iclass decrypt' - now takes transport key as param. (@iceman1001) + - Chg 'hf mf fchk m' - now secretly dumps card to emul, if all keys are found (@iceman1001) - Chg history and logfile are now saved into $HOME/.proxmark3/ (@doegox) - Chg optimization of iclass mac calculations on deviceside (@pwpiwi) - Add 'hf mf autopwn' - Autopwn function for Mifare Classic, extract all keys and dump card memory (@matthiaskonrath) From 0a81a72758785bd1698f5bfc968f7bda8e42c680 Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Thu, 29 Aug 2019 19:21:51 +0300 Subject: [PATCH 171/347] appveyour next fix (#373) --- appveyor.yml | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b8e3636f2..b77cef02d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -73,12 +73,13 @@ clone_script: Write-Host "[ OK ]" -ForegroundColor Green - Write-Host "Update msys2 packages..." -NoNewLine + Write-Host "Update msys2 packages..." $env:Path = "C:\ProxSpace\msys2\usr\bin;C:\ProxSpace\msys2\mingw32\bin;C:\ProxSpace\gcc-arm-none-eabi\bin;$env:Path" Function ExecUpdate($Name, $Cmd, $ErrorLine) { + Write-Host "Exec [$Name]... " -NoNewLine #--- begin Job $Job = Start-Job -Name "$Name" -ScriptBlock { @@ -96,10 +97,16 @@ clone_script: $JobTime=[System.Environment]::TickCount while($true) { - Receive-Job -Job $Job -Keep -OutVariable Res 2>&1 6>&1 | Out-Null + Try { + $Res = Receive-Job -Job $Job -Keep 2>&1 6>&1 + } + Catch { + $Res = "" + Write-host "error in Receive-Job" + } if ($Res -is "String" -and $Res -like "*$ErrorLine*"){ - Write-host "Exit by stop phrase" + Write-host "Exit by stop phrase" -ForegroundColor Green break } @@ -107,7 +114,7 @@ clone_script: [bool]$needexit = $false ForEach($line in $Res){ if ($line -like "*$ErrorLine*"){ - Write-host "Exit by stop phrase [obj]" + Write-host "Exit by stop phrase [obj]" -ForegroundColor Green $needexit = $true break } @@ -118,12 +125,12 @@ clone_script: } if(Wait-Job $Job -Timeout 5){ - Write-host "Exit by end job" + Write-host "Exit by end job" -ForegroundColor Green break } - if ([System.Environment]::TickCount-$JobTime -gt 600000) { - Write-host "Exit by timeout" + if ([System.Environment]::TickCount-$JobTime -gt 1000000) { + Write-host "Exit by timeout" -ForegroundColor Yellow break } } @@ -135,6 +142,7 @@ clone_script: ExecUpdate "update2" "C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null" "terminate?MSYS2" + Write-Host "Update " -NoNewLine Write-Host "[ OK ]" -ForegroundColor Green install: - ps: >- @@ -341,6 +349,7 @@ test_script: Remove-Job -Force $Job if(!$res){ + Write-host "--------------------- tests fail" -ForegroundColor Red $global:TestsPassed=$false } } @@ -364,11 +373,11 @@ test_script: #proxmark logic tests - ExecTest "proxmark help" "proxmark3 -h" {bash -lc 'cd ~/client;./proxmark3 -h | grep -q wait && echo Passed || echo Failed'} + ExecTest "proxmark help" "proxmark3 -h" {bash -lc 'cd ~/client;./proxmark3 -h | grep -q wait && echo passed || echo failed'} - ExecTest "proxmark help text ISO7816" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t 2>&1 | grep -q ISO7816 && echo Passed || echo Failed'} + ExecTest "proxmark help text ISO7816" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t | grep -q ISO7816 && echo passed || echo failed'} - ExecTest "proxmark help text hardnested" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t 2>&1 | grep -q hardnested && echo Passed || echo Failed'} + ExecTest "proxmark help text hardnested" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t | grep -q hardnested && echo passed || echo failed'} ExecTest "hf mf offline text" "hf mf" {bash -lc "cd ~/client;./proxmark3 -c 'hf mf'"} "at_enc" From 73cefedd61736a117a8fcf8d4f4cff96bd712580 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 29 Aug 2019 18:22:00 +0200 Subject: [PATCH 172/347] remove entirely ncurses, not needed nowadays --- CHANGELOG.md | 1 + COMPILING.txt | 4 +++- client/Makefile | 1 - .../Linux-Installation-Instructions.md | 8 ++------ .../Windows-Installation-Instructions.md | 2 +- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 999d08676..9a3df33cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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... ## [unreleased][unreleased] + - Chg remove entirely ncurses, not needed nowadays (@doegox) - Chg remove deprecated termcap, use ncurses instead (@ZeroChaos-) - Chg 'hf iclass encrypt' - now takes transport key as param. (@iceman1001) - Chg 'hf iclass decrypt' - now takes transport key as param. (@iceman1001) diff --git a/COMPILING.txt b/COMPILING.txt index 04ff1d8bf..b1f5cb960 100644 --- a/COMPILING.txt +++ b/COMPILING.txt @@ -1,3 +1,6 @@ + +** BEWARE the instructions here might be outdated, better refer to doc/md/Installation_Instructions/ ** + The project compiles on Linux, Mac OS X and Windows (MinGW/MSYS). it requires: @@ -7,7 +10,6 @@ it requires: - libusb - perl - an ARM cross-compiler to compile the firmware -- libncurses5-dev and optionally QT for the GUI diff --git a/client/Makefile b/client/Makefile index 1ca87678a..ccf7d5ab8 100644 --- a/client/Makefile +++ b/client/Makefile @@ -90,7 +90,6 @@ else LIBS := -I/usr/local/opt/readline/include $(LIBS) else LUALIB += -ldl - LDLIBS += $(shell pkg-config --libs ncurses 2>/dev/null) LUAPLATFORM = linux endif endif diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index fe23db001..476309fb6 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -25,7 +25,7 @@ Install the requirements ```sh sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev \ -libusb-0.1-4 libusb-dev perl pkg-config wget libncurses5-dev gcc-arm-none-eabi libnewlib-dev libqt4-dev +libusb-0.1-4 libusb-dev perl pkg-config wget gcc-arm-none-eabi libnewlib-dev libqt4-dev ``` If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. @@ -35,11 +35,7 @@ If you get some (non blocking) error at runtime such as _Gtk-Message: Failed to ## On ArchLinux ```sh -sudo pacman -Sy base-devel p7zip libusb readline ncurses arm-none-eabi-gcc arm-none-eabi-newlib git --needed -``` -Additional AUR packages: -```sh -yaourt -S termcap +sudo pacman -Sy base-devel p7zip libusb readline arm-none-eabi-gcc arm-none-eabi-newlib git --needed ``` If you want graphical output (such as in `hw tune`): ```sh diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index db9a9084f..e2895f73a 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -99,7 +99,7 @@ Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instruct ```sh sudo apt-get update sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev libusb-0.1-4 \ -libusb-dev perl pkg-config wget libncurses5-dev gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ +libusb-dev perl pkg-config wget gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ libqt4-dev ``` From e6f2644c1be504c312fdb1d366fe2ecf66c60770 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 29 Aug 2019 18:53:54 +0200 Subject: [PATCH 173/347] remove srecswap.pl, never seen modern jtag requiring it --- tools/srecswap.pl | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 tools/srecswap.pl diff --git a/tools/srecswap.pl b/tools/srecswap.pl deleted file mode 100644 index 47db8e687..000000000 --- a/tools/srecswap.pl +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/perl - -# endian-swap S records; we need this because the JTAG tools we're using -# expect the memory image in byte-swapped format -# -# Jonathan Westhues, April 2004 - -if(@ARGV == 0) { - die "usage: $0 file-to-endian-swap.s19 > out.s19\n"; -} - -while(<>) { - chomp; - - if(/^S0/) { - next; - } - if(/^S7/) { - print "$_\n"; - next; - } - - if(not /^S3(..)(........)(.*)(..)$/) { - die "bad S record at line $.\n"; - } - - $data = $3; - $checksum = $4; - - print "S3$1$2"; - while($data =~ m#(..)(..)(..)(..)#g) { - print "$4$3$2$1"; - } - print "$checksum\n"; -} From 04f3cbe58c77cf7ba68cd05bdd2c9fbe1eaa5b6e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 29 Aug 2019 19:06:11 +0200 Subject: [PATCH 174/347] Update COMPILING.txt to point to the docs, update some instructions --- COMPILING.txt | 133 +----------------- ...OS-X-Homebrew-Installation-Instructions.md | 4 +- .../Windows-Installation-Instructions.md | 2 +- 3 files changed, 5 insertions(+), 134 deletions(-) diff --git a/COMPILING.txt b/COMPILING.txt index b1f5cb960..58ee40c08 100644 --- a/COMPILING.txt +++ b/COMPILING.txt @@ -1,133 +1,2 @@ -** BEWARE the instructions here might be outdated, better refer to doc/md/Installation_Instructions/ ** - -The project compiles on Linux, Mac OS X and Windows (MinGW/MSYS). - -it requires: -- gcc >= 4.8 -- libpthread -- libreadline -- libusb -- perl -- an ARM cross-compiler to compile the firmware - -and optionally QT for the GUI - - -To compile, just run "make". - -=========== -= Windows = -=========== - -Rather than download and install every one of these packages, a new ProxSpace -environment archive file will be made available for download on the project -page at @Gator96100's repo - -Afterwards just clone the iceman repo or download someone elses. Read instructions on @Gator96100 repo page. (https://github.com/Gator96100/ProxSpace/) - -Download the ProxSpace environment archive and extract it to C:\ - -Links - https://github.com/Gator96100/ProxSpace/archive/master.zip - - -============ -= Mac OS X = -============ - -Installing from HomeBrew tap ---------------------------- -This method is recommended and tested on macOS Sierra 10.12.3 - -1. Install homebrew if you haven't yet already done so: http://brew.sh/ - -2. Tap proxmark repo: - brew tap iceman1001/proxmark3 - -3. Install Proxmark3: - -Stable release - brew install proxmark3 - -Latest non-stable from GitHub (use this if previous command fails) - brew install --HEAD proxmark3 - -For more information go to https://github.com/iceman1001/homebrew-proxmark3 - -Upgrading HomeBrew tap formula ------------------------------ -*This method is useful for those looking to run bleeding-edge versions of iceman's client. Keep this in mind when attempting to update your HomeBrew tap formula as this procedure could easily cause a build to break if an update is unstable on macOS.* - -Tested on macOS Sierra 10.12.6 - -*Note: This assumes you have already installed iceman's fork from HomeBrew as mentioned above* - -1. Force HomeBrew to pull the latest source from github -`brew upgrade --fetch-HEAD iceman1001/proxmark3/proxmark3` - -2. Flash the bootloader - * With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark 3 as you plug it into a USB port. After about 5 seconds let go of the button and run this command - `$ sudo proxmark3-flasher /dev/tty.usbmodem881 /usr/local/Cellar/proxmark3/HEAD-ccfdd60/share/firmware/fullimage.elf` - * After the bootloader finishes flashing, unplug your Proxmark3 from your machine - -3. Flash fullimage.elf - * Press and hold the button on your Proxmark 3 and keep it held as you plug the Proxmark 3 back into the USB port; continue to hold the button until after this step is complete and the `proxmark3-flasher` command outputs "Have a nice day!"* - -`$ sudo proxmark3-flasher /dev/tty.usbmodem881 /usr/local/Cellar/proxmark3/HEAD-ccfdd60/share/firmware/fullimage.elf` - -4. Enjoy the update - -Compilling from source manually (Legacy) ---------------------------- - -Tested on OSX 10.10 Yosemite - -1 - Install Xcode and Xcode Command Line Tools - -2 - Install Homebrew and dependencies - brew install readline libusb p7zip libusb-compat wget qt5 pkgconfig - -3 - Download DevKitARM for OSX - http://sourceforge.net/projects/devkitpro/files/devkitARM/devkitARM_r44/ - Unpack devkitARM_r44-osx.tar.bz2 to proxmark3 directory. - -4 - Edit proxmark3/client/Makefile adding path to readline and qt5 - - LDLIBS = -L/usr/local/opt/readline/lib -L/usr/local/opt/qt5/lib -L/opt/local/lib -L/usr/local/lib ../liblua/liblua.a -lreadline -lpthread -lm - CFLAGS = -std=c99 -I/usr/local/opt/qt5/include -I/usr/local/opt/readline/include -I. -I../include -I../common -I../zlib -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4 - - If your old brew intallation use /usr/local/Cellar/ path replace /usr/local/opt/readline/lib with your actuall readline and qt5 path. See homebrew manuals. - -5 - Set Environment - - export DEVKITPRO=$HOME/proxmark3/ - export DEVKITARM=$DEVKITPRO/devkitARM - export PATH=${PATH}:${DEVKITARM}/bin - - -============ -= Linux = -============ - -1 - Download - -A precompiled DevKitARM cross compiler tool chain package can be found at -http://sourceforge.net/projects/devkitpro/files/devkitARM -Select the one you need (32bit or 64bit) and unpack to a convinient place, eg -$HOME/proxmark3/. It will create a devkitARM/ subdirectory. - -You will also need a general compiling environment on your computer for -the client and the libusb headers. In most distributions you will get all you -need with the lsb-package (Linux Standard Base). In debian/ubuntu you simply -call `aptitude install lsb libusb-dev libreadline-dev libreadline6`. - -For the graphical plot view, you might need the qtlibs (debian/ubuntu: -libqt4-dev), too. - -2 - Set Environment - -export DEVKITPRO=$HOME/proxmark3/ -export DEVKITARM=$DEVKITPRO/devkitARM -export PATH=${PATH}:${DEVKITARM}/bin - +Refer to doc/md/Installation_Instructions/ for up-to-date intructions for various platforms. diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index fd336104d..f38d2056c 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -11,6 +11,8 @@ For further questions about Mac & Homebrew, contact @Chrisfu (https://github.c 3. Install Proxmark3: `brew install proxmark3` for stable release or `brew install --HEAD proxmark3` for latest non-stable from GitHub. +For more info, go to https://github.com/RfidResearchGroup/homebrew-proxmark3 + ## Upgrade HomeBrew tap formula *This method is useful for those looking to run bleeding-edge versions of RRG/iceman's client. Keep this in mind when attempting to update your HomeBrew tap formula as this procedure could easily cause a build to break if an update is unstable on macOS.* @@ -64,7 +66,7 @@ These instructions will show how to setup the environment on OSX to the point wh 2. Install dependencies: ``` -brew install readline p7zip libusb-compat perl qt5 wget +brew install readline p7zip libusb-compat perl qt5 wget pkgconfig brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc ``` diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index e2895f73a..631b864c1 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -19,7 +19,7 @@ Step by step guides are online such as [RiscCorps](https://store.ryscc.com/blogs ## Download / clone ProxSpace repo -Download the Gator96100 ProxSpace package from https://github.com/Gator96100/ProxSpace/ +Download the Gator96100 ProxSpace package from https://github.com/Gator96100/ProxSpace/releases If you prefer, you can clone it, provided that you installed Github for Windows https://desktop.github.com/. From 3408d75ac90f9af3e8cf45558cb39369dc4db31f Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 29 Aug 2019 21:25:06 +0200 Subject: [PATCH 175/347] Update Makefile.hal fix https://github.com/RfidResearchGroup/proxmark3/issues/375 --- armsrc/Standalone/Makefile.hal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/Standalone/Makefile.hal b/armsrc/Standalone/Makefile.hal index 5d3904794..f082dd117 100644 --- a/armsrc/Standalone/Makefile.hal +++ b/armsrc/Standalone/Makefile.hal @@ -1,6 +1,6 @@ # Default standalone if no standalone specified DEFAULT_STANDALONE=LF_SAMYRUN -HELP_EXAMPLE_STANDALONE=HF_COLIN +HELP_EXAMPLE_STANDALONE=HF_YOUNG # (you can set explicitly STANDALONE= to disable standalone modes) STANDALONE?=$(DEFAULT_STANDALONE) STANDALONE_REQ_DEFS= From 4d073ae19d703116f3ff5007c101c8c4c9e608c8 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 21:49:54 +0200 Subject: [PATCH 176/347] mv iclass_dump.bin one folder up --- client/{loclass => }/iclass_dump.bin | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename client/{loclass => }/iclass_dump.bin (100%) diff --git a/client/loclass/iclass_dump.bin b/client/iclass_dump.bin similarity index 100% rename from client/loclass/iclass_dump.bin rename to client/iclass_dump.bin From 0d986ab212ede35caf0b7a21da3afd4ac30064fa Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 29 Aug 2019 21:57:01 +0200 Subject: [PATCH 177/347] Delete unused hash files --- tools/simmodule/SIM010.md5.txt | 1 - tools/simmodule/SIM011.md5.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 tools/simmodule/SIM010.md5.txt delete mode 100644 tools/simmodule/SIM011.md5.txt diff --git a/tools/simmodule/SIM010.md5.txt b/tools/simmodule/SIM010.md5.txt deleted file mode 100644 index c790101f7..000000000 --- a/tools/simmodule/SIM010.md5.txt +++ /dev/null @@ -1 +0,0 @@ -136e157364609e5c395540dc8dadbfd6 *SIM010.BIN diff --git a/tools/simmodule/SIM011.md5.txt b/tools/simmodule/SIM011.md5.txt deleted file mode 100644 index 2a564eeb6..000000000 --- a/tools/simmodule/SIM011.md5.txt +++ /dev/null @@ -1 +0,0 @@ -e0be612fd3e68681ef0ee4706b4f28e2 *SIM011.BIN From 8987e956acb59fe07848931182be0f37a5d2103b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 29 Aug 2019 20:58:36 +0200 Subject: [PATCH 178/347] POSIX sh version of mkversion Most targeted platforms have "sh" and don't need Perl as requirement. Still Perl script is present as fallback. --- CHANGELOG.md | 1 + armsrc/Makefile | 2 +- bootrom/Makefile | 2 +- common_arm/default_version.c | 2 +- .../Linux-Installation-Instructions.md | 2 +- ...OS-X-Homebrew-Installation-Instructions.md | 2 +- .../Windows-Installation-Instructions.md | 2 +- tools/mkversion.sh | 60 +++++++++++++++++++ 8 files changed, 67 insertions(+), 6 deletions(-) create mode 100755 tools/mkversion.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3df33cc..6fcbc68d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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... ## [unreleased][unreleased] + - Chg posix sh version of mkversion (@doegox) - Chg remove entirely ncurses, not needed nowadays (@doegox) - Chg remove deprecated termcap, use ncurses instead (@ZeroChaos-) - Chg 'hf iclass encrypt' - now takes transport key as param. (@iceman1001) diff --git a/armsrc/Makefile b/armsrc/Makefile index 665c91005..048879d96 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -144,7 +144,7 @@ all: $(OBJS) # version.c should be remade on every time fullimage.stage1.elf should be remade version.c: default_version.c $(OBJDIR)/fpga_version_info.o $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ) $(info [-] GEN $@) - $(Q)perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@ + $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(COPY) $^ $@ fpga_version_info.c: $(FPGA_BITSTREAMS) | $(FPGA_COMPRESSOR) $(info [-] GEN $@) diff --git a/bootrom/Makefile b/bootrom/Makefile index c4103b522..884f01757 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -36,7 +36,7 @@ OBJS = $(OBJDIR)/bootrom.s19 # version.c should be remade on every compilation version.c: default_version.c $(info [=] GEN $@) - $(Q)perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@ + $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(COPY) $^ $@ all: $(OBJS) diff --git a/common_arm/default_version.c b/common_arm/default_version.c index e1e5dc64c..b4b8ae17d 100644 --- a/common_arm/default_version.c +++ b/common_arm/default_version.c @@ -1,5 +1,5 @@ #include "proxmark3_arm.h" -/* This is the default version.c file that Makefile.common falls back to if perl is not available */ +/* This is the default version.c file that Makefile.common falls back to if neither sh nor perl are available */ const struct version_information __attribute__((section(".version_information"))) version_information = { VERSION_INFORMATION_MAGIC, 1, /* version 1 */ diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index 476309fb6..aa3ce9272 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -25,7 +25,7 @@ Install the requirements ```sh sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev \ -libusb-0.1-4 libusb-dev perl pkg-config wget gcc-arm-none-eabi libnewlib-dev libqt4-dev +libusb-0.1-4 libusb-dev pkg-config wget gcc-arm-none-eabi libnewlib-dev libqt4-dev ``` If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index f38d2056c..f2d87aa66 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -66,7 +66,7 @@ These instructions will show how to setup the environment on OSX to the point wh 2. Install dependencies: ``` -brew install readline p7zip libusb-compat perl qt5 wget pkgconfig +brew install readline p7zip libusb-compat qt5 wget pkgconfig brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc ``` diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 631b864c1..1df9e541b 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -99,7 +99,7 @@ Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instruct ```sh sudo apt-get update sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev libusb-0.1-4 \ -libusb-dev perl pkg-config wget gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ +libusb-dev pkg-config wget gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ libqt4-dev ``` diff --git a/tools/mkversion.sh b/tools/mkversion.sh new file mode 100755 index 000000000..b91eab8af --- /dev/null +++ b/tools/mkversion.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# Output a version.c file that includes information about the current build +# From mkversion.pl +# pure sh POSIX as now even on Windows we use WSL or ProxSpace with sh available + +# Clear environment locale so that git will not use localized strings +export LC_ALL="C" +export LANG="C" + +# if you are making your own fork, change this line to reflect your fork-name +fullgitinfo="RRG/Iceman" +# GIT status 0 = dirty, 1 = clean , 2 = undecided +clean=2 + +# Do we have acces to git command? +commandGIT=$(env which git) + +if [ "$commandGIT" != "" ]; then + + # now avoiding the "fatal: No names found, cannot describe anything." error by fallbacking to abbrev hash in such case + gitversion=$(git describe --dirty --always) + gitbranch=$(git rev-parse --abbrev-ref HEAD) + if [ "$gitversion" != "${gitversion%-dirty}" ]; then + clean=0 + else + clean=1 + fi + if [ "$gitbranch" != "" ] && [ "$gitversion" != "" ]; then + fullgitinfo="${fullgitinfo}/${gitbranch}/${gitversion}" + ctime="$(date '+%Y-%m-%d %H:%M:%S')" + else + fullgitinfo="${fullgitinfo}/master/release (git)" + fi +else + fullgitinfo="${fullgitinfo}/master/release (no_git)" + dl_time=$(stat --printf="%y" ../README.md) + # POSIX way... + ctime=${dl_time%.*} +fi + +# Crop so it fits within 50 characters C string, so max 49 chars +# POSIX way +fullgitinfoextra="${fullgitinfo#??????????????????????????????????????????????}" +if [ "$fullgitinfoextra" != "$fullgitinfo" ]; then + fullgitinfo46="${fullgitinfo%"${fullgitinfoextra}"}" + fullgitinfo="${fullgitinfo46}..." +fi +cat < Date: Thu, 29 Aug 2019 23:43:48 +0200 Subject: [PATCH 179/347] migrate simmodule/readme.txt content to 2_Configuration-and-Verification.md --- .../2_Configuration-and-Verification.md | 20 +++++++++++- tools/simmodule/readme.txt | 32 ------------------- 2 files changed, 19 insertions(+), 33 deletions(-) delete mode 100644 tools/simmodule/readme.txt diff --git a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md index 8b5244cf6..503c4b988 100644 --- a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md +++ b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md @@ -30,8 +30,20 @@ Find version in the long output, look for these two lines #db# version.................v2.06 ``` -This version is obsolete. The following command upgrades your device sim module firmware. +This version is obsolete. + +If you didn't download SIM011.bin from the RRG Repo be aware that it might be corrupted or faulty. +You find a hash text file in this folder. It was generated with the following linux command. + +``` +sha512sum -b SIM011.bin > SIM011.sha512.txt +``` + +You should validate the SIM011.bin file against this hash file in order to be sure the file is not corrupted or faulty. + +The following command upgrades your device sim module firmware. Don't not turn off your device during the execution of this command!! +Even its a quite fast command you should be warned. You may brick it if you interrupt it. ``` pm3 --> sc upgrade f ../tools/simmodule/SIM011.BIN @@ -54,6 +66,12 @@ You get the following output if the execution was successful: [+] Smartcard socket firmware upgraded successful ``` +Run hw status command to verify that the upgrade went well. + +``` +pm3 --> hw status +``` + ## Next steps For the next steps, please read the following page: diff --git a/tools/simmodule/readme.txt b/tools/simmodule/readme.txt deleted file mode 100644 index 5dad9cd85..000000000 --- a/tools/simmodule/readme.txt +++ /dev/null @@ -1,32 +0,0 @@ - -2018-12-20 Iceman -2019-03-11 Iceman chg -======================================= - -The latest firmware for the SIM MODULE is : SIM011.bin - -You can use it to upgrade you sim module via the pm3 client. - -pm3 --> sc upgrade -h -pm3 --> sc upgrade f ../tools/simmodule/SIM011.bin - - -Even its a quite fast command you should be warned. You may brick it if you interrupt it. - - -Run hw status command to verify that the upgrade went well. - -pm3 --> hw status - - - -If you didn't download this file from the RRG Repo be aware that it might be corrupt or faulty. - -You find to hash text files in this folder. They were generated with the following linux commands. - - -md5sum -b SIM011.bin > SIM011.md5.txt -sha512sum -b SIM011.bin > SIM011.sha512.txt - - -You should validate the SIM011.bin file against these hash files in order to be sure the file is not corrupt or faulty. \ No newline at end of file From de5c5df732398980f72bc6e51bdfa1d52de79d4b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 00:08:31 +0200 Subject: [PATCH 180/347] remove debug print --- client/fileutils.c | 1 - 1 file changed, 1 deletion(-) diff --git a/client/fileutils.c b/client/fileutils.c index 1a6b40e53..62671952e 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -407,7 +407,6 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s char *path; int res = searchFile(&path, "", preferredName, suffix); if (res != PM3_SUCCESS) { - PrintAndLogEx(INFO, "res: %d Curr path:: %s", res, path); return PM3_EFILE; } From ca8aee33ea5ea7e594dc439a3278801b71573591 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 01:23:10 +0200 Subject: [PATCH 181/347] move iclass_dump.bin in resources/ --- client/fileutils.c | 2 +- client/{ => resources}/iclass_dump.bin | Bin include/common.h | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) rename client/{ => resources}/iclass_dump.bin (100%) diff --git a/client/fileutils.c b/client/fileutils.c index 62671952e..bff8771ad 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -405,7 +405,7 @@ out: int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, size_t *datalen) { char *path; - int res = searchFile(&path, "", preferredName, suffix); + int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, suffix); if (res != PM3_SUCCESS) { return PM3_EFILE; } diff --git a/client/iclass_dump.bin b/client/resources/iclass_dump.bin similarity index 100% rename from client/iclass_dump.bin rename to client/resources/iclass_dump.bin diff --git a/include/common.h b/include/common.h index a2850ef32..830a99e79 100644 --- a/include/common.h +++ b/include/common.h @@ -30,6 +30,7 @@ #define DICTIONARIES_SUBDIR "dictionaries/" #define LUA_LIBRARIES_SUBDIR "lualibs/" #define LUA_SCRIPTS_SUBDIR "luascripts/" +#define RESOURCES_SUBDIR "resources/" #define PACKED __attribute__((packed)) From af65beb9879d393b072a9cdc7ff8aab4d2dd6022 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 01:23:50 +0200 Subject: [PATCH 182/347] move aidlist.json to resources/ --- client/cmdsmartcard.c | 31 ++++++++++++++++------------- client/{ => resources}/aidlist.json | 0 2 files changed, 17 insertions(+), 14 deletions(-) rename client/{ => resources}/aidlist.json (100%) diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index f1fd2b917..4ea67be95 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -22,6 +22,7 @@ #include "crypto/libpcrypto.h" // sha512hash #include "emv/dump.h" #include "ui.h" +#include "fileutils.h" static int CmdHelp(const char *Cmd); @@ -92,33 +93,35 @@ static int usage_sm_brute(void) { return 0; } -static int smart_loadjson(const char *preferredName, const char *suffix, json_t **root) { +static int smart_loadjson(const char *preferredName, json_t **root) { json_error_t error; if (preferredName == NULL) return 1; - if (suffix == NULL) return 1; - int retval = 0; - int size = sizeof(char) * (strlen(get_my_executable_directory()) + strlen(preferredName) + strlen(suffix) + 10); - char *fileName = calloc(size, sizeof(char)); - sprintf(fileName, "%s%s.%s", get_my_executable_directory(), preferredName, suffix); - *root = json_load_file(fileName, 0, &error); + char *path; + int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, ".json"); + if (res != PM3_SUCCESS) { + return PM3_EFILE; + } + + int retval = PM3_SUCCESS; + *root = json_load_file(path, 0, &error); if (!*root) { - PrintAndLogEx(ERR, "json (%s) error on line %d: %s", fileName, error.line, error.text); - retval = 2; + PrintAndLogEx(ERR, "json (%s) error on line %d: %s", path, error.line, error.text); + retval = PM3_ESOFT; goto out; } if (!json_is_array(*root)) { - PrintAndLogEx(ERR, "Invalid json (%s) format. root must be an array.", fileName); - retval = 3; + PrintAndLogEx(ERR, "Invalid json (%s) format. root must be an array.", path); + retval = PM3_ESOFT; goto out; } - PrintAndLogEx(SUCCESS, "Loaded file (%s) OK.", fileName); + PrintAndLogEx(SUCCESS, "Loaded file (%s) OK.", path); out: - free(fileName); + free(path); return retval; } @@ -1035,7 +1038,7 @@ static int CmdSmartBruteforceSFI(const char *Cmd) { PrintAndLogEx(INFO, "Importing AID list"); json_t *root = NULL; - smart_loadjson("aidlist", "json", &root); + smart_loadjson("aidlist", &root); uint8_t *buf = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); if (!buf) diff --git a/client/aidlist.json b/client/resources/aidlist.json similarity index 100% rename from client/aidlist.json rename to client/resources/aidlist.json From 5b6af929ab89eaef235f920baceae43ed29d2f26 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 02:00:41 +0200 Subject: [PATCH 183/347] move oid.json to resources/ --- client/crypto/asn1dump.c | 20 +++++++------------- client/{crypto => resources}/oids.json | 0 2 files changed, 7 insertions(+), 13 deletions(-) rename client/{crypto => resources}/oids.json (100%) diff --git a/client/crypto/asn1dump.c b/client/crypto/asn1dump.c index 356dd3591..140b0d2e2 100644 --- a/client/crypto/asn1dump.c +++ b/client/crypto/asn1dump.c @@ -25,6 +25,8 @@ #include "emv/emvjson.h" #include "util.h" #include "proxmark3.h" +#include "fileutils.h" +#include "pm3_cmd.h" #ifndef PRINT_INDENT # define PRINT_INDENT(level) {for (int myi = 0; myi < (level); myi++) fprintf(f, " ");} @@ -235,25 +237,17 @@ static void asn1_tag_dump_integer(const struct tlv *tlv, const struct asn1_tag * static char *asn1_oid_description(const char *oid, bool with_group_desc) { json_error_t error; json_t *root = NULL; - char fname[300] = {0}; static char res[300]; memset(res, 0x00, sizeof(res)); - size_t len = strlen(get_my_executable_directory()); - if (len >= 300) len = 299; - - strncpy(fname, get_my_executable_directory(), len); - strcat(fname, "crypto/oids.json"); - if (access(fname, F_OK) < 0) { - strncpy(fname, get_my_executable_directory(), len); - strcat(fname, "oids.json"); - if (access(fname, F_OK) < 0) { - goto error; // file not found - } + char *path; + if (searchFile(&path, RESOURCES_SUBDIR, "oids", ".json") != PM3_SUCCESS) { + return NULL; } // load `oids.json` - root = json_load_file(fname, 0, &error); + root = json_load_file(path, 0, &error); + free(path); if (!root || !json_is_object(root)) { goto error; diff --git a/client/crypto/oids.json b/client/resources/oids.json similarity index 100% rename from client/crypto/oids.json rename to client/resources/oids.json From c6ac4056d3541b0eebebca4f1e7e1c534206c1ee Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 02:01:14 +0200 Subject: [PATCH 184/347] fix iclass txt --- client/cmdhficlass.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index bd937fe17..f5406e8e7 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -74,7 +74,7 @@ static int usage_hf_iclass_decrypt(void) { PrintAndLogEx(NORMAL, "Correct behaviour would be to decrypt only the application areas where the key is valid,"); PrintAndLogEx(NORMAL, "which is defined by the configuration block."); PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside"); - PrintAndLogEx(NORMAL, "in the working directory. The file should be 16 bytes binary data"); + PrintAndLogEx(NORMAL, "in the resources directory. The file should be 16 bytes binary data"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: hf iclass decrypt f k "); PrintAndLogEx(NORMAL, " options"); @@ -88,7 +88,7 @@ static int usage_hf_iclass_decrypt(void) { } static int usage_hf_iclass_encrypt(void) { PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside"); - PrintAndLogEx(NORMAL, "in the working directory. The file should be 16 bytes binary data"); + PrintAndLogEx(NORMAL, "in the resources directory. The file should be 16 bytes binary data"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: hf iclass encrypt d k "); PrintAndLogEx(NORMAL, ""); From 382129205f01c63408923cb7d4f71a194d0a1e02 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 02:10:55 +0200 Subject: [PATCH 185/347] move capk.txt to resources/ --- client/emv/emv_pk.c | 15 ++++++++------- client/{emv => resources}/capk.txt | 0 2 files changed, 8 insertions(+), 7 deletions(-) rename client/{emv => resources}/capk.txt (100%) diff --git a/client/emv/emv_pk.c b/client/emv/emv_pk.c index e273480c8..bb124c63c 100644 --- a/client/emv/emv_pk.c +++ b/client/emv/emv_pk.c @@ -29,6 +29,8 @@ #include "ui.h" #include "crypto.h" #include "proxmark3.h" +#include "fileutils.h" +#include "pm3_cmd.h" #define BCD(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : \ -1) @@ -483,13 +485,12 @@ struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx) { } } */ - const char *relfname = "emv/capk.txt"; - - char fname[strlen(get_my_executable_directory()) + strlen(relfname) + 1]; - strcpy(fname, get_my_executable_directory()); - strcat(fname, relfname); - - pk = emv_pk_get_ca_pk_from_file(fname, rid, idx); + char *path; + if (searchFile(&path, RESOURCES_SUBDIR, "capk", ".txt") != PM3_SUCCESS) { + return NULL; + } + pk = emv_pk_get_ca_pk_from_file(path, rid, idx); + free(path); if (!pk) return NULL; diff --git a/client/emv/capk.txt b/client/resources/capk.txt similarity index 100% rename from client/emv/capk.txt rename to client/resources/capk.txt From 40709f45365f21ba831eec3b523952de5bb5fabf Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 02:18:14 +0200 Subject: [PATCH 186/347] move defparams.json to resources/emv_defparams.json --- client/emv/cmdemv.c | 10 +++++----- client/emv/emvjson.c | 15 ++++++++------- .../emv_defparams.json} | 0 3 files changed, 13 insertions(+), 12 deletions(-) rename client/{emv/defparams.json => resources/emv_defparams.json} (100%) diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 3891bdb48..348840cb3 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -232,7 +232,7 @@ static int CmdEMVGPO(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_lit0("kK", "keep", "keep field ON for next command"), - arg_lit0("pP", "params", "load parameters from `emv/defparams.json` file for PDOLdata making from PDOL and parameters"), + arg_lit0("pP", "params", "load parameters from `emv_defparams.json` file for PDOLdata making from PDOL and parameters"), arg_lit0("mM", "make", "make PDOLdata from PDOL (tag 9F38) and parameters (by default uses default parameters)"), arg_lit0("aA", "apdu", "show APDU reqests and responses"), arg_lit0("tT", "tlv", "TLV decode results of selected applets"), @@ -398,7 +398,7 @@ static int CmdEMVAC(const char *Cmd) { arg_lit0("kK", "keep", "keep field ON for next command"), arg_lit0("cC", "cda", "executes CDA transaction. Needs to get SDAD in results."), arg_str0("dD", "decision", "", "Terminal decision. aac - declined, tc - approved, arqc - online authorisation requested"), - arg_lit0("pP", "params", "load parameters from `emv/defparams.json` file for CDOLdata making from CDOL and parameters"), + arg_lit0("pP", "params", "load parameters from `emv_defparams.json` file for CDOLdata making from CDOL and parameters"), arg_lit0("mM", "make", "make CDOLdata from CDOL (tag 8C and 8D) and parameters (by default uses default parameters)"), arg_lit0("aA", "apdu", "show APDU reqests and responses"), arg_lit0("tT", "tlv", "TLV decode results of selected applets"), @@ -564,7 +564,7 @@ static int CmdEMVInternalAuthenticate(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_lit0("kK", "keep", "keep field ON for next command"), - arg_lit0("pP", "params", "load parameters from `emv/defparams.json` file for DDOLdata making from DDOL and parameters"), + arg_lit0("pP", "params", "load parameters from `emv_defparams.json` file for DDOLdata making from DDOL and parameters"), arg_lit0("mM", "make", "make DDOLdata from DDOL (tag 9F49) and parameters (by default uses default parameters)"), arg_lit0("aA", "apdu", "show APDU reqests and responses"), arg_lit0("tT", "tlv", "TLV decode results of selected applets"), @@ -785,7 +785,7 @@ static int CmdEMVExec(const char *Cmd) { arg_lit0("sS", "select", "activate field and select card."), arg_lit0("aA", "apdu", "show APDU reqests and responses."), arg_lit0("tT", "tlv", "TLV decode results."), - arg_lit0("jJ", "jload", "Load transaction parameters from `emv/defparams.json` file."), + arg_lit0("jJ", "jload", "Load transaction parameters from `emv_defparams.json` file."), arg_lit0("fF", "forceaid", "Force search AID. Search AID instead of execute PPSE."), arg_rem("By default:", "Transaction type - MSD"), arg_lit0("vV", "qvsdc", "Transaction type - qVSDC or M/Chip."), @@ -1376,7 +1376,7 @@ static int CmdEMVScan(const char *Cmd) { arg_lit0("aA", "apdu", "show APDU reqests and responses."), arg_lit0("tT", "tlv", "TLV decode results."), arg_lit0("eE", "extract", "Extract TLV elements and fill Application Data"), - arg_lit0("jJ", "jload", "Load transaction parameters from `emv/defparams.json` file."), + arg_lit0("jJ", "jload", "Load transaction parameters from `emv_defparams.json` file."), arg_rem("By default:", "Transaction type - MSD"), arg_lit0("vV", "qvsdc", "Transaction type - qVSDC or M/Chip."), arg_lit0("cC", "qvsdccda", "Transaction type - qVSDC or M/Chip plus CDA (SDAD generation)."), diff --git a/client/emv/emvjson.c b/client/emv/emvjson.c index 88d886c6e..715407a23 100644 --- a/client/emv/emvjson.c +++ b/client/emv/emvjson.c @@ -17,6 +17,8 @@ #include "util.h" #include "proxmark3.h" #include "emv_tags.h" +#include "fileutils.h" +#include "pm3_cmd.h" static const ApplicationDataElm ApplicationData[] = { {0x82, "AIP"}, @@ -303,13 +305,12 @@ bool ParamLoadFromJson(struct tlvdb *tlv) { return false; } - // current path + file name - const char *relfname = "emv/defparams.json"; - char fname[strlen(get_my_executable_directory()) + strlen(relfname) + 1]; - strcpy(fname, get_my_executable_directory()); - strcat(fname, relfname); - - root = json_load_file(fname, 0, &error); + char *path; + if (searchFile(&path, RESOURCES_SUBDIR, "emv_defparams", ".json") != PM3_SUCCESS) { + return false; + } + root = json_load_file(path, 0, &error); + free(path); if (!root) { PrintAndLogEx(ERR, "Load params: json error on line " _YELLOW_("%d") ": %s", error.line, error.text); return false; diff --git a/client/emv/defparams.json b/client/resources/emv_defparams.json similarity index 100% rename from client/emv/defparams.json rename to client/resources/emv_defparams.json From 08a5de1f0edea2531c5393ab945873d9447d6db6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 08:32:34 +0200 Subject: [PATCH 187/347] searchFile traces --- client/cmddata.c | 14 +++++++++++--- client/fileutils.c | 42 ++++++++++++++++++++++++++++++++++++++++-- include/common.h | 1 + 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 81060cd59..817a63930 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -23,6 +23,7 @@ #include "lfdemod.h" // for demod code #include "loclass/cipherutils.h" // for decimating samples in getsamples #include "cmdlfem4x.h" // askem410xdecode +#include "fileutils.h" // searchFile uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN]; size_t DemodBufferLen = 0; @@ -1646,12 +1647,19 @@ static int CmdLoad(const char *Cmd) { if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; memcpy(filename, Cmd, len); - FILE *f = fopen(filename, "r"); - if (!f) { - PrintAndLogEx(WARNING, "couldn't open '%s'", filename); + char *path; + if (searchFile(&path, TRACES_SUBDIR, filename, "") != PM3_SUCCESS) { return PM3_EFILE; } + FILE *f = fopen(path, "r"); + if (!f) { + PrintAndLogEx(WARNING, "couldn't open '%s'", path); + free(path); + return PM3_EFILE; + } + free(path); + GraphTraceLen = 0; char line[80]; while (fgets(line, sizeof(line), f)) { diff --git a/client/fileutils.c b/client/fileutils.c index bff8771ad..ae7531771 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -869,6 +869,9 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea char *filename = calloc(strlen(searchname) + 1, sizeof(char)); if (filename == NULL) return PM3_EMALLOC; strcpy(filename, searchname); + if (g_debugMode == 2) { + PrintAndLogEx(INFO, "Searching %s", filename); + } if (((strlen(filename) > 1) && (filename[0] == '/')) || ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) { if (fileExists(filename)) { @@ -887,15 +890,44 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea return PM3_SUCCESS; } } - // try pm3 dirs in current workdir (dev mode) + // try pm3 dirs in current client workdir (dev mode) const char *exec_path = get_my_executable_directory(); - if (exec_path != NULL) { + if ((exec_path != NULL) && + ((strcmp(DICTIONARIES_SUBDIR, pm3dir) == 0) || + (strcmp(LUA_LIBRARIES_SUBDIR, pm3dir) == 0) || + (strcmp(LUA_SCRIPTS_SUBDIR, pm3dir) == 0) || + (strcmp(RESOURCES_SUBDIR, pm3dir) == 0))) { char *path = calloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; strcpy(path, exec_path); strcat(path, pm3dir); strcat(path, filename); + if (g_debugMode == 2) { + PrintAndLogEx(INFO, "Searching %s", path); + } + if (fileExists(path)) { + free(filename); + *foundpath = path; + return PM3_SUCCESS; + } else { + free(path); + } + } + // try pm3 dirs in current repo workdir (dev mode) + if ((exec_path != NULL) && + ((strcmp(TRACES_SUBDIR, pm3dir) == 0))) { + char *above = "../"; + char *path = calloc(strlen(exec_path) + strlen(above) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); + if (path == NULL) + goto out; + strcpy(path, exec_path); + strcat(path, above); + strcat(path, pm3dir); + strcat(path, filename); + if (g_debugMode == 2) { + PrintAndLogEx(INFO, "Searching %s", path); + } if (fileExists(path)) { free(filename); *foundpath = path; @@ -914,6 +946,9 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea strcat(path, PM3_USER_DIRECTORY); strcat(path, pm3dir); strcat(path, filename); + if (g_debugMode == 2) { + PrintAndLogEx(INFO, "Searching %s", path); + } if (fileExists(path)) { free(filename); *foundpath = path; @@ -930,6 +965,9 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea strcpy(path, PM3_SHARE_PATH); strcat(path, pm3dir); strcat(path, filename); + if (g_debugMode == 2) { + PrintAndLogEx(INFO, "Searching %s", path); + } if (fileExists(path)) { free(filename); *foundpath = path; diff --git a/include/common.h b/include/common.h index 830a99e79..c4c5d6370 100644 --- a/include/common.h +++ b/include/common.h @@ -31,6 +31,7 @@ #define LUA_LIBRARIES_SUBDIR "lualibs/" #define LUA_SCRIPTS_SUBDIR "luascripts/" #define RESOURCES_SUBDIR "resources/" +#define TRACES_SUBDIR "traces/" #define PACKED __attribute__((packed)) From 5bb12724aee538716af9596d53ccf6c4b3bee2b4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 30 Aug 2019 08:51:31 +0200 Subject: [PATCH 188/347] add: updated the loclass document --- doc/loclass_notes.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 doc/loclass_notes.md diff --git a/doc/loclass_notes.md b/doc/loclass_notes.md new file mode 100644 index 000000000..d77e8ba57 --- /dev/null +++ b/doc/loclass_notes.md @@ -0,0 +1,22 @@ +# About LOCLASS attack + +This document is primarily intended for understanding `hf iclass loclass` and used files with it. + +LOCLASS aim is to recoved the used masterkey for that specific reader configued in Elite mode / High Security mode. + +LOCLASS, is a two part attack. First is the online part where you gather needed information from the reader by presenting a carefully selected CSN and save the responses to file. For the first part you run `hf iclass sim 2` and take notice of the saved filename. + +The second part is offline, where the information gathered from the first step is used in a series of DES operations to figure out the used +masterkey. run `hf iclass loclass f abc.bin' + +If you don't have access to a iClass SE reader configured in Elite mode there is a test file which you can use. +`hf iclass loclass f iclass_dump.bin` + + +# Unit testing +In order to verify that loclass is actually working, there is a "unit" test mode. run `hf iclass loclass t`. +This test mode uses two files. +- iclass_dump.bin + this is a sample file from `hf iclass sim 2`, with complete keytable recovery, using 128 carefully selected CSN and the file contains the MAC results from reader. +- iclass_key.bin + this is file shall contain the legacy masterkey, AA1 key. loclass uses it to verify that permution / reversing / generation of key is correct. \ No newline at end of file From f6fa2c465174c189e4b880e9a255b2e126fd1cb0 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 30 Aug 2019 08:51:55 +0200 Subject: [PATCH 189/347] moved to docs --- client/loclass/loclass_information.txt | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 client/loclass/loclass_information.txt diff --git a/client/loclass/loclass_information.txt b/client/loclass/loclass_information.txt deleted file mode 100644 index 307d28203..000000000 --- a/client/loclass/loclass_information.txt +++ /dev/null @@ -1,12 +0,0 @@ -2017-08-19 iceman, - -iclass_dump.bin -=============== -The file iclass_dump.bin contains CSN's mac results from 128 CSNs. -Hence when running the test mode, - 'hf iclass loclass t' -it shows a long output from the bruteforce test. - -iclass_key.bin -============== -The file iclass_key.bin is where you add the AA1 master key in order for the proxmark3 client to use it with the loclass commands From eba13925e437fce57107bd751d78004f4bbfb5b6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 08:53:04 +0200 Subject: [PATCH 190/347] move bf_bench_data.bin to resources/hardnested_* --- client/hardnested/hardnested_bruteforce.c | 29 ++++++++++++------ .../hardnested_bf_bench_data.bin} | Bin 2 files changed, 19 insertions(+), 10 deletions(-) rename client/{hardnested/bf_bench_data.bin => resources/hardnested_bf_bench_data.bin} (100%) diff --git a/client/hardnested/hardnested_bruteforce.c b/client/hardnested/hardnested_bruteforce.c index 5f93d4811..96211f47f 100644 --- a/client/hardnested/hardnested_bruteforce.c +++ b/client/hardnested/hardnested_bruteforce.c @@ -65,11 +65,13 @@ THE SOFTWARE. #include "util_posix.h" #include "crapto1/crapto1.h" #include "parity.h" +#include "fileutils.h" +#include "pm3_cmd.h" #define NUM_BRUTE_FORCE_THREADS (num_CPUs()) #define DEFAULT_BRUTE_FORCE_RATE (120000000.0) // if benchmark doesn't succeed #define TEST_BENCH_SIZE (6000) // number of odd and even states for brute force benchmark -#define TEST_BENCH_FILENAME "hardnested/bf_bench_data.bin" +#define TEST_BENCH_FILENAME "hardnested_bf_bench_data.bin" //#define WRITE_BENCH_FILE // debugging options @@ -265,8 +267,12 @@ void prepare_bf_test_nonces(noncelist_t *nonces, uint8_t best_first_byte) { #if defined (WRITE_BENCH_FILE) static void write_benchfile(statelist_t *candidates) { - printf("Writing brute force benchmark data..."); - FILE *benchfile = fopen(TEST_BENCH_FILENAME, "wb"); + PrintAndLogEx(NORMAL, "Writing brute force benchmark data in " RESOURCES_SUBDIR " subdirectory..."); + FILE *benchfile = fopen(RESOURCES_SUBDIR TEST_BENCH_FILENAME, "wb"); + if (benchfile == NULL) { + PrintAndLogEx(ERR, "Can't write " RESOURCES_SUBDIR TEST_BENCH_FILENAME", abort!"); + return; + } fwrite(&nonces_to_bruteforce, 1, sizeof(nonces_to_bruteforce), benchfile); for (uint32_t i = 0; i < nonces_to_bruteforce; i++) { fwrite(&(bf_test_nonce[i]), 1, sizeof(bf_test_nonce[i]), benchfile); @@ -283,7 +289,7 @@ static void write_benchfile(statelist_t *candidates) { fwrite(&(candidates->states[ODD_STATE][i]), 1, sizeof(uint32_t), benchfile); } fclose(benchfile); - printf("done.\n"); + PrintAndLogEx(NORMAL, "Done"); } #endif @@ -360,14 +366,17 @@ static bool read_bench_data(statelist_t *test_candidates) { uint32_t num_states = 0; uint32_t states_read = 0; - char bench_file_path[strlen(get_my_executable_directory()) + strlen(TEST_BENCH_FILENAME) + 1]; - strcpy(bench_file_path, get_my_executable_directory()); - strcat(bench_file_path, TEST_BENCH_FILENAME); - - FILE *benchfile = fopen(bench_file_path, "rb"); - if (benchfile == NULL) { + char *path; + if (searchFile(&path, RESOURCES_SUBDIR, TEST_BENCH_FILENAME, "") != PM3_SUCCESS) { return false; } + + FILE *benchfile = fopen(path, "rb"); + if (benchfile == NULL) { + free(path); + return false; + } + free(path); bytes_read = fread(&nonces_to_bruteforce, 1, sizeof(nonces_to_bruteforce), benchfile); if (bytes_read != sizeof(nonces_to_bruteforce)) { fclose(benchfile); diff --git a/client/hardnested/bf_bench_data.bin b/client/resources/hardnested_bf_bench_data.bin similarity index 100% rename from client/hardnested/bf_bench_data.bin rename to client/resources/hardnested_bf_bench_data.bin From 491e8925bb7fe52493e5d817e313ea256aa0cac6 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 30 Aug 2019 08:54:23 +0200 Subject: [PATCH 191/347] linked in --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bf18de1a..8f2bf4b5a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. |[Notes on external flash](/doc/ext_flash_notes.md)||| |[Notes on Termux / Android](/doc/termux_notes.md)||| |[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||| +|[Notes on loclass](/doc/loclass_notes.md)||| |[Developing standalone mode](/armsrc/Standalone/readme.md)|[Wiki about standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) || |[Donations](#Donations)||| @@ -46,7 +47,7 @@ This fork now compiles just fine on - Windows/mingw environment with Qt5.6.1 & GCC 4.8 - Ubuntu 1404, 1510, 1604, 1804, 1904 - Mac OS X / Homebrew - - ParrotOS, Gentoo, Pentoo + - ParrotOS, Gentoo, Pentoo, Kali, Nethunter, Archlinux - WSL, WSL2 (Windows subsystem linux) on Windows 10 - Docker container @@ -59,6 +60,7 @@ If you intend to contribute to the code, please read the [coding style notes](HA - Internal notes on [standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) - Internal notes on [Termux / Android](/doc/termux_notes.md) - Internal notes on [Wireshark / tracedata](/doc/trace_wireshark_notes.md) +- Internal notes on [loclass](/doc/loclass_notes.md) ## Cheat sheet Thanks to Alex Dibs, you can enjoy a [command cheat sheet](/doc/cheatsheet.md) From 54a58cde4e3f873bd18c952f4f93c3f41f6f33f2 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 30 Aug 2019 08:57:04 +0200 Subject: [PATCH 192/347] textual --- doc/loclass_notes.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/loclass_notes.md b/doc/loclass_notes.md index d77e8ba57..2684ae433 100644 --- a/doc/loclass_notes.md +++ b/doc/loclass_notes.md @@ -1,22 +1,26 @@ # About LOCLASS attack -This document is primarily intended for understanding `hf iclass loclass` and used files with it. +This document is primarily intended for understanding `hf iclass loclass` and files used with it. LOCLASS aim is to recoved the used masterkey for that specific reader configued in Elite mode / High Security mode. LOCLASS, is a two part attack. First is the online part where you gather needed information from the reader by presenting a carefully selected CSN and save the responses to file. For the first part you run `hf iclass sim 2` and take notice of the saved filename. The second part is offline, where the information gathered from the first step is used in a series of DES operations to figure out the used -masterkey. run `hf iclass loclass f abc.bin' +masterkey. + run `hf iclass loclass f abc.bin` If you don't have access to a iClass SE reader configured in Elite mode there is a test file which you can use. -`hf iclass loclass f iclass_dump.bin` + `hf iclass loclass f iclass_dump.bin` # Unit testing -In order to verify that loclass is actually working, there is a "unit" test mode. run `hf iclass loclass t`. +In order to verify that loclass is actually working, there is a "unit" test mode. +run `hf iclass loclass t`. + This test mode uses two files. -- iclass_dump.bin - this is a sample file from `hf iclass sim 2`, with complete keytable recovery, using 128 carefully selected CSN and the file contains the MAC results from reader. -- iclass_key.bin - this is file shall contain the legacy masterkey, AA1 key. loclass uses it to verify that permution / reversing / generation of key is correct. \ No newline at end of file + +- `iclass_dump.bin` + this is a sample file from `hf iclass sim 2`, with complete keytable recovery, using 128 carefully selected CSN and the file contains the MAC results from reader. +- `iclass_key.bin` + this is file shall contain the legacy masterkey, AA1 key. loclass uses it to verify that permution / reversing / generation of key is correct. \ No newline at end of file From f227cebc3b6c90ff0baea5f6909b52ffc8524e64 Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 30 Aug 2019 09:22:32 +0200 Subject: [PATCH 193/347] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8f2bf4b5a..f02deabf6 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ On the software side: quite a lot, see the [Changelog file](CHANGELOG.md). ## Development This fork now compiles just fine on + - Proxspace v3.2 - Windows/mingw environment with Qt5.6.1 & GCC 4.8 - Ubuntu 1404, 1510, 1604, 1804, 1904 - Mac OS X / Homebrew From 2c853d94ea78356509f71f608670fd820ce508a1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 09:02:01 +0200 Subject: [PATCH 194/347] move hardnested tables to resources/ --- client/cmddata.c | 2 +- client/cmdhfmf.c | 4 +- client/cmdhfmfhard.c | 14 ++++-- client/cmdscript.c | 2 +- client/cmdsmartcard.c | 2 +- client/crypto/asn1dump.c | 2 +- client/emv/emv_pk.c | 2 +- client/emv/emvjson.c | 2 +- client/fileutils.c | 42 +++++++++++++----- client/fileutils.h | 2 +- client/hardnested/hardnested_bruteforce.c | 2 +- .../bitflip_0_001_states.bin.z | Bin .../bitflip_0_003_states.bin.z | Bin .../bitflip_0_005_states.bin.z | Bin .../bitflip_0_007_states.bin.z | Bin .../bitflip_0_009_states.bin.z | Bin .../bitflip_0_00b_states.bin.z | Bin .../bitflip_0_00d_states.bin.z | Bin .../bitflip_0_00f_states.bin.z | Bin .../bitflip_0_010_states.bin.z | Bin .../bitflip_0_014_states.bin.z | Bin .../bitflip_0_01c_states.bin.z | Bin .../bitflip_0_021_states.bin.z | Bin .../bitflip_0_023_states.bin.z | Bin .../bitflip_0_025_states.bin.z | 0 .../bitflip_0_027_states.bin.z | Bin .../bitflip_0_029_states.bin.z | Bin .../bitflip_0_02b_states.bin.z | Bin .../bitflip_0_02d_states.bin.z | Bin .../bitflip_0_02f_states.bin.z | Bin .../bitflip_0_030_states.bin.z | Bin .../bitflip_0_034_states.bin.z | Bin .../bitflip_0_03c_states.bin.z | Bin .../bitflip_0_040_states.bin.z | Bin .../bitflip_0_044_states.bin.z | Bin .../bitflip_0_04c_states.bin.z | Bin .../bitflip_0_051_states.bin.z | Bin .../bitflip_0_053_states.bin.z | Bin .../bitflip_0_055_states.bin.z | Bin .../bitflip_0_057_states.bin.z | Bin .../bitflip_0_059_states.bin.z | Bin .../bitflip_0_05b_states.bin.z | Bin .../bitflip_0_05d_states.bin.z | Bin .../bitflip_0_05f_states.bin.z | Bin .../bitflip_0_064_states.bin.z | Bin .../bitflip_0_06c_states.bin.z | Bin .../bitflip_0_071_states.bin.z | Bin .../bitflip_0_073_states.bin.z | Bin .../bitflip_0_075_states.bin.z | Bin .../bitflip_0_077_states.bin.z | Bin .../bitflip_0_079_states.bin.z | Bin .../bitflip_0_07b_states.bin.z | Bin .../bitflip_0_07f_states.bin.z | Bin .../bitflip_0_081_states.bin.z | Bin .../bitflip_0_083_states.bin.z | Bin .../bitflip_0_085_states.bin.z | Bin .../bitflip_0_087_states.bin.z | Bin .../bitflip_0_089_states.bin.z | Bin .../bitflip_0_08b_states.bin.z | Bin .../bitflip_0_08d_states.bin.z | Bin .../bitflip_0_08f_states.bin.z | Bin .../bitflip_0_090_states.bin.z | Bin .../bitflip_0_094_states.bin.z | Bin .../bitflip_0_09c_states.bin.z | Bin .../bitflip_0_0a1_states.bin.z | Bin .../bitflip_0_0a3_states.bin.z | Bin .../bitflip_0_0a5_states.bin.z | Bin .../bitflip_0_0a7_states.bin.z | Bin .../bitflip_0_0a9_states.bin.z | Bin .../bitflip_0_0ab_states.bin.z | Bin .../bitflip_0_0ad_states.bin.z | Bin .../bitflip_0_0af_states.bin.z | Bin .../bitflip_0_0b0_states.bin.z | Bin .../bitflip_0_0b4_states.bin.z | Bin .../bitflip_0_0bc_states.bin.z | Bin .../bitflip_0_0c0_states.bin.z | Bin .../bitflip_0_0c4_states.bin.z | Bin .../bitflip_0_0cc_states.bin.z | Bin .../bitflip_0_0d1_states.bin.z | Bin .../bitflip_0_0d3_states.bin.z | Bin .../bitflip_0_0d5_states.bin.z | Bin .../bitflip_0_0d7_states.bin.z | Bin .../bitflip_0_0d9_states.bin.z | Bin .../bitflip_0_0db_states.bin.z | Bin .../bitflip_0_0dd_states.bin.z | Bin .../bitflip_0_0df_states.bin.z | Bin .../bitflip_0_0e4_states.bin.z | Bin .../bitflip_0_0ec_states.bin.z | Bin .../bitflip_0_0f1_states.bin.z | 0 .../bitflip_0_0f3_states.bin.z | Bin .../bitflip_0_0f5_states.bin.z | Bin .../bitflip_0_0f7_states.bin.z | Bin .../bitflip_0_0f9_states.bin.z | Bin .../bitflip_0_0fb_states.bin.z | Bin .../bitflip_0_0fd_states.bin.z | Bin .../bitflip_0_0ff_states.bin.z | Bin .../bitflip_0_104_states.bin.z | Bin .../bitflip_0_10c_states.bin.z | Bin .../bitflip_0_111_states.bin.z | Bin .../bitflip_0_113_states.bin.z | Bin .../bitflip_0_115_states.bin.z | Bin .../bitflip_0_117_states.bin.z | Bin .../bitflip_0_119_states.bin.z | Bin .../bitflip_0_11b_states.bin.z | Bin .../bitflip_0_11d_states.bin.z | Bin .../bitflip_0_11f_states.bin.z | Bin .../bitflip_0_124_states.bin.z | Bin .../bitflip_0_12c_states.bin.z | Bin .../bitflip_0_131_states.bin.z | Bin .../bitflip_0_133_states.bin.z | Bin .../bitflip_0_135_states.bin.z | Bin .../bitflip_0_137_states.bin.z | Bin .../bitflip_0_139_states.bin.z | Bin .../bitflip_0_13b_states.bin.z | Bin .../bitflip_0_13d_states.bin.z | Bin .../bitflip_0_13f_states.bin.z | Bin .../bitflip_0_141_states.bin.z | Bin .../bitflip_0_143_states.bin.z | Bin .../bitflip_0_145_states.bin.z | Bin .../bitflip_0_147_states.bin.z | Bin .../bitflip_0_149_states.bin.z | Bin .../bitflip_0_14b_states.bin.z | Bin .../bitflip_0_14d_states.bin.z | Bin .../bitflip_0_14f_states.bin.z | Bin .../bitflip_0_150_states.bin.z | Bin .../bitflip_0_154_states.bin.z | Bin .../bitflip_0_15c_states.bin.z | Bin .../bitflip_0_161_states.bin.z | Bin .../bitflip_0_163_states.bin.z | Bin .../bitflip_0_165_states.bin.z | 0 .../bitflip_0_167_states.bin.z | Bin .../bitflip_0_169_states.bin.z | Bin .../bitflip_0_16b_states.bin.z | Bin .../bitflip_0_16d_states.bin.z | Bin .../bitflip_0_16f_states.bin.z | Bin .../bitflip_0_170_states.bin.z | Bin .../bitflip_0_174_states.bin.z | Bin .../bitflip_0_17c_states.bin.z | Bin .../bitflip_0_184_states.bin.z | Bin .../bitflip_0_18c_states.bin.z | Bin .../bitflip_0_191_states.bin.z | Bin .../bitflip_0_193_states.bin.z | Bin .../bitflip_0_195_states.bin.z | Bin .../bitflip_0_197_states.bin.z | Bin .../bitflip_0_199_states.bin.z | Bin .../bitflip_0_19b_states.bin.z | Bin .../bitflip_0_19d_states.bin.z | Bin .../bitflip_0_19f_states.bin.z | Bin .../bitflip_0_1a4_states.bin.z | Bin .../bitflip_0_1ac_states.bin.z | Bin .../bitflip_0_1b1_states.bin.z | Bin .../bitflip_0_1b3_states.bin.z | Bin .../bitflip_0_1b5_states.bin.z | Bin .../bitflip_0_1b7_states.bin.z | Bin .../bitflip_0_1b9_states.bin.z | Bin .../bitflip_0_1bb_states.bin.z | Bin .../bitflip_0_1bd_states.bin.z | Bin .../bitflip_0_1bf_states.bin.z | Bin .../bitflip_0_1c1_states.bin.z | Bin .../bitflip_0_1c3_states.bin.z | Bin .../bitflip_0_1c5_states.bin.z | Bin .../bitflip_0_1c9_states.bin.z | Bin .../bitflip_0_1cb_states.bin.z | Bin .../bitflip_0_1d0_states.bin.z | Bin .../bitflip_0_1d4_states.bin.z | Bin .../bitflip_0_1dc_states.bin.z | Bin .../bitflip_0_1e1_states.bin.z | Bin .../bitflip_0_1e3_states.bin.z | Bin .../bitflip_0_1e5_states.bin.z | Bin .../bitflip_0_1e7_states.bin.z | Bin .../bitflip_0_1e9_states.bin.z | Bin .../bitflip_0_1eb_states.bin.z | Bin .../bitflip_0_1ed_states.bin.z | Bin .../bitflip_0_1ef_states.bin.z | Bin .../bitflip_0_1f0_states.bin.z | Bin .../bitflip_0_1f4_states.bin.z | Bin .../bitflip_0_1fc_states.bin.z | Bin .../bitflip_0_210_states.bin.z | 0 .../bitflip_0_225_states.bin.z | Bin .../bitflip_0_227_states.bin.z | Bin .../bitflip_0_22d_states.bin.z | Bin .../bitflip_0_22f_states.bin.z | Bin .../bitflip_0_240_states.bin.z | 0 .../bitflip_0_275_states.bin.z | Bin .../bitflip_0_277_states.bin.z | Bin .../bitflip_0_27f_states.bin.z | Bin .../bitflip_0_294_states.bin.z | 0 .../bitflip_0_2a1_states.bin.z | Bin .../bitflip_0_2a3_states.bin.z | Bin .../bitflip_0_2a9_states.bin.z | Bin .../bitflip_0_2ab_states.bin.z | Bin .../bitflip_0_2c4_states.bin.z | 0 .../bitflip_0_2f1_states.bin.z | Bin .../bitflip_0_2f3_states.bin.z | Bin .../bitflip_0_2f9_states.bin.z | Bin .../bitflip_0_2fb_states.bin.z | Bin .../bitflip_0_335_states.bin.z | Bin .../bitflip_0_337_states.bin.z | Bin .../bitflip_0_33d_states.bin.z | Bin .../bitflip_0_33f_states.bin.z | Bin .../bitflip_0_350_states.bin.z | 0 .../bitflip_0_365_states.bin.z | Bin .../bitflip_0_367_states.bin.z | Bin .../bitflip_0_36d_states.bin.z | Bin .../bitflip_0_36f_states.bin.z | Bin .../bitflip_0_384_states.bin.z | 0 .../bitflip_0_3b1_states.bin.z | Bin .../bitflip_0_3b3_states.bin.z | Bin .../bitflip_0_3b9_states.bin.z | Bin .../bitflip_0_3bb_states.bin.z | Bin .../bitflip_0_3d4_states.bin.z | 0 .../bitflip_0_3e1_states.bin.z | Bin .../bitflip_0_3e3_states.bin.z | Bin .../bitflip_0_3e9_states.bin.z | Bin .../bitflip_0_3eb_states.bin.z | Bin .../bitflip_1_002_states.bin.z | Bin .../bitflip_1_008_states.bin.z | Bin .../bitflip_1_00a_states.bin.z | Bin .../bitflip_1_012_states.bin.z | Bin .../bitflip_1_018_states.bin.z | Bin .../bitflip_1_01a_states.bin.z | Bin .../bitflip_1_020_states.bin.z | Bin .../bitflip_1_028_states.bin.z | Bin .../bitflip_1_02a_states.bin.z | Bin .../bitflip_1_02e_states.bin.z | Bin .../bitflip_1_032_states.bin.z | Bin .../bitflip_1_036_states.bin.z | Bin .../bitflip_1_038_states.bin.z | Bin .../bitflip_1_03a_states.bin.z | Bin .../bitflip_1_03e_states.bin.z | Bin .../bitflip_1_040_states.bin.z | Bin .../bitflip_1_042_states.bin.z | Bin .../bitflip_1_046_states.bin.z | Bin .../bitflip_1_048_states.bin.z | Bin .../bitflip_1_04a_states.bin.z | Bin .../bitflip_1_04e_states.bin.z | Bin .../bitflip_1_052_states.bin.z | Bin .../bitflip_1_056_states.bin.z | Bin .../bitflip_1_058_states.bin.z | Bin .../bitflip_1_05a_states.bin.z | Bin .../bitflip_1_05e_states.bin.z | Bin .../bitflip_1_060_states.bin.z | Bin .../bitflip_1_062_states.bin.z | Bin .../bitflip_1_066_states.bin.z | Bin .../bitflip_1_068_states.bin.z | Bin .../bitflip_1_06a_states.bin.z | Bin .../bitflip_1_06e_states.bin.z | Bin .../bitflip_1_072_states.bin.z | Bin .../bitflip_1_076_states.bin.z | Bin .../bitflip_1_078_states.bin.z | Bin .../bitflip_1_07a_states.bin.z | Bin .../bitflip_1_07e_states.bin.z | Bin .../bitflip_1_080_states.bin.z | Bin .../bitflip_1_082_states.bin.z | Bin .../bitflip_1_086_states.bin.z | Bin .../bitflip_1_088_states.bin.z | Bin .../bitflip_1_08a_states.bin.z | Bin .../bitflip_1_08e_states.bin.z | Bin .../bitflip_1_092_states.bin.z | Bin .../bitflip_1_096_states.bin.z | Bin .../bitflip_1_098_states.bin.z | Bin .../bitflip_1_09a_states.bin.z | Bin .../bitflip_1_09e_states.bin.z | Bin .../bitflip_1_0a0_states.bin.z | Bin .../bitflip_1_0a2_states.bin.z | Bin .../bitflip_1_0a6_states.bin.z | Bin .../bitflip_1_0a8_states.bin.z | Bin .../bitflip_1_0aa_states.bin.z | Bin .../bitflip_1_0ae_states.bin.z | Bin .../bitflip_1_0b2_states.bin.z | Bin .../bitflip_1_0b6_states.bin.z | Bin .../bitflip_1_0b8_states.bin.z | Bin .../bitflip_1_0ba_states.bin.z | Bin .../bitflip_1_0be_states.bin.z | Bin .../bitflip_1_0c0_states.bin.z | Bin .../bitflip_1_0c2_states.bin.z | Bin .../bitflip_1_0c6_states.bin.z | Bin .../bitflip_1_0c8_states.bin.z | Bin .../bitflip_1_0ca_states.bin.z | Bin .../bitflip_1_0ce_states.bin.z | Bin .../bitflip_1_0d2_states.bin.z | Bin .../bitflip_1_0d6_states.bin.z | Bin .../bitflip_1_0d8_states.bin.z | Bin .../bitflip_1_0da_states.bin.z | Bin .../bitflip_1_0de_states.bin.z | Bin .../bitflip_1_0e0_states.bin.z | Bin .../bitflip_1_0e8_states.bin.z | Bin .../bitflip_1_0f8_states.bin.z | Bin .../bitflip_1_108_states.bin.z | Bin .../bitflip_1_111_states.bin.z | Bin .../bitflip_1_113_states.bin.z | Bin .../bitflip_1_115_states.bin.z | Bin .../bitflip_1_117_states.bin.z | Bin .../bitflip_1_118_states.bin.z | Bin .../bitflip_1_11a_states.bin.z | Bin .../bitflip_1_11b_states.bin.z | Bin .../bitflip_1_120_states.bin.z | Bin .../bitflip_1_122_states.bin.z | Bin .../bitflip_1_128_states.bin.z | Bin .../bitflip_1_131_states.bin.z | Bin .../bitflip_1_135_states.bin.z | Bin .../bitflip_1_138_states.bin.z | Bin .../bitflip_1_145_states.bin.z | Bin .../bitflip_1_147_states.bin.z | Bin .../bitflip_1_148_states.bin.z | Bin .../bitflip_1_158_states.bin.z | Bin .../bitflip_1_160_states.bin.z | Bin .../bitflip_1_161_states.bin.z | Bin .../bitflip_1_163_states.bin.z | Bin .../bitflip_1_165_states.bin.z | Bin .../bitflip_1_168_states.bin.z | Bin .../bitflip_1_178_states.bin.z | Bin .../bitflip_1_180_states.bin.z | Bin .../bitflip_1_188_states.bin.z | Bin .../bitflip_1_191_states.bin.z | Bin .../bitflip_1_198_states.bin.z | Bin .../bitflip_1_199_states.bin.z | Bin .../bitflip_1_19d_states.bin.z | Bin .../bitflip_1_19f_states.bin.z | Bin .../bitflip_1_1a0_states.bin.z | 0 .../bitflip_1_1a8_states.bin.z | Bin .../bitflip_1_1b3_states.bin.z | Bin .../bitflip_1_1b5_states.bin.z | Bin .../bitflip_1_1b7_states.bin.z | Bin .../bitflip_1_1b8_states.bin.z | Bin .../bitflip_1_1b9_states.bin.z | Bin .../bitflip_1_1bd_states.bin.z | Bin .../bitflip_1_1c1_states.bin.z | Bin .../bitflip_1_1c3_states.bin.z | Bin .../bitflip_1_1c8_states.bin.z | Bin .../bitflip_1_1c9_states.bin.z | Bin .../bitflip_1_1cd_states.bin.z | Bin .../bitflip_1_1cf_states.bin.z | Bin .../bitflip_1_1d8_states.bin.z | Bin .../bitflip_1_1e0_states.bin.z | 0 .../bitflip_1_1e1_states.bin.z | Bin .../bitflip_1_1e5_states.bin.z | Bin .../bitflip_1_1e7_states.bin.z | Bin .../bitflip_1_1e8_states.bin.z | Bin .../bitflip_1_1e9_states.bin.z | Bin .../bitflip_1_1eb_states.bin.z | Bin .../bitflip_1_1ed_states.bin.z | Bin .../bitflip_1_1f8_states.bin.z | Bin .../bitflip_1_208_states.bin.z | 0 .../bitflip_1_220_states.bin.z | 0 .../bitflip_1_24a_states.bin.z | Bin .../bitflip_1_24e_states.bin.z | Bin .../bitflip_1_25a_states.bin.z | Bin .../bitflip_1_25e_states.bin.z | Bin .../bitflip_1_262_states.bin.z | Bin .../bitflip_1_266_states.bin.z | Bin .../bitflip_1_272_states.bin.z | Bin .../bitflip_1_276_states.bin.z | Bin .../bitflip_1_280_states.bin.z | 0 .../bitflip_1_2a8_states.bin.z | 0 .../bitflip_1_2c2_states.bin.z | Bin .../bitflip_1_2c6_states.bin.z | Bin .../bitflip_1_2d2_states.bin.z | Bin .../bitflip_1_2d6_states.bin.z | Bin .../bitflip_1_328_states.bin.z | 0 .../bitflip_1_388_states.bin.z | 0 .../bitflip_1_3a0_states.bin.z | 0 362 files changed, 50 insertions(+), 26 deletions(-) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_001_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_003_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_005_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_007_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_009_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_00b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_00d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_00f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_010_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_014_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_01c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_021_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_023_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_025_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_027_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_029_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_02b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_02d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_02f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_030_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_034_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_03c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_040_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_044_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_04c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_051_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_053_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_055_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_057_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_059_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_05b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_05d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_05f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_064_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_06c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_071_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_073_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_075_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_077_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_079_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_07b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_07f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_081_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_083_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_085_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_087_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_089_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_08b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_08d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_08f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_090_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_094_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_09c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0a1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0a3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0a5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0a7_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0a9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0ab_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0ad_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0af_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0b0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0b4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0bc_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0c0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0c4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0cc_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0d1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0d3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0d5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0d7_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0d9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0db_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0dd_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0df_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0e4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0ec_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0f1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0f3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0f5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0f7_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0f9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0fb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0fd_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_0ff_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_104_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_10c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_111_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_113_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_115_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_117_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_119_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_11b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_11d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_11f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_124_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_12c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_131_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_133_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_135_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_137_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_139_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_13b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_13d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_13f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_141_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_143_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_145_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_147_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_149_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_14b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_14d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_14f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_150_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_154_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_15c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_161_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_163_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_165_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_167_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_169_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_16b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_16d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_16f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_170_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_174_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_17c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_184_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_18c_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_191_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_193_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_195_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_197_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_199_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_19b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_19d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_19f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1a4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1ac_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1b1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1b3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1b5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1b7_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1b9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1bb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1bd_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1bf_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1c1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1c3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1c5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1c9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1cb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1d0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1d4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1dc_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1e1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1e3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1e5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1e7_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1e9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1eb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1ed_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1ef_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1f0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1f4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_1fc_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_210_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_225_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_227_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_22d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_22f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_240_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_275_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_277_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_27f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_294_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2a1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2a3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2a9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2ab_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2c4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2f1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2f3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2f9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_2fb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_335_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_337_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_33d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_33f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_350_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_365_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_367_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_36d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_36f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_384_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3b1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3b3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3b9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3bb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3d4_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3e1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3e3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3e9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_0_3eb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_002_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_008_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_00a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_012_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_018_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_01a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_020_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_028_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_02a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_02e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_032_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_036_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_038_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_03a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_03e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_040_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_042_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_046_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_048_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_04a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_04e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_052_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_056_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_058_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_05a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_05e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_060_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_062_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_066_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_068_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_06a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_06e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_072_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_076_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_078_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_07a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_07e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_080_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_082_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_086_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_088_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_08a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_08e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_092_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_096_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_098_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_09a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_09e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0a0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0a2_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0a6_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0a8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0aa_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0ae_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0b2_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0b6_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0b8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0ba_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0be_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0c0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0c2_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0c6_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0c8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0ca_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0ce_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0d2_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0d6_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0d8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0da_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0de_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0e0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0e8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_0f8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_108_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_111_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_113_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_115_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_117_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_118_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_11a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_11b_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_120_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_122_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_128_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_131_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_135_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_138_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_145_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_147_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_148_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_158_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_160_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_161_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_163_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_165_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_168_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_178_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_180_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_188_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_191_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_198_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_199_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_19d_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_19f_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1a0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1a8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1b3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1b5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1b7_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1b8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1b9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1bd_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1c1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1c3_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1c8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1c9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1cd_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1cf_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1d8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1e0_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1e1_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1e5_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1e7_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1e8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1e9_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1eb_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1ed_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_1f8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_208_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_220_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_24a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_24e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_25a_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_25e_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_262_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_266_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_272_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_276_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_280_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_2a8_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_2c2_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_2c6_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_2d2_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_2d6_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_328_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_388_states.bin.z (100%) rename client/{hardnested/tables => resources/hardnested_tables}/bitflip_1_3a0_states.bin.z (100%) diff --git a/client/cmddata.c b/client/cmddata.c index 817a63930..91bf4b65a 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1648,7 +1648,7 @@ static int CmdLoad(const char *Cmd) { memcpy(filename, Cmd, len); char *path; - if (searchFile(&path, TRACES_SUBDIR, filename, "") != PM3_SUCCESS) { + if (searchFile(&path, TRACES_SUBDIR, filename, "", false) != PM3_SUCCESS) { return PM3_EFILE; } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 7a1d2f4b2..538ec0569 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2398,7 +2398,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { } char *dict_path; - int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic"); + int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic", false); if (res != PM3_SUCCESS) { free(keyBlock); return res; @@ -2660,7 +2660,7 @@ static int CmdHF14AMfChk(const char *Cmd) { } char *dict_path; - int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic"); + int res = searchFile(&dict_path, DICTIONARIES_SUBDIR, filename, ".dic", false); if (res != PM3_SUCCESS) { free(keyBlock); return PM3_EFILE; diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index d66df7eae..c38c4022e 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -36,13 +36,14 @@ #include "hardnested/hardnested_bf_core.h" #include "hardnested/hardnested_bitarray_core.h" #include "zlib.h" +#include "fileutils.h" #define NUM_CHECK_BITFLIPS_THREADS (num_CPUs()) #define NUM_REDUCTION_WORKING_THREADS (num_CPUs()) #define IGNORE_BITFLIP_THRESHOLD 0.99 // ignore bitflip arrays which have nearly only valid states -#define STATE_FILES_DIRECTORY "hardnested/tables/" +#define STATE_FILES_DIRECTORY "hardnested_tables/" #define STATE_FILE_TEMPLATE "bitflip_%d_%03" PRIx16 "_states.bin.z" #define DEBUG_KEY_ELIMINATION @@ -248,10 +249,15 @@ static void init_bitflip_bitarrays(void) { bitflip_bitarrays[odd_even][bitflip] = NULL; count_bitflip_bitarrays[odd_even][bitflip] = 1 << 24; sprintf(state_file_name, STATE_FILE_TEMPLATE, odd_even, bitflip); - strcpy(state_files_path, get_my_executable_directory()); - strcat(state_files_path, STATE_FILES_DIRECTORY); + strcpy(state_files_path, STATE_FILES_DIRECTORY); strcat(state_files_path, state_file_name); - FILE *statesfile = fopen(state_files_path, "rb"); + char *path; + if (searchFile(&path, RESOURCES_SUBDIR, state_files_path, "", true) != PM3_SUCCESS) { + continue; + } + + FILE *statesfile = fopen(path, "rb"); + free(path); if (statesfile == NULL) { continue; } else { diff --git a/client/cmdscript.c b/client/cmdscript.c index 318cc1dd4..473477228 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -67,7 +67,7 @@ static int CmdScriptRun(const char *Cmd) { sscanf(Cmd, "%127s%n %255[^\n\r]%n", preferredName, &name_len, arguments, &arg_len); char *script_path; - int res = searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua"); + int res = searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua", false); if (res != PM3_SUCCESS) return res; diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index 4ea67be95..d6606ad19 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -100,7 +100,7 @@ static int smart_loadjson(const char *preferredName, json_t **root) { if (preferredName == NULL) return 1; char *path; - int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, ".json"); + int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, ".json", false); if (res != PM3_SUCCESS) { return PM3_EFILE; } diff --git a/client/crypto/asn1dump.c b/client/crypto/asn1dump.c index 140b0d2e2..91b04216a 100644 --- a/client/crypto/asn1dump.c +++ b/client/crypto/asn1dump.c @@ -241,7 +241,7 @@ static char *asn1_oid_description(const char *oid, bool with_group_desc) { memset(res, 0x00, sizeof(res)); char *path; - if (searchFile(&path, RESOURCES_SUBDIR, "oids", ".json") != PM3_SUCCESS) { + if (searchFile(&path, RESOURCES_SUBDIR, "oids", ".json", false) != PM3_SUCCESS) { return NULL; } diff --git a/client/emv/emv_pk.c b/client/emv/emv_pk.c index bb124c63c..8465a6e95 100644 --- a/client/emv/emv_pk.c +++ b/client/emv/emv_pk.c @@ -486,7 +486,7 @@ struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx) { } */ char *path; - if (searchFile(&path, RESOURCES_SUBDIR, "capk", ".txt") != PM3_SUCCESS) { + if (searchFile(&path, RESOURCES_SUBDIR, "capk", ".txt", false) != PM3_SUCCESS) { return NULL; } pk = emv_pk_get_ca_pk_from_file(path, rid, idx); diff --git a/client/emv/emvjson.c b/client/emv/emvjson.c index 715407a23..785b6b8e7 100644 --- a/client/emv/emvjson.c +++ b/client/emv/emvjson.c @@ -306,7 +306,7 @@ bool ParamLoadFromJson(struct tlvdb *tlv) { } char *path; - if (searchFile(&path, RESOURCES_SUBDIR, "emv_defparams", ".json") != PM3_SUCCESS) { + if (searchFile(&path, RESOURCES_SUBDIR, "emv_defparams", ".json", false) != PM3_SUCCESS) { return false; } root = json_load_file(path, 0, &error); diff --git a/client/fileutils.c b/client/fileutils.c index ae7531771..427ebd9da 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -405,7 +405,7 @@ out: int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, size_t *datalen) { char *path; - int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, suffix); + int res = searchFile(&path, RESOURCES_SUBDIR, preferredName, suffix, false); if (res != PM3_SUCCESS) { return PM3_EFILE; } @@ -634,7 +634,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u if (data == NULL) return PM3_ESOFT; char *path; - if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic") != PM3_SUCCESS) + if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic", false) != PM3_SUCCESS) return PM3_EFILE; // t5577 == 4bytes @@ -701,7 +701,7 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key int retval = PM3_SUCCESS; char *path; - if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic") != PM3_SUCCESS) + if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic", false) != PM3_SUCCESS) return PM3_EFILE; // t5577 == 4bytes @@ -863,19 +863,22 @@ int searchAndList(const char *pm3dir, const char *ext) { return PM3_SUCCESS; } -static int searchFinalFile(char **foundpath, const char *pm3dir, const char *searchname) { +static int searchFinalFile(char **foundpath, const char *pm3dir, const char *searchname, bool silent) { if ((foundpath == NULL) || (pm3dir == NULL) || (searchname == NULL)) return PM3_ESOFT; // explicit absolute (/) or relative path (./) => try only to match it directly char *filename = calloc(strlen(searchname) + 1, sizeof(char)); if (filename == NULL) return PM3_EMALLOC; strcpy(filename, searchname); - if (g_debugMode == 2) { + if ((g_debugMode == 2) && (!silent)) { PrintAndLogEx(INFO, "Searching %s", filename); } if (((strlen(filename) > 1) && (filename[0] == '/')) || ((strlen(filename) > 2) && (filename[0] == '.') && (filename[1] == '/'))) { if (fileExists(filename)) { *foundpath = filename; + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Found %s", *foundpath); + } return PM3_SUCCESS; } else { goto out; @@ -887,6 +890,9 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea { if (fileExists(filename)) { *foundpath = filename; + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Found %s", *foundpath); + } return PM3_SUCCESS; } } @@ -903,12 +909,15 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea strcpy(path, exec_path); strcat(path, pm3dir); strcat(path, filename); - if (g_debugMode == 2) { + if ((g_debugMode == 2) && (!silent)) { PrintAndLogEx(INFO, "Searching %s", path); } if (fileExists(path)) { free(filename); *foundpath = path; + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Found %s", *foundpath); + } return PM3_SUCCESS; } else { free(path); @@ -925,12 +934,15 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea strcat(path, above); strcat(path, pm3dir); strcat(path, filename); - if (g_debugMode == 2) { + if ((g_debugMode == 2) && (!silent)) { PrintAndLogEx(INFO, "Searching %s", path); } if (fileExists(path)) { free(filename); *foundpath = path; + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Found %s", *foundpath); + } return PM3_SUCCESS; } else { free(path); @@ -946,12 +958,15 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea strcat(path, PM3_USER_DIRECTORY); strcat(path, pm3dir); strcat(path, filename); - if (g_debugMode == 2) { + if ((g_debugMode == 2) && (!silent)) { PrintAndLogEx(INFO, "Searching %s", path); } if (fileExists(path)) { free(filename); *foundpath = path; + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Found %s", *foundpath); + } return PM3_SUCCESS; } else { free(path); @@ -965,12 +980,15 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea strcpy(path, PM3_SHARE_PATH); strcat(path, pm3dir); strcat(path, filename); - if (g_debugMode == 2) { + if ((g_debugMode == 2) && (!silent)) { PrintAndLogEx(INFO, "Searching %s", path); } if (fileExists(path)) { free(filename); *foundpath = path; + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Found %s", *foundpath); + } return PM3_SUCCESS; } else { free(path); @@ -981,14 +999,14 @@ out: return PM3_EFILE; } -int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix) { +int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix, bool silent) { if (foundpath == NULL) return PM3_EINVARG; char *filename = filenamemcopy(searchname, suffix); if (filename == NULL) return PM3_EMALLOC; - int res = searchFinalFile(foundpath, pm3dir, filename); + int res = searchFinalFile(foundpath, pm3dir, filename, silent); if (res != PM3_SUCCESS) { - if (res == PM3_EFILE) + if ((res == PM3_EFILE) && (!silent)) PrintAndLogEx(FAILED, "Error - can't find %s", filename); free(filename); return res; diff --git a/client/fileutils.h b/client/fileutils.h index d7fdb13a3..5432aa816 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -202,6 +202,6 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key int convertOldMfuDump(uint8_t **dump, size_t *dumplen); int searchAndList(const char *pm3dir, const char *ext); -int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix); +int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix, bool silent); #endif // FILEUTILS_H diff --git a/client/hardnested/hardnested_bruteforce.c b/client/hardnested/hardnested_bruteforce.c index 96211f47f..3aea34a96 100644 --- a/client/hardnested/hardnested_bruteforce.c +++ b/client/hardnested/hardnested_bruteforce.c @@ -367,7 +367,7 @@ static bool read_bench_data(statelist_t *test_candidates) { uint32_t states_read = 0; char *path; - if (searchFile(&path, RESOURCES_SUBDIR, TEST_BENCH_FILENAME, "") != PM3_SUCCESS) { + if (searchFile(&path, RESOURCES_SUBDIR, TEST_BENCH_FILENAME, "", false) != PM3_SUCCESS) { return false; } diff --git a/client/hardnested/tables/bitflip_0_001_states.bin.z b/client/resources/hardnested_tables/bitflip_0_001_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_001_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_001_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_003_states.bin.z b/client/resources/hardnested_tables/bitflip_0_003_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_003_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_003_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_005_states.bin.z b/client/resources/hardnested_tables/bitflip_0_005_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_005_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_005_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_007_states.bin.z b/client/resources/hardnested_tables/bitflip_0_007_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_007_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_007_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_009_states.bin.z b/client/resources/hardnested_tables/bitflip_0_009_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_009_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_009_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_00b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_00b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_00b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_00b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_00d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_00d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_00d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_00d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_00f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_00f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_00f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_00f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_010_states.bin.z b/client/resources/hardnested_tables/bitflip_0_010_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_010_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_010_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_014_states.bin.z b/client/resources/hardnested_tables/bitflip_0_014_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_014_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_014_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_01c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_01c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_01c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_01c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_021_states.bin.z b/client/resources/hardnested_tables/bitflip_0_021_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_021_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_021_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_023_states.bin.z b/client/resources/hardnested_tables/bitflip_0_023_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_023_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_023_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_025_states.bin.z b/client/resources/hardnested_tables/bitflip_0_025_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_025_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_025_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_027_states.bin.z b/client/resources/hardnested_tables/bitflip_0_027_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_027_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_027_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_029_states.bin.z b/client/resources/hardnested_tables/bitflip_0_029_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_029_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_029_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_02b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_02b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_02b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_02b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_02d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_02d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_02d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_02d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_02f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_02f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_02f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_02f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_030_states.bin.z b/client/resources/hardnested_tables/bitflip_0_030_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_030_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_030_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_034_states.bin.z b/client/resources/hardnested_tables/bitflip_0_034_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_034_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_034_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_03c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_03c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_03c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_03c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_040_states.bin.z b/client/resources/hardnested_tables/bitflip_0_040_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_040_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_040_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_044_states.bin.z b/client/resources/hardnested_tables/bitflip_0_044_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_044_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_044_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_04c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_04c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_04c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_04c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_051_states.bin.z b/client/resources/hardnested_tables/bitflip_0_051_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_051_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_051_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_053_states.bin.z b/client/resources/hardnested_tables/bitflip_0_053_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_053_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_053_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_055_states.bin.z b/client/resources/hardnested_tables/bitflip_0_055_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_055_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_055_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_057_states.bin.z b/client/resources/hardnested_tables/bitflip_0_057_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_057_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_057_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_059_states.bin.z b/client/resources/hardnested_tables/bitflip_0_059_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_059_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_059_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_05b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_05b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_05b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_05b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_05d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_05d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_05d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_05d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_05f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_05f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_05f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_05f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_064_states.bin.z b/client/resources/hardnested_tables/bitflip_0_064_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_064_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_064_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_06c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_06c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_06c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_06c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_071_states.bin.z b/client/resources/hardnested_tables/bitflip_0_071_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_071_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_071_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_073_states.bin.z b/client/resources/hardnested_tables/bitflip_0_073_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_073_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_073_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_075_states.bin.z b/client/resources/hardnested_tables/bitflip_0_075_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_075_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_075_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_077_states.bin.z b/client/resources/hardnested_tables/bitflip_0_077_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_077_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_077_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_079_states.bin.z b/client/resources/hardnested_tables/bitflip_0_079_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_079_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_079_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_07b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_07b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_07b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_07b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_07f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_07f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_07f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_07f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_081_states.bin.z b/client/resources/hardnested_tables/bitflip_0_081_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_081_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_081_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_083_states.bin.z b/client/resources/hardnested_tables/bitflip_0_083_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_083_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_083_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_085_states.bin.z b/client/resources/hardnested_tables/bitflip_0_085_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_085_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_085_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_087_states.bin.z b/client/resources/hardnested_tables/bitflip_0_087_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_087_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_087_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_089_states.bin.z b/client/resources/hardnested_tables/bitflip_0_089_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_089_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_089_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_08b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_08b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_08b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_08b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_08d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_08d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_08d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_08d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_08f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_08f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_08f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_08f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_090_states.bin.z b/client/resources/hardnested_tables/bitflip_0_090_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_090_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_090_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_094_states.bin.z b/client/resources/hardnested_tables/bitflip_0_094_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_094_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_094_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_09c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_09c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_09c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_09c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0a1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0a1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0a1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0a1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0a3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0a3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0a3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0a3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0a5_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0a5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0a5_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0a5_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0a7_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0a7_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0a7_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0a7_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0a9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0a9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0a9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0a9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0ab_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0ab_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0ab_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0ab_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0ad_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0ad_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0ad_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0ad_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0af_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0af_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0af_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0af_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0b0_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0b0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0b0_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0b0_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0b4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0b4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0b4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0b4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0bc_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0bc_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0bc_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0bc_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0c0_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0c0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0c0_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0c0_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0c4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0c4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0c4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0c4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0cc_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0cc_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0cc_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0cc_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0d1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0d1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0d1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0d1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0d3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0d3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0d3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0d3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0d5_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0d5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0d5_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0d5_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0d7_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0d7_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0d7_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0d7_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0d9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0d9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0d9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0d9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0db_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0db_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0db_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0db_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0dd_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0dd_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0dd_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0dd_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0df_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0df_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0df_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0df_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0e4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0e4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0e4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0e4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0ec_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0ec_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0ec_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0ec_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0f1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0f1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0f1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0f1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0f3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0f3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0f3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0f3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0f5_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0f5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0f5_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0f5_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0f7_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0f7_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0f7_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0f7_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0f9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0f9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0f9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0f9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0fb_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0fb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0fb_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0fb_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0fd_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0fd_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0fd_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0fd_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_0ff_states.bin.z b/client/resources/hardnested_tables/bitflip_0_0ff_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_0ff_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_0ff_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_104_states.bin.z b/client/resources/hardnested_tables/bitflip_0_104_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_104_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_104_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_10c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_10c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_10c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_10c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_111_states.bin.z b/client/resources/hardnested_tables/bitflip_0_111_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_111_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_111_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_113_states.bin.z b/client/resources/hardnested_tables/bitflip_0_113_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_113_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_113_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_115_states.bin.z b/client/resources/hardnested_tables/bitflip_0_115_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_115_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_115_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_117_states.bin.z b/client/resources/hardnested_tables/bitflip_0_117_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_117_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_117_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_119_states.bin.z b/client/resources/hardnested_tables/bitflip_0_119_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_119_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_119_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_11b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_11b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_11b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_11b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_11d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_11d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_11d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_11d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_11f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_11f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_11f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_11f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_124_states.bin.z b/client/resources/hardnested_tables/bitflip_0_124_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_124_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_124_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_12c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_12c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_12c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_12c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_131_states.bin.z b/client/resources/hardnested_tables/bitflip_0_131_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_131_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_131_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_133_states.bin.z b/client/resources/hardnested_tables/bitflip_0_133_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_133_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_133_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_135_states.bin.z b/client/resources/hardnested_tables/bitflip_0_135_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_135_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_135_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_137_states.bin.z b/client/resources/hardnested_tables/bitflip_0_137_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_137_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_137_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_139_states.bin.z b/client/resources/hardnested_tables/bitflip_0_139_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_139_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_139_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_13b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_13b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_13b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_13b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_13d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_13d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_13d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_13d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_13f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_13f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_13f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_13f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_141_states.bin.z b/client/resources/hardnested_tables/bitflip_0_141_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_141_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_141_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_143_states.bin.z b/client/resources/hardnested_tables/bitflip_0_143_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_143_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_143_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_145_states.bin.z b/client/resources/hardnested_tables/bitflip_0_145_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_145_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_145_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_147_states.bin.z b/client/resources/hardnested_tables/bitflip_0_147_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_147_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_147_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_149_states.bin.z b/client/resources/hardnested_tables/bitflip_0_149_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_149_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_149_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_14b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_14b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_14b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_14b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_14d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_14d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_14d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_14d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_14f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_14f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_14f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_14f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_150_states.bin.z b/client/resources/hardnested_tables/bitflip_0_150_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_150_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_150_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_154_states.bin.z b/client/resources/hardnested_tables/bitflip_0_154_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_154_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_154_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_15c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_15c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_15c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_15c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_161_states.bin.z b/client/resources/hardnested_tables/bitflip_0_161_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_161_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_161_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_163_states.bin.z b/client/resources/hardnested_tables/bitflip_0_163_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_163_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_163_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_165_states.bin.z b/client/resources/hardnested_tables/bitflip_0_165_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_165_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_165_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_167_states.bin.z b/client/resources/hardnested_tables/bitflip_0_167_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_167_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_167_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_169_states.bin.z b/client/resources/hardnested_tables/bitflip_0_169_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_169_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_169_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_16b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_16b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_16b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_16b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_16d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_16d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_16d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_16d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_16f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_16f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_16f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_16f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_170_states.bin.z b/client/resources/hardnested_tables/bitflip_0_170_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_170_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_170_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_174_states.bin.z b/client/resources/hardnested_tables/bitflip_0_174_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_174_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_174_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_17c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_17c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_17c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_17c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_184_states.bin.z b/client/resources/hardnested_tables/bitflip_0_184_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_184_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_184_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_18c_states.bin.z b/client/resources/hardnested_tables/bitflip_0_18c_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_18c_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_18c_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_191_states.bin.z b/client/resources/hardnested_tables/bitflip_0_191_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_191_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_191_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_193_states.bin.z b/client/resources/hardnested_tables/bitflip_0_193_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_193_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_193_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_195_states.bin.z b/client/resources/hardnested_tables/bitflip_0_195_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_195_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_195_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_197_states.bin.z b/client/resources/hardnested_tables/bitflip_0_197_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_197_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_197_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_199_states.bin.z b/client/resources/hardnested_tables/bitflip_0_199_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_199_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_199_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_19b_states.bin.z b/client/resources/hardnested_tables/bitflip_0_19b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_19b_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_19b_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_19d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_19d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_19d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_19d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_19f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_19f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_19f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_19f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1a4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1a4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1a4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1a4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1ac_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1ac_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1ac_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1ac_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1b1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1b1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1b1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1b1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1b3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1b3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1b3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1b3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1b5_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1b5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1b5_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1b5_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1b7_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1b7_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1b7_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1b7_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1b9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1b9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1b9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1b9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1bb_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1bb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1bb_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1bb_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1bd_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1bd_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1bd_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1bd_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1bf_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1bf_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1bf_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1bf_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1c1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1c1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1c1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1c1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1c3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1c3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1c3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1c3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1c5_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1c5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1c5_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1c5_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1c9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1c9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1c9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1c9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1cb_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1cb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1cb_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1cb_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1d0_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1d0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1d0_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1d0_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1d4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1d4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1d4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1d4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1dc_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1dc_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1dc_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1dc_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1e1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1e1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1e1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1e1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1e3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1e3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1e3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1e3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1e5_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1e5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1e5_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1e5_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1e7_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1e7_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1e7_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1e7_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1e9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1e9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1e9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1e9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1eb_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1eb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1eb_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1eb_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1ed_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1ed_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1ed_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1ed_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1ef_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1ef_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1ef_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1ef_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1f0_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1f0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1f0_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1f0_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1f4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1f4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1f4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1f4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_1fc_states.bin.z b/client/resources/hardnested_tables/bitflip_0_1fc_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_1fc_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_1fc_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_210_states.bin.z b/client/resources/hardnested_tables/bitflip_0_210_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_210_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_210_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_225_states.bin.z b/client/resources/hardnested_tables/bitflip_0_225_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_225_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_225_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_227_states.bin.z b/client/resources/hardnested_tables/bitflip_0_227_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_227_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_227_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_22d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_22d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_22d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_22d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_22f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_22f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_22f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_22f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_240_states.bin.z b/client/resources/hardnested_tables/bitflip_0_240_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_240_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_240_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_275_states.bin.z b/client/resources/hardnested_tables/bitflip_0_275_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_275_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_275_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_277_states.bin.z b/client/resources/hardnested_tables/bitflip_0_277_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_277_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_277_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_27f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_27f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_27f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_27f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_294_states.bin.z b/client/resources/hardnested_tables/bitflip_0_294_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_294_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_294_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2a1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2a1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2a1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2a1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2a3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2a3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2a3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2a3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2a9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2a9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2a9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2a9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2ab_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2ab_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2ab_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2ab_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2c4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2c4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2c4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2c4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2f1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2f1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2f1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2f1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2f3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2f3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2f3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2f3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2f9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2f9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2f9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2f9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_2fb_states.bin.z b/client/resources/hardnested_tables/bitflip_0_2fb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_2fb_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_2fb_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_335_states.bin.z b/client/resources/hardnested_tables/bitflip_0_335_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_335_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_335_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_337_states.bin.z b/client/resources/hardnested_tables/bitflip_0_337_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_337_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_337_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_33d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_33d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_33d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_33d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_33f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_33f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_33f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_33f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_350_states.bin.z b/client/resources/hardnested_tables/bitflip_0_350_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_350_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_350_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_365_states.bin.z b/client/resources/hardnested_tables/bitflip_0_365_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_365_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_365_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_367_states.bin.z b/client/resources/hardnested_tables/bitflip_0_367_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_367_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_367_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_36d_states.bin.z b/client/resources/hardnested_tables/bitflip_0_36d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_36d_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_36d_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_36f_states.bin.z b/client/resources/hardnested_tables/bitflip_0_36f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_36f_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_36f_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_384_states.bin.z b/client/resources/hardnested_tables/bitflip_0_384_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_384_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_384_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3b1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3b1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3b1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3b1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3b3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3b3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3b3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3b3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3b9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3b9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3b9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3b9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3bb_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3bb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3bb_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3bb_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3d4_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3d4_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3d4_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3d4_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3e1_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3e1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3e1_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3e1_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3e3_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3e3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3e3_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3e3_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3e9_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3e9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3e9_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3e9_states.bin.z diff --git a/client/hardnested/tables/bitflip_0_3eb_states.bin.z b/client/resources/hardnested_tables/bitflip_0_3eb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_0_3eb_states.bin.z rename to client/resources/hardnested_tables/bitflip_0_3eb_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_002_states.bin.z b/client/resources/hardnested_tables/bitflip_1_002_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_002_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_002_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_008_states.bin.z b/client/resources/hardnested_tables/bitflip_1_008_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_008_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_008_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_00a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_00a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_00a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_00a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_012_states.bin.z b/client/resources/hardnested_tables/bitflip_1_012_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_012_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_012_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_018_states.bin.z b/client/resources/hardnested_tables/bitflip_1_018_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_018_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_018_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_01a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_01a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_01a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_01a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_020_states.bin.z b/client/resources/hardnested_tables/bitflip_1_020_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_020_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_020_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_028_states.bin.z b/client/resources/hardnested_tables/bitflip_1_028_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_028_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_028_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_02a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_02a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_02a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_02a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_02e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_02e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_02e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_02e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_032_states.bin.z b/client/resources/hardnested_tables/bitflip_1_032_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_032_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_032_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_036_states.bin.z b/client/resources/hardnested_tables/bitflip_1_036_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_036_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_036_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_038_states.bin.z b/client/resources/hardnested_tables/bitflip_1_038_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_038_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_038_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_03a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_03a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_03a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_03a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_03e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_03e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_03e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_03e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_040_states.bin.z b/client/resources/hardnested_tables/bitflip_1_040_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_040_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_040_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_042_states.bin.z b/client/resources/hardnested_tables/bitflip_1_042_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_042_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_042_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_046_states.bin.z b/client/resources/hardnested_tables/bitflip_1_046_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_046_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_046_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_048_states.bin.z b/client/resources/hardnested_tables/bitflip_1_048_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_048_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_048_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_04a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_04a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_04a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_04a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_04e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_04e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_04e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_04e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_052_states.bin.z b/client/resources/hardnested_tables/bitflip_1_052_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_052_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_052_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_056_states.bin.z b/client/resources/hardnested_tables/bitflip_1_056_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_056_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_056_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_058_states.bin.z b/client/resources/hardnested_tables/bitflip_1_058_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_058_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_058_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_05a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_05a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_05a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_05a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_05e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_05e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_05e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_05e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_060_states.bin.z b/client/resources/hardnested_tables/bitflip_1_060_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_060_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_060_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_062_states.bin.z b/client/resources/hardnested_tables/bitflip_1_062_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_062_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_062_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_066_states.bin.z b/client/resources/hardnested_tables/bitflip_1_066_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_066_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_066_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_068_states.bin.z b/client/resources/hardnested_tables/bitflip_1_068_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_068_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_068_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_06a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_06a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_06a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_06a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_06e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_06e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_06e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_06e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_072_states.bin.z b/client/resources/hardnested_tables/bitflip_1_072_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_072_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_072_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_076_states.bin.z b/client/resources/hardnested_tables/bitflip_1_076_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_076_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_076_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_078_states.bin.z b/client/resources/hardnested_tables/bitflip_1_078_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_078_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_078_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_07a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_07a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_07a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_07a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_07e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_07e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_07e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_07e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_080_states.bin.z b/client/resources/hardnested_tables/bitflip_1_080_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_080_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_080_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_082_states.bin.z b/client/resources/hardnested_tables/bitflip_1_082_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_082_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_082_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_086_states.bin.z b/client/resources/hardnested_tables/bitflip_1_086_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_086_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_086_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_088_states.bin.z b/client/resources/hardnested_tables/bitflip_1_088_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_088_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_088_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_08a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_08a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_08a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_08a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_08e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_08e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_08e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_08e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_092_states.bin.z b/client/resources/hardnested_tables/bitflip_1_092_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_092_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_092_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_096_states.bin.z b/client/resources/hardnested_tables/bitflip_1_096_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_096_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_096_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_098_states.bin.z b/client/resources/hardnested_tables/bitflip_1_098_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_098_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_098_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_09a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_09a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_09a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_09a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_09e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_09e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_09e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_09e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0a0_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0a0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0a0_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0a0_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0a2_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0a2_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0a2_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0a2_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0a6_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0a6_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0a6_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0a6_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0a8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0a8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0a8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0a8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0aa_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0aa_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0aa_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0aa_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0ae_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0ae_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0ae_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0ae_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0b2_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0b2_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0b2_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0b2_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0b6_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0b6_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0b6_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0b6_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0b8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0b8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0b8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0b8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0ba_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0ba_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0ba_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0ba_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0be_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0be_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0be_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0be_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0c0_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0c0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0c0_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0c0_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0c2_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0c2_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0c2_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0c2_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0c6_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0c6_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0c6_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0c6_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0c8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0c8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0c8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0c8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0ca_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0ca_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0ca_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0ca_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0ce_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0ce_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0ce_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0ce_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0d2_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0d2_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0d2_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0d2_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0d6_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0d6_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0d6_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0d6_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0d8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0d8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0d8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0d8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0da_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0da_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0da_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0da_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0de_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0de_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0de_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0de_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0e0_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0e0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0e0_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0e0_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0e8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0e8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0e8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0e8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_0f8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_0f8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_0f8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_0f8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_108_states.bin.z b/client/resources/hardnested_tables/bitflip_1_108_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_108_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_108_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_111_states.bin.z b/client/resources/hardnested_tables/bitflip_1_111_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_111_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_111_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_113_states.bin.z b/client/resources/hardnested_tables/bitflip_1_113_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_113_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_113_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_115_states.bin.z b/client/resources/hardnested_tables/bitflip_1_115_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_115_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_115_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_117_states.bin.z b/client/resources/hardnested_tables/bitflip_1_117_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_117_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_117_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_118_states.bin.z b/client/resources/hardnested_tables/bitflip_1_118_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_118_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_118_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_11a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_11a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_11a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_11a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_11b_states.bin.z b/client/resources/hardnested_tables/bitflip_1_11b_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_11b_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_11b_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_120_states.bin.z b/client/resources/hardnested_tables/bitflip_1_120_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_120_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_120_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_122_states.bin.z b/client/resources/hardnested_tables/bitflip_1_122_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_122_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_122_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_128_states.bin.z b/client/resources/hardnested_tables/bitflip_1_128_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_128_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_128_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_131_states.bin.z b/client/resources/hardnested_tables/bitflip_1_131_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_131_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_131_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_135_states.bin.z b/client/resources/hardnested_tables/bitflip_1_135_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_135_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_135_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_138_states.bin.z b/client/resources/hardnested_tables/bitflip_1_138_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_138_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_138_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_145_states.bin.z b/client/resources/hardnested_tables/bitflip_1_145_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_145_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_145_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_147_states.bin.z b/client/resources/hardnested_tables/bitflip_1_147_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_147_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_147_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_148_states.bin.z b/client/resources/hardnested_tables/bitflip_1_148_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_148_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_148_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_158_states.bin.z b/client/resources/hardnested_tables/bitflip_1_158_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_158_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_158_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_160_states.bin.z b/client/resources/hardnested_tables/bitflip_1_160_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_160_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_160_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_161_states.bin.z b/client/resources/hardnested_tables/bitflip_1_161_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_161_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_161_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_163_states.bin.z b/client/resources/hardnested_tables/bitflip_1_163_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_163_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_163_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_165_states.bin.z b/client/resources/hardnested_tables/bitflip_1_165_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_165_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_165_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_168_states.bin.z b/client/resources/hardnested_tables/bitflip_1_168_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_168_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_168_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_178_states.bin.z b/client/resources/hardnested_tables/bitflip_1_178_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_178_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_178_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_180_states.bin.z b/client/resources/hardnested_tables/bitflip_1_180_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_180_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_180_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_188_states.bin.z b/client/resources/hardnested_tables/bitflip_1_188_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_188_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_188_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_191_states.bin.z b/client/resources/hardnested_tables/bitflip_1_191_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_191_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_191_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_198_states.bin.z b/client/resources/hardnested_tables/bitflip_1_198_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_198_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_198_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_199_states.bin.z b/client/resources/hardnested_tables/bitflip_1_199_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_199_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_199_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_19d_states.bin.z b/client/resources/hardnested_tables/bitflip_1_19d_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_19d_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_19d_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_19f_states.bin.z b/client/resources/hardnested_tables/bitflip_1_19f_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_19f_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_19f_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1a0_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1a0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1a0_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1a0_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1a8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1a8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1a8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1a8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1b3_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1b3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1b3_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1b3_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1b5_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1b5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1b5_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1b5_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1b7_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1b7_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1b7_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1b7_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1b8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1b8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1b8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1b8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1b9_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1b9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1b9_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1b9_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1bd_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1bd_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1bd_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1bd_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1c1_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1c1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1c1_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1c1_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1c3_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1c3_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1c3_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1c3_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1c8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1c8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1c8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1c8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1c9_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1c9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1c9_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1c9_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1cd_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1cd_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1cd_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1cd_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1cf_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1cf_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1cf_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1cf_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1d8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1d8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1d8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1d8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1e0_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1e0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1e0_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1e0_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1e1_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1e1_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1e1_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1e1_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1e5_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1e5_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1e5_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1e5_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1e7_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1e7_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1e7_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1e7_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1e8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1e8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1e8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1e8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1e9_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1e9_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1e9_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1e9_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1eb_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1eb_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1eb_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1eb_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1ed_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1ed_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1ed_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1ed_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_1f8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_1f8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_1f8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_1f8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_208_states.bin.z b/client/resources/hardnested_tables/bitflip_1_208_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_208_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_208_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_220_states.bin.z b/client/resources/hardnested_tables/bitflip_1_220_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_220_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_220_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_24a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_24a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_24a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_24a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_24e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_24e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_24e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_24e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_25a_states.bin.z b/client/resources/hardnested_tables/bitflip_1_25a_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_25a_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_25a_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_25e_states.bin.z b/client/resources/hardnested_tables/bitflip_1_25e_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_25e_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_25e_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_262_states.bin.z b/client/resources/hardnested_tables/bitflip_1_262_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_262_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_262_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_266_states.bin.z b/client/resources/hardnested_tables/bitflip_1_266_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_266_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_266_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_272_states.bin.z b/client/resources/hardnested_tables/bitflip_1_272_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_272_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_272_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_276_states.bin.z b/client/resources/hardnested_tables/bitflip_1_276_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_276_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_276_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_280_states.bin.z b/client/resources/hardnested_tables/bitflip_1_280_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_280_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_280_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_2a8_states.bin.z b/client/resources/hardnested_tables/bitflip_1_2a8_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_2a8_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_2a8_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_2c2_states.bin.z b/client/resources/hardnested_tables/bitflip_1_2c2_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_2c2_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_2c2_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_2c6_states.bin.z b/client/resources/hardnested_tables/bitflip_1_2c6_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_2c6_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_2c6_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_2d2_states.bin.z b/client/resources/hardnested_tables/bitflip_1_2d2_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_2d2_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_2d2_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_2d6_states.bin.z b/client/resources/hardnested_tables/bitflip_1_2d6_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_2d6_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_2d6_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_328_states.bin.z b/client/resources/hardnested_tables/bitflip_1_328_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_328_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_328_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_388_states.bin.z b/client/resources/hardnested_tables/bitflip_1_388_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_388_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_388_states.bin.z diff --git a/client/hardnested/tables/bitflip_1_3a0_states.bin.z b/client/resources/hardnested_tables/bitflip_1_3a0_states.bin.z similarity index 100% rename from client/hardnested/tables/bitflip_1_3a0_states.bin.z rename to client/resources/hardnested_tables/bitflip_1_3a0_states.bin.z From a78839a644fbc509742974efeef068548f8570d5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 10:28:56 +0200 Subject: [PATCH 195/347] make os -> make fullimage --- Makefile | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 9be67311b..52793c104 100644 --- a/Makefile +++ b/Makefile @@ -58,29 +58,30 @@ recovery/%: FORCE cleanifplatformchanged bootrom/% armsrc/% $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) -.PHONY: all clean help _test bootrom flash-bootrom os flash-os flash-all recovery client mfkey nonce2key style checks FORCE udev accessrights cleanifplatformchanged +.PHONY: all clean help _test bootrom flash-bootrom fullimage flash-fullimage flash-all recovery client mfkey nonce2key style checks FORCE udev accessrights cleanifplatformchanged help: @echo "Multi-OS Makefile" @echo @echo "Possible targets:" - @echo "+ all - Make all targets: bootrom, armsrc and OS-specific host tools" - @echo "+ clean - Clean in all targets" + @echo "+ all - Make all targets: bootrom, fullimage and OS-specific host tools" + @echo "+ clean - Clean in all targets" + @echo "+ .../clean - Clean in specified target and its deps, e.g. bootrom/clean" @echo - @echo "+ bootrom - Make bootrom" - @echo "+ os - Make armsrc (includes fpga)" - @echo "+ flash-bootrom - Make bootrom and flash it" - @echo "+ flash-os - Make armsrc and flash os image (includes fpga)" - @echo "+ flash-all - Make bootrom and armsrc and flash bootrom and os image" - @echo "+ recovery - Make bootrom and armsrc images for JTAG flashing" + @echo "+ bootrom - Make bootrom" + @echo "+ fullimage - Make armsrc fullimage (includes fpga)" + @echo "+ flash-bootrom - Make and flash bootrom" + @echo "+ flash-fullimage - Make and flash fullimage" + @echo "+ flash-all - Make and flash bootrom and fullimage" + @echo "+ recovery - Make bootrom and fullimage files for JTAG flashing" @echo - @echo "+ client - Make only the OS-specific host client" - @echo "+ mfkey - Make tools/mfkey" - @echo "+ nonce2key - Make tools/nonce2key" - @echo "+ fpga_compress - Make tools/fpga_compress" + @echo "+ client - Make only the OS-specific host client" + @echo "+ mfkey - Make tools/mfkey" + @echo "+ nonce2key - Make tools/nonce2key" + @echo "+ fpga_compress - Make tools/fpga_compress" @echo - @echo "+ style - Apply some automated source code formatting rules" - @echo "+ checks - Detect various encoding issues in source code" + @echo "+ style - Apply some automated source code formatting rules" + @echo "+ checks - Detect various encoding issues in source code" @echo @echo "Possible platforms: try \"make PLATFORM=\" for more info, default is PM3RDV4" @echo "To activate verbose mode, use make V=1" @@ -89,7 +90,9 @@ client: client/all bootrom: bootrom/all -os: armsrc/all +fullimage: armsrc/all + +fullimage/clean: armsrc/clean recovery: recovery/all @@ -102,7 +105,7 @@ fpga_compress: fpga_compress/all flash-bootrom: bootrom/obj/bootrom.elf $(FLASH_TOOL) $(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$<) -flash-os: armsrc/obj/fullimage.elf $(FLASH_TOOL) +flash-fullimage: armsrc/obj/fullimage.elf $(FLASH_TOOL) $(FLASH_TOOL) $(FLASH_PORT) $(subst /,$(PATHSEP),$<) flash-all: bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf $(FLASH_TOOL) From b5e1408e4cc125f83ff25ecc75d56beb3f7d598f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 10:35:41 +0200 Subject: [PATCH 196/347] fix pm3test.sh --- pm3test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pm3test.sh b/pm3test.sh index 119fffbb8..8785bf8df 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -80,7 +80,7 @@ while true; do if ! CheckFileExist "proxmark3 exists" "./client/proxmark3"; then break; fi if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi if ! CheckFileExist "bootrom exists" "./bootrom/obj/bootrom.elf"; then break; fi - if ! CheckFileExist "hardnested tables exists" "./client/hardnested/tables/*.z"; then break; fi + if ! CheckFileExist "hardnested tables exists" "./client/resources/hardnested_tables/*.z"; then break; fi printf "\n${C_BLUE}Testing basic help:${C_NC}\n" if ! CheckExecute "proxmark help" "./client/proxmark3 -h" "wait"; then break; fi From 99159b3cda735fa510eac4cf6d5639fad9f5fc6e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 10:40:02 +0200 Subject: [PATCH 197/347] remove makefile flash targets, better to use provided scripts or direct calls to flasher --- Makefile | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 52793c104..7ca9e313f 100644 --- a/Makefile +++ b/Makefile @@ -5,30 +5,6 @@ endif # To see full command lines, use make V=1 GZIP=gzip -# Windows' echo echos its input verbatim, on Posix there is some -# amount of shell command line parsing going on. echo "" on -# Windows yields literal "", on Linux yields an empty line -ifeq ($(shell echo ""),) - # This is probably a proper system, so we can use uname - DELETE=rm -rf - FLASH_TOOL=client/flasher - platform=$(shell uname) - ifneq (,$(findstring MINGW,$(platform))) - FLASH_PORT=com3 - PATHSEP=\\# - else - FLASH_PORT=/dev/ttyACM0 - PATHSEP=/ - endif -else - # Assume that we are running on native Windows - DELETE=del /q - FLASH_TOOL=client/flasher.exe - platform=Windows - FLASH_PORT=com3 - PATHSEP=\\# -endif - -include Makefile.platform -include .Makefile.options.cache include common_arm/Makefile.hal @@ -58,7 +34,7 @@ recovery/%: FORCE cleanifplatformchanged bootrom/% armsrc/% $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) -.PHONY: all clean help _test bootrom flash-bootrom fullimage flash-fullimage flash-all recovery client mfkey nonce2key style checks FORCE udev accessrights cleanifplatformchanged +.PHONY: all clean help _test bootrom fullimage recovery client mfkey nonce2key style checks FORCE udev accessrights cleanifplatformchanged help: @echo "Multi-OS Makefile" @@ -70,9 +46,6 @@ help: @echo @echo "+ bootrom - Make bootrom" @echo "+ fullimage - Make armsrc fullimage (includes fpga)" - @echo "+ flash-bootrom - Make and flash bootrom" - @echo "+ flash-fullimage - Make and flash fullimage" - @echo "+ flash-all - Make and flash bootrom and fullimage" @echo "+ recovery - Make bootrom and fullimage files for JTAG flashing" @echo @echo "+ client - Make only the OS-specific host client" @@ -102,15 +75,6 @@ nonce2key: nonce2key/all fpga_compress: fpga_compress/all -flash-bootrom: bootrom/obj/bootrom.elf $(FLASH_TOOL) - $(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$<) - -flash-fullimage: armsrc/obj/fullimage.elf $(FLASH_TOOL) - $(FLASH_TOOL) $(FLASH_PORT) $(subst /,$(PATHSEP),$<) - -flash-all: bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf $(FLASH_TOOL) - $(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$(filter-out $(FLASH_TOOL),$^)) - newtarbin: $(DELETE) proxmark3-$(platform)-bin.tar proxmark3-$(platform)-bin.tar.gz @touch proxmark3-$(platform)-bin.tar From 2022df10680cd245ae27a711402e8571679b373a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 10:45:52 +0200 Subject: [PATCH 198/347] make style --- armsrc/appmain.c | 2 +- armsrc/iclass.c | 18 ++--- armsrc/mifarecmd.c | 78 +++++++++--------- client/cmdhficlass.c | 92 +++++++++++----------- client/cmdhfmf.c | 148 +++++++++++++++++------------------ client/cmdlft55xx.c | 4 +- client/fileutils.c | 25 +++--- client/loclass/elite_crack.c | 2 +- client/loclass/ikeys.c | 14 ++-- client/mifare/mifarehost.c | 2 +- client/ui.c | 6 +- include/pm3_cmd.h | 6 +- 12 files changed, 199 insertions(+), 198 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 13aa6bc84..c789f6aac 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1134,7 +1134,7 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_MIFARE_EML_LOAD: { - mfc_eload_t *payload = (mfc_eload_t *) packet->data.asBytes; + mfc_eload_t *payload = (mfc_eload_t *) packet->data.asBytes; MifareECardLoadExt(payload->sectorcnt, payload->keytype); break; } diff --git a/armsrc/iclass.c b/armsrc/iclass.c index b550158cc..b63c696d6 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -59,7 +59,7 @@ static int g_wait = 300; static int timeout = 2900; static uint32_t time_rdr = 0; static uint32_t time_delta = 0; -static uint32_t time_delta_wait = 0; +static uint32_t time_delta_wait = 0; static uint32_t time_response = 0; static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay); @@ -1875,15 +1875,15 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, } // keep tx buffer in a defined state anyway. -/* - if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { - AT91C_BASE_SSC->SSC_THR = 0x00; - } -*/ + /* + if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { + AT91C_BASE_SSC->SSC_THR = 0x00; + } + */ // Wait for byte be become available in rx holding register if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { - if ( GetCountSspClk() - foo > timeout) return false; + if (GetCountSspClk() - foo > timeout) return false; // if (c >= timeout) return false; c++; @@ -1896,7 +1896,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, if (ManchesterDecoding_iclass(b & 0x0f)) { if (samples) *samples = c << 3; - + time_response = GetCountSspClk() - foo; return true; } @@ -1959,7 +1959,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re // since its called with fixed sized arrays // update/write commadn takes 4ms to 15ms before responding - if ( command[0] == ICLASS_CMD_UPDATE ) + if (command[0] == ICLASS_CMD_UPDATE) g_wait = 15000; uint8_t got_n = ReaderReceiveIClass(resp); diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 17570e680..e8263d52a 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1523,33 +1523,33 @@ OUT: FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); BigBuf_free(); BigBuf_Clear_ext(false); - - // special trick ecfill - if (use_flashmem && foundkeys == allkeys) { - - uint8_t block[16] = {0}; - for (int i = 0; i < sectorcnt; i++) { - - uint8_t blockno; - if (i < 32) { - blockno = (i * 4) ^ 0x3; - } else { - blockno = (32 * 4 + (i - 32) * 16) ^ 0xF; - } - // get ST - emlGetMem(block, blockno, 1); - memcpy(block, k_sector[i].keyA, 6); - memcpy(block + 10, k_sector[i].keyB, 6); - - emlSetMem_xt(block, blockno, 1, sizeof(block)); - } - int oldbg = DBGLEVEL; - DBGLEVEL = DBG_NONE; - MifareECardLoad(sectorcnt, 0); - MifareECardLoad(sectorcnt, 1); - DBGLEVEL = oldbg; - } + // special trick ecfill + if (use_flashmem && foundkeys == allkeys) { + + uint8_t block[16] = {0}; + for (int i = 0; i < sectorcnt; i++) { + + uint8_t blockno; + if (i < 32) { + blockno = (i * 4) ^ 0x3; + } else { + blockno = (32 * 4 + (i - 32) * 16) ^ 0xF; + } + // get ST + emlGetMem(block, blockno, 1); + + memcpy(block, k_sector[i].keyA, 6); + memcpy(block + 10, k_sector[i].keyB, 6); + + emlSetMem_xt(block, blockno, 1, sizeof(block)); + } + int oldbg = DBGLEVEL; + DBGLEVEL = DBG_NONE; + MifareECardLoad(sectorcnt, 0); + MifareECardLoad(sectorcnt, 1); + DBGLEVEL = oldbg; + } } else { // partial/none keys found reply_mix(CMD_ACK, foundkeys, 0, 0, 0, 0); @@ -1695,9 +1695,9 @@ void MifareEMemGet(uint8_t blockno, uint8_t blockcnt) { // //----------------------------------------------------------------------------- int MifareECardLoadExt(uint8_t numSectors, uint8_t keyType) { - int retval = MifareECardLoad(numSectors, keyType); - reply_ng(CMD_HF_MIFARE_EML_LOAD, retval, NULL, 0); - return retval; + int retval = MifareECardLoad(numSectors, keyType); + reply_ng(CMD_HF_MIFARE_EML_LOAD, retval, NULL, 0); + return retval; } int MifareECardLoad(uint8_t numSectors, uint8_t keyType) { @@ -1723,7 +1723,7 @@ int MifareECardLoad(uint8_t numSectors, uint8_t keyType) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { retval = PM3_ESOFT; if (DBGLEVEL > DBG_ERROR) Dbprintf("Can't select card"); - goto out; + goto out; } for (uint8_t sectorNo = 0; sectorNo < numSectors; sectorNo++) { @@ -1747,22 +1747,22 @@ int MifareECardLoad(uint8_t numSectors, uint8_t keyType) { if (DBGLEVEL > DBG_ERROR) Dbprintf("Error reading sector %2d block %2d", sectorNo, blockNo); break; } - if (blockNo < NumBlocksPerSector(sectorNo) - 1) { - emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1); - } else { // sector trailer, keep the keys, set only the AC - emlGetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1); - memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4); - emlSetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1); - } + if (blockNo < NumBlocksPerSector(sectorNo) - 1) { + emlSetMem(dataoutbuf, FirstBlockOfSector(sectorNo) + blockNo, 1); + } else { // sector trailer, keep the keys, set only the AC + emlGetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1); + memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4); + emlSetMem(dataoutbuf2, FirstBlockOfSector(sectorNo) + blockNo, 1); } } + } if (mifare_classic_halt(pcs, cuid)) { if (DBGLEVEL > DBG_ERROR) Dbprintf("Halt error"); - } + } - if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished"); + if (DBGLEVEL >= DBG_INFO) DbpString("Emulator fill sectors finished"); out: crypto1_destroy(pcs); diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index f5406e8e7..39fbf9658 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -696,7 +696,7 @@ static int CmdHFiClassELoad(const char *Cmd) { return usage_hf_iclass_eload(); case 'f': if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { - PrintAndLogEx(FAILED, "Filename too long"); + PrintAndLogEx(FAILED, "Filename too long"); errors = true; break; } @@ -704,12 +704,12 @@ static int CmdHFiClassELoad(const char *Cmd) { break; case 'j': dftype = JSON; - cmdp++; - break; + cmdp++; + break; case 'e': - dftype = EML; - cmdp++; - break; + dftype = EML; + cmdp++; + break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); errors = true; @@ -733,9 +733,9 @@ static int CmdHFiClassELoad(const char *Cmd) { size_t bytes_read = 2048; int res = 0; - switch ( dftype ) { + switch (dftype) { case BIN: { - res = loadFile(filename, ".bin", (void*)&dump, 2048, &bytes_read); + res = loadFile(filename, ".bin", (void *)&dump, 2048, &bytes_read); break; } case EML: { @@ -747,11 +747,11 @@ static int CmdHFiClassELoad(const char *Cmd) { break; } default: - PrintAndLogEx(ERR, "No dictionary loaded"); - return PM3_ESOFT; + PrintAndLogEx(ERR, "No dictionary loaded"); + return PM3_ESOFT; } - if ( res != PM3_SUCCESS ) { + if (res != PM3_SUCCESS) { free(dump); return PM3_EFILE; } @@ -793,15 +793,15 @@ static int CmdHFiClassELoad(const char *Cmd) { #define ICLASS_DECRYPTION_BIN "iclass_decryptionkey.bin" static int CmdHFiClassDecrypt(const char *Cmd) { - + bool errors = false; bool have_key = false; uint8_t cmdp = 0; - + size_t keylen = 0; uint8_t key[32] = {0}; uint8_t *keyptr = NULL; - + size_t decryptedlen = 0; uint8_t *decrypted = NULL; char filename[FILE_PATH_SIZE]; @@ -811,13 +811,13 @@ static int CmdHFiClassDecrypt(const char *Cmd) { case 'h': return usage_hf_iclass_decrypt(); case 'f': - if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename) ) == 0) { + if (param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) == 0) { PrintAndLogEx(WARNING, "no filename found after f"); errors = true; break; } - if ( loadFile_safe(filename, "", (void**)&decrypted, &decryptedlen) != PM3_SUCCESS ) { + if (loadFile_safe(filename, "", (void **)&decrypted, &decryptedlen) != PM3_SUCCESS) { errors = true; break; } @@ -840,11 +840,11 @@ static int CmdHFiClassDecrypt(const char *Cmd) { if (errors || cmdp < 1) return usage_hf_iclass_decrypt(); - if ( have_key == false ) { - int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void**)&keyptr, &keylen); + if (have_key == false) { + int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); if (res != PM3_SUCCESS) return PM3_EINVARG; - + memcpy(key, keyptr, sizeof(key)); } @@ -857,7 +857,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { uint8_t app_areas = 2; uint8_t max_blk = 31; getMemConfig(mem, chip, &max_blk, &app_areas, &kb); - + // tripledes mbedtls_des3_context ctx; mbedtls_des3_set2key_dec(&ctx, key); @@ -876,10 +876,10 @@ static int CmdHFiClassDecrypt(const char *Cmd) { } //Use the first block (CSN) for filename - char *fptr = calloc(42, sizeof(uint8_t)); + char *fptr = calloc(42, sizeof(uint8_t)); strcat(fptr, "hf-iclass-"); - FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn) ); - + FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn)); + saveFile(fptr, ".bin", decrypted, decryptedlen); saveFileEML(fptr, decrypted, decryptedlen, 8); saveFileJSON(fptr, jsfIclass, decrypted, decryptedlen); @@ -935,12 +935,12 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { if (errors || cmdp < 1) return usage_hf_iclass_encrypt(); - if ( have_key == false ) { + if (have_key == false) { size_t keylen = 0; - int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void**)&keyptr, &keylen); + int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); if (res != PM3_SUCCESS) return PM3_EINVARG; - + memcpy(key, keyptr, sizeof(key)); } @@ -1265,7 +1265,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { //Use the first block (CSN) for filename strcat(filename, "hf-iclass-"); - FillFileNameByUID(filename, tag_data, "-data", 8 ); + FillFileNameByUID(filename, tag_data, "-data", 8); } // save the dump to .bin file @@ -1565,7 +1565,7 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, } //data read is stored in: resp.data.asBytes[0-15] PrintAndLogEx(NORMAL, "block %02X: %s\n", blockno, sprint_hex(resp.data.asBytes, 8)); - // should decrypt it if file is accessable. + // should decrypt it if file is accessable. return 1; } @@ -1936,9 +1936,9 @@ static int saveKeys(char *filename) { static int printKeys(void) { PrintAndLogEx(NORMAL, ""); for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) { - if ( memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) + if (memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) PrintAndLogEx(NORMAL, "%u: %s", i, sprint_hex(iClass_Key_Table[i], 8)); - else + else PrintAndLogEx(NORMAL, "%u: "_YELLOW_("%s"), i, sprint_hex(iClass_Key_Table[i], 8)); } PrintAndLogEx(NORMAL, ""); @@ -2096,7 +2096,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { uint16_t keycount = 0; // load keys - int res = loadFileDICTIONARY_safe(filename, (void**)&keyBlock, 8, &keycount); + int res = loadFileDICTIONARY_safe(filename, (void **)&keyBlock, 8, &keycount); if (res != PM3_SUCCESS || keycount == 0) { free(keyBlock); return res; @@ -2106,11 +2106,11 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { PrintAndLogEx(SUCCESS, "Reading tag CSN"); for (uint8_t i = 0; i < 10 && !got_csn; i++) { got_csn = select_only(CSN, CCNR, false, false); - if ( got_csn == false ) + if (got_csn == false) PrintAndLogEx(WARNING, "one more try\n"); - } + } - if ( got_csn == false ) { + if (got_csn == false) { PrintAndLogEx(WARNING, "Tried 10 times. Can't select card, aborting..."); return PM3_ESOFT; } @@ -2232,13 +2232,13 @@ out: PrintAndLogEx(SUCCESS, "\nTime in iclass checkkeys: %.0f seconds\n", (float)t1 / 1000.0); DropField(); - // add to managekeys - if ( found_debit ) { - for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) { + // add to managekeys + if (found_debit) { + for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) { // simple check for preexistences - if ( memcmp(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8) == 0 ) break; + if (memcmp(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8) == 0) break; - if ( memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) { + if (memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) { memcpy(iClass_Key_Table[i], keyBlock + (key_offset + found_offset) * 8, 8); PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")" to view", i); break; @@ -2295,7 +2295,7 @@ static int CmdHFiClassLookUp(const char *Cmd) { case 'h': return usage_hf_iclass_lookup(); case 'f': - if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) < 1 ) { + if (param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) < 1) { PrintAndLogEx(WARNING, "No filename found after f"); errors = true; } @@ -2358,12 +2358,12 @@ static int CmdHFiClassLookUp(const char *Cmd) { uint16_t keycount = 0; // load keys - int res = loadFileDICTIONARY_safe(filename, (void**)&keyBlock, 8, &keycount); + int res = loadFileDICTIONARY_safe(filename, (void **)&keyBlock, 8, &keycount); if (res != PM3_SUCCESS || keycount == 0) { free(keyBlock); return res; } - + //iclass_prekey_t prekey = calloc(keycount, sizeof(iclass_prekey_t)); if (!prekey) { @@ -2395,18 +2395,18 @@ static int CmdHFiClassLookUp(const char *Cmd) { // foudn if (item != NULL) { PrintAndLogEx(SUCCESS, "[debit] found key " _YELLOW_("%s"), sprint_hex(item->key, 8)); - for (uint8_t i=0; i< ICLASS_KEYS_MAX; i++) { + for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++) { // simple check for preexistences - if ( memcmp(item->key, iClass_Key_Table[i], 8) == 0 ) break; + if (memcmp(item->key, iClass_Key_Table[i], 8) == 0) break; - if ( memcmp(iClass_Key_Table[i] , "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0 ) { + if (memcmp(iClass_Key_Table[i], "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) { memcpy(iClass_Key_Table[i], item->key, 8); PrintAndLogEx(SUCCESS, "Added key to keyslot [%d] - "_YELLOW_("`hf iclass managekeys p`")"to view", i); break; } } } - + free(prekey); free(keyBlock); PrintAndLogEx(NORMAL, ""); diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 538ec0569..be05d85d2 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -774,31 +774,31 @@ static char GetFormatFromSector(uint8_t sectorNo) { } } -static int FastDumpWithEcFill(uint8_t numsectors){ - PacketResponseNG resp; - - mfc_eload_t payload; - payload.sectorcnt = numsectors; - payload.keytype = 0; +static int FastDumpWithEcFill(uint8_t numsectors) { + PacketResponseNG resp; - // ecfill key A - clearCommandBuffer(); - SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); - - int res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000); - if ( res != PM3_SUCCESS) { - } - - // ecfill key B - payload.keytype = 1; - - clearCommandBuffer(); - SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); - res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000); - if ( res != PM3_SUCCESS) { + mfc_eload_t payload; + payload.sectorcnt = numsectors; + payload.keytype = 0; - } - return PM3_SUCCESS; + // ecfill key A + clearCommandBuffer(); + SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); + + int res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000); + if (res != PM3_SUCCESS) { + } + + // ecfill key B + payload.keytype = 1; + + clearCommandBuffer(); + SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); + res = WaitForResponseTimeout(CMD_HF_MIFARE_EML_LOAD, &resp, 2000); + if (res != PM3_SUCCESS) { + + } + return PM3_SUCCESS; } static int CmdHF14AMfDump(const char *Cmd) { @@ -1287,11 +1287,11 @@ static int CmdHF14AMfNested(const char *Cmd) { PrintAndLogEx(SUCCESS, "Testing known keys. Sector count=%d", SectorsCnt); int res = mfCheckKeys_fast(SectorsCnt, true, true, 1, ARRAYLEN(g_mifare_default_keys) + 1, keyBlock, e_sector, false); - if ( res == PM3_SUCCESS ) { - // all keys found - PrintAndLogEx(SUCCESS, "Fast check found all keys"); - goto jumptoend; - } + if (res == PM3_SUCCESS) { + // all keys found + PrintAndLogEx(SUCCESS, "Fast check found all keys"); + goto jumptoend; + } uint64_t t2 = msclock() - t1; PrintAndLogEx(SUCCESS, "Time to check %d known keys: %.0f seconds\n", ARRAYLEN(g_mifare_default_keys), (float)t2 / 1000.0); @@ -1663,29 +1663,29 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { bool prng_type = false; bool verbose = false; bool has_filename = false; - bool errors = false; + bool errors = false; // Parse the options given by the user - while ( (ctmp = param_getchar(Cmd, cmdp)) && !errors ) { + while ((ctmp = param_getchar(Cmd, cmdp)) && !errors) { switch (tolower(ctmp)) { case 'h': return usage_hf14_autopwn(); case 'f': if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "Filename too long"); - errors = true; + errors = true; } else { - has_filename = true; + has_filename = true; } cmdp += 2; break; case 'l': legacy_mfchk = true; - cmdp++; + cmdp++; break; case 'v': verbose = true; - cmdp++; + cmdp++; break; case '*': // Get the number of sectors @@ -1696,35 +1696,35 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { case 'k': // Get the known block number if (param_getchar(Cmd, cmdp + 1) == 0x00) { - errors = true; + errors = true; break; } - + blockNo = param_get8(Cmd, cmdp + 1); - + // Get the knonwn block type ctmp = tolower(param_getchar(Cmd, cmdp + 2)); if (ctmp != 'a' && ctmp != 'b') { PrintAndLogEx(WARNING, "Key type must be A or B"); errors = true; - break; + break; } - + if (ctmp != 'a') { keyType = 1; } - + // Get the known block key if (param_gethex(Cmd, cmdp + 3, key, 12)) { PrintAndLogEx(WARNING, "Key must include 12 HEX symbols"); - errors = true; + errors = true; return PM3_EINVARG; } know_target_key = true; cmdp += 3; case 's': slow = true; - cmdp++; + cmdp++; break; case 'i': SetSIMDInstr(SIMD_AUTO); @@ -1759,9 +1759,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { return usage_hf14_autopwn(); } } - - if ( errors ) { - return usage_hf14_autopwn(); + + if (errors) { + return usage_hf14_autopwn(); } // Create the key storage stucture @@ -1821,7 +1821,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { ); PrintAndLogEx(WARNING, "falling back to dictionary"); } - + // Check if the user supplied key is used by other sectors for (int i = 0; i < sectors_cnt; i++) { for (int j = 0; j < 2; j++) { @@ -1858,18 +1858,18 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { bool load_success = true; // Load the dictionary if (has_filename) { - int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 6, &key_cnt); + int res = loadFileDICTIONARY_safe(filename, (void **) &keyBlock, 6, &key_cnt); if (res != PM3_SUCCESS || key_cnt == 0 || keyBlock == NULL) { PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)"); if (keyBlock != NULL) free(keyBlock); - - load_success = false; + + load_success = false; } } - if ( has_filename == false || load_success == false ) { + if (has_filename == false || load_success == false) { keyBlock = calloc(ARRAYLEN(g_mifare_default_keys), 6); if (keyBlock == NULL) { free(e_sector); @@ -1880,7 +1880,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { num_to_bytes(g_mifare_default_keys[cnt], 6, keyBlock + cnt * 6); } key_cnt = ARRAYLEN(g_mifare_default_keys); - PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from hardcoded default array", key_cnt); + PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%2d") "keys from hardcoded default array", key_cnt); } // Use the dictionary to find sector keys on the card @@ -1950,7 +1950,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { if (e_sector[i].foundKey[j] == 1) { e_sector[i].foundKey[j] = 'D'; num_to_bytes(e_sector[i].Key[j], 6, tmp_key); - + // Store valid credentials for the nested / hardnested attack if none exist if (know_target_key == false) { num_to_bytes(e_sector[i].Key[j], 6, key); @@ -2018,7 +2018,7 @@ noValidKeyFound: return PM3_ESOFT; } } - + free(keyBlock); // Clear the needed variables num_to_bytes(0, 6, tmp_key); @@ -2062,7 +2062,7 @@ noValidKeyFound: if (verbose) { PrintAndLogEx(INFO, _YELLOW_("======================= START READ B KEY ATTACK =======================")); PrintAndLogEx(INFO, "reading B key: sector: %3d key type: %c", - current_sector_i, + current_sector_i, current_key_type_i ? 'B' : 'A'); } uint8_t sectrail = (FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1); @@ -2094,9 +2094,9 @@ noValidKeyFound: ); } else { if (verbose) PrintAndLogEx(WARNING, "unknown B key: sector: %3d key type: %c (reading the B key was not possible, maybe due to insufficient access rights) ", - current_sector_i, - current_key_type_i ? 'B' : 'A' - ); + current_sector_i, + current_key_type_i ? 'B' : 'A' + ); } if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP READ B KEY ATTACK =======================")); } @@ -2226,13 +2226,13 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack ); } PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); - PrintAndLogEx(NORMAL, "( " + PrintAndLogEx(NORMAL, "( " _YELLOW_("D") ":Dictionary / " _YELLOW_("S") ":darkSide / " _YELLOW_("U") ":User / " _YELLOW_("R") ":Reused / " _YELLOW_("N") ":Nested / " - _YELLOW_("H") ":Hardnested / " + _YELLOW_("H") ":Hardnested / " _YELLOW_("A") ":keyA " ")" ); @@ -2254,8 +2254,8 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack mfEmlSetMem(block, FirstBlockOfSector(current_sector_i) + NumBlocksPerSector(current_sector_i) - 1, 1); } - // use ecfill trick - FastDumpWithEcFill(sectors_cnt); + // use ecfill trick + FastDumpWithEcFill(sectors_cnt); bytes = block_cnt * MFBLOCK_SIZE; dump = calloc(bytes, sizeof(uint8_t)); @@ -2526,12 +2526,12 @@ out: printKeyTable(sectorsCnt, e_sector); - if ( use_flashmemory && found_keys == (sectorsCnt << 1) ) { - PrintAndLogEx(SUCCESS, "Card dumped aswell. run " _YELLOW_("`%s %c`"), - "hf mf esave", - GetFormatFromSector(sectorsCnt) - ); - } + if (use_flashmemory && found_keys == (sectorsCnt << 1)) { + PrintAndLogEx(SUCCESS, "Card dumped aswell. run " _YELLOW_("`%s %c`"), + "hf mf esave", + GetFormatFromSector(sectorsCnt) + ); + } if (transferToEml) { // fast push mode @@ -2551,10 +2551,10 @@ out: mfEmlSetMem(block, blockno, 1); } PrintAndLogEx(SUCCESS, "Found keys have been transferred to the emulator memory"); - - if ( found_keys == (sectorsCnt << 1) ) { - FastDumpWithEcFill(sectorsCnt); - } + + if (found_keys == (sectorsCnt << 1)) { + FastDumpWithEcFill(sectorsCnt); + } } if (createDumpFile) { @@ -3534,10 +3534,10 @@ static int CmdHF14AMfECFill(const char *Cmd) { PrintAndLogEx(NORMAL, "--params: numSectors: %d, keyType: %c\n", numSectors, (keyType == 0) ? 'A' : 'B'); mfc_eload_t payload; - payload.sectorcnt = numSectors; - payload.keytype = keyType; + payload.sectorcnt = numSectors; + payload.keytype = keyType; clearCommandBuffer(); - SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); + SendCommandNG(CMD_HF_MIFARE_EML_LOAD, (uint8_t *)&payload, sizeof(payload)); return PM3_SUCCESS; } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 46cc3e017..1431ca62a 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2128,10 +2128,10 @@ static int CmdT55xxChkPwds(const char *Cmd) { if (use_pwd_file) { uint16_t keycount = 0; - int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 4, &keycount); + int res = loadFileDICTIONARY_safe(filename, (void **) &keyBlock, 4, &keycount); if (res != PM3_SUCCESS || keycount == 0 || keyBlock == NULL) { PrintAndLogEx(WARNING, "No keys found in file"); - if (keyBlock != NULL) + if (keyBlock != NULL) free(keyBlock); return PM3_ESOFT; diff --git a/client/fileutils.c b/client/fileutils.c index 427ebd9da..3c98b345a 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -435,7 +435,7 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s } size_t bytes_read = fread(*pdata, 1, fsize, f); - + fclose(f); if (bytes_read != fsize) { @@ -699,7 +699,7 @@ out: int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt) { int retval = PM3_SUCCESS; - + char *path; if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic", false) != PM3_SUCCESS) return PM3_EFILE; @@ -713,7 +713,7 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key } size_t mem_size; - size_t block_size = 10 * keylen; + size_t block_size = 10 * keylen; // double up since its chars keylen <<= 1; @@ -721,24 +721,25 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key char line[255]; // allocate some space for the dictionary - *pdata = calloc( block_size , sizeof(uint8_t)); + *pdata = calloc(block_size, sizeof(uint8_t)); if (*pdata == NULL) - return PM3_EFILE; + return PM3_EFILE; - mem_size = block_size; + mem_size = block_size; FILE *f = fopen(path, "r"); if (!f) { PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path); retval = PM3_EFILE; - goto out; } + goto out; + } // read file while (fgets(line, sizeof(line), f)) { // check if we have enough space (if not allocate more) - if ( (*keycnt * (keylen >> 1) ) >= mem_size ) { - + if ((*keycnt * (keylen >> 1)) >= mem_size) { + mem_size += block_size; *pdata = realloc(*pdata, mem_size); @@ -767,10 +768,10 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key uint64_t key = strtoull(line, NULL, 16); - num_to_bytes(key, keylen >> 1, *pdata + (*keycnt * (keylen >> 1)) ); - + num_to_bytes(key, keylen >> 1, *pdata + (*keycnt * (keylen >> 1))); + (*keycnt)++; - + memset(line, 0, sizeof(line)); } fclose(f); diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index bc474fc21..bf9aee5b3 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -543,7 +543,7 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) { size_t dumplen = 0; uint8_t *dump = NULL; - if ( loadFile_safe(filename, "", (void**)&dump, &dumplen) != PM3_SUCCESS ) { + if (loadFile_safe(filename, "", (void **)&dump, &dumplen) != PM3_SUCCESS) { return PM3_EFILE; } diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index f53f80221..f14e43eaf 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -655,19 +655,19 @@ static int doTestsWithKnownInputs() { } -static bool readKeyFile(uint8_t* key, size_t keylen) { +static bool readKeyFile(uint8_t *key, size_t keylen) { size_t len = 0; - uint8_t *keyptr = NULL; - if ( loadFile_safe("iclass_key.bin", "", (void**)&keyptr, &len) != PM3_SUCCESS ) { + uint8_t *keyptr = NULL; + if (loadFile_safe("iclass_key.bin", "", (void **)&keyptr, &len) != PM3_SUCCESS) { return false; } - - if ( keylen != len ) { + + if (keylen != len) { return false; } - - memcpy(key, keyptr, keylen ); + + memcpy(key, keyptr, keylen); return true; } diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 54de89046..429605a4e 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -210,7 +210,7 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk, icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t)); if (tmp == NULL) return PM3_EMALLOC; - + memcpy(tmp, resp.data.asBytes, sectorsCnt * sizeof(icesector_t)); for (int i = 0; i < sectorsCnt; i++) { diff --git a/client/ui.c b/client/ui.c index 6f177078d..68c8b197c 100644 --- a/client/ui.c +++ b/client/ui.c @@ -64,10 +64,10 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) #ifdef _WIN32 struct _stat st; // Mingw _stat fails if path ends with /, so let's use a stripped path - if (path[strlen(path)-1]=='/') { - path[strlen(path)-1]='\0'; + if (path[strlen(path) - 1] == '/') { + path[strlen(path) - 1] = '\0'; result = _stat(path, &st); - path[strlen(path)]='/'; + path[strlen(path)] = '/'; } else { result = _stat(path, &st); } diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index dc48bd110..e87e8bc33 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -230,9 +230,9 @@ typedef struct { } PACKED mf_readblock_t; typedef struct { - uint8_t sectorcnt; - uint8_t keytype; -} PACKED mfc_eload_t; + uint8_t sectorcnt; + uint8_t keytype; +} PACKED mfc_eload_t; // For the bootloader #define CMD_DEVICE_INFO 0x0000 From bd7c1ccf4b7f11cf3dcbbc9af0d5ccd4d9fef19d Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Fri, 30 Aug 2019 12:42:17 +0300 Subject: [PATCH 199/347] Appveyour works (#378) * c2 * vfix * ff * dd2 --- appveyor.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b77cef02d..893aa7034 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -143,6 +143,7 @@ clone_script: ExecUpdate "update2" "C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null" "terminate?MSYS2" Write-Host "Update " -NoNewLine + Write-Host "[ OK ]" -ForegroundColor Green install: - ps: >- @@ -280,7 +281,7 @@ test_script: Function ExecTest($Name, $File, $Cmd, $CheckResult) { - + #--- begin Job $Job = Start-Job -ScriptBlock { @@ -318,6 +319,13 @@ test_script: if ($Cond -is "String" -and $Cond -like "*true*"){ $res= $true } + ForEach($line in $Cond){ + if ($line -like "*passed*"){ + $res = $true + $Cond = $line + break + } + } } Else { $res=$Cond } @@ -373,11 +381,11 @@ test_script: #proxmark logic tests - ExecTest "proxmark help" "proxmark3 -h" {bash -lc 'cd ~/client;./proxmark3 -h | grep -q wait && echo passed || echo failed'} + ExecTest "proxmark help" "proxmark3 -h" {bash -lc 'cd ~/client;./proxmark3 -h 2>&1 | grep -q wait && echo passed || echo failed'} - ExecTest "proxmark help text ISO7816" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t | grep -q ISO7816 && echo passed || echo failed'} + ExecTest "proxmark help text ISO7816" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t 2>&1 | grep -q ISO7816 && echo passed || echo failed'} - ExecTest "proxmark help text hardnested" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t | grep -q hardnested && echo passed || echo failed'} + ExecTest "proxmark help text hardnested" "proxmark3 -t" {bash -lc 'cd ~/client;./proxmark3 -t 2>&1 | grep -q hardnested && echo passed || echo failed'} ExecTest "hf mf offline text" "hf mf" {bash -lc "cd ~/client;./proxmark3 -c 'hf mf'"} "at_enc" From 4433f8982c721c50a0a70f8951129522338ed07d Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Fri, 30 Aug 2019 13:55:35 +0300 Subject: [PATCH 200/347] Appveyour fix paths (#379) --- appveyor.yml | 8 +++----- client/emv/test/cryptotest.c | 8 +++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 893aa7034..1c4cc5ae5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -193,9 +193,9 @@ build_script: } - if(!(Test-Path C:\ProxSpace\pm3\client\hardnested\tables\*.bin.z)){ + if(!(Test-Path C:\ProxSpace\pm3\client\resources\hardnested_tables\*.bin.z)){ - throw "Files in hardnested\tables not exists." + throw "Files in client\resources\hardnested_tables is not exists." } @@ -220,9 +220,7 @@ build_script: New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\hardnested\tables - Copy-Item C:\ProxSpace\pm3\client\hardnested\*.bin C:\ProxSpace\Release\hardnested - - Copy-Item C:\ProxSpace\pm3\client\hardnested\tables\*.bin.z C:\ProxSpace\Release\hardnested\tables + Copy-Item C:\ProxSpace\pm3\client\resources\hardnested_tables\*.bin.z C:\ProxSpace\Release\hardnested\tables # dll files diff --git a/client/emv/test/cryptotest.c b/client/emv/test/cryptotest.c index 29c4fdaa3..937ff7e8e 100644 --- a/client/emv/test/cryptotest.c +++ b/client/emv/test/cryptotest.c @@ -58,7 +58,13 @@ int ExecuteCryptoTests(bool verbose) { res = mbedtls_entropy_self_test(verbose); if (res) TestFail = true; - res = mbedtls_timing_self_test(verbose); + // retry for CI (when resources too low) + for (int i = 0; i < 3; i++) { + res = mbedtls_timing_self_test(verbose); + if (!res) + break; + PrintAndLogEx(WARNING, "Repeat timing test %d", i + 1); + } if (res) TestFail = true; res = mbedtls_ctr_drbg_self_test(verbose); From e1e5687e32b9fea11c95af5f3f28c01638f85721 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 30 Aug 2019 14:53:53 +0200 Subject: [PATCH 201/347] add: lua scripts can now search for files. --- client/scripting.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/client/scripting.c b/client/scripting.c index 5a3eaed61..6c2dbb07c 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -31,6 +31,7 @@ #include "proxmark3.h" #include "crc16.h" #include "protocols.h" +#include "fileutils.h" // searchfile static int returnToLuaWithError(lua_State *L, const char *fmt, ...) { char buffer[200]; @@ -1052,6 +1053,29 @@ static int l_ndefparse(lua_State *L) { return 1; } +static int l_searchfile(lua_State *L) { + //Check number of arguments + int n = lua_gettop(L); + if (n != 2) { + return returnToLuaWithError(L, "Only filename and extension"); + } + + size_t size; + // data + const char *filename = luaL_checklstring(L, 1, &size); + if ( size == 0 ) + return returnToLuaWithError(L, "Must specify filename"); + + const char *suffix = luaL_checklstring(L, 2, &size); + char *path; + int res = searchFile(&path, "", filename, suffix, false); + if ( res != PM3_SUCCESS) { + return returnToLuaWithError(L, "Failed to find file"); + } + + lua_pushstring(L, path); + return 1; +} /** * @brief Sets the lua path to include "./lualibs/?.lua", in order for a script to be @@ -1112,6 +1136,7 @@ int set_pm3_libraries(lua_State *L) { {"t55xx_detect", l_T55xx_detect}, {"ndefparse", l_ndefparse}, {"fast_push_mode", l_fast_push_mode}, + {"search_file", l_searchfile}, {NULL, NULL} }; From 24be423551d4ed4825cd2e3506a47abbd6c1d7f2 Mon Sep 17 00:00:00 2001 From: Uli Heilmeier Date: Fri, 30 Aug 2019 21:02:48 +0200 Subject: [PATCH 202/347] Readme: Fix links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f02deabf6..2515cb6ec 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. | ------------------- |:-------------------:| -------------------:| |[What has changed?](#what-has-changed) | [Setup and build for Linux](/doc/md/Installation_Instructions/Linux-Installation-Instructions.md) | [Compilation Instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md)| |[Development](#development) | [Important notes on ModemManager for Linux users](/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md) | [Validating proxmark client functionality](/doc/md/Use_of_Proxmark/1_Validation.md) | -|[Why didn't you base it on official PM3 Master?](#why-didnt-you-base-it-on-official-pm3-master)| [Homebrew (Mac OS X) & Upgrading HomeBrew Tap Formula](/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md) | [First Use and Verification](/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md)| -|[PM3 GUI](#pm3-gui)|[Setup and build for Windows](/doc/md/Installation_Instructions/Windows-Installation-Instructions.md)|[Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| +|[Why didn't you base it on official Proxmark3 Master?](#why-didnt-you-base-it-on-official-proxmark3-master)| [Homebrew (Mac OS X) & Upgrading HomeBrew Tap Formula](/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md) | [First Use and Verification](/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md)| +|[Proxmark3 GUI](#proxmark3-gui)|[Setup and build for Windows](/doc/md/Installation_Instructions/Windows-Installation-Instructions.md)|[Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| |[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) |[Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md)| |[Notes on UART](/doc/uart_notes.md)||[Command Cheat sheet](/doc/cheatsheet.md)| |[Notes on Frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| From 4d31b2399b320e186f864386bf6e9d12f5113ccc Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 21:36:10 +0200 Subject: [PATCH 203/347] reintroduce PREFIX and use relative paths for finding share/ when installed, independently of PREFIX --- Makefile.host | 7 +------ client/Makefile | 7 +------ client/fileutils.c | 13 ++++++++----- client/scripting.c | 20 +++++++++++--------- include/common.h | 25 +++++++++++-------------- 5 files changed, 32 insertions(+), 40 deletions(-) diff --git a/Makefile.host b/Makefile.host index 3220f7add..66f3ccce0 100644 --- a/Makefile.host +++ b/Makefile.host @@ -15,12 +15,7 @@ FALSE = false CFLAGS ?= -Wall -Werror -O3 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES) -ifneq (,$(PM3_BIN_PATH)) - CFLAGS += -DPM3_BIN_PATH=\"$(PM3_BIN_PATH)\" -endif -ifneq (,$(PM3_SHARE_PATH)) - CFLAGS += -DPM3_SHARE_PATH=\"$(PM3_SHARE_PATH)\" -endif +PREFIX ?= /usr/local platform = $(shell uname) diff --git a/client/Makefile b/client/Makefile index ccf7d5ab8..4a2e12329 100644 --- a/client/Makefile +++ b/client/Makefile @@ -66,12 +66,7 @@ INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) CFLAGS ?= -Wall -Werror -g -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT) -ifneq (,$(PM3_BIN_PATH)) - PM3CFLAGS += -DPM3_BIN_PATH=\"$(PM3_BIN_PATH)\" -endif -ifneq (,$(PM3_SHARE_PATH)) - PM3CFLAGS += -DPM3_SHARE_PATH=\"$(PM3_SHARE_PATH)\" -endif +PREFIX ?= /usr/local ifneq (,$(findstring MINGW,$(platform))) PM3CFLAGS += -mno-ms-bitfields -fexec-charset=cp850 endif diff --git a/client/fileutils.c b/client/fileutils.c index 3c98b345a..1c0403294 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -855,9 +855,11 @@ int searchAndList(const char *pm3dir, const char *ext) { filelist(script_directory_path, ext, false, false); } // try pm3 dirs in pm3 installation dir (install mode) - { - char script_directory_path[strlen(PM3_SHARE_PATH) + strlen(pm3dir) + 1]; - strcpy(script_directory_path, PM3_SHARE_PATH); + const char *exec_path = get_my_executable_directory(); + if (exec_path != NULL) { + char script_directory_path[strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(pm3dir) + 1]; + strcpy(script_directory_path, exec_path); + strcat(script_directory_path, PM3_SHARE_RELPATH); strcat(script_directory_path, pm3dir); filelist(script_directory_path, ext, true, false); } @@ -975,10 +977,11 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea } // try pm3 dirs in pm3 installation dir (install mode) { - char *path = calloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); + char *path = calloc(strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; - strcpy(path, PM3_SHARE_PATH); + strcpy(path, exec_path); + strcat(path, PM3_SHARE_RELPATH); strcat(path, pm3dir); strcat(path, filename); if ((g_debugMode == 2) && (!silent)) { diff --git a/client/scripting.c b/client/scripting.c index 6c2dbb07c..33e7c6c42 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1175,7 +1175,7 @@ int set_pm3_libraries(lua_State *L) { } char *user_path = getenv("HOME"); if (user_path != NULL) { - // from the ~/.proxmark3/luascripts/ directory + // from the $HOME/.proxmark3/luascripts/ directory char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, user_path); strcat(scripts_path, PM3_USER_DIRECTORY); @@ -1183,7 +1183,7 @@ int set_pm3_libraries(lua_State *L) { strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); - // from the ~/.proxmark3/lualib/ directory + // from the $HOME/.proxmark3/lualib/ directory char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, user_path); strcat(libraries_path, PM3_USER_DIRECTORY); @@ -1192,16 +1192,18 @@ int set_pm3_libraries(lua_State *L) { setLuaPath(L, libraries_path); } - if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_SUBDIR) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0) { - // from the /usr/local/share/proxmark3/luascripts/ directory - char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, PM3_SHARE_PATH); + if (exec_path != NULL) { + // from the $PREFIX/share/proxmark3/luascripts/ directory + char scripts_path[strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, exec_path); + strcat(scripts_path, PM3_SHARE_RELPATH); strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); - // from the /usr/local/share/proxmark3/lualib/ directory - char libraries_path[strlen(PM3_SHARE_PATH) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, PM3_SHARE_PATH); + // from the $PREFIX/share/proxmark3/lualib/ directory + char libraries_path[strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, exec_path); + strcat(libraries_path, PM3_SHARE_RELPATH); strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); diff --git a/include/common.h b/include/common.h index c4c5d6370..bdda44aae 100644 --- a/include/common.h +++ b/include/common.h @@ -16,22 +16,19 @@ #include #include -// brew prefixes are a bit weird so we've to split bin & share to be prepared: -#ifndef PM3_BIN_PATH -# define PM3_BIN_PATH "/usr/local/bin/" -#endif -#ifndef PM3_SHARE_PATH -# define PM3_SHARE_PATH "/usr/local/share/proxmark3/" -#endif -// PM3_USER_DIRECTORY will be expanded as if with a "~" upfront, e.g. ~/.proxmark3/ -#define PM3_USER_DIRECTORY "/.proxmark3/" +#define PATHSEP "/" +// PM3 share path relative to executable when installed +#define PM3_SHARE_RELPATH ".." PATHSEP "share" PATHSEP "proxmark3" PATHSEP + +// PM3_USER_DIRECTORY will be expanded from $HOME, e.g. ~/.proxmark3/ +#define PM3_USER_DIRECTORY PATHSEP ".proxmark3" PATHSEP // PM3 subdirectories: -#define DICTIONARIES_SUBDIR "dictionaries/" -#define LUA_LIBRARIES_SUBDIR "lualibs/" -#define LUA_SCRIPTS_SUBDIR "luascripts/" -#define RESOURCES_SUBDIR "resources/" -#define TRACES_SUBDIR "traces/" +#define DICTIONARIES_SUBDIR "dictionaries" PATHSEP +#define LUA_LIBRARIES_SUBDIR "lualibs" PATHSEP +#define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP +#define RESOURCES_SUBDIR "resources" PATHSEP +#define TRACES_SUBDIR "traces" PATHSEP #define PACKED __attribute__((packed)) From dbc9865c367a68258932f1c592c5ff9324d2770a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 21:38:12 +0200 Subject: [PATCH 204/347] clean common_arm/Makefile.common --- common_arm/Makefile.common | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/common_arm/Makefile.common b/common_arm/Makefile.common index cf4405d6a..b2f085d56 100644 --- a/common_arm/Makefile.common +++ b/common_arm/Makefile.common @@ -40,28 +40,11 @@ INCLUDE = -I../include -I../common_arm -I../common_fpga -I../common -I. TAR=tar TARFLAGS = -C .. -rvf -# Windows' echo echos its input verbatim, on Posix there is some -# amount of shell command line parsing going on. echo "" on -# Windows yields literal "", on Linux yields an empty line -ifeq ($(shell echo ""),) DELETE=rm -rf MOVE=mv COPY=cp PATHSEP=/ -FLASH_TOOL=client/flasher -# This is probably a proper system, so we can use uname DETECTED_OS=$(platform) -else - -# Assume that we are running on Windows. -DELETE=del /q -MOVE=ren -COPY=copy -PATHSEP=\\# -FLASH_TOOL=client\\flasher.exe -DETECTED_OS=Windows - -endif # Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/zlib ../fpga ../armsrc/Standalone From b5f5b9276f2fc39a8ea18e3ab5a0eabf7faa7bd0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 21:44:40 +0200 Subject: [PATCH 205/347] make install skeleton --- Makefile | 5 +++-- Makefile.host | 10 +++++++++- armsrc/Makefile | 10 +++++++++- bootrom/Makefile | 10 +++++++++- client/Makefile | 10 +++++++++- common_arm/Makefile.common | 5 +++-- recovery/Makefile | 9 +++++++++ 7 files changed, 51 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7ca9e313f..3f288f504 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,13 @@ ifneq ($(V),1) endif # To see full command lines, use make V=1 +COPY=cp GZIP=gzip -include Makefile.platform -include .Makefile.options.cache include common_arm/Makefile.hal -all clean: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% fpga_compress/% +all clean install uninstall: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% fpga_compress/% mfkey/%: FORCE $(info [*] MAKE $@) @@ -34,7 +35,7 @@ recovery/%: FORCE cleanifplatformchanged bootrom/% armsrc/% $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) -.PHONY: all clean help _test bootrom fullimage recovery client mfkey nonce2key style checks FORCE udev accessrights cleanifplatformchanged +.PHONY: all clean install uninstall help _test bootrom fullimage recovery client mfkey nonce2key style checks FORCE udev accessrights cleanifplatformchanged help: @echo "Multi-OS Makefile" diff --git a/Makefile.host b/Makefile.host index 66f3ccce0..8e76caa50 100644 --- a/Makefile.host +++ b/Makefile.host @@ -48,7 +48,15 @@ clean: $(Q)$(RM) $(CLEAN) $(Q)$(RMDIR) $(OBJDIR) -.PHONY: all clean +install: all + $(info [@] Installing $(BINS) $(LIB_A) to $(PREFIX)) + @true + +uninstall: + $(info [@] Uninstalling $(BINS) $(LIB_A) from $(PREFIX)) + @true + +.PHONY: all clean install uninstall $(BINDIR)/$(LIB_A): $(MYOBJS) $(info [=] AR $(notdir $@)) diff --git a/armsrc/Makefile b/armsrc/Makefile index 048879d96..6e67913e4 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -213,7 +213,15 @@ clean: $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.bin $(Q)$(DELETE) version.c -.PHONY: all clean help +install: all + $(info [@] Installing fullimage to $(PREFIX)) + @true + +uninstall: + $(info [@] Uninstalling fullimage from $(PREFIX)) + @true + +.PHONY: all clean help install uninstall help: @echo Multi-OS Makefile, you are running on $(DETECTED_OS) @echo Possible targets: diff --git a/bootrom/Makefile b/bootrom/Makefile index 884f01757..179678b92 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -56,7 +56,15 @@ clean: $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.d $(Q)$(DELETE) version.c -.PHONY: all clean help +install: all + $(info [@] Installing bootrom to $(PREFIX)) + @true + +uninstall: + $(info [@] Uninstalling bootrom from $(PREFIX)) + @true + +.PHONY: all clean help install help: @echo Multi-OS Makefile, you are running on $(DETECTED_OS) @echo Possible targets: diff --git a/client/Makefile b/client/Makefile index 4a2e12329..42e617e1f 100644 --- a/client/Makefile +++ b/client/Makefile @@ -334,6 +334,14 @@ clean: $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean +install: all + $(info [@] Installing client to $(PREFIX)) + @true + +uninstall: + $(info [@] Uninstalling client from $(PREFIX)) + @true + tarbin: $(BINS) $(info [=] TAR ../proxmark3-$(platform)-bin.tar) $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%) @@ -364,7 +372,7 @@ $(ZLIB): $(info [*] MAKE zlib) $(Q)$(MAKE) --no-print-directory -C $(ZLIBPATH) OBJDIR=$(ROOT_DIR)$(OBJDIR) BINDIR=$(ROOT_DIR)$(OBJDIR) all -.PHONY: all clean +.PHONY: all clean install uninstall # easy printing of MAKE VARIABLES print-%: ; @echo $* = $($*) diff --git a/common_arm/Makefile.common b/common_arm/Makefile.common index b2f085d56..011f020f8 100644 --- a/common_arm/Makefile.common +++ b/common_arm/Makefile.common @@ -21,10 +21,11 @@ endif # Make sure that all is the default target # (The including Makefile still needs to define what 'all' is) -platform = $(shell uname) - all: +platform = $(shell uname) +PREFIX?=/usr/local + CROSS ?= arm-none-eabi- CC = $(CROSS)gcc AS = $(CROSS)as diff --git a/recovery/Makefile b/recovery/Makefile index 59f7f37c8..60b62cfe1 100644 --- a/recovery/Makefile +++ b/recovery/Makefile @@ -19,3 +19,12 @@ proxmark3_recovery.bin: bootrom.bin fullimage.bin clean: $(Q)rm -f $(BINS) +install: all + $(info [@] Installing recovery to $(PREFIX)) + @true + +uninstall: all + $(info [@] Uninstalling recovery from $(PREFIX)) + @true + +PHONY: all clean install uninstall From 4fdb5a2f4bb8b4fd5f1499e138eff364ad594e1f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 21:55:13 +0200 Subject: [PATCH 206/347] make install: half way --- Makefile | 31 ++++++++++++++++++++++--------- Makefile.host | 14 ++++++++++++-- armsrc/Makefile | 30 ++++++++++++++++-------------- bootrom/Makefile | 25 ++++++++++++++----------- client/Makefile | 25 +++++++++++++++++++++++-- common_arm/Makefile.common | 9 +++++---- fpga/Makefile | 16 ++++++++-------- recovery/Makefile | 18 ++++++++++-------- tools/mfkey/Makefile | 1 + tools/nonce2key/Makefile | 1 + 10 files changed, 112 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index 3f288f504..f74932ccc 100644 --- a/Makefile +++ b/Makefile @@ -4,35 +4,48 @@ ifneq ($(V),1) endif # To see full command lines, use make V=1 -COPY=cp +CP = cp -a GZIP=gzip +MKDIR = mkdir -p +RM = rm -f +RMDIR = rm -rf -include Makefile.platform -include .Makefile.options.cache include common_arm/Makefile.hal +# preserve relative DESTDIR path for subdir makes +ifneq (,$(DESTDIR)) + # realpath needs the directory to exist + $(shell $(MKDIR) $(DESTDIR)) + MYDESTDIR:=$(realpath $(DESTDIR)) + ifeq (,$(MYDESTDIR)) + $(error Can't create $(DESTDIR)) + endif +endif + all clean install uninstall: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% fpga_compress/% mfkey/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) DESTDIR=$(MYDESTDIR) nonce2key/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/nonce2key $(patsubst nonce2key/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C tools/nonce2key $(patsubst nonce2key/%,%,$@) DESTDIR=$(MYDESTDIR) fpga_compress/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C tools/fpga_compress $(patsubst fpga_compress/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C tools/fpga_compress $(patsubst fpga_compress/%,%,$@) DESTDIR=$(MYDESTDIR) bootrom/%: FORCE cleanifplatformchanged $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C bootrom $(patsubst bootrom/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C bootrom $(patsubst bootrom/%,%,$@) DESTDIR=$(MYDESTDIR) armsrc/%: FORCE cleanifplatformchanged fpga_compress/% $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C armsrc $(patsubst armsrc/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C armsrc $(patsubst armsrc/%,%,$@) DESTDIR=$(MYDESTDIR) client/%: FORCE $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C client $(patsubst client/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C client $(patsubst client/%,%,$@) DESTDIR=$(MYDESTDIR) recovery/%: FORCE cleanifplatformchanged bootrom/% armsrc/% $(info [*] MAKE $@) - $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) + $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) 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 style checks FORCE udev accessrights cleanifplatformchanged @@ -77,7 +90,7 @@ nonce2key: nonce2key/all fpga_compress: fpga_compress/all newtarbin: - $(DELETE) proxmark3-$(platform)-bin.tar proxmark3-$(platform)-bin.tar.gz + $(RM) proxmark3-$(platform)-bin.tar proxmark3-$(platform)-bin.tar.gz @touch proxmark3-$(platform)-bin.tar tarbin: newtarbin client/tarbin armsrc/tarbin bootrom/tarbin diff --git a/Makefile.host b/Makefile.host index 8e76caa50..861e697fb 100644 --- a/Makefile.host +++ b/Makefile.host @@ -4,6 +4,9 @@ ifneq ($(V),1) endif # To see full command lines, use make V=1 +INSTALLBINRELPATH = /bin/ +INSTALLTOOLSRELPATH = /share/proxmark3/tools/ + CC = gcc LD = gcc RM = rm -f @@ -49,11 +52,18 @@ clean: $(Q)$(RMDIR) $(OBJDIR) install: all - $(info [@] Installing $(BINS) $(LIB_A) to $(PREFIX)) +ifneq (,$(INSTALLTOOLS)) + $(info [@] Installing $(BINS) to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) + $(Q)$(CP) $(INSTALLTOOLS) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) +endif @true uninstall: - $(info [@] Uninstalling $(BINS) $(LIB_A) from $(PREFIX)) +ifneq (,$(INSTALLTOOLS)) + $(info [@] Uninstalling $(BINS) from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH)$(notdir $(tool))) +endif @true .PHONY: all clean install uninstall diff --git a/armsrc/Makefile b/armsrc/Makefile index 6e67913e4..8cbe03dab 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -134,6 +134,7 @@ include ../common_arm/Makefile.common COMMON_FLAGS = -Os +INSTALLFW = $(OBJDIR)/fullimage.elf OBJS = $(OBJDIR)/fullimage.s19 FPGA_COMPRESSOR = ../tools/fpga_compress/fpga_compress @@ -144,7 +145,7 @@ all: $(OBJS) # version.c should be remade on every time fullimage.stage1.elf should be remade version.c: default_version.c $(OBJDIR)/fpga_version_info.o $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ) $(info [-] GEN $@) - $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(COPY) $^ $@ + $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(CP) $^ $@ fpga_version_info.c: $(FPGA_BITSTREAMS) | $(FPGA_COMPRESSOR) $(info [-] GEN $@) @@ -203,23 +204,24 @@ tarbin: $(OBJS) $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(OBJS:%=armsrc/%) $(OBJS:%.s19=armsrc/%.elf) clean: - $(Q)$(DELETE) $(DEPENDENCY_FILES) - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.o - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.elf - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.s19 - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.map - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.d - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.z - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.bin - $(Q)$(DELETE) version.c + $(Q)$(RM) $(DEPENDENCY_FILES) + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.o + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.elf + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.s19 + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.map + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.d + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.z + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.bin + $(Q)$(RM) version.c install: all - $(info [@] Installing fullimage to $(PREFIX)) - @true + $(info [@] Installing fullimage to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) uninstall: - $(info [@] Uninstalling fullimage from $(PREFIX)) - @true + $(info [@] Uninstalling fullimage from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) .PHONY: all clean help install uninstall help: diff --git a/bootrom/Makefile b/bootrom/Makefile index 179678b92..0d3f081d9 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -31,12 +31,14 @@ APP_CFLAGS += -fno-stack-protector -fno-pie # Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC include ../common_arm/Makefile.common +INSTALLFW = $(OBJDIR)/bootrom.elf + OBJS = $(OBJDIR)/bootrom.s19 # version.c should be remade on every compilation version.c: default_version.c $(info [=] GEN $@) - $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(COPY) $^ $@ + $(Q)sh ../tools/mkversion.sh > $@ || perl ../tools/mkversion.pl > $@ || $(CP) $^ $@ all: $(OBJS) @@ -49,20 +51,21 @@ $(OBJDIR)/bootrom.elf: $(VERSIONOBJ) $(ASMOBJ) $(ARMOBJ) $(THUMBOBJ) $(Q)$(CC) $(LDFLAGS) -Wl,-T,ldscript-flash,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS) clean: - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.o - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.elf - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.s19 - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.map - $(Q)$(DELETE) $(OBJDIR)$(PATHSEP)*.d - $(Q)$(DELETE) version.c + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.o + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.elf + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.s19 + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.map + $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.d + $(Q)$(RM) version.c install: all - $(info [@] Installing bootrom to $(PREFIX)) - @true + $(info [@] Installing bootrom to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) uninstall: - $(info [@] Uninstalling bootrom from $(PREFIX)) - @true + $(info [@] Uninstalling bootrom from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) .PHONY: all clean help install help: diff --git a/client/Makefile b/client/Makefile index 42e617e1f..a8232f7e9 100644 --- a/client/Makefile +++ b/client/Makefile @@ -15,6 +15,12 @@ ifneq ($(V),1) endif # To see full command lines, use make V=1 +INSTALLBINRELPATH = /bin/ +INSTALLSHARERELPATH = /share/proxmark3/ +#TODO INSTALLBIN = proxmark3 proxmark3-flasher +INSTALLBIN = proxmark3 flasher +INSTALLSHARE = lualibs luascripts resources dictionaries + CC = gcc CXX = g++ LD = g++ @@ -27,6 +33,7 @@ MKDIR = mkdir -p MV = mv TOUCH = touch FALSE = false +CP=cp -a platform = $(shell uname) ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) @@ -335,11 +342,25 @@ clean: $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean install: all - $(info [@] Installing client to $(PREFIX)) + $(info [@] Installing client to $(DESTDIR)$(PREFIX)...) +ifneq (,$(INSTALLBIN)) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) + $(Q)$(CP) $(INSTALLBIN) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) +endif +ifneq (,$(INSTALLSHARE)) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(CP) $(INSTALLSHARE) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) +endif @true uninstall: - $(info [@] Uninstalling client from $(PREFIX)) + $(info [@] Uninstalling client from $(DESTDIR)$(PREFIX)...) +ifneq (,$(INSTALLBIN)) + $(Q)$(RM) $(foreach tool,$(INSTALLBIN),$(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)$(notdir $(tool))) +endif +ifneq (,$(INSTALLSHARE)) + $(Q)$(RMDIR) $(foreach tool,$(INSTALLSHARE),$(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)$(notdir $(tool))) +endif @true tarbin: $(BINS) diff --git a/common_arm/Makefile.common b/common_arm/Makefile.common index 011f020f8..5af77bcf7 100644 --- a/common_arm/Makefile.common +++ b/common_arm/Makefile.common @@ -25,6 +25,7 @@ all: platform = $(shell uname) PREFIX?=/usr/local +INSTALLFWRELPATH = /share/proxmark3/firmware/ CROSS ?= arm-none-eabi- CC = $(CROSS)gcc @@ -40,10 +41,10 @@ INCLUDE = -I../include -I../common_arm -I../common_fpga -I../common -I. TAR=tar TARFLAGS = -C .. -rvf - -DELETE=rm -rf -MOVE=mv -COPY=cp +RM=rm -f +RMDIR=rm -rf +CP=cp -a +MKDIR=mkdir -p PATHSEP=/ DETECTED_OS=$(platform) diff --git a/fpga/Makefile b/fpga/Makefile index b28c27db9..06cdec2ee 100644 --- a/fpga/Makefile +++ b/fpga/Makefile @@ -1,36 +1,36 @@ all: fpga_lf.bit fpga_hf.bit clean: - $(Q)$(DELETE) *.bgn *.drc *.ncd *.ngd *_par.xrpt *-placed.* *-placed_pad.* *_usage.xml xst_hf.srp xst_lf.srp - $(Q)$(DELETE) *.map *.ngc *.xrpt *.pcf *.rbt *_auto_* *.bld *.mrp *.ngm *.unroutes *_summary.xml netlist.lst xst + $(Q)$(RM) *.bgn *.drc *.ncd *.ngd *_par.xrpt *-placed.* *-placed_pad.* *_usage.xml xst_hf.srp xst_lf.srp + $(Q)$(RM) *.map *.ngc *.xrpt *.pcf *.rbt *_auto_* *.bld *.mrp *.ngm *.unroutes *_summary.xml netlist.lst xst fpga_hf.ngc: fpga_hf.v fpga.ucf xst_hf.scr util.v hi_simulate.v hi_read_tx.v hi_read_rx_xcorr.v hi_iso14443a.v hi_sniffer.v hi_flite.v - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] XST $@) $(Q)$(XILINX_TOOLS_PREFIX)xst -ifn xst_hf.scr fpga_lf.ngc: fpga_lf.v fpga.ucf xst_lf.scr util.v clk_divider.v lo_edge_detect.v lo_read.v lo_passthru.v lp20khz_1MSa_iir_filter.v min_max_tracker.v lf_edge_detect.v - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] XST $@) $(Q)$(XILINX_TOOLS_PREFIX)xst -ifn xst_lf.scr %.ngd: %.ngc - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] NGD $@) $(Q)$(XILINX_TOOLS_PREFIX)ngdbuild -aul -p xc2s30-5-vq100 -nt timestamp -uc fpga.ucf $< $@ %.ncd: %.ngd - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] MAP $@) $(Q)$(XILINX_TOOLS_PREFIX)map -p xc2s30-5-vq100 $< %-placed.ncd: %.ncd - $(Q)$(DELETE) $@ + $(Q)$(RM) $@ $(info [-] PAR $@) $(Q)$(XILINX_TOOLS_PREFIX)par $< $@ %.bit: %-placed.ncd - $(Q)$(DELETE) $@ $*.drc $*.rbt + $(Q)$(RM) $@ $*.drc $*.rbt $(info [=] BITGEN $@) $(Q)$(XILINX_TOOLS_PREFIX)bitgen $< $@ diff --git a/recovery/Makefile b/recovery/Makefile index 60b62cfe1..fd10020bf 100644 --- a/recovery/Makefile +++ b/recovery/Makefile @@ -1,6 +1,7 @@ include ../common_arm/Makefile.common -BINS = bootrom.bin fullimage.bin proxmark3_recovery.bin +INSTALLFW = proxmark3_recovery.bin +BINS = bootrom.bin fullimage.bin $(INSTALLFW) all: $(BINS) @@ -17,14 +18,15 @@ proxmark3_recovery.bin: bootrom.bin fullimage.bin $(Q)cat bootrom.bin fullimage.bin > $@ clean: - $(Q)rm -f $(BINS) + $(Q)$(RM) $(BINS) install: all - $(info [@] Installing recovery to $(PREFIX)) - @true + $(info [@] Installing recovery to $(DESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) -uninstall: all - $(info [@] Uninstalling recovery from $(PREFIX)) - @true +uninstall: + $(info [@] Uninstalling recovery from $(DESTDIR)$(PREFIX)...) + $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) -PHONY: all clean install uninstall +.PHONY: all clean install uninstall diff --git a/tools/mfkey/Makefile b/tools/mfkey/Makefile index 27fa95aa0..a7b006f6e 100644 --- a/tools/mfkey/Makefile +++ b/tools/mfkey/Makefile @@ -5,6 +5,7 @@ MYCFLAGS = -std=c99 -D_ISOC99_SOURCE MYDEFS = BINS = mfkey32 mfkey32v2 mfkey64 +INSTALLTOOLS = $(BINS) include ../../Makefile.host diff --git a/tools/nonce2key/Makefile b/tools/nonce2key/Makefile index 8b5d05278..77dc18099 100644 --- a/tools/nonce2key/Makefile +++ b/tools/nonce2key/Makefile @@ -5,6 +5,7 @@ MYCFLAGS = -std=c99 -D_ISOC99_SOURCE MYDEFS = BINS = nonce2key +INSTALLTOOLS = $(BINS) include ../../Makefile.host From d772c6169a719d37c798f8f75d90c90f0f2cd30d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 21:57:43 +0200 Subject: [PATCH 207/347] rename flasher -> proxmark3-flasher --- client/Makefile | 11 +++++----- doc/bt_manual_v10.md | 6 +++--- ...OS-X-Homebrew-Installation-Instructions.md | 2 +- .../ModemManager-Must-Be-Discarded.md | 2 +- .../Troubleshooting.md | 20 +++++++++---------- .../Windows-Installation-Instructions.md | 6 +++--- .../0_Compilation-Instructions.md | 2 +- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/client/Makefile b/client/Makefile index a8232f7e9..5157e3e57 100644 --- a/client/Makefile +++ b/client/Makefile @@ -17,8 +17,7 @@ endif INSTALLBINRELPATH = /bin/ INSTALLSHARERELPATH = /share/proxmark3/ -#TODO INSTALLBIN = proxmark3 proxmark3-flasher -INSTALLBIN = proxmark3 flasher +INSTALLBIN = proxmark3 proxmark3-flasher INSTALLSHARE = lualibs luascripts resources dictionaries CC = gcc @@ -297,8 +296,10 @@ ifeq "$(SUPPORTS_AVX512)" "True" MULTIARCHOBJS += $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX512.o) endif -BINS = proxmark3 flasher +BINS = proxmark3 proxmark3-flasher CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua +# transition: make sure old flasher is gone too +CLEAN += flasher # need to assign dependancies to build these first... all: $(BINS) @@ -311,7 +312,7 @@ proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(info [=] LD $@) $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LDLIBS) -o $@ -flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS) $(OBJCOBJS) +proxmark3-flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS) $(OBJCOBJS) $(info [=] LD $@) $(Q)$(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@ @@ -459,7 +460,7 @@ DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(REVEN $(patsubst %.o, %.d, $(MULTIARCHOBJS)) \ $(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \ $(patsubst %.m, $(OBJDIR)/%.d, $(OBJCSRCS)) \ - $(OBJDIR)/proxmark3.d $(OBJDIR)/flash.d $(OBJDIR)/flasher.d + $(OBJDIR)/proxmark3.d $(OBJDIR)/flash.d $(OBJDIR)/proxmark3-flasher.d $(OBJDIR)/flasher.d $(DEPENDENCY_FILES): ; .PRECIOUS: $(DEPENDENCY_FILES) diff --git a/doc/bt_manual_v10.md b/doc/bt_manual_v10.md index 5f140976f..38f5f0d3b 100644 --- a/doc/bt_manual_v10.md +++ b/doc/bt_manual_v10.md @@ -128,7 +128,7 @@ connection is successful. 4. Use Proxmark client on BT-serial port ```sh -./proxmark /dev/rfcomm0 +./proxmark3 /dev/rfcomm0 ``` The first time, your OS will ask you for pairing. The default PIN is 1234. If PIN is not typed in quickly, the client might timeout. Simply @@ -169,7 +169,7 @@ turn on solid. 4. a serial port `/dev/ttyUSB0` will be created, use Proxmark3 client on it ```sh -./proxmark /dev/ttyUSB0 +./proxmark3 /dev/ttyUSB0 ``` #### MacOS @@ -191,7 +191,7 @@ After reboot you can go ahead to pairing your Proxmark3 RDV4 Blue Shark: 8. A serial port like `/dev/tty.PM3_RDV40-DevB` will be created, use Proxmark3 client on it ```sh -./proxmark /dev/tty.PM3_RDV40-DevB +./proxmark3 /dev/tty.PM3_RDV40-DevB ``` #### Android diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index f2d87aa66..09b986ff3 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -87,7 +87,7 @@ In principle, the helper script `flash-all.sh` should auto-detect your port, so If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -client/flasher /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3-flasher /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: diff --git a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md index 68b69ea7b..76a4626e3 100644 --- a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md +++ b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md @@ -121,7 +121,7 @@ In short: * unplug device * press button and keep it pressed (IMPORTANT) * plug in device -* run flash command `sudo client/flasher /dev/ttyACM0 armsrc/obj/fullimage.elf` +* run flash command `sudo client/proxmark3-flasher /dev/ttyACM0 armsrc/obj/fullimage.elf` * wait until flash is finished * release button * un/plug device diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index b4ed877cb..336d89fe1 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -4,13 +4,13 @@ Always use the latest repository commits from *master* branch. There are always many fixes done almost daily. -## `./proxmark.sh` or `./flash-*.sh` doesn't see my Proxmark +## `./proxmark3.sh` or `./proxmark3-flash-*.sh` doesn't see my Proxmark Try using directly the client or flasher: ``` -client/flasher ... -client/proxmark ... +client/proxmark3-flasher ... +client/proxmark3 ... ``` Refer to the installation guide specific to your OS for details about ports. @@ -35,8 +35,8 @@ The flasher refused to flash your Proxmark3? Are there any messages in *red*? Th ``` or ``` -client/flasher -b bootrom/obj/bootrom.elf -client/flasher armsrc/obj/fullimage.elf +client/proxmark3-flasher -b bootrom/obj/bootrom.elf +client/proxmark3-flasher armsrc/obj/fullimage.elf ``` ### Find out why it would be bricked @@ -57,7 +57,7 @@ Once in bootloader mode, flash the main image. ``` or ``` -client/flasher armsrc/obj/fullimage.elf +client/proxmark3-flasher armsrc/obj/fullimage.elf ``` You should be back on tracks now. In case the flasher complains about bootloader version, you can follow the button procedure and flash first your bootloader. @@ -67,7 +67,7 @@ You should be back on tracks now. In case the flasher complains about bootloader ``` or ``` -client/flasher -b bootrom/obj/bootrom.elf +client/proxmark3-flasher -b bootrom/obj/bootrom.elf ``` ### Ok, my bootloader is definitively dead, now what? @@ -98,14 +98,14 @@ Instructions evolve over time so check if you're still up to date! Depending how you launch the client, your working directory might be the root of the repository: ``` -./proxmark.sh ... -client/proxmark ... +./proxmark3.sh ... +client/proxmark3 ... ``` or the `client/` subdirectory: ``` -cd client; ./proxmark ... +cd client; ./proxmark3 ... ``` Therefore client commands referring to files of the repo must be adapted, e.g. diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 1df9e541b..f01e695e9 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -54,7 +54,7 @@ pacman -S mingw-w64-x86_64-astyle Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). -To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `client/flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. +To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `client/proxmark3-flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. To flash: In principle, the helper script `flash-all.sh` should auto-detect your COM port, so you can just try: @@ -65,7 +65,7 @@ To flash: In principle, the helper script `flash-all.sh` should auto-detect your If COM port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -client/flasher.exe comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3-flasher.exe comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: @@ -151,7 +151,7 @@ To flash: In principle, the helper script `flash-all.sh` should auto-detect your If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -client/flasher /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3-flasher /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: diff --git a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md index 7493fba1a..1e6b24b88 100644 --- a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md +++ b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md @@ -31,7 +31,7 @@ In most cases, you can run the script `flash-all.sh` which try to auto-detect th For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: ```sh -client/flasher /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3-flasher /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` ## Run the client From 3245260c009580c20eec57c0bdeb4c8972a154ce Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 22:10:06 +0200 Subject: [PATCH 208/347] Add Makefile.defs with common defs --- Makefile | 11 +--------- Makefile.defs | 42 ++++++++++++++++++++++++++++++++++++++ Makefile.host | 41 +++++++++++-------------------------- client/Makefile | 28 ++++--------------------- common_arm/Makefile.common | 40 ++++++++++++------------------------ 5 files changed, 72 insertions(+), 90 deletions(-) create mode 100644 Makefile.defs diff --git a/Makefile b/Makefile index f74932ccc..d2d4ca643 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,5 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 -CP = cp -a -GZIP=gzip -MKDIR = mkdir -p -RM = rm -f -RMDIR = rm -rf +include Makefile.defs -include Makefile.platform -include .Makefile.options.cache include common_arm/Makefile.hal diff --git a/Makefile.defs b/Makefile.defs new file mode 100644 index 000000000..d69b58b33 --- /dev/null +++ b/Makefile.defs @@ -0,0 +1,42 @@ +# Hide full compilation line: +ifneq ($(V),1) + Q?=@ +endif +# To see full command lines, use make V=1 + +# been here +DEFSBEENHERE = true + +CP = cp -a +GZIP = gzip +MKDIR = mkdir -p +RM = rm -f +RMDIR = rm -rf +MV = mv +TOUCH = touch +FALSE = false +TAR = tar +TARFLAGS ?= -v --ignore-failed-read -r +TARFLAGS += -C .. -f +CROSS ?= arm-none-eabi- +CC = gcc +CXX = g++ +LD = g++ + +PATHSEP=/ +PREFIX ?= /usr/local +INSTALLBINRELPATH = /bin/ +INSTALLSHARERELPATH = /share/proxmark3/ +INSTALLFWRELPATH = /share/proxmark3/firmware/ +INSTALLTOOLSRELPATH = /share/proxmark3/tools/ + +platform = $(shell uname) +DETECTED_OS=$(platform) + +ifeq ($(platform),Darwin) + AR= /usr/bin/ar rcs + RANLIB= /usr/bin/ranlib +else + AR= ar rcs + RANLIB= ranlib +endif diff --git a/Makefile.host b/Makefile.host index 861e697fb..8fb6fceed 100644 --- a/Makefile.host +++ b/Makefile.host @@ -1,36 +1,19 @@ -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ +# This Makefile might have been called from various subdirs, trying to find our Makefile.defs +ifeq ($(DEFSBEENHERE),) + -include Makefile.defs +endif +ifeq ($(DEFSBEENHERE),) + -include ../Makefile.defs +endif +ifeq ($(DEFSBEENHERE),) + -include ../../Makefile.defs +endif +ifeq ($(DEFSBEENHERE),) + $(error Can't find Makefile.defs) endif -# To see full command lines, use make V=1 - -INSTALLBINRELPATH = /bin/ -INSTALLTOOLSRELPATH = /share/proxmark3/tools/ - -CC = gcc -LD = gcc -RM = rm -f -MV = mv -CP = cp -a -MKDIR = mkdir -p -TOUCH = touch -FALSE = false CFLAGS ?= -Wall -Werror -O3 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES) -PREFIX ?= /usr/local - -platform = $(shell uname) - -ifeq ($(platform),Darwin) -AR= /usr/bin/ar rcs -RANLIB= /usr/bin/ranlib -else -AR= ar rcs -RANLIB= ranlib -endif -RM= rm -f -RMDIR= rm -rf vpath %.c $(MYSRCPATHS) diff --git a/client/Makefile b/client/Makefile index 5157e3e57..4c5d53c9c 100644 --- a/client/Makefile +++ b/client/Makefile @@ -9,34 +9,14 @@ # Add -DNOFORCE to disable the -F switch # Add -DPRESETS to compile with preset models (edit config.h) -# Hide full compilation line: -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 +# Must be called before any Makefile include +ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) + +include ../Makefile.defs -INSTALLBINRELPATH = /bin/ -INSTALLSHARERELPATH = /share/proxmark3/ INSTALLBIN = proxmark3 proxmark3-flasher INSTALLSHARE = lualibs luascripts resources dictionaries -CC = gcc -CXX = g++ -LD = g++ -TAR = tar -TARFLAGS ?= -v --ignore-failed-read -r -TARFLAGS += -C .. -f -RM = rm -f -RMDIR= rm -rf -MKDIR = mkdir -p -MV = mv -TOUCH = touch -FALSE = false -CP=cp -a - -platform = $(shell uname) -ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) - VPATH = ../common uart vpath %.dic dictionaries OBJDIR = obj diff --git a/common_arm/Makefile.common b/common_arm/Makefile.common index 5af77bcf7..52ec2ebd2 100644 --- a/common_arm/Makefile.common +++ b/common_arm/Makefile.common @@ -6,48 +6,34 @@ # Common makefile functions for all platforms #----------------------------------------------------------------------------- -# This new makefile replaces the previous Makefile/Makefile.linux -# with as much common code for both environments as possible. -# Following is a short OS detection to set up variables, all the -# remaining Makefile should be portable and only depend on these -# variables -# - -ifneq ($(V),1) - Q?=@ -endif -# To see full command lines, use make V=1 - # Make sure that all is the default target # (The including Makefile still needs to define what 'all' is) all: -platform = $(shell uname) -PREFIX?=/usr/local -INSTALLFWRELPATH = /share/proxmark3/firmware/ +# This Makefile might have been called from various subdirs, trying to find our Makefile.defs +ifeq ($(DEFSBEENHERE),) + -include Makefile.defs +endif +ifeq ($(DEFSBEENHERE),) + -include ../Makefile.defs +endif +ifeq ($(DEFSBEENHERE),) + -include ../../Makefile.defs +endif +ifeq ($(DEFSBEENHERE),) + $(error Can't find Makefile.defs) +endif -CROSS ?= arm-none-eabi- CC = $(CROSS)gcc AS = $(CROSS)as LD = $(CROSS)ld OBJCOPY = $(CROSS)objcopy -GZIP=gzip -MV=mv OBJDIR = obj INCLUDE = -I../include -I../common_arm -I../common_fpga -I../common -I. -TAR=tar -TARFLAGS = -C .. -rvf -RM=rm -f -RMDIR=rm -rf -CP=cp -a -MKDIR=mkdir -p -PATHSEP=/ -DETECTED_OS=$(platform) - # Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the zlib directory VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/zlib ../fpga ../armsrc/Standalone From f6a4f9cbe37a06101a4b99fe287c22c0a2375c5d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 22:11:02 +0200 Subject: [PATCH 209/347] move client scripts to tools --- {client => tools}/pm3_eml2lower.sh | 0 {client => tools}/pm3_eml2mfd.py | 0 {client => tools}/pm3_eml2upper.sh | 0 {client => tools}/pm3_eml_mfd_test.py | 0 {client => tools}/pm3_mfd2eml.py | 0 {client => tools}/pm3_mfdread.py | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {client => tools}/pm3_eml2lower.sh (100%) rename {client => tools}/pm3_eml2mfd.py (100%) rename {client => tools}/pm3_eml2upper.sh (100%) rename {client => tools}/pm3_eml_mfd_test.py (100%) rename {client => tools}/pm3_mfd2eml.py (100%) rename {client => tools}/pm3_mfdread.py (100%) diff --git a/client/pm3_eml2lower.sh b/tools/pm3_eml2lower.sh similarity index 100% rename from client/pm3_eml2lower.sh rename to tools/pm3_eml2lower.sh diff --git a/client/pm3_eml2mfd.py b/tools/pm3_eml2mfd.py similarity index 100% rename from client/pm3_eml2mfd.py rename to tools/pm3_eml2mfd.py diff --git a/client/pm3_eml2upper.sh b/tools/pm3_eml2upper.sh similarity index 100% rename from client/pm3_eml2upper.sh rename to tools/pm3_eml2upper.sh diff --git a/client/pm3_eml_mfd_test.py b/tools/pm3_eml_mfd_test.py similarity index 100% rename from client/pm3_eml_mfd_test.py rename to tools/pm3_eml_mfd_test.py diff --git a/client/pm3_mfd2eml.py b/tools/pm3_mfd2eml.py similarity index 100% rename from client/pm3_mfd2eml.py rename to tools/pm3_mfd2eml.py diff --git a/client/pm3_mfdread.py b/tools/pm3_mfdread.py similarity index 100% rename from client/pm3_mfdread.py rename to tools/pm3_mfdread.py From 7e579f9fca28ea730f7a49441bd0f998dfee949f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 22:13:51 +0200 Subject: [PATCH 210/347] rename SIMxxx.BIN in lowercase --- client/cmdsmartcard.c | 2 +- doc/cheatsheet.md | 2 +- doc/md/Installation_Instructions/Troubleshooting.md | 4 ++-- .../2_Configuration-and-Verification.md | 8 ++++---- tools/simmodule/{SIM010.BIN => sim010.bin} | Bin .../{SIM010.sha512.txt => sim010.sha512.txt} | 2 +- tools/simmodule/{SIM011.BIN => sim011.bin} | Bin .../{SIM011.sha512.txt => sim011.sha512.txt} | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) rename tools/simmodule/{SIM010.BIN => sim010.bin} (100%) rename tools/simmodule/{SIM010.sha512.txt => sim010.sha512.txt} (90%) rename tools/simmodule/{SIM011.BIN => sim011.bin} (100%) rename tools/simmodule/{SIM011.sha512.txt => sim011.sha512.txt} (90%) diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index d6606ad19..c9dde7063 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -69,7 +69,7 @@ static int usage_sm_upgrade(void) { PrintAndLogEx(NORMAL, " f : firmware file name"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " sc upgrade f ../tools/simmodule/SIM011.BIN"); + PrintAndLogEx(NORMAL, " sc upgrade f ../tools/simmodule/sim011.bin"); return 0; } static int usage_sm_setclock(void) { diff --git a/doc/cheatsheet.md b/doc/cheatsheet.md index 670ae1979..4a61ae7d2 100644 --- a/doc/cheatsheet.md +++ b/doc/cheatsheet.md @@ -522,7 +522,7 @@ pm3 --> mem load f iclass_default_keys i Upgrade Sim Module firmware ``` -pm3 --> sc upgrade f ../tools/simmodule/SIM011.BIN +pm3 --> sc upgrade f ../tools/simmodule/sim011.bin ``` ## Smart Card diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index 336d89fe1..19f1dbee7 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -111,9 +111,9 @@ cd client; ./proxmark3 ... Therefore client commands referring to files of the repo must be adapted, e.g. ``` -pm3 --> sc upgrade f tools/simmodule/SIM011.BIN +pm3 --> sc upgrade f tools/simmodule/sim011.bin <> -pm3 --> sc upgrade f ../tools/simmodule/SIM011.BIN +pm3 --> sc upgrade f ../tools/simmodule/sim011.bin ``` ``` diff --git a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md index 503c4b988..8ec176edb 100644 --- a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md +++ b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md @@ -32,21 +32,21 @@ Find version in the long output, look for these two lines This version is obsolete. -If you didn't download SIM011.bin from the RRG Repo be aware that it might be corrupted or faulty. +If you didn't download sim011.bin from the RRG Repo be aware that it might be corrupted or faulty. You find a hash text file in this folder. It was generated with the following linux command. ``` -sha512sum -b SIM011.bin > SIM011.sha512.txt +sha512sum -b sim011.bin > sim011.sha512.txt ``` -You should validate the SIM011.bin file against this hash file in order to be sure the file is not corrupted or faulty. +You should validate the sim011.bin file against this hash file in order to be sure the file is not corrupted or faulty. The following command upgrades your device sim module firmware. Don't not turn off your device during the execution of this command!! Even its a quite fast command you should be warned. You may brick it if you interrupt it. ``` -pm3 --> sc upgrade f ../tools/simmodule/SIM011.BIN +pm3 --> sc upgrade f ../tools/simmodule/sim011.bin ``` You get the following output if the execution was successful: diff --git a/tools/simmodule/SIM010.BIN b/tools/simmodule/sim010.bin similarity index 100% rename from tools/simmodule/SIM010.BIN rename to tools/simmodule/sim010.bin diff --git a/tools/simmodule/SIM010.sha512.txt b/tools/simmodule/sim010.sha512.txt similarity index 90% rename from tools/simmodule/SIM010.sha512.txt rename to tools/simmodule/sim010.sha512.txt index b7bab7246..0b3e6b438 100644 --- a/tools/simmodule/SIM010.sha512.txt +++ b/tools/simmodule/sim010.sha512.txt @@ -1 +1 @@ -e6ac5e6f1d7cc86d56f2128f2a495f1395fe044bf6ff3b6ca24ce90d1e361ae835fe273a206f2fc90e4344a13b37b180dd017a2c7f23312f1ed163f10c01ea5a *SIM010.BIN +e6ac5e6f1d7cc86d56f2128f2a495f1395fe044bf6ff3b6ca24ce90d1e361ae835fe273a206f2fc90e4344a13b37b180dd017a2c7f23312f1ed163f10c01ea5a *sim010.bin diff --git a/tools/simmodule/SIM011.BIN b/tools/simmodule/sim011.bin similarity index 100% rename from tools/simmodule/SIM011.BIN rename to tools/simmodule/sim011.bin diff --git a/tools/simmodule/SIM011.sha512.txt b/tools/simmodule/sim011.sha512.txt similarity index 90% rename from tools/simmodule/SIM011.sha512.txt rename to tools/simmodule/sim011.sha512.txt index 54a8bfd09..23ee6875f 100644 --- a/tools/simmodule/SIM011.sha512.txt +++ b/tools/simmodule/sim011.sha512.txt @@ -1 +1 @@ -752f9d8af3db214a797bacb7362a0b53eff4dd3793853e467047b7d36ddae9d1b4a050d9136225a48830d9c70bbad791f89d05553b0453f004b7bbcdc337e658 *SIM011.BIN +752f9d8af3db214a797bacb7362a0b53eff4dd3793853e467047b7d36ddae9d1b4a050d9136225a48830d9c70bbad791f89d05553b0453f004b7bbcdc337e658 *sim011.bin From 742b62502e233b1aa7fd286741a1d9d8ee9e00ad Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 22:29:01 +0200 Subject: [PATCH 211/347] make install, second half --- Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile.defs | 4 ++++ 2 files changed, 55 insertions(+) diff --git a/Makefile b/Makefile index d2d4ca643..92e53cb93 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,57 @@ endif all clean install uninstall: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% fpga_compress/% +INSTALLTOOLS=pm3_eml2lower.sh pm3_eml2upper.sh pm3_mfdread.py pm3_mfd2eml.py pm3_eml2mfd.py findbits.py rfidtest.pl xorcheck.py +INSTALLSIMFW=sim011.bin sim011.sha512.txt + +install: all + $(info [@] Installing common resources to $(MYDESTDIR)$(PREFIX)...) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) + # TODO scripts must be adapted, they're currently broken + $(Q)$(CP) proxmark3.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3 + $(Q)$(CP) flash-all.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-all + $(Q)$(CP) flash-bootrom.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-bootrom + $(Q)$(CP) flash-fullimage.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-fullimage + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(CP) tools/jtag_openocd $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(CP) traces $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLDOCRELPATH) + $(Q)$(CP) doc/* $(DESTDIR)$(PREFIX)$(INSTALLDOCRELPATH) +ifneq (,$(INSTALLTOOLS)) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) + $(Q)$(CP) $(foreach tool,$(INSTALLTOOLS),tools/$(tool)) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) +endif +ifneq (,$(INSTALLSIMFW)) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(foreach fw,$(INSTALLSIMFW),tools/simmodule/$(fw)) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) +endif +ifeq ($(platform),Linux) + $(Q)$(MKDIR) $(DESTDIR)$(UDEV_PREFIX) + $(Q)$(CP) driver/77-pm3-usb-device-blacklist.rules $(DESTDIR)$(UDEV_PREFIX)/77-pm3-usb-device-blacklist.rules +endif + +uninstall: + $(info [@] Uninstalling common resources from $(MYDESTDIR)$(PREFIX)...) + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3 + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-all + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-bootrom + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-fullimage + $(Q)$(RMDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)/jtag_openocd + $(Q)$(RMDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)/traces + $(Q)$(RMDIR) $(DESTDIR)$(PREFIX)$(INSTALLDOCRELPATH) +ifneq (,$(INSTALLTOOLS)) + $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH)$(notdir $(tool))) +endif + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) +ifneq (,$(INSTALLSIMFW)) + $(Q)$(RM) $(foreach fw,$(INSTALLSIMFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) +endif + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) +ifeq ($(platform),Linux) + $(Q)$(RM) $(DESTDIR)$(UDEV_PREFIX)/77-pm3-usb-device-blacklist.rules +endif + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + mfkey/%: FORCE $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) DESTDIR=$(MYDESTDIR) diff --git a/Makefile.defs b/Makefile.defs index d69b58b33..3f12cacb3 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -12,6 +12,8 @@ GZIP = gzip MKDIR = mkdir -p RM = rm -f RMDIR = rm -rf +# rmdir only if dir is empty, tolerate failure +RMDIR_SOFT = -rmdir MV = mv TOUCH = touch FALSE = false @@ -25,10 +27,12 @@ LD = g++ PATHSEP=/ PREFIX ?= /usr/local +UDEV_PREFIX ?= /etc/udev/rules.d INSTALLBINRELPATH = /bin/ INSTALLSHARERELPATH = /share/proxmark3/ INSTALLFWRELPATH = /share/proxmark3/firmware/ INSTALLTOOLSRELPATH = /share/proxmark3/tools/ +INSTALLDOCRELPATH = /share/doc/proxmark3/ platform = $(shell uname) DETECTED_OS=$(platform) From 595fde53126bf61f79565367ed2b545a9b2509ed Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 23:35:29 +0200 Subject: [PATCH 212/347] update scripts to work with make install --- Makefile | 39 +++++++++++++++++++++++---------------- Makefile.defs | 2 +- flash-all.sh | 5 ----- flash-bootrom.sh | 5 ----- flash-fullimage.sh | 5 ----- proxmark3.sh => pm3 | 39 +++++++++++++++++++++++++++------------ pm3-flash-all | 4 ++++ pm3-flash-bootrom | 4 ++++ pm3-flash-fullimage | 4 ++++ 9 files changed, 63 insertions(+), 44 deletions(-) delete mode 100755 flash-all.sh delete mode 100755 flash-bootrom.sh delete mode 100755 flash-fullimage.sh rename proxmark3.sh => pm3 (66%) create mode 100755 pm3-flash-all create mode 100755 pm3-flash-bootrom create mode 100755 pm3-flash-fullimage diff --git a/Makefile b/Makefile index 92e53cb93..79d9a2ff8 100644 --- a/Makefile +++ b/Makefile @@ -18,20 +18,24 @@ all clean install uninstall: %: client/% bootrom/% armsrc/% recovery/% mfkey/% n INSTALLTOOLS=pm3_eml2lower.sh pm3_eml2upper.sh pm3_mfdread.py pm3_mfd2eml.py pm3_eml2mfd.py findbits.py rfidtest.pl xorcheck.py INSTALLSIMFW=sim011.bin sim011.sha512.txt +INSTALLSCRIPTS=pm3 pm3-flash-all pm3-flash-bootrom pm3-flash-fullimage +INSTALLSHARES=tools/jtag_openocd traces +INSTALLDOCS=doc/*.md doc/md install: all $(info [@] Installing common resources to $(MYDESTDIR)$(PREFIX)...) +ifneq (,$(INSTALLSCRIPTS)) $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) - # TODO scripts must be adapted, they're currently broken - $(Q)$(CP) proxmark3.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3 - $(Q)$(CP) flash-all.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-all - $(Q)$(CP) flash-bootrom.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-bootrom - $(Q)$(CP) flash-fullimage.sh $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-fullimage + $(Q)$(CP) $(INSTALLSCRIPTS) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) +endif +ifneq (,$(INSTALLSHARES)) $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) - $(Q)$(CP) tools/jtag_openocd $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) - $(Q)$(CP) traces $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLDOCRELPATH) - $(Q)$(CP) doc/* $(DESTDIR)$(PREFIX)$(INSTALLDOCRELPATH) + $(Q)$(CP) $(INSTALLSHARES) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) +endif +ifneq (,$(INSTALLDOCS)) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH) + $(Q)$(CP) $(INSTALLDOCS) $(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH) +endif ifneq (,$(INSTALLTOOLS)) $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) $(Q)$(CP) $(foreach tool,$(INSTALLTOOLS),tools/$(tool)) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) @@ -47,13 +51,16 @@ endif uninstall: $(info [@] Uninstalling common resources from $(MYDESTDIR)$(PREFIX)...) - $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3 - $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-all - $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-bootrom - $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)/pm3-flash-fullimage - $(Q)$(RMDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)/jtag_openocd - $(Q)$(RMDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)/traces - $(Q)$(RMDIR) $(DESTDIR)$(PREFIX)$(INSTALLDOCRELPATH) +ifneq (,$(INSTALLSCRIPTS)) + $(Q)$(RM) $(foreach script,$(INSTALLSCRIPTS),$(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)$(notdir $(script))) +endif +ifneq (,$(INSTALLSHARES)) + $(Q)$(RMDIR) $(foreach share,$(INSTALLSHARES),$(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)$(notdir $(share))) +endif +ifneq (,$(INSTALLDOCS)) + $(Q)$(RMDIR) $(foreach doc,$(INSTALLDOCS),$(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH)$(notdir $(doc))) + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH) +endif ifneq (,$(INSTALLTOOLS)) $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH)$(notdir $(tool))) endif diff --git a/Makefile.defs b/Makefile.defs index 3f12cacb3..6364c794a 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -32,7 +32,7 @@ INSTALLBINRELPATH = /bin/ INSTALLSHARERELPATH = /share/proxmark3/ INSTALLFWRELPATH = /share/proxmark3/firmware/ INSTALLTOOLSRELPATH = /share/proxmark3/tools/ -INSTALLDOCRELPATH = /share/doc/proxmark3/ +INSTALLDOCSRELPATH = /share/doc/proxmark3/ platform = $(shell uname) DETECTED_OS=$(platform) diff --git a/flash-all.sh b/flash-all.sh deleted file mode 100755 index d4fcdc975..000000000 --- a/flash-all.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -PM3PATH=$(dirname "$0") -cd "$PM3PATH" || exit 1 -. proxmark3.sh diff --git a/flash-bootrom.sh b/flash-bootrom.sh deleted file mode 100755 index d4fcdc975..000000000 --- a/flash-bootrom.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -PM3PATH=$(dirname "$0") -cd "$PM3PATH" || exit 1 -. proxmark3.sh diff --git a/flash-fullimage.sh b/flash-fullimage.sh deleted file mode 100755 index d4fcdc975..000000000 --- a/flash-fullimage.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -PM3PATH=$(dirname "$0") -cd "$PM3PATH" || exit 1 -. proxmark3.sh diff --git a/proxmark3.sh b/pm3 similarity index 66% rename from proxmark3.sh rename to pm3 index 89e7e960b..11eb59d31 100755 --- a/proxmark3.sh +++ b/pm3 @@ -1,10 +1,25 @@ #!/bin/bash -FULLIMAGE="armsrc/obj/fullimage.elf" -BOOTIMAGE="bootrom/obj/bootrom.elf" - PM3PATH=$(dirname "$0") -cd "$PM3PATH" || exit 1 +# try pm3 dirs in current repo workdir +if [ -d "$PM3PATH/client/" ]; then + CLIENT="$PM3PATH/client/proxmark3" + FLASHER="$PM3PATH/client/proxmark3-flasher" + FULLIMAGE="$PM3PATH/armsrc/obj/fullimage.elf" + BOOTIMAGE="$PM3PATH/bootrom/obj/bootrom.elf" +# try install dir +elif [ -x "$PM3PATH/proxmark3" ]; then + CLIENT="$PM3PATH/proxmark3" + FLASHER="$PM3PATH/proxmark3-flasher" + FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf" + BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf" +else +# hope it's installed somehow, still not sure where fw images are... + CLIENT="proxmark3" + FLASHER="proxmark3-flasher" + FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf" + BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf" +fi function wait4proxmark_Linux { echo >&2 "[=] Waiting for Proxmark3 to appear..." @@ -63,14 +78,14 @@ function wait4proxmark_WSL { SCRIPT=$(basename -- "$0") -if [ "$SCRIPT" = "proxmark3.sh" ]; then - CMD() { client/proxmark3 "$@"; } -elif [ "$SCRIPT" = "flash-all.sh" ]; then - CMD() { client/flasher "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; } -elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then - CMD() { client/flasher "$1" "$FULLIMAGE"; } -elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then - CMD() { client/flasher "$1" -b "$BOOTIMAGE"; } +if [ "$SCRIPT" = "pm3" ]; then + CMD() { $CLIENT "$@"; } +elif [ "$SCRIPT" = "pm3-flash-all" ]; then + CMD() { $FLASHER "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; } +elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then + CMD() { $FLASHER "$1" "$FULLIMAGE"; } +elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then + CMD() { $FLASHER "$1" -b "$BOOTIMAGE"; } else echo "[!!] Script ran under unknown name, abort: $SCRIPT" exit 1 diff --git a/pm3-flash-all b/pm3-flash-all new file mode 100755 index 000000000..e5cd5479d --- /dev/null +++ b/pm3-flash-all @@ -0,0 +1,4 @@ +#!/bin/bash + +PM3PATH=$(dirname "$0") +. "$PM3PATH/pm3" diff --git a/pm3-flash-bootrom b/pm3-flash-bootrom new file mode 100755 index 000000000..e5cd5479d --- /dev/null +++ b/pm3-flash-bootrom @@ -0,0 +1,4 @@ +#!/bin/bash + +PM3PATH=$(dirname "$0") +. "$PM3PATH/pm3" diff --git a/pm3-flash-fullimage b/pm3-flash-fullimage new file mode 100755 index 000000000..e5cd5479d --- /dev/null +++ b/pm3-flash-fullimage @@ -0,0 +1,4 @@ +#!/bin/bash + +PM3PATH=$(dirname "$0") +. "$PM3PATH/pm3" From ddd32bcb4bbcfa26cbe77719f97588ce3261749a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 23:53:13 +0200 Subject: [PATCH 213/347] Maintainers.md --- doc/md/Development/Maintainers.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 doc/md/Development/Maintainers.md diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md new file mode 100644 index 000000000..9472cacb6 --- /dev/null +++ b/doc/md/Development/Maintainers.md @@ -0,0 +1,31 @@ +Hi maintainers! + +Here are some tips how to integrate this repo in some nice package for your distro. +Feel free to contact us via Github issues for any question, suggestion or if you want to share useful tricks in this file for other maintainers. + +Makefile +======== + +`PREFIX` and `UDEV_PREFIX` can be provided by environment variable, else it defaults to `/usr/local/share` and `/etc/udev/rules.d`. + +`DESTDIR` can be provided by environment variable, it can be a relative path and it will be prepended to `PREFIX`, so you can use e.g.: + +`make install DESTDIR=build PREFIX=/usr UDEV_PREFIX=/lib/udev/rules.d` + +and it will be deployed as + +``` +./build/lib/udev/rules.d/77-pm3-usb-device-blacklist.rules +./build/usr/bin/proxmark3 ... +./build/usr/share/doc/proxmark3/... +./build/usr/share/proxmark3/... +``` + +That should be a good start for you to create your package :) + +For verbose usage and see the actual commands being executed, add `V=1`. + +`CFLAGS` and `LDFLAGS` can be overriden by environment variables. + +Default compiler is gcc but you can use clang for the non-ARM parts with e.g. `make client CC=clang CXX=clang++ LD=clang++`. + From 6949a780fc6928f8dfd12b09484bfdfb5c8db56d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 31 Aug 2019 00:26:35 +0200 Subject: [PATCH 214/347] Add possibility to make install more firmware variants --- Makefile | 2 ++ armsrc/Makefile | 10 ++++++++-- doc/md/Development/Maintainers.md | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 79d9a2ff8..43de3969b 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,8 @@ fullimage: armsrc/all fullimage/clean: armsrc/clean +fullimage/install: armsrc/install + recovery: recovery/all mfkey: mfkey/all diff --git a/armsrc/Makefile b/armsrc/Makefile index 8cbe03dab..bb8f17ef2 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -135,6 +135,12 @@ include ../common_arm/Makefile.common COMMON_FLAGS = -Os INSTALLFW = $(OBJDIR)/fullimage.elf +ifneq (,$(FWTAG)) + INSTALLFWTAG = $(notdir $(INSTALLFW:%.elf=%-$(FWTAG).elf)) +else + INSTALLFWTAG = $(notdir $(INSTALLFW)) +endif + OBJS = $(OBJDIR)/fullimage.s19 FPGA_COMPRESSOR = ../tools/fpga_compress/fpga_compress @@ -217,11 +223,11 @@ clean: install: all $(info [@] Installing fullimage to $(DESTDIR)$(PREFIX)...) $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) - $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) uninstall: $(info [@] Uninstalling fullimage from $(DESTDIR)$(PREFIX)...) - $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) .PHONY: all clean help install uninstall help: diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index 9472cacb6..542512fd0 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -10,7 +10,7 @@ Makefile `DESTDIR` can be provided by environment variable, it can be a relative path and it will be prepended to `PREFIX`, so you can use e.g.: -`make install DESTDIR=build PREFIX=/usr UDEV_PREFIX=/lib/udev/rules.d` +`make -j install DESTDIR=build PREFIX=/usr UDEV_PREFIX=/lib/udev/rules.d` and it will be deployed as @@ -18,11 +18,22 @@ and it will be deployed as ./build/lib/udev/rules.d/77-pm3-usb-device-blacklist.rules ./build/usr/bin/proxmark3 ... ./build/usr/share/doc/proxmark3/... -./build/usr/share/proxmark3/... +./build/usr/share/proxmark3/firmware/fullimage.elf +etc. ``` That should be a good start for you to create your package :) +It's possible to add other firmwares as well with tagged names (`FWTAG=`), e.g. here we're compiling another image for non-RDV4 devices: + +`make -j fullimage/install DESTDIR=build PREFIX=/usr PLATFORM=PM3OTHER PLATFORM_EXTRAS= FWTAG=other` + +and it will be added along the other firmware as: + +``` +./build/usr/share/proxmark3/firmware/fullimage-other.elf +``` + For verbose usage and see the actual commands being executed, add `V=1`. `CFLAGS` and `LDFLAGS` can be overriden by environment variables. From 555c0743cb044390dc59d2a086a4f4be6ef48345 Mon Sep 17 00:00:00 2001 From: edward-p Date: Sat, 31 Aug 2019 15:31:33 +0800 Subject: [PATCH 215/347] Add possibility to make install more recovery variants --- recovery/Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/recovery/Makefile b/recovery/Makefile index fd10020bf..5a5fda0e8 100644 --- a/recovery/Makefile +++ b/recovery/Makefile @@ -1,6 +1,12 @@ include ../common_arm/Makefile.common INSTALLFW = proxmark3_recovery.bin +ifneq (,$(FWTAG)) + INSTALLFWTAG = $(notdir $(INSTALLFW:%.bin=%-$(FWTAG).bin)) +else + INSTALLFWTAG = $(notdir $(INSTALLFW)) +endif + BINS = bootrom.bin fullimage.bin $(INSTALLFW) all: $(BINS) @@ -23,10 +29,10 @@ clean: install: all $(info [@] Installing recovery to $(DESTDIR)$(PREFIX)...) $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) - $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) uninstall: $(info [@] Uninstalling recovery from $(DESTDIR)$(PREFIX)...) - $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) .PHONY: all clean install uninstall From 66c8b31e65660e8d871129040a0382551281d9c9 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sat, 31 Aug 2019 10:55:38 +0200 Subject: [PATCH 216/347] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2515cb6ec..97dadaabb 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. |[Why didn't you base it on official Proxmark3 Master?](#why-didnt-you-base-it-on-official-proxmark3-master)| [Homebrew (Mac OS X) & Upgrading HomeBrew Tap Formula](/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md) | [First Use and Verification](/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md)| |[Proxmark3 GUI](#proxmark3-gui)|[Setup and build for Windows](/doc/md/Installation_Instructions/Windows-Installation-Instructions.md)|[Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| |[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) |[Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md)| -|[Notes on UART](/doc/uart_notes.md)||[Command Cheat sheet](/doc/cheatsheet.md)| +|[Notes on UART](/doc/uart_notes.md)|[Maintainers](/doc/md/Development/Maintainers.md)|[Command Cheat sheet](/doc/cheatsheet.md)| |[Notes on Frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| |[Notes on external flash](/doc/ext_flash_notes.md)||| |[Notes on Termux / Android](/doc/termux_notes.md)||| From c5c5427f9edeae94786332c3ebc62eda72dcd080 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sat, 31 Aug 2019 10:58:42 +0200 Subject: [PATCH 217/347] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 97dadaabb..37b53a95c 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,10 @@ If you intend to contribute to the code, please read the [coding style notes](HA ## Cheat sheet Thanks to Alex Dibs, you can enjoy a [command cheat sheet](/doc/cheatsheet.md) +## Maintainers ( package, distro ) +To all distro, package maintainers, we tried to make your life easier. `make install` is now available and if you want to know more. +- [Maintainers](/doc/md/Development/Maintainers.md) + ## Why didn't you base it on official Proxmark3 Master? The separation from official Proxmark3 repo gives us a lot of freedom to create a firmware/client that suits the RDV40 features. We don't want to mess up the official Proxmark3 repo with RDV40 specific code. From 3c515e8ec545ac101d76f5f31cf682b86d3f6507 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sat, 31 Aug 2019 10:59:21 +0200 Subject: [PATCH 218/347] Update Maintainers.md --- doc/md/Development/Maintainers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index 542512fd0..758a4a41d 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -1,4 +1,4 @@ -Hi maintainers! +# Hi maintainers! Here are some tips how to integrate this repo in some nice package for your distro. Feel free to contact us via Github issues for any question, suggestion or if you want to share useful tricks in this file for other maintainers. From 5ff9cbaac0c1b52c248cd1ed6ffc41ddd089e6ee Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 31 Aug 2019 15:25:36 +0200 Subject: [PATCH 219/347] fix: 'hf iclass eload' - load file works again. --- client/cmdhficlass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 39fbf9658..26e23d170 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -735,7 +735,7 @@ static int CmdHFiClassELoad(const char *Cmd) { switch (dftype) { case BIN: { - res = loadFile(filename, ".bin", (void *)&dump, 2048, &bytes_read); + res = loadFile_safe(filename, ".bin", (void **)&dump, &bytes_read); break; } case EML: { From b792d0d51b164ec206bce905b480371e58cc34bf Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 31 Aug 2019 19:57:49 +0200 Subject: [PATCH 220/347] make -j install fails from now, do make -j; make install --- doc/md/Development/Maintainers.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index 758a4a41d..b59987881 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -10,7 +10,10 @@ Makefile `DESTDIR` can be provided by environment variable, it can be a relative path and it will be prepended to `PREFIX`, so you can use e.g.: -`make -j install DESTDIR=build PREFIX=/usr UDEV_PREFIX=/lib/udev/rules.d` +``` +make -j +make install DESTDIR=build PREFIX=/usr UDEV_PREFIX=/lib/udev/rules.d +``` and it will be deployed as From 3352904f1d08dcc76424c64b3b9bcc67a53356ed Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 31 Aug 2019 21:47:31 +0200 Subject: [PATCH 221/347] chg 'mem spiffs load' - use loadfile_safe --- client/cmdflashmemspiffs.c | 40 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/client/cmdflashmemspiffs.c b/client/cmdflashmemspiffs.c index 5783e2705..0eef78259 100644 --- a/client/cmdflashmemspiffs.c +++ b/client/cmdflashmemspiffs.c @@ -330,12 +330,15 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) { if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { PrintAndLogEx(FAILED, "Filename too long"); errors = true; - break; } cmdp += 2; break; case 'o': param_getstr(Cmd, cmdp + 1, destfilename, 32); + if (strlen(destfilename) == 0) { + PrintAndLogEx(FAILED, "Destination Filename missing or invalid"); + errors = true; + } cmdp += 2; break; default: @@ -345,42 +348,20 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) { } } - if (destfilename[0] == '\0') { - PrintAndLogEx(FAILED, "Destination Filename missing or invalid"); - errors = true; - } - // Validations - if (errors || cmdp == 0) { - usage_flashmemspiffs_load(); - return PM3_EINVARG; - } + if (errors || cmdp == 0) + return usage_flashmemspiffs_load(); size_t datalen = 0; - int res = 0; - uint8_t *data = calloc(FLASH_MEM_MAX_SIZE, sizeof(uint8_t)); + uint8_t *data = NULL; - res = loadFile(filename, "", data, FLASH_MEM_MAX_SIZE, &datalen); + int res = loadFile_safe(filename, "", (void**)&data, &datalen); // int res = loadFileEML( filename, data, &datalen); - if (res) { + if (res != PM3_SUCCESS) { free(data); return PM3_EFILE; } - - if (datalen > FLASH_MEM_MAX_SIZE) { - PrintAndLogEx(ERR, "error, filesize is larger than available memory"); - free(data); - return PM3_EOVFLOW; - } - - uint8_t *newdata = realloc(data, datalen); - if (newdata == NULL) { - free(data); - return PM3_EMALLOC; - } else { - data = newdata; - } - + // We want to mount before multiple operation so the lazy writes/append will not // trigger a mount + umount each loop iteration (lazy ops device side) SendCommandNG(CMD_SPIFFS_MOUNT, NULL, 0); @@ -425,6 +406,7 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) { if (!isok) { conn.block_after_ACK = false; PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent); + free(data); return PM3_EFLASH; } } From f1d31f1e4328d9eb5a2db20ac03b0abe34a41d20 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 31 Aug 2019 21:49:59 +0200 Subject: [PATCH 222/347] chg: 'mem load' - use loadxxxx_safe method --- client/cmdflashmem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 7f1fa103e..0fb25fad9 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -209,9 +209,8 @@ static int CmdFlashMemLoad(const char *Cmd) { datalen += 2; break; case DICTIONARY_NONE: - res = loadFile(filename, ".bin", data, FLASH_MEM_MAX_SIZE, &datalen); - //int res = loadFileEML( filename, data, &datalen); - if (res) { + res = loadFile_safe(filename, ".bin", (void**)&data, &datalen); + if (res != PM3_SUCCESS) { free(data); return PM3_EFILE; } @@ -223,7 +222,7 @@ static int CmdFlashMemLoad(const char *Cmd) { } break; } - +// not needed when we transite to loadxxxx_safe methods.(iceman) uint8_t *newdata = realloc(data, datalen); if (newdata == NULL) { free(data); From d4e8ac27a3edf7cdfa925463ab7f6ebf08d6bc0d Mon Sep 17 00:00:00 2001 From: Oleg Moiseenko <807634+merlokk@users.noreply.github.com> Date: Sun, 1 Sep 2019 00:56:24 +0300 Subject: [PATCH 223/347] appveyor make install (#383) --- appveyor.yml | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 1c4cc5ae5..fa8776607 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -200,45 +200,31 @@ build_script: } - #copy + #install - Write-Host "Copy release files..." -NoNewLine -ForegroundColor Yellow + Write-Host "Installing..." -NoNewLine -ForegroundColor Yellow - New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release + New-Item -ItemType Directory -Force -Path C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\pm3\client\*.exe C:\ProxSpace\Release - - New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\arm - - Copy-Item C:\ProxSpace\pm3\armsrc\obj\*.elf C:\ProxSpace\Release\arm - - Copy-Item C:\ProxSpace\pm3\bootrom\obj\*.elf C:\ProxSpace\Release\arm - - New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\luascripts - - Copy-Item C:\ProxSpace\pm3\client\luascripts\*.lua C:\ProxSpace\Release\luascripts - - New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\hardnested\tables - - Copy-Item C:\ProxSpace\pm3\client\resources\hardnested_tables\*.bin.z C:\ProxSpace\Release\hardnested\tables + bash -c -i 'make install DESTDIR=Release PREFIX= UDEV_PREFIX=\udev\rules.d' # dll files - Copy-Item C:\ProxSpace\msys2\mingw32\bin\libgcc_s_dw2-1.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\libgcc_s_dw2-1.dll C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\msys2\mingw32\bin\libstdc++-6.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\libstdc++-6.dll C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\msys2\mingw32\bin\libwinpthread-1.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\libwinpthread-1.dll C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\msys2\mingw32\bin\Qt5Core.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\Qt5Core.dll C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\msys2\mingw32\bin\Qt5Gui.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\Qt5Gui.dll C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\msys2\mingw32\bin\Qt5Widgets.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\Qt5Widgets.dll C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\msys2\mingw32\bin\libreadline*.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\libreadline*.dll C:\ProxSpace\pm3\Release\bin - Copy-Item C:\ProxSpace\msys2\mingw32\bin\libtermcap-0.dll C:\ProxSpace\Release + Copy-Item C:\ProxSpace\msys2\mingw32\bin\libtermcap-0.dll C:\ProxSpace\pm3\Release\bin Write-Host "[ OK ]" -ForegroundColor Green @@ -260,7 +246,7 @@ build_script: cd C:\ProxSpace - 7z a release.zip C:\ProxSpace\Release + 7z a release.zip C:\ProxSpace\pm3\Release Push-AppveyorArtifact release.zip -DeploymentName "$releasename" @@ -366,13 +352,13 @@ test_script: #file test - ExecTest "proxmark3 exists" "proxmark3.exe" {Test-Path C:\ProxSpace\Release\proxmark3.exe} + ExecTest "proxmark3 exists" "proxmark3.exe" {Test-Path C:\ProxSpace\pm3\Release\bin\proxmark3.exe} - ExecTest "arm image exists" "\arm\fullimage1.elf" {Test-Path C:\ProxSpace\Release\arm\fullimage.elf} + ExecTest "arm image exists" "pm3-flash-fullimage" {Test-Path C:\ProxSpace\pm3\Release\bin\pm3-flash-fullimage} - ExecTest "bootrom exists" "bootrom.elf" {Test-Path C:\ProxSpace\Release\arm\bootrom.elf} + ExecTest "bootrom exists" "pm3-flash-bootrom" {Test-Path C:\ProxSpace\pm3\Release\bin\pm3-flash-bootrom} - ExecTest "hardnested tables exists" "hardnested" {Test-Path C:\ProxSpace\Release\hardnested\tables\*.z} + ExecTest "hardnested tables exists" "hardnested" {Test-Path C:\ProxSpace\pm3\Release\share\proxmark3\resources\hardnested_tables\*.z} ExecTest "release exists" "release.zip" {Test-Path C:\ProxSpace\release.zip} From b4400bbcecea28eabddcdac1f9e6d209e0ca3ff0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 12:09:31 +0200 Subject: [PATCH 224/347] appveyor: no udev on windows, fix check fw images --- appveyor.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index fa8776607..af725ef93 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -206,8 +206,8 @@ build_script: New-Item -ItemType Directory -Force -Path C:\ProxSpace\pm3\Release\bin - bash -c -i 'make install DESTDIR=Release PREFIX= UDEV_PREFIX=\udev\rules.d' - + bash -c -i 'make install DESTDIR=Release PREFIX=' + # dll files Copy-Item C:\ProxSpace\msys2\mingw32\bin\libgcc_s_dw2-1.dll C:\ProxSpace\pm3\Release\bin @@ -354,9 +354,11 @@ test_script: ExecTest "proxmark3 exists" "proxmark3.exe" {Test-Path C:\ProxSpace\pm3\Release\bin\proxmark3.exe} - ExecTest "arm image exists" "pm3-flash-fullimage" {Test-Path C:\ProxSpace\pm3\Release\bin\pm3-flash-fullimage} + ExecTest "arm bootrom exists" "bootrom.elf" {Test-Path C:\ProxSpace\pm3\Release\share\proxmark3\firmware\bootrom.elf} - ExecTest "bootrom exists" "pm3-flash-bootrom" {Test-Path C:\ProxSpace\pm3\Release\bin\pm3-flash-bootrom} + ExecTest "arm image exists" "fullimage.elf" {Test-Path C:\ProxSpace\pm3\Release\share\proxmark3\firmware\fullimage.elf} + + ExecTest "arm recovery image exists" "proxmark3_recovery.bin" {Test-Path C:\ProxSpace\pm3\Release\share\proxmark3\firmware\proxmark3_recovery.bin} ExecTest "hardnested tables exists" "hardnested" {Test-Path C:\ProxSpace\pm3\Release\share\proxmark3\resources\hardnested_tables\*.z} From 3cedaf450d961bbf72dd49fb59839d382bb5efa3 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sun, 1 Sep 2019 18:05:23 +0200 Subject: [PATCH 225/347] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37b53a95c..74ee01f37 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. |[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) |[Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md)| |[Notes on UART](/doc/uart_notes.md)|[Maintainers](/doc/md/Development/Maintainers.md)|[Command Cheat sheet](/doc/cheatsheet.md)| |[Notes on Frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| -|[Notes on external flash](/doc/ext_flash_notes.md)||| +|[Notes on external flash](/doc/ext_flash_notes.md)||[EMV](/doc/emv_notes.md)| |[Notes on Termux / Android](/doc/termux_notes.md)||| |[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||| |[Notes on loclass](/doc/loclass_notes.md)||| @@ -62,6 +62,7 @@ If you intend to contribute to the code, please read the [coding style notes](HA - Internal notes on [Termux / Android](/doc/termux_notes.md) - Internal notes on [Wireshark / tracedata](/doc/trace_wireshark_notes.md) - Internal notes on [loclass](/doc/loclass_notes.md) +- Internal notes on [EMV](/doc/emv_notes.md) ## Cheat sheet Thanks to Alex Dibs, you can enjoy a [command cheat sheet](/doc/cheatsheet.md) From 854374a344d4e22cfd10a6fe1b78219e76437806 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sun, 1 Sep 2019 18:07:57 +0200 Subject: [PATCH 226/347] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 74ee01f37..7acb362a3 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. |[Notes on UART](/doc/uart_notes.md)|[Maintainers](/doc/md/Development/Maintainers.md)|[Command Cheat sheet](/doc/cheatsheet.md)| |[Notes on Frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| |[Notes on external flash](/doc/ext_flash_notes.md)||[EMV](/doc/emv_notes.md)| -|[Notes on Termux / Android](/doc/termux_notes.md)||| +|[Notes on Termux / Android](/doc/termux_notes.md)||[Troubleshooting](/doc/md/Installation_Instructions/Troubleshooting.md)| |[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||| |[Notes on loclass](/doc/loclass_notes.md)||| |[Developing standalone mode](/armsrc/Standalone/readme.md)|[Wiki about standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) || From a8d2f395e2490bccce13e5b29234b9ddd7e1b5e0 Mon Sep 17 00:00:00 2001 From: Iceman Date: Sun, 1 Sep 2019 18:09:10 +0200 Subject: [PATCH 227/347] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7acb362a3..26a1ae126 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. |[Notes on Frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| |[Notes on external flash](/doc/ext_flash_notes.md)||[EMV](/doc/emv_notes.md)| |[Notes on Termux / Android](/doc/termux_notes.md)||[Troubleshooting](/doc/md/Installation_Instructions/Troubleshooting.md)| -|[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||| +|[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||[JTAG](/doc/jtag_notes.md)| |[Notes on loclass](/doc/loclass_notes.md)||| |[Developing standalone mode](/armsrc/Standalone/readme.md)|[Wiki about standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) || |[Donations](#Donations)||| From e80fe2588b3df5d0a1e699c2ff0a750f32b64c16 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 19:30:29 +0200 Subject: [PATCH 228/347] "which" not always available... --- tools/mkversion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mkversion.sh b/tools/mkversion.sh index b91eab8af..f839f6e18 100755 --- a/tools/mkversion.sh +++ b/tools/mkversion.sh @@ -14,7 +14,7 @@ fullgitinfo="RRG/Iceman" clean=2 # Do we have acces to git command? -commandGIT=$(env which git) +commandGIT=$(env git) if [ "$commandGIT" != "" ]; then From 0bd3d3673f42cce9aa0a8158d05dcbba724f09b5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 19:52:14 +0200 Subject: [PATCH 229/347] remove p7zip requirement --- .../Linux-Installation-Instructions.md | 2 +- .../Mac-OS-X-Homebrew-Installation-Instructions.md | 2 +- .../Windows-Installation-Instructions.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index aa3ce9272..738784301 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -24,7 +24,7 @@ sudo apt-get update Install the requirements ```sh -sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev \ +sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev \ libusb-0.1-4 libusb-dev pkg-config wget gcc-arm-none-eabi libnewlib-dev libqt4-dev ``` diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 09b986ff3..808b2c7ce 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -66,7 +66,7 @@ These instructions will show how to setup the environment on OSX to the point wh 2. Install dependencies: ``` -brew install readline p7zip libusb-compat qt5 wget pkgconfig +brew install readline libusb-compat qt5 wget pkgconfig brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc ``` diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index f01e695e9..db378b615 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -98,7 +98,7 @@ Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instruct ```sh sudo apt-get update -sudo apt-get install p7zip git ca-certificates build-essential libreadline5 libreadline-dev libusb-0.1-4 \ +sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev libusb-0.1-4 \ libusb-dev pkg-config wget gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ libqt4-dev ``` From bd4cce1270fc6ed7ff92ae6f097bb17a1115f1d3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 20:02:48 +0200 Subject: [PATCH 230/347] remove global libusb requirement, add note to compile HID flasher --- .../Linux-Installation-Instructions.md | 4 ++-- .../Mac-OS-X-Homebrew-Installation-Instructions.md | 2 +- .../Windows-Installation-Instructions.md | 4 ++-- tools/deprecated-hid-flasher/flasher/README.md | 9 +++++++++ 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 tools/deprecated-hid-flasher/flasher/README.md diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index 738784301..55a906a4e 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -25,7 +25,7 @@ Install the requirements ```sh sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev \ -libusb-0.1-4 libusb-dev pkg-config wget gcc-arm-none-eabi libnewlib-dev libqt4-dev +pkg-config wget gcc-arm-none-eabi libnewlib-dev libqt4-dev ``` If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. @@ -35,7 +35,7 @@ If you get some (non blocking) error at runtime such as _Gtk-Message: Failed to ## On ArchLinux ```sh -sudo pacman -Sy base-devel p7zip libusb readline arm-none-eabi-gcc arm-none-eabi-newlib git --needed +sudo pacman -Sy base-devel readline arm-none-eabi-gcc arm-none-eabi-newlib git --needed ``` If you want graphical output (such as in `hw tune`): ```sh diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 808b2c7ce..2ad0efc23 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -66,7 +66,7 @@ These instructions will show how to setup the environment on OSX to the point wh 2. Install dependencies: ``` -brew install readline libusb-compat qt5 wget pkgconfig +brew install readline qt5 wget pkgconfig brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc ``` diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index db378b615..61eebe47d 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -98,8 +98,8 @@ Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instruct ```sh sudo apt-get update -sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev libusb-0.1-4 \ -libusb-dev pkg-config wget gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ +sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev \ +pkg-config wget gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ libqt4-dev ``` diff --git a/tools/deprecated-hid-flasher/flasher/README.md b/tools/deprecated-hid-flasher/flasher/README.md new file mode 100644 index 000000000..d8086a7bc --- /dev/null +++ b/tools/deprecated-hid-flasher/flasher/README.md @@ -0,0 +1,9 @@ +Compilation notes +================= + +Besides the global Proxmark3 requirements, this flasher compatible with very old firmwares requires the libusb 0.1 to work. +So you'll need to install the libusb 0.1 package first. + +* OSX: libusb-compat +* Debian-alike: libusb-0.1-4 libusb-dev +* Arch: libusb From 43ed7ff1458c094e39565bd5c168e4409e09bea8 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 20:03:59 +0200 Subject: [PATCH 231/347] reduce Travis prereqs --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac39433f8..c75bffe9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,11 +36,7 @@ addons: homebrew: packages: - readline - - p7zip - - libusb-compat - - perl - qt5 - - wget - RfidResearchGroup/proxmark3/arm-none-eabi-gcc taps: RfidResearchGroup/proxmark3 From d0ad275f1e083a0ac85c2334ef1aed367cc3cfaf Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 20:05:08 +0200 Subject: [PATCH 232/347] Remove wget from global requirements --- .../Linux-Installation-Instructions.md | 2 +- .../Mac-OS-X-Homebrew-Installation-Instructions.md | 2 +- .../Windows-Installation-Instructions.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index 55a906a4e..bbf4587e8 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -25,7 +25,7 @@ Install the requirements ```sh sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev \ -pkg-config wget gcc-arm-none-eabi libnewlib-dev libqt4-dev +pkg-config gcc-arm-none-eabi libnewlib-dev libqt4-dev ``` If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 2ad0efc23..4e225b318 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -66,7 +66,7 @@ These instructions will show how to setup the environment on OSX to the point wh 2. Install dependencies: ``` -brew install readline qt5 wget pkgconfig +brew install readline qt5 pkgconfig brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc ``` diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 61eebe47d..4e7f6bac2 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -99,7 +99,7 @@ Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instruct ```sh sudo apt-get update sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev \ -pkg-config wget gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ +pkg-config gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ libqt4-dev ``` From bf8d4ece1898001858db684270eed8a413fb0ca5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 20:09:03 +0200 Subject: [PATCH 233/347] Add instructions for Fedora --- .../Linux-Installation-Instructions.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index bbf4587e8..786c73d36 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -42,6 +42,12 @@ If you want graphical output (such as in `hw tune`): sudo pacman -Su qt5-base ``` +## On Fedora + +```sh +sudo dnf install git make gcc gcc-c++ arm-none-eabi-gcc-cs arm-none-eabi-newlib readline-devel qt5-qtbase-devel libatomic +``` + # Clone the RRG/Iceman repository ```sh From 27a0402a3d039449e026c651414afb3507cd17aa Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 20:13:33 +0200 Subject: [PATCH 234/347] HID flasher: add libusb for Fedora in readme --- tools/deprecated-hid-flasher/flasher/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/deprecated-hid-flasher/flasher/README.md b/tools/deprecated-hid-flasher/flasher/README.md index d8086a7bc..c5ddfed62 100644 --- a/tools/deprecated-hid-flasher/flasher/README.md +++ b/tools/deprecated-hid-flasher/flasher/README.md @@ -7,3 +7,4 @@ So you'll need to install the libusb 0.1 package first. * OSX: libusb-compat * Debian-alike: libusb-0.1-4 libusb-dev * Arch: libusb +* Fedora: libusb-devel From 1cc027d41af549c5d29ae49eb9c469a3777987ec Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 1 Sep 2019 22:51:08 +0200 Subject: [PATCH 235/347] Debian/WSL: align reqs and move to QT5 by default --- .../Linux-Installation-Instructions.md | 8 +++++--- .../Windows-Installation-Instructions.md | 7 +++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md index 786c73d36..70d102aa3 100644 --- a/doc/md/Installation_Instructions/Linux-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Linux-Installation-Instructions.md @@ -24,11 +24,11 @@ sudo apt-get update Install the requirements ```sh -sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev \ -pkg-config gcc-arm-none-eabi libnewlib-dev libqt4-dev +sudo apt-get install --no-install-recommends git ca-certificates build-essential pkg-config \ +libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev ``` -If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. +If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qtbase5-dev`. If you get some (non blocking) error at runtime such as _Gtk-Message: Failed to load module "canberra-gtk-module"_ you may have to install `libcanberra-gtk-module`. @@ -48,6 +48,8 @@ sudo pacman -Su qt5-base sudo dnf install git make gcc gcc-c++ arm-none-eabi-gcc-cs arm-none-eabi-newlib readline-devel qt5-qtbase-devel libatomic ``` +If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qt5-qtbase-devel`. + # Clone the RRG/Iceman repository ```sh diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 4e7f6bac2..f9eb9e988 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -98,12 +98,11 @@ Enter WSL prompt (`wsl`) and from there, follow the [Linux Installation Instruct ```sh sudo apt-get update -sudo apt-get install git ca-certificates build-essential libreadline5 libreadline-dev \ -pkg-config gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib \ -libqt4-dev +sudo apt-get install --no-install-recommends git ca-certificates build-essential pkg-config \ +libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev ``` -If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `libqt4-dev`. +If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qtbase5-dev`. ## Clone the RRG/Iceman repository From 002580b6d4ad57b1ea47af90a4c9b9ad7d8899b9 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 2 Sep 2019 22:46:06 +0200 Subject: [PATCH 236/347] fido: fix typos --- client/cmdhffido.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/client/cmdhffido.c b/client/cmdhffido.c index e9b3376a9..a7ce63c98 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -44,7 +44,7 @@ static int CmdHelp(const char *Cmd); static int CmdHFFidoInfo(const char *cmd) { if (cmd && strlen(cmd) > 0) - PrintAndLogEx(WARNING, "WARNING: command don't have any parameters.\n"); + PrintAndLogEx(WARNING, "WARNING: command doesn't have any parameters.\n"); // info about 14a part infoHF14A(false, false); @@ -75,14 +75,14 @@ static int CmdHFFidoInfo(const char *cmd) { if (!strncmp((char *)buf, "U2F_V2", 7)) { if (!strncmp((char *)buf, "FIDO_2_0", 8)) { - PrintAndLogEx(INFO, "FIDO2 authenricator detected. Version: %.*s", len, buf); + PrintAndLogEx(INFO, "FIDO2 authenticator detected. Version: %.*s", len, buf); } else { - PrintAndLogEx(INFO, "FIDO authenricator detected (not standard U2F)."); + PrintAndLogEx(INFO, "FIDO authenticator detected (not standard U2F)."); PrintAndLogEx(INFO, "Non U2F authenticator version:"); dump_buffer((const unsigned char *)buf, len, NULL, 0); } } else { - PrintAndLogEx(INFO, "FIDO U2F authenricator detected. Version: %.*s", len, buf); + PrintAndLogEx(INFO, "FIDO U2F authenticator detected. Version: %.*s", len, buf); } res = FIDO2GetInfo(buf, sizeof(buf), &len, &sw); @@ -91,13 +91,13 @@ static int CmdHFFidoInfo(const char *cmd) { return res; } if (sw != 0x9000) { - PrintAndLogEx(ERR, "FIDO2 version not exists (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); + PrintAndLogEx(ERR, "FIDO2 version doesn't exist (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); return 0; } if (buf[0]) { - PrintAndLogEx(ERR, "FIDO2 ger version error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0])); + PrintAndLogEx(ERR, "FIDO2 get version error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0])); return 0; } @@ -163,14 +163,14 @@ static int CmdHFFidoRegister(const char *cmd) { json_t *root = NULL; CLIParserInit("hf fido reg", - "Initiate a U2F token registration. Needs two 32-byte hash number. \nchallenge parameter (32b) and application parameter (32b).", + "Initiate a U2F token registration. Needs two 32-byte hash numbers. \nchallenge parameter (32b) and application parameter (32b).", "Usage:\n\thf fido reg -> execute command with 2 parameters, filled 0x00\n" "\thf fido reg 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with parameters" "\thf fido reg -p s0 s1 -> execute command with plain parameters"); void *argtable[] = { arg_param_begin, - arg_lit0("aA", "apdu", "show APDU reqests and responses"), + arg_lit0("aA", "apdu", "show APDU requests and responses"), arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"), arg_lit0("pP", "plain", "send plain ASCII to challenge and application parameters instead of HEX"), arg_lit0("tT", "tlv", "Show DER certificate contents in TLV representation"), @@ -393,7 +393,7 @@ static int CmdHFFidoAuthenticate(const char *cmd) { json_t *root = NULL; CLIParserInit("hf fido auth", - "Initiate a U2F token authentication. Needs key handle and two 32-byte hash number. \nkey handle(var 0..255), challenge parameter (32b) and application parameter (32b).", + "Initiate a U2F token authentication. Needs key handle and two 32-byte hash numbers. \nkey handle(var 0..255), challenge parameter (32b) and application parameter (32b).", "Usage:\n\thf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with 2 parameters, filled 0x00 and key handle\n" "\thf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f " "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with parameters"); @@ -640,8 +640,8 @@ static int CmdHFFido2MakeCredential(const char *cmd) { char fname[300] = {0}; CLIParserInit("hf fido make", - "Execute a FIDO2 Make Credentional command. Needs json file with parameters. Sample file `fido2.json`. File can be placed in proxmark directory or in `proxmark/fido` directory.", - "Usage:\n\thf fido make -> execute command default parameters file `fido2.json`\n" + "Execute a FIDO2 Make Credential command. Needs json file with parameters. Sample file " _YELLOW_("`fido2.json`") " in `resources/`.", + "Usage:\n\thf fido make -> execute command with default parameters file `fido2.json`\n" "\thf fido make test.json -> execute command with parameters file `text.json`"); void *argtable[] = { @@ -713,7 +713,7 @@ static int CmdHFFido2MakeCredential(const char *cmd) { return res; if (showCBOR) { - PrintAndLogEx(INFO, "CBOR make credentional request:"); + PrintAndLogEx(INFO, "CBOR make credential request:"); PrintAndLogEx(NORMAL, "---------------- CBOR ------------------"); TinyCborPrintFIDOPackage(fido2CmdMakeCredential, false, data, datalen); PrintAndLogEx(NORMAL, "---------------- CBOR ------------------"); @@ -738,7 +738,7 @@ static int CmdHFFido2MakeCredential(const char *cmd) { PrintAndLogEx(SUCCESS, "MakeCredential result (%d b) OK.", len); if (showCBOR) { - PrintAndLogEx(SUCCESS, "CBOR make credentional response:"); + PrintAndLogEx(SUCCESS, "CBOR make credential response:"); PrintAndLogEx(NORMAL, "---------------- CBOR ------------------"); TinyCborPrintFIDOPackage(fido2CmdMakeCredential, true, &buf[1], len - 1); PrintAndLogEx(NORMAL, "---------------- CBOR ------------------"); @@ -766,8 +766,8 @@ static int CmdHFFido2GetAssertion(const char *cmd) { char fname[300] = {0}; CLIParserInit("hf fido assert", - "Execute a FIDO2 Get Assertion command. Needs json file with parameters. Sample file " _YELLOW_("`fido2.json`") ". File can be placed in proxmark directory or in `proxmark/fido` directory.", - "Usage:\n\thf fido assert -> execute command default parameters file `fido2.json`\n" + "Execute a FIDO2 Get Assertion command. Needs json file with parameters. Sample file " _YELLOW_("`fido2.json`") " in `resources/`.", + "Usage:\n\thf fido assert -> execute command with default parameters file `fido2.json`\n" "\thf fido assert test.json -l -> execute command with parameters file `text.json` and add to request CredentialId"); void *argtable[] = { @@ -775,7 +775,7 @@ static int CmdHFFido2GetAssertion(const char *cmd) { arg_lit0("aA", "apdu", "show APDU reqests and responses"), arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"), arg_lit0("cC", "cbor", "show CBOR decoded data"), - arg_lit0("lL", "list", "add CredentialId from json to allowList. Needs if `rk` option is `false` (authenticator don't store credential to its memory)"), + arg_lit0("lL", "list", "add CredentialId from json to allowList. Needs if `rk` option is `false` (authenticator doesn't store credential to its memory)"), arg_str0(NULL, NULL, "", "JSON input / output file name for parameters. Default `fido2.json`"), arg_param_end }; From f7f80a9b9fe8c60182077e445d7bfb1c112b678e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 2 Sep 2019 22:51:28 +0200 Subject: [PATCH 237/347] fido2: fix fido assert loading file --- client/cmdhffido.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhffido.c b/client/cmdhffido.c index a7ce63c98..fbc91e814 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -801,7 +801,7 @@ static int CmdHFFido2GetAssertion(const char *cmd) { SetAPDULogging(APDULogging); - int res = GetExistsFileNameJson("fido", "fido2", fname); + int res = GetExistsFileNameJson("fido", cjsonname, fname); if (res) { PrintAndLogEx(ERR, "ERROR: Can't found the json file."); return res; From bccb9069f9d4e84e30d912b6f562a34892545b4b Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 3 Sep 2019 00:18:29 +0200 Subject: [PATCH 238/347] prepare libamiibo.a inclusion --- client/Makefile | 13 ++++++++++--- client/amiitool/Makefile | 19 +++++++++++++++++++ client/amiitool/amiibo.c | 1 + client/amiitool/amiibo.h | 1 - client/amiitool/amiitool.c | 15 ++++++++++----- client/amiitool/drbg.c | 2 +- client/amiitool/keygen.c | 2 +- 7 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 client/amiitool/Makefile diff --git a/client/Makefile b/client/Makefile index 4c5d53c9c..56de12f97 100644 --- a/client/Makefile +++ b/client/Makefile @@ -40,6 +40,8 @@ CBORLIBPATH = ./tinycbor CBORLIB = $(CBORLIBPATH)/tinycbor.a REVENGPATH = ./reveng REVENGLIB = $(REVENGPATH)/libreveng.a +AMIIBOLIBPATH = ./amiitool +AMIIBOLIB = $(AMIIBOLIBPATH)/libamiibo.a # common libraries MBEDTLSLIBPATH = ../common/mbedtls @@ -47,7 +49,7 @@ MBEDTLSLIB = $(OBJDIR)/libmbedtls.a ZLIBPATH = ../common/zlib ZLIB = $(OBJDIR)/libz.a -LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) +LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) -I$(AMIIBOLIBPATH) INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) CFLAGS ?= -Wall -Werror -g -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: @@ -287,8 +289,8 @@ all: $(BINS) all-static: LDLIBS:=-static $(LDLIBS) all-static: $(BINS) -proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(QTLDLIBS) -proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua +proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(AMIIBOLIB) $(QTLDLIBS) +proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) $(AMIIBOLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua $(info [=] LD $@) $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LDLIBS) -o $@ @@ -321,6 +323,7 @@ clean: $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(CBORLIBPATH) clean $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean + $(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) clean install: all $(info [@] Installing client to $(DESTDIR)$(PREFIX)...) @@ -365,6 +368,10 @@ $(REVENGLIB): $(info [*] MAKE reveng) $(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) all +$(AMIIBOLIB): + $(info [*] MAKE amiibo) + $(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) all + # common libraries: $(MBEDTLSLIB): $(info [*] MAKE mbedtls) diff --git a/client/amiitool/Makefile b/client/amiitool/Makefile new file mode 100644 index 000000000..c473f58ee --- /dev/null +++ b/client/amiitool/Makefile @@ -0,0 +1,19 @@ +MYSRCPATHS = +MYINCLUDES = -I. -I.. -I../jansson -I../../common/ -I../../include/ +MYCFLAGS = -std=c99 -D_ISOC99_SOURCE +MYDEFS = +MYSRCS = \ + amiibo.c \ + drbg.c \ + keygen.c + +LIB_A = libamiibo.a + +include ../../Makefile.host + +# just for testing amiitool before complete migration into a lib: + +amiitool: + gcc $(CFLAGS) \ + amiitool.c $(MYSRCS) ../../common/commonutil.c ../ui.c -lreadline -lm ../../common/mbedtls/libmbedtls.a \ + -o amiitool diff --git a/client/amiitool/amiibo.c b/client/amiitool/amiibo.c index a8596e30a..d8fe837b1 100644 --- a/client/amiitool/amiibo.c +++ b/client/amiitool/amiibo.c @@ -8,6 +8,7 @@ #include "amiibo.h" #include "mbedtls/md.h" #include "mbedtls/aes.h" +#include "commonutil.h" #define HMAC_POS_DATA 0x008 #define HMAC_POS_TAG 0x1B4 diff --git a/client/amiitool/amiibo.h b/client/amiitool/amiibo.h index 7b56a2c0a..47d544875 100644 --- a/client/amiitool/amiibo.h +++ b/client/amiitool/amiibo.h @@ -13,7 +13,6 @@ #include #include #include "keygen.h" -#include "util.h" #define NFC3D_AMIIBO_SIZE 520 diff --git a/client/amiitool/amiitool.c b/client/amiitool/amiitool.c index 78c8f4d1e..ca34a5c6a 100644 --- a/client/amiitool/amiitool.c +++ b/client/amiitool/amiitool.c @@ -5,10 +5,11 @@ * SPDX-License-Identifier: MIT */ -#include #include #include -#include "../loclass/fileutils.h" +#include "fileutils.h" +#include "amiibo.h" +#include "getopt.h" #define NTAG215_SIZE 540 @@ -16,7 +17,7 @@ static char *self; void amiitool_usage() { fprintf(stderr, - "amiitool build %i (commit %s-%08x)\n" + /*"amiitool build %i (commit %s-%08x)\n"*/ "by Marcos Del Sol Vives \n" "\n" "Usage: %s (-e|-d|-c) -k keyfile [-i input] [-s input2] [-o output]\n" @@ -28,7 +29,7 @@ void amiitool_usage() { " -s input save file, save from this file will replace input file ones.\n" " -o output file. If not specified, stdout will be used.\n" " -l decrypt files with invalid signatures.\n", - , self + self ); } @@ -62,6 +63,9 @@ int main(int argc, char **argv) { case 'i': infile = optarg; break; + case 'k': + keyfile = optarg; + break; case 's': savefile = optarg; break; @@ -83,7 +87,8 @@ int main(int argc, char **argv) { } nfc3d_amiibo_keys amiiboKeys; - + if (! LoadAmiikey(amiiboKeys, keyfile)) + return 5; uint8_t original[NTAG215_SIZE]; uint8_t modified[NFC3D_AMIIBO_SIZE]; diff --git a/client/amiitool/drbg.c b/client/amiitool/drbg.c index 623a29776..c1297920f 100644 --- a/client/amiitool/drbg.c +++ b/client/amiitool/drbg.c @@ -8,7 +8,7 @@ #include "drbg.h" #include #include -#include +#include "mbedtls/md.h" void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize) { assert(ctx != NULL); diff --git a/client/amiitool/keygen.c b/client/amiitool/keygen.c index 4b74a0232..f148c0dc8 100644 --- a/client/amiitool/keygen.c +++ b/client/amiitool/keygen.c @@ -19,7 +19,7 @@ void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const ui uint8_t *start = output; // 1: Copy whole type string - output = memccpy(output, baseKeys->typeString, '\0', sizeof(baseKeys->typeString)); + output = (uint8_t *)strcpy((char *)output, baseKeys->typeString); // 2: Append (16 - magicBytesSize) from the input seed size_t leadingSeedBytes = 16 - baseKeys->magicBytesSize; From 6b12cdc6d82453e2dc02c64215164f6ef2f0648e Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 3 Sep 2019 13:11:49 +0200 Subject: [PATCH 239/347] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 26a1ae126..9d8492f56 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. |[Donations](#Donations)||| ## Support on other Proxmark3 platforms + In order to build this repo for other Proxmark3 platforms we urge you to read [Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md) ## What has changed? @@ -43,12 +44,13 @@ On the hardware side: On the software side: quite a lot, see the [Changelog file](CHANGELOG.md). ## Development -This fork now compiles just fine on + +This repo now compiles just fine on - Proxspace v3.2 - Windows/mingw environment with Qt5.6.1 & GCC 4.8 - Ubuntu 1404, 1510, 1604, 1804, 1904 - Mac OS X / Homebrew - - ParrotOS, Gentoo, Pentoo, Kali, Nethunter, Archlinux + - ParrotOS, Gentoo, Pentoo, Kali, Nethunter, Archlinux, Fedora - WSL, WSL2 (Windows subsystem linux) on Windows 10 - Docker container @@ -65,9 +67,11 @@ If you intend to contribute to the code, please read the [coding style notes](HA - Internal notes on [EMV](/doc/emv_notes.md) ## Cheat sheet + Thanks to Alex Dibs, you can enjoy a [command cheat sheet](/doc/cheatsheet.md) ## Maintainers ( package, distro ) + To all distro, package maintainers, we tried to make your life easier. `make install` is now available and if you want to know more. - [Maintainers](/doc/md/Development/Maintainers.md) @@ -76,6 +80,7 @@ To all distro, package maintainers, we tried to make your life easier. `make ins The separation from official Proxmark3 repo gives us a lot of freedom to create a firmware/client that suits the RDV40 features. We don't want to mess up the official Proxmark3 repo with RDV40 specific code. ## Proxmark3 GUI + The official PM3-GUI from Gaucho will not work. The new universal GUI will work. [Proxmark3 Universal GUI](https://github.com/burma69/PM3UniversalGUI) Almost, change needed in order to show helptext when client isn't connected to a device. @@ -91,6 +96,7 @@ It's needed to have a good USB cable to connect Proxmark3 to USB. If you have st - updated Feb 2019 [@5w0rdfish](https://mobile.twitter.com/5w0rdFish) # Donations + Nothing says thank you as much as a donation. So if you feel the love, do feel free to become a iceman patron. For some tiers it comes with rewards. https://www.patreon.com/iceman1001 From 15d8e246d8404b21cad4f3636eededbbbb802af4 Mon Sep 17 00:00:00 2001 From: CristarIngram <49596976+CristarIngram@users.noreply.github.com> Date: Tue, 3 Sep 2019 16:10:22 +0200 Subject: [PATCH 240/347] more mfc keys --- client/dictionaries/mfc_default_keys.dic | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/dictionaries/mfc_default_keys.dic b/client/dictionaries/mfc_default_keys.dic index 924f75488..280604b3a 100644 --- a/client/dictionaries/mfc_default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -106,6 +106,9 @@ ba5b895da162 # VIGIK1 B d01afeeb890a # 16 B 4b791bea7bcc # 17 B # +43454952534E # ARD (fr) key A +4A2B29111213 # ARD (fr) key B +# 4143414F5250 a9b43414F585 # Tehran Railway 1FB235AC1388 # Tehran Railway From 21f34fabc255916110f8c56496100f3ab8789711 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 3 Sep 2019 20:30:27 +0200 Subject: [PATCH 241/347] update troubleshooting notes --- doc/md/Installation_Instructions/Troubleshooting.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index 19f1dbee7..041ce0f41 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -76,7 +76,7 @@ At this point, only reflashing via JTAG can revive your Proxmark3. See [details here](/doc/jtag_notes.md). -## Slow to boot +## Slow to boot or difficulties to enumerate the device over USB You're using another Proxmark3 than a RDV4? The RDV4 firmware can run on other Proxmark3 as such but the booting procedure is a bit slower because of the absence of SIM and external flash. @@ -116,13 +116,8 @@ pm3 --> sc upgrade f tools/simmodule/sim011.bin pm3 --> sc upgrade f ../tools/simmodule/sim011.bin ``` -``` -pm3 --> mem load f default_keys m -<> -pm3 --> mem load f client/default_keys m -``` - etc. -This also affects where your history and logfile will be read from and written to. +## pixmap / pixbuf warnings +If you get warnings related to pixmap or pixbuf such as *Pixbuf theme: Cannot load pixmap file* or *Invalid borders specified for theme pixmap*, it's a problem of your Theme, try another one and the problem should vanish. See e.g. [#354](https://github.com/RfidResearchGroup/proxmark3/issues/354) (Yaru theme on Ubuntu) and [#386](https://github.com/RfidResearchGroup/proxmark3/issues/386) (Kali-X theme on Kali). From 5ec14e0c94f8d132f72686c69120718d4dcedfbc Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 3 Sep 2019 20:39:47 +0200 Subject: [PATCH 242/347] Troubleshooting ToC Done with https://github.com/ekalinin/github-markdown-toc --- .../Installation_Instructions/Troubleshooting.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index 041ce0f41..b8153ba8b 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -4,6 +4,20 @@ Always use the latest repository commits from *master* branch. There are always many fixes done almost daily. +## Table of Contents + + * [./proxmark3.sh or ./proxmark3-flash-*.sh doesn't see my Proxmark](#proxmark3sh-or-proxmark3-flash-sh-doesnt-see-my-proxmark) + * [My Proxmark3 seems bricked](#my-proxmark3-seems-bricked) + * [Maybe just a false alarm?](#maybe-just-a-false-alarm) + * [Find out why it would be bricked](#find-out-why-it-would-be-bricked) + * [Determine if the bootloader was damaged or only the main OS image](#determine-if-the-bootloader-was-damaged-or-only-the-main-os-image) + * [Ok, my bootloader is definitively dead, now what?](#ok-my-bootloader-is-definitively-dead-now-what) + * [Slow to boot or difficulties to enumerate the device over USB](#slow-to-boot-or-difficulties-to-enumerate-the-device-over-usb) + * [Troubles with SIM card reader](#troubles-with-sim-card-reader) + * [Troubles with t5577 commands or MFC/iClass/T55x7 dictionaries](#troubles-with-t5577-commands-or-mfciclasst55x7-dictionaries) + * [File not found](#file-not-found) + * [pixmap / pixbuf warnings](#pixmap--pixbuf-warnings) + ## `./proxmark3.sh` or `./proxmark3-flash-*.sh` doesn't see my Proxmark Try using directly the client or flasher: From 62f598c4139bb3f0581692f0f84ace4d5c8efa2c Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 3 Sep 2019 20:59:23 +0200 Subject: [PATCH 243/347] Update Troubleshooting.md --- .../Installation_Instructions/Troubleshooting.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index b8153ba8b..1eefe1c6e 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -6,7 +6,7 @@ Always use the latest repository commits from *master* branch. There are always ## Table of Contents - * [./proxmark3.sh or ./proxmark3-flash-*.sh doesn't see my Proxmark](#proxmark3sh-or-proxmark3-flash-sh-doesnt-see-my-proxmark) + * [./pm3.sh or ./pma3-flash-*.sh doesn't see my Proxmark](#pm3sh-or-pmk3-flash-sh-doesnt-see-my-proxmark) * [My Proxmark3 seems bricked](#my-proxmark3-seems-bricked) * [Maybe just a false alarm?](#maybe-just-a-false-alarm) * [Find out why it would be bricked](#find-out-why-it-would-be-bricked) @@ -18,7 +18,7 @@ Always use the latest repository commits from *master* branch. There are always * [File not found](#file-not-found) * [pixmap / pixbuf warnings](#pixmap--pixbuf-warnings) -## `./proxmark3.sh` or `./proxmark3-flash-*.sh` doesn't see my Proxmark +## `./pm3.sh` or `./pm3-flash-*.sh` doesn't see my Proxmark Try using directly the client or flasher: @@ -44,8 +44,8 @@ Note that with the Bluetooth adapter, you *have to* use directly the client, and The flasher refused to flash your Proxmark3? Are there any messages in *red*? The most common reason is that the Proxmark3 RDV4 firmware recently got a new bootloader able to handle larger firmwares and... the image grew over 256k almost at the same time. So your old bootloader can't flash such new images. But it's easy, you just need to flash *first* the bootloader *only*, then the image. ``` -./flash-bootrom.sh -./flash-fullimage.sh +./pm3-flash-bootrom.sh +./pm3-flash-fullimage.sh ``` or ``` @@ -67,7 +67,7 @@ On new bootloaders, you can release the button. If the pattern disappears, you'r Once in bootloader mode, flash the main image. ``` -./flash-fullimage.sh +./pm3-flash-fullimage.sh ``` or ``` @@ -77,7 +77,7 @@ client/proxmark3-flasher armsrc/obj/fullimage.elf You should be back on tracks now. In case the flasher complains about bootloader version, you can follow the button procedure and flash first your bootloader. ``` -./flash-bootrom.sh +./pm3-flash-bootrom.sh ``` or ``` @@ -112,7 +112,7 @@ Instructions evolve over time so check if you're still up to date! Depending how you launch the client, your working directory might be the root of the repository: ``` -./proxmark3.sh ... +./pm3.sh ... client/proxmark3 ... ``` From d4cd32b723b4339d8d524d86bcb5ebf6b63786e0 Mon Sep 17 00:00:00 2001 From: Iceman Date: Tue, 3 Sep 2019 21:00:30 +0200 Subject: [PATCH 244/347] Update Troubleshooting.md --- doc/md/Installation_Instructions/Troubleshooting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index 1eefe1c6e..ae56ce012 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -6,7 +6,7 @@ Always use the latest repository commits from *master* branch. There are always ## Table of Contents - * [./pm3.sh or ./pma3-flash-*.sh doesn't see my Proxmark](#pm3sh-or-pmk3-flash-sh-doesnt-see-my-proxmark) + * [./pm3.sh or ./pm3-flash-*.sh doesn't see my Proxmark](#pm3sh-or-pm3-flash-sh-doesnt-see-my-proxmark) * [My Proxmark3 seems bricked](#my-proxmark3-seems-bricked) * [Maybe just a false alarm?](#maybe-just-a-false-alarm) * [Find out why it would be bricked](#find-out-why-it-would-be-bricked) From b577ca15e9c899f6537fb5eabb94c22ac9026996 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 3 Sep 2019 22:54:42 +0200 Subject: [PATCH 245/347] update instructions --- ...OS-X-Homebrew-Installation-Instructions.md | 34 ++++++++++---- .../ModemManager-Must-Be-Discarded.md | 2 +- .../Troubleshooting.md | 47 ++++++++++++++----- .../Windows-Installation-Instructions.md | 32 +++++++++---- .../0_Compilation-Instructions.md | 33 +++++++++++-- .../2_Configuration-and-Verification.md | 4 +- 6 files changed, 116 insertions(+), 36 deletions(-) diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 4e225b318..ba6547cb2 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -31,19 +31,31 @@ brew upgrade --fetch-HEAD proxmark3 With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark3 as you plug it into a USB port. You can release the button, two of the four LEDs should stay on. You're un bootloader mode, ready for the next step. In case the two LEDs don't stay on when you're releasing the button, you've an old bootloader, start over and keep the button pressed during the whole flashing procedure. +In principle, the helper script `pm3-flash-all` should auto-detect your port, so you can just try: + ```sh -sudo proxmark3-flasher /dev/tty.usbmodemiceman1 -b /usr/local/Cellar/proxmark3/HEAD-/share/firmware/bootrom.elf /usr/local/Cellar/proxmark3/HEAD-/share/firmware/fullimage.elf +pm3-flash-all ``` -> Replace \ with the HEAD-XXXX ID displayed by brew. -> Depending on the firmware version your Proxmark3 can also appear as `/dev/tty.usbmodem881` +If port detection failed, you'll have to call the flasher manually and specify the correct port: +```sh +proxmark3-flasher /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +``` + +> Depending on the firmware version your Proxmark3 can also appear as `/dev/tty.usbmodem881`. ## Run the client ```sh -sudo proxmark3 /dev/tty.usbmodemiceman1 +pm3 +``` + +or, if the port doesn't get properly detected: + +```sh +proxmark3 /dev/tty.usbmodemiceman1 ``` ## Next steps @@ -78,14 +90,20 @@ To use the compiled client and flasher, the only difference is that the Proxmark To flash: With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark3 as you plug it into a USB port. You can release the button, two of the four LEDs should stay on. You're un bootloader mode, ready for the next step. In case the two LEDs don't stay on when you're releasing the button, you've an old bootloader, start over and keep the button pressed during the whole flashing procedure. -In principle, the helper script `flash-all.sh` should auto-detect your port, so you can just try: +In principle, the helper script `pm3-flash-all` should auto-detect your port, so you can just try: ```sh -./flash-all.sh +pm3-flash-all ``` If port detection failed, you'll have to call the flasher manually and specify the correct port: +```sh +proxmark3-flasher /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +``` + +or from the local repo + ```sh client/proxmark3-flasher /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` @@ -93,12 +111,12 @@ client/proxmark3-flasher /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf arm Similarly, to run the client, you may try: ```sh -./proxmark3.sh +pm3 ``` Or, by specifying the port manually: ```sh -client/proxmark3 /dev/tty.usbmodemiceman1 +proxmark3 /dev/tty.usbmodemiceman1 ``` diff --git a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md index 76a4626e3..bbf6f6ca6 100644 --- a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md +++ b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md @@ -121,7 +121,7 @@ In short: * unplug device * press button and keep it pressed (IMPORTANT) * plug in device -* run flash command `sudo client/proxmark3-flasher /dev/ttyACM0 armsrc/obj/fullimage.elf` +* run flash command `sudo proxmark3-flasher /dev/ttyACM0 /usr/local/share/proxmark3/firmware/fullimage.elf` * wait until flash is finished * release button * un/plug device diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index ae56ce012..e9ae8bce9 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -6,7 +6,7 @@ Always use the latest repository commits from *master* branch. There are always ## Table of Contents - * [./pm3.sh or ./pm3-flash-*.sh doesn't see my Proxmark](#pm3sh-or-pm3-flash-sh-doesnt-see-my-proxmark) + * [pm3 or pm3-flash-* doesn't see my Proxmark](#pm3-or-pm3-flash-doesnt-see-my-proxmark) * [My Proxmark3 seems bricked](#my-proxmark3-seems-bricked) * [Maybe just a false alarm?](#maybe-just-a-false-alarm) * [Find out why it would be bricked](#find-out-why-it-would-be-bricked) @@ -18,7 +18,7 @@ Always use the latest repository commits from *master* branch. There are always * [File not found](#file-not-found) * [pixmap / pixbuf warnings](#pixmap--pixbuf-warnings) -## `./pm3.sh` or `./pm3-flash-*.sh` doesn't see my Proxmark +## `pm3` or `pm3-flash-*` doesn't see my Proxmark Try using directly the client or flasher: @@ -44,13 +44,13 @@ Note that with the Bluetooth adapter, you *have to* use directly the client, and The flasher refused to flash your Proxmark3? Are there any messages in *red*? The most common reason is that the Proxmark3 RDV4 firmware recently got a new bootloader able to handle larger firmwares and... the image grew over 256k almost at the same time. So your old bootloader can't flash such new images. But it's easy, you just need to flash *first* the bootloader *only*, then the image. ``` -./pm3-flash-bootrom.sh -./pm3-flash-fullimage.sh +pm3-flash-bootrom +pm3-flash-fullimage ``` or ``` -client/proxmark3-flasher -b bootrom/obj/bootrom.elf -client/proxmark3-flasher armsrc/obj/fullimage.elf +proxmark3-flasher -b bootrom/obj/bootrom.elf +proxmark3-flasher armsrc/obj/fullimage.elf ``` ### Find out why it would be bricked @@ -67,21 +67,21 @@ On new bootloaders, you can release the button. If the pattern disappears, you'r Once in bootloader mode, flash the main image. ``` -./pm3-flash-fullimage.sh +pm3-flash-fullimage ``` or ``` -client/proxmark3-flasher armsrc/obj/fullimage.elf +proxmark3-flasher armsrc/obj/fullimage.elf ``` You should be back on tracks now. In case the flasher complains about bootloader version, you can follow the button procedure and flash first your bootloader. ``` -./pm3-flash-bootrom.sh +pm3-flash-bootrom ``` or ``` -client/proxmark3-flasher -b bootrom/obj/bootrom.elf +proxmark3-flasher -b bootrom/obj/bootrom.elf ``` ### Ok, my bootloader is definitively dead, now what? @@ -109,10 +109,29 @@ Instructions evolve over time so check if you're still up to date! ## File not found -Depending how you launch the client, your working directory might be the root of the repository: +If Proxmark3 has been installed with `make install` or packaged for your distro, the binaries should be in your path and you can call them directly: ``` -./pm3.sh ... +pm3 +proxmark3 +``` + +and you must adapt accordingly the file path of some commands, e.g. + +``` +proxmark3-flasher /usr/local/share/proxmark3/firmware/fullimage.elf +<> +proxmark3-flasher /usr/share/proxmark3/firmware/fullimage.elf + +pm3 --> sc upgrade f /usr/local/share/proxmark3/firmware/sim011.bin +<> +pm3 --> sc upgrade f /usr/share/proxmark3/firmware/sim011.bin +``` + +If you didn't install the PRoxmark but you're working from the sources directory and depending how you launch the client, your working directory might be the root of the repository: + +``` +./pm3 ... client/proxmark3 ... ``` @@ -125,6 +144,10 @@ cd client; ./proxmark3 ... Therefore client commands referring to files of the repo must be adapted, e.g. ``` +client/proxmark3-flasher armsrc/obj/fullimage.elf +<> +./proxmark3-flasher ../armsrc/obj/fullimage.elf + pm3 --> sc upgrade f tools/simmodule/sim011.bin <> pm3 --> sc upgrade f ../tools/simmodule/sim011.bin diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index f9eb9e988..6a821a992 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -54,16 +54,22 @@ pacman -S mingw-w64-x86_64-astyle Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). -To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `client/proxmark3-flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. +To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `proxmark3-flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. -To flash: In principle, the helper script `flash-all.sh` should auto-detect your COM port, so you can just try: +To flash: In principle, the helper script `pm3-flash-all` should auto-detect your COM port, so you can just try: ```sh -./flash-all.sh +pm3-flash-all ``` If COM port detection failed, you'll have to call the flasher manually and specify the correct port: +```sh +proxmark3-flasher.exe comX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +``` + +or from the local repo + ```sh client/proxmark3-flasher.exe comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` @@ -71,13 +77,13 @@ client/proxmark3-flasher.exe comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimag Similarly, to run the client, you may try: ```sh -./proxmark3.sh +pm3 ``` Or, by specifying the COM port manually: ```sh -client/proxmark3.exe comX +proxmark3.exe comX ``` # Installing on Windows with WSL @@ -141,28 +147,34 @@ and add it to your Bash profile for the next times: echo "export DISPLAY=:0" >> ~/.bashrc ``` -To flash: In principle, the helper script `flash-all.sh` should auto-detect your COMX==/dev/ttySX port, so you can just try: +To flash: In principle, the helper script `pm3-flash-all` should auto-detect your COMX==/dev/ttySX port, so you can just try: ```sh -./flash-all.sh +pm3-flash-all ``` If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -client/proxmark3-flasher /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +proxmark3-flasher.exe /dev/ttySX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +``` + +or from the local repo + +```sh +client/proxmark3-flasher.exe /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: ```sh -./proxmark3.sh +pm3 ``` Or, by specifying the COM port manually: ```sh -client/proxmark3 /dev/ttySX +proxmark3 /dev/ttySX ``` Note that it may take a quite long time for a freshly plugged Proxmark3 to be visible on a WSL /dev/ttySX port. diff --git a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md index 1e6b24b88..7faa6a658 100644 --- a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md +++ b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md @@ -24,27 +24,52 @@ git pull make clean && make all ``` +## Install + +This is an optional step. If you do + +```sh +sudo make install +``` + +Then the required files will be installed on your system, by default in `/usr/local/bin` and `/usr/local/share/proxmark3`. +Maintainers can read [this doc](../Development/Maintainers.md) to learn how to modify installation paths via `DESTDIR` and `PREFIX` Makefile variables. + +The commands given in the documentation assume you did the installation step. If you didn't, you've to adjust the commands paths and files paths accordingly, +e.g. calling `./pm3` or `client/proxmark3` instead of just `pm3` or `proxmark3`. + ## Flash the BOOTROM & FULLIMAGE -In most cases, you can run the script `flash-all.sh` which try to auto-detect the port to use, on several OS. +In most cases, you can run the script `pm3-flash-all` which try to auto-detect the port to use, on several OS. For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: +```sh +proxmark3-flasher /dev/ttyACM0 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +``` + +or from the local repo + ```sh client/proxmark3-flasher /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` ## Run the client -In most cases, you can run the script `proxmark3.sh` which try to auto-detect the port to use, on several OS. +In most cases, you can run the script `pm3` which try to auto-detect the port to use, on several OS. For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: Here, for example, for a Proxmark3 connected via USB under Linux: ```sh -cd client -./proxmark3 /dev/ttyACM0 +proxmark3 /dev/ttyACM0 +``` + +or from the local repo + +```sh +client/proxmark3 /dev/ttyACM0 ``` ## Next steps diff --git a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md index 8ec176edb..8b88115c6 100644 --- a/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md +++ b/doc/md/Use_of_Proxmark/2_Configuration-and-Verification.md @@ -46,7 +46,9 @@ Don't not turn off your device during the execution of this command!! Even its a quite fast command you should be warned. You may brick it if you interrupt it. ``` -pm3 --> sc upgrade f ../tools/simmodule/sim011.bin +pm3 --> sc upgrade f /usr/local/share/proxmark3/firmware/sim011.bin +# or if from local repo +pm3 --> sc upgrade f tools/simmodule/sim011.bin ``` You get the following output if the execution was successful: From c2b6fb16a220d391f159db8bac325fd4290226e0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 09:00:03 +0200 Subject: [PATCH 246/347] leftover sudo --- .../Installation_Instructions/ModemManager-Must-Be-Discarded.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md index bbf6f6ca6..c2c01f44f 100644 --- a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md +++ b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md @@ -121,7 +121,7 @@ In short: * unplug device * press button and keep it pressed (IMPORTANT) * plug in device -* run flash command `sudo proxmark3-flasher /dev/ttyACM0 /usr/local/share/proxmark3/firmware/fullimage.elf` +* run flash command `proxmark3-flasher /dev/ttyACM0 /usr/local/share/proxmark3/firmware/fullimage.elf` * wait until flash is finished * release button * un/plug device From 0e3d1d48072d4d12c17cadc865669c9864b35b9e Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 4 Sep 2019 10:49:16 +0200 Subject: [PATCH 247/347] Create path_notes.md Inital comment of notes about path. --- doc/path_notes.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 doc/path_notes.md diff --git a/doc/path_notes.md b/doc/path_notes.md new file mode 100644 index 000000000..3fc4d9629 --- /dev/null +++ b/doc/path_notes.md @@ -0,0 +1,80 @@ +# Notes on paths. + + +With the recent (2019-09-01) changes and creation of _make install_ command it is still easy to get lost. + +We are adapting the client to use searchFile when creating or calling a Proxmark3 command with a filename. +Here is where it tries to find the file and in which precedense order it takes. + + + + +## binary paths +This is where the executable / shellscripts will be copied to. + +``` +/usr/share/proxmark3 +/usr/local/share/proxmark3 +``` + +## User given paths +``` +~/.proxmark3/ +./ +``` + +## Proxmark3 client essential files +``` +/resources +/dictionaries +/lualibs +/luascripts +/cmdscripts +``` + +## seaching for a file +First instance where a file is found will be used in the client. + +1. share (install paths) +2. $HOME/.proxmark3 (user home directory +3. ./ (current working directory) + + +## What is where? +/resources +command like + +/dictionaries +Here you find the default dictionaries or your own used for commands like `hf mf chk`, `hf mf fchk`, `lf t55xx chk` +A dictionary file is a text based file with one key per line in hexdecimal form. +The length of the key is decided by the Proxmark3 client for the different commands. All chars afterwards on line is ignored. +if key isn't a hex number, the key is igonored. + +- t55xx, Mifare Ultralight/NTAG - uses 4 hexbytes (11223344) +- Mifare classic uses 6 hexbytes (112233445566) +- iClass uses 8 hexbytes (1122334455667788) + +/luascripts +Here you find existing lua scripts available, or where you put your own custom lua scripts. Look at existing scripts for ideas how to create your own scripts. + +/lualibs +Here is the supporting lua libraries used for lua scripts. basically reused functions in a lua file like converting string to hex etc. + +/cmdscripts +Here you find the proxmark3 client command line scripts. The client can run a text file containing Proxmark3 commands. + +a samplefile could be like this. +``` +$> cat myscript.cmd + +rem running some HF-based info commands +hf 14a info +hf mfu info +rem done +``` + +You call it with: +`$> pm3 -c myscript.cmd` + +The client will execute eachone of the commands in order and then exit. There are also a possibility to remain in the client afterward with the -i parameter +`pm3 -c myscript.cmd -i` From 4623340374b2a211b6d69e81dbef3d2cb9eef1c5 Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 4 Sep 2019 11:01:49 +0200 Subject: [PATCH 248/347] Update path_notes.md --- doc/path_notes.md | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/doc/path_notes.md b/doc/path_notes.md index 3fc4d9629..94500e52a 100644 --- a/doc/path_notes.md +++ b/doc/path_notes.md @@ -7,16 +7,50 @@ We are adapting the client to use searchFile when creating or calling a Proxmark Here is where it tries to find the file and in which precedense order it takes. - - -## binary paths -This is where the executable / shellscripts will be copied to. - +# ``` /usr/share/proxmark3 /usr/local/share/proxmark3 ``` +## binary paths +This is where the Proxmark3 executable / shellscripts will be copied to. +``` +/usr/share/proxmark3/bin +/usr/local/share/proxmark3/bin +``` + +This is where the tools executable / scripts will be copied to +``` +/usr/share/proxmark3/tools +/usr/local/share/proxmark3/tools +``` +executables: mfkey32, mfkey32v2, mfkey64, nonce2key, +scripts: pm3_eml2lower.sh, pm3_eml2upper.sh, pm3_mfdread.py, pm3_mfd2eml.py, pm3_eml2mfd.py, findbits.py, rfidtest.pl, xorcheck.py + +## JTAG stuff +This is where JTAG configurations will be copied to +``` +/usr/share/proxmark3/jtag_openocd +/usr/local/share/proxmark3/tools/jtag_openocd +``` + +# Traces +Proxmark3 client has a lot of sample trace files for many different low frequency tags. They will be copied to +``` +/usr/share/proxmark3/traces +/usr/local/share/proxmark3/traces +``` + + +# Firmware paths +This is where the recovery / firmware files will be copied to. +bootrom.elf, fullimage.elf, proxmark3_recovery.bin (used for JTAG), sim011.bin, sim011.sha512.txt +``` +/usr/share/proxmark3/firmware +/usr/local/share/proxmark3/firmware +``` + ## User given paths ``` ~/.proxmark3/ @@ -42,7 +76,7 @@ First instance where a file is found will be used in the client. ## What is where? /resources -command like +The needed files for commands like hardnested, fido, EMV, iClass. /dictionaries Here you find the default dictionaries or your own used for commands like `hf mf chk`, `hf mf fchk`, `lf t55xx chk` From affecd63bf56b9843efca56d6c1de5b128f840a1 Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 4 Sep 2019 11:03:58 +0200 Subject: [PATCH 249/347] Update path_notes.md --- doc/path_notes.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/path_notes.md b/doc/path_notes.md index 94500e52a..97c117de1 100644 --- a/doc/path_notes.md +++ b/doc/path_notes.md @@ -73,6 +73,12 @@ First instance where a file is found will be used in the client. 2. $HOME/.proxmark3 (user home directory 3. ./ (current working directory) +## .history / log files +We have now a rolling log file, created new per day. All those logfiles and the .history file is found +``` +~/.proxmar3/history.txt +~/.proxmar3/log_%Y%m%d.txt +``` ## What is where? /resources From 9d620922bb1a5f797876ed5ea51b09dcdb3c67ca Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 19:14:34 +0200 Subject: [PATCH 250/347] tweak makefile targets recovery and fullimage --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 43de3969b..a602f0578 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,9 @@ armsrc/%: FORCE cleanifplatformchanged fpga_compress/% client/%: FORCE $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C client $(patsubst client/%,%,$@) DESTDIR=$(MYDESTDIR) -recovery/%: FORCE cleanifplatformchanged bootrom/% armsrc/% +recovery/all: bootrom/all armsrc/all +recovery/install: bootrom/all armsrc/all +recovery/%: FORCE cleanifplatformchanged $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) DESTDIR=$(MYDESTDIR) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) @@ -126,12 +128,18 @@ client: client/all bootrom: bootrom/all +# aliases fullimage = armsrc + fullimage: armsrc/all +fullimage/all: armsrc/all + fullimage/clean: armsrc/clean fullimage/install: armsrc/install +fullimage/uninstall: armsrc/uninstall + recovery: recovery/all mfkey: mfkey/all From 02a2b902cebdf8693c24d8804e7fcac62ee01d2a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 19:15:13 +0200 Subject: [PATCH 251/347] document make install breakdown for maintainers --- doc/md/Development/Maintainers.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index b59987881..225912c2b 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -43,3 +43,21 @@ For verbose usage and see the actual commands being executed, add `V=1`. Default compiler is gcc but you can use clang for the non-ARM parts with e.g. `make client CC=clang CXX=clang++ LD=clang++`. +`make install` is actually triggering the following individual targets which can be accessed individually: + +* `make client/install` +* `make bootrom/install` +* `make fullimage/install` (alias of `make armsrc/install`) +* `make recovery/install` +* `make mfkey/install` +* `make nonce2key/install` +* `make fpga_compress/install` (dummy) +* some shared content installation handled by the root Makefile, which can't be installed alone: + * `pm3-*` scripts + * `tools/jtag_openocd`, `traces` + * `doc/md`, `doc/*.md` + * Tools scripts (`pm3_eml2lower.sh` etc) + * SIM firmware (beware currently it's binary blob, may break your distro policies on open source) + * udev rule on Linux + +Same logic for `make all`, `make clean`, `make uninstall` From 2ddbbd255b2ebb534e640a61a5d2f8cd0f0a1a34 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 22:53:54 +0200 Subject: [PATCH 252/347] data load: search file with and without extension .pm3 --- client/cmddata.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/cmddata.c b/client/cmddata.c index 91bf4b65a..59c80102d 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1648,8 +1648,10 @@ static int CmdLoad(const char *Cmd) { memcpy(filename, Cmd, len); char *path; - if (searchFile(&path, TRACES_SUBDIR, filename, "", false) != PM3_SUCCESS) { - return PM3_EFILE; + if (searchFile(&path, TRACES_SUBDIR, filename, ".pm3", true) != PM3_SUCCESS) { + if (searchFile(&path, TRACES_SUBDIR, filename, "", false) != PM3_SUCCESS) { + return PM3_EFILE; + } } FILE *f = fopen(path, "r"); From 7594ea49426566a40b30aafb4a786fe9b543058f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 23:13:51 +0200 Subject: [PATCH 253/347] skip comments in cmdscripts --- client/cmdparser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/cmdparser.c b/client/cmdparser.c index 768941e10..9e7b83afa 100644 --- a/client/cmdparser.c +++ b/client/cmdparser.c @@ -176,6 +176,9 @@ int CmdsParse(const command_t Commands[], const char *Cmd) { memset(cmd_name, 0, sizeof(cmd_name)); sscanf(Cmd, "%127s%n", cmd_name, &len); str_lower(cmd_name); + // Comment + if (cmd_name[0] == '#') + return PM3_SUCCESS; int i = 0; while (Commands[i].Name) { if (0 == strcmp(Commands[i].Name, cmd_name)) { From 00ad68215bd7c54a4c050abfde3f7ec6460c4cdb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 23:28:02 +0200 Subject: [PATCH 254/347] add cmdscript example --- client/Makefile | 2 +- client/cmdscripts/rdv4_init_extflash.cmd | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 client/cmdscripts/rdv4_init_extflash.cmd diff --git a/client/Makefile b/client/Makefile index 56de12f97..b670965b6 100644 --- a/client/Makefile +++ b/client/Makefile @@ -15,7 +15,7 @@ ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) include ../Makefile.defs INSTALLBIN = proxmark3 proxmark3-flasher -INSTALLSHARE = lualibs luascripts resources dictionaries +INSTALLSHARE = cmdscripts lualibs luascripts resources dictionaries VPATH = ../common uart vpath %.dic dictionaries diff --git a/client/cmdscripts/rdv4_init_extflash.cmd b/client/cmdscripts/rdv4_init_extflash.cmd new file mode 100755 index 000000000..2cae05294 --- /dev/null +++ b/client/cmdscripts/rdv4_init_extflash.cmd @@ -0,0 +1,6 @@ +#!/usr/bin/env -S pm3 -s + +mem load f mfc_default_keys m +mem load f t55xx_default_pwds t +mem load f iclass_default_keys i +lf t55xx deviceconfig z p From 43055ae6a74afd5b827f9198eafa65640da8e374 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 23:29:03 +0200 Subject: [PATCH 255/347] searchFile for cmdscripts --- client/proxmark3.c | 16 +++++++++++----- include/common.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index cb3444ad7..7e732360f 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -27,6 +27,7 @@ #include "cmdhw.h" #include "whereami.h" #include "comms.h" +#include "fileutils.h" //#include "usart.h" static void showBanner(void) { @@ -95,11 +96,16 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { if (script_cmds_file) { - sf = fopen(script_cmds_file, "r"); - if (sf) - PrintAndLogEx(SUCCESS, "executing commands from file: %s\n", script_cmds_file); - else - PrintAndLogEx(ERR, "could not open " _YELLOW_("%s") "...", script_cmds_file); + char *path; + int res = searchFile(&path, CMD_SCRIPTS_SUBDIR, script_cmds_file, ".cmd", false); + if (res == PM3_SUCCESS) { + sf = fopen(path, "r"); + if (sf) + PrintAndLogEx(SUCCESS, "executing commands from file: %s\n", path); + else + PrintAndLogEx(ERR, "could not open " _YELLOW_("%s") "...", path); + free(path); + } } char *my_history_path = NULL; diff --git a/include/common.h b/include/common.h index bdda44aae..f13f5f99a 100644 --- a/include/common.h +++ b/include/common.h @@ -24,6 +24,7 @@ #define PM3_USER_DIRECTORY PATHSEP ".proxmark3" PATHSEP // PM3 subdirectories: +#define CMD_SCRIPTS_SUBDIR "cmdscripts" PATHSEP #define DICTIONARIES_SUBDIR "dictionaries" PATHSEP #define LUA_LIBRARIES_SUBDIR "lualibs" PATHSEP #define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP From d84c0397426575102e87fff77236733a1d526ceb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 23:36:23 +0200 Subject: [PATCH 256/347] Example of shebang on Lua script --- client/luascripts/cmdline.lua | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 client/luascripts/cmdline.lua diff --git a/client/luascripts/cmdline.lua b/client/luascripts/cmdline.lua old mode 100644 new mode 100755 index dc1e752c1..baa76eed6 --- a/client/luascripts/cmdline.lua +++ b/client/luascripts/cmdline.lua @@ -1,5 +1,8 @@ +#!/usr/bin/env -S pm3 -l + --[[ A sampe script file on how to implement at cmd line inteface. +It also demonstrates how the script can be used with a shebang. --]] print("This is how a cmd-line interface could be implemented\nPrint 'exit' to exit.\n") From f8636b18dbdc1f508de37d53b752a0659552f26e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 4 Sep 2019 23:40:42 +0200 Subject: [PATCH 257/347] searchFile: HOME takes precedence on repo and installed paths, more coherent --- client/fileutils.c | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 1c0403294..a4521fcf8 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -899,6 +899,30 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea return PM3_SUCCESS; } } + // try pm3 dirs in user .proxmark3 (user mode) + char *user_path = getenv("HOME"); + if (user_path != NULL) { + char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); + if (path == NULL) + goto out; + strcpy(path, user_path); + strcat(path, PM3_USER_DIRECTORY); + strcat(path, pm3dir); + strcat(path, filename); + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Searching %s", path); + } + if (fileExists(path)) { + free(filename); + *foundpath = path; + if ((g_debugMode == 2) && (!silent)) { + PrintAndLogEx(INFO, "Found %s", *foundpath); + } + return PM3_SUCCESS; + } else { + free(path); + } + } // try pm3 dirs in current client workdir (dev mode) const char *exec_path = get_my_executable_directory(); if ((exec_path != NULL) && @@ -951,30 +975,6 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea free(path); } } - // try pm3 dirs in user .proxmark3 (user mode) - char *user_path = getenv("HOME"); - if (user_path != NULL) { - char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); - if (path == NULL) - goto out; - strcpy(path, user_path); - strcat(path, PM3_USER_DIRECTORY); - strcat(path, pm3dir); - strcat(path, filename); - if ((g_debugMode == 2) && (!silent)) { - PrintAndLogEx(INFO, "Searching %s", path); - } - if (fileExists(path)) { - free(filename); - *foundpath = path; - if ((g_debugMode == 2) && (!silent)) { - PrintAndLogEx(INFO, "Found %s", *foundpath); - } - return PM3_SUCCESS; - } else { - free(path); - } - } // try pm3 dirs in pm3 installation dir (install mode) { char *path = calloc(strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); From 505eb0a3ca09f064142d82c406b2cd6a7ae8bba9 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 00:11:34 +0200 Subject: [PATCH 258/347] path notes: updates --- doc/path_notes.md | 257 +++++++++++++++++++++++++++++++--------------- 1 file changed, 174 insertions(+), 83 deletions(-) diff --git a/doc/path_notes.md b/doc/path_notes.md index 97c117de1..c263adb57 100644 --- a/doc/path_notes.md +++ b/doc/path_notes.md @@ -1,109 +1,178 @@ # Notes on paths. -With the recent (2019-09-01) changes and creation of _make install_ command it is still easy to get lost. +With the recent (2019-09-01) changes and creation of `make install` command it is still easy to get lost. -We are adapting the client to use searchFile when creating or calling a Proxmark3 command with a filename. -Here is where it tries to find the file and in which precedense order it takes. +If you install the Proxmark tools yourself with `make install`, they will go under the prefix `/usr/local/` but if you install the tools from your distro, there are chances the path is `/usr` so you'll have to adapth the paths presented here. + +# Installed elements + +## Binaries + +The main Proxmark3 executables / shellscripts will be copied to + +`/usr/local/bin/` + +* executables: `proxmark3`, `proxmark3-flasher` +* scripts: `pm3`, `pm3-flash-all`, `pm3-flash-bootloader`, `pm3-flash-fullimage` + +Some more executable / scripts will be copied to + +`/usr/local/share/proxmark3/tools` + +* executables: `mfkey32`, `mfkey32v2`, `mfkey64`, `nonce2key` +* scripts: `pm3_eml2lower.sh`, `pm3_eml2upper.sh`, `pm3_mfdread.py`, `pm3_mfd2eml.py`, `pm3_eml2mfd.py`, `findbits.py`, `rfidtest.pl`, `xorcheck.py` -# -``` -/usr/share/proxmark3 -/usr/local/share/proxmark3 -``` +## Firmwares -## binary paths -This is where the Proxmark3 executable / shellscripts will be copied to. -``` -/usr/share/proxmark3/bin -/usr/local/share/proxmark3/bin -``` +The recovery / firmware files will be copied to -This is where the tools executable / scripts will be copied to -``` -/usr/share/proxmark3/tools -/usr/local/share/proxmark3/tools -``` -executables: mfkey32, mfkey32v2, mfkey64, nonce2key, -scripts: pm3_eml2lower.sh, pm3_eml2upper.sh, pm3_mfdread.py, pm3_mfd2eml.py, pm3_eml2mfd.py, findbits.py, rfidtest.pl, xorcheck.py +`/usr/local/share/proxmark3/firmware` -## JTAG stuff -This is where JTAG configurations will be copied to -``` -/usr/share/proxmark3/jtag_openocd -/usr/local/share/proxmark3/tools/jtag_openocd -``` +* Proxmark3 firmware: `bootrom.elf`, `fullimage.elf`, `proxmark3_recovery.bin` (used for JTAG) +* SIM firmware: `sim011.bin`, `sim011.sha512.txt` + + +## Traces -# Traces Proxmark3 client has a lot of sample trace files for many different low frequency tags. They will be copied to -``` -/usr/share/proxmark3/traces -/usr/local/share/proxmark3/traces -``` + +`/usr/local/share/proxmark3/traces` -# Firmware paths -This is where the recovery / firmware files will be copied to. -bootrom.elf, fullimage.elf, proxmark3_recovery.bin (used for JTAG), sim011.bin, sim011.sha512.txt +## JTAG-related stuff + +JTAG configurations and helper scripts for OpenOCD will be copied to + +`/usr/local/share/proxmark3/jtag_openocd` + +## Proxmark3 client files: dictionaries + +Dictionaries used by the client will be copied to + ``` -/usr/share/proxmark3/firmware -/usr/local/share/proxmark3/firmware +/usr/local/share/proxmark3/dictionaries ``` -## User given paths -``` -~/.proxmark3/ -./ -``` - -## Proxmark3 client essential files -``` -/resources -/dictionaries -/lualibs -/luascripts -/cmdscripts -``` - -## seaching for a file -First instance where a file is found will be used in the client. - -1. share (install paths) -2. $HOME/.proxmark3 (user home directory -3. ./ (current working directory) - -## .history / log files -We have now a rolling log file, created new per day. All those logfiles and the .history file is found -``` -~/.proxmar3/history.txt -~/.proxmar3/log_%Y%m%d.txt -``` - -## What is where? -/resources -The needed files for commands like hardnested, fido, EMV, iClass. - -/dictionaries -Here you find the default dictionaries or your own used for commands like `hf mf chk`, `hf mf fchk`, `lf t55xx chk` +Here you find the default dictionaries used for commands like `hf mf chk`, `hf mf fchk`, `lf t55xx chk` A dictionary file is a text based file with one key per line in hexdecimal form. The length of the key is decided by the Proxmark3 client for the different commands. All chars afterwards on line is ignored. if key isn't a hex number, the key is igonored. -- t55xx, Mifare Ultralight/NTAG - uses 4 hexbytes (11223344) +- t55xx, Mifare Ultralight/NTAG - uses 4 hexbytes (11223344) - Mifare classic uses 6 hexbytes (112233445566) - iClass uses 8 hexbytes (1122334455667788) -/luascripts -Here you find existing lua scripts available, or where you put your own custom lua scripts. Look at existing scripts for ideas how to create your own scripts. +See [here](#proxmark3-client-files-and-traces) how to add your own dictionaries. -/lualibs -Here is the supporting lua libraries used for lua scripts. basically reused functions in a lua file like converting string to hex etc. +## Proxmark3 client files: cmd scripts -/cmdscripts -Here you find the proxmark3 client command line scripts. The client can run a text file containing Proxmark3 commands. +Cmd scripts used by the client will be copied to -a samplefile could be like this. +``` +/usr/local/share/proxmark3/cmdscripts +``` + +See [here](#proxmark3-client-files-and-traces) how to add your own cmd scripts. + +## Proxmark3 client files: Lua libraries and scripts + +Lua libraries and scripts used by the client will be copied to + +``` +/usr/local/share/proxmark3/lualibs +/usr/local/share/proxmark3/luascripts +``` + +`lualibs` contains the supporting lua libraries used for lua scripts. Basically reused functions in a lua file like converting string to hex etc. + +See [here](#proxmark3-client-files-and-traces) how to add your own Lua scripts. + +## Proxmark3 client files: various resources + +Various resources used by the client will be copied to + +``` +/usr/local/share/proxmark3/resources +``` + +It comprises the needed files for commands like hardnested, fido, EMV, iClass. + +See [here](#proxmark3-client-files-and-traces) how to add your own resources. + +## Documentation + +Documentation will be copied to + +`/usr/local/share/doc/proxmark3` + +# User files + +The client will make use of a personal directory `~/.proxmark3` (or more precisely `$HOME/.proxmark3`) + +## .history / log files + +We have now a rolling log file, created new per day. All these logfiles and the history file are now located at + +``` +~/.proxmark3/history.txt +~/.proxmark3/log_YYYYMMDD.txt +``` + +## Proxmark3 client files and traces + +If you wants to add scripts, dictionaries or other resources, you can use the same structure as the installed directory structure and add your own files there, e.g. + +``` +~/.proxmark3/cmdscripts/mycmdscript.cmd +~/.proxmark3/dictionaries/mydict.dic +~/.proxmark3/luascripts/myluascript.lua +~/.proxmark3/resources/oids.json +~/.proxmark3/traces/mylftrace.pm3 +``` + +If you add a file with the same name as the file provided with the Proxmark3 installation, it will take precedence. + +See also [Scripts](#scripts) on how to write your own scripts. + +# Seaching files + +With the directory structure explained above, the client applies some heuristics to find its files or the files you specified in command line. + +## TL;DR + +It adds the expected suffix if you didn't provide it yet, then it looks (by order of precedence): + +1. in the current directory, or in the path if you provided also a path, so it works with autocompletion +2. in the `~/.proxmark3` directory structure as seen above, so it works with your stuffs +3. in the repo directory structure, so it works as usual if used from the Git repo +4. in the installed directory structure, so it works when installed + +## Gory details + +The client is using _searchFile_ (in _client/fileutils.c_) when calling a Proxmark3 command with a filename or when the client needs to find its files. +_searchFile_ takes as argument a relative path *pm3dir*, a file to search and possibly a *suffix*. + +So for example when using _searchFile_ over a filename supposed to be a dictionary file, it's called with *pm3dir=dictionaries/* and *suffix=.dic*. +When a user provides a filename (including possibly a path), _searchFile_ will search different locations and return as soon as a file is found: + +* Add the suffix if the suffix is not yet present, so: *foo* -> *foo.dic* and *foo.dic* -> *foo.dic* +* If the filename is an absolute path (*/tmp/foo.dic*), take it as it is, try to access the file and return. +* If the filename is an explicit relative path (*./foo.dic*), take it as it is, try to access the file from the current directory and return. +* Try to find the filename as relative path (*foo.dic* -> *./foo.dic*), so filenames provided by CLI autocompletion work as expected. +* Try to find the filename in the *pm3dir* relative to the user directory *$HOME/.proxmark3* (*foo.dic* -> *~/.proxmark3/dictionaries/foo.dic*) +* Try to find the filename in the *pm3dir* relative to where the client binary is when in the repo configuration (*foo.dic* -> *$(path_to_dir_of_proxmark3_bin)/dictionaries/foo.dic*), so when the client is executed from a repo workdir, filenames are searched in the expected location. +* Try to find the filename in the *pm3dir* relative to where the client binary is when in the installed configuration (*foo.dic* -> *$(path_to_dir_of_proxmark3_bin)/../share/proxmark3/dictionaries/foo.dic* which resolves to e.g. */usr/share/proxmark3/dictionaries/foo.dic* or */usr/local/share/proxmark3/dictionaries/foo.dic*), so when the client is executed from a repo workdir, filenames are searched in the expected location. + +# Scripts + +We've seen that you can provide your own Lua or cmd scripts. +Look at existing scripts for ideas how to create your own scripts. + +For cmd scripts, the command line scripts, the client can run a text file containing Proxmark3 commands. + +A samplefile could be like this. ``` $> cat myscript.cmd @@ -114,7 +183,29 @@ rem done ``` You call it with: -`$> pm3 -c myscript.cmd` -The client will execute eachone of the commands in order and then exit. There are also a possibility to remain in the client afterward with the -i parameter -`pm3 -c myscript.cmd -i` +`$> pm3 -s myscript.cmd` + +The client will execute each one of the commands in order and then exit. There is also a possibility to remain in the client afterwards with the -i parameter: + +`$> pm3 -s myscript.cmd -i` + +You can place it in `~/.proxmark3/cmdscripts/` and it will be found automatically. +You can skip the extension, so `pm3 -s myscript` works equally. + +You can also use the magic of shebangs to make an executable script, e.g. taking the example above, we can write: + +``` +$> cat myscript.cmd + +#!/usr/bin/env -S pm3 -s +hf 14a info +hf mfu info + +$> chmod +x myscript.cmd +$> ./myscript.cmd +``` + +And it will be executed invoking the `pm3` script! + +Or use `#!/usr/bin/env -S proxmark3 -s` if your script is intended to work offline. From 620be5f5ccdbb1d2ba3ab74077856f4705db3380 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 00:14:30 +0200 Subject: [PATCH 259/347] doc style --- doc/path_notes.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/doc/path_notes.md b/doc/path_notes.md index c263adb57..cfe532daf 100644 --- a/doc/path_notes.md +++ b/doc/path_notes.md @@ -11,14 +11,18 @@ If you install the Proxmark tools yourself with `make install`, they will go und The main Proxmark3 executables / shellscripts will be copied to -`/usr/local/bin/` +``` +/usr/local/bin/ +``` * executables: `proxmark3`, `proxmark3-flasher` * scripts: `pm3`, `pm3-flash-all`, `pm3-flash-bootloader`, `pm3-flash-fullimage` Some more executable / scripts will be copied to -`/usr/local/share/proxmark3/tools` +``` +/usr/local/share/proxmark3/tools +``` * executables: `mfkey32`, `mfkey32v2`, `mfkey64`, `nonce2key` * scripts: `pm3_eml2lower.sh`, `pm3_eml2upper.sh`, `pm3_mfdread.py`, `pm3_mfd2eml.py`, `pm3_eml2mfd.py`, `findbits.py`, `rfidtest.pl`, `xorcheck.py` @@ -28,7 +32,9 @@ Some more executable / scripts will be copied to The recovery / firmware files will be copied to -`/usr/local/share/proxmark3/firmware` +``` +/usr/local/share/proxmark3/firmware +``` * Proxmark3 firmware: `bootrom.elf`, `fullimage.elf`, `proxmark3_recovery.bin` (used for JTAG) * SIM firmware: `sim011.bin`, `sim011.sha512.txt` @@ -38,7 +44,9 @@ The recovery / firmware files will be copied to Proxmark3 client has a lot of sample trace files for many different low frequency tags. They will be copied to -`/usr/local/share/proxmark3/traces` +``` +/usr/local/share/proxmark3/traces +``` ## JTAG-related stuff @@ -105,7 +113,9 @@ See [here](#proxmark3-client-files-and-traces) how to add your own resources. Documentation will be copied to -`/usr/local/share/doc/proxmark3` +``` +/usr/local/share/doc/proxmark3 +``` # User files From 7151f3fd50b4c1aa5b37de242e9f5a52364bbce6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 00:27:15 +0200 Subject: [PATCH 260/347] Provide make common/install --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a602f0578..bca9681d4 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,9 @@ INSTALLSCRIPTS=pm3 pm3-flash-all pm3-flash-bootrom pm3-flash-fullimage INSTALLSHARES=tools/jtag_openocd traces INSTALLDOCS=doc/*.md doc/md -install: all +install: all common/install + +common/install: $(info [@] Installing common resources to $(MYDESTDIR)$(PREFIX)...) ifneq (,$(INSTALLSCRIPTS)) $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) @@ -49,7 +51,9 @@ ifeq ($(platform),Linux) $(Q)$(CP) driver/77-pm3-usb-device-blacklist.rules $(DESTDIR)$(UDEV_PREFIX)/77-pm3-usb-device-blacklist.rules endif -uninstall: +uninstall: common/uninstall + +common/uninstall: $(info [@] Uninstalling common resources from $(MYDESTDIR)$(PREFIX)...) ifneq (,$(INSTALLSCRIPTS)) $(Q)$(RM) $(foreach script,$(INSTALLSCRIPTS),$(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)$(notdir $(script))) From 326547281d8d6be8ac01d7f90b46f2c266fc324d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 00:37:25 +0200 Subject: [PATCH 261/347] update docs --- Makefile | 2 ++ doc/md/Development/Maintainers.md | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bca9681d4..77e038124 100644 --- a/Makefile +++ b/Makefile @@ -112,6 +112,8 @@ help: @echo "+ all - Make all targets: bootrom, fullimage and OS-specific host tools" @echo "+ clean - Clean in all targets" @echo "+ .../clean - Clean in specified target and its deps, e.g. bootrom/clean" + @echo "+ (un)install - Install/uninstall Proxmark files in the system, default to /usr/local/share, + @echo " else provide a PREFIX. See Maintainers.md for more options" @echo @echo "+ bootrom - Make bootrom" @echo "+ fullimage - Make armsrc fullimage (includes fpga)" diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index 225912c2b..0dda8af3d 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -29,7 +29,10 @@ That should be a good start for you to create your package :) It's possible to add other firmwares as well with tagged names (`FWTAG=`), e.g. here we're compiling another image for non-RDV4 devices: -`make -j fullimage/install DESTDIR=build PREFIX=/usr PLATFORM=PM3OTHER PLATFORM_EXTRAS= FWTAG=other` +``` +make -j fullimage PLATFORM=PM3OTHER PLATFORM_EXTRAS= +make fullimage/install PLATFORM=PM3OTHER PLATFORM_EXTRAS= DESTDIR=build PREFIX=/usr FWTAG=other +``` and it will be added along the other firmware as: @@ -52,7 +55,7 @@ Default compiler is gcc but you can use clang for the non-ARM parts with e.g. `m * `make mfkey/install` * `make nonce2key/install` * `make fpga_compress/install` (dummy) -* some shared content installation handled by the root Makefile, which can't be installed alone: +* `make common/install` (some shared content installation:) * `pm3-*` scripts * `tools/jtag_openocd`, `traces` * `doc/md`, `doc/*.md` From 22c5364a232cf0131f4d2ed88f5e8f5407ccd670 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 00:48:14 +0200 Subject: [PATCH 262/347] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fcbc68d8..c4e1fe1fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ 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... ## [unreleased][unreleased] + - Add cmdscript example and show usage with shebang (@doegox) + - Add instructions for Fedora (@doegox) + - Chg reduce the list of requirements to the minimum and move to QT5 (@doegox) + - Add `make install` and reorganize/rename stuffs accordingly (@doegox) + - Add searchFile for several types of files (@doegox / @iceman1001) - Chg posix sh version of mkversion (@doegox) - Chg remove entirely ncurses, not needed nowadays (@doegox) - Chg remove deprecated termcap, use ncurses instead (@ZeroChaos-) From ecb535cc58b8ba01301c07c0168f3179e2eca2da Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 00:48:48 +0200 Subject: [PATCH 263/347] make style --- client/cmdflashmem.c | 2 +- client/cmdflashmemspiffs.c | 4 ++-- client/scripting.c | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 0fb25fad9..ce5b37f44 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -209,7 +209,7 @@ static int CmdFlashMemLoad(const char *Cmd) { datalen += 2; break; case DICTIONARY_NONE: - res = loadFile_safe(filename, ".bin", (void**)&data, &datalen); + res = loadFile_safe(filename, ".bin", (void **)&data, &datalen); if (res != PM3_SUCCESS) { free(data); return PM3_EFILE; diff --git a/client/cmdflashmemspiffs.c b/client/cmdflashmemspiffs.c index 0eef78259..109f51ae1 100644 --- a/client/cmdflashmemspiffs.c +++ b/client/cmdflashmemspiffs.c @@ -355,13 +355,13 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) { size_t datalen = 0; uint8_t *data = NULL; - int res = loadFile_safe(filename, "", (void**)&data, &datalen); + int res = loadFile_safe(filename, "", (void **)&data, &datalen); // int res = loadFileEML( filename, data, &datalen); if (res != PM3_SUCCESS) { free(data); return PM3_EFILE; } - + // We want to mount before multiple operation so the lazy writes/append will not // trigger a mount + umount each loop iteration (lazy ops device side) SendCommandNG(CMD_SPIFFS_MOUNT, NULL, 0); diff --git a/client/scripting.c b/client/scripting.c index 33e7c6c42..724f72235 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1059,20 +1059,20 @@ static int l_searchfile(lua_State *L) { if (n != 2) { return returnToLuaWithError(L, "Only filename and extension"); } - + size_t size; - // data + // data const char *filename = luaL_checklstring(L, 1, &size); - if ( size == 0 ) + if (size == 0) return returnToLuaWithError(L, "Must specify filename"); - - const char *suffix = luaL_checklstring(L, 2, &size); + + const char *suffix = luaL_checklstring(L, 2, &size); char *path; int res = searchFile(&path, "", filename, suffix, false); - if ( res != PM3_SUCCESS) { + if (res != PM3_SUCCESS) { return returnToLuaWithError(L, "Failed to find file"); } - + lua_pushstring(L, path); return 1; } From 70a7a99751832a2c2cfdb79f8f8e9b114bfcc9b5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 08:45:12 +0200 Subject: [PATCH 264/347] make install: more flexible on relpath tuning --- Makefile.defs | 10 +++++----- doc/md/Development/Maintainers.md | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Makefile.defs b/Makefile.defs index 6364c794a..64e74c243 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -28,11 +28,11 @@ LD = g++ PATHSEP=/ PREFIX ?= /usr/local UDEV_PREFIX ?= /etc/udev/rules.d -INSTALLBINRELPATH = /bin/ -INSTALLSHARERELPATH = /share/proxmark3/ -INSTALLFWRELPATH = /share/proxmark3/firmware/ -INSTALLTOOLSRELPATH = /share/proxmark3/tools/ -INSTALLDOCSRELPATH = /share/doc/proxmark3/ +INSTALLBINRELPATH ?= /bin/ +INSTALLSHARERELPATH ?= /share/proxmark3/ +INSTALLFWRELPATH ?= /share/proxmark3/firmware/ +INSTALLTOOLSRELPATH ?= /share/proxmark3/tools/ +INSTALLDOCSRELPATH ?= /share/doc/proxmark3/ platform = $(shell uname) DETECTED_OS=$(platform) diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index 0dda8af3d..3d5e6dbef 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -27,6 +27,15 @@ etc. That should be a good start for you to create your package :) +If you need to tune some more paths, see their definition in `Makefile.defs`. +E.g. you might need to move the documentation elsewhere according to your distro policy: + +``` +make install PREFIX=/usr INSTALLDOCSRELPATH=/share/doc/proxmark3-${version}/ +``` + +Be careful to respect the same leading/closing `/` schema else you'll mess up your paths! + It's possible to add other firmwares as well with tagged names (`FWTAG=`), e.g. here we're compiling another image for non-RDV4 devices: ``` From 5dc63fa2392b123862b320b1e3a4ae8e1bdffb96 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 09:29:45 +0200 Subject: [PATCH 265/347] Add sim011.asm --- doc/md/Development/Maintainers.md | 2 +- tools/simmodule/sim010.bin | Bin 719 -> 0 bytes tools/simmodule/sim010.sha512.txt | 1 - tools/simmodule/sim011.asm | 713 ++++++++++++++++++++++++++++++ 4 files changed, 714 insertions(+), 2 deletions(-) delete mode 100644 tools/simmodule/sim010.bin delete mode 100644 tools/simmodule/sim010.sha512.txt create mode 100644 tools/simmodule/sim011.asm diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index 3d5e6dbef..bc6b66cf5 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -69,7 +69,7 @@ Default compiler is gcc but you can use clang for the non-ARM parts with e.g. `m * `tools/jtag_openocd`, `traces` * `doc/md`, `doc/*.md` * Tools scripts (`pm3_eml2lower.sh` etc) - * SIM firmware (beware currently it's binary blob, may break your distro policies on open source) + * SIM firmware * udev rule on Linux Same logic for `make all`, `make clean`, `make uninstall` diff --git a/tools/simmodule/sim010.bin b/tools/simmodule/sim010.bin deleted file mode 100644 index dea57a7d8608a34020f7d9e5e40a5b6e915be6fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 719 zcmbVJO=uHA6rS1L$-l5DLa~?K$zPi&EQ<%hi&CM-7^G)Cc=O`ri3c%jCH{bwbYmf* z2XzZliW1uHp@&G~bZdKD268JV2XpY2OEJ|ZaaU8USKl1o_kF{A?|VD}ucL7&IpOTI zGD})h0x#>wDni)!i+zOG{^kG6Sf3s0az&D>s?L!joojZ8)vXrkJUqrdLW$*eSQ(}+ zl9bMadb87X!JVjmY@jfA*tX&f)Jo%)%uI%v$OsFt5DTkj!?>s59LL?d9h7*~Ahr-= zQAi?AAc0iV#;3RdDFhTj+~)y7eQisz`&mdM$VlAlVUuG@e5#rXi78=0HQ&`kB(0iU z^qkg<3C}6&kp!_w(i{9{lABssVqqT9#7j)%(upyRRlyJ&TdEc!PwFABV<5-_#Z+B2 ziB*jID|Zg+Bu*^0!yL|B*IRyD_e^C1kQLy(2p1yUtAj^-uyF;}M_}KC%`NzV;Qa`m zQ+R=3;Tt@ggWWaQots(2uqpq+Hx`G`yvASgGJI-6#f7H^^sj>xf}QX1c?3%WC +; --------------------------------------------------------------------------- + VERS_HI equ 3 + VERS_LO equ 11 +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- + SCON_0 equ 098h + FE_0 equ 098h.7 + + SCON_1 equ 0F8h + RI_1 equ 0F8h.0 + TI_1 equ 0F8h.1 + FE_1 equ 0F8h.7 + SBUF_1 equ 09Ah + T3CON equ 0C4h + RL3 equ 0C5h + RH3 equ 0C6h + + P0M1 equ 0B1h + P0M2 equ 0B2h + P1M1 equ 0B3h + P1M2 equ 0B4h + P3M1 equ 0ACh; + P3M2 equ 0ADh; + + EIE equ 09Bh + EIE1 equ 09Ch + + TA equ 0C7h + + RCTRIM0 equ 084h +; --------------------------------------------------------------------------- + CKCON equ 08Eh + CKDIV equ 095h +; --------------------------------------------------------------------------- + P1S equ 0B3h ;Page1 + SFRS equ 091h ;TA Protection +; --------------------------------------------------------------------------- + AUXR1 equ 0A2h +; --------------------------------------------------------------------------- + I2DAT equ 0BCh; + I2STAT equ 0BDh; + I2CLK equ 0BEh; + I2TOC equ 0BFh; + I2CON equ 0C0h; + ; equ I2CON.7;8 + I2CEN equ I2CON.6;4 + STA equ I2CON.5;2 + STO equ I2CON.4;1 + SI equ I2CON.3;8 + AA equ I2CON.2;4 + ; equ I2CON.1;2 + I2CPX equ I2CON.0;1 + + + I2ADDR equ 0C1h; + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- + pin_TX1 equ P1.6 + + pin_TX0 equ P0.6 + pin_RX0 equ P0.7 + + pin_SCL equ P1.3 + pin_SDA equ P1.4 + + pin_RST equ P1.0 + pin_CLC equ P1.1 + pin_led equ P1.2 + +; --------------------------------------------------------------------------- +; =========================================================================== + + + CMD_GENERATE_ATR equ 01h + CMD_WRITE_DATA_SIM equ 02h + CMD_READ_DATA_SIM equ 03h + + CMD_SET_BAUD_RATE equ 04h + CMD_SET_SIM_CLC equ 05h + CMD_GET_VERS equ 06h + CMD_WRITE_CONFIRM equ 07h + + + +; --------------------------------------------------------------------------- +; =========================================================================== + + bit_RX0 equ 32.0 + bit_command_receive equ 32.1 + bit_generate_ATR equ 32.2 + i2c_write_mode equ 32.3 + i2c_write_done equ 32.4 + bit_data_sim_wr equ 32.5 + bit_length_answer equ 32.6 + bit_TX0 equ 32.7 + + bit_command_buff equ 33.0 + i2c_write_command equ 33.1 + i2c_command_done equ 33.2 + bit_wait_confirm equ 33.3 + bit_first_ATR equ 33.4 ;11/03/2019 +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + bit_32 equ 32 + bit_33 equ 33 + pointer_RX1 equ 34 ;save SBUF(SIM) to XRAM + pointer_RX2 equ 35 ;read XRAM to I2C + pointer_TX equ 36 + + length_send_to_sim equ 37 + length_answer_sim equ 38 + length_command equ 39 + time_data_read equ 40 + time_confirm equ 41 + + buff_command equ 42 + cmd_command equ 42 + data_command equ 43 + + STACKKKKK equ 200 +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +; Beginning of the main program + cseg at 00 + Ljmp main_start + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- + cseg at 11 ;1302Hz = 4MHZ(Fsys)/12/256 +; --------------------------------------------------------------------------- + jb time_confirm.7, $+3+2 ;3 + dec time_confirm ;2 +; --------------------------------------------------------------------------- + jb time_data_read.7,reti_timer0 + djnz time_data_read, reti_timer0 + setb pin_scl +reti_timer0: + reti + + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- + cseg at 35 ;UART0 + ajmp jmp_UART0_interrupt + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- + cseg at 51 ;I2C + ajmp jmp_i2c_interrupt + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- + cseg at 123 ;UART1 + clr RI_1 + clr TI_1 + reti + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +jmp_UART0_interrupt: + jbc RI,jmp_byte_RI + jbc TI,jmp_byte_TI + reti +; --------------------------------------------------------------------------- +jmp_byte_RI: + jnb bit_first_ATR, jmp_not_collect ;11/03/2019 + + setb bit_RX0 + jb i2c_write_done,jmp_not_collect + PUSH ACC + inc AUXR1 ;DPTR2 + mov a,SBUF ;DPTR2 + ;mov SBUF_1,DPL ;DPTR2 + mov DPL,pointer_RX1 ;DPTR2 + mov DPH,#1 ;DPTR2 + movx @DPTR,a ;DPTR2 + inc pointer_RX1 ;DPTR2 + inc AUXR1 ;DPTR2 + POP ACC + ;09/08/2018 + clr pin_scl + mov time_data_read,#52 ;52/1302Hz = 40mS + + inc length_answer_sim +jmp_not_collect: + reti +; --------------------------------------------------------------------------- +jmp_byte_TI: + setb bit_TX0 + reti + + +; =========================================================================== +; --------------------------------------------------------------------------- +jmp_i2c_interrupt: + PUSH ACC + PUSH PSW + mov PSW,#24 + mov R7,I2STAT +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + cjne R7,#000h,nextttt00000 + setb STO + clr SI + jb STO,$ + ajmp pop_i2c_psw +nextttt00000: +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + cjne R7,#060h,nextttt00001 ;START+MY ADRESS + clr pin_led ;LED ON + + clr bit_command_receive + clr i2c_write_mode + clr bit_data_sim_wr + clr bit_length_answer + clr bit_command_buff + clr i2c_write_command + + ajmp end_i2c_interrupt +nextttt00001: +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + cjne R7,#080h,nextttt00002 ;RAM ADRESS + + jb bit_command_receive,jmp_data_receive + setb bit_command_receive + + mov a,I2DAT +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + cjne a,#CMD_WRITE_CONFIRM,next_comm001a + + setb bit_wait_confirm + + sjmp jmp_WRITEDATASIM +next_comm001a: +; --------------------------------------------------------------------------- + cjne a,#CMD_WRITE_DATA_SIM,next_comm001b + clr bit_wait_confirm +jmp_WRITEDATASIM: + mov length_send_to_sim,#0 + setb bit_data_sim_wr + mov pointer_TX,#0 + ajmp end_i2c_interrupt +next_comm001b: +; --------------------------------------------------------------------------- + cjne a,#CMD_GENERATE_ATR,next_comm002 + setb bit_generate_ATR + ;Prepare to answer + mov length_answer_sim,#0 + mov pointer_RX1,#0 + mov pointer_RX2,#0 + ajmp end_i2c_interrupt +next_comm002: +; --------------------------------------------------------------------------- + cjne a,#CMD_GET_VERS,next_comm003 + ajmp ANSWER_VERS +next_comm003: +; --------------------------------------------------------------------------- + cjne a,#CMD_SET_BAUD_RATE,next_comm004 + mov R0,#data_command + mov length_command,#0 + mov cmd_command,#CMD_SET_BAUD_RATE + setb i2c_write_command + ajmp end_i2c_interrupt +next_comm004: +; --------------------------------------------------------------------------- + cjne a,#CMD_SET_SIM_CLC,next_comm005 + mov R0,#data_command + mov length_command,#0 + mov cmd_command,#CMD_SET_SIM_CLC + setb i2c_write_command + ajmp end_i2c_interrupt +next_comm005: +; --------------------------------------------------------------------------- + ajmp end_i2c_interrupt +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +jmp_data_receive: + ;What receive ? Data to SIM/Command to bridge + jb bit_data_sim_wr, jmp_data_sim_receive + jb i2c_write_command,jmp_comm_bridge_receive + ajmp end_i2c_interrupt +; --------------------------------------------------------------------------- +jmp_comm_bridge_receive: + mov @R0,I2DAT + inc R0 + inc length_command + ajmp end_i2c_interrupt +; --------------------------------------------------------------------------- +jmp_data_sim_receive: + + setb i2c_write_mode + + inc AUXR1 ;DPTR2 + mov a,I2DAT ;DPTR2 + mov DPL,pointer_TX ;DPTR2 + mov DPH,#0 ;DPTR2 + movx @DPTR,a ;DPTR2 + inc pointer_TX ;DPTR2 + inc AUXR1 ;DPTR2 + + inc length_send_to_sim + ajmp end_i2c_interrupt +nextttt00002: +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + cjne R7,#0A0h,nextttt00003 ;STOP + setb pin_led ;LED OFF + + ;Command finish ? + jnb i2c_write_command,jmp_not_command + clr i2c_write_command + setb i2c_command_done +jmp_not_command: + + ;data to SIM finish ? + jnb i2c_write_mode,end_i2c_interrupt + clr i2c_write_mode + + setb i2c_write_done + ;Prepare to answer + mov length_answer_sim,#0 + mov pointer_RX1,#0 + mov pointer_RX2,#0 + + ajmp end_i2c_interrupt +nextttt00003: +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + cjne R7,#0A8h,nextttt00004 + sjmp read_byte_I2C +nextttt00004: +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + cjne R7,#0B8h,nextttt00005 +read_byte_I2C: + jnb bit_command_buff,jmp_not_comm_buff2 + mov I2DAT,@R0 + inc R0 + ajmp end_i2c_interrupt + +jmp_not_comm_buff2: + jb bit_length_answer,read_byte_APROM + setb bit_length_answer + + mov I2DAT,length_answer_sim + ajmp end_i2c_interrupt +read_byte_APROM: + inc AUXR1 ;DPTR2 + mov DPL,pointer_RX2 ;DPTR2 + mov DPH,#1 ;DPTR2 + movx a,@DPTR ;DPTR2 + mov I2DAT,a ;DPTR2 + inc pointer_RX2 ;DPTR2 + inc AUXR1 ;DPTR2 +nextttt00005: +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +end_i2c_interrupt: + clr STA + clr STO + setb AA +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +pop_i2c_psw: + POP PSW + POP ACC + clr SI + reti + + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +ANSWER_VERS: + mov R0,#data_command + mov cmd_command,#CMD_GET_VERS + mov (data_command+0),#2 + mov (data_command+1),#VERS_HI + mov (data_command+2),#VERS_LO + setb bit_command_buff + ajmp end_i2c_interrupt + + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +main_start: + mov SP,#STACKKKKK +; --------------------------------------------------------------------------- + ;0-bidirect 1-push pull 0-input only 1-open drain + ;0 0 1 1 +; --------------------------------------------------------------------------- + mov P0M2,#01000000b ;Р0 + mov P0M1,#11111111b ;P1.6-Tx0 SIM; + ; + mov P1M2,#01011111b ;Р1 + mov P1M1,#10111000b ;P1.6-Tx1 DEBUG; P1.4,P1.3 - I2C; + + mov P3M2,#00000000b ;P3 + mov P3M1,#11111111b ; +; --------------------------------------------------------------------------- + mov TMOD, #22h + mov TH0, #0 ;14400hz + mov TH1, #0E9h ;UART0 10800 Bit/sec + mov TCON, #55h +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + mov TA,#0AAh + mov TA,#055h + orl SFRS,#00000001b + + mov P1S, #00010000b ;P1.4 trigger schmiddt + + mov TA,#0AAh + mov TA,#055h + anl SFRS,#11111110b +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + ;------- CONFIG I2C --------- + mov I2CON, #44h ;set AA, set I2C enable + setb pin_sda + setb pin_scl + mov I2ADDR,#0C0h +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + ;mov SCON, #050h ;UART0 8bit + mov SCON, #0D0h ;UART0 9bit + ;mov PCON, #11000000b;FE_0 enable + mov PCON, #10000000b;FE_0 disable +; --------------------------------------------------------------------------- + mov SCON_1,#050h ;UART1 + ;mov T3CON, #01101000b;FE_1 enable TIMER3 UART0 BAUD + ;mov T3CON, #00101000b;FE_1 disable TIMER3 UART0 BAUD + mov T3CON, #00001000b;FE_1 disable TIMER1 UART0 BAUD + ;mov RL3,#0E9h ;10800/21600 + ;mov RH3,#0FFh +; --------------------------------------------------------------------------- + ;UART1 + mov RL3,#0F7h ;27777/55556 + mov RH3,#0FFh +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + mov CKDIV,#2 ;Fsys=4.00MHZ + ;mov CKDIV,#1 ;Fsys=8.00MHZ +; --------------------------------------------------------------------------- + mov bit_32,#0 + mov bit_33,#0 + setb time_data_read.7 +; --------------------------------------------------------------------------- + ;orl CKCON,#00000010b ;ENABLE CLC TIMER1 Fsys/12 + orl CKCON,#00010010b ;ENABLE CLC TIMER1 Fsys +; --------------------------------------------------------------------------- + ;mov a,RCTRIM0 + ;add a,#31 + ;mov TA,#0AAh + ;mov TA,#055h + ;mov RCTRIM0,a +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + acall clr_buffer +; --------------------------------------------------------------------------- + mov EIE, #00000001b ;I2C Interrupt + ;mov IE, #10010000b ;EA, SERIAL0 + mov IE, #10010010b ;EA, SERIAL0, TIMER0 +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +main_loop: + acall control_ATR + acall control_send_to_sim + acall control_command + sjmp main_loop + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +control_command: + jbc i2c_command_done,$+3+1 ;3 + ret ;1 +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + ;Control Length command=1 + mov a,length_command + cjne a,#1,next_commandEND ;error length_command != 1 +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + mov a,cmd_command + cjne a,#CMD_SET_BAUD_RATE,next_command001 + mov TH1,data_command ;Timer1 HIGH byte + ret +next_command001: +; --------------------------------------------------------------------------- + cjne a,#CMD_SET_SIM_CLC, next_command002 + mov CKDIV,data_command ;Fsys DIV + ret +next_command002: +; --------------------------------------------------------------------------- +next_commandEND: + ret + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +control_send_to_sim: + jb i2c_write_done,$+3+1 ;3 + ret ;1 +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + jbc bit_wait_confirm,jmp_wait_confirm +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + mov DPTR,#0000 +looop_send: + movx a,@DPTR + inc DPTR + acall for_coooooom0 + djnz length_send_to_sim,looop_send +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + jnb bit_RX0,$ + clr i2c_write_done + ret + + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +jmp_wait_confirm: + mov DPTR,#0001 + movx a,@DPTR + mov R3,a + mov R4,#5 +; --------------------------------------------------------------------------- + mov DPTR,#0000 +looop_seend: + movx a,@DPTR + inc DPTR + acall for_coooooom0 + djnz R4,jmp_not_5byte + + jnb bit_RX0,$ + clr bit_RX0 + ;18/12/2018 + mov time_confirm,#65 ;New timeout 50mS +looop_waitconf: + jb time_confirm.7,jmp_no_answer + jnb bit_RX0,looop_waitconf + + ;clr pin_scl ;TEST PULSE! + mov a,SBUF + xrl a,R3 + ;setb pin_scl ;TEST PULSE! + + jnz jmp_no_correct_answer ;18/12/2018 + + ;pause for next byte 17/12/2018 + mov R7,#0 + djnz R7,$ ;~260mkSec + djnz R7,$ ;~260mkSec + djnz R7,$ ;~260mkSec + +jmp_not_5byte: + djnz length_send_to_sim,looop_seend +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- + jnb bit_RX0,$ + clr bit_RX0 +jmp_no_answer: + clr i2c_write_done + ret + +; --------------------------------------------------------------------------- +; --------------------------------------------------------------------------- +;18/12/2018 +jmp_no_correct_answer: + clr EA + clr i2c_write_done + mov a,SBUF + mov DPL,pointer_RX1 + mov DPH,#1 + movx @DPTR,a + inc pointer_RX1 + clr pin_scl + mov time_data_read,#52 ;52/1302Hz = 40mS + inc length_answer_sim + setb EA + ret + + + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +control_ATR: + jbc bit_generate_ATR,$+3+1 ;3 + ret ;1 +; --------------------------------------------------------------------------- + clr pin_RST + ;acall clr_buffer + ; Add rezet pause 17/12/2018 + + mov R6,#200 +looop_pause50mS: + djnz R7,$ ;~260mkSec + djnz R6,looop_pause50mS + + ;Prepare to answer 11/03/2019 + acall clr_buffer + mov length_answer_sim,#0 + mov pointer_RX1,#0 + mov pointer_RX2,#0 + setb bit_first_ATR + setb pin_RST + ret + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +for_coooooom0: + clr bit_RX0 + mov c,P + mov TB8,c ;9bit parity + mov SBUF,a + jnb bit_TX0,$ + clr bit_TX0 + mov R7,#100 + djnz R7,$ + ret + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +clr_buffer: + mov DPTR,#0256 ;Receive SIM buffer + mov R7,#255 + clr a +looop_clr_bufff: + movx @DPTR,a + inc DPTR + djnz R7,looop_clr_bufff + ret + +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- +;for_coooooom1: +; mov SBUF_1,a +; jnb TI_1,$ +; clr TI_1 +; ret +; +; --------------------------------------------------------------------------- +; =========================================================================== +; --------------------------------------------------------------------------- + +end. From b1a63eac71b6f9fca49250803268e3d20930f8de Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 5 Sep 2019 11:05:59 +0200 Subject: [PATCH 266/347] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d8492f56..6680f5333 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,12 @@ It is dedicated to bringing the most out of the new features for Proxmark3 RDV4. |[Proxmark3 GUI](#proxmark3-gui)|[Setup and build for Windows](/doc/md/Installation_Instructions/Windows-Installation-Instructions.md)|[Commands & Features](/doc/md/Use_of_Proxmark/3_Commands-and-Features.md)| |[Issues](#issues)|[Blue shark manual](/doc/bt_manual_v10.md) |[Advanced compilation parameters](/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md)| |[Notes on UART](/doc/uart_notes.md)|[Maintainers](/doc/md/Development/Maintainers.md)|[Command Cheat sheet](/doc/cheatsheet.md)| -|[Notes on Frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| +|[Notes on frame format](/doc/new_frame_format.md)||[More cheat sheets](https://github.com/RfidResearchGroup/proxmark3/wiki/More-cheat-sheets)| |[Notes on external flash](/doc/ext_flash_notes.md)||[EMV](/doc/emv_notes.md)| |[Notes on Termux / Android](/doc/termux_notes.md)||[Troubleshooting](/doc/md/Installation_Instructions/Troubleshooting.md)| -|[Notes on Wireshark / tracedata](/doc/trace_wireshark_notes.md)||[JTAG](/doc/jtag_notes.md)| +|[Notes on wireshark / tracedata](/doc/trace_wireshark_notes.md)||[JTAG](/doc/jtag_notes.md)| |[Notes on loclass](/doc/loclass_notes.md)||| +|[Notes on paths](/doc/path_notes.md)||| |[Developing standalone mode](/armsrc/Standalone/readme.md)|[Wiki about standalone mode](https://github.com/RfidResearchGroup/proxmark3/wiki/Standalone-mode) || |[Donations](#Donations)||| @@ -65,6 +66,7 @@ If you intend to contribute to the code, please read the [coding style notes](HA - Internal notes on [Wireshark / tracedata](/doc/trace_wireshark_notes.md) - Internal notes on [loclass](/doc/loclass_notes.md) - Internal notes on [EMV](/doc/emv_notes.md) +- Internal notes on [Paths](/doc/path_notes.md) ## Cheat sheet From 955eb2e5367a6ab3e7b08facbef605a931f8959c Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 5 Sep 2019 11:21:54 +0200 Subject: [PATCH 267/347] Update path_notes.md --- doc/path_notes.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/path_notes.md b/doc/path_notes.md index cfe532daf..334b435b0 100644 --- a/doc/path_notes.md +++ b/doc/path_notes.md @@ -1,9 +1,9 @@ # Notes on paths. -With the recent (2019-09-01) changes and creation of `make install` command it is still easy to get lost. +With the recent (2019-09-01) changes and creation of `make install` command it is easy to get lost. -If you install the Proxmark tools yourself with `make install`, they will go under the prefix `/usr/local/` but if you install the tools from your distro, there are chances the path is `/usr` so you'll have to adapth the paths presented here. +If you install the Proxmark tools with `make install`, they will go under the prefix `/usr/local/` but if you install the tools from your distro, there are chances the path is `/usr` so you'll have to adapt the paths presented here. # Installed elements @@ -55,6 +55,7 @@ JTAG configurations and helper scripts for OpenOCD will be copied to `/usr/local/share/proxmark3/jtag_openocd` + ## Proxmark3 client files: dictionaries Dictionaries used by the client will be copied to @@ -146,7 +147,7 @@ If you add a file with the same name as the file provided with the Proxmark3 ins See also [Scripts](#scripts) on how to write your own scripts. -# Seaching files +# Searching files With the directory structure explained above, the client applies some heuristics to find its files or the files you specified in command line. @@ -177,9 +178,10 @@ When a user provides a filename (including possibly a path), _searchFile_ will s # Scripts -We've seen that you can provide your own Lua or cmd scripts. +You can provide your own lua or cmd scripts. Look at existing scripts for ideas how to create your own scripts. +### Proxmark command script (.cmd) For cmd scripts, the command line scripts, the client can run a text file containing Proxmark3 commands. A samplefile could be like this. @@ -201,8 +203,13 @@ The client will execute each one of the commands in order and then exit. There `$> pm3 -s myscript.cmd -i` You can place it in `~/.proxmark3/cmdscripts/` and it will be found automatically. -You can skip the extension, so `pm3 -s myscript` works equally. +You can skip the script file extension, it works equally well with. + +`pm3 -s myscript` + + +### Shebangs (on *nix) You can also use the magic of shebangs to make an executable script, e.g. taking the example above, we can write: ``` @@ -216,6 +223,7 @@ $> chmod +x myscript.cmd $> ./myscript.cmd ``` -And it will be executed invoking the `pm3` script! +And it will be executed invoking the `pm3` script. -Or use `#!/usr/bin/env -S proxmark3 -s` if your script is intended to work offline. +use the following if your script is intended to work offline. +`#!/usr/bin/env -S proxmark3 -s` From 9fd646f25fc105e00e0c07f7f070d59e328b964a Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 5 Sep 2019 11:29:32 +0200 Subject: [PATCH 268/347] Create extensions_notes.md --- doc/extensions_notes.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 doc/extensions_notes.md diff --git a/doc/extensions_notes.md b/doc/extensions_notes.md new file mode 100644 index 000000000..3d4cfe5a1 --- /dev/null +++ b/doc/extensions_notes.md @@ -0,0 +1,16 @@ +# Notes on file extensions + +The Proxmark3 client uses a wide range of files. Here is a brief recap to get you up to speed. + + +- .exe windows executable +- .bin binary file, can be firmware or memory dump of a tag +- .eml text file, with memory dump of a tag +- .mfd binary file, usually created with Mifare Classic Tool app (MCT), contains memory dump of tag. Very similar to .bin file +- .json JSON file, usually settings file or it can also be a memory dump of a tag +- .dic dictionary file. textual, with keys/passwords one line / key +- .elf binary proxmark3 device firmware file. +- .cmd text file, contains proxmark3 client commands used to call client with -s +- .lua text file, contains lua script to be run inside client. or called with -l +- .pm3 text file, with numbers ranging 0-255 or -127 - 128. Contains trace signal data for low frequency tags (data load) +- .trace binary file, contains trace log data usually from high frequency tags. (hw trace load) From 9ce37fdd1c66418f69cb77801c3ae4140a91973a Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 5 Sep 2019 11:33:34 +0200 Subject: [PATCH 269/347] Update extensions_notes.md --- doc/extensions_notes.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/doc/extensions_notes.md b/doc/extensions_notes.md index 3d4cfe5a1..f8d4c75c1 100644 --- a/doc/extensions_notes.md +++ b/doc/extensions_notes.md @@ -2,15 +2,16 @@ The Proxmark3 client uses a wide range of files. Here is a brief recap to get you up to speed. - -- .exe windows executable -- .bin binary file, can be firmware or memory dump of a tag -- .eml text file, with memory dump of a tag -- .mfd binary file, usually created with Mifare Classic Tool app (MCT), contains memory dump of tag. Very similar to .bin file -- .json JSON file, usually settings file or it can also be a memory dump of a tag -- .dic dictionary file. textual, with keys/passwords one line / key -- .elf binary proxmark3 device firmware file. -- .cmd text file, contains proxmark3 client commands used to call client with -s -- .lua text file, contains lua script to be run inside client. or called with -l -- .pm3 text file, with numbers ranging 0-255 or -127 - 128. Contains trace signal data for low frequency tags (data load) -- .trace binary file, contains trace log data usually from high frequency tags. (hw trace load) +| extension | description| +|---|---| +| .exe | windows executable | +| .bin | binary file, can be firmware or memory dump of a tag | +| .eml | text file, with memory dump of a tag | +| .mfd | binary file, usually created with Mifare Classic Tool app (MCT), contains memory dump of tag. Very similar to .bin file | +| .json | JSON file, usually settings file or it can also be a memory dump of a tag | +| .dic | dictionary file. textual, with keys/passwords one line / key | +| .elf | binary proxmark3 device firmware file. | +| .cmd | text file, contains proxmark3 client commands used to call client with -s | +| .lua | text file, contains lua script to be run inside client. or called with -l | +| .pm3 | text file, with numbers ranging 0-255 or -127 - 128. Contains trace signal data for low frequency tags (data load) | +| .trace | binary file, contains trace log data usually from high frequency tags. (hw trace load) | From 1429ef20f0b1ce2c79f1397c04314cdc8e10f6a4 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 14:22:52 +0200 Subject: [PATCH 270/347] update notes --- doc/path_notes.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/path_notes.md b/doc/path_notes.md index 334b435b0..bcdc19e33 100644 --- a/doc/path_notes.md +++ b/doc/path_notes.md @@ -210,6 +210,7 @@ You can skip the script file extension, it works equally well with. ### Shebangs (on *nix) + You can also use the magic of shebangs to make an executable script, e.g. taking the example above, we can write: ``` @@ -225,5 +226,10 @@ $> ./myscript.cmd And it will be executed invoking the `pm3` script. -use the following if your script is intended to work offline. -`#!/usr/bin/env -S proxmark3 -s` +Use the following if your script is intended to work offline. + +``` +#!/usr/bin/env -S proxmark3 -s +``` + +Beware the shebang trick is not available on all the platforms, it requires your `env` to accept the `-S` switch. From 01950bd962e835e9d37596efeb4f8e9478eee34d Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 5 Sep 2019 15:46:40 +0200 Subject: [PATCH 271/347] chg more ansi color --- include/ansi.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/ansi.h b/include/ansi.h index 29df618a1..49bd46039 100644 --- a/include/ansi.h +++ b/include/ansi.h @@ -1,11 +1,14 @@ #ifndef __ANSI_H #define __ANSI_H -#define _BLUE_(s) "\x1b[34m" s "\x1b[0m " -#define _RED_(s) "\x1b[31m" s "\x1b[0m " -#define _GREEN_(s) "\x1b[32m" s "\x1b[0m " -#define _YELLOW_(s) "\x1b[33m" s "\x1b[0m " -#define _MAGENTA_(s) "\x1b[35m" s "\x1b[0m " -#define _CYAN_(s) "\x1b[36m" s "\x1b[0m " +#define AEND "\x1b[0m " + +#define _BLUE_(s) "\x1b[34m" s AEND +#define _RED_(s) "\x1b[31m" s AEND +#define _GREEN_(s) "\x1b[32m" s AEND +#define _YELLOW_(s) "\x1b[33m" s AEND +#define _MAGENTA_(s) "\x1b[35m" s AEND +#define _CYAN_(s) "\x1b[36m" s AEND +#define _WHITE_(s) "\x1b[37m" s AEND #endif From c9d42699fbb7f961cfb051a5fa90a1f2bd5b46f0 Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 5 Sep 2019 15:52:40 +0200 Subject: [PATCH 272/347] textual --- client/proxmark3.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 7e732360f..26256dd12 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -8,18 +8,15 @@ //----------------------------------------------------------------------------- // Main binary //----------------------------------------------------------------------------- + #include "proxmark3.h" - #include - #include // for Mingw readline #include #include #include #include - #include "usart_defs.h" - #include "util_posix.h" #include "proxgui.h" #include "cmdmain.h" @@ -28,7 +25,7 @@ #include "whereami.h" #include "comms.h" #include "fileutils.h" -//#include "usart.h" + static void showBanner(void) { PrintAndLogEx(NORMAL, "\n"); @@ -47,7 +44,8 @@ static void showBanner(void) { PrintAndLogEx(NORMAL, "==. ==. ... ==. ====.. https://github.com/rfidresearchgroup/proxmark3/"); PrintAndLogEx(NORMAL, "... ... ... ..... pre-release v4.0"); #endif - PrintAndLogEx(NORMAL, "\nSupport iceman on patreon, https://www.patreon.com/iceman1001/"); + PrintAndLogEx(NORMAL, "\nSupport iceman on patreon - https://www.patreon.com/iceman1001/"); + PrintAndLogEx(NORMAL, " on paypal - https://www.paypal.me/iceman1001"); // printf("\nMonero: 43mNJLpgBVaTvyZmX9ajcohpvVkaRy1kbZPm8tqAb7itZgfuYecgkRF36rXrKFUkwEGeZedPsASRxgv4HPBHvJwyJdyvQuP"); PrintAndLogEx(NORMAL, "\n"); fflush(stdout); From 3323126d7ba9df6a89c2507fbecd4a4f446b9b9f Mon Sep 17 00:00:00 2001 From: Iceman Date: Thu, 5 Sep 2019 16:07:25 +0200 Subject: [PATCH 273/347] adaption --- client/cmdhficlass.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 26e23d170..8a544f655 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -36,10 +36,10 @@ static int CmdHelp(const char *Cmd); static uint8_t iClass_Key_Table[ICLASS_KEYS_MAX][8] = { - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0xAE, 0xA6, 0x84, 0xA6, 0xDA, 0xB2, 0x32, 0x78 }, + { 0x76, 0x65, 0x54, 0x43, 0x32, 0x21, 0x10, 0x00 }, + { 0x5B, 0x7C, 0x62, 0xC4, 0x91, 0xc1, 0x1b, 0x39 }, + { 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, From 1ca235e58f5337eb06013e7c59c4d3a9e7606e44 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 5 Sep 2019 22:39:30 +0200 Subject: [PATCH 274/347] chg: `hf iclass decrypt -d` - now also reads enccrypted blockdata as param to decrypt --- client/cmdhficlass.c | 94 ++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 8a544f655..bed919cc9 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -76,14 +76,17 @@ static int usage_hf_iclass_decrypt(void) { PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside"); PrintAndLogEx(NORMAL, "in the resources directory. The file should be 16 bytes binary data"); PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: hf iclass decrypt f k "); + PrintAndLogEx(NORMAL, "Usage: hf iclass decrypt d f k "); PrintAndLogEx(NORMAL, " options"); - PrintAndLogEx(NORMAL, " f filename of dump"); - PrintAndLogEx(NORMAL, " k 16 bytes hex"); + PrintAndLogEx(NORMAL, " d 16 bytes hex") + PrintAndLogEx(NORMAL, " f filename of dump"); + PrintAndLogEx(NORMAL, " k 16 bytes hex"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, "S hf iclass decrypt f tagdump_1.bin"); PrintAndLogEx(NORMAL, "S hf iclass decrypt f tagdump_1.bin k 000102030405060708090a0b0c0d0e0f"); + PrintAndLogEx(NORMAL, "S hf iclass decrypt d 1122334455667788 k 000102030405060708090a0b0c0d0e0f"); + return PM3_SUCCESS; } static int usage_hf_iclass_encrypt(void) { @@ -796,8 +799,12 @@ static int CmdHFiClassDecrypt(const char *Cmd) { bool errors = false; bool have_key = false; + bool have_data = false; + bool have_file = false; uint8_t cmdp = 0; + uint8_t enc_data[8] = {0}; + size_t keylen = 0; uint8_t key[32] = {0}; uint8_t *keyptr = NULL; @@ -810,6 +817,15 @@ static int CmdHFiClassDecrypt(const char *Cmd) { switch (tolower(param_getchar(Cmd, cmdp))) { case 'h': return usage_hf_iclass_decrypt(); + case 'd': + if (param_gethex(Cmd, cmdp + 1, enc_data, 16)) { + PrintAndLogEx(ERR, "data must be 16 HEX symbols"); + errors = true; + break; + } + have_data = true; + cmdp += 2; + break; case 'f': if (param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) == 0) { PrintAndLogEx(WARNING, "no filename found after f"); @@ -821,6 +837,7 @@ static int CmdHFiClassDecrypt(const char *Cmd) { errors = true; break; } + have_file = true; cmdp += 2; break; case 'k': @@ -848,45 +865,54 @@ static int CmdHFiClassDecrypt(const char *Cmd) { memcpy(key, keyptr, sizeof(key)); } - picopass_hdr *hdr = (picopass_hdr *)decrypted; - - uint8_t mem = hdr->conf.mem_config; - uint8_t chip = hdr->conf.chip_config; - uint8_t applimit = hdr->conf.app_limit; - uint8_t kb = 2; - uint8_t app_areas = 2; - uint8_t max_blk = 31; - getMemConfig(mem, chip, &max_blk, &app_areas, &kb); - // tripledes mbedtls_des3_context ctx; mbedtls_des3_set2key_dec(&ctx, key); - uint8_t enc_dump[8] = {0}; - uint8_t empty[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - for (uint16_t blocknum = 0; blocknum < applimit; ++blocknum) { + uint8_t dec_data[8] = {0}; + + if ( have_data ) { + mbedtls_des3_crypt_ecb(&ctx, enc_data, dec_data); + PrintAndLogEx(SUCCESS, "Data: %s", sprint_hex(dec_data, sizeof(dec_data))); + } - uint8_t idx = blocknum * 8; - memcpy(enc_dump, decrypted + idx, 8); + if ( have_file ) { + picopass_hdr *hdr = (picopass_hdr *)decrypted; - // block 7 or higher, and not empty 0xFF - if (blocknum > 6 && memcmp(enc_dump, empty, 8) != 0) { - mbedtls_des3_crypt_ecb(&ctx, enc_dump, decrypted + idx); + uint8_t mem = hdr->conf.mem_config; + uint8_t chip = hdr->conf.chip_config; + uint8_t applimit = hdr->conf.app_limit; + uint8_t kb = 2; + uint8_t app_areas = 2; + uint8_t max_blk = 31; + getMemConfig(mem, chip, &max_blk, &app_areas, &kb); + + uint8_t empty[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + + for (uint16_t blocknum = 0; blocknum < applimit; ++blocknum) { + + uint8_t idx = blocknum * 8; + memcpy(enc_data, decrypted + idx, 8); + + // block 7 or higher, and not empty 0xFF + if (blocknum > 6 && memcmp(enc_data, empty, 8) != 0) { + mbedtls_des3_crypt_ecb(&ctx, enc_data, decrypted + idx); + } } + + //Use the first block (CSN) for filename + char *fptr = calloc(42, sizeof(uint8_t)); + strcat(fptr, "hf-iclass-"); + FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn)); + + saveFile(fptr, ".bin", decrypted, decryptedlen); + saveFileEML(fptr, decrypted, decryptedlen, 8); + saveFileJSON(fptr, jsfIclass, decrypted, decryptedlen); + + printIclassDumpContents(decrypted, 1, (decryptedlen / 8), decryptedlen); + free(decrypted); + free(fptr); } - - //Use the first block (CSN) for filename - char *fptr = calloc(42, sizeof(uint8_t)); - strcat(fptr, "hf-iclass-"); - FillFileNameByUID(fptr, hdr->csn, "-data-decrypted", sizeof(hdr->csn)); - - saveFile(fptr, ".bin", decrypted, decryptedlen); - saveFileEML(fptr, decrypted, decryptedlen, 8); - saveFileJSON(fptr, jsfIclass, decrypted, decryptedlen); - - printIclassDumpContents(decrypted, 1, (decryptedlen / 8), decryptedlen); - free(decrypted); - free(fptr); return PM3_SUCCESS; } From 9cf2cd7ca92ee637cd97427b8f4181a524181fc4 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 23:20:46 +0200 Subject: [PATCH 275/347] remove leading/tailing "/" from installation RELPATHs --- Makefile | 38 +++++++++++++++---------------- Makefile.defs | 14 ++++++------ Makefile.host | 6 ++--- armsrc/Makefile | 6 ++--- bootrom/Makefile | 6 ++--- client/Makefile | 12 +++++----- doc/md/Development/Maintainers.md | 4 +--- recovery/Makefile | 6 ++--- 8 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 77e038124..90ee442ca 100644 --- a/Makefile +++ b/Makefile @@ -27,24 +27,24 @@ install: all common/install common/install: $(info [@] Installing common resources to $(MYDESTDIR)$(PREFIX)...) ifneq (,$(INSTALLSCRIPTS)) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) - $(Q)$(CP) $(INSTALLSCRIPTS) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) + $(Q)$(CP) $(INSTALLSCRIPTS) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) endif ifneq (,$(INSTALLSHARES)) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) - $(Q)$(CP) $(INSTALLSHARES) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH) + $(Q)$(CP) $(INSTALLSHARES) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH) endif ifneq (,$(INSTALLDOCS)) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH) - $(Q)$(CP) $(INSTALLDOCS) $(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH) + $(Q)$(CP) $(INSTALLDOCS) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH) endif ifneq (,$(INSTALLTOOLS)) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) - $(Q)$(CP) $(foreach tool,$(INSTALLTOOLS),tools/$(tool)) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH) + $(Q)$(CP) $(foreach tool,$(INSTALLTOOLS),tools/$(tool)) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH) endif ifneq (,$(INSTALLSIMFW)) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) - $(Q)$(CP) $(foreach fw,$(INSTALLSIMFW),tools/simmodule/$(fw)) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH) + $(Q)$(CP) $(foreach fw,$(INSTALLSIMFW),tools/simmodule/$(fw)) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH) endif ifeq ($(platform),Linux) $(Q)$(MKDIR) $(DESTDIR)$(UDEV_PREFIX) @@ -56,27 +56,27 @@ uninstall: common/uninstall common/uninstall: $(info [@] Uninstalling common resources from $(MYDESTDIR)$(PREFIX)...) ifneq (,$(INSTALLSCRIPTS)) - $(Q)$(RM) $(foreach script,$(INSTALLSCRIPTS),$(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)$(notdir $(script))) + $(Q)$(RM) $(foreach script,$(INSTALLSCRIPTS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)$(PATHSEP)$(notdir $(script))) endif ifneq (,$(INSTALLSHARES)) - $(Q)$(RMDIR) $(foreach share,$(INSTALLSHARES),$(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)$(notdir $(share))) + $(Q)$(RMDIR) $(foreach share,$(INSTALLSHARES),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)$(PATHSEP)$(notdir $(share))) endif ifneq (,$(INSTALLDOCS)) - $(Q)$(RMDIR) $(foreach doc,$(INSTALLDOCS),$(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH)$(notdir $(doc))) - $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLDOCSRELPATH) + $(Q)$(RMDIR) $(foreach doc,$(INSTALLDOCS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH)$(PATHSEP)$(notdir $(doc))) + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH) endif ifneq (,$(INSTALLTOOLS)) - $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH)$(notdir $(tool))) + $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)$(PATHSEP)$(notdir $(tool))) endif - $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH) ifneq (,$(INSTALLSIMFW)) - $(Q)$(RM) $(foreach fw,$(INSTALLSIMFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) + $(Q)$(RM) $(foreach fw,$(INSTALLSIMFW),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(notdir $(fw))) endif - $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH) ifeq ($(platform),Linux) $(Q)$(RM) $(DESTDIR)$(UDEV_PREFIX)/77-pm3-usb-device-blacklist.rules endif - $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH) mfkey/%: FORCE $(info [*] MAKE $@) diff --git a/Makefile.defs b/Makefile.defs index 64e74c243..4068d7516 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -26,13 +26,13 @@ CXX = g++ LD = g++ PATHSEP=/ -PREFIX ?= /usr/local -UDEV_PREFIX ?= /etc/udev/rules.d -INSTALLBINRELPATH ?= /bin/ -INSTALLSHARERELPATH ?= /share/proxmark3/ -INSTALLFWRELPATH ?= /share/proxmark3/firmware/ -INSTALLTOOLSRELPATH ?= /share/proxmark3/tools/ -INSTALLDOCSRELPATH ?= /share/doc/proxmark3/ +PREFIX ?= /usr/local +UDEV_PREFIX ?= /etc/udev/rules.d +INSTALLBINRELPATH ?= bin +INSTALLSHARERELPATH ?= share/proxmark3 +INSTALLFWRELPATH ?= share/proxmark3/firmware +INSTALLTOOLSRELPATH ?= share/proxmark3/tools +INSTALLDOCSRELPATH ?= share/doc/proxmark3 platform = $(shell uname) DETECTED_OS=$(platform) diff --git a/Makefile.host b/Makefile.host index 8fb6fceed..bfadd82b7 100644 --- a/Makefile.host +++ b/Makefile.host @@ -37,15 +37,15 @@ clean: install: all ifneq (,$(INSTALLTOOLS)) $(info [@] Installing $(BINS) to $(DESTDIR)$(PREFIX)...) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) - $(Q)$(CP) $(INSTALLTOOLS) $(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH) + $(Q)$(CP) $(INSTALLTOOLS) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH) endif @true uninstall: ifneq (,$(INSTALLTOOLS)) $(info [@] Uninstalling $(BINS) from $(DESTDIR)$(PREFIX)...) - $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(INSTALLTOOLSRELPATH)$(notdir $(tool))) + $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)$(PATHSEP)$(notdir $(tool))) endif @true diff --git a/armsrc/Makefile b/armsrc/Makefile index bb8f17ef2..f94868b6e 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -222,12 +222,12 @@ clean: install: all $(info [@] Installing fullimage to $(DESTDIR)$(PREFIX)...) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) - $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(INSTALLFWTAG) uninstall: $(info [@] Uninstalling fullimage from $(DESTDIR)$(PREFIX)...) - $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(INSTALLFWTAG) .PHONY: all clean help install uninstall help: diff --git a/bootrom/Makefile b/bootrom/Makefile index 0d3f081d9..d666f3acd 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -60,12 +60,12 @@ clean: install: all $(info [@] Installing bootrom to $(DESTDIR)$(PREFIX)...) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) - $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH) uninstall: $(info [@] Uninstalling bootrom from $(DESTDIR)$(PREFIX)...) - $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(notdir $(fw))) + $(Q)$(RM) $(foreach fw,$(INSTALLFW),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(notdir $(fw))) .PHONY: all clean help install help: diff --git a/client/Makefile b/client/Makefile index b670965b6..96b5d1bf4 100644 --- a/client/Makefile +++ b/client/Makefile @@ -328,22 +328,22 @@ clean: install: all $(info [@] Installing client to $(DESTDIR)$(PREFIX)...) ifneq (,$(INSTALLBIN)) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) - $(Q)$(CP) $(INSTALLBIN) $(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) + $(Q)$(CP) $(INSTALLBIN) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH) endif ifneq (,$(INSTALLSHARE)) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) - $(Q)$(CP) $(INSTALLSHARE) $(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH) + $(Q)$(CP) $(INSTALLSHARE) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH) endif @true uninstall: $(info [@] Uninstalling client from $(DESTDIR)$(PREFIX)...) ifneq (,$(INSTALLBIN)) - $(Q)$(RM) $(foreach tool,$(INSTALLBIN),$(DESTDIR)$(PREFIX)$(INSTALLBINRELPATH)$(notdir $(tool))) + $(Q)$(RM) $(foreach tool,$(INSTALLBIN),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)$(PATHSEP)$(notdir $(tool))) endif ifneq (,$(INSTALLSHARE)) - $(Q)$(RMDIR) $(foreach tool,$(INSTALLSHARE),$(DESTDIR)$(PREFIX)$(INSTALLSHARERELPATH)$(notdir $(tool))) + $(Q)$(RMDIR) $(foreach tool,$(INSTALLSHARE),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)$(PATHSEP)$(notdir $(tool))) endif @true diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index bc6b66cf5..ff3525784 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -31,11 +31,9 @@ If you need to tune some more paths, see their definition in `Makefile.defs`. E.g. you might need to move the documentation elsewhere according to your distro policy: ``` -make install PREFIX=/usr INSTALLDOCSRELPATH=/share/doc/proxmark3-${version}/ +make install PREFIX=/usr INSTALLDOCSRELPATH=share/doc/proxmark3-${version} ``` -Be careful to respect the same leading/closing `/` schema else you'll mess up your paths! - It's possible to add other firmwares as well with tagged names (`FWTAG=`), e.g. here we're compiling another image for non-RDV4 devices: ``` diff --git a/recovery/Makefile b/recovery/Makefile index 5a5fda0e8..2bfd1475f 100644 --- a/recovery/Makefile +++ b/recovery/Makefile @@ -28,11 +28,11 @@ clean: install: all $(info [@] Installing recovery to $(DESTDIR)$(PREFIX)...) - $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH) - $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) + $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH) + $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(INSTALLFWTAG) uninstall: $(info [@] Uninstalling recovery from $(DESTDIR)$(PREFIX)...) - $(Q)$(RM) $(DESTDIR)$(PREFIX)$(INSTALLFWRELPATH)$(INSTALLFWTAG) + $(Q)$(RM) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(INSTALLFWTAG) .PHONY: all clean install uninstall From ffe849fb93e431039fa2a125a0b0b30a50a43d40 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Sep 2019 23:34:51 +0200 Subject: [PATCH 276/347] fixing compilation bug in iclass --- client/cmdhficlass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index bed919cc9..1580f40f6 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -78,7 +78,7 @@ static int usage_hf_iclass_decrypt(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Usage: hf iclass decrypt d f k "); PrintAndLogEx(NORMAL, " options"); - PrintAndLogEx(NORMAL, " d 16 bytes hex") + PrintAndLogEx(NORMAL, " d 16 bytes hex"); PrintAndLogEx(NORMAL, " f filename of dump"); PrintAndLogEx(NORMAL, " k 16 bytes hex"); PrintAndLogEx(NORMAL, ""); From f1eceab385f53b13f68d003234f8acb77190d5fd Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 6 Sep 2019 09:00:01 +0200 Subject: [PATCH 277/347] chg: `hf iclass` / `hf mfu` - free some 3des contexts --- client/cmdhficlass.c | 7 +++++-- client/cmdhfmfu.c | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 1580f40f6..1482db5bd 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -870,11 +870,11 @@ static int CmdHFiClassDecrypt(const char *Cmd) { mbedtls_des3_set2key_dec(&ctx, key); uint8_t dec_data[8] = {0}; - + if ( have_data ) { mbedtls_des3_crypt_ecb(&ctx, enc_data, dec_data); PrintAndLogEx(SUCCESS, "Data: %s", sprint_hex(dec_data, sizeof(dec_data))); - } + } if ( have_file ) { picopass_hdr *hdr = (picopass_hdr *)decrypted; @@ -913,6 +913,8 @@ static int CmdHFiClassDecrypt(const char *Cmd) { free(decrypted); free(fptr); } + + mbedtls_des3_free(&ctx); return PM3_SUCCESS; } @@ -923,6 +925,7 @@ static void iClassEncryptBlkData(uint8_t *blk_data, uint8_t *key) { mbedtls_des3_set2key_enc(&ctx, key); mbedtls_des3_crypt_ecb(&ctx, blk_data, encrypted); memcpy(blk_data, encrypted, 8); + mbedtls_des3_free(&ctx); } static int CmdHFiClassEncryptBlk(const char *Cmd) { diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index 23eac5504..818265569 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -2519,7 +2519,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { if (param_gethex(Cmd, 0, uid, 14)) { PrintAndLogEx(WARNING, "UID must include 14 HEX symbols"); - return 1; + return PM3_EINVARG; } // read block2. @@ -2527,7 +2527,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { SendCommandMIX(CMD_HF_MIFAREU_READBL, 2, 0, 0, NULL, 0); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(WARNING, "Command execute timeout"); - return 2; + return PM3_ETIMEOUT; } // save old block2. @@ -2544,7 +2544,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 0, 0, 0, data, sizeof(data)); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(WARNING, "Command execute timeout"); - return 3; + return PM3_ETIMEOUT; } // block 1. @@ -2556,7 +2556,7 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 1, 0, 0, data, sizeof(data)); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(WARNING, "Command execute timeout"); - return 4; + return PM3_ETIMEOUT; } // block 2. @@ -2568,9 +2568,9 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { SendCommandOLD(CMD_HF_MIFAREU_WRITEBL, 2, 0, 0, data, sizeof(data)); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(WARNING, "Command execute timeout"); - return 5; + return PM3_ETIMEOUT; } - return 0; + return PM3_SUCCESS; } static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) { @@ -2681,8 +2681,9 @@ static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) { PrintAndLogEx(NORMAL, "Mifare ABA :\t %s", sprint_hex(dmkey, sizeof(dmkey))); PrintAndLogEx(NORMAL, "Mifare Pwd :\t %s", sprint_hex(newpwd, sizeof(newpwd))); + mbedtls_des3_free(&ctx); // next. from the diversify_key method. - return 0; + return PM3_SUCCESS; } static int CmdHF14AMfUPwdGen(const char *Cmd) { @@ -2709,11 +2710,11 @@ static int CmdHF14AMfUPwdGen(const char *Cmd) { // 3: proprietary Anticollision if (select_status == 0) { PrintAndLogEx(WARNING, "iso14443a card select failed"); - return 1; + return PM3_ESOFT; } if (card.uidlen != 7) { PrintAndLogEx(WARNING, "Wrong sized UID, expected 7bytes got %d", card.uidlen); - return 1; + return PM3_ESOFT; } memcpy(uid, card.uid, sizeof(uid)); } else { @@ -2732,7 +2733,7 @@ static int CmdHF14AMfUPwdGen(const char *Cmd) { PrintAndLogEx(NORMAL, "------+----------+-----"); PrintAndLogEx(NORMAL, " Vingcard algo"); PrintAndLogEx(NORMAL, "--------------------"); - return 0; + return PM3_SUCCESS; } //------------------------------------ // Menu Stuff @@ -2757,7 +2758,7 @@ static command_t CommandTable[] = { static int CmdHelp(const char *Cmd) { (void)Cmd; // Cmd is not used so far CmdsHelp(CommandTable); - return 0; + return PM3_SUCCESS; } int CmdHFMFUltra(const char *Cmd) { From c373929c75d2749cc8f5367454e6ee1827258cca Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 6 Sep 2019 09:15:02 +0200 Subject: [PATCH 278/347] ignore renamed flasher --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5b45564b3..55640b44a 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ client/ui/ui_overlays.h hardnested_stats.txt proxmark3 +proxmark3-flasher flasher !flasher/ lua From 57dc1849dafc5fa1c045361777cc7bbbf3a64441 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 6 Sep 2019 16:52:05 +0200 Subject: [PATCH 279/347] return --- client/cmdhfmfu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index 818265569..7c81ebfd6 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -2191,7 +2191,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { // convert old format to new format, if need int res = convertOldMfuDump(&dump, &bytes_read); - if (res) { + if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, "Failed convert on load to new Ultralight/NTAG format"); free(dump); return res; From da4da03d320771dd524b3fa62ac4494ab8caab6d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 6 Sep 2019 16:52:25 +0200 Subject: [PATCH 280/347] ignore .proxmark3 folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 55640b44a..fda8c21af 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,4 @@ client/lualibs/pm3_cmd.lua # recompiled fpga_version_info.c +.proxmark3/* From c34660b74c6d80a67055ffc3b3b1bf7a0ed27bf8 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 6 Sep 2019 17:22:54 +0200 Subject: [PATCH 281/347] free some mem --- client/fileutils.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index a4521fcf8..3abdcc4f0 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -103,9 +103,9 @@ static char *newfilenamemcopy(const char *preferredName, const char *suffix) { int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen) { - if (data == NULL) return 1; + if (data == NULL) return PM3_EINVARG; char *fileName = newfilenamemcopy(preferredName, suffix); - if (fileName == NULL) return 1; + if (fileName == NULL) return PM3_EMALLOC; /* We should have a valid filename now, e.g. dumpdata-3.bin */ @@ -126,9 +126,9 @@ int saveFile(const char *preferredName, const char *suffix, const void *data, si int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize) { - if (data == NULL) return 1; + if (data == NULL) return PM3_EINVARG; char *fileName = newfilenamemcopy(preferredName, ".eml"); - if (fileName == NULL) return 1; + if (fileName == NULL) return PM3_EMALLOC; int retval = PM3_SUCCESS; int blocks = datalen / blocksize; @@ -171,9 +171,9 @@ out: int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, size_t datalen) { - if (data == NULL) return 1; + if (data == NULL) return PM3_EINVARG; char *fileName = newfilenamemcopy(preferredName, ".json"); - if (fileName == NULL) return 1; + if (fileName == NULL) return PM3_EMALLOC; int retval = PM3_SUCCESS; @@ -425,12 +425,16 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s if (fsize <= 0) { PrintAndLogEx(FAILED, "error, when getting filesize"); + free(path); + fclose(f); return PM3_EFILE; } *pdata = calloc(fsize, sizeof(uint8_t)); if (!pdata) { PrintAndLogEx(FAILED, "error, cannot allocate memory"); + free(path); + fclose(f); return PM3_EMALLOC; } @@ -440,20 +444,22 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s if (bytes_read != fsize) { PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); + free(path); return PM3_EFILE; } *datalen = bytes_read; PrintAndLogEx(SUCCESS, "loaded %d bytes from binary file " _YELLOW_("%s"), bytes_read, preferredName); + free(path); return retval; } int loadFileEML(const char *preferredName, void *data, size_t *datalen) { - if (data == NULL) return 1; + if (data == NULL) return PM3_EINVARG; char *fileName = filenamemcopy(preferredName, ".eml"); - if (fileName == NULL) return 1; + if (fileName == NULL) return PM3_EMALLOC; size_t counter = 0; int retval = PM3_SUCCESS, hexlen = 0; @@ -505,9 +511,9 @@ out: int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen) { - if (data == NULL) return 1; + if (data == NULL) return PM3_EINVARG; char *fileName = filenamemcopy(preferredName, ".json"); - if (fileName == NULL) return 1; + if (fileName == NULL) return PM3_EMALLOC; *datalen = 0; json_t *root; @@ -632,7 +638,7 @@ out: int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, uint8_t keylen, uint16_t *keycnt) { - if (data == NULL) return PM3_ESOFT; + if (data == NULL) return PM3_EINVARG; char *path; if (searchFile(&path, DICTIONARIES_SUBDIR, preferredName, ".dic", false) != PM3_SUCCESS) return PM3_EFILE; From 8228b66cb6d6a8e1c43df436c705f6fac897e467 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 7 Sep 2019 10:32:16 +0200 Subject: [PATCH 282/347] chg: \n - param not obsessed with two hexsamples. \n textual --- client/cmdhficlass.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 1482db5bd..a096137ee 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1350,10 +1350,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { case 'h': return usage_hf_iclass_writeblock(); case 'b': - if (param_gethex(Cmd, cmdp + 1, &blockno, 2)) { - PrintAndLogEx(WARNING, "Block No must include 2 HEX symbols\n"); - errors = true; - } + blockno = param_get8ex(Cmd, cmdp + 1, 06, 16); cmdp += 2; break; case 'c': @@ -1616,10 +1613,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { case 'h': return usage_hf_iclass_readblock(); case 'b': - if (param_gethex(Cmd, cmdp + 1, &blockno, 2)) { - PrintAndLogEx(WARNING, "Block No must include 2 HEX symbols\n"); - errors = true; - } + blockno = param_get8ex(Cmd, cmdp + 1, 06, 16); cmdp += 2; break; case 'c': @@ -2610,25 +2604,25 @@ static int CmdHFiClassPermuteKey(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"calcnewkey", CmdHFiClassCalcNewKey, AlwaysAvailable, "[options..] Calc Diversified keys (blocks 3 & 4) to write new keys"}, - {"chk", CmdHFiClassCheckKeys, AlwaysAvailable, " Check keys"}, - {"clone", CmdHFiClassCloneTag, IfPm3Iclass, "[options..] Authenticate and Clone from iClass bin file"}, - {"decrypt", CmdHFiClassDecrypt, AlwaysAvailable, "[f ] Decrypt tagdump" }, + {"calcnewkey", CmdHFiClassCalcNewKey, AlwaysAvailable, "[options..] Calc diversified keys (blocks 3 & 4) to write new keys"}, + {"chk", CmdHFiClassCheckKeys, AlwaysAvailable, "[options..] Check keys"}, + {"clone", CmdHFiClassCloneTag, IfPm3Iclass, "[options..] Clone (restore from tagdump file)"}, + {"decrypt", CmdHFiClassDecrypt, AlwaysAvailable, "[options..] Decrypt given block data or tagdump file" }, {"dump", CmdHFiClassReader_Dump, IfPm3Iclass, "[options..] Authenticate and Dump iClass tag's AA1"}, {"eload", CmdHFiClassELoad, IfPm3Iclass, "[f ] (experimental) Load data into iClass emulator memory"}, - {"encryptblk", CmdHFiClassEncryptBlk, AlwaysAvailable, " Encrypt given block data"}, - {"list", CmdHFiClassList, AlwaysAvailable, " List iClass history"}, + {"encrypt", CmdHFiClassEncryptBlk, AlwaysAvailable, "[options..] Encrypt given block data"}, + {"list", CmdHFiClassList, AlwaysAvailable, " List iClass history"}, {"loclass", CmdHFiClass_loclass, AlwaysAvailable, "[options..] Use loclass to perform bruteforce of reader attack dump"}, {"lookup", CmdHFiClassLookUp, AlwaysAvailable, "[options..] Uses authentication trace to check for key in dictionary file"}, {"managekeys", CmdHFiClassManageKeys, AlwaysAvailable, "[options..] Manage the keys to use with iClass"}, {"permutekey", CmdHFiClassPermuteKey, IfPm3Iclass, " Permute function from 'heart of darkness' paper"}, - {"readblk", CmdHFiClass_ReadBlock, IfPm3Iclass, "[options..] Authenticate and Read iClass block"}, + {"readblk", CmdHFiClass_ReadBlock, IfPm3Iclass, "[options..] Read iClass block"}, {"reader", CmdHFiClassReader, IfPm3Iclass, " Act like an iClass reader"}, {"readtagfile", CmdHFiClassReadTagFile, AlwaysAvailable, "[options..] Display Content from tagfile"}, {"replay", CmdHFiClassReader_Replay, IfPm3Iclass, " Read an iClass tag via Replay Attack"}, {"sim", CmdHFiClassSim, IfPm3Iclass, "[options..] Simulate iClass tag"}, {"sniff", CmdHFiClassSniff, IfPm3Iclass, " Eavesdrop iClass communication"}, - {"writeblk", CmdHFiClass_WriteBlock, IfPm3Iclass, "[options..] Authenticate and Write iClass block"}, + {"writeblk", CmdHFiClass_WriteBlock, IfPm3Iclass, "[options..] Write iClass block"}, {NULL, NULL, NULL, NULL} }; From 710c49f7632f4d9fea09e16c515108d624f522a9 Mon Sep 17 00:00:00 2001 From: sh7d <47714037+sh7d@users.noreply.github.com> Date: Sat, 7 Sep 2019 11:36:41 +0200 Subject: [PATCH 283/347] autopwn: fix card detection --- client/cmdhfmf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index be05d85d2..b74a5af3a 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1660,7 +1660,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Settings bool slow = false; bool legacy_mfchk = false; - bool prng_type = false; + int prng_type = 0; bool verbose = false; bool has_filename = false; bool errors = false; @@ -1776,8 +1776,12 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } } - // card prng type (weak=true / hard=false) + // card prng type (weak=1 / hard=0 / select/card comm error fail = -vaule) prng_type = detect_classic_prng(); + if (prng_type < 0){ + PrintAndLogEx(FAILED, "\nNo tag detected or other tag communication error"); + goto noValidKeyFound; + } // print parameters if (verbose) { From 9ce820768c7778db6620511bdf51f32fb7f09f66 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 7 Sep 2019 12:07:09 +0200 Subject: [PATCH 284/347] missing free --- client/fileutils.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 3abdcc4f0..9a5907882 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -415,8 +415,10 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s FILE *f = fopen(path, "rb"); if (!f) { PrintAndLogEx(WARNING, "file not found or locked. '" _YELLOW_("%s")"'", path); + free(path); return PM3_EFILE; } + free(path); // get filesize in order to malloc memory fseek(f, 0, SEEK_END); @@ -425,7 +427,6 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s if (fsize <= 0) { PrintAndLogEx(FAILED, "error, when getting filesize"); - free(path); fclose(f); return PM3_EFILE; } @@ -433,7 +434,6 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s *pdata = calloc(fsize, sizeof(uint8_t)); if (!pdata) { PrintAndLogEx(FAILED, "error, cannot allocate memory"); - free(path); fclose(f); return PM3_EMALLOC; } @@ -444,14 +444,12 @@ int loadFile_safe(const char *preferredName, const char *suffix, void **pdata, s if (bytes_read != fsize) { PrintAndLogEx(FAILED, "error, bytes read mismatch file size"); - free(path); return PM3_EFILE; } *datalen = bytes_read; PrintAndLogEx(SUCCESS, "loaded %d bytes from binary file " _YELLOW_("%s"), bytes_read, preferredName); - free(path); return retval; } From 93e323d890c1912c756c9b4d3b4484655832c7e8 Mon Sep 17 00:00:00 2001 From: sh7d <47714037+sh7d@users.noreply.github.com> Date: Sat, 7 Sep 2019 19:41:48 +0200 Subject: [PATCH 285/347] Review requested changes --- client/cmdhfmf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index b74a5af3a..90501943b 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1660,7 +1660,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Settings bool slow = false; bool legacy_mfchk = false; - int prng_type = 0; + int prng_type = PM3_EUNDEF; bool verbose = false; bool has_filename = false; bool errors = false; @@ -1776,11 +1776,12 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { } } - // card prng type (weak=1 / hard=0 / select/card comm error fail = -vaule) + // card prng type (weak=1 / hard=0 / select/card comm error = negative value) prng_type = detect_classic_prng(); if (prng_type < 0){ PrintAndLogEx(FAILED, "\nNo tag detected or other tag communication error"); - goto noValidKeyFound; + free(e_sector); + return prng_type; } // print parameters From 28534c10ade76c41e6ff8245abdcc47258d44384 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 7 Sep 2019 20:45:12 +0200 Subject: [PATCH 286/347] hf mf autopwn not available offline --- client/cmdhfmf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 90501943b..30c7c2c32 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -4394,7 +4394,7 @@ static command_t CommandTable[] = { {"darkside", CmdHF14AMfDarkside, IfPm3Iso14443a, "Darkside attack. read parity error messages."}, {"nested", CmdHF14AMfNested, IfPm3Iso14443a, "Nested attack. Test nested authentication"}, {"hardnested", CmdHF14AMfNestedHard, AlwaysAvailable, "Nested attack for hardened Mifare cards"}, - {"autopwn", CmdHF14AMfAutoPWN, AlwaysAvailable, "Automatic attack tool, to extrackt the nfc keys (with dicrionaries, nested and hardnested attacks)"}, + {"autopwn", CmdHF14AMfAutoPWN, IfPm3Iso14443a, "Automatic attack tool, to extrackt the nfc keys (with dicrionaries, nested and hardnested attacks)"}, {"keybrute", CmdHF14AMfKeyBrute, IfPm3Iso14443a, "J_Run's 2nd phase of multiple sector nested authentication key recovery"}, {"nack", CmdHf14AMfNack, IfPm3Iso14443a, "Test for Mifare NACK bug"}, {"chk", CmdHF14AMfChk, IfPm3Iso14443a, "Check keys"}, @@ -4410,7 +4410,7 @@ static command_t CommandTable[] = { {"auth4", CmdHF14AMfAuth4, IfPm3Iso14443a, "ISO14443-4 AES authentication"}, // {"sniff", CmdHF14AMfSniff, 0, "Sniff card-reader communication"}, {"-----------", CmdHelp, IfPm3Iso14443a, ""}, - {"sim", CmdHF14AMfSim, IfPm3Iso14443a, "Simulate MIFARE card"}, + {"sim", CmdHF14AMfSim, IfPm3Iso14443a, "Simulate MIFARE card"}, {"eclr", CmdHF14AMfEClear, IfPm3Iso14443a, "Clear simulator memory"}, {"eget", CmdHF14AMfEGet, IfPm3Iso14443a, "Get simulator memory block"}, {"eset", CmdHF14AMfESet, IfPm3Iso14443a, "Set simulator memory block"}, From fbe86a9070c5c2c86eb6a316fc7eca7c01912ddc Mon Sep 17 00:00:00 2001 From: Iceman Date: Sun, 8 Sep 2019 12:29:10 +0200 Subject: [PATCH 287/347] Update cmdhfmf.c Textual, and HF MF KEYBRUTE is considered obselete since improved hardnested. Will let it still be in code for learning purposes. --- client/cmdhfmf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 30c7c2c32..7335a41af 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -4390,13 +4390,13 @@ static int CmdHF14AMfList(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"list", CmdHF14AMfList, AlwaysAvailable, "List Mifare history"}, - {"darkside", CmdHF14AMfDarkside, IfPm3Iso14443a, "Darkside attack. read parity error messages."}, - {"nested", CmdHF14AMfNested, IfPm3Iso14443a, "Nested attack. Test nested authentication"}, - {"hardnested", CmdHF14AMfNestedHard, AlwaysAvailable, "Nested attack for hardened Mifare cards"}, - {"autopwn", CmdHF14AMfAutoPWN, IfPm3Iso14443a, "Automatic attack tool, to extrackt the nfc keys (with dicrionaries, nested and hardnested attacks)"}, - {"keybrute", CmdHF14AMfKeyBrute, IfPm3Iso14443a, "J_Run's 2nd phase of multiple sector nested authentication key recovery"}, - {"nack", CmdHf14AMfNack, IfPm3Iso14443a, "Test for Mifare NACK bug"}, + {"list", CmdHF14AMfList, AlwaysAvailable, "List MIFARE history"}, + {"darkside", CmdHF14AMfDarkside, IfPm3Iso14443a, "Darkside attack"}, + {"nested", CmdHF14AMfNested, IfPm3Iso14443a, "Nested attack"}, + {"hardnested", CmdHF14AMfNestedHard, AlwaysAvailable, "Nested attack for hardened MIFARE Classic cards"}, + {"autopwn", CmdHF14AMfAutoPWN, IfPm3Iso14443a, "Automatic key recovery tool for MIFARE Classic"}, +// {"keybrute", CmdHF14AMfKeyBrute, IfPm3Iso14443a, "J_Run's 2nd phase of multiple sector nested authentication key recovery"}, + {"nack", CmdHf14AMfNack, IfPm3Iso14443a, "Test for MIFARE NACK bug"}, {"chk", CmdHF14AMfChk, IfPm3Iso14443a, "Check keys"}, {"fchk", CmdHF14AMfChk_fast, IfPm3Iso14443a, "Check keys fast, targets all keys on card"}, {"decrypt", CmdHf14AMfDecryptBytes, AlwaysAvailable, "[nt] [ar_enc] [at_enc] [data] - to decrypt sniff or trace"}, @@ -4429,7 +4429,7 @@ static command_t CommandTable[] = { {"mad", CmdHF14AMfMAD, IfPm3Iso14443a, "Checks and prints MAD"}, {"ndef", CmdHFMFNDEF, IfPm3Iso14443a, "Prints NDEF records from card"}, - {"ice", CmdHF14AMfice, IfPm3Iso14443a, "collect Mifare Classic nonces to file"}, + {"ice", CmdHF14AMfice, IfPm3Iso14443a, "collect MIFARE Classic nonces to file"}, {NULL, NULL, NULL, NULL} }; From a037766e26ecc405ed6c76fb00241c4c9df1cfdc Mon Sep 17 00:00:00 2001 From: RFID Research Group Date: Sun, 8 Sep 2019 12:57:25 +0200 Subject: [PATCH 288/347] Update cmdhfmf.c chg: hf mf brute - commented out. --- client/cmdhfmf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 7335a41af..baa999128 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -244,6 +244,7 @@ static int usage_hf14_chk_fast(void) { PrintAndLogEx(NORMAL, " hf mf fchk 1 m -- target 1K, use dictionary from flashmemory"); return 0; } +/* static int usage_hf14_keybrute(void) { PrintAndLogEx(NORMAL, "J_Run's 2nd phase of multiple sector nested authentication key recovery"); PrintAndLogEx(NORMAL, "You have a known 4 last bytes of a key recovered with mf_nonce_brute tool."); @@ -261,6 +262,7 @@ static int usage_hf14_keybrute(void) { PrintAndLogEx(NORMAL, " hf mf keybrute 1 A 000011223344"); return 0; } +*/ static int usage_hf14_restore(void) { PrintAndLogEx(NORMAL, "Usage: hf mf restore [card memory] u k f "); PrintAndLogEx(NORMAL, "Options:"); @@ -3250,6 +3252,8 @@ static int CmdHF14AMfSniff(const char *Cmd) { return PM3_SUCCESS; } */ + +/* static int CmdHF14AMfKeyBrute(const char *Cmd) { uint8_t blockNo = 0, keytype = 0; @@ -3280,6 +3284,7 @@ static int CmdHF14AMfKeyBrute(const char *Cmd) { PrintAndLogEx(SUCCESS, "\ntime in keybrute: %.0f seconds\n", (float)t1 / 1000.0); return PM3_SUCCESS; } +*/ void printKeyTable(uint8_t sectorscnt, sector_t *e_sector) { char strA[12 + 1] = {0}; @@ -3308,6 +3313,7 @@ void printKeyTable(uint8_t sectorscnt, sector_t *e_sector) { PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|"); } + // EMULATOR COMMANDS static int CmdHF14AMfEGet(const char *Cmd) { char c = tolower(param_getchar(Cmd, 0)); From 305c54f3cfcd9acf9e394cdd68fbc60728a59dc1 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 8 Sep 2019 17:37:14 +0200 Subject: [PATCH 289/347] chg: 'hf iclass rdbl' - now retries 10 ten times and uses NG --- armsrc/appmain.c | 6 ++- armsrc/iclass.c | 19 +++++--- client/cmdhficlass.c | 100 +++++++++++++++++++++++++++++-------------- 3 files changed, 85 insertions(+), 40 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index c789f6aac..e673c078a 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1237,7 +1237,11 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ICLASS_READBL: { - iClass_ReadBlk(packet->oldarg[0]); + struct p { + uint8_t blockno; + } PACKED; + struct p *payload = (struct p *)packet->data.asBytes; + iClass_ReadBlk( payload->blockno ); break; } case CMD_HF_ICLASS_AUTH: { //check diff --git a/armsrc/iclass.c b/armsrc/iclass.c index b63c696d6..940d0157a 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -1720,7 +1720,7 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) { static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int *wait) { int c = 0; - volatile uint32_t b; +// volatile uint32_t b; bool firstpart = true; uint8_t sendbyte; @@ -1758,10 +1758,12 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int } // Prevent rx holding register from overflowing + /* if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { b = AT91C_BASE_SSC->SSC_RHR; (void)b; } + */ } time_rdr = GetCountSspClk(); @@ -1949,12 +1951,11 @@ void setupIclassReader() { LED_A_ON(); } -bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *resp, uint8_t expected_size, uint8_t retries) { +bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *resp, uint8_t expected_size, int8_t retries) { while (retries-- > 0) { ReaderTransmitIClass(command, cmdsize); - //iceman - if received size is bigger than expected, we smash the stack here // since its called with fixed sized arrays @@ -1967,7 +1968,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re // 0xBB is the internal debug separator byte.. if (expected_size != got_n || (resp[0] == 0xBB || resp[7] == 0xBB || resp[2] == 0xBB)) { //try again - SpinDelayUs(400); + SpinDelayUs(360); continue; } @@ -2456,10 +2457,14 @@ bool iClass_ReadBlock(uint8_t blockno, uint8_t *data, uint8_t len) { // turn off afterwards // readblock 8 + 2. only want 8. void iClass_ReadBlk(uint8_t blockno) { - uint8_t data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - bool isOK = iClass_ReadBlock(blockno, data, sizeof(data)); - reply_mix(CMD_ACK, isOK, 0, 0, data, sizeof(data)); + struct p { + bool isOK; + uint8_t blockdata[8]; + } PACKED result; + + result.isOK = iClass_ReadBlock(blockno, result.blockdata, sizeof(result.blockdata)); switch_off(); + reply_ng(CMD_HF_ICLASS_READBL, PM3_SUCCESS, (uint8_t *)&result, sizeof(result)); } // turn off afterwards diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index a096137ee..2f8d3b56d 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -32,6 +32,7 @@ #define NUM_CSNS 9 #define ICLASS_KEYS_MAX 8 +#define ICLASS_AUTH_RETRY 10 static int CmdHelp(const char *Cmd); @@ -662,6 +663,10 @@ static int CmdHFiClassSim(const char *Cmd) { return PM3_SUCCESS; } +static int CmdHFiClassInfo(const char *Cmd) { + return PM3_SUCCESS; +} + static int CmdHFiClassReader(const char *Cmd) { char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_hf_iclass_reader(); @@ -1563,36 +1568,62 @@ static int CmdHFiClassCloneTag(const char *Cmd) { } static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool verbose, bool auth) { - // block 0,1 should always be able to read, and block 5 on some cards. - if (auth || blockno >= 2) { - uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; - uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (!select_and_auth(KEY, MAC, div_key, (keyType == 0x18), elite, rawkey, verbose)) - return 0; + + int numberAuthRetries = ICLASS_AUTH_RETRY; + // return data. + struct p { + bool isOK; + uint8_t blockdata[8]; + } PACKED; + + struct p *result = NULL; + + do { + // block 0,1 should always be able to read, and block 5 on some cards. + if (auth || blockno >= 2) { + uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; + uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + if (!select_and_auth(KEY, MAC, div_key, (keyType == 0x18), elite, rawkey, verbose)) { + numberAuthRetries--; + continue; + } + } else { + uint8_t CSN[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + if (!select_only(CSN, CCNR, (keyType == 0x18), verbose)) { + numberAuthRetries--; + continue; + } + } + + PacketResponseNG resp; + clearCommandBuffer(); + uint8_t payload[] = { blockno }; + SendCommandNG(CMD_HF_ICLASS_READBL, payload, sizeof(payload)); + + if (WaitForResponseTimeout(CMD_HF_ICLASS_READBL, &resp, 2000) == 0) { + PrintAndLogEx(WARNING, "Command execute timeout"); + return PM3_ETIMEOUT; + } + + if ( resp.status != PM3_SUCCESS ) { + PrintAndLogEx(ERR, "failed to communicate with card"); + return PM3_EWRONGANSVER; + } + + result = (struct p*)resp.data.asBytes; + if (result->isOK) + break; + + } while (numberAuthRetries); + + if ( numberAuthRetries > 0 ) { + PrintAndLogEx(SUCCESS, "block %02X: %s\n", blockno, sprint_hex(result->blockdata, sizeof(result->blockdata))); } else { - uint8_t CSN[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (!select_only(CSN, CCNR, (keyType == 0x18), verbose)) - return 0; + PrintAndLogEx(ERR,"failed to authenticate and read block"); + return PM3_ESOFT; } - - PacketResponseNG resp; - clearCommandBuffer(); - SendCommandMIX(CMD_HF_ICLASS_READBL, blockno, 0, 0, NULL, 0); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) { - PrintAndLogEx(WARNING, "Command execute timeout"); - return 0; - } - - uint8_t isOK = resp.oldarg[0] & 0xff; - if (!isOK) { - PrintAndLogEx(WARNING, "read block failed"); - return 0; - } - //data read is stored in: resp.data.asBytes[0-15] - PrintAndLogEx(NORMAL, "block %02X: %s\n", blockno, sprint_hex(resp.data.asBytes, 8)); - // should decrypt it if file is accessable. - return 1; + return PM3_SUCCESS; } static int CmdHFiClass_ReadBlock(const char *Cmd) { @@ -1613,14 +1644,16 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { case 'h': return usage_hf_iclass_readblock(); case 'b': - blockno = param_get8ex(Cmd, cmdp + 1, 06, 16); + blockno = param_get8ex(Cmd, cmdp + 1, 7, 16); cmdp += 2; break; case 'c': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("CREDIT")); keyType = 0x18; cmdp++; break; case 'e': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("elite algo")); elite = true; cmdp++; break; @@ -1632,6 +1665,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { } else if (dataLen == 1) { keyNbr = param_get8(Cmd, cmdp + 1); if (keyNbr < ICLASS_KEYS_MAX) { + PrintAndLogEx(SUCCESS, "Using key[%d] %s", keyNbr, sprint_hex(iClass_Key_Table[keyNbr], 8 )); memcpy(KEY, iClass_Key_Table[keyNbr], 8); } else { PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n"); @@ -1644,6 +1678,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { cmdp += 2; break; case 'r': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("raw mode")); rawkey = true; cmdp++; break; @@ -2127,7 +2162,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { // Get CSN / UID and CCNR PrintAndLogEx(SUCCESS, "Reading tag CSN"); - for (uint8_t i = 0; i < 10 && !got_csn; i++) { + for (uint8_t i = 0; i < ICLASS_AUTH_RETRY && !got_csn; i++) { got_csn = select_only(CSN, CCNR, false, false); if (got_csn == false) PrintAndLogEx(WARNING, "one more try\n"); @@ -2611,18 +2646,19 @@ static command_t CommandTable[] = { {"dump", CmdHFiClassReader_Dump, IfPm3Iclass, "[options..] Authenticate and Dump iClass tag's AA1"}, {"eload", CmdHFiClassELoad, IfPm3Iclass, "[f ] (experimental) Load data into iClass emulator memory"}, {"encrypt", CmdHFiClassEncryptBlk, AlwaysAvailable, "[options..] Encrypt given block data"}, + {"info", CmdHFiClassInfo, AlwaysAvailable, " Tag information"}, {"list", CmdHFiClassList, AlwaysAvailable, " List iClass history"}, {"loclass", CmdHFiClass_loclass, AlwaysAvailable, "[options..] Use loclass to perform bruteforce of reader attack dump"}, {"lookup", CmdHFiClassLookUp, AlwaysAvailable, "[options..] Uses authentication trace to check for key in dictionary file"}, {"managekeys", CmdHFiClassManageKeys, AlwaysAvailable, "[options..] Manage the keys to use with iClass"}, {"permutekey", CmdHFiClassPermuteKey, IfPm3Iclass, " Permute function from 'heart of darkness' paper"}, - {"readblk", CmdHFiClass_ReadBlock, IfPm3Iclass, "[options..] Read iClass block"}, + {"rdbl", CmdHFiClass_ReadBlock, IfPm3Iclass, "[options..] Read iClass block"}, {"reader", CmdHFiClassReader, IfPm3Iclass, " Act like an iClass reader"}, {"readtagfile", CmdHFiClassReadTagFile, AlwaysAvailable, "[options..] Display Content from tagfile"}, {"replay", CmdHFiClassReader_Replay, IfPm3Iclass, " Read an iClass tag via Replay Attack"}, {"sim", CmdHFiClassSim, IfPm3Iclass, "[options..] Simulate iClass tag"}, {"sniff", CmdHFiClassSniff, IfPm3Iclass, " Eavesdrop iClass communication"}, - {"writeblk", CmdHFiClass_WriteBlock, IfPm3Iclass, "[options..] Write iClass block"}, + {"wrbl", CmdHFiClass_WriteBlock, IfPm3Iclass, "[options..] Write iClass block"}, {NULL, NULL, NULL, NULL} }; From d8217a13d9ab9dc14428b8f4ede48ebbc4e6e70f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 8 Sep 2019 21:21:30 +0200 Subject: [PATCH 290/347] chg: 'hf iclass rdbl' 'hf iclass wrbl' - both commands now tries tens times. Both honor verbose param, both has gotten some love with regards to timing on device side, and they also turn off the field more consistent. --- armsrc/appmain.c | 18 +++++- armsrc/iclass.c | 61 ++++++++------------ client/cmdhficlass.c | 131 +++++++++++++++++++++++++++++++------------ 3 files changed, 133 insertions(+), 77 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index e673c078a..cb5dbe8a2 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1229,22 +1229,36 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ICLASS_WRITEBL: { - iClass_WriteBlock(packet->oldarg[0], packet->data.asBytes); + struct p { + uint8_t blockno; + uint8_t data[12]; + } PACKED; + struct p *payload = (struct p *)packet->data.asBytes; + iClass_WriteBlock(payload->blockno, payload->data); break; } + // iceman2019, unused? case CMD_HF_ICLASS_READCHECK: { // auth step 1 iClass_ReadCheck(packet->oldarg[0], packet->oldarg[1]); break; } case CMD_HF_ICLASS_READBL: { +/* struct p { uint8_t blockno; } PACKED; struct p *payload = (struct p *)packet->data.asBytes; - iClass_ReadBlk( payload->blockno ); + */ + iClass_ReadBlk( packet->data.asBytes[0] ); break; } case CMD_HF_ICLASS_AUTH: { //check +/* + struct p { + uint8_t mac[4]; + } PACKED; + struct p *payload = (struct p *)packet->data.asBytes; +*/ iClass_Authentication(packet->data.asBytes); break; } diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 940d0157a..fa90f0881 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -56,10 +56,8 @@ #include "ticks.h" static int g_wait = 300; -static int timeout = 2900; +static int timeout = 5000; static uint32_t time_rdr = 0; -static uint32_t time_delta = 0; -static uint32_t time_delta_wait = 0; static uint32_t time_response = 0; static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay); @@ -1854,12 +1852,9 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, // only, since we are receiving, not transmitting). FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN); - time_delta = GetCountSspClk() - time_rdr; - SpinDelayUs(g_wait); //310 Tout= 330us (iso15603-2) (330/21.3) take consideration for clock increments. - time_delta_wait = GetCountSspClk() - time_rdr - time_delta; - uint32_t foo = GetCountSspClk(); + // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; (void)b; @@ -1877,21 +1872,15 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, } // keep tx buffer in a defined state anyway. - /* - if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { - AT91C_BASE_SSC->SSC_THR = 0x00; - } - */ + if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { + AT91C_BASE_SSC->SSC_THR = 0x00; + } + // Wait for byte be become available in rx holding register if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { - if (GetCountSspClk() - foo > timeout) return false; -// if (c >= timeout) return false; - c++; - b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; - skip = !skip; if (skip) continue; @@ -1902,6 +1891,8 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, time_response = GetCountSspClk() - foo; return true; } + + if (GetCountSspClk() - foo > timeout) return false; } } @@ -1959,12 +1950,15 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re //iceman - if received size is bigger than expected, we smash the stack here // since its called with fixed sized arrays - // update/write commadn takes 4ms to 15ms before responding + // update/write command takes 4ms to 15ms before responding + int old_wait = g_wait; if (command[0] == ICLASS_CMD_UPDATE) - g_wait = 15000; + g_wait = 3900; uint8_t got_n = ReaderReceiveIClass(resp); + g_wait = old_wait; + // 0xBB is the internal debug separator byte.. if (expected_size != got_n || (resp[0] == 0xBB || resp[7] == 0xBB || resp[2] == 0xBB)) { //try again @@ -2337,8 +2331,8 @@ void iClass_Authentication(uint8_t *mac) { //memcpy(check+5, mac, 4); // 6 retries - bool isOK = sendCmdGetResponseWithRetries(check, sizeof(check), resp, 4, 6); - reply_mix(CMD_ACK, isOK, 0, 0, 0, 0); + uint8_t isOK = sendCmdGetResponseWithRetries(check, sizeof(check), resp, 4, 6); + reply_ng(CMD_HF_ICLASS_AUTH, PM3_SUCCESS, (uint8_t*)&isOK ,sizeof(uint8_t)); } typedef struct iclass_premac { @@ -2397,6 +2391,8 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { }; // since handshakeIclassTag_ext call sends s readcheck, we start with sending first response. + checked = 0; + // Keychunk loop for (i = 0; i < keyCount; i++) { @@ -2496,39 +2492,26 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks) { } memcpy(dataout + (blkCnt * 8), blockdata, 8); } + + switch_off(); //return pointer to dump memory in arg3 reply_mix(CMD_ACK, isOK, blkCnt, BigBuf_max_traceLen(), 0, 0); - switch_off(); BigBuf_free(); } bool iClass_WriteBlock_ext(uint8_t blockno, uint8_t *data) { - uint8_t resp[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t write[] = { ICLASS_CMD_UPDATE, blockno, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; memcpy(write + 2, data, 12); // data + mac AddCrc(write + 1, 13); - - bool isOK = sendCmdGetResponseWithRetries(write, sizeof(write), resp, sizeof(resp), 5); - if (isOK) { //if reader responded correctly - - //if response is not equal to write values - if (memcmp(write + 2, resp, 8)) { - - //if not programming key areas (note key blocks don't get programmed with actual key data it is xor data) - if (blockno != 3 && blockno != 4) { - isOK = sendCmdGetResponseWithRetries(write, sizeof(write), resp, sizeof(resp), 5); - } - } - } - return isOK; + return sendCmdGetResponseWithRetries(write, sizeof(write), resp, sizeof(resp), 5); } // turn off afterwards void iClass_WriteBlock(uint8_t blockno, uint8_t *data) { - bool isOK = iClass_WriteBlock_ext(blockno, data); - reply_mix(CMD_ACK, isOK, 0, 0, 0, 0); + uint8_t isOK = iClass_WriteBlock_ext(blockno, data); switch_off(); + reply_ng(CMD_HF_ICLASS_WRITEBL, PM3_SUCCESS, (uint8_t*)&isOK, sizeof(uint8_t)); } // turn off afterwards diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 2f8d3b56d..5ac3a8925 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1000,7 +1000,7 @@ static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool v clearCommandBuffer(); SendCommandMIX(CMD_HF_ICLASS_READER, flags, 0, 0, NULL, 0); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) { + if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { PrintAndLogEx(WARNING, "command execute timeout"); return false; } @@ -1019,7 +1019,9 @@ static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool v } if (isOK <= 1) { - PrintAndLogEx(FAILED, "failed to obtain CC! Tag-select is aborting... (%d)", isOK); + if ( verbose ) + PrintAndLogEx(FAILED, "failed to obtain CC! Tag-select is aborting... (%d)", isOK); + return false; } return true; @@ -1042,18 +1044,27 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u if (verbose) PrintAndLogEx(SUCCESS, "authing with %s: %s", rawkey ? "raw key" : "diversified key", sprint_hex(div_key, 8)); doMAC(CCNR, div_key, MAC); + PacketResponseNG resp; clearCommandBuffer(); - SendCommandOLD(CMD_HF_ICLASS_AUTH, 0, 0, 0, MAC, 4); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 4000)) { - if (verbose) PrintAndLogEx(FAILED, "auth command execute timeout"); + + SendCommandNG(CMD_HF_ICLASS_AUTH, MAC, 4); + if (WaitForResponseTimeout(CMD_HF_ICLASS_AUTH, &resp, 2000) == 0) { + if (verbose) PrintAndLogEx(WARNING, "Command execute timeout"); return false; } - uint8_t isOK = resp.oldarg[0] & 0xFF; - if (!isOK) { + + if ( resp.status != PM3_SUCCESS ) { + if (verbose) PrintAndLogEx(ERR, "failed to communicate with card"); + return false; + } + + uint8_t isOK = resp.data.asBytes[0]; + if (isOK == 0) { if (verbose) PrintAndLogEx(FAILED, "authentication error"); return false; } + return true; } @@ -1311,30 +1322,60 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { } static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool rawkey, bool verbose) { - uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; - uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose)) - return 0; - PacketResponseNG resp; + int numberAuthRetries = ICLASS_AUTH_RETRY; + do { + + uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; + uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose)) { + numberAuthRetries--; + DropField(); + continue; + } - Calc_wb_mac(blockno, bldata, div_key, MAC); - uint8_t data[12]; - memcpy(data, bldata, 8); - memcpy(data + 8, MAC, 4); + Calc_wb_mac(blockno, bldata, div_key, MAC); - clearCommandBuffer(); - SendCommandOLD(CMD_HF_ICLASS_WRITEBL, blockno, 0, 0, data, sizeof(data)); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) { - if (verbose) PrintAndLogEx(WARNING, "Write Command execute timeout"); - return 0; + struct p { + uint8_t blockno; + uint8_t data[12]; + } PACKED payload; + payload.blockno = blockno; + + memcpy(payload.data, bldata, 8); + memcpy(payload.data + 8, MAC, 4); + + clearCommandBuffer(); + SendCommandNG(CMD_HF_ICLASS_WRITEBL, (uint8_t*)&payload, sizeof(payload)); + PacketResponseNG resp; + + if (WaitForResponseTimeout(CMD_HF_ICLASS_WRITEBL, &resp, 4000) == 0) { + if (verbose) PrintAndLogEx(WARNING, "Command execute timeout"); + DropField(); + return PM3_ETIMEOUT; + } + + if ( resp.status != PM3_SUCCESS ) { + if (verbose) PrintAndLogEx(ERR, "failed to communicate with card"); + DropField(); + return PM3_EWRONGANSVER; + } + + if (resp.data.asBytes[0] == 1) + break; + + } while (numberAuthRetries); + + DropField(); + + if ( numberAuthRetries > 0 ) { + PrintAndLogEx(SUCCESS, "Write block %02X successful\n", blockno); + } else { + PrintAndLogEx(ERR,"failed to authenticate and write block"); + return PM3_ESOFT; } - uint8_t isOK = resp.oldarg[0] & 0xff; - if (isOK) - PrintAndLogEx(SUCCESS, "Write block successful"); - else - PrintAndLogEx(WARNING, "Write block failed"); - return isOK; + + return PM3_SUCCESS; } static int CmdHFiClass_WriteBlock(const char *Cmd) { @@ -1344,6 +1385,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { uint8_t keyNbr = 0; uint8_t dataLen = 0; char tempStr[50] = {0}; + bool got_blockno = false; bool use_credit_key = false; bool elite = false; bool rawkey = false; @@ -1355,10 +1397,12 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { case 'h': return usage_hf_iclass_writeblock(); case 'b': - blockno = param_get8ex(Cmd, cmdp + 1, 06, 16); + blockno = param_get8ex(Cmd, cmdp + 1, 07, 16); + got_blockno = true; cmdp += 2; break; case 'c': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("CREDIT")); use_credit_key = true; cmdp++; break; @@ -1370,6 +1414,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { cmdp += 2; break; case 'e': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("elite algo")); elite = true; cmdp++; break; @@ -1380,6 +1425,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { } else if (dataLen == 1) { keyNbr = param_get8(Cmd, cmdp + 1); if (keyNbr < ICLASS_KEYS_MAX) { + PrintAndLogEx(SUCCESS, "Using key[%d] %s", keyNbr, sprint_hex(iClass_Key_Table[keyNbr], 8 )); memcpy(KEY, iClass_Key_Table[keyNbr], 8); } else { PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n"); @@ -1392,6 +1438,7 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { cmdp += 2; break; case 'r': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("raw mode")); rawkey = true; cmdp++; break; @@ -1405,11 +1452,12 @@ static int CmdHFiClass_WriteBlock(const char *Cmd) { break; } } + if ( got_blockno == false) + errors = true; + if (errors || cmdp < 6) return usage_hf_iclass_writeblock(); - int ans = WriteBlock(blockno, bldata, KEY, use_credit_key, elite, rawkey, verbose); - DropField(); - return ans; + return WriteBlock(blockno, bldata, KEY, use_credit_key, elite, rawkey, verbose); } static int CmdHFiClassCloneTag(const char *Cmd) { @@ -1585,6 +1633,7 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; if (!select_and_auth(KEY, MAC, div_key, (keyType == 0x18), elite, rawkey, verbose)) { numberAuthRetries--; + DropField(); continue; } } else { @@ -1592,22 +1641,24 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; if (!select_only(CSN, CCNR, (keyType == 0x18), verbose)) { numberAuthRetries--; + DropField(); continue; } } PacketResponseNG resp; - clearCommandBuffer(); - uint8_t payload[] = { blockno }; - SendCommandNG(CMD_HF_ICLASS_READBL, payload, sizeof(payload)); + clearCommandBuffer(); + SendCommandNG(CMD_HF_ICLASS_READBL, (uint8_t*)&blockno, sizeof(uint8_t)); if (WaitForResponseTimeout(CMD_HF_ICLASS_READBL, &resp, 2000) == 0) { - PrintAndLogEx(WARNING, "Command execute timeout"); + if (verbose) PrintAndLogEx(WARNING, "Command execute timeout"); + DropField(); return PM3_ETIMEOUT; } if ( resp.status != PM3_SUCCESS ) { - PrintAndLogEx(ERR, "failed to communicate with card"); + if (verbose) PrintAndLogEx(ERR, "failed to communicate with card"); + DropField(); return PM3_EWRONGANSVER; } @@ -1617,10 +1668,13 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, } while (numberAuthRetries); + DropField(); + if ( numberAuthRetries > 0 ) { PrintAndLogEx(SUCCESS, "block %02X: %s\n", blockno, sprint_hex(result->blockdata, sizeof(result->blockdata))); } else { PrintAndLogEx(ERR,"failed to authenticate and read block"); + return PM3_ESOFT; } return PM3_SUCCESS; @@ -1633,6 +1687,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { uint8_t keyNbr = 0; uint8_t dataLen = 0; char tempStr[50] = {0}; + bool got_blockno = false; bool elite = false; bool rawkey = false; bool errors = false; @@ -1645,6 +1700,7 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { return usage_hf_iclass_readblock(); case 'b': blockno = param_get8ex(Cmd, cmdp + 1, 7, 16); + got_blockno = true; cmdp += 2; break; case 'c': @@ -1692,6 +1748,9 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) { break; } } + if ( got_blockno == false) + errors = true; + if (errors || cmdp < 4) return usage_hf_iclass_readblock(); if (!auth) From 9a2a0116e41d48e5fd5bb87ba55c041748a295bb Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 8 Sep 2019 23:19:06 +0200 Subject: [PATCH 291/347] fix: 'hf iclass clone' - last block write fails, see (https://github.com/RfidResearchGroup/proxmark3/issues/183) chg: 'hf iclass clone' - now tries ten times, behavies better, obey verbose nicer, drop field constant. Uses NG. chg: 'hf iclass dump' - now tries ten times, in general nice outputs.. --- armsrc/appmain.c | 8 +- armsrc/iclass.c | 24 +++--- client/cmdhficlass.c | 200 +++++++++++++++++++++++++++---------------- 3 files changed, 145 insertions(+), 87 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index cb5dbe8a2..990ac1c56 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1271,7 +1271,13 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ICLASS_CLONE: { - iClass_Clone(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes); + struct p { + uint8_t startblock; + uint8_t endblock; + uint8_t data[]; + } PACKED; + struct p *payload = (struct p *)packet->data.asBytes; + iClass_Clone(payload->startblock, payload->endblock, payload->data); break; } #endif diff --git a/armsrc/iclass.c b/armsrc/iclass.c index fa90f0881..c87bade4b 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -2520,23 +2520,19 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) { int total_block = (endblock - startblock) + 1; for (i = 0; i < total_block; i++) { // block number - if (iClass_WriteBlock_ext(i + startblock, data + (i * 12))) { - Dbprintf("Write block [%02x] successful", i + startblock); + if (iClass_WriteBlock_ext(startblock + i, data + (i * 12))) { + Dbprintf("Write block [%02x] successful", startblock + i); written++; } else { - if (iClass_WriteBlock_ext(i + startblock, data + (i * 12))) { - Dbprintf("Write block [%02x] successful", i + startblock); - written++; - } else { - Dbprintf("Write block [%02x] failed", i + startblock); - } + Dbprintf("Write block [%02x] failed", startblock + i); } } - if (written == total_block) - DbpString("Clone complete"); - else - DbpString("Clone incomplete"); - - reply_mix(CMD_ACK, 1, 0, 0, 0, 0); + switch_off(); + + uint8_t isOK = 0; + if (written == total_block) + isOK = 1; + + reply_ng(CMD_HF_ICLASS_CLONE, PM3_SUCCESS, (uint8_t *)&isOK, sizeof(uint8_t)); } diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 5ac3a8925..4f9a34113 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1118,6 +1118,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { cmdp += 2; break; case 'e': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("elite algo")); elite = true; cmdp++; break; @@ -1149,6 +1150,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { cmdp += 2; break; case 'r': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("raw mode")); rawkey = true; cmdp++; break; @@ -1180,7 +1182,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) { PrintAndLogEx(WARNING, "command execute timeout"); DropField(); - return 0; + return PM3_ESOFT; } DropField(); @@ -1189,7 +1191,8 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { if (readStatus == 0) { PrintAndLogEx(FAILED, "no tag found"); - return 0; + DropField(); + return PM3_ESOFT; } if (readStatus & (FLAG_ICLASS_READER_CSN | FLAG_ICLASS_READER_CONF | FLAG_ICLASS_READER_CC)) { @@ -1202,14 +1205,16 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { } // authenticate debit key and get div_key - later store in dump block 3 - if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose)) { - //try twice - for some reason it sometimes fails the first time... - PrintAndLogEx(SUCCESS, "retry to select card"); - if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose)) { - PrintAndLogEx(WARNING, "failed authenticating with debit key"); - DropField(); - return 0; - } + int numberAuthRetries = ICLASS_AUTH_RETRY; + do { + if (select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose)) + break; + } while (numberAuthRetries--); + + if ( numberAuthRetries <= 0) { + PrintAndLogEx(WARNING, "failed authenticating with debit key"); + DropField(); + return PM3_ESOFT; } // begin dump @@ -1233,7 +1238,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { uint8_t isOK = resp.oldarg[0] & 0xff; if (!isOK && !blocksRead) { PrintAndLogEx(WARNING, "read block failed"); - return 0; + return PM3_ESOFt; } uint32_t startindex = resp.oldarg[2]; @@ -1245,7 +1250,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { // response ok - now get bigbuf content of the dump if (!GetFromDevice(BIG_BUF, tag_data + (blockno * 8), blocksRead * 8, startindex, NULL, 0, NULL, 2500, false)) { PrintAndLogEx(WARNING, "command execution time out"); - return 0; + return PM3_ETIMEOUT; } size_t gotBytes = blocksRead * 8 + blockno * 8; @@ -1254,16 +1259,22 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { if (have_credit_key) { //turn off hf field before authenticating with different key DropField(); + memset(MAC, 0, 4); + // AA2 authenticate credit key and git c_div_key - later store in dump block 4 - if (!select_and_auth(CreditKEY, MAC, c_div_key, true, elite, rawkey, verbose)) { - //try twice - for some reason it sometimes fails the first time... - if (!select_and_auth(CreditKEY, MAC, c_div_key, true, elite, rawkey, verbose)) { - PrintAndLogEx(WARNING, "failed authenticating with credit key"); - DropField(); - return 0; - } + numberAuthRetries = ICLASS_AUTH_RETRY; + do { + if (select_and_auth(CreditKEY, MAC, c_div_key, true, elite, rawkey, verbose)) + break; + } while (numberAuthRetries--); + + if ( numberAuthRetries <= 0) { + PrintAndLogEx(WARNING, "failed authenticating with credit key"); + DropField(); + return PM3_ESOFT; } + // do we still need to read more block? (aa2 enabled?) if (maxBlk > blockno + numblks + 1) { // setup dump and start @@ -1271,13 +1282,13 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { SendCommandMIX(CMD_HF_ICLASS_DUMP, blockno + blocksRead, maxBlk - (blockno + blocksRead), 0, NULL, 0); if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) { PrintAndLogEx(WARNING, "command execute timeout 2"); - return 0; + return PM3_ETIMEOUT; } isOK = resp.oldarg[0] & 0xff; blocksRead = resp.oldarg[1]; if (!isOK && !blocksRead) { PrintAndLogEx(WARNING, "read block failed 2"); - return 0; + return PM3_ESOFT; } startindex = resp.oldarg[2]; @@ -1288,7 +1299,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { // get dumped data from bigbuf if (!GetFromDevice(BIG_BUF, tag_data + gotBytes, blocksRead * 8, startindex, NULL, 0, NULL, 2500, false)) { PrintAndLogEx(WARNING, "command execution time out"); - return 0; + return PM3_ETIMEOUT; } gotBytes += blocksRead * 8; @@ -1298,16 +1309,20 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { DropField(); // add diversified keys to dump - if (have_debit_key) memcpy(tag_data + (3 * 8), div_key, 8); - if (have_credit_key) memcpy(tag_data + (4 * 8), c_div_key, 8); + if (have_debit_key) + memcpy(tag_data + (3 * 8), div_key, 8); + + if (have_credit_key) + memcpy(tag_data + (4 * 8), c_div_key, 8); + // print the dump - PrintAndLogEx(NORMAL, "------+--+-------------------------+\n"); - PrintAndLogEx(NORMAL, "CSN |00| %s|\n", sprint_hex(tag_data, 8)); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "------+--+-------------------------+"); + PrintAndLogEx(NORMAL, "CSN |00| %s|", sprint_hex(tag_data, 8)); printIclassDumpContents(tag_data, 1, (gotBytes / 8), gotBytes); if (filename[0] == 0) { - //Use the first block (CSN) for filename strcat(filename, "hf-iclass-"); FillFileNameByUID(filename, tag_data, "-data", 8); @@ -1469,6 +1484,7 @@ static int CmdHFiClassCloneTag(const char *Cmd) { uint8_t startblock = 0; uint8_t endblock = 0; uint8_t dataLen = 0; + bool got_startblk = false, got_endblk = false; bool use_credit_key = false; bool elite = false; bool rawkey = false; @@ -1480,17 +1496,17 @@ static int CmdHFiClassCloneTag(const char *Cmd) { case 'h': return usage_hf_iclass_clone(); case 'b': - if (param_gethex(Cmd, cmdp + 1, &startblock, 2)) { - PrintAndLogEx(WARNING, "start block No must include 2 HEX symbols\n"); - errors = true; - } + startblock = param_get8ex(Cmd, cmdp + 1, 07, 16); + got_startblk = true; cmdp += 2; break; case 'c': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("CREDIT")); use_credit_key = true; cmdp++; break; case 'e': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("elite algo")); elite = true; cmdp++; break; @@ -1509,6 +1525,7 @@ static int CmdHFiClassCloneTag(const char *Cmd) { } else if (dataLen == 1) { keyNbr = param_get8(Cmd, cmdp + 1); if (keyNbr < ICLASS_KEYS_MAX) { + PrintAndLogEx(SUCCESS, "Using key[%d] %s", keyNbr, sprint_hex(iClass_Key_Table[keyNbr], 8 )); memcpy(KEY, iClass_Key_Table[keyNbr], 8); } else { PrintAndLogEx(WARNING, "\nERROR: Credit KeyNbr is invalid\n"); @@ -1521,13 +1538,12 @@ static int CmdHFiClassCloneTag(const char *Cmd) { cmdp += 2; break; case 'l': - if (param_gethex(Cmd, cmdp + 1, &endblock, 2)) { - PrintAndLogEx(WARNING, "start Block No must include 2 HEX symbols\n"); - errors = true; - } + endblock = param_get8ex(Cmd, cmdp + 1, 07, 16); + got_endblk = true; cmdp += 2; break; case 'r': + PrintAndLogEx(SUCCESS, "Using " _YELLOW_("raw mode")); rawkey = true; cmdp++; break; @@ -1541,53 +1557,66 @@ static int CmdHFiClassCloneTag(const char *Cmd) { break; } } + if ( got_endblk == false || got_startblk == false) + errors = true; if (errors || cmdp < 8) return usage_hf_iclass_clone(); - FILE *f; - - iclass_block_t tag_data[PM3_CMD_DATA_SIZE / 12]; - - if ((endblock - startblock + 1) * 12 > PM3_CMD_DATA_SIZE) { - PrintAndLogEx(NORMAL, "Trying to write too many blocks at once. Max: %d", PM3_CMD_DATA_SIZE / 8); + if (startblock < 5) { + PrintAndLogEx(WARNING, "you cannot write key blocks this way. yet... make your start block > 4"); + return PM3_EINVARG; } + + int total_bytes = (((endblock - startblock) + 1) * 12); + + if (total_bytes > PM3_CMD_DATA_SIZE - 2) { + PrintAndLogEx(NORMAL, "Trying to write too many blocks at once. Max: %d", PM3_CMD_DATA_SIZE / 8); + return PM3_EINVARG; + } + // file handling and reading - f = fopen(filename, "rb"); + FILE *f = fopen(filename, "rb"); if (!f) { PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", filename); return PM3_EFILE; } - if (startblock < 5) { - PrintAndLogEx(WARNING, "you cannot write key blocks this way. yet... make your start block > 4"); - fclose(f); - return 0; - } - // now read data from the file from block 6 --- 19 - // ok we will use this struct [data 8 bytes][MAC 4 bytes] for each block calculate all mac number for each data - // then copy to usbcommand->asbytes; the max is 32 - 6 = 24 block 12 bytes each block 288 bytes then we can only accept to clone 21 blocks at the time, - // else we have to create a share memory + iclass_block_t tag_data[PM3_CMD_DATA_SIZE / 12]; + + // read data from file from block 6 --- 19 + // we will use this struct [data 8 bytes][MAC 4 bytes] for each block calculate all mac number for each data + // then copy to usbcommand->asbytes; + // max is 32 - 6 = 28 block. 28 x 12 bytes gives 336 bytes int i; fseek(f, startblock * 8, SEEK_SET); size_t bytes_read = fread(tag_data, sizeof(iclass_block_t), endblock - startblock + 1, f); + fclose(f); + if (bytes_read == 0) { PrintAndLogEx(ERR, "file reading error."); - fclose(f); - return 2; + return PM3_EFILE; } - fclose(f); - uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00}; uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose)) { - return 0; + + int numberAuthRetries = ICLASS_AUTH_RETRY; + do { + if (select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose)) + break; + } while (numberAuthRetries--); + + if ( numberAuthRetries <= 0 ) { + PrintAndLogEx(ERR, "failed to authenticate"); + DropField(); + return PM3_ESOFT; } - uint8_t data[(endblock - startblock) * 12]; + uint8_t data[total_bytes]; + // calculate all mac for every the block we will write for (i = startblock; i <= endblock; i++) { + Calc_wb_mac(i, tag_data[i - startblock].d, div_key, MAC); // usb command d start pointer = d + (i - 6) * 12 // memcpy(pointer,tag_data[i - 6],8) 8 bytes @@ -1597,22 +1626,49 @@ static int CmdHFiClassCloneTag(const char *Cmd) { memcpy(ptr, &(tag_data[i - startblock].d[0]), 8); memcpy(ptr + 8, MAC, 4); } - uint8_t p[12]; - for (i = 0; i <= endblock - startblock; i++) { - memcpy(p, data + (i * 12), 12); - PrintAndLogEx(NORMAL, "Block |%02x|", i + startblock); - PrintAndLogEx(NORMAL, " %02x%02x%02x%02x%02x%02x%02x%02x |", p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - PrintAndLogEx(NORMAL, " MAC |%02x%02x%02x%02x|\n", p[8], p[9], p[10], p[11]); + + if ( verbose ) { + PrintAndLogEx(NORMAL,"------+--------------------------+-------------"); + PrintAndLogEx(NORMAL,"block | data | mac"); + PrintAndLogEx(NORMAL,"------+--------------------------+-------------"); + uint8_t p[12]; + for (i = 0; i <= endblock - startblock; i++) { + memcpy(p, data + (i * 12), 12); + char *s = calloc(70, sizeof(uint8_t)); + sprintf(s, "| %s ", sprint_hex(p, 8)); + sprintf(s + strlen(s), "| %s", sprint_hex(p + 8, 4)); + PrintAndLogEx(NORMAL, " %02X %s", i + startblock, s ); + free(s); + } } + struct p { + uint8_t startblock; + uint8_t endblock; + uint8_t data[PM3_CMD_DATA_SIZE - 2]; + } PACKED payload; + + payload.startblock = startblock; + payload.endblock = endblock; + memcpy(payload.data, data, total_bytes); + PacketResponseNG resp; clearCommandBuffer(); - SendCommandOLD(CMD_HF_ICLASS_CLONE, startblock, endblock, 0, data, (endblock - startblock) * 12); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 4500)) { + SendCommandNG(CMD_HF_ICLASS_CLONE, (uint8_t*)&payload, total_bytes + 2 ); + + if (WaitForResponseTimeout(CMD_HF_ICLASS_CLONE, &resp, 4500) == 0) { PrintAndLogEx(WARNING, "command execute timeout"); - return 0; + DropField(); + return PM3_ETIMEOUT; } - return PM3_SUCCESS; + + if (resp.status == PM3_SUCCESS) { + if ( resp.data.asBytes[0] == 1 ) + PrintAndLogEx(SUCCESS, "Clone successful"); + else + PrintAndLogEx(WARNING, "Clone failed"); + } + return resp.status; } static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool verbose, bool auth) { @@ -1809,13 +1865,13 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e //PrintAndLog ("startblock: %d, endblock: %d, filesize: %d, maxmemcount: %d, filemaxblock: %d",startblock, endblock,filesize, maxmemcount, filemaxblock); int i = startblock; - PrintAndLogEx(NORMAL, "------+--+-------------------------+\n"); + PrintAndLogEx(NORMAL, "------+--+-------------------------+"); while (i <= endblock) { uint8_t *blk = iclass_dump + (i * 8); - PrintAndLogEx(NORMAL, " |%02X| %s\n", i, sprint_hex_ascii(blk, 8)); + PrintAndLogEx(NORMAL, " |%02X| %s", i, sprint_hex_ascii(blk, 8)); i++; } - PrintAndLogEx(NORMAL, "------+--+-------------------------+\n"); + PrintAndLogEx(NORMAL, "------+--+-------------------------+"); } static int CmdHFiClassReadTagFile(const char *Cmd) { From ca606bb2117bc952ffdb2a7fa4c0610717ebb1e6 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 8 Sep 2019 23:23:06 +0200 Subject: [PATCH 292/347] stupid... --- client/cmdhficlass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 4f9a34113..c24853dcb 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1238,7 +1238,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) { uint8_t isOK = resp.oldarg[0] & 0xff; if (!isOK && !blocksRead) { PrintAndLogEx(WARNING, "read block failed"); - return PM3_ESOFt; + return PM3_ESOFT; } uint32_t startindex = resp.oldarg[2]; From fe0fe0d65b887bf5179f9f10dc70e7ff0422006a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 8 Sep 2019 23:28:45 +0200 Subject: [PATCH 293/347] textual --- CHANGELOG.md | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e1fe1fe..5cb0e5c1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ 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... ## [unreleased][unreleased] + - Chg `hf iclass clone\dump\rdbl\wrbl` - now uses NG (@iceman1001) + - Fix `hf iclass clone` - last block always fails (@iceman1001) + - Chg `hf iclass clone` - retries ten times, less output (honor verbose) (@iceman1001) + - Chg `hf iclass dump` - retries ten times, less output (honor verbose) (@iceman1001) + - Rename `hf iclass writeblk` -> `hf iclass wrbl` to match hf mf wrbl (@iceman1001) + - Rename `hf iclass readblk` -> `hf iclass rdbl` to match hf mf rdbl (@iceman1001) - Add cmdscript example and show usage with shebang (@doegox) - Add instructions for Fedora (@doegox) - Chg reduce the list of requirements to the minimum and move to QT5 (@doegox) @@ -11,23 +17,23 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Chg posix sh version of mkversion (@doegox) - Chg remove entirely ncurses, not needed nowadays (@doegox) - Chg remove deprecated termcap, use ncurses instead (@ZeroChaos-) - - Chg 'hf iclass encrypt' - now takes transport key as param. (@iceman1001) - - Chg 'hf iclass decrypt' - now takes transport key as param. (@iceman1001) - - Chg 'hf mf fchk m' - now secretly dumps card to emul, if all keys are found (@iceman1001) + - Chg `hf iclass encrypt` - now takes transport key as param. (@iceman1001) + - Chg `hf iclass decrypt` - now takes transport key as param. (@iceman1001) + - Chg `hf mf fchk m` - now secretly dumps card to emul, if all keys are found (@iceman1001) - Chg history and logfile are now saved into $HOME/.proxmark3/ (@doegox) - Chg optimization of iclass mac calculations on deviceside (@pwpiwi) - - Add 'hf mf autopwn' - Autopwn function for Mifare Classic, extract all keys and dump card memory (@matthiaskonrath) + - Add `hf mf autopwn` - Autopwn function for Mifare Classic, extract all keys and dump card memory (@matthiaskonrath) - Add Lua paths: look for scripts also in ~/.proxmark/lua{scripts,libs} and /usr/local/share/proxmark3/lua{scripts,libs} (@doegox) - Change Lua directory scripts/ to luascript/ (@doegox) - Change non-rdv4 PLATFORM must now use the generic PM3OTHER, simpler (@doegox) - Fix reveng integration for all platforms else than WIN32 (@doegox) - Add cheat sheet for easy operations of the Proxmark3 (scund00r) - Chg commands are now in green in the helptext list (@iceman1001) - - Fix 'script run ndefdump' - better exit messages when failing (@iceman1001) - - Fix 'hf iclass dump' - now also saves in EML format (@iceman1001) - - Fix 'hf iclass sim 3' - now works on legacy readers and legacy SE readers (@iceman1001) + - Fix `script run ndefdump` - better exit messages when failing (@iceman1001) + - Fix `hf iclass dump` - now also saves in EML format (@iceman1001) + - Fix `hf iclass sim 3` - now works on legacy readers and legacy SE readers (@iceman1001) - Rework hitag2 read/write help (@ViRb3) - - Add 'lf nedap' - encoding / decoding (anon) + - Add `lf nedap` - encoding / decoding (anon) - Add client option `-i` to stay in interactive mode after a script or command (@DidierStevens/@doegox) - Add VSCode tasks (@ViRb3) - Better warn user of hardcoded hitag info (@ViRb3) @@ -35,10 +41,10 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fix hitag password write offset by 1 (@ViRb3) - Fix momentarily flash read/write of dicts (@doegox/@cjbrigato) - Add some more default keys (@anon) - - Add 'hf thinfilm sim' simulating Thinfilm NFC barcode tags (@doegox) - - Add 'hf thinfilm list' specific trace decoding (Thinfilm NFC barcode tags) (@doegox) - - Fix 'hf topaz reader' - don't crash when trying to read a Thinfilm tag (@iceman1001) - - Add 'hf thinfilm info' - read / decode Kovio Thinfilm NFC barcode tags (@iceman1001) + - Add `hf thinfilm sim` simulating Thinfilm NFC barcode tags (@doegox) + - Add `hf thinfilm list` specific trace decoding (Thinfilm NFC barcode tags) (@doegox) + - Fix `hf topaz reader` - don't crash when trying to read a Thinfilm tag (@iceman1001) + - Add `hf thinfilm info` - read / decode Kovio Thinfilm NFC barcode tags (@iceman1001) - Add FPGA LF adc path (@anon) - Add ECC support / check for NID_secp128r1 (@pwpiwi) - Add some more default keys (ollibolli) From afe891647fa3702ae8164d6f7503aaa4d9734626 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 01:07:46 +0200 Subject: [PATCH 294/347] merge flasher in client --- Makefile | 2 +- client/Makefile | 13 +- client/flash.c | 90 ++++++----- client/flash.h | 3 + client/flasher.c | 130 ---------------- client/proxmark3.c | 144 +++++++++++++++--- ...OS-X-Homebrew-Installation-Instructions.md | 6 +- .../ModemManager-Must-Be-Discarded.md | 2 +- .../Troubleshooting.md | 18 +-- .../Windows-Installation-Instructions.md | 10 +- .../0_Compilation-Instructions.md | 4 +- doc/path_notes.md | 4 +- pm3 | 23 ++- pm3-flash | 4 + 14 files changed, 231 insertions(+), 222 deletions(-) delete mode 100644 client/flasher.c create mode 100755 pm3-flash diff --git a/Makefile b/Makefile index 90ee442ca..ebb4dacb8 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ all clean install uninstall: %: client/% bootrom/% armsrc/% recovery/% mfkey/% n INSTALLTOOLS=pm3_eml2lower.sh pm3_eml2upper.sh pm3_mfdread.py pm3_mfd2eml.py pm3_eml2mfd.py findbits.py rfidtest.pl xorcheck.py INSTALLSIMFW=sim011.bin sim011.sha512.txt -INSTALLSCRIPTS=pm3 pm3-flash-all pm3-flash-bootrom pm3-flash-fullimage +INSTALLSCRIPTS=pm3 pm3-flash pm3-flash-all pm3-flash-bootrom pm3-flash-fullimage INSTALLSHARES=tools/jtag_openocd traces INSTALLDOCS=doc/*.md doc/md diff --git a/client/Makefile b/client/Makefile index 96b5d1bf4..6fee6eae8 100644 --- a/client/Makefile +++ b/client/Makefile @@ -14,7 +14,7 @@ ROOT_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST)))) include ../Makefile.defs -INSTALLBIN = proxmark3 proxmark3-flasher +INSTALLBIN = proxmark3 INSTALLSHARE = cmdscripts lualibs luascripts resources dictionaries VPATH = ../common uart @@ -237,7 +237,8 @@ CMDSRCS = crapto1/crapto1.c \ cmdscript.c \ pm3_bitlib.c \ cmdcrc.c \ - bucketsort.c + bucketsort.c \ + flash.c cpu_arch = $(shell uname -m) ifneq ($(findstring 86, $(cpu_arch)), ) @@ -278,7 +279,7 @@ ifeq "$(SUPPORTS_AVX512)" "True" MULTIARCHOBJS += $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX512.o) endif -BINS = proxmark3 proxmark3-flasher +BINS = proxmark3 CLEAN = $(BINS) *.moc.cpp ui/ui_overlays.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua # transition: make sure old flasher is gone too CLEAN += flasher @@ -294,10 +295,6 @@ proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(info [=] LD $@) $(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(LDLIBS) -o $@ -proxmark3-flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS) $(OBJCOBJS) - $(info [=] LD $@) - $(Q)$(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@ - proxgui.cpp: ui/ui_overlays.h proxguiqt.moc.cpp: proxguiqt.h @@ -447,7 +444,7 @@ DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(REVEN $(patsubst %.o, %.d, $(MULTIARCHOBJS)) \ $(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \ $(patsubst %.m, $(OBJDIR)/%.d, $(OBJCSRCS)) \ - $(OBJDIR)/proxmark3.d $(OBJDIR)/flash.d $(OBJDIR)/proxmark3-flasher.d $(OBJDIR)/flasher.d + $(OBJDIR)/proxmark3.d $(DEPENDENCY_FILES): ; .PRECIOUS: $(DEPENDENCY_FILES) diff --git a/client/flash.c b/client/flash.c index 84e1d687b..5bbb669c0 100644 --- a/client/flash.c +++ b/client/flash.c @@ -83,7 +83,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, ctx->segments = calloc(sizeof(flash_seg_t) * num_phdrs, sizeof(uint8_t)); if (!ctx->segments) { PrintAndLogEx(ERR, "Out of memory"); - return -1; + return PM3_EMALLOC; } ctx->num_segs = 0; seg = ctx->segments; @@ -113,19 +113,19 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, if (filesz != memsz) { PrintAndLogEx(ERR, "Error: PHDR file size does not equal memory size\n" "(DATA+BSS PHDRs do not make sense on ROM platforms!)"); - return -1; + return PM3_EFILE; } if (paddr < last_end) { PrintAndLogEx(ERR, "Error: PHDRs not sorted or overlap"); - return -1; + return PM3_EFILE; } if (paddr < FLASH_START || (paddr + filesz) > flash_end) { PrintAndLogEx(ERR, "Error: PHDR is not contained in Flash"); - return -1; + return PM3_EFILE; } if (vaddr >= FLASH_START && vaddr < flash_end && (flags & PF_W)) { PrintAndLogEx(ERR, "Error: Flash VMA segment is writable"); - return -1; + return PM3_EFILE; } uint8_t *data; @@ -133,12 +133,12 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, data = calloc(filesz + BLOCK_SIZE, sizeof(uint8_t)); if (!data) { PrintAndLogEx(ERR, "Error: Out of memory"); - return -1; + return PM3_EMALLOC; } if (fseek(fd, offset, SEEK_SET) < 0 || fread(data, 1, filesz, fd) != filesz) { PrintAndLogEx(ERR, "Error while reading PHDR payload"); free(data); - return -1; + return PM3_EFILE; } uint32_t block_offset = paddr & (BLOCK_SIZE - 1); @@ -157,7 +157,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, if (!new_data) { PrintAndLogEx(ERR, "Error: Out of memory"); free(data); - return -1; + return PM3_EMALLOC; } memset(new_data, 0xff, new_length); memcpy(new_data, prev_seg->data, prev_seg->length); @@ -191,7 +191,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, last_end = paddr + filesz; phdr++; } - return 0; + return PM3_SUCCESS; } // Sanity check segments and check for bootloader writes @@ -201,26 +201,26 @@ static int check_segs(flash_file_t *ctx, int can_write_bl, uint32_t flash_end) { if (seg->start & (BLOCK_SIZE - 1)) { PrintAndLogEx(ERR, "Error: Segment is not aligned"); - return -1; + return PM3_EFILE; } if (seg->start < FLASH_START) { PrintAndLogEx(ERR, "Error: Segment is outside of flash bounds"); - return -1; + return PM3_EFILE; } if (seg->start + seg->length > flash_end) { PrintAndLogEx(ERR, "Error: Segment is outside of flash bounds"); - return -1; + return PM3_EFILE; } if (!can_write_bl && seg->start < BOOTLOADER_END) { PrintAndLogEx(ERR, "Attempted to write bootloader but bootloader writes are not enabled"); - return -1; + return PM3_EINVARG; } if (can_write_bl && seg->start < BOOTLOADER_END && (seg->start + seg->length > BOOTLOADER_END)) { PrintAndLogEx(ERR, "Error: Segment is outside of bootloader bounds"); - return -1; + return PM3_EFILE; } } - return 0; + return PM3_SUCCESS; } // Load an ELF file and prepare it for flashing @@ -230,11 +230,12 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl, int flash_ Elf32_Phdr *phdrs = NULL; uint16_t num_phdrs; uint32_t flash_end = FLASH_START + flash_size; - int res; + int res = PM3_EUNDEF; fd = fopen(name, "rb"); if (!fd) { PrintAndLogEx(ERR, _RED_("Could not open file") "%s >>> ", name); + res = PM3_EFILE; goto fail; } @@ -242,28 +243,34 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl, int flash_ if (fread(&ehdr, sizeof(ehdr), 1, fd) != 1) { PrintAndLogEx(ERR, "Error while reading ELF file header"); + res = PM3_EFILE; goto fail; } if (memcmp(ehdr.e_ident, elf_ident, sizeof(elf_ident)) || le32(ehdr.e_version) != 1) { PrintAndLogEx(ERR, "Not an ELF file or wrong ELF type"); + res = PM3_EFILE; goto fail; } if (le16(ehdr.e_type) != ET_EXEC) { PrintAndLogEx(ERR, "ELF is not executable"); + res = PM3_EFILE; goto fail; } if (le16(ehdr.e_machine) != EM_ARM) { PrintAndLogEx(ERR, "Wrong ELF architecture"); + res = PM3_EFILE; goto fail; } if (!ehdr.e_phnum || !ehdr.e_phoff) { PrintAndLogEx(ERR, "ELF has no PHDRs"); + res = PM3_EFILE; goto fail; } if (le16(ehdr.e_phentsize) != sizeof(Elf32_Phdr)) { // could be a structure padding issue... PrintAndLogEx(ERR, "Either the ELF file or this code is made of fail"); + res = PM3_EFILE; goto fail; } num_phdrs = le16(ehdr.e_phnum); @@ -271,28 +278,31 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl, int flash_ phdrs = calloc(le16(ehdr.e_phnum) * sizeof(Elf32_Phdr), sizeof(uint8_t)); if (!phdrs) { PrintAndLogEx(ERR, "Out of memory"); + res = PM3_EMALLOC; goto fail; } if (fseek(fd, le32(ehdr.e_phoff), SEEK_SET) < 0) { PrintAndLogEx(ERR, "Error while reading ELF PHDRs"); + res = PM3_EFILE; goto fail; } if (fread(phdrs, sizeof(Elf32_Phdr), num_phdrs, fd) != num_phdrs) { + res = PM3_EFILE; PrintAndLogEx(ERR, "Error while reading ELF PHDRs"); goto fail; } res = build_segs_from_phdrs(ctx, fd, phdrs, num_phdrs, flash_end); - if (res < 0) + if (res != PM3_SUCCESS) goto fail; res = check_segs(ctx, can_write_bl, flash_end); - if (res < 0) + if (res != PM3_SUCCESS) goto fail; free(phdrs); fclose(fd); ctx->filename = name; - return 0; + return PM3_SUCCESS; fail: if (phdrs) @@ -300,7 +310,7 @@ fail: if (fd) fclose(fd); flash_free(ctx); - return -1; + return res; } // Get the state of the proxmark, backwards compatible @@ -326,22 +336,23 @@ static int get_proxmark_state(uint32_t *state) { break; default: PrintAndLogEx(ERR, _RED_("Error:") "Couldn't get Proxmark3 state, bad response type: 0x%04x", resp.cmd); - return -1; + return PM3_EFATAL; break; } - return 0; + return PM3_SUCCESS; } // Enter the bootloader to be able to start flashing static int enter_bootloader(char *serial_port_name) { uint32_t state; + int ret; - if (get_proxmark_state(&state) < 0) - return -1; + if ((ret = get_proxmark_state(&state)) != PM3_SUCCESS) + return ret; /* Already in flash state, we're done. */ if (state & DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM) - return 0; + return PM3_SUCCESS; if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) { PrintAndLogEx(SUCCESS, _BLUE_("Entering bootloader...")); @@ -364,15 +375,15 @@ static int enter_bootloader(char *serial_port_name) { if (OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) { PrintAndLogEx(NORMAL, " " _GREEN_("Found")); - return 0; + return PM3_SUCCESS; } else { PrintAndLogEx(ERR, _RED_("Error:") "Proxmark3 not found."); - return -1; + return PM3_ETIMEOUT; } } PrintAndLogEx(ERR, _RED_("Error:") "Unknown Proxmark3 mode"); - return -1; + return PM3_EFATAL; } static int wait_for_ack(PacketResponseNG *ack) { @@ -383,9 +394,9 @@ static int wait_for_ack(PacketResponseNG *ack) { ack->cmd, (ack->cmd == CMD_NACK) ? "NACK" : "" ); - return -1; + return PM3_ESOFT; } - return 0; + return PM3_SUCCESS; } static void flash_suggest_update_bootloader(void) { @@ -401,12 +412,15 @@ static void flash_suggest_update_flasher(void) { int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *max_allowed) { uint32_t state; uint32_t chipinfo = 0; + int ret; - if (enter_bootloader(serial_port_name) < 0) - return -1; + ret = enter_bootloader(serial_port_name); + if (ret != PM3_SUCCESS) + return ret; - if (get_proxmark_state(&state) < 0) - return -1; + ret = get_proxmark_state(&state); + if (ret != PM3_SUCCESS) + return ret; if (state & DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO) { SendCommandBL(CMD_CHIP_INFO, 0, 0, 0, NULL, 0); @@ -485,7 +499,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new " _YELLOW_("START_FLASH") _RED_("command"))); flash_suggest_update_bootloader(); } - return 0; + return PM3_SUCCESS; } static int write_block(uint32_t address, uint8_t *data, uint32_t length) { @@ -531,7 +545,7 @@ int flash_write(flash_file_t *ctx) { if (write_block(baddr, data, block_size) < 0) { PrintAndLogEx(ERR, "Error writing block %d of %u", block, blocks); - return -1; + return PM3_EFATAL; } data += block_size; @@ -544,7 +558,7 @@ int flash_write(flash_file_t *ctx) { PrintAndLogEx(NORMAL, " " _GREEN_("OK")); fflush(stdout); } - return 0; + return PM3_SUCCESS; } // free a file context @@ -564,5 +578,5 @@ void flash_free(flash_file_t *ctx) { int flash_stop_flashing(void) { SendCommandBL(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0); msleep(100); - return 0; + return PM3_SUCCESS; } diff --git a/client/flash.h b/client/flash.h index eca4d9ccc..23dd28079 100644 --- a/client/flash.h +++ b/client/flash.h @@ -11,6 +11,9 @@ #include "common.h" +#define FLASH_MAX_FILES 4 +#define ONE_KB 1024 + typedef struct { void *data; uint32_t start; diff --git a/client/flasher.c b/client/flasher.c deleted file mode 100644 index 931976997..000000000 --- a/client/flasher.c +++ /dev/null @@ -1,130 +0,0 @@ -//----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Flasher frontend tool -//----------------------------------------------------------------------------- - -#include -#include -#include "usart_defs.h" -#include "flash.h" -#include "comms.h" -#include "ui.h" - -#define MAX_FILES 4 -#define ONE_KB 1024 - -static void usage(char *argv0) { - PrintAndLogEx(NORMAL, "Usage: %s [-b] image.elf [image.elf...]", argv0); - PrintAndLogEx(NORMAL, " %s -i\n", argv0); - PrintAndLogEx(NORMAL, "\t-b\tEnable flashing of bootloader area (DANGEROUS)"); - PrintAndLogEx(NORMAL, "\t-i\tProbe the connected Proxmark3 to retrieve its memory size"); - PrintAndLogEx(NORMAL, "\nExamples:\n\t %s "SERIAL_PORT_EXAMPLE_H" -i", argv0); - PrintAndLogEx(NORMAL, "\t %s "SERIAL_PORT_EXAMPLE_H" armsrc/obj/fullimage.elf", argv0); -#ifdef __linux__ - PrintAndLogEx(NORMAL, "\nNote (Linux):\nif the flasher gets stuck in 'Waiting for Proxmark3 to reappear on ',"); - PrintAndLogEx(NORMAL, "you need to blacklist Proxmark3 for modem-manager - see documentation for more details:"); - PrintAndLogEx(NORMAL, "* https://github.com/RfidResearchGroup/proxmark3/blob/master/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md"); - PrintAndLogEx(NORMAL, "\nMore info on flashing procedure from the official Proxmark3 wiki:"); - PrintAndLogEx(NORMAL, "* https://github.com/Proxmark/proxmark3/wiki/Gentoo%%20Linux"); - PrintAndLogEx(NORMAL, "* https://github.com/Proxmark/proxmark3/wiki/Ubuntu%%20Linux"); - PrintAndLogEx(NORMAL, "* https://github.com/Proxmark/proxmark3/wiki/OSX\n"); -#endif -} - -int main(int argc, char **argv) { - int can_write_bl = 0; - int num_files = 0; - int res; - int ret = 0; - flash_file_t files[MAX_FILES]; - char *filenames[MAX_FILES]; - bool info = false; - memset(files, 0, sizeof(files)); - - session.supports_colors = false; - session.stdinOnTTY = isatty(STDIN_FILENO); - session.stdoutOnTTY = isatty(STDOUT_FILENO); -#if defined(__linux__) || (__APPLE__) - if (session.stdinOnTTY && session.stdoutOnTTY) - session.supports_colors = true; -#endif - session.help_dump_mode = false; - - if (argc < 3) { - usage(argv[0]); - return -1; - } - - for (int i = 2; i < argc; i++) { - if (argv[i][0] == '-') { - if (!strcmp(argv[i], "-b")) { - can_write_bl = 1; - } else if (!strcmp(argv[i], "-i")) { - info = true; - } else { - usage(argv[0]); - return -1; - } - } else { - filenames[num_files] = argv[i]; - num_files++; - } - } - - char *serial_port_name = argv[1]; - - if (OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) { - PrintAndLogEx(NORMAL, _GREEN_("Found")); - } else { - PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name); - return -1; - } - - uint32_t max_allowed = 0; - res = flash_start_flashing(can_write_bl, serial_port_name, &max_allowed); - if (res < 0) { - ret = -1; - goto finish; - } - - if (info) - goto finish; - - for (int i = 0 ; i < num_files; ++i) { - res = flash_load(&files[i], filenames[i], can_write_bl, max_allowed * ONE_KB); - if (res < 0) { - ret = -1; - goto finish; - } - PrintAndLogEx(NORMAL, ""); - } - - PrintAndLogEx(SUCCESS, "\n" _BLUE_("Flashing...")); - - for (int i = 0; i < num_files; i++) { - res = flash_write(&files[i]); - if (res < 0) { - ret = -1; - goto finish; - } - flash_free(&files[i]); - PrintAndLogEx(NORMAL, "\n"); - } - -finish: - res = flash_stop_flashing(); - if (res < 0) - ret = -1; - - CloseProxmark(); - - if (ret == 0) - PrintAndLogEx(SUCCESS, _BLUE_("All done.")); - else - PrintAndLogEx(ERR, "Aborted on error."); - PrintAndLogEx(NORMAL, "\nHave a nice day!"); - return ret; -} diff --git a/client/proxmark3.c b/client/proxmark3.c index 26256dd12..05afcc1fd 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -25,6 +25,7 @@ #include "whereami.h" #include "comms.h" #include "fileutils.h" +#include "flash.h" static void showBanner(void) { @@ -278,12 +279,12 @@ static void set_my_executable_path(void) { static void show_help(bool showFullHelp, char *exec_name) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "syntax: %s [-h|-t|-m]\n", exec_name); - PrintAndLogEx(NORMAL, " %s [[-p] ] [-b] [-w] [-f] [-c ]|[-l ]|[-s ] [-i]\n", exec_name); + PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m]", exec_name); + PrintAndLogEx(NORMAL, " %s [[-p] ] [-b] [-w] [-f] [-c ]|[-l ]|[-s ] [-i]", exec_name); + PrintAndLogEx(NORMAL, " %s [-p] --flash [--unlock-bootloader] [--image ]+", exec_name); if (showFullHelp) { - PrintAndLogEx(NORMAL, "options:"); + PrintAndLogEx(NORMAL, "\nOptions in client mode:"); PrintAndLogEx(NORMAL, " -h/--help this help"); PrintAndLogEx(NORMAL, " -t/--text dump all interactive command's help at once"); PrintAndLogEx(NORMAL, " -m/--markdown dump all interactive help at once in markdown syntax"); @@ -296,21 +297,93 @@ static void show_help(bool showFullHelp, char *exec_name) { PrintAndLogEx(NORMAL, " -s/--script-file script file with one Proxmark3 command per line"); PrintAndLogEx(NORMAL, " -i/--interactive enter interactive mode after executing the script or the command"); PrintAndLogEx(NORMAL, " -v/--version print client version"); - PrintAndLogEx(NORMAL, "\nsamples:"); - PrintAndLogEx(NORMAL, " %s -h\n", exec_name); - PrintAndLogEx(NORMAL, " %s -m\n", exec_name); - PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -f -- flush output everytime\n", exec_name); - PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -w -- wait for serial port\n", exec_name); - PrintAndLogEx(NORMAL, "\n how to run Proxmark3 client\n"); - PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -- runs the pm3 client\n", exec_name); - PrintAndLogEx(NORMAL, " %s -- runs the pm3 client in OFFLINE mode\n", exec_name); - PrintAndLogEx(NORMAL, "\n how to execute different commands from terminal\n"); - PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -c \"hf mf chk 1* ?\" -- execute cmd and quit client\n", exec_name); - PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -l hf_read -- execute lua script " _YELLOW_("`hf_read`")"and quit client\n", exec_name); - PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -s mycmds.txt -- execute each pm3 cmd in file and quit client\n", exec_name); + PrintAndLogEx(NORMAL, "\nOptions in flasher mode:"); + PrintAndLogEx(NORMAL, " --flash flash Proxmark3, requires at least one --image"); + PrintAndLogEx(NORMAL, " --unlock-bootloader Enable flashing of bootloader area *DANGEROUS* (need --flash or --flash-info)"); + PrintAndLogEx(NORMAL, " --image image to flash. Can be specified several times."); + PrintAndLogEx(NORMAL, "\nExamples:"); + PrintAndLogEx(NORMAL, "\n to run Proxmark3 client:\n"); + PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -- runs the pm3 client", exec_name); + PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -f -- flush output everytime", exec_name); + PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -w -- wait for serial port", exec_name); + PrintAndLogEx(NORMAL, " %s -- runs the pm3 client in OFFLINE mode", exec_name); + PrintAndLogEx(NORMAL, "\n to execute different commands from terminal:\n"); + PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -c \"hf mf chk 1* ?\" -- execute cmd and quit client", exec_name); + PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -l hf_read -- execute lua script " _YELLOW_("`hf_read`")"and quit client", exec_name); + PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -s mycmds.txt -- execute each pm3 cmd in file and quit client", exec_name); + PrintAndLogEx(NORMAL, "\n to flash fullimage and bootloader:\n"); + PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" --flash --unlock-bootloader --image bootrom.elf --image fullimage.elf", exec_name); +#ifdef __linux__ + PrintAndLogEx(NORMAL, "\nNote (Linux):\nif the flasher gets stuck in 'Waiting for Proxmark3 to reappear on ',"); + PrintAndLogEx(NORMAL, "you need to blacklist Proxmark3 for modem-manager - see documentation for more details:"); + PrintAndLogEx(NORMAL, "* https://github.com/RfidResearchGroup/proxmark3/blob/master/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md"); + PrintAndLogEx(NORMAL, "\nMore info on flashing procedure from the official Proxmark3 wiki:"); + PrintAndLogEx(NORMAL, "* https://github.com/Proxmark/proxmark3/wiki/Gentoo%%20Linux"); + PrintAndLogEx(NORMAL, "* https://github.com/Proxmark/proxmark3/wiki/Ubuntu%%20Linux"); + PrintAndLogEx(NORMAL, "* https://github.com/Proxmark/proxmark3/wiki/OSX\n"); +#endif } } +static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[FLASH_MAX_FILES], bool can_write_bl) { + + int ret = PM3_EUNDEF; + flash_file_t files[FLASH_MAX_FILES]; + memset(files, 0, sizeof(files)); + + if (serial_port_name == NULL) { + PrintAndLogEx(ERR, "You must specify a port.\n"); + return PM3_EINVARG; + } + + if (OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) { + PrintAndLogEx(NORMAL, _GREEN_("Found")); + } else { + PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name); + return PM3_ETIMEOUT; + } + + uint32_t max_allowed = 0; + ret = flash_start_flashing(can_write_bl, serial_port_name, &max_allowed); + if (ret != PM3_SUCCESS) { + goto finish; + } + + if (num_files == 0) + goto finish; + + for (int i = 0 ; i < num_files; ++i) { + ret = flash_load(&files[i], filenames[i], can_write_bl, max_allowed * ONE_KB); + if (ret != PM3_SUCCESS) { + goto finish; + } + PrintAndLogEx(NORMAL, ""); + } + + PrintAndLogEx(SUCCESS, "\n" _BLUE_("Flashing...")); + + for (int i = 0; i < num_files; i++) { + ret = flash_write(&files[i]); + if (ret != PM3_SUCCESS) { + goto finish; + } + flash_free(&files[i]); + PrintAndLogEx(NORMAL, "\n"); + } + +finish: + ret = flash_stop_flashing(); + + CloseProxmark(); + + if (ret == PM3_SUCCESS) + PrintAndLogEx(SUCCESS, _BLUE_("All done.")); + else + PrintAndLogEx(ERR, "Aborted on error."); + PrintAndLogEx(NORMAL, "\nHave a nice day!"); + return ret; +} + int main(int argc, char *argv[]) { srand(time(0)); @@ -341,6 +414,11 @@ int main(int argc, char *argv[]) { } #endif + bool flash_mode = false; + bool flash_can_write_bl = false; + int flash_num_files = 0; + char *flash_filenames[FLASH_MAX_FILES]; + for (int i = 1; i < argc; i++) { if (argv[i][0] != '-') { @@ -467,6 +545,33 @@ int main(int argc, char *argv[]) { continue; } + // go to flash mode + if (strcmp(argv[i], "--flash") == 0) { + flash_mode = true; + continue; + } + + // unlock bootloader area + if (strcmp(argv[i], "--unlock-bootloader") == 0) { + flash_can_write_bl = true; + continue; + } + + // flash file + if (strcmp(argv[i], "--image") == 0) { + if (flash_num_files == FLASH_MAX_FILES) { + PrintAndLogEx(ERR, _RED_("ERROR:") "too many --image, please use it max %i times\n", FLASH_MAX_FILES); + return 1; + } + if (i + 1 == argc) { + PrintAndLogEx(ERR, _RED_("ERROR:") "missing image specification after --image\n"); + show_help(false, exec_name); + return 1; + } + flash_filenames[flash_num_files++] = argv[++i]; + continue; + } + // We got an unknown parameter PrintAndLogEx(ERR, _RED_("ERROR:") "invalid parameter: " _YELLOW_("%s") "\n", argv[i]); show_help(false, exec_name); @@ -487,13 +592,18 @@ int main(int argc, char *argv[]) { session.supports_colors = true; #endif // ascii art only in interactive client - if (!script_cmds_file && !script_cmd && session.stdinOnTTY && session.stdoutOnTTY) + if (!script_cmds_file && !script_cmd && session.stdinOnTTY && session.stdoutOnTTY && !flash_mode) showBanner(); // Let's take a baudrate ok for real UART, USB-CDC & BT don't use that info anyway if (speed == 0) speed = USART_BAUD_RATE; + if (flash_mode) { + flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl); + exit(EXIT_SUCCESS); + } + if (script_cmd) { while (script_cmd[strlen(script_cmd) - 1] == ' ') script_cmd[strlen(script_cmd) - 1] = 0x00; diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index ba6547cb2..6d6a1c48a 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -40,7 +40,7 @@ pm3-flash-all If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -proxmark3-flasher /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +pm3-flash /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf ``` > Depending on the firmware version your Proxmark3 can also appear as `/dev/tty.usbmodem881`. @@ -99,13 +99,13 @@ pm3-flash-all If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -proxmark3-flasher /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +pm3-flash /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/proxmark3-flasher /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/pm3-flash /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: diff --git a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md index c2c01f44f..7303bdb4b 100644 --- a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md +++ b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md @@ -121,7 +121,7 @@ In short: * unplug device * press button and keep it pressed (IMPORTANT) * plug in device -* run flash command `proxmark3-flasher /dev/ttyACM0 /usr/local/share/proxmark3/firmware/fullimage.elf` +* run flash command `pm3-flash /dev/ttyACM0 /usr/local/share/proxmark3/firmware/fullimage.elf` * wait until flash is finished * release button * un/plug device diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index e9ae8bce9..b7898fb97 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -23,7 +23,7 @@ Always use the latest repository commits from *master* branch. There are always Try using directly the client or flasher: ``` -client/proxmark3-flasher ... +client/pm3-flash ... client/proxmark3 ... ``` @@ -49,8 +49,8 @@ pm3-flash-fullimage ``` or ``` -proxmark3-flasher -b bootrom/obj/bootrom.elf -proxmark3-flasher armsrc/obj/fullimage.elf +pm3-flash -b bootrom/obj/bootrom.elf +pm3-flash armsrc/obj/fullimage.elf ``` ### Find out why it would be bricked @@ -71,7 +71,7 @@ pm3-flash-fullimage ``` or ``` -proxmark3-flasher armsrc/obj/fullimage.elf +pm3-flash armsrc/obj/fullimage.elf ``` You should be back on tracks now. In case the flasher complains about bootloader version, you can follow the button procedure and flash first your bootloader. @@ -81,7 +81,7 @@ pm3-flash-bootrom ``` or ``` -proxmark3-flasher -b bootrom/obj/bootrom.elf +pm3-flash -b bootrom/obj/bootrom.elf ``` ### Ok, my bootloader is definitively dead, now what? @@ -119,9 +119,9 @@ proxmark3 and you must adapt accordingly the file path of some commands, e.g. ``` -proxmark3-flasher /usr/local/share/proxmark3/firmware/fullimage.elf +pm3-flash /usr/local/share/proxmark3/firmware/fullimage.elf <> -proxmark3-flasher /usr/share/proxmark3/firmware/fullimage.elf +pm3-flash /usr/share/proxmark3/firmware/fullimage.elf pm3 --> sc upgrade f /usr/local/share/proxmark3/firmware/sim011.bin <> @@ -144,9 +144,9 @@ cd client; ./proxmark3 ... Therefore client commands referring to files of the repo must be adapted, e.g. ``` -client/proxmark3-flasher armsrc/obj/fullimage.elf +client/pm3-flash armsrc/obj/fullimage.elf <> -./proxmark3-flasher ../armsrc/obj/fullimage.elf +./pm3-flash ../armsrc/obj/fullimage.elf pm3 --> sc upgrade f tools/simmodule/sim011.bin <> diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 6a821a992..4f6bf99e8 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -54,7 +54,7 @@ pacman -S mingw-w64-x86_64-astyle Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). -To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `proxmark3-flasher.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. +To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `proxmark3.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. To flash: In principle, the helper script `pm3-flash-all` should auto-detect your COM port, so you can just try: @@ -65,13 +65,13 @@ pm3-flash-all If COM port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -proxmark3-flasher.exe comX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +pm3-flash comX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/proxmark3-flasher.exe comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/pm3-flash comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: @@ -156,13 +156,13 @@ pm3-flash-all If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -proxmark3-flasher.exe /dev/ttySX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +pm3-flash /dev/ttySX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/proxmark3-flasher.exe /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/pm3-flash /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: diff --git a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md index 7faa6a658..7ec483d0c 100644 --- a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md +++ b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md @@ -45,13 +45,13 @@ In most cases, you can run the script `pm3-flash-all` which try to auto-detect t For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: ```sh -proxmark3-flasher /dev/ttyACM0 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +pm3-flash /dev/ttyACM0 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/proxmark3-flasher /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/pm3-flash /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf ``` ## Run the client diff --git a/doc/path_notes.md b/doc/path_notes.md index bcdc19e33..556780f54 100644 --- a/doc/path_notes.md +++ b/doc/path_notes.md @@ -15,8 +15,8 @@ The main Proxmark3 executables / shellscripts will be copied to /usr/local/bin/ ``` -* executables: `proxmark3`, `proxmark3-flasher` -* scripts: `pm3`, `pm3-flash-all`, `pm3-flash-bootloader`, `pm3-flash-fullimage` +* executables: `proxmark3` +* scripts: `pm3`, `pm3-flash`, `pm3-flash-all`, `pm3-flash-bootloader`, `pm3-flash-fullimage` Some more executable / scripts will be copied to diff --git a/pm3 b/pm3 index 11eb59d31..705cd288e 100755 --- a/pm3 +++ b/pm3 @@ -4,19 +4,16 @@ PM3PATH=$(dirname "$0") # try pm3 dirs in current repo workdir if [ -d "$PM3PATH/client/" ]; then CLIENT="$PM3PATH/client/proxmark3" - FLASHER="$PM3PATH/client/proxmark3-flasher" FULLIMAGE="$PM3PATH/armsrc/obj/fullimage.elf" BOOTIMAGE="$PM3PATH/bootrom/obj/bootrom.elf" # try install dir elif [ -x "$PM3PATH/proxmark3" ]; then CLIENT="$PM3PATH/proxmark3" - FLASHER="$PM3PATH/proxmark3-flasher" FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf" BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf" else # hope it's installed somehow, still not sure where fw images are... CLIENT="proxmark3" - FLASHER="proxmark3-flasher" FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf" BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf" fi @@ -80,12 +77,26 @@ SCRIPT=$(basename -- "$0") if [ "$SCRIPT" = "pm3" ]; then CMD() { $CLIENT "$@"; } +elif [ "$SCRIPT" = "pm3-flash" ]; then + CMD() { + ARGS=("$1" "--flash") + shift; + while [ "$1" != "" ]; do + if [ "$1" == "-b" ]; then + ARGS+=("--unlock-bootloader") + else + ARGS+=("--image" "$1") + fi + shift; + done + $CLIENT ${ARGS[@]}; + } elif [ "$SCRIPT" = "pm3-flash-all" ]; then - CMD() { $FLASHER "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; } + CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; } elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then - CMD() { $FLASHER "$1" "$FULLIMAGE"; } + CMD() { $CLIENT "$1" "--flash" "--image" "$FULLIMAGE"; } elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then - CMD() { $FLASHER "$1" -b "$BOOTIMAGE"; } + CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; } else echo "[!!] Script ran under unknown name, abort: $SCRIPT" exit 1 diff --git a/pm3-flash b/pm3-flash new file mode 100755 index 000000000..e5cd5479d --- /dev/null +++ b/pm3-flash @@ -0,0 +1,4 @@ +#!/bin/bash + +PM3PATH=$(dirname "$0") +. "$PM3PATH/pm3" From 1a459d644de3e7f701bb6adf06fb549561b54953 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 01:54:59 +0200 Subject: [PATCH 295/347] fix flasher doc --- CHANGELOG.md | 1 + ...OS-X-Homebrew-Installation-Instructions.md | 6 ++--- .../ModemManager-Must-Be-Discarded.md | 2 +- .../Troubleshooting.md | 23 +++++++++---------- .../Windows-Installation-Instructions.md | 8 +++---- .../0_Compilation-Instructions.md | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb0e5c1d..2099db5fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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... ## [unreleased][unreleased] + - Chg proxmark3-flasher is now merged into proxmark3 client. Add pm3-flash (@doegox) - Chg `hf iclass clone\dump\rdbl\wrbl` - now uses NG (@iceman1001) - Fix `hf iclass clone` - last block always fails (@iceman1001) - Chg `hf iclass clone` - retries ten times, less output (honor verbose) (@iceman1001) diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 6d6a1c48a..85fb7f98f 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -40,7 +40,7 @@ pm3-flash-all If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -pm3-flash /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +proxmark3 /dev/tty.usbmodemiceman1 --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf ``` > Depending on the firmware version your Proxmark3 can also appear as `/dev/tty.usbmodem881`. @@ -99,13 +99,13 @@ pm3-flash-all If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -pm3-flash /dev/tty.usbmodemiceman1 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +proxmark3 /dev/tty.usbmodemiceman1 --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/pm3-flash /dev/tty.usbmodemiceman1 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3 /dev/tty.usbmodemiceman1 --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: diff --git a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md index 7303bdb4b..23ae480cc 100644 --- a/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md +++ b/doc/md/Installation_Instructions/ModemManager-Must-Be-Discarded.md @@ -121,7 +121,7 @@ In short: * unplug device * press button and keep it pressed (IMPORTANT) * plug in device -* run flash command `pm3-flash /dev/ttyACM0 /usr/local/share/proxmark3/firmware/fullimage.elf` +* run flash command `pm3-flash-fullimage` * wait until flash is finished * release button * un/plug device diff --git a/doc/md/Installation_Instructions/Troubleshooting.md b/doc/md/Installation_Instructions/Troubleshooting.md index b7898fb97..e0cf7f7aa 100644 --- a/doc/md/Installation_Instructions/Troubleshooting.md +++ b/doc/md/Installation_Instructions/Troubleshooting.md @@ -6,7 +6,7 @@ Always use the latest repository commits from *master* branch. There are always ## Table of Contents - * [pm3 or pm3-flash-* doesn't see my Proxmark](#pm3-or-pm3-flash-doesnt-see-my-proxmark) + * [pm3 or pm3-flash* doesn't see my Proxmark](#pm3-or-pm3-flash-doesnt-see-my-proxmark) * [My Proxmark3 seems bricked](#my-proxmark3-seems-bricked) * [Maybe just a false alarm?](#maybe-just-a-false-alarm) * [Find out why it would be bricked](#find-out-why-it-would-be-bricked) @@ -18,12 +18,11 @@ Always use the latest repository commits from *master* branch. There are always * [File not found](#file-not-found) * [pixmap / pixbuf warnings](#pixmap--pixbuf-warnings) -## `pm3` or `pm3-flash-*` doesn't see my Proxmark +## `pm3` or `pm3-flash*` doesn't see my Proxmark -Try using directly the client or flasher: +Try using directly the client: ``` -client/pm3-flash ... client/proxmark3 ... ``` @@ -49,8 +48,8 @@ pm3-flash-fullimage ``` or ``` -pm3-flash -b bootrom/obj/bootrom.elf -pm3-flash armsrc/obj/fullimage.elf +proxmark3 --flash --unlock-bootloader --image bootrom/obj/bootrom.elf +proxmark3 --flash --image armsrc/obj/fullimage.elf ``` ### Find out why it would be bricked @@ -71,7 +70,7 @@ pm3-flash-fullimage ``` or ``` -pm3-flash armsrc/obj/fullimage.elf +proxmark3 --flash --image armsrc/obj/fullimage.elf ``` You should be back on tracks now. In case the flasher complains about bootloader version, you can follow the button procedure and flash first your bootloader. @@ -81,7 +80,7 @@ pm3-flash-bootrom ``` or ``` -pm3-flash -b bootrom/obj/bootrom.elf +proxmark3 --flash --unlock-bootloader --image bootrom/obj/bootrom.elf ``` ### Ok, my bootloader is definitively dead, now what? @@ -119,9 +118,9 @@ proxmark3 and you must adapt accordingly the file path of some commands, e.g. ``` -pm3-flash /usr/local/share/proxmark3/firmware/fullimage.elf +proxmark3 --flash --image /usr/local/share/proxmark3/firmware/fullimage.elf <> -pm3-flash /usr/share/proxmark3/firmware/fullimage.elf +proxmark3 --flash --image /usr/share/proxmark3/firmware/fullimage.elf pm3 --> sc upgrade f /usr/local/share/proxmark3/firmware/sim011.bin <> @@ -144,9 +143,9 @@ cd client; ./proxmark3 ... Therefore client commands referring to files of the repo must be adapted, e.g. ``` -client/pm3-flash armsrc/obj/fullimage.elf +client/proxmark3 --flash --image armsrc/obj/fullimage.elf <> -./pm3-flash ../armsrc/obj/fullimage.elf +./proxmark3 --flash --image ../armsrc/obj/fullimage.elf pm3 --> sc upgrade f tools/simmodule/sim011.bin <> diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 4f6bf99e8..303a87d1e 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -65,13 +65,13 @@ pm3-flash-all If COM port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -pm3-flash comX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +proxmark3 comX --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/pm3-flash comX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3 comX --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: @@ -156,13 +156,13 @@ pm3-flash-all If port detection failed, you'll have to call the flasher manually and specify the correct port: ```sh -pm3-flash /dev/ttySX -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +proxmark3 /dev/ttySX --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/pm3-flash /dev/ttySX -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3 /dev/ttySX --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf ``` Similarly, to run the client, you may try: diff --git a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md index 7ec483d0c..dd2630f18 100644 --- a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md +++ b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md @@ -45,13 +45,13 @@ In most cases, you can run the script `pm3-flash-all` which try to auto-detect t For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: ```sh -pm3-flash /dev/ttyACM0 -b /usr/local/share/proxmark3/firmware/bootrom.elf /usr/local/share/proxmark3/firmware/fullimage.elf +proxmark3 /dev/ttyACM0 --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf ``` or from the local repo ```sh -client/pm3-flash /dev/ttyACM0 -b bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf +client/proxmark3 /dev/ttyACM0 --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf ``` ## Run the client From 936243a488cdd9b269ffa7d169683157ebd60a93 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 12:58:11 +0200 Subject: [PATCH 296/347] add -h to scripts --- pm3 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/pm3 b/pm3 index 705cd288e..90aec7eb8 100755 --- a/pm3 +++ b/pm3 @@ -1,5 +1,7 @@ #!/bin/bash +# Usage: run option -h to get help + PM3PATH=$(dirname "$0") # try pm3 dirs in current repo workdir if [ -d "$PM3PATH/client/" ]; then @@ -77,6 +79,22 @@ SCRIPT=$(basename -- "$0") if [ "$SCRIPT" = "pm3" ]; then CMD() { $CLIENT "$@"; } + HELP() { + cat << EOF +Quick helper script for proxmark3 client when working with a Proxmark device connected via USB + +Description: + The usage is the same as for the proxmark3 client, with the following differences: + * the correct port name will be automatically guessed; + * the script will wait for a Proxmark to be connected (same as option -w of the client). + Don't use this script if you want to work offline or with the BT addon. + +Usage: + $SCRIPT [-f] [-c ]|[-l ]|[-s ] [-i] + +See "$CLIENT -h" for more details on options. +EOF + } elif [ "$SCRIPT" = "pm3-flash" ]; then CMD() { ARGS=("$1" "--flash") @@ -91,16 +109,74 @@ elif [ "$SCRIPT" = "pm3-flash" ]; then done $CLIENT ${ARGS[@]}; } + HELP() { + cat << EOF +Quick helper script for flashing a Proxmark device via USB + +Description: + The usage is similar to the old proxmark3-flasher binary, except that the correct port name will be automatically guessed. + If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h". + +Usage: + $SCRIPT [-b] image.elf [image.elf...] + +Options: + -b Enable flashing of bootloader area (DANGEROUS) + +Example: + $SCRIPT -b bootloader.elf fullimage.elf +EOF + } elif [ "$SCRIPT" = "pm3-flash-all" ]; then CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; } + HELP() { + cat << EOF +Quick helper script for flashing a Proxmark device via USB + +Description: + The correct port name will be automatically guessed and the stock bootloader and firmware image will be flashed. + If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h". + +Usage: + $SCRIPT +EOF + } elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then CMD() { $CLIENT "$1" "--flash" "--image" "$FULLIMAGE"; } + HELP() { + cat << EOF +Quick helper script for flashing a Proxmark device via USB + +Description: + The correct port name will be automatically guessed and the stock firmware image will be flashed. + If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h". + +Usage: + $SCRIPT +EOF + } elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; } + HELP() { + cat << EOF +Quick helper script for flashing a Proxmark device via USB + +Description: + The correct port name will be automatically guessed and the stock bootloader will be flashed. + If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h". + +Usage: + $SCRIPT +EOF + } else echo "[!!] Script ran under unknown name, abort: $SCRIPT" exit 1 fi +if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + HELP + exit 0 +fi HOSTOS=$(uname | awk '{print toupper($0)}') if [ "$HOSTOS" = "LINUX" ]; then if uname -a|grep -q Microsoft; then From c918e0ab802cebee7ba75748744b6536ddcdc69c Mon Sep 17 00:00:00 2001 From: Iceman Date: Mon, 9 Sep 2019 13:15:55 +0200 Subject: [PATCH 297/347] chg: 'hf search' - feedback text (@wvzlad) --- client/cmdhf.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/cmdhf.c b/client/cmdhf.c index a6c5ea11e..8326d988f 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -76,18 +76,23 @@ int CmdHFSearch(const char *Cmd) { PrintAndLogEx(INFO, "Checking for known tags...\n"); + PrintAndLogEx(INPLACE, "Searching for ThinFilm tag..."); if (IfPm3NfcBarcode()) { if (infoThinFilm(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Thinfilm tag") " found\n"); return PM3_SUCCESS; } } + + PrintAndLogEx(INPLACE, "Searching for ISO14443-A tag..."); if (IfPm3Iso14443a()) { if (infoHF14A(false, false) > 0) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-A tag") " found\n"); return PM3_SUCCESS; } } + + PrintAndLogEx(INPLACE, "Searching for ISO15693 tag..."); if (IfPm3Iso15693()) { if (readHF15Uid(false) == 1) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO15693 tag") " found\n"); @@ -97,25 +102,33 @@ int CmdHFSearch(const char *Cmd) { // until refactoring of ISO15693 cmds, this is needed. DropField(); } + + PrintAndLogEx(INPLACE, "Searching for LEGIC tag..."); if (IfPm3Legicrf()) { if (readLegicUid(false) == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LEGIC tag") " found\n"); return PM3_SUCCESS; } } + + PrintAndLogEx(INPLACE, "Searching for Topaz tag..."); if (IfPm3Iso14443a()) { if (readTopazUid() == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n"); return PM3_SUCCESS; } } + // 14b and iclass is the longest test (put last) + PrintAndLogEx(INPLACE, "Searching for ISO14443-B tag..."); if (IfPm3Iso14443a()) { if (readHF14B(false) == 1) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-B tag") " found\n"); return PM3_SUCCESS; } } + + PrintAndLogEx(INPLACE, "Searching for iClass / PicoPass tag..."); if (IfPm3Iclass()) { if (readIclass(false, false) == 1) { PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("iClass tag / PicoPass tag") " found\n"); @@ -133,7 +146,7 @@ int CmdHFSearch(const char *Cmd) { //} - PrintAndLogEx(FAILED, "\nno known/supported 13.56 MHz tags found\n"); + PrintAndLogEx(FAILED, "\nNo known/supported 13.56 MHz tags found\n"); return PM3_ESOFT; } @@ -208,7 +221,7 @@ static command_t CommandTable[] = { {"thinfilm", CmdHFThinfilm, AlwaysAvailable, "{ Thinfilm RFIDs... }"}, {"list", CmdTraceList, AlwaysAvailable, "List protocol data in trace buffer"}, {"tune", CmdHFTune, IfPm3Present, "Continuously measure HF antenna tuning"}, - {"search", CmdHFSearch, AlwaysAvailable, "Search for known HF tags [preliminary]"}, + {"search", CmdHFSearch, AlwaysAvailable, "Search for known HF tags"}, {"sniff", CmdHFSniff, IfPm3Hfsniff, " Generic HF Sniff"}, {NULL, NULL, NULL, NULL} }; From 98189d6ef8e7140f4db762d0889e6ee41a18fbe0 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 13:24:45 +0200 Subject: [PATCH 298/347] typo --- pm3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pm3 b/pm3 index 90aec7eb8..d235a0f67 100755 --- a/pm3 +++ b/pm3 @@ -124,7 +124,7 @@ Options: -b Enable flashing of bootloader area (DANGEROUS) Example: - $SCRIPT -b bootloader.elf fullimage.elf + $SCRIPT -b bootrom.elf fullimage.elf EOF } elif [ "$SCRIPT" = "pm3-flash-all" ]; then From df40da13805038e9e0cb34ad8e9273dc27809346 Mon Sep 17 00:00:00 2001 From: Iceman Date: Mon, 9 Sep 2019 13:38:44 +0200 Subject: [PATCH 299/347] ignore bmptst (@wzvlad) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fda8c21af..348195eba 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ Makefile.platform !client/hardnested/*.bin !client/hardnested/tables/*.z client/ui/ui_overlays.h +client/reveng/bmptst hardnested_stats.txt proxmark3 From 7b773c571b08d9079972228103d5fd1d21c6a588 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Sep 2019 15:19:00 +0200 Subject: [PATCH 300/347] chg: 'lf t55xx dump p 11223344' - less verbose output. --- client/cmdlft55xx.c | 53 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 1431ca62a..55b711482 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -409,12 +409,12 @@ int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, uint8_t override, uin //Password mode if (usepwd) { // try reading the config block and verify that PWD bit is set before doing this! - if (!override) { + if (override == 0) { if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0, downlink_mode)) return PM3_ESOFT; if (!tryDetectModulation()) { PrintAndLogEx(NORMAL, "Safety Check: Could not detect if PWD bit is set in config block. Exits."); - return 0; + return PM3_ESOFT; } else { PrintAndLogEx(NORMAL, "Safety Check: PWD bit is NOT set in config block. Reading without password..."); usepwd = false; @@ -422,28 +422,31 @@ int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, uint8_t override, uin } } else { // Show only if first for command i.e. override = 1 (override and display) override = 2 (override and dont display) - if ((override & 2) != 2) + if (override == 1) PrintAndLogEx(NORMAL, "Safety Check Overriden - proceeding despite risk"); } } - if (!AquireData(page1, block, usepwd, password, downlink_mode)) return PM3_ESOFT; - if (!DecodeT55xxBlock()) return PM3_ESOFT; + if (!AquireData(page1, block, usepwd, password, downlink_mode)) + return PM3_ESOFT; + + if (!DecodeT55xxBlock()) + return PM3_ESOFT; printT55xxBlock(block); return PM3_SUCCESS; } static int CmdT55xxReadBlock(const char *Cmd) { - uint8_t block = REGULAR_READ_MODE_BLOCK; - uint32_t password = 0; //default to blank Block 7 - bool usepwd = false; - bool override = false; - bool page1 = false; - bool errors = false; - uint8_t cmdp = 0; - uint8_t downlink_mode = 0; + uint8_t block = REGULAR_READ_MODE_BLOCK; + uint8_t override = 0; + uint8_t cmdp = 0; + uint8_t downlink_mode = 0; + uint32_t password = 0; //default to blank Block 7 + bool usepwd = false; + bool page1 = false; + bool errors = false; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -454,7 +457,7 @@ static int CmdT55xxReadBlock(const char *Cmd) { cmdp += 2; break; case 'o': - override = true; + override = 1; cmdp++; break; case 'p': @@ -467,7 +470,6 @@ static int CmdT55xxReadBlock(const char *Cmd) { cmdp++; break; case 'r': - case 'R': downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; if (downlink_mode > 3) downlink_mode = 0; cmdp += 2; @@ -1653,26 +1655,27 @@ static int CmdT55xxInfo(const char *Cmd) { static int CmdT55xxDump(const char *Cmd) { - uint32_t password = 0; - uint8_t override = false; - uint8_t cmd_opt_idx = 0; - uint8_t downlink_mode = 0; - uint8_t pwd_offset = 0; - char cmdp = tolower(param_getchar(Cmd, 0)); - + uint32_t password = 0; + uint8_t override = 0; + uint8_t cmd_opt_idx = 0; + uint8_t downlink_mode = 0; + uint8_t pwd_offset = 0; + char cmdp = tolower(param_getchar(Cmd, 0)); if (cmdp == 'h') return usage_t55xx_dump(); if (cmdp == 'r') { cmd_opt_idx++; downlink_mode = param_getchar(Cmd, cmd_opt_idx++) - '0'; - if (downlink_mode > 3) downlink_mode = 0; + if (downlink_mode > 3) + downlink_mode = 0; + pwd_offset = 3; } bool usepwd = (strlen(Cmd) > pwd_offset); if (usepwd) { password = param_get32ex(Cmd, cmd_opt_idx++, 0, 16); if (param_getchar(Cmd, cmd_opt_idx++) == 'o') - override = true; + override = 1; } printT5xxHeader(0); @@ -1680,7 +1683,7 @@ static int CmdT55xxDump(const char *Cmd) { T55xxReadBlock(i, 0, usepwd, override, password, downlink_mode); // idea for better user experience and display. // only show override warning on the first block read - if (override) override |= 2; // flag not to show safty for 2nd and on. + if (override == 1) override++; // flag not to show safty for 2nd and on. } printT5xxHeader(1); for (uint8_t i = 0; i < 4; i++) From f7624a7767384297da03450007ff21d4dbbc14ea Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Sep 2019 17:33:44 +0200 Subject: [PATCH 301/347] textual --- client/cmdhficlass.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index c24853dcb..8b0c4ea35 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -2756,21 +2756,21 @@ static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"calcnewkey", CmdHFiClassCalcNewKey, AlwaysAvailable, "[options..] Calc diversified keys (blocks 3 & 4) to write new keys"}, {"chk", CmdHFiClassCheckKeys, AlwaysAvailable, "[options..] Check keys"}, - {"clone", CmdHFiClassCloneTag, IfPm3Iclass, "[options..] Clone (restore from tagdump file)"}, - {"decrypt", CmdHFiClassDecrypt, AlwaysAvailable, "[options..] Decrypt given block data or tagdump file" }, - {"dump", CmdHFiClassReader_Dump, IfPm3Iclass, "[options..] Authenticate and Dump iClass tag's AA1"}, - {"eload", CmdHFiClassELoad, IfPm3Iclass, "[f ] (experimental) Load data into iClass emulator memory"}, + {"clone", CmdHFiClassCloneTag, IfPm3Iclass, "[options..] Restore a dump file onto a iClass tag"}, + {"decrypt", CmdHFiClassDecrypt, AlwaysAvailable, "[options..] Decrypt given block data or tag dump file" }, + {"dump", CmdHFiClassReader_Dump, IfPm3Iclass, "[options..] Dump iClass tag to file"}, + {"eload", CmdHFiClassELoad, IfPm3Iclass, "[f ] Load iClass dump file into emulator memory"}, {"encrypt", CmdHFiClassEncryptBlk, AlwaysAvailable, "[options..] Encrypt given block data"}, {"info", CmdHFiClassInfo, AlwaysAvailable, " Tag information"}, {"list", CmdHFiClassList, AlwaysAvailable, " List iClass history"}, - {"loclass", CmdHFiClass_loclass, AlwaysAvailable, "[options..] Use loclass to perform bruteforce of reader attack dump"}, + {"loclass", CmdHFiClass_loclass, AlwaysAvailable, "[options..] Use loclass to perform bruteforce reader attack"}, {"lookup", CmdHFiClassLookUp, AlwaysAvailable, "[options..] Uses authentication trace to check for key in dictionary file"}, - {"managekeys", CmdHFiClassManageKeys, AlwaysAvailable, "[options..] Manage the keys to use with iClass"}, + {"managekeys", CmdHFiClassManageKeys, AlwaysAvailable, "[options..] Manage keys to use with iClass"}, {"permutekey", CmdHFiClassPermuteKey, IfPm3Iclass, " Permute function from 'heart of darkness' paper"}, {"rdbl", CmdHFiClass_ReadBlock, IfPm3Iclass, "[options..] Read iClass block"}, {"reader", CmdHFiClassReader, IfPm3Iclass, " Act like an iClass reader"}, - {"readtagfile", CmdHFiClassReadTagFile, AlwaysAvailable, "[options..] Display Content from tagfile"}, - {"replay", CmdHFiClassReader_Replay, IfPm3Iclass, " Read an iClass tag via Replay Attack"}, + {"readtagfile", CmdHFiClassReadTagFile, AlwaysAvailable, "[options..] Display content from tag dump file"}, + {"replay", CmdHFiClassReader_Replay, IfPm3Iclass, " Read iClass tag via replay attack"}, {"sim", CmdHFiClassSim, IfPm3Iclass, "[options..] Simulate iClass tag"}, {"sniff", CmdHFiClassSniff, IfPm3Iclass, " Eavesdrop iClass communication"}, {"wrbl", CmdHFiClass_WriteBlock, IfPm3Iclass, "[options..] Write iClass block"}, @@ -2812,7 +2812,7 @@ int readIclass(bool loop, bool verbose) { if (verbose) { PrintAndLogEx(FAILED, "Quitting..."); DropField(); - return 0; + return PM3_EOPABORTED; } } if (readStatus & FLAG_ICLASS_READER_CSN) { @@ -2841,7 +2841,7 @@ int readIclass(bool loop, bool verbose) { if (tagFound && !loop) { DropField(); - return 1; + return PM3_SUCCESS; } } else { if (verbose) From 6385ee960f4276bdac9755bce7c22744d2cf2527 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 19:55:27 +0200 Subject: [PATCH 302/347] searchFile for firmwares --- client/fileutils.c | 5 ++++- client/proxmark3.c | 40 +++++++++++++++++++++++++++++++++------- include/common.h | 3 +++ pm3 | 8 ++------ 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 9a5907882..f379f56d3 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -956,7 +956,10 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea } // try pm3 dirs in current repo workdir (dev mode) if ((exec_path != NULL) && - ((strcmp(TRACES_SUBDIR, pm3dir) == 0))) { + ((strcmp(TRACES_SUBDIR, pm3dir) == 0) || + (strcmp(FIRMWARES_SUBDIR, pm3dir) == 0) || + (strcmp(BOOTROM_SUBDIR, pm3dir) == 0) || + (strcmp(FULLIMAGE_SUBDIR, pm3dir) == 0))) { char *above = "../"; char *path = calloc(strlen(exec_path) + strlen(above) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) diff --git a/client/proxmark3.c b/client/proxmark3.c index 05afcc1fd..50f63ec51 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -330,17 +330,40 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[ int ret = PM3_EUNDEF; flash_file_t files[FLASH_MAX_FILES]; memset(files, 0, sizeof(files)); + char *filepaths[FLASH_MAX_FILES]; if (serial_port_name == NULL) { PrintAndLogEx(ERR, "You must specify a port.\n"); return PM3_EINVARG; } + for (int i = 0 ; i < num_files; ++i) { + char *path; + ret = searchFile(&path, FIRMWARES_SUBDIR, filenames[i], ".elf", true); + if (ret != PM3_SUCCESS) { + ret = searchFile(&path, BOOTROM_SUBDIR, filenames[i], ".elf", true); + } + if (ret != PM3_SUCCESS) { + // Last try, let the error msg be displayed if not found + ret = searchFile(&path, FULLIMAGE_SUBDIR, filenames[i], ".elf", false); + } + if (ret != PM3_SUCCESS) { + goto finish2; + } + filepaths[i] = path; + } + + PrintAndLogEx(SUCCESS, "About to use the following file%s:", num_files > 1 ? "s" : ""); + for (int i = 0 ; i < num_files; ++i) { + PrintAndLogEx(SUCCESS, " %s", filepaths[i]); + } + if (OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) { PrintAndLogEx(NORMAL, _GREEN_("Found")); } else { PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name); - return PM3_ETIMEOUT; + ret = PM3_ETIMEOUT; + goto finish2; } uint32_t max_allowed = 0; @@ -353,7 +376,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[ goto finish; for (int i = 0 ; i < num_files; ++i) { - ret = flash_load(&files[i], filenames[i], can_write_bl, max_allowed * ONE_KB); + ret = flash_load(&files[i], filepaths[i], can_write_bl, max_allowed * ONE_KB); if (ret != PM3_SUCCESS) { goto finish; } @@ -373,9 +396,12 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[ finish: ret = flash_stop_flashing(); - CloseProxmark(); - +finish2: + for (int i = 0 ; i < num_files; ++i) { + if (filepaths[i] != NULL) + free(filepaths[i]); + } if (ret == PM3_SUCCESS) PrintAndLogEx(SUCCESS, _BLUE_("All done.")); else @@ -599,6 +625,9 @@ int main(int argc, char *argv[]) { if (speed == 0) speed = USART_BAUD_RATE; + // set global variables + set_my_executable_path(); + if (flash_mode) { flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl); exit(EXIT_SUCCESS); @@ -629,9 +658,6 @@ int main(int argc, char *argv[]) { } } - // set global variables - set_my_executable_path(); - // try to open USB connection to Proxmark if (port != NULL) { OpenProxmark(port, waitCOMPort, 20, false, speed); diff --git a/include/common.h b/include/common.h index f13f5f99a..627846ff2 100644 --- a/include/common.h +++ b/include/common.h @@ -30,6 +30,9 @@ #define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP #define RESOURCES_SUBDIR "resources" PATHSEP #define TRACES_SUBDIR "traces" PATHSEP +#define FIRMWARES_SUBDIR "firmware" PATHSEP +#define BOOTROM_SUBDIR "bootrom/obj" PATHSEP +#define FULLIMAGE_SUBDIR "armsrc/obj" PATHSEP #define PACKED __attribute__((packed)) diff --git a/pm3 b/pm3 index d235a0f67..a740beb12 100755 --- a/pm3 +++ b/pm3 @@ -3,21 +3,17 @@ # Usage: run option -h to get help PM3PATH=$(dirname "$0") +FULLIMAGE="fullimage.elf" +BOOTIMAGE="bootrom.elf" # try pm3 dirs in current repo workdir if [ -d "$PM3PATH/client/" ]; then CLIENT="$PM3PATH/client/proxmark3" - FULLIMAGE="$PM3PATH/armsrc/obj/fullimage.elf" - BOOTIMAGE="$PM3PATH/bootrom/obj/bootrom.elf" # try install dir elif [ -x "$PM3PATH/proxmark3" ]; then CLIENT="$PM3PATH/proxmark3" - FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf" - BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf" else # hope it's installed somehow, still not sure where fw images are... CLIENT="proxmark3" - FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf" - BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf" fi function wait4proxmark_Linux { From 9f88580061ef3d29115d668d56d96b60b6182446 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 19:55:55 +0200 Subject: [PATCH 303/347] adapt flasher docs --- ...OS-X-Homebrew-Installation-Instructions.md | 43 +++-------- .../Windows-Installation-Instructions.md | 76 +++---------------- .../0_Compilation-Instructions.md | 24 ++++-- 3 files changed, 38 insertions(+), 105 deletions(-) diff --git a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md index 85fb7f98f..f78016df9 100644 --- a/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Mac-OS-X-Homebrew-Installation-Instructions.md @@ -84,39 +84,14 @@ brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc ## Compile and use the project +To use the compiled client, the only difference is that the Proxmark3 port is `/dev/tty.usbmodemiceman1`, so commands become: + +```sh +proxmark3 /dev/ttyACM0 => proxmark3 /dev/tty.usbmodemiceman1 +``` + Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). -To use the compiled client and flasher, the only difference is that the Proxmark3 port is `/dev/tty.usbmodemiceman1`. - -To flash: With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark3 as you plug it into a USB port. You can release the button, two of the four LEDs should stay on. You're un bootloader mode, ready for the next step. In case the two LEDs don't stay on when you're releasing the button, you've an old bootloader, start over and keep the button pressed during the whole flashing procedure. - -In principle, the helper script `pm3-flash-all` should auto-detect your port, so you can just try: - -```sh -pm3-flash-all -``` - -If port detection failed, you'll have to call the flasher manually and specify the correct port: - -```sh -proxmark3 /dev/tty.usbmodemiceman1 --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf -``` - -or from the local repo - -```sh -client/proxmark3 /dev/tty.usbmodemiceman1 --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf -``` - -Similarly, to run the client, you may try: - -```sh -pm3 -``` - -Or, by specifying the port manually: - -```sh -proxmark3 /dev/tty.usbmodemiceman1 -``` - +To flash on OS X, better to enter the bootloader mode manually, else you may experience errors. +With your Proxmark3 unplugged from your machine, press and hold the button on your Proxmark3 as you plug it into a USB port. You can release the button, two of the four LEDs should stay on. You're in bootloader mode, ready for the next step. In case the two LEDs don't stay on when you're releasing the button, you've an old bootloader, start over and keep the button pressed during the whole flashing procedure. +From there, you can follow the original compilation instructions. diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index 303a87d1e..9cd150a22 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -52,40 +52,14 @@ pacman -S mingw-w64-x86_64-astyle ## Compile and use the project +To use the compiled client, the only differences are that executables end with `.exe` (e.g. `proxmark3.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows, so commands become: + +```sh +proxmark3 /dev/ttyACM0 => proxmark3.exe comX +``` + Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). -To use the compiled client and flasher, the only differences are that executables end with `.exe` (e.g. `proxmark3.exe`) and that the Proxmark3 port is one of your `comX` ports where "X" is the com port number assigned to proxmark3 under Windows. - -To flash: In principle, the helper script `pm3-flash-all` should auto-detect your COM port, so you can just try: - -```sh -pm3-flash-all -``` - -If COM port detection failed, you'll have to call the flasher manually and specify the correct port: - -```sh -proxmark3 comX --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf -``` - -or from the local repo - -```sh -client/proxmark3 comX --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf -``` - -Similarly, to run the client, you may try: - -```sh -pm3 -``` - -Or, by specifying the COM port manually: - -```sh -proxmark3.exe comX -``` - # Installing on Windows with WSL It requires to run a Windows 10 version 1709 or above. Previous versions didn't have support for COM ports. @@ -118,9 +92,11 @@ git clone https://github.com/RfidResearchGroup/proxmark3.git ## Compile and use the project -Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). +To use the compiled client, the only difference is that the Proxmark3 port is translated from your `comX` port where "X" is the com port number assigned to proxmark3 under Windows, to a `/dev/ttySX`, so commands become: -To use the compiled client and flasher, the only difference is that the Proxmark3 port is translated from your `comX` port where "X" is the com port number assigned to proxmark3 under Windows, to a `/dev/ttySX`. +```sh +proxmark3 /dev/ttyACM0 => proxmark3 /dev/ttySX +``` Depending on the Windows version, you might need to give permission to the current user to access `/dev/ttySX`: (change X to your port number) @@ -147,34 +123,6 @@ and add it to your Bash profile for the next times: echo "export DISPLAY=:0" >> ~/.bashrc ``` -To flash: In principle, the helper script `pm3-flash-all` should auto-detect your COMX==/dev/ttySX port, so you can just try: - -```sh -pm3-flash-all -``` - -If port detection failed, you'll have to call the flasher manually and specify the correct port: - -```sh -proxmark3 /dev/ttySX --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf -``` - -or from the local repo - -```sh -client/proxmark3 /dev/ttySX --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf -``` - -Similarly, to run the client, you may try: - -```sh -pm3 -``` - -Or, by specifying the COM port manually: - -```sh -proxmark3 /dev/ttySX -``` - Note that it may take a quite long time for a freshly plugged Proxmark3 to be visible on a WSL /dev/ttySX port. + +Now you're ready to follow the [compilation instructions](/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md). diff --git a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md index dd2630f18..e423752ab 100644 --- a/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md +++ b/doc/md/Use_of_Proxmark/0_Compilation-Instructions.md @@ -40,18 +40,28 @@ e.g. calling `./pm3` or `client/proxmark3` instead of just `pm3` or `proxmark3`. ## Flash the BOOTROM & FULLIMAGE -In most cases, you can run the script `pm3-flash-all` which try to auto-detect the port to use, on several OS. - -For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: +In most cases, you can run the following script which try to auto-detect the port to use, on several OS: ```sh -proxmark3 /dev/ttyACM0 --flash --unlock-bootloader --image /usr/local/share/proxmark3/firmware/bootrom.elf --image /usr/local/share/proxmark3/firmware/fullimage.elf +pm3-flash-all ``` -or from the local repo +For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux (adjust the port for your OS): ```sh -client/proxmark3 /dev/ttyACM0 --flash --unlock-bootloader --image bootrom/obj/bootrom.elf --image armsrc/obj/fullimage.elf +proxmark3 /dev/ttyACM0 --flash --unlock-bootloader --image bootrom.elf --image fullimage.elf +``` + +The firmware files will be searched in the expected locations (installed files, working repo files, user folder, etc.). You can also specify their location: + +```sh +pm3-flash -b /tmp/my-bootrom.elf /tmp/my-fullimage.elf +``` + +or + +```sh +proxmark3 /dev/ttyACM0 --flash --unlock-bootloader --image /tmp/my-bootrom.elf --image /tmp/my-fullimage.elf ``` ## Run the client @@ -60,7 +70,7 @@ In most cases, you can run the script `pm3` which try to auto-detect the port to For the other cases, specify the port by yourself. For example, for a Proxmark3 connected via USB under Linux: -Here, for example, for a Proxmark3 connected via USB under Linux: +Here, for example, for a Proxmark3 connected via USB under Linux (adjust the port for your OS): ```sh proxmark3 /dev/ttyACM0 From d5d2c64d5025a1724016cfb93e692209cc74b8a3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 20:45:10 +0200 Subject: [PATCH 304/347] allow to set debugmode from cli options --- client/proxmark3.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 50f63ec51..f1a8bb05f 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -280,23 +280,26 @@ static void set_my_executable_path(void) { static void show_help(bool showFullHelp, char *exec_name) { PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m]", exec_name); - PrintAndLogEx(NORMAL, " %s [[-p] ] [-b] [-w] [-f] [-c ]|[-l ]|[-s ] [-i]", exec_name); - PrintAndLogEx(NORMAL, " %s [-p] --flash [--unlock-bootloader] [--image ]+", exec_name); + PrintAndLogEx(NORMAL, " %s [[-p] ] [-b] [-w] [-f] [-c ]|[-l ]|[-s ] [-i] [-d <0|1|2>]", exec_name); + PrintAndLogEx(NORMAL, " %s [-p] --flash [--unlock-bootloader] [--image ]+ [-w] [-f] [-d <0|1|2>]", exec_name); if (showFullHelp) { - PrintAndLogEx(NORMAL, "\nOptions in client mode:"); + + PrintAndLogEx(NORMAL, "\nCommon options:"); PrintAndLogEx(NORMAL, " -h/--help this help"); - PrintAndLogEx(NORMAL, " -t/--text dump all interactive command's help at once"); - PrintAndLogEx(NORMAL, " -m/--markdown dump all interactive help at once in markdown syntax"); + PrintAndLogEx(NORMAL, " -v/--version print client version"); PrintAndLogEx(NORMAL, " -p/--port serial port to connect to"); - PrintAndLogEx(NORMAL, " -b/--baud serial port speed (only needed for physical UART, not for USB-CDC or BT)"); PrintAndLogEx(NORMAL, " -w/--wait 20sec waiting the serial port to appear in the OS"); PrintAndLogEx(NORMAL, " -f/--flush output will be flushed after every print"); + PrintAndLogEx(NORMAL, " -d/--debug <0|1|2> set debugmode"); + PrintAndLogEx(NORMAL, "\nOptions in client mode:"); + PrintAndLogEx(NORMAL, " -t/--text dump all interactive command's help at once"); + PrintAndLogEx(NORMAL, " -m/--markdown dump all interactive help at once in markdown syntax"); + PrintAndLogEx(NORMAL, " -b/--baud serial port speed (only needed for physical UART, not for USB-CDC or BT)"); PrintAndLogEx(NORMAL, " -c/--command execute one Proxmark3 command (or several separated by ';')."); PrintAndLogEx(NORMAL, " -l/--lua execute lua script."); PrintAndLogEx(NORMAL, " -s/--script-file script file with one Proxmark3 command per line"); PrintAndLogEx(NORMAL, " -i/--interactive enter interactive mode after executing the script or the command"); - PrintAndLogEx(NORMAL, " -v/--version print client version"); PrintAndLogEx(NORMAL, "\nOptions in flasher mode:"); PrintAndLogEx(NORMAL, " --flash flash Proxmark3, requires at least one --image"); PrintAndLogEx(NORMAL, " --unlock-bootloader Enable flashing of bootloader area *DANGEROUS* (need --flash or --flash-info)"); @@ -494,12 +497,28 @@ int main(int argc, char *argv[]) { dumpAllHelp(1); return 0; } - // pritn client version + // print client version if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { pm3_version(true, true); return 0; } + // set debugmode + if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--debug") == 0) { + if (i + 1 == argc) { + PrintAndLogEx(ERR, _RED_("ERROR:") "missing debugmode specification after -d\n"); + show_help(false, exec_name); + return 1; + } + int demod = atoi(argv[i + 1]); + if (demod < 0 || demod > 2) { + PrintAndLogEx(ERR, _RED_("ERROR:") "invalid debugmode: -d " _YELLOW_("%s") "\n", argv[i + 1]); + return 1; + } + g_debugMode = demod; + i++; + continue; + } // flush output if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--flush") == 0) { From ba47ac36cbc65aeb669119889b67d4bb5e7de747 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 21:01:43 +0200 Subject: [PATCH 305/347] Do not log to history with -h/-t/-m --- client/proxmark3.c | 3 +++ client/ui.c | 4 ++-- client/util.c | 2 ++ client/util.h | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index f1a8bb05f..58b082078 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -481,12 +481,14 @@ int main(int argc, char *argv[]) { // short help if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { + g_disableLogging = true; show_help(true, exec_name); return 0; } // dump help if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--text") == 0) { + g_disableLogging = true; show_help(false, exec_name); dumpAllHelp(0); return 0; @@ -494,6 +496,7 @@ int main(int argc, char *argv[]) { // dump markup if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--markdown") == 0) { + g_disableLogging = true; dumpAllHelp(1); return 0; } diff --git a/client/ui.c b/client/ui.c index 68c8b197c..2055ab972 100644 --- a/client/ui.c +++ b/client/ui.c @@ -223,7 +223,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { // lock this section to avoid interlacing prints from different threads pthread_mutex_lock(&print_lock); - if (logging && !logfile) { + if (!g_disableLogging && logging && !logfile) { char *my_logfile_path = NULL; char filename[40]; struct tm *timenow; @@ -284,7 +284,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { } #endif - if (logging && logfile) { + if (!g_disableLogging && logging && logfile) { if (filter_ansi) { // already done fprintf(logfile, "%s\n", buffer2); } else { diff --git a/client/util.c b/client/util.c index 52321689b..2261684e9 100644 --- a/client/util.c +++ b/client/util.c @@ -28,6 +28,8 @@ #define UTIL_BUFFER_SIZE_SPRINT 4097 // global client debug variable uint8_t g_debugMode = 0; +// global client disable logging variable +bool g_disableLogging = false; #ifdef _WIN32 #include diff --git a/client/util.h b/client/util.h index 09aeeaecb..072c04cfb 100644 --- a/client/util.h +++ b/client/util.h @@ -22,6 +22,7 @@ #endif uint8_t g_debugMode; +bool g_disableLogging; int kbd_enter_pressed(void); void AddLogLine(const char *fn, const char *data, const char *c); From e10085bfe82c62eadcdf1776574ac6e64ffcf0c7 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 21:30:25 +0200 Subject: [PATCH 306/347] log interactive commands as well --- client/proxmark3.c | 21 ++++++++++++--------- client/ui.c | 12 +++++++----- client/util.c | 2 +- client/util.h | 4 +++- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 58b082078..dbca25d17 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -117,6 +117,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { // loops every time enter is pressed... while (1) { bool printprompt = false; + char *prompt = PROXPROMPT; // If there is a script file if (sf) { @@ -171,12 +172,12 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { rl_event_hook = check_comm; if (session.pm3_present) { if (conn.send_via_fpc_usart == false) - cmd = readline(PROXPROMPT_USB); + prompt = PROXPROMPT_USB; else - cmd = readline(PROXPROMPT_FPC); + prompt = PROXPROMPT_FPC; } else - cmd = readline(PROXPROMPT_OFFLINE); - + prompt = PROXPROMPT_OFFLINE; + cmd = readline(prompt); fflush(NULL); } } @@ -199,8 +200,10 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { cmd[strlen(cmd) - off] = '\0'; if (cmd[0] != '\0') { - if (printprompt) - PrintAndLogEx(NORMAL, PROXPROMPT"%s", cmd); + if (!printprompt) + g_printAndLog = PRINTANDLOG_LOG; + PrintAndLogEx(NORMAL, "%s%s", prompt, cmd); + g_printAndLog = PRINTANDLOG_PRINT | PRINTANDLOG_LOG; int ret = CommandReceived(cmd); @@ -481,14 +484,14 @@ int main(int argc, char *argv[]) { // short help if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - g_disableLogging = true; + g_printAndLog = PRINTANDLOG_PRINT; show_help(true, exec_name); return 0; } // dump help if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--text") == 0) { - g_disableLogging = true; + g_printAndLog = PRINTANDLOG_PRINT; show_help(false, exec_name); dumpAllHelp(0); return 0; @@ -496,7 +499,7 @@ int main(int argc, char *argv[]) { // dump markup if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--markdown") == 0) { - g_disableLogging = true; + g_printAndLog = PRINTANDLOG_PRINT; dumpAllHelp(1); return 0; } diff --git a/client/ui.c b/client/ui.c index 2055ab972..883ea963a 100644 --- a/client/ui.c +++ b/client/ui.c @@ -223,7 +223,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { // lock this section to avoid interlacing prints from different threads pthread_mutex_lock(&print_lock); - if (!g_disableLogging && logging && !logfile) { + if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) { char *my_logfile_path = NULL; char filename[40]; struct tm *timenow; @@ -269,9 +269,11 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { bool filter_ansi = !session.supports_colors; memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi); - fprintf(stream, "%s", buffer2); - fprintf(stream, " "); // cleaning prompt - fprintf(stream, "\n"); + if (g_printAndLog & PRINTANDLOG_PRINT) { + fprintf(stream, "%s", buffer2); + fprintf(stream, " "); // cleaning prompt + fprintf(stream, "\n"); + } #ifdef RL_STATE_READCMD // We are using GNU readline. libedit (OSX) doesn't support this flag. @@ -284,7 +286,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) { } #endif - if (!g_disableLogging && logging && logfile) { + if ((g_printAndLog & PRINTANDLOG_LOG) && logging && logfile) { if (filter_ansi) { // already done fprintf(logfile, "%s\n", buffer2); } else { diff --git a/client/util.c b/client/util.c index 2261684e9..1f5a29781 100644 --- a/client/util.c +++ b/client/util.c @@ -29,7 +29,7 @@ // global client debug variable uint8_t g_debugMode = 0; // global client disable logging variable -bool g_disableLogging = false; +uint8_t g_printAndLog = PRINTANDLOG_PRINT | PRINTANDLOG_LOG; #ifdef _WIN32 #include diff --git a/client/util.h b/client/util.h index 072c04cfb..7cfea0f8b 100644 --- a/client/util.h +++ b/client/util.h @@ -22,7 +22,9 @@ #endif uint8_t g_debugMode; -bool g_disableLogging; +uint8_t g_printAndLog; +#define PRINTANDLOG_PRINT 1 +#define PRINTANDLOG_LOG 2 int kbd_enter_pressed(void); void AddLogLine(const char *fn, const char *data, const char *c); From d08f03058bc9680cd39c427b8adac87aa0a44429 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 9 Sep 2019 23:46:38 +0200 Subject: [PATCH 307/347] add support for (nested) cmd scripts in script list/run --- client/cmdscript.c | 102 ++++++++++++++++++++++++++------------------- client/fileutils.c | 1 + client/proxmark3.c | 63 +++++++++++++++++++++------- client/proxmark3.h | 2 + 4 files changed, 111 insertions(+), 57 deletions(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index 473477228..a721acee5 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -33,7 +33,10 @@ static int CmdHelp(const char *Cmd); */ static int CmdScriptList(const char *Cmd) { (void)Cmd; // Cmd is not used so far - return searchAndList(LUA_SCRIPTS_SUBDIR, ".lua"); + int ret = searchAndList(LUA_SCRIPTS_SUBDIR, ".lua"); + if (ret != PM3_SUCCESS) + return ret; + return searchAndList(CMD_SCRIPTS_SUBDIR, ".cmd"); } /** @@ -43,21 +46,6 @@ static int CmdScriptList(const char *Cmd) { * @return */ static int CmdScriptRun(const char *Cmd) { - // create new Lua state - lua_State *lua_state; - lua_state = luaL_newstate(); - - // load Lua libraries - luaL_openlibs(lua_state); - - //Sets the pm3 core libraries, that go a bit 'under the hood' - set_pm3_libraries(lua_state); - - //Add the 'bin' library - set_bin_library(lua_state); - - //Add the 'bit' library - set_bit_library(lua_state); char preferredName[128] = {0}; char arguments[256] = {0}; @@ -67,37 +55,65 @@ static int CmdScriptRun(const char *Cmd) { sscanf(Cmd, "%127s%n %255[^\n\r]%n", preferredName, &name_len, arguments, &arg_len); char *script_path; - int res = searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua", false); - if (res != PM3_SUCCESS) - return res; + if ((!str_endswith(preferredName, ".cmd")) && (searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua", true) == PM3_SUCCESS)) { + int error; + PrintAndLogEx(SUCCESS, "Executing Lua script: %s, args '%s'\n", script_path, arguments); - int error; - PrintAndLogEx(SUCCESS, "Executing: %s, args '%s'\n", script_path, arguments); - error = luaL_loadfile(lua_state, script_path); - free(script_path); - if (!error) { - lua_pushstring(lua_state, arguments); - lua_setglobal(lua_state, "args"); + // create new Lua state + lua_State *lua_state; + lua_state = luaL_newstate(); - //Call it with 0 arguments - error = lua_pcall(lua_state, 0, LUA_MULTRET, 0); // once again, returns non-0 on error, + // load Lua libraries + luaL_openlibs(lua_state); + + //Sets the pm3 core libraries, that go a bit 'under the hood' + set_pm3_libraries(lua_state); + + //Add the 'bin' library + set_bin_library(lua_state); + + //Add the 'bit' library + set_bit_library(lua_state); + + error = luaL_loadfile(lua_state, script_path); + free(script_path); + if (!error) { + lua_pushstring(lua_state, arguments); + lua_setglobal(lua_state, "args"); + + //Call it with 0 arguments + error = lua_pcall(lua_state, 0, LUA_MULTRET, 0); // once again, returns non-0 on error, + } + if (error) { // if non-0, then an error + // the top of the stack should be the error string + if (!lua_isstring(lua_state, lua_gettop(lua_state))) + PrintAndLogEx(FAILED, "Error - but no error (?!)"); + + // get the top of the stack as the error and pop it off + const char *str = lua_tostring(lua_state, lua_gettop(lua_state)); + lua_pop(lua_state, 1); + puts(str); + } + + //luaL_dofile(lua_state, buf); + // close the Lua state + lua_close(lua_state); + PrintAndLogEx(SUCCESS, "\nFinished\n"); + return PM3_SUCCESS; } - if (error) { // if non-0, then an error - // the top of the stack should be the error string - if (!lua_isstring(lua_state, lua_gettop(lua_state))) - PrintAndLogEx(FAILED, "Error - but no error (?!)"); - - // get the top of the stack as the error and pop it off - const char *str = lua_tostring(lua_state, lua_gettop(lua_state)); - lua_pop(lua_state, 1); - puts(str); + if ((!str_endswith(preferredName, ".lua")) && (searchFile(&script_path, CMD_SCRIPTS_SUBDIR, preferredName, ".cmd", true) == PM3_SUCCESS)) { + PrintAndLogEx(SUCCESS, "Executing Cmd script: %s, args '%s'\n", script_path, arguments); + int ret = push_cmdscriptfile(script_path, true); + if (ret != PM3_SUCCESS) + PrintAndLogEx(ERR, "could not open " _YELLOW_("%s") "...", script_path); + free(script_path); + return ret; } - - //luaL_dofile(lua_state, buf); - // close the Lua state - lua_close(lua_state); - PrintAndLogEx(SUCCESS, "\nFinished\n"); - return 0; + // file not found, let's search again to display the error messages + int ret = PM3_EUNDEF; + if (!str_endswith(preferredName, ".cmd")) ret = searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua", false); + if (!str_endswith(preferredName, ".lua")) ret = searchFile(&script_path, CMD_SCRIPTS_SUBDIR, preferredName, ".cmd", false); + return ret; } static command_t CommandTable[] = { diff --git a/client/fileutils.c b/client/fileutils.c index f379f56d3..8e0e3bb72 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -933,6 +933,7 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea ((strcmp(DICTIONARIES_SUBDIR, pm3dir) == 0) || (strcmp(LUA_LIBRARIES_SUBDIR, pm3dir) == 0) || (strcmp(LUA_SCRIPTS_SUBDIR, pm3dir) == 0) || + (strcmp(CMD_SCRIPTS_SUBDIR, pm3dir) == 0) || (strcmp(RESOURCES_SUBDIR, pm3dir) == 0))) { char *path = calloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) diff --git a/client/proxmark3.c b/client/proxmark3.c index dbca25d17..aa37cda9a 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -63,6 +63,38 @@ int check_comm(void) { return 0; } +// first slot is always NULL, indicating absence of script when idx=0 +FILE *cmdscriptfile[MAX_NESTED_CMDSCRIPT + 1] = {0}; +uint8_t cmdscriptfile_idx = 0; +bool cmdscriptfile_stayafter = false; + +int push_cmdscriptfile(char *path, bool stayafter) { + if (cmdscriptfile_idx == MAX_NESTED_CMDSCRIPT) { + PrintAndLogEx(ERR, "Too many nested scripts, skipping %s\n", path); + return PM3_EMALLOC; + } + FILE *tmp = fopen(path, "r"); + if (tmp == NULL) + return PM3_EFILE; + if (cmdscriptfile_idx == 0) + cmdscriptfile_stayafter = stayafter; + cmdscriptfile[++cmdscriptfile_idx] = tmp; + return PM3_SUCCESS; +} + +FILE *current_cmdscriptfile() { + return cmdscriptfile[cmdscriptfile_idx]; +} + +bool pop_cmdscriptfile() { + fclose(cmdscriptfile[cmdscriptfile_idx]); + cmdscriptfile[cmdscriptfile_idx--] = NULL; + if (cmdscriptfile_idx == 0) + return cmdscriptfile_stayafter; + else + return true; +} + // Main thread of PM3 Client void #ifdef __has_attribute @@ -80,7 +112,6 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { strcreplace(script_cmd, script_cmd_len, ';', '\0'); } bool stdinOnPipe = !isatty(STDIN_FILENO); - FILE *sf = NULL; char script_cmd_buf[256] = {0x00}; // iceman, needs lua script the same file_path_buffer as the rest PrintAndLogEx(DEBUG, "ISATTY/STDIN_FILENO == %s\n", (stdinOnPipe) ? "true" : "false"); @@ -98,8 +129,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { char *path; int res = searchFile(&path, CMD_SCRIPTS_SUBDIR, script_cmds_file, ".cmd", false); if (res == PM3_SUCCESS) { - sf = fopen(path, "r"); - if (sf) + if (push_cmdscriptfile(path, stayInCommandLoop) == PM3_SUCCESS) PrintAndLogEx(SUCCESS, "executing commands from file: %s\n", path); else PrintAndLogEx(ERR, "could not open " _YELLOW_("%s") "...", path); @@ -119,16 +149,18 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { bool printprompt = false; char *prompt = PROXPROMPT; +check_script: // If there is a script file - if (sf) { + if (current_cmdscriptfile()) { // clear array memset(script_cmd_buf, 0, sizeof(script_cmd_buf)); // read script file - if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), sf)) { - fclose(sf); - sf = NULL; + if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), current_cmdscriptfile())) { + if (!pop_cmdscriptfile()) + break; + goto check_script; } else { // remove linebreaks @@ -205,12 +237,15 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { PrintAndLogEx(NORMAL, "%s%s", prompt, cmd); g_printAndLog = PRINTANDLOG_PRINT | PRINTANDLOG_LOG; + // add to history if not from a script + if (!current_cmdscriptfile()) { + HIST_ENTRY *entry = history_get(history_length); + // add if not identical to latest recorded cmd + if ((!entry) || (strcmp(entry->line, cmd) != 0)) + add_history(cmd); + } + // process cmd int ret = CommandReceived(cmd); - - HIST_ENTRY *entry = history_get(history_length); - if ((!entry) || (strcmp(entry->line, cmd) != 0)) - add_history(cmd); - // exit or quit if (ret == PM3_EFATAL) break; @@ -230,8 +265,8 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) { SendCommandNG(CMD_QUIT_SESSION, NULL, 0); msleep(100); // Make sure command is sent before killing client - if (sf) - fclose(sf); + while (current_cmdscriptfile()) + pop_cmdscriptfile(); if (my_history_path) { write_history(my_history_path); diff --git a/client/proxmark3.h b/client/proxmark3.h index 3da261c31..14148747c 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -20,11 +20,13 @@ #define PROXPROMPT_OFFLINE "[offline] pm3 --> " #define PROXHISTORY "history.txt" #define PROXLOG "log_%Y%m%d.txt" +#define MAX_NESTED_CMDSCRIPT 10 #ifdef __cplusplus extern "C" { #endif +int push_cmdscriptfile(char *path, bool stayafter); const char *get_my_executable_path(void); const char *get_my_executable_directory(void); void main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop); From 608e0ba27c7aae1f41a4d30c03cc1ea8474f7cd1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 10 Sep 2019 00:06:16 +0200 Subject: [PATCH 308/347] fix plot strange values --- client/proxguiqt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 344f48b03..6bf99f5a1 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -535,7 +535,7 @@ void Plot::paintEvent(QPaintEvent *event) { sprintf(str, "@%d dt=%d [%2.2f] zoom=%2.2f CursorAPos=%d CursorBPos=%d GridX=%d GridY=%d (%s) GridXoffset=%d", GraphStart, CursorBPos - CursorAPos, - (CursorBPos - CursorAPos) / CursorScaleFactor, + ((int32_t)(CursorBPos - CursorAPos)) / CursorScaleFactor, GraphPixelsPerPoint, CursorAPos, CursorBPos, From 843f554503a1fa1876964cc6da14c1626187cc4e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 10 Sep 2019 12:32:01 +0200 Subject: [PATCH 309/347] prevent lua bombs --- client/cmdscript.c | 9 ++++++++- client/proxmark3.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/client/cmdscript.c b/client/cmdscript.c index a721acee5..6d7858d54 100644 --- a/client/cmdscript.c +++ b/client/cmdscript.c @@ -52,12 +52,18 @@ static int CmdScriptRun(const char *Cmd) { int name_len = 0; int arg_len = 0; + static uint8_t luascriptfile_idx = 0; sscanf(Cmd, "%127s%n %255[^\n\r]%n", preferredName, &name_len, arguments, &arg_len); char *script_path; if ((!str_endswith(preferredName, ".cmd")) && (searchFile(&script_path, LUA_SCRIPTS_SUBDIR, preferredName, ".lua", true) == PM3_SUCCESS)) { int error; + if (luascriptfile_idx == MAX_NESTED_LUASCRIPT) { + PrintAndLogEx(ERR, "Too many nested scripts, skipping %s\n", script_path); + return PM3_EMALLOC; + } PrintAndLogEx(SUCCESS, "Executing Lua script: %s, args '%s'\n", script_path, arguments); + luascriptfile_idx++; // create new Lua state lua_State *lua_state; @@ -98,7 +104,8 @@ static int CmdScriptRun(const char *Cmd) { //luaL_dofile(lua_state, buf); // close the Lua state lua_close(lua_state); - PrintAndLogEx(SUCCESS, "\nFinished\n"); + luascriptfile_idx--; + PrintAndLogEx(SUCCESS, "\nFinished %s\n", preferredName); return PM3_SUCCESS; } if ((!str_endswith(preferredName, ".lua")) && (searchFile(&script_path, CMD_SCRIPTS_SUBDIR, preferredName, ".cmd", true) == PM3_SUCCESS)) { diff --git a/client/proxmark3.h b/client/proxmark3.h index 14148747c..c370efdff 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -21,6 +21,7 @@ #define PROXHISTORY "history.txt" #define PROXLOG "log_%Y%m%d.txt" #define MAX_NESTED_CMDSCRIPT 10 +#define MAX_NESTED_LUASCRIPT 10 #ifdef __cplusplus extern "C" { From 1966e23e4d1bc36663cc81c9fd5fe23d8c6c7e38 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 11 Sep 2019 00:51:29 +0300 Subject: [PATCH 310/347] Fix vscode tasks --- .vscode/tasks.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ca3660980..20b68be0e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -14,13 +14,13 @@ { "label": "flash fullimage", "type": "shell", - "command": "./flash-fullimage.sh", + "command": "sudo ./pm3-flash-fullimage", "problemMatcher": [] }, { "label": "FLASH BOOTROM", "type": "shell", - "command": "./flash-bootrom.sh", + "command": "sudo ./pm3-flash-bootrom", "problemMatcher": [] } ] From 341703d9a7de1fa81177e75f8ffe241214908cfc Mon Sep 17 00:00:00 2001 From: Iceman Date: Wed, 11 Sep 2019 13:09:08 +0200 Subject: [PATCH 311/347] chg: 'hf iclass sim' - better iClass protocol implementation --- armsrc/iclass.c | 56 +++++++++++++++++++++++---------------------- client/cmdhflist.c | 55 ++++++++++++++++++++++++++------------------ include/protocols.h | 27 +++++++++++----------- 3 files changed, 75 insertions(+), 63 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index c87bade4b..08f05857b 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -1435,6 +1435,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { uint32_t r2t_stime, r2t_etime = 0; LED_A_ON(); bool buttonPressed = false; + uint8_t cmd, options, block; while (!exitLoop) { WDT_HIT(); @@ -1455,7 +1456,11 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { LED_C_ON(); //Signal tracer - if (receivedCmd[0] == ICLASS_CMD_ACTALL) { // 0x0A + cmd = receivedCmd[0] & 0xF; + options = (receivedCmd[0] >> 4) & 0xFF; + block = receivedCmd[1]; + + if (cmd == ICLASS_CMD_ACTALL) { // 0x0A // Reader in anticollission phase modulated_response = resp_sof; modulated_response_size = resp_sof_Len; //order = 1; @@ -1463,7 +1468,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { trace_data_size = sizeof(sof_data); // adjusted for 330 + (160*num of slot) goto send; - } else if (receivedCmd[0] == ICLASS_CMD_READ_OR_IDENTIFY) { // 0x0C + } else if (cmd == ICLASS_CMD_READ_OR_IDENTIFY) { // 0x0C if (len == 1) { // Reader asks for anticollission CSN modulated_response = resp_anticoll; @@ -1475,7 +1480,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { if (len == 4) { // block0,1,2,5 is always readable. - switch (receivedCmd[1]) { + switch (block) { case 0: // csn (0c 00) modulated_response = resp_csn; modulated_response_size = resp_csn_len; @@ -1508,7 +1513,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { if (simulationMode == MODE_FULLSIM) { // 0x0C //Read block //Take the data... - memcpy(data_generic_trace, emulator + (receivedCmd[1] << 3), 8); + memcpy(data_generic_trace, emulator + (block << 3), 8); AddCrc(data_generic_trace, 8); trace_data = data_generic_trace; trace_data_size = 10; @@ -1521,7 +1526,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { } }//swith }// if 4 - } else if (receivedCmd[0] == ICLASS_CMD_SELECT) { // 0x81 + } else if (cmd == ICLASS_CMD_SELECT) { // 0x81 // Reader selects anticollission CSN. // Tag sends the corresponding real CSN modulated_response = resp_csn; @@ -1529,23 +1534,15 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { trace_data = csn_data; trace_data_size = sizeof(csn_data); goto send; - } else if (receivedCmd[0] == ICLASS_CMD_READCHECK_KD) { // 0x88 - // Read e-purse (88 02) + } else if (cmd == ICLASS_CMD_READCHECK ) { // 0x88 + // Read e-purse KD (88 02) KC (18 02) modulated_response = resp_cc; modulated_response_size = resp_cc_len; //order = 4; trace_data = card_challenge_data; trace_data_size = sizeof(card_challenge_data); LED_B_ON(); goto send; - } else if (receivedCmd[0] == ICLASS_CMD_READCHECK_KC) { // 0x18 - // Read e-purse (18 02) - modulated_response = resp_cc; - modulated_response_size = resp_cc_len; //order = 4; - trace_data = card_challenge_data; - trace_data_size = sizeof(card_challenge_data); - LED_B_ON(); - goto send; - } else if (receivedCmd[0] == ICLASS_CMD_CHECK) { // 0x05 + } else if (cmd == ICLASS_CMD_CHECK) { // 0x05 // Reader random and reader MAC!!! if (simulationMode == MODE_FULLSIM) { // NR, from reader, is in receivedCmd +1 @@ -1583,17 +1580,17 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { } } goto send; - } else if (receivedCmd[0] == ICLASS_CMD_HALT && len == 1) { + } else if (cmd == ICLASS_CMD_HALT && options == 0 && len == 1) { // Reader ends the session modulated_response = resp_sof; modulated_response_size = 0; //order = 0; trace_data = NULL; trace_data_size = 0; goto send; - } else if (simulationMode == MODE_FULLSIM && receivedCmd[0] == ICLASS_CMD_READ4 && len == 4) { // 0x06 + } else if (simulationMode == MODE_FULLSIM && cmd == ICLASS_CMD_READ4 && len == 4) { // 0x06 //Read block //Take the data... - memcpy(data_generic_trace, emulator + (receivedCmd[1] << 3), 8 * 4); + memcpy(data_generic_trace, emulator + (block << 3), 8 * 4); AddCrc(data_generic_trace, 8 * 4); trace_data = data_generic_trace; trace_data_size = 34; @@ -1601,7 +1598,7 @@ int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) { memcpy(modulated_response, ToSend, ToSendMax); modulated_response_size = ToSendMax; goto send; - } else if (simulationMode == MODE_FULLSIM && receivedCmd[0] == ICLASS_CMD_UPDATE) { + } else if (simulationMode == MODE_FULLSIM && cmd == ICLASS_CMD_UPDATE) { //Probably the reader wants to update the nonce. Let's just ignore that for now. // OBS! If this is implemented, don't forget to regenerate the cipher_state @@ -1854,6 +1851,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, SpinDelayUs(g_wait); //310 Tout= 330us (iso15603-2) (330/21.3) take consideration for clock increments. uint32_t foo = GetCountSspClk(); + uint32_t bar; // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; @@ -1892,7 +1890,11 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, return true; } - if (GetCountSspClk() - foo > timeout) return false; + bar = GetCountSspClk(); + if ( foo > bar ) + bar += ( UINT32_MAX - foo ); + + if (bar - foo > timeout) return false; } } @@ -1985,10 +1987,10 @@ uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) { static uint8_t act_all[] = { ICLASS_CMD_ACTALL }; static uint8_t identify[] = { ICLASS_CMD_READ_OR_IDENTIFY, 0x00, 0x73, 0x33 }; static uint8_t select[] = { ICLASS_CMD_SELECT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - uint8_t readcheck_cc[] = { ICLASS_CMD_READCHECK_KD, 0x02 }; + uint8_t readcheck_cc[] = { ICLASS_CMD_READCHECK, 0x02 }; - if (use_credit_key) - readcheck_cc[0] = ICLASS_CMD_READCHECK_KC; + if (use_credit_key == false) + readcheck_cc[0] |= 0x10; uint8_t resp[ICLASS_BUFFER_SIZE] = {0}; uint8_t read_status = 0; @@ -2353,10 +2355,10 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { uint8_t keyCount = arg1 & 0xFF; uint8_t check[] = { ICLASS_CMD_CHECK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t resp[ICLASS_BUFFER_SIZE]; - uint8_t readcheck_cc[] = { ICLASS_CMD_READCHECK_KD, 0x02 }; + uint8_t readcheck_cc[] = { ICLASS_CMD_READCHECK, 0x02 }; - if (use_credit_key) - readcheck_cc[0] = ICLASS_CMD_READCHECK_KC; + if (use_credit_key == false) + readcheck_cc[0] |= 0x10; // select card / e-purse uint8_t card_data[6 * 8] = {0}; diff --git a/client/cmdhflist.c b/client/cmdhflist.c index 5a2ff5248..d0fcea8f5 100644 --- a/client/cmdhflist.c +++ b/client/cmdhflist.c @@ -323,10 +323,35 @@ void annotateIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { } void annotateIclass(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { - switch (cmd[0]) { + uint8_t c = cmd[0] & 0x0F; + uint8_t parity = 0; + for ( uint8_t i=0; i<7; i++) { + parity ^= (cmd[0] >> i) & 1; + } + + if ( parity == ((cmd[0] >> 7) & 1) ) { + printf("Calc %d, cmd %02x, Par %d \n", parity, cmd[0], (cmd[0] >> 7) & 1); + } + + switch (c) { + case ICLASS_CMD_HALT: + snprintf(exp, size, "HALT"); + break; + case ICLASS_CMD_SELECT: + snprintf(exp, size, "SELECT"); + break; case ICLASS_CMD_ACTALL: snprintf(exp, size, "ACTALL"); break; + case ICLASS_CMD_DETECT: + snprintf(exp, size, "DETECT"); + break; + case ICLASS_CMD_CHECK: + snprintf(exp, size, "CHECK"); + break; + case ICLASS_CMD_READ4: + snprintf(exp, size, "READ4(%d)", cmd[1]); + break; case ICLASS_CMD_READ_OR_IDENTIFY: { if (cmdsize > 1) { snprintf(exp, size, "READ(%d)", cmd[1]); @@ -335,36 +360,22 @@ void annotateIclass(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { } break; } - case ICLASS_CMD_SELECT: - snprintf(exp, size, "SELECT"); - break; case ICLASS_CMD_PAGESEL: snprintf(exp, size, "PAGESEL(%d)", cmd[1]); break; - case ICLASS_CMD_READCHECK_KC: - snprintf(exp, size, "READCHECK[Kc](%d)", cmd[1]); - break; - case ICLASS_CMD_READCHECK_KD: - snprintf(exp, size, "READCHECK[Kd](%d)", cmd[1]); - break; - case ICLASS_CMD_CHECK: - snprintf(exp, size, "CHECK"); - break; - case ICLASS_CMD_DETECT: - snprintf(exp, size, "DETECT"); - break; - case ICLASS_CMD_HALT: - snprintf(exp, size, "HALT"); - break; case ICLASS_CMD_UPDATE: snprintf(exp, size, "UPDATE(%d)", cmd[1]); break; + case ICLASS_CMD_READCHECK: + if ( ICLASS_CREDIT(c) ) { + snprintf(exp, size, "READCHECK[Kc](%d)", cmd[1]); + } else { + snprintf(exp, size, "READCHECK[Kd](%d)", cmd[1]); + } + break; case ICLASS_CMD_ACT: snprintf(exp, size, "ACT"); break; - case ICLASS_CMD_READ4: - snprintf(exp, size, "READ4(%d)", cmd[1]); - break; default: snprintf(exp, size, "?"); break; diff --git a/include/protocols.h b/include/protocols.h index cb38d9c84..9b47266c3 100644 --- a/include/protocols.h +++ b/include/protocols.h @@ -120,22 +120,21 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. // for instance ICLASS_CMD_SELECT 0x81 tells if ISO14443b/BPSK coding/106 kbits/s // for instance ICLASS_CMD_SELECT 0x41 tells if ISO14443b/BPSK coding/423 kbits/s // -#define ICLASS_CMD_HALT 0x00 -#define ICLASS_CMD_SELECT_15 0x01 -#define ICLASS_CMD_ACTALL 0x0A -#define ICLASS_CMD_DETECT 0x0F +#define ICLASS_CMD_HALT 0x0 +#define ICLASS_CMD_SELECT 0x1 +#define ICLASS_CMD_ACTALL 0xA +#define ICLASS_CMD_DETECT 0xF -#define ICLASS_CMD_CHECK 0x05 -#define ICLASS_CMD_READ4 0x06 -#define ICLASS_CMD_READ_OR_IDENTIFY 0x0C - -#define ICLASS_CMD_SELECT 0x81 -#define ICLASS_CMD_PAGESEL 0x84 -#define ICLASS_CMD_UPDATE 0x87 -#define ICLASS_CMD_READCHECK_KC 0x18 -#define ICLASS_CMD_READCHECK_KD 0x88 -#define ICLASS_CMD_ACT 0x8E +#define ICLASS_CMD_PAGESEL 0x4 +#define ICLASS_CMD_CHECK 0x5 +#define ICLASS_CMD_READ4 0x6 +#define ICLASS_CMD_UPDATE 0x7 +#define ICLASS_CMD_READCHECK 0x8 +#define ICLASS_CMD_READ_OR_IDENTIFY 0xC +#define ICLASS_CMD_ACT 0xE +#define ICLASS_CREDIT(x) (((x) & 0x5) == 1) +#define ICLASS_DEBIT(x) (((x) & 0x5) == 0) #define ISO14443A_CMD_REQA 0x26 From 387dd82895dc427e11d6176b643b7a04c4b71765 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 14:03:14 +0200 Subject: [PATCH 312/347] chg 'hf iclass list' - fix parity checks --- client/cmdhflist.c | 4 ---- client/cmdtrace.c | 14 +++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/client/cmdhflist.c b/client/cmdhflist.c index d0fcea8f5..d44ac635c 100644 --- a/client/cmdhflist.c +++ b/client/cmdhflist.c @@ -329,10 +329,6 @@ void annotateIclass(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) { parity ^= (cmd[0] >> i) & 1; } - if ( parity == ((cmd[0] >> 7) & 1) ) { - printf("Calc %d, cmd %02x, Par %d \n", parity, cmd[0], (cmd[0] >> 7) & 1); - } - switch (c) { case ICLASS_CMD_HALT: snprintf(exp, size, "HALT"); diff --git a/client/cmdtrace.c b/client/cmdtrace.c index ecb3fc158..401dac66e 100644 --- a/client/cmdtrace.c +++ b/client/cmdtrace.c @@ -294,6 +294,8 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr uint8_t parityBits = parityBytes[j >> 3]; if (protocol != LEGIC && protocol != ISO_14443B + && protocol != ISO_15693 + && protocol != ICLASS && protocol != ISO_7816_4 && protocol != PROTO_HITAG && protocol != THINFILM @@ -301,7 +303,17 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr && (oddparity8(frame[j]) != ((parityBits >> (7 - (j & 0x0007))) & 0x01))) { snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]); - } else { + } else if ( protocol == ICLASS && isResponse == true) { + uint8_t parity = 0; + for (int i=0; i<6; i++) { + parity ^= ((frame[0] >> i) & 1); + } + if ( parity == ((frame[0] >> 7) & 1)) { + snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x ", frame[j]); + } else { + snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]); + } + } else { snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x ", frame[j]); } From df2c294cac9e4e9edae5ac0fd77b04561bd60960 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 15:15:13 +0200 Subject: [PATCH 313/347] chg - cleaning out testcode... --- armsrc/iso14443a.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 786db50dc..794ead3c5 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -1672,26 +1672,11 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing // clear TXRDY AT91C_BASE_SSC->SSC_THR = SEC_Y; - volatile uint8_t b; uint16_t c = 0; - uint32_t sendtimer = GetTickCount(); - uint32_t cntr = 0; while (c < len) { if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { - AT91C_BASE_SSC->SSC_THR = cmd[c++]; - cntr = 0; - } else { - if (cntr++ > 1000) { - cntr = 0; - if (GetTickCount() - sendtimer > 100) - break; - } - } - - //iceman test - if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { - b = (uint16_t)(AT91C_BASE_SSC->SSC_RHR); - (void)b; + AT91C_BASE_SSC->SSC_THR = cmd[c]; + c++; } } From ff66ea896b11893b1b05f0e8498c1db92ea6630b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 15:16:20 +0200 Subject: [PATCH 314/347] ssp clock delta --- armsrc/ticks.c | 7 +++++++ armsrc/ticks.h | 1 + 2 files changed, 8 insertions(+) diff --git a/armsrc/ticks.c b/armsrc/ticks.c index 43555b21b..1510de490 100644 --- a/armsrc/ticks.c +++ b/armsrc/ticks.c @@ -185,6 +185,13 @@ uint32_t RAMFUNC GetCountSspClk(void) { return tmp_count; } +uint32_t RAMFUNC GetCountSspClkDelta(uint32_t start) { + uint32_t stop = GetCountSspClk(); + if ( stop >= start ) + return stop - start; + return (UINT32_MAX - start) + stop; +} + // ------------------------------------------------------------------------- // Timer for bitbanging, or LF stuff when you need a very precis timer // 1us = 1.5ticks diff --git a/armsrc/ticks.h b/armsrc/ticks.h index 089501c87..e036e018c 100644 --- a/armsrc/ticks.h +++ b/armsrc/ticks.h @@ -33,6 +33,7 @@ void SpinDelayCountUs(uint32_t us); void StartCountSspClk(); void ResetSspClk(void); uint32_t RAMFUNC GetCountSspClk(); +uint32_t RAMFUNC GetCountSspClkDelta(); void StartTicks(void); uint32_t GetTicks(void); From 105665ed0acf5abbcfd52e83d58ca08e291ce9b4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 15:18:40 +0200 Subject: [PATCH 315/347] chg: iclass.. cleaning out test/unused code.\n 'hf iclass sim' - Try LUT table --- armsrc/iclass.c | 70 ++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 08f05857b..0f572cae3 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -55,7 +55,7 @@ #include "protocols.h" #include "ticks.h" -static int g_wait = 300; +static int g_wait = 270; static int timeout = 5000; static uint32_t time_rdr = 0; static uint32_t time_response = 0; @@ -1054,6 +1054,7 @@ static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen) return false; } +/* static uint8_t encode4Bits(const uint8_t b) { // OTA, the least significant bits first // Manchester encoding added @@ -1100,6 +1101,9 @@ static uint8_t encode4Bits(const uint8_t b) { return 0xaa; // 0000 -> 0000 -> 10101010 -> 0xaa } } +*/ + +static uint8_t lut_enc[] = { 0xAA, 0x6A, 0x9A, 0x5A, 0xA6, 0x66, 0x96, 0x56, 0xA9, 0x69, 0x99, 0x59, 0xA5, 0x65, 0x95, 0x55 }; //----------------------------------------------------------------------------- // Prepare tag messages @@ -1146,8 +1150,8 @@ static void CodeIClassTagAnswer(const uint8_t *cmd, int len) { int i; for (i = 0; i < len; i++) { uint8_t b = cmd[i]; - ToSend[++ToSendMax] = encode4Bits(b & 0xF); // least significant half - ToSend[++ToSendMax] = encode4Bits((b >> 4) & 0xF); // most significant half + ToSend[++ToSendMax] = lut_enc[b & 0xF]; // least significant half + ToSend[++ToSendMax] = lut_enc[(b >> 4) & 0xF]; // most significant half } // Send EOF @@ -1642,7 +1646,7 @@ send: A legit tag has about 330us delay between reader EOT and tag SOF. **/ if (modulated_response_size > 0) { - t2r_stime = (GetCountSspClk() - time_0) << 4; + t2r_stime = GetCountSspClkDelta(time_0) << 4; SendIClassAnswer(modulated_response, modulated_response_size, 0); t2r_etime = ((GetCountSspClk() - time_0) << 4) - t2r_stime; } @@ -1722,6 +1726,7 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int time_rdr = 0; FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD); + AT91C_BASE_SSC->SSC_THR = 0x00; // make sure we timeout previous comms. @@ -1762,13 +1767,6 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int } time_rdr = GetCountSspClk(); - - if (samples) { - if (wait) - *samples = (c + *wait) << 3; - else - *samples = c << 3; - } } //----------------------------------------------------------------------------- @@ -1819,15 +1817,14 @@ void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) { // Select the card TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait); - if (trigger) - LED_A_ON(); + LED_A_ON(); rsamples += samples; LogTrace(frame, len, rsamples, rsamples, NULL, true); } void ReaderTransmitIClass(uint8_t *frame, int len) { - ReaderTransmitIClass_ext(frame, len, 330); + ReaderTransmitIClass_ext(frame, len, 400); } //----------------------------------------------------------------------------- @@ -1835,23 +1832,21 @@ void ReaderTransmitIClass(uint8_t *frame, int len) { // If a response is captured return TRUE // If it takes too long return FALSE //----------------------------------------------------------------------------- -static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *wait) { +static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *wait) { // buffer needs to be 512 bytes // maxLen is not used... - - int c = 0; bool skip = false; - // Setup UART/DEMOD to receive - DemodIcInit(receivedResponse); + LED_D_ON(); // Set FPGA mode to "reader listen mode", no modulation (listen // only, since we are receiving, not transmitting). FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_LISTEN); + // Setup UART/DEMOD to receive + DemodIcInit(receivedResponse); + SpinDelayUs(g_wait); //310 Tout= 330us (iso15603-2) (330/21.3) take consideration for clock increments. - uint32_t foo = GetCountSspClk(); - uint32_t bar; // clear RXRDY: uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; @@ -1859,61 +1854,42 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, uint16_t checked = 0; + uint32_t card_start = GetCountSspClk(); for (;;) { WDT_HIT(); - if (checked == 1000) { + if (checked == 2000) { if (BUTTON_PRESS() || data_available()) return false; checked = 0; - } else { - checked++; - } - - // keep tx buffer in a defined state anyway. - if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { - AT91C_BASE_SSC->SSC_THR = 0x00; } + checked++; // Wait for byte be become available in rx holding register if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { - c++; b = (uint8_t)AT91C_BASE_SSC->SSC_RHR; skip = !skip; if (skip) continue; if (ManchesterDecoding_iclass(b & 0x0f)) { - if (samples) - *samples = c << 3; - time_response = GetCountSspClk() - foo; + time_response = GetCountSspClk() - card_start; return true; + } else if (GetCountSspClkDelta(card_start) > timeout && Demod.state == DEMOD_IC_UNSYNCD) { + return false; } - bar = GetCountSspClk(); - if ( foo > bar ) - bar += ( UINT32_MAX - foo ); - - if (bar - foo > timeout) return false; } } - return false; } int ReaderReceiveIClass(uint8_t *receivedAnswer) { - int samples = 0; - if (GetIClassAnswer(receivedAnswer, 0, &samples, NULL) == false) + if (GetIClassAnswer(receivedAnswer, 0, NULL) == false) return 0; - rsamples += samples; - LogTrace(receivedAnswer, Demod.len, rsamples, rsamples, NULL, false); - - if (samples == 0) - return 0; - return Demod.len; } From 4540b31d67f459a0445279d3a8ea694e10643aba Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 11 Sep 2019 15:58:03 +0200 Subject: [PATCH 316/347] thinfilm: textual --- client/cmdhfthinfilm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/cmdhfthinfilm.c b/client/cmdhfthinfilm.c index 2e9ab7a85..a32aa8f59 100644 --- a/client/cmdhfthinfilm.c +++ b/client/cmdhfthinfilm.c @@ -60,10 +60,11 @@ static int print_barcode(uint8_t *barcode, const size_t barcode_len, bool verbos compute_crc(CRC_14443_A, barcode, barcode_len - 2, &b1, &b2); bool isok = (barcode[barcode_len - 1] == b1 && barcode[barcode_len - 2] == b2); - PrintAndLogEx(SUCCESS, " checksum : "_YELLOW_("%02X %02X")"- %s", b2, b1, (isok) ? _GREEN_("OK") : _RED_("fail")); + PrintAndLogEx(SUCCESS, " Checksum : "_YELLOW_("%02X %02X")"- %s", b2, b1, (isok) ? _GREEN_("OK") : _RED_("fail")); } else { - PrintAndLogEx(SUCCESS, " checksum : "_YELLOW_("too few data for checksum")"- " _RED_("fail")); + PrintAndLogEx(SUCCESS, " Checksum : "_YELLOW_("too few data for checksum")"- " _RED_("fail")); } + PrintAndLogEx(SUCCESS, " Data len (bits) : "_YELLOW_("%i")"- %s", barcode_len*8, (barcode_len==16||barcode_len==32) ? _GREEN_("OK") : _YELLOW_("warning")); PrintAndLogEx(SUCCESS, " Raw data : "_YELLOW_("%s"), sprint_hex(barcode, barcode_len)); if (barcode_len < 4) // too few to go to next decoding stages return PM3_ESOFT; From 08c345e560e7d6dcd587ab538a3fd404a8f7ed96 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 11 Sep 2019 17:21:27 +0300 Subject: [PATCH 317/347] added yubikey link --- client/fido/additional_ca.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/fido/additional_ca.c b/client/fido/additional_ca.c index 21d9d80f6..7ea103004 100644 --- a/client/fido/additional_ca.c +++ b/client/fido/additional_ca.c @@ -36,6 +36,7 @@ // Name: Yubico U2F Root CA Serial 457200631 // Issued: 2014-08-01 +// https://github.com/Yubico/developers.yubico.com/tree/master/static/U2F #define YUBICO_CA \ "-----BEGIN CERTIFICATE-----\r\n" \ "MIIDHjCCAgagAwIBAgIEG0BT9zANBgkqhkiG9w0BAQsFADAuMSwwKgYDVQQDEyNZ\r\n" \ From a623e6a24647b5c7ad0f8ef3851debbdff9b6d61 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 16:22:37 +0200 Subject: [PATCH 318/347] chg: 'hf iclass list' - no parity on responses --- client/cmdtrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/cmdtrace.c b/client/cmdtrace.c index 401dac66e..010621498 100644 --- a/client/cmdtrace.c +++ b/client/cmdtrace.c @@ -303,7 +303,7 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr && (oddparity8(frame[j]) != ((parityBits >> (7 - (j & 0x0007))) & 0x01))) { snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]); - } else if ( protocol == ICLASS && isResponse == true) { + } else if ( protocol == ICLASS && isResponse == false) { uint8_t parity = 0; for (int i=0; i<6; i++) { parity ^= ((frame[0] >> i) & 1); @@ -313,6 +313,7 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr } else { snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x! ", frame[j]); } + } else { snprintf(line[j / 18] + ((j % 18) * 4), 110, "%02x ", frame[j]); } From 9f0db0bbdc89705b30bc04a746352f3e45dd9417 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 16:23:06 +0200 Subject: [PATCH 319/347] textual --- client/cmdhficlass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 8b0c4ea35..6de758d31 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -2805,7 +2805,7 @@ int readIclass(bool loop, bool verbose) { uint8_t readStatus = resp.oldarg[0] & 0xff; uint8_t *data = resp.data.asBytes; - if (verbose) PrintAndLogEx(NORMAL, "Readstatus:%02x", readStatus); + if (verbose) PrintAndLogEx(INFO, "Readstatus:%02x", readStatus); // no tag found or button pressed if ((readStatus == 0 && !loop) || readStatus == 0xFF) { // abort From ab0d81d01acce45cfd35e15555fd663aebb228ed Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 16:24:16 +0200 Subject: [PATCH 320/347] ..adapt parity to cmds, prolong button loop test --- armsrc/iclass.c | 64 +++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 0f572cae3..5e9ffb913 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -55,8 +55,8 @@ #include "protocols.h" #include "ticks.h" -static int g_wait = 270; -static int timeout = 5000; +static int g_wait = 200; +static int timeout = 15000; static uint32_t time_rdr = 0; static uint32_t time_response = 0; @@ -1029,12 +1029,11 @@ static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen) WDT_HIT(); - if (checked == 1000) { + if (checked == 2000) { if (BUTTON_PRESS() || data_available()) return false; checked = 0; - } else { - checked++; } + checked++; // keep tx buffer in a defined state anyway. if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) @@ -1682,12 +1681,12 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) { uint16_t checked = 0; for (;;) { - if (checked == 1000) { + if (checked == 2000) { if (BUTTON_PRESS() || data_available()) return 0; checked = 0; - } else { - checked++; } + checked++; + // Prevent rx holding register from overflowing if ((AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)) { b = AT91C_BASE_SSC->SSC_RHR; @@ -1872,7 +1871,6 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *wait) { if (skip) continue; if (ManchesterDecoding_iclass(b & 0x0f)) { - time_response = GetCountSspClk() - card_start; return true; } else if (GetCountSspClkDelta(card_start) > timeout && Demod.state == DEMOD_IC_UNSYNCD) { @@ -1930,7 +1928,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re // update/write command takes 4ms to 15ms before responding int old_wait = g_wait; - if (command[0] == ICLASS_CMD_UPDATE) + if ( (command[0] & 0xF) == ICLASS_CMD_UPDATE) g_wait = 3900; uint8_t got_n = ReaderReceiveIClass(resp); @@ -1962,8 +1960,8 @@ uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) { // act_all... static uint8_t act_all[] = { ICLASS_CMD_ACTALL }; static uint8_t identify[] = { ICLASS_CMD_READ_OR_IDENTIFY, 0x00, 0x73, 0x33 }; - static uint8_t select[] = { ICLASS_CMD_SELECT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - uint8_t readcheck_cc[] = { ICLASS_CMD_READCHECK, 0x02 }; + static uint8_t select[] = { 0x80 | ICLASS_CMD_SELECT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t readcheck_cc[] = { 0x80 | ICLASS_CMD_READCHECK, 0x02 }; if (use_credit_key == false) readcheck_cc[0] |= 0x10; @@ -2055,7 +2053,7 @@ void ReaderIClass(uint8_t arg0) { WDT_HIT(); // if only looking for one card try 2 times if we missed it the first time - if (try_once && tryCnt > 2) { + if (try_once && tryCnt > 10) { if (DBGLEVEL > 1) DbpString("Failed to find a tag"); break; } @@ -2138,9 +2136,10 @@ void ReaderIClass(uint8_t arg0) { if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SEND %c", send ? 'y' : 'n'); if (send) { - reply_old(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data)); + reply_mix(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data)); if (abort_after_read) { LED_B_OFF(); + swith_off(); return; } //Save that we already sent this.... @@ -2149,19 +2148,18 @@ void ReaderIClass(uint8_t arg0) { } LED_B_OFF(); - if (checked == 1000) { + if (checked == 2000) { userCancelled = BUTTON_PRESS() || data_available(); checked = 0; - } else { - checked++; } + checked++; } if (userCancelled) { - reply_old(CMD_ACK, 0xFF, 0, 0, card_data, 0); + reply_mix(CMD_ACK, 0xFF, 0, 0, card_data, 0); switch_off(); } else { - reply_old(CMD_ACK, 0, 0, 0, card_data, 0); + reply_mix(CMD_ACK, 0, 0, 0, card_data, 0); } } @@ -2331,7 +2329,7 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { uint8_t keyCount = arg1 & 0xFF; uint8_t check[] = { ICLASS_CMD_CHECK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t resp[ICLASS_BUFFER_SIZE]; - uint8_t readcheck_cc[] = { ICLASS_CMD_READCHECK, 0x02 }; + uint8_t readcheck_cc[] = { 0x80 | ICLASS_CMD_READCHECK, 0x02 }; if (use_credit_key == false) readcheck_cc[0] |= 0x10; @@ -2353,12 +2351,11 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { uint8_t startup_limit = 10; while (read_status != 2) { - if (checked == 1000) { + if (checked == 2000) { if (BUTTON_PRESS() || !data_available()) goto out; checked = 0; - } else { - checked++; } + checked++; read_status = handshakeIclassTag_ext(card_data, use_credit_key); if (startup_limit-- == 0) { @@ -2375,12 +2372,11 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { for (i = 0; i < keyCount; i++) { // Allow button press / usb cmd to interrupt device - if (checked == 1000) { + if (checked == 2000) { if (BUTTON_PRESS() || !data_available()) goto out; checked = 0; - } else { - checked++; } + checked++; WDT_HIT(); LED_B_ON(); @@ -2432,10 +2428,10 @@ bool iClass_ReadBlock(uint8_t blockno, uint8_t *data, uint8_t len) { // readblock 8 + 2. only want 8. void iClass_ReadBlk(uint8_t blockno) { struct p { - bool isOK; + bool isOK; uint8_t blockdata[8]; } PACKED result; - + result.isOK = iClass_ReadBlock(blockno, result.blockdata, sizeof(result.blockdata)); switch_off(); reply_ng(CMD_HF_ICLASS_READBL, PM3_SUCCESS, (uint8_t *)&result, sizeof(result)); @@ -2470,7 +2466,7 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks) { } memcpy(dataout + (blkCnt * 8), blockdata, 8); } - + switch_off(); //return pointer to dump memory in arg3 reply_mix(CMD_ACK, isOK, blkCnt, BigBuf_max_traceLen(), 0, 0); @@ -2479,7 +2475,7 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks) { bool iClass_WriteBlock_ext(uint8_t blockno, uint8_t *data) { uint8_t resp[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - uint8_t write[] = { ICLASS_CMD_UPDATE, blockno, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t write[] = { 0x80 | ICLASS_CMD_UPDATE, blockno, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; memcpy(write + 2, data, 12); // data + mac AddCrc(write + 1, 13); return sendCmdGetResponseWithRetries(write, sizeof(write), resp, sizeof(resp), 5); @@ -2505,12 +2501,12 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) { Dbprintf("Write block [%02x] failed", startblock + i); } } - + switch_off(); - + uint8_t isOK = 0; if (written == total_block) isOK = 1; - - reply_ng(CMD_HF_ICLASS_CLONE, PM3_SUCCESS, (uint8_t *)&isOK, sizeof(uint8_t)); + + reply_ng(CMD_HF_ICLASS_CLONE, PM3_SUCCESS, (uint8_t *)&isOK, sizeof(uint8_t)); } From 312e4b358c9749ec71c74c691b12ae4c10b86938 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 16:36:41 +0200 Subject: [PATCH 321/347] fix: 'hf iclass reader 1' - now turns off --- client/cmdhficlass.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 6de758d31..4d6af964b 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -2806,25 +2806,27 @@ int readIclass(bool loop, bool verbose) { uint8_t *data = resp.data.asBytes; if (verbose) PrintAndLogEx(INFO, "Readstatus:%02x", readStatus); + // no tag found or button pressed if ((readStatus == 0 && !loop) || readStatus == 0xFF) { // abort - if (verbose) { - PrintAndLogEx(FAILED, "Quitting..."); - DropField(); - return PM3_EOPABORTED; - } + DropField(); + return PM3_EOPABORTED; } + if (readStatus & FLAG_ICLASS_READER_CSN) { PrintAndLogEx(NORMAL, " CSN: %s", sprint_hex(data, 8)); tagFound = true; } + if (readStatus & FLAG_ICLASS_READER_CC) { PrintAndLogEx(NORMAL, " CC: %s", sprint_hex(data + 16, 8)); } + if (readStatus & FLAG_ICLASS_READER_CONF) { printIclassDumpInfo(data); } + if (readStatus & FLAG_ICLASS_READER_AIA) { bool legacy = (memcmp((uint8_t *)(data + 8 * 5), "\xff\xff\xff\xff\xff\xff\xff\xff", 8) == 0); From 6090a66f34fb3d223fb47651c8102662f73ce3db Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 16:37:10 +0200 Subject: [PATCH 322/347] ... --- armsrc/iclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 5e9ffb913..d6c0ea72e 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -2139,7 +2139,7 @@ void ReaderIClass(uint8_t arg0) { reply_mix(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data)); if (abort_after_read) { LED_B_OFF(); - swith_off(); + switch_off(); return; } //Save that we already sent this.... From f57a6195ded5f83a779657ad778806666dea040e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 16:56:08 +0200 Subject: [PATCH 323/347] turning off field on failure --- client/cmdhficlass.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 4d6af964b..fc6b2e53b 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1021,7 +1021,7 @@ static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool v if (isOK <= 1) { if ( verbose ) PrintAndLogEx(FAILED, "failed to obtain CC! Tag-select is aborting... (%d)", isOK); - + return false; } return true; @@ -1033,6 +1033,8 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u if (!select_only(CSN, CCNR, use_credit_key, verbose)) { if (verbose) PrintAndLogEx(FAILED, "selecting tag failed"); + + DropField(); return false; } //get div_key @@ -2042,8 +2044,10 @@ static int CmdHFiClassCalcNewKey(const char *Cmd) { if (!givenCSN) { uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (!select_only(CSN, CCNR, false, true)) + if (!select_only(CSN, CCNR, false, true)) { + DropField(); return 0; + } } HFiClassCalcNewKey(CSN, OLDKEY, NEWKEY, xor_div_key, elite, oldElite, true); @@ -2280,16 +2284,18 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { for (uint8_t i = 0; i < ICLASS_AUTH_RETRY && !got_csn; i++) { got_csn = select_only(CSN, CCNR, false, false); if (got_csn == false) - PrintAndLogEx(WARNING, "one more try\n"); + PrintAndLogEx(WARNING, "one more try"); } if (got_csn == false) { PrintAndLogEx(WARNING, "Tried 10 times. Can't select card, aborting..."); + DropField(); return PM3_ESOFT; } pre = calloc(keycount, sizeof(iclass_premac_t)); if (!pre) { + DropField(); free(keyBlock); return PM3_EMALLOC; } From f4ff22a5bcca8f21e560ac7eaa1f0328479fdc7d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 20:40:59 +0200 Subject: [PATCH 324/347] revert back timeout values --- armsrc/iclass.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index d6c0ea72e..c4253a260 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -55,8 +55,8 @@ #include "protocols.h" #include "ticks.h" -static int g_wait = 200; -static int timeout = 15000; +static int g_wait = 100; +static int timeout = 5000; static uint32_t time_rdr = 0; static uint32_t time_response = 0; @@ -895,9 +895,7 @@ void RAMFUNC SniffIClass(void) { // time ZERO, the point from which it all is calculated. time_0 = GetCountSspClk(); - - int divi = 0; - uint8_t tag_byte = 0, foo = 0; + // loop and listen // every sample (1byte in data), // contains HIGH nibble = reader data @@ -908,12 +906,11 @@ void RAMFUNC SniffIClass(void) { for (;;) { WDT_HIT(); - if (checked == 1000) { + if (checked == 2000) { if (BUTTON_PRESS() || data_available()) break; checked = 0; - } else { - checked++; } + checked++; previous_data <<= 8; previous_data |= *data; @@ -927,14 +924,6 @@ void RAMFUNC SniffIClass(void) { AT91C_BASE_PDC_SSC->PDC_RNCR = ICLASS_DMA_BUFFER_SIZE; } - if (*data & 0xF) { - //tag_byte <<= 1; - tag_byte ^= (1 << 4); - foo ^= (1 << (3 - divi)); - Dbprintf(" %d|%x == %d|%x", tag_byte, tag_byte, foo, foo); - } - divi++; - // every odd sample if (sniffCounter & 0x01) { // no need to try decoding reader data if the tag is sending @@ -964,8 +953,6 @@ void RAMFUNC SniffIClass(void) { LED_C_INV(); // LOW nibble is always tag data. /* - - uint32_t tag_byte = ((previous_data & 0x0F000000) >> 8 ) | ((previous_data & 0x000F0000) >> 4 ) | @@ -975,8 +962,8 @@ void RAMFUNC SniffIClass(void) { */ - //uint8_t tag_byte = ((previous_data & 0xF) << 4 ) | (*data & 0xF); - if (ManchesterDecoding_iclass(foo)) { + uint8_t tag_byte = ((previous_data & 0xF) << 4 ) | (*data & 0xF); + if (ManchesterDecoding_iclass(tag_byte)) { time_stop = GetCountSspClk() - time_0; LogTrace(Demod.output, Demod.len, time_start, time_stop, NULL, false); DemodIcReset(); @@ -986,17 +973,15 @@ void RAMFUNC SniffIClass(void) { } TagIsActive = (Demod.state != DEMOD_IC_UNSYNCD); } - tag_byte = 0; - foo = 0; - divi = 0; } } // end main loop +/* if (DBGLEVEL >= 1) { DbpString("[+] Sniff statistics:"); Dbhexdump(ICLASS_DMA_BUFFER_SIZE, data, false); } - +*/ switch_off(); } From 236175a688b15626be0dee59b939dde7e49e7978 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 21:14:46 +0200 Subject: [PATCH 325/347] fix 'hf iclass chk' - timings and fixing the parity / kc / kd ... --- armsrc/iclass.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index c4253a260..b13eff66f 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -55,7 +55,7 @@ #include "protocols.h" #include "ticks.h" -static int g_wait = 100; +static int g_wait = 240; static int timeout = 5000; static uint32_t time_rdr = 0; static uint32_t time_response = 0; @@ -1700,10 +1700,9 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) { //----------------------------------------------------------------------------- // Transmit the command (to the tag) that was placed in ToSend[]. //----------------------------------------------------------------------------- -static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int *wait) { +static void TransmitIClassCommand(const uint8_t *cmd, int len, int *wait) { int c = 0; -// volatile uint32_t b; bool firstpart = true; uint8_t sendbyte; @@ -1740,14 +1739,6 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int if (c >= len) break; } - - // Prevent rx holding register from overflowing - /* - if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { - b = AT91C_BASE_SSC->SSC_RHR; - (void)b; - } - */ } time_rdr = GetCountSspClk(); @@ -1794,21 +1785,17 @@ void CodeIClassCommand(const uint8_t *cmd, int len) { void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) { - int samples = 0; - // This is tied to other size changes CodeIClassCommand(frame, len); // Select the card - TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait); + TransmitIClassCommand(ToSend, ToSendMax, &wait); LED_A_ON(); - rsamples += samples; - LogTrace(frame, len, rsamples, rsamples, NULL, true); } void ReaderTransmitIClass(uint8_t *frame, int len) { - ReaderTransmitIClass_ext(frame, len, 400); + ReaderTransmitIClass_ext(frame, len, 330); } //----------------------------------------------------------------------------- @@ -1948,14 +1935,17 @@ uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) { static uint8_t select[] = { 0x80 | ICLASS_CMD_SELECT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t readcheck_cc[] = { 0x80 | ICLASS_CMD_READCHECK, 0x02 }; - if (use_credit_key == false) - readcheck_cc[0] |= 0x10; + // Bit 4: K.If this bit equals to one, the READCHECK will use the Credit Key (Kc); if equals to zero, Debit Key (Kd) willbe used + // bit 7: parity. + + if (use_credit_key) + readcheck_cc[0] = 0x10 | ICLASS_CMD_READCHECK; uint8_t resp[ICLASS_BUFFER_SIZE] = {0}; uint8_t read_status = 0; // Send act_all - ReaderTransmitIClass_ext(act_all, 1, 330 + 160); + ReaderTransmitIClass_ext(act_all, 1, 330); // Card present? if (!ReaderReceiveIClass(resp)) return read_status;//Fail @@ -2316,8 +2306,8 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) { uint8_t resp[ICLASS_BUFFER_SIZE]; uint8_t readcheck_cc[] = { 0x80 | ICLASS_CMD_READCHECK, 0x02 }; - if (use_credit_key == false) - readcheck_cc[0] |= 0x10; + if (use_credit_key) + readcheck_cc[0] = 0x10 | ICLASS_CMD_READCHECK; // select card / e-purse uint8_t card_data[6 * 8] = {0}; From 1ad66c917f52333c2b1cd504ef44543f482fb39c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 11 Sep 2019 22:51:13 +0200 Subject: [PATCH 326/347] fixin... --- armsrc/iclass.c | 54 ++++++++++++++++++++++---------------------- client/cmdhficlass.c | 9 ++++---- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/armsrc/iclass.c b/armsrc/iclass.c index b13eff66f..5bbcc1b4b 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -55,7 +55,7 @@ #include "protocols.h" #include "ticks.h" -static int g_wait = 240; +static int g_wait = 290; static int timeout = 5000; static uint32_t time_rdr = 0; static uint32_t time_response = 0; @@ -1808,7 +1808,6 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *wait) { // maxLen is not used... bool skip = false; - LED_D_ON(); // Set FPGA mode to "reader listen mode", no modulation (listen // only, since we are receiving, not transmitting). @@ -1848,7 +1847,6 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *wait) { } else if (GetCountSspClkDelta(card_start) > timeout && Demod.state == DEMOD_IC_UNSYNCD) { return false; } - } } return false; @@ -1910,7 +1908,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re // 0xBB is the internal debug separator byte.. if (expected_size != got_n || (resp[0] == 0xBB || resp[7] == 0xBB || resp[2] == 0xBB)) { //try again - SpinDelayUs(360); +// SpinDelayUs(360); continue; } @@ -1942,19 +1940,20 @@ uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) { readcheck_cc[0] = 0x10 | ICLASS_CMD_READCHECK; uint8_t resp[ICLASS_BUFFER_SIZE] = {0}; - uint8_t read_status = 0; - // Send act_all - ReaderTransmitIClass_ext(act_all, 1, 330); + // Send act_all ( 330 timeout + 160 timeslot); + ReaderTransmitIClass_ext(act_all, 1, 330 + 180); + // Card present? - if (!ReaderReceiveIClass(resp)) return read_status;//Fail + if (ReaderReceiveIClass(resp) == 0) + return 0; //Send Identify ReaderTransmitIClass(identify, 1); //We expect a 10-byte response here, 8 byte anticollision-CSN and 2 byte CRC - uint8_t len = ReaderReceiveIClass(resp); - if (len != 10) return read_status;//Fail + if ( ReaderReceiveIClass(resp) != 10 ) + return 0; //Copy the Anti-collision CSN to our select-packet memcpy(&select[1], resp, 8); @@ -1963,31 +1962,33 @@ uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) { ReaderTransmitIClass(select, sizeof(select)); //We expect a 10-byte response here, 8 byte CSN and 2 byte CRC - len = ReaderReceiveIClass(resp); - if (len != 10) return read_status;//Fail + if ( ReaderReceiveIClass(resp) != 10) + return 0; - //Success - level 1, we got CSN - //Save CSN in response data - memcpy(card_data, resp, 8); - - //Flag that we got to at least stage 1, read CSN - read_status = 1; - - // Card selected, now read e-purse (cc) (block2) (only 8 bytes no CRC) + // Card selected, now read e-purse (cc) (block2) (only 8 bytes no CRC) // ReaderTransmitIClass(readcheck_cc, sizeof(readcheck_cc)); // if (ReaderReceiveIClass(resp) == 8) { // //Save CC (e-purse) in response data // memcpy(card_data+8, resp, 8); // read_status++; // } + + //Success - level 1, we got CSN + //Save CSN in response data + memcpy(card_data, resp, 8); + + bool isBlk_2 = sendCmdGetResponseWithRetries(readcheck_cc, sizeof(readcheck_cc), resp, 8, 3); - bool isOK = sendCmdGetResponseWithRetries(readcheck_cc, sizeof(readcheck_cc), resp, 8, 3); - if (!isOK) return read_status; - + //Flag that we got to at least stage 1, read CSN + if ( isBlk_2 == false) { + return 1; + } + //Save CC (e-purse) in response data memcpy(card_data + 8, resp, 8); - read_status++; - return read_status; + + // we got all data; + return 2; } uint8_t handshakeIclassTag(uint8_t *card_data) { return handshakeIclassTag_ext(card_data, false); @@ -2114,7 +2115,6 @@ void ReaderIClass(uint8_t arg0) { reply_mix(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data)); if (abort_after_read) { LED_B_OFF(); - switch_off(); return; } //Save that we already sent this.... @@ -2421,7 +2421,7 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks) { BigBuf_free(); uint8_t *dataout = BigBuf_malloc(255 * 8); if (dataout == NULL) { - DbpString("[!] out of memory"); + DbpString("[!] fail to allocate memory"); OnError(1); return; } diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index fc6b2e53b..f45151a7b 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1034,7 +1034,7 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u if (!select_only(CSN, CCNR, use_credit_key, verbose)) { if (verbose) PrintAndLogEx(FAILED, "selecting tag failed"); - DropField(); +// DropField(); return false; } //get div_key @@ -1728,13 +1728,12 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, DropField(); - if ( numberAuthRetries > 0 ) { - PrintAndLogEx(SUCCESS, "block %02X: %s\n", blockno, sprint_hex(result->blockdata, sizeof(result->blockdata))); - } else { + if ( numberAuthRetries == 0 ) { PrintAndLogEx(ERR,"failed to authenticate and read block"); - return PM3_ESOFT; } + + PrintAndLogEx(SUCCESS, "block %02X: %s\n", blockno, sprint_hex(result->blockdata, sizeof(result->blockdata))); return PM3_SUCCESS; } From 22ead8ca0b50d50d7f3344ce344b4f1c2d6e6af5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 12 Sep 2019 01:23:43 +0200 Subject: [PATCH 327/347] printdemodbuffer: add option to strip leading zeroes --- client/cmddata.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/cmddata.c b/client/cmddata.c index 59c80102d..9465c63ac 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -39,6 +39,7 @@ static int usage_data_printdemodbuf(void) { PrintAndLogEx(NORMAL, " x output in hex (omit for binary output)"); PrintAndLogEx(NORMAL, " o enter offset in # of bits"); PrintAndLogEx(NORMAL, " l enter length to print in # of bits or hex characters respectively"); + PrintAndLogEx(NORMAL, " s strip leading zeroes, i.e. set offset to first bit equal to one"); return PM3_SUCCESS; } static int usage_data_manrawdecode(void) { @@ -402,6 +403,7 @@ void printDemodBuff(void) { int CmdPrintDemodBuff(const char *Cmd) { bool hexMode = false; bool errors = false; + bool lstrip = false; uint32_t offset = 0; uint32_t length = 512; char cmdp = 0; @@ -423,6 +425,10 @@ int CmdPrintDemodBuff(const char *Cmd) { if (!length) errors = true; cmdp += 2; break; + case 's': + lstrip = true; + cmdp ++; + break; default: PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); errors = true; @@ -436,6 +442,15 @@ int CmdPrintDemodBuff(const char *Cmd) { PrintAndLogEx(NORMAL, "Demodbuffer is empty"); return PM3_ESOFT; } + if (lstrip) { + char *buf = (char *)(DemodBuffer + offset); + length = (length > (DemodBufferLen - offset)) ? DemodBufferLen - offset : length; + uint32_t i; + for (i = 0; i < length; i++) { + if (buf[i] == 1) break; + } + offset += i; + } length = (length > (DemodBufferLen - offset)) ? DemodBufferLen - offset : length; if (hexMode) { From 3587aeff2aaeb8d326ac2baa35824eecb02a7936 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 09:58:05 +0200 Subject: [PATCH 328/347] fix: LED is used as a flag, 1,2,4,8 not 1,2,3,4.. --- armsrc/Standalone/hf_bog.c | 2 +- armsrc/Standalone/hf_colin.c | 8 ++++---- armsrc/appmain.c | 15 ++++++++------- armsrc/util.c | 32 +++++++++++++++++--------------- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index 6580af7fd..dc5c2e071 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -229,7 +229,7 @@ void RAMFUNC SniffAndStore(uint8_t param) { if (DBGLEVEL > 1) Dbprintf("[!] Wrote %u Authentification attempts into logfile", auth_attempts); - SpinErr(0, 200, 5); // blink led A + SpinErr(LED_A, 200, 5); SpinDelay(100); } diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 265b7e3c9..4997f775e 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -518,7 +518,7 @@ failtag: if (cjcuid == 0) { cjSetCursLeft(); DbprintfEx(FLAG_NEWLINE, "%s>>%s BUG: 0000_CJCUID! Retrying...", _XRED_, _XWHITE_); - SpinErr(0, 100, 8); + SpinErr(LED_A, 100, 8); goto failtag; } @@ -636,7 +636,7 @@ failtag: cjTabulize(); DbprintfEx(FLAG_NEWLINE, "%s[ FAIL ]%s\r\n->did not found all the keys :'(", _XRED_, _XWHITE_); cjSetCursLeft(); - SpinErr(1, 100, 8); + SpinErr(LEB_B, 100, 8); SpinOff(100); return; } @@ -672,7 +672,7 @@ failtag: cjSetCursLeft(); DbprintfEx(FLAG_NEWLINE, "FATAL:EML_FALLBACKFILL_B"); - SpinErr(2, 100, 8); + SpinErr(LED_C, 100, 8); SpinOff(100); return; } @@ -778,7 +778,7 @@ readysim: DbprintfEx(FLAG_NEWLINE, "- [ LA FIN ] -\r\n%s`-> You can take shell back :) ...", _XWHITE_); cjSetCursLeft(); vtsend_set_attribute(NULL, 0); - SpinErr(3, 100, 16); + SpinErr(LED_D, 100, 16); SpinDown(75); SpinOff(100); return; diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 990ac1c56..a4b1c45bc 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -447,15 +447,12 @@ void SendCapabilities(void) { // Show some leds in a pattern to identify StandAlone mod is running void StandAloneMode(void) { - - DbpString("Stand-alone mode! No PC necessary."); - + DbpString("Stand-alone mode, no computer necessary"); SpinDown(50); - SpinOff(50); + SpinDelay(50); SpinUp(50); - SpinOff(50); + SpinDelay(50); SpinDown(50); - SpinDelay(500); } /* @@ -1215,7 +1212,11 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ICLASS_READER: { - ReaderIClass(packet->oldarg[0]); + struct p { + uint8_t flags; + } PACKED; + struct p *payload = (struct p *)packet->data.asBytes; + ReaderIClass(payload->flags); break; } case CMD_HF_ICLASS_REPLAY: { diff --git a/armsrc/util.c b/armsrc/util.c index b855ab949..888c64b9d 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -90,6 +90,7 @@ void LEDsoff() { LED_D_OFF(); } +//ICEMAN: LED went from 1,2,3,4 -> 1,2,4,8 void LED(int led, int ms) { if (led & LED_A) // Proxmark3 historical mapping: LED_ORANGE LED_A_ON(); @@ -123,26 +124,27 @@ void SpinOff(uint32_t pause) { SpinDelay(pause); } -// 0=A, 1=B, 2=C, 3=D +// Blinks.. +// A = 1, B = 2, C = 4, D = 8 void SpinErr(uint8_t led, uint32_t speed, uint8_t times) { SpinOff(speed); NTIME(times) { - switch (led) { - case 0: - LED_A_INV(); - break; - case 1: - LED_B_INV(); - break; - case 2: - LED_C_INV(); - break; - case 3: - LED_D_INV(); - break; - } + + if (led & LED_A) // Proxmark3 historical mapping: LED_ORANGE + LED_A_INV(); + if (led & LED_B) // Proxmark3 historical mapping: LED_GREEN + LED_B_INV(); + if (led & LED_C) // Proxmark3 historical mapping: LED_RED + LED_C_INV(); + if (led & LED_D) // Proxmark3 historical mapping: LED_RED2 + LED_D_INV(); + SpinDelay(speed); } + LED_A_OFF(); + LED_B_OFF(); + LED_C_OFF(); + LED_D_OFF(); } void SpinDown(uint32_t speed) { From d3b2f1f6d05915d495690328ccf7a084101060ac Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 10:39:10 +0200 Subject: [PATCH 329/347] fix leds. dbg msg --- armsrc/pcf7931.c | 76 ++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index 82865b311..1690c6ad3 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -94,7 +94,10 @@ size_t DemodPCF7931(uint8_t **outBlocks) { } else { // Error if (++warnings > 10) { - Dbprintf("Error: too many detection errors, aborting."); + + if ( DBGLEVEL >= DBG_EXTENDED ) + Dbprintf("Error: too many detection errors, aborting."); + return 0; } } @@ -135,11 +138,14 @@ bool IsBlock0PCF7931(uint8_t *block) { // assuming all RFU bits are set to 0 // if PAC is enabled password is set to 0 if (block[7] == 0x01) { - if (!memcmp(block, "\x00\x00\x00\x00\x00\x00\x00", 7) && !memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) + if (!memcmp(block, "\x00\x00\x00\x00\x00\x00\x00", 7) + && !memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) { return true; + } } else if (block[7] == 0x00) { - if (!memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) + if (!memcmp(block + 9, "\x00\x00\x00\x00\x00\x00\x00", 7)) { return true; + } } return false; } @@ -152,14 +158,14 @@ bool IsBlock1PCF7931(uint8_t *block) { uint8_t rlb = block[15]; if (block[10] == 0 - && block[11] == 0 - && block[12] == 0 - && block[13] == 0) { + && block[11] == 0 + && block[12] == 0 + && block[13] == 0) { // block 1 is sent only if (RLB >= 1 && RFB <= 1) or RB1 enabled if (rfb <= rlb - && rfb <= 9 - && rlb <= 9 - && ((rfb <= 1 && rlb >= 1) || rb1)) { + && rfb <= 9 + && rlb <= 9 + && ((rfb <= 1 && rlb >= 1) || rb1)) { return true; } } @@ -196,13 +202,18 @@ void ReadPCF7931() { // exit if no block is received if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) { - Dbprintf("Error, no tag or bad tag"); + + if ( DBGLEVEL >= DBG_INFO ) + Dbprintf("[!!] Error, no tag or bad tag"); + return; } // exit if too many errors during reading if (tries > 50 && (2 * errors > tries)) { - Dbprintf("Error reading the tag"); - Dbprintf("Here is the partial content"); + + if ( DBGLEVEL >= DBG_INFO ) + Dbprintf("[!!] Error reading the tag, only partial content"); + goto end; } @@ -231,7 +242,9 @@ void ReadPCF7931() { continue; } - Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors); + if ( DBGLEVEL >= DBG_EXTENDED ) + Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors); + for (i = 0; i < n; ++i) { print_result("got consecutive blocks", tmp_blocks[i], 16); } @@ -293,7 +306,9 @@ void ReadPCF7931() { } ++tries; if (BUTTON_PRESS()) { - Dbprintf("Button pressed, stopping."); + if ( DBGLEVEL >= DBG_EXTENDED) + Dbprintf("Button pressed, stopping."); + goto end; } } while (found_blocks < max_blocks); @@ -319,7 +334,7 @@ end: Dbprintf("-----------------------------------------"); } - reply_old(CMD_ACK, 0, 0, 0, 0, 0); + reply_mix(CMD_ACK, 0, 0, 0, 0, 0); } static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) { @@ -405,8 +420,12 @@ static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int3 @param data : data to write */ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) { - Dbprintf("Initialization delay : %d us", init_delay); - Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p); + + if ( DBGLEVEL >= DBG_INFO ) { + Dbprintf("Initialization delay : %d us", init_delay); + Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p); + } + Dbprintf("Password (LSB first on each byte): %02x %02x %02x %02x %02x %02x %02x", pass1, pass2, pass3, pass4, pass5, pass6, pass7); Dbprintf("Block address : %02x", address); Dbprintf("Byte address : %02x", byte); @@ -425,8 +444,10 @@ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, ui void SendCmdPCF7931(uint32_t *tab) { uint16_t u = 0, tempo = 0; - Dbprintf("Sending data frame..."); - + if ( DBGLEVEL >= DBG_INFO ) { + Dbprintf("Sending data frame..."); + } + FpgaDownloadAndGo(FPGA_BITSTREAM_LF); FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125kHz FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU); @@ -468,7 +489,6 @@ void SendCmdPCF7931(uint32_t *tab) { SpinDelay(200); AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // timer disable - LED(0xFFFF, 1000); } @@ -482,13 +502,13 @@ bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p) { uint32_t u; for (u = 0; u < 8; ++u) { if (byte & (1 << u)) { //bit is 1 - if (AddBitPCF7931(1, tab, l, p) == 1) return 1; + if (AddBitPCF7931(1, tab, l, p) == 1) return true; } else { //bit is 0 - if (AddBitPCF7931(0, tab, l, p) == 1) return 1; + if (AddBitPCF7931(0, tab, l, p) == 1) return true; } } - return 0; + return false; } /* Add a bits for building the data frame of PCF7931 tags @@ -501,7 +521,7 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) { uint8_t u = 0; //we put the cursor at the last value of the array - for (u = 0; tab[u] != 0; u += 3) { } + for (u = 0; tab[u] != 0; u += 3) { }; if (b == 1) { //add a bit 1 if (u == 0) @@ -511,7 +531,7 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) { tab[u + 1] = 6 * T0_PCF + tab[u] + l; tab[u + 2] = 88 * T0_PCF + tab[u + 1] - l - p; - return 0; + return false; } else { //add a bit 0 if (u == 0) @@ -521,9 +541,9 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) { tab[u + 1] = 6 * T0_PCF + tab[u] + l; tab[u + 2] = 24 * T0_PCF + tab[u + 1] - l - p; - return 0; + return false; } - return 1; + return true; } /* Add a custom pattern in the data frame @@ -540,5 +560,5 @@ bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t *tab) { tab[u + 1] = b + tab[u]; tab[u + 2] = c + tab[u + 1]; - return 0; + return true; } From ef281465ae728fbd480bc915317faf996a37711f Mon Sep 17 00:00:00 2001 From: 3ldidi94 Date: Thu, 12 Sep 2019 11:38:53 +0200 Subject: [PATCH 330/347] Add keys found on hardenest Mifare Classic Card Add keys found on hardenest Mifare Classic Card of an Hotel in Berlin (DE) --- client/dictionaries/mfc_default_keys.dic | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/dictionaries/mfc_default_keys.dic b/client/dictionaries/mfc_default_keys.dic index 280604b3a..a12291199 100644 --- a/client/dictionaries/mfc_default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -1018,3 +1018,5 @@ e6849fcc324b # 0b83797a9c64 39ad2963d3d1 +34b16cd59ff8 # Hotel Berlin Classic room A KEY +bb2c0007d022 # Hotel Berlin Classic room B KEY From c3a0d7d88a6bfa22ac6d330c2e704bbe677e7243 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 17:34:55 +0200 Subject: [PATCH 331/347] chg: 'lf t55xx info p' - got some more love, now can read with password :) chg: 'lf t55xx dump p' - less outputs and now can read with password :) chg: 'lf t55xx trace 1' - can now decode trace from a saved trace. However you must have correct configuration set in order to work. chg: 'lf t55xx wipe p' - now can use a password to write to configblock first. --- client/cmdlft55xx.c | 542 ++++++++++++++++++++++++++++---------------- 1 file changed, 348 insertions(+), 194 deletions(-) diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 55b711482..320b193b6 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -91,6 +91,17 @@ static int usage_t55xx_read() { PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } +static int usage_t55xx_resetread() { + PrintAndLogEx(NORMAL, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"); + PrintAndLogEx(NORMAL, "Usage: lf t55xx resetread [r ]"); + PrintAndLogEx(NORMAL, "Options:"); + print_usage_t55xx_downloadlink(); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "Examples:"); + PrintAndLogEx(NORMAL, " lf t55xx resetread"); + PrintAndLogEx(NORMAL, ""); + return PM3_SUCCESS; +} static int usage_t55xx_write() { PrintAndLogEx(NORMAL, "Usage: lf t55xx write [r ] b d [p ] [1] [t]"); PrintAndLogEx(NORMAL, "Options:"); @@ -108,26 +119,26 @@ static int usage_t55xx_write() { return PM3_SUCCESS; } static int usage_t55xx_trace() { - PrintAndLogEx(NORMAL, "Usage: lf t55xx trace [r mode]"); + PrintAndLogEx(NORMAL, "Usage: lf t55xx trace [1] [r mode]"); PrintAndLogEx(NORMAL, "Options:"); print_usage_t55xx_downloadlink(); - // Command did not seem to support the 1 option (yet) so have removed the help lines - // PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer otherwise read data from tag."); + PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer otherwise read data from tag."); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf t55xx trace"); - // PrintAndLogEx(NORMAL, " lf t55xx trace 1"); + PrintAndLogEx(NORMAL, " lf t55xx trace 1"); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } static int usage_t55xx_info() { PrintAndLogEx(NORMAL, "Usage: lf t55xx info [1] [r ] [d [q]]"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " (default) - read data from tag."); - PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer instead of reading tag."); - PrintAndLogEx(NORMAL, " d - 4 bytes of data (8 hex characters)"); - PrintAndLogEx(NORMAL, " if set, use these data instead of reading tag."); - PrintAndLogEx(NORMAL, " q - if set, provided data are interpreted as Q5 config."); + PrintAndLogEx(NORMAL, " (default) - read data from tag."); + PrintAndLogEx(NORMAL, " p - OPTIONAL password 4bytes (8 hex symbols)"); + PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer instead of reading tag."); + PrintAndLogEx(NORMAL, " d - 4 bytes of data (8 hex characters)"); + PrintAndLogEx(NORMAL, " if set, use these data instead of reading tag."); + PrintAndLogEx(NORMAL, " q - if set, provided data are interpreted as Q5 config."); print_usage_t55xx_downloadlink(); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); @@ -135,19 +146,20 @@ static int usage_t55xx_info() { PrintAndLogEx(NORMAL, " lf t55xx info 1"); PrintAndLogEx(NORMAL, " lf t55xx info d 00083040"); PrintAndLogEx(NORMAL, " lf t55xx info d 6001805A q"); + PrintAndLogEx(NORMAL, " lf t55xx info p 11223344"); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } static int usage_t55xx_dump() { - PrintAndLogEx(NORMAL, "Usage: lf t55xx dump [r ] [ [o]]"); + PrintAndLogEx(NORMAL, "Usage: lf t55xx dump [r ] [p [o]]"); PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " - OPTIONAL password 4bytes (8 hex symbols)"); - PrintAndLogEx(NORMAL, " o - OPTIONAL override, force pwd read despite danger to card"); + PrintAndLogEx(NORMAL, " p - OPTIONAL password 4bytes (8 hex symbols)"); + PrintAndLogEx(NORMAL, " o - OPTIONAL override, force pwd read despite danger to card"); print_usage_t55xx_downloadlink(); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf t55xx dump"); - PrintAndLogEx(NORMAL, " lf t55xx dump feedbeef o"); + PrintAndLogEx(NORMAL, " lf t55xx dump p feedbeef o"); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -215,16 +227,16 @@ static int usage_t55xx_bruteforce() { PrintAndLogEx(NORMAL, "press " _YELLOW_("'enter'") " to cancel the command"); PrintAndLogEx(NORMAL, "WARNING: this may brick non-password protected chips!"); PrintAndLogEx(NORMAL, "Try reading block 7 before\n"); - PrintAndLogEx(NORMAL, "Usage: lf t55xx bruteforce [h] [r ] "); + PrintAndLogEx(NORMAL, "Usage: lf t55xx bruteforce [h] [r ] [s ] [e ]"); PrintAndLogEx(NORMAL, " password must be 4 bytes (8 hex symbols)"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - this help"); print_usage_t55xx_downloadlink(); - PrintAndLogEx(NORMAL, " - 4 byte hex value to start pwd search at"); - PrintAndLogEx(NORMAL, " - 4 byte hex value to end pwd search at"); + PrintAndLogEx(NORMAL, " s - 4 byte hex value to start pwd search at"); + PrintAndLogEx(NORMAL, " e - 4 byte hex value to end pwd search at"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf t55xx bruteforce r 2 aaaaaa77 aaaaaa99"); + PrintAndLogEx(NORMAL, " lf t55xx bruteforce r 2 s aaaaaa77 e aaaaaa99"); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } @@ -248,15 +260,15 @@ static int usage_t55xx_recoverpw() { return PM3_SUCCESS; } static int usage_t55xx_wipe() { - PrintAndLogEx(NORMAL, "Usage: lf t55xx wipe [h] [Q5]"); + PrintAndLogEx(NORMAL, "Usage: lf t55xx wipe [h] [Q5] [p ]"); PrintAndLogEx(NORMAL, "This commands wipes a tag, fills blocks 1-7 with zeros and a default configuration block"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h - this help"); - PrintAndLogEx(NORMAL, " Q5 - indicates to use the T5555 (Q5) default configuration block"); + PrintAndLogEx(NORMAL, " q - indicates to use the T5555 (Q5) default configuration block"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf t55xx wipe - wipes a t55x7 tag, config block 0x000880E0"); - PrintAndLogEx(NORMAL, " lf t55xx wipe Q5 - wipes a t5555 Q5 tag, config block 0x6001F004"); + PrintAndLogEx(NORMAL, " lf t55xx wipe - wipes a t55x7 tag, config block 0x000880E0"); + PrintAndLogEx(NORMAL, " lf t55xx wipe q - wipes a t5555 Q5 tag, config block 0x6001F004"); return PM3_SUCCESS; } static int usage_lf_deviceconfig() { @@ -292,6 +304,9 @@ void printT5xxHeader(uint8_t page) { static int CmdT55xxSetConfig(const char *Cmd) { + // No args + if (strlen(Cmd) == 0) return printConfiguration(config); + uint8_t offset = 0, bitRate = 0; char modulation[6] = {0x00}; uint8_t rates[9] = {8, 16, 32, 40, 50, 64, 100, 128, 0}; @@ -395,9 +410,6 @@ static int CmdT55xxSetConfig(const char *Cmd) { } } - // No args - if (cmdp == 0) return printConfiguration(config); - //Validations if (errors) return usage_t55xx_config(); @@ -418,19 +430,17 @@ int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, uint8_t override, uin } else { PrintAndLogEx(NORMAL, "Safety Check: PWD bit is NOT set in config block. Reading without password..."); usepwd = false; - page1 = false; + page1 = false; // ?? } - } else { + } else if (override == 1) { // Show only if first for command i.e. override = 1 (override and display) override = 2 (override and dont display) - if (override == 1) - PrintAndLogEx(NORMAL, "Safety Check Overriden - proceeding despite risk"); + PrintAndLogEx(NORMAL, "Safety Check Overriden - proceeding despite risk"); } } - if (!AquireData(page1, block, usepwd, password, downlink_mode)) return PM3_ESOFT; - + if (!DecodeT55xxBlock()) return PM3_ESOFT; @@ -470,8 +480,10 @@ static int CmdT55xxReadBlock(const char *Cmd) { cmdp++; break; case 'r': - downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; - if (downlink_mode > 3) downlink_mode = 0; + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + cmdp += 2; break; @@ -595,15 +607,15 @@ void T55xx_Print_DownlinkMode(uint8_t downlink_mode) { // static int CmdT55xxDetect(const char *Cmd) { - bool errors = false; - bool useGB = false; - bool usepwd = false; - bool try_all_dl_modes = false; - bool found = false; - uint32_t password = 0; - uint8_t cmdp = 0; - uint8_t downlink_mode = 0; - uint8_t dl_mode = 0; + bool errors = false; + bool useGB = false; + bool usepwd = false; + bool try_all_dl_modes = false; + bool found = false; + uint32_t password = 0; + uint8_t cmdp = 0; + uint8_t downlink_mode = 0; + uint8_t dl_mode = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -620,9 +632,13 @@ static int CmdT55xxDetect(const char *Cmd) { cmdp++; break; case 'r': - downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; - if (downlink_mode == 4) try_all_dl_modes = true; - if (downlink_mode > 3) downlink_mode = 0; + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode == 4) + try_all_dl_modes = true; + + if (downlink_mode > 3) + downlink_mode = 0; + cmdp += 2; break; default: @@ -1109,24 +1125,24 @@ int special(const char *Cmd) { } int printConfiguration(t55xx_conf_block_t b) { - PrintAndLogEx(NORMAL, "Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7"); - PrintAndLogEx(NORMAL, "Modulation : %s", GetSelectedModulationStr(b.modulation)); - PrintAndLogEx(NORMAL, "Bit Rate : %s", GetBitRateStr(b.bitrate, (b.block0 & T55x7_X_MODE && (b.block0 >> 28 == 6 || b.block0 >> 28 == 9)))); - PrintAndLogEx(NORMAL, "Inverted : %s", (b.inverted) ? _GREEN_("Yes") : "No"); - PrintAndLogEx(NORMAL, "Offset : %d", b.offset); - PrintAndLogEx(NORMAL, "Seq. Term. : %s", (b.ST) ? _GREEN_("Yes") : "No"); - PrintAndLogEx(NORMAL, "Block0 : 0x%08X", b.block0); + PrintAndLogEx(NORMAL, " Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7"); + PrintAndLogEx(NORMAL, " Modulation : %s", GetSelectedModulationStr(b.modulation)); + PrintAndLogEx(NORMAL, " Bit Rate : %s", GetBitRateStr(b.bitrate, (b.block0 & T55x7_X_MODE && (b.block0 >> 28 == 6 || b.block0 >> 28 == 9)))); + PrintAndLogEx(NORMAL, " Inverted : %s", (b.inverted) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " Offset : %d", b.offset); + PrintAndLogEx(NORMAL, " Seq. Term. : %s", (b.ST) ? _GREEN_("Yes") : "No"); + PrintAndLogEx(NORMAL, " Block0 : 0x%08X", b.block0); PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } static int CmdT55xxWakeUp(const char *Cmd) { - uint32_t password = 0; - uint8_t cmdp = 0; - bool errors = false; - uint8_t downlink_mode = 0; - uint8_t flags = 0; + uint32_t password = 0; + uint8_t cmdp = 0; + bool errors = false; + uint8_t downlink_mode = 0; + uint8_t flags = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -1135,11 +1151,12 @@ static int CmdT55xxWakeUp(const char *Cmd) { case 'p': password = param_get32ex(Cmd, cmdp + 1, 0, 16); cmdp += 2; - errors = false; break; case 'r': - downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; - if (downlink_mode > 3) downlink_mode = 0; + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + cmdp += 2; break; default: @@ -1160,15 +1177,15 @@ static int CmdT55xxWakeUp(const char *Cmd) { } static int CmdT55xxWriteBlock(const char *Cmd) { - uint8_t block = 0xFF; //default to invalid block - uint32_t data = 0; //default to blank Block - uint32_t password = 0; //default to blank Block 7 - bool usepwd = false; - bool page1 = false; - bool gotdata = false; - bool testMode = false; - bool errors = false; - uint8_t cmdp = 0; + uint8_t block = 0xFF; // default to invalid block + uint32_t data = 0; // default to blank Block + uint32_t password = 0; // default to blank Block 7 + bool usepwd = false; + bool page1 = false; + bool gotdata = false; + bool testMode = false; + bool errors = false; + uint8_t cmdp = 0; uint32_t downlink_mode = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { @@ -1203,8 +1220,10 @@ static int CmdT55xxWriteBlock(const char *Cmd) { cmdp++; break; case 'r': - downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; - if (downlink_mode > 3) downlink_mode = 0; + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + cmdp += 2; break; default: @@ -1254,29 +1273,47 @@ static int CmdT55xxWriteBlock(const char *Cmd) { } static int CmdT55xxReadTrace(const char *Cmd) { - uint8_t cmd_len = 0; + + bool frombuff = false; uint8_t downlink_mode = 0; - - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'r') { - downlink_mode = param_getchar(Cmd, 1) - '0'; - if (downlink_mode > 3) downlink_mode = 0; - cmd_len = 3; + uint8_t cmdp = 0; + bool errors = false; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_trace(); + case 'r': + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + + cmdp += 2; + break; + case '1': + frombuff = true; + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } - if ((strlen(Cmd) != cmd_len) || (cmdp == 'h')) return usage_t55xx_trace(); - if (strlen(Cmd) == cmd_len) { + if (errors) return usage_t55xx_trace(); + + if (!frombuff) { // sanity check. if (SanityOfflineCheck(false) != PM3_SUCCESS) return PM3_ENODATA; bool pwdmode = false; uint32_t password = 0; -// REGULAR_READ_MODE_BLOCK - yeilds correct Page 1 Block 2 data i.e. + 32 bit offset. -// if (!AquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, pwdmode, password,downlink_mode)) + + // REGULAR_READ_MODE_BLOCK - yeilds correct Page 1 Block 2 data i.e. + 32 bit offset. if (!AquireData(T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password, downlink_mode)) return PM3_ENODATA; } - + if (config.Q5) { if (!DecodeT5555TraceBlock()) return PM3_ESOFT; } else { @@ -1515,10 +1552,10 @@ static int CmdT55xxInfo(const char *Cmd) { Normal mode Extended mode */ - bool frombuff = false, gotdata = false, dataasq5 = false; - uint8_t cmdp = 0; - uint8_t downlink_mode = 0; - uint32_t block0 = 0; + bool frombuff = false, gotdata = false, dataasq5 = false, usepwd = false; + uint8_t cmdp = 0; + uint8_t downlink_mode = 0; + uint32_t block0 = 0, password = 0; while (param_getchar(Cmd, cmdp) != 0x00) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -1529,6 +1566,11 @@ static int CmdT55xxInfo(const char *Cmd) { gotdata = true; cmdp += 2; break; + case 'p': + password = param_get32ex(Cmd, cmdp + 1, 0, 16); + usepwd = true; + cmdp += 2; + break; case '1': frombuff = true; cmdp += 2; @@ -1538,8 +1580,10 @@ static int CmdT55xxInfo(const char *Cmd) { cmdp += 2; break; case 'r': - downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; - if (downlink_mode > 3) downlink_mode = 0; + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + cmdp += 2; break; default: @@ -1558,11 +1602,10 @@ static int CmdT55xxInfo(const char *Cmd) { // sanity check. if (SanityOfflineCheck(false) != PM3_SUCCESS) return PM3_ENODATA; - bool pwdmode = false; - uint32_t password = 0; - if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password, downlink_mode)) + if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password, downlink_mode)) return PM3_ENODATA; } + if (!gotdata) { if (!DecodeT55xxBlock()) return PM3_ESOFT; @@ -1657,26 +1700,38 @@ static int CmdT55xxDump(const char *Cmd) { uint32_t password = 0; uint8_t override = 0; - uint8_t cmd_opt_idx = 0; uint8_t downlink_mode = 0; - uint8_t pwd_offset = 0; - char cmdp = tolower(param_getchar(Cmd, 0)); + bool usepwd = false; + bool errors = false; + uint8_t cmdp = 0; - if (cmdp == 'h') return usage_t55xx_dump(); - if (cmdp == 'r') { - cmd_opt_idx++; - downlink_mode = param_getchar(Cmd, cmd_opt_idx++) - '0'; - if (downlink_mode > 3) - downlink_mode = 0; - - pwd_offset = 3; - } - bool usepwd = (strlen(Cmd) > pwd_offset); - if (usepwd) { - password = param_get32ex(Cmd, cmd_opt_idx++, 0, 16); - if (param_getchar(Cmd, cmd_opt_idx++) == 'o') - override = 1; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_dump(); + case 'r': + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + + cmdp += 2; + break; + case 'p': + password = param_get32ex(Cmd, cmdp + 1, 0, 16); + usepwd = true; + cmdp += 2; + break; + case 'o': + override = 1; + cmdp++; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } + if (errors) return usage_t55xx_dump(); printT5xxHeader(0); for (uint8_t i = 0; i < 8; ++i) { @@ -1973,16 +2028,34 @@ static void t55x7_create_config_block(int tagtype) { static int CmdResetRead(const char *Cmd) { uint8_t downlink_mode = 0; - uint8_t flags = 0; + uint8_t flags = 0; + uint8_t cmdp = 0; + bool errors = false; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_resetread(); + case 'r': + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } + } - if (strlen(Cmd) == 3) - downlink_mode = param_getchar(Cmd, 1) - '0'; + if (errors) return usage_t55xx_resetread(); - if (downlink_mode > 3) downlink_mode = 0; - - printf("DL : %d\n", downlink_mode); + PrintAndLogEx(INFO, "DL : %d\n", downlink_mode); + flags = downlink_mode << 3; + clearCommandBuffer(); SendCommandNG(CMD_LF_T55XX_RESET_READ, &flags, sizeof(flags)); if (!WaitForResponseTimeout(CMD_ACK, NULL, 2500)) { @@ -2002,27 +2075,63 @@ static int CmdResetRead(const char *Cmd) { static int CmdT55xxWipe(const char *Cmd) { char writeData[20] = {0}; char *ptrData = writeData; - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'h') return usage_t55xx_wipe(); + uint32_t password = 0; + bool usepwd = false; + bool Q5 = false; + uint8_t cmdp = 0; + bool errors = false; - bool Q5 = (cmdp == 'q'); + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_wipe(); + case 'p': + // password used by handheld cloners + password = param_get32ex(Cmd, cmdp + 1, 0x51243648, 16); + usepwd = true; + cmdp += 2; + break; + case 'q': + Q5 = true; + cmdp++; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } + } + + if (errors) return usage_t55xx_wipe(); // Try with the default password to reset block 0 // With a pwd should work even if pwd bit not set PrintAndLogEx(INFO, "\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n"); - if (Q5) - snprintf(ptrData, sizeof(writeData), "b 0 d 6001F004 p 0"); - else - snprintf(ptrData, sizeof(writeData), "b 0 d 000880E0 p 0"); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Warning: error writing blk 0"); + if (usepwd) { + snprintf(ptrData, sizeof(writeData), "b 0 p %08x ", password); + } else { + snprintf(ptrData, sizeof(writeData), "b 0 "); + } + + if (Q5) + snprintf(ptrData + strlen(ptrData), sizeof(writeData) - strlen(ptrData), "d 6001F004"); + else + snprintf(ptrData + strlen(ptrData), sizeof(writeData) - strlen(ptrData), "d 000880E0"); + + PrintAndLogEx(INFO, "%s", ptrData); + return 0; + + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) + PrintAndLogEx(WARNING, "Warning: error writing blk 0"); for (uint8_t blk = 1; blk < 8; blk++) { snprintf(ptrData, sizeof(writeData), "b %d d 0", blk); - if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Warning: error writing blk %d", blk); + if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) + PrintAndLogEx(WARNING, "Warning: error writing blk %d", blk); memset(writeData, 0x00, sizeof(writeData)); } @@ -2040,44 +2149,52 @@ static bool IsCancelled(void) { // load a default pwd file. static int CmdT55xxChkPwds(const char *Cmd) { - char filename[FILE_PATH_SIZE] = {0}; - bool found = false; + char filename[FILE_PATH_SIZE] = {0}; + bool found = false; uint8_t timeout = 0; uint8_t *keyBlock = NULL; - bool from_flash = false; - bool try_all_dl_modes = false; + bool from_flash = false; + bool try_all_dl_modes = false; uint8_t downlink_mode = 0; - int len; - char cmdp; - bool use_pwd_file = false; - int dl_mode; // to try each downlink mode for each password + bool use_pwd_file = false; + int dl_mode; // to try each downlink mode for each password + uint8_t cmdp = 0; + bool errors = false; - - cmdp = tolower(param_getchar(Cmd, 0)); - - if (cmdp == 'h') return usage_t55xx_chk(); - if (cmdp == 'm') { - from_flash = true; - Cmd += 2; - cmdp = tolower(param_getchar(Cmd, 0)); - } - if (cmdp == 'r') { - Cmd += 2; - downlink_mode = param_getchar(Cmd, 0) - '0'; // get 2nd option, as this is fixed order. - if (downlink_mode == 4) try_all_dl_modes = true; - if (downlink_mode > 3) downlink_mode = 0; - Cmd += 2; - cmdp = param_getchar(Cmd, 0); - } - if (cmdp == 'i') { - Cmd += 2; - len = strlen(Cmd); - if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE; - memcpy(filename, Cmd, len); - use_pwd_file = true; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_chk(); + case 'r': + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode == 4) + try_all_dl_modes = true; + + if (downlink_mode > 3) + downlink_mode = 0; + + cmdp += 2; + break; + case 'm': + from_flash = true; + cmdp++; + break; + case 'i': + if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename)) == 0 ) { + PrintAndLogEx(ERR, "Error, no filename after 'f' was found"); + errors = true; + } + use_pwd_file = true; + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } - + if (errors) return usage_t55xx_chk(); /* // block 7, page1 = false, usepwd = false, override = false, pwd = 00000000 @@ -2191,33 +2308,48 @@ out: static int CmdT55xxBruteForce(const char *Cmd) { uint32_t start_password = 0x00000000; //start password - uint32_t end_password = 0xFFFFFFFF; //end password - uint32_t curr = 0; - uint8_t downlink_mode = 0; - uint8_t cmd_opt_idx = 0; - uint8_t found = 0; // > 0 if found xx1 xx downlink needed, 1 found + uint32_t end_password = 0xFFFFFFFF; //end password + uint32_t curr = 0; + uint8_t downlink_mode = 0; + uint8_t found = 0; // > 0 if found xx1 xx downlink needed, 1 found + uint8_t cmdp = 0; + bool errors = false; - char cmdp = tolower(param_getchar(Cmd, cmd_opt_idx)); - - if (cmdp == 'h') return usage_t55xx_bruteforce(); - if (cmdp == 'r') { // downlink mode supplied - cmd_opt_idx++; // skip over 'r' - downlink_mode = param_getchar(Cmd, cmd_opt_idx++) - '0'; - if (downlink_mode > 4) downlink_mode = 0; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_bruteforce(); + case 'r': + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 4) + downlink_mode = 0; + + cmdp += 2; + break; + case 's': + start_password = param_get32ex(Cmd, cmdp + 1, 0, 16); + cmdp += 2; + break; + case 'e': + end_password = param_get32ex(Cmd, cmdp + 1, 0, 16); + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } - - - uint64_t t1 = msclock(); - - start_password = param_get32ex(Cmd, cmd_opt_idx++, 0, 16); - end_password = param_get32ex(Cmd, cmd_opt_idx++, 0, 16); - - curr = start_password; - if (start_password >= end_password) { return usage_t55xx_bruteforce(); } + if (errors) return usage_t55xx_bruteforce(); + + uint64_t t1 = msclock(); + + curr = start_password; + PrintAndLogEx(INFO, "Search password range [%08X -> %08X]", start_password, end_password); while (found == 0) { @@ -2278,25 +2410,41 @@ uint8_t tryOnePassword(uint32_t password, uint8_t downlink_mode) { } static int CmdT55xxRecoverPW(const char *Cmd) { - int bit = 0; + int bit = 0; uint32_t orig_password = 0x0; uint32_t curr_password = 0x0; uint32_t prev_password = 0xffffffff; - uint32_t mask = 0x0; - uint8_t downlink_mode = 0; - uint8_t found = 0; - uint8_t cmd_opt_idx = 0; + uint32_t mask = 0x0; + uint8_t downlink_mode = 0; + uint8_t found = 0; + uint8_t cmdp = 0; + bool errors = false; - char cmdp = tolower(param_getchar(Cmd, cmd_opt_idx)); - - if (cmdp == 'h') return usage_t55xx_recoverpw(); - if (cmdp == 'r') { // downlink mode supplied - cmd_opt_idx++; // skip over 'r' - downlink_mode = param_getchar(Cmd, cmd_opt_idx++) - '0'; - if (downlink_mode > 4) downlink_mode = 0; + while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { + switch (tolower(param_getchar(Cmd, cmdp))) { + case 'h': + return usage_t55xx_recoverpw(); + case 'p': + // password used by handheld cloners + orig_password = param_get32ex(Cmd, cmdp + 1, 0x51243648, 16); + cmdp += 2; + break; + case 'r': + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 4) + downlink_mode = 0; + + cmdp += 2; + break; + default: + PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + errors = true; + break; + } } - orig_password = param_get32ex(Cmd, cmd_opt_idx++, 0x51243648, 16); //password used by handheld cloners + if (errors) return usage_t55xx_recoverpw(); + // first try fliping each bit in the expected password while (bit < 32) { @@ -2511,9 +2659,13 @@ static int CmdT55xxDetectPage1(const char *Cmd) { cmdp++; break; case 'r': - downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; - if (downlink_mode == 4) try_all_dl_modes = true; - if (downlink_mode > 3) downlink_mode = 0; + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode == 4) + try_all_dl_modes = true; + + if (downlink_mode > 3) + downlink_mode = 0; + cmdp += 2; break; default: @@ -2589,8 +2741,10 @@ static int CmdT55xxSetDeviceConfig(const char *Cmd) { cmdp += 2; break; case 'r': - downlink_mode = param_getchar(Cmd, cmdp + 1) - '0'; - if (downlink_mode > 3) downlink_mode = 0; + downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); + if (downlink_mode > 3) + downlink_mode = 0; + cmdp += 2; break; case 'p': From 4eab354f448a87c2426a707639af5c1d1a97b2b8 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 17:37:36 +0200 Subject: [PATCH 332/347] chg: 'lf samyrun' standalone - rework of LED messages. A = bank A reading B = bank B reading A,C = bank A simulating A,D = bank A cloning B,C = bank B simulating B,D = bank B cloning One button press to go between steps. Maybe practice with the proxmark3 device connected with usb-cable to see the new steps. --- armsrc/Standalone/lf_samyrun.c | 184 +++++++++++++++------------------ 1 file changed, 82 insertions(+), 102 deletions(-) diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index 8228db512..5e1a35c73 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -24,131 +24,111 @@ void ModInfo(void) { } // samy's sniff and repeat routine for LF + +// LEDS. +// A , B == which bank (recording) +// FLASHING A, B = clone bank +// C = playing bank A +// D = playing bank B + void RunMod() { StandAloneMode(); - Dbprintf(">> LF HID Read/Clone/Sim a.k.a SamyRun Started <<"); FpgaDownloadAndGo(FPGA_BITSTREAM_LF); + Dbprintf(">> LF HID Read/Clone/Sim a.k.a SamyRun Started <<"); uint32_t high[OPTS], low[OPTS]; int selected = 0; - int playing = 0; - int cardRead = 0; - bool gotCard; - // Turn on selected LED - LED(selected + 1, 0); +#define STATE_READ 0 +#define STATE_SIM 1 +#define STATE_CLONE 2 + + uint8_t state = STATE_READ; + for (;;) { + WDT_HIT(); - + // exit from SamyRun, send a usbcommand. if (data_available()) break; // Was our button held down or pressed? - int button_pressed = BUTTON_HELD(1000); + int button_pressed = BUTTON_HELD(280); + if ( button_pressed != BUTTON_HOLD ) + continue; +/* +#define BUTTON_NO_CLICK 0 +#define BUTTON_SINGLE_CLICK -1 +#define BUTTON_DOUBLE_CLICK -2 +*/ - Dbprintf("button %d", button_pressed); - SpinDelay(300); + if ( state == STATE_READ ) { - // Button was held for a second, begin recording - if (button_pressed > 0 && cardRead == 0) { - LEDsoff(); - LED(selected + 1, 0); - LED(LED_D, 0); + if (selected == 0) { + LED_A_ON(); + LED_B_OFF(); + } else { + LED_B_ON(); + LED_A_OFF(); + } + + LED_C_OFF(); + LED_D_OFF(); + WAIT_BUTTON_RELEASED(); + // record DbpString("[=] starting recording"); - // wait for button to be released - while (BUTTON_PRESS()) - WDT_HIT(); + // findone, high, low, no ledcontrol (A) + uint32_t hi = 0, lo = 0; + CmdHIDdemodFSK(1, &hi, &lo, 0); + high[selected] = hi; + low[selected] = lo; + + Dbprintf("[=] recorded bank %x | %x%08x", selected, high[selected], low[selected]); - /* need this delay to prevent catching some weird data */ - SpinDelay(500); - - CmdHIDdemodFSK(1, &high[selected], &low[selected], 0); - Dbprintf("[=] recorded bank %x | %x %08x", selected, high[selected], low[selected]); - - LEDsoff(); - LED(selected + 1, 0); - // Finished recording - // If we were previously playing, set playing off - // so next button push begins playing what we recorded - playing = 0; - cardRead = 1; - - gotCard = true; - } else if (button_pressed > 0 && cardRead == 1) { - LEDsoff(); - LED(selected + 1, 0); - LED(LED_A, 0); - - // record - Dbprintf("[=] cloning %x %x %08x", selected, high[selected], low[selected]); - - // wait for button to be released - while (BUTTON_PRESS()) - WDT_HIT(); - - /* need this delay to prevent catching some weird data */ - SpinDelay(500); - - CopyHIDtoT55x7(0, high[selected], low[selected], 0); - Dbprintf("[=] cloned %x %x %08x", selected, high[selected], low[selected]); - - LEDsoff(); - LED(selected + 1, 0); - // Finished recording - - // If we were previously playing, set playing off - // so next button push begins playing what we recorded - playing = 0; - cardRead = 0; - } - - // Change where to record (or begin playing) - else if (button_pressed && gotCard) { - // Next option if we were previously playing - if (playing) - selected = (selected + 1) % OPTS; - - playing = !playing; - - LEDsoff(); - LED(selected + 1, 0); - - // Begin transmitting - if (playing) { - - LED(LED_B, 0); - DbpString("[=] playing"); - - // wait for button to be released - while (BUTTON_PRESS()) - WDT_HIT(); - - Dbprintf("[=] %x %x %08x", selected, high[selected], low[selected]); - CmdHIDsimTAG(high[selected], low[selected], false); - DbpString("[=] done playing"); - - if (BUTTON_HELD(1000) > 0) - goto out; - - /* We pressed a button so ignore it here with a delay */ - SpinDelay(300); - - // when done, we're done playing, move to next option - selected = (selected + 1) % OPTS; - playing = !playing; - LEDsoff(); - LED(selected + 1, 0); - } else { - while (BUTTON_PRESS()) - WDT_HIT(); + // got nothing. blink and loop. + if ( hi == 0 && lo == 0 ) { + SpinErr( (selected == 0) ? LED_A : LED_B, 100, 12); + Dbprintf("[=] recorded nothing, looping"); + continue; } + + state = STATE_SIM; + continue; + + } else if ( state == STATE_SIM ) { + + LED_C_ON(); // Simulate + LED_D_OFF(); + WAIT_BUTTON_RELEASED(); + + Dbprintf("[=] simulating %x | %x%08x", selected, high[selected], low[selected]); + + // high, low, no led control(A) no time limit + CmdHIDsimTAGEx(high[selected], low[selected], false, -1); + state = STATE_CLONE; + continue; + + } else if ( state == STATE_CLONE ) { + + LED_C_OFF(); + LED_D_ON(); // clone + WAIT_BUTTON_RELEASED(); + + Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]); + + // high2, high, low, no longFMT + CopyHIDtoT55x7(0, high[selected], low[selected], 0); + state = STATE_READ; + + selected = (selected + 1) % OPTS; + + LEDsoff(); } } -out: - DbpString("[=] exiting"); + DbpString("[=] exiting samyrun"); LEDsoff(); } From 75f4a6123c623d67ecb9ad979ca29592777d3058 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 17:38:13 +0200 Subject: [PATCH 333/347] textual --- armsrc/lfops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index bee1413fc..6addf000e 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -1306,7 +1306,7 @@ void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) hi2 = hi = lo = idx = 0; } FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - DbpString("Stopped"); + DbpString("HID fsk demod stopped"); if (ledcontrol) LED_A_OFF(); } From 74cd1bee3513b8970ad9765cc8b5f9851ec7b406 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 17:39:12 +0200 Subject: [PATCH 334/347] minor --- armsrc/mifarecmd.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index e8263d52a..e8cce812f 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1997,19 +1997,19 @@ void MifareCIdent() { // Generation 1 test ReaderTransmitBitsPar(wupC1, 7, NULL, NULL); - if (!ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) { - goto TEST2; - }; + + if (ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) { - ReaderTransmit(wupC2, sizeof(wupC2), NULL); - if (!ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) { - isGen = GEN_1B; - goto OUT; - }; - isGen = GEN_1A; - goto OUT; + ReaderTransmit(wupC2, sizeof(wupC2), NULL); + + if (!ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) { + isGen = GEN_1B; + goto OUT; + }; + isGen = GEN_1A; + goto OUT; + } -TEST2: // reset card FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); SpinDelay(100); @@ -2017,6 +2017,7 @@ TEST2: int res = iso14443a_select_card(uid, NULL, &cuid, true, 0, true); if (res == 2) { + Dbprintf("cident AA55C396 == %08X", cuid); if (cuid == 0xAA55C396) { isGen = GEN_UNFUSED; goto OUT; From a5bcecd05c582512b3cb5ee2727611ed300065b8 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 17:39:57 +0200 Subject: [PATCH 335/347] wait define.. --- include/proxmark3_arm.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/proxmark3_arm.h b/include/proxmark3_arm.h index a2f76e93d..3ea80da9d 100644 --- a/include/proxmark3_arm.h +++ b/include/proxmark3_arm.h @@ -90,6 +90,7 @@ #define LED_D_OFF() LOW(GPIO_LED_D) #define LED_D_INV() INVBIT(GPIO_LED_D) + // SPI #define SCK_LOW LOW(GPIO_SPCK) #define SCK_HIGH HIGH(GPIO_SPCK) @@ -107,7 +108,9 @@ #define RELAY_ON() HIGH(GPIO_RELAY) #define RELAY_OFF() LOW(GPIO_RELAY) -#define BUTTON_PRESS() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_BUTTON) == GPIO_BUTTON) + +#define BUTTON_PRESS() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_BUTTON) == GPIO_BUTTON) +#define WAIT_BUTTON_RELEASED() { while ( BUTTON_PRESS() ) { WDT_HIT(); }; } //NVDD goes LOW when USB is attached. #define USB_ATTACHED() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_NVDD_ON) == GPIO_NVDD_ON) From da68369e0258fd759b58e9eeb220200ca737ffd8 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 12 Sep 2019 19:49:42 +0200 Subject: [PATCH 336/347] fix issue #397 --- armsrc/appmain.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index a4b1c45bc..45b53c985 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1212,11 +1212,7 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_HF_ICLASS_READER: { - struct p { - uint8_t flags; - } PACKED; - struct p *payload = (struct p *)packet->data.asBytes; - ReaderIClass(payload->flags); + ReaderIClass(packet->oldarg[0]); break; } case CMD_HF_ICLASS_REPLAY: { From 46574ae0f5a3f21f4b9e694da60068e4e80d3bcd Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 12 Sep 2019 20:13:01 +0200 Subject: [PATCH 337/347] add get_my_user_directory() to centralize HOME processing --- client/fileutils.c | 10 +++++----- client/proxmark3.c | 17 ++++++++++++++--- client/proxmark3.h | 1 + client/scripting.c | 2 +- client/ui.c | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 8e0e3bb72..23553d15c 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -850,10 +850,10 @@ int searchAndList(const char *pm3dir, const char *ext) { filelist(script_directory_path, ext, false, true); } // try pm3 dirs in user .proxmark3 (user mode) - char *userpath = getenv("HOME"); - if (userpath != NULL) { - char script_directory_path[strlen(userpath) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + 1]; - strcpy(script_directory_path, userpath); + const char *user_path = get_my_user_directory(); + if (user_path != NULL) { + char script_directory_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + 1]; + strcpy(script_directory_path, user_path); strcat(script_directory_path, PM3_USER_DIRECTORY); strcat(script_directory_path, pm3dir); filelist(script_directory_path, ext, false, false); @@ -904,7 +904,7 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea } } // try pm3 dirs in user .proxmark3 (user mode) - char *user_path = getenv("HOME"); + const char *user_path = get_my_user_directory(); if (user_path != NULL) { char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) diff --git a/client/proxmark3.c b/client/proxmark3.c index aa37cda9a..b07884b91 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -315,6 +315,16 @@ static void set_my_executable_path(void) { } } +static char *my_user_directory = NULL; + +const char *get_my_user_directory(void) { + return my_user_directory; +} + +static void set_my_user_directory(void) { + my_user_directory = getenv("HOME"); +} + static void show_help(bool showFullHelp, char *exec_name) { PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m]", exec_name); @@ -486,6 +496,10 @@ int main(int argc, char *argv[]) { int flash_num_files = 0; char *flash_filenames[FLASH_MAX_FILES]; + // set global variables soon enough to get the log path + set_my_executable_path(); + set_my_user_directory(); + for (int i = 1; i < argc; i++) { if (argv[i][0] != '-') { @@ -685,9 +699,6 @@ int main(int argc, char *argv[]) { if (speed == 0) speed = USART_BAUD_RATE; - // set global variables - set_my_executable_path(); - if (flash_mode) { flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl); exit(EXIT_SUCCESS); diff --git a/client/proxmark3.h b/client/proxmark3.h index c370efdff..9313e4c28 100644 --- a/client/proxmark3.h +++ b/client/proxmark3.h @@ -30,6 +30,7 @@ extern "C" { int push_cmdscriptfile(char *path, bool stayafter); const char *get_my_executable_path(void); const char *get_my_executable_directory(void); +const char *get_my_user_directory(void); void main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop); #ifdef __cplusplus diff --git a/client/scripting.c b/client/scripting.c index 724f72235..6e35f809f 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1173,7 +1173,7 @@ int set_pm3_libraries(lua_State *L) { strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); } - char *user_path = getenv("HOME"); + const char *user_path = get_my_user_directory(); if (user_path != NULL) { // from the $HOME/.proxmark3/luascripts/ directory char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; diff --git a/client/ui.c b/client/ui.c index 883ea963a..d12713b9b 100644 --- a/client/ui.c +++ b/client/ui.c @@ -49,7 +49,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...); int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) { if (foundpath == NULL) return PM3_EINVARG; - char *user_path = getenv("HOME"); + const char *user_path = get_my_user_directory(); if (user_path == NULL) { fprintf(stderr, "Could not retrieve $HOME from the environment\n"); return PM3_EFILE; From ed5fed8fac22d97c05fdda8d446c3e0fe0be3e34 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 12 Sep 2019 20:16:52 +0200 Subject: [PATCH 338/347] Attempt to fallback to current directory if no HOME in env --- client/proxmark3.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/proxmark3.c b/client/proxmark3.c index b07884b91..2ff94b841 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -323,6 +323,9 @@ const char *get_my_user_directory(void) { static void set_my_user_directory(void) { my_user_directory = getenv("HOME"); + // if not found, default to current directory + if (my_user_directory == NULL) + my_user_directory = "."; } static void show_help(bool showFullHelp, char *exec_name) { From 3821a03a4000feeea75fe5ca64f43d9bf27d6162 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 12 Sep 2019 21:20:40 +0200 Subject: [PATCH 339/347] chg: 'lf t55xx wipe p' - now takes a password for wipe chg: 'lf t55xx wakeup' - uses NG --- armsrc/appmain.c | 7 ++- armsrc/lfops.c | 1 + client/cmdlft55xx.c | 102 +++++++++++++++++++------------------------- 3 files changed, 50 insertions(+), 60 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 45b53c985..6194cfe39 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -797,7 +797,12 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_LF_T55XX_WAKEUP: { - T55xxWakeUp(packet->oldarg[0], packet->oldarg[1]); + struct p { + uint32_t password; + uint8_t flags; + } PACKED; + struct p *payload = (struct p *) packet->data.asBytes; + T55xxWakeUp(payload->password, payload->flags); break; } case CMD_LF_T55XX_RESET_READ: { diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 6addf000e..3277100b0 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -2060,6 +2060,7 @@ void T55xxWakeUp(uint32_t pwd, uint8_t flags) { //-- Turn and leave field on to let the begin repeating transmission TurnReadLFOn(20 * 1000); + reply_ng(CMD_LF_T55XX_WAKEUP, PM3_SUCCESS, NULL, 0); } diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 320b193b6..cefb40cc6 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -493,7 +493,7 @@ static int CmdT55xxReadBlock(const char *Cmd) { break; } } - if (errors) return usage_t55xx_read(); + if (errors || cmdp == 0) return usage_t55xx_read(); if (block > 7 && block != REGULAR_READ_MODE_BLOCK) { PrintAndLogEx(NORMAL, "Block must be between 0 and 7"); @@ -611,11 +611,9 @@ static int CmdT55xxDetect(const char *Cmd) { bool useGB = false; bool usepwd = false; bool try_all_dl_modes = false; - bool found = false; uint32_t password = 0; uint8_t cmdp = 0; uint8_t downlink_mode = 0; - uint8_t dl_mode = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -627,18 +625,15 @@ static int CmdT55xxDetect(const char *Cmd) { cmdp += 2; break; case '1': - // use Graphbuffer data useGB = true; cmdp++; break; case 'r': downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); - if (downlink_mode == 4) + if (downlink_mode >= 4) { try_all_dl_modes = true; - - if (downlink_mode > 3) - downlink_mode = 0; - + downlink_mode = 4; + } cmdp += 2; break; default: @@ -650,48 +645,32 @@ static int CmdT55xxDetect(const char *Cmd) { if (errors) return usage_t55xx_detect(); // sanity check. - if (SanityOfflineCheck(useGB) != PM3_SUCCESS) return PM3_ENODATA; + if (SanityOfflineCheck(useGB) != PM3_SUCCESS) + return PM3_ESOFT; - if (!useGB) { - for (dl_mode = downlink_mode; dl_mode < 4; dl_mode++) { - found = AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password, dl_mode); + if (useGB == false) { + if ( try_all_dl_modes ) { + for (uint8_t mode = 0; mode < 4; mode++) { + + if ( AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password, mode) == false ) { + continue; + } - // found = false if password is supplied but wrong d/l mode - // so keep trying other modes (if requested) - /* - if (!found) { - printf ("Aquire not found"); - return PM3_ENODATA; + if (tryDetectModulation()) { + T55xx_Print_DownlinkMode(mode); + return PM3_SUCCESS; + } } - */ - if (tryDetectModulation()) { - T55xx_Print_DownlinkMode(dl_mode); - dl_mode = 4; - found = true; - } else found = false; - - if (!try_all_dl_modes) dl_mode = 4; + return PM3_ESOFT; + } else { + if ( AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password, downlink_mode) == false ) + return PM3_ENODATA; } } - - if (useGB) found = tryDetectModulation(); - - if (!found) + if (tryDetectModulation() == false) PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'")); - - /* - if (!useGB) { - if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password,downlink_mode)) - return PM3_ENODATA; - } - if (!tryDetectModulation()) - PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'")); - else - T55xx_Print_DownlinkMode (downlink_mode); - */ - return PM3_SUCCESS; } // detect configuration? @@ -1142,7 +1121,6 @@ static int CmdT55xxWakeUp(const char *Cmd) { uint8_t cmdp = 0; bool errors = false; uint8_t downlink_mode = 0; - uint8_t flags = 0; while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { switch (tolower(param_getchar(Cmd, cmdp))) { @@ -1168,11 +1146,22 @@ static int CmdT55xxWakeUp(const char *Cmd) { if (errors) return usage_t55xx_wakup(); - flags = (downlink_mode & 3) << 3; + struct p { + uint32_t password; + uint8_t flags; + } PACKED payload; + + payload.password = password; + payload.flags = (downlink_mode & 3) << 3; + clearCommandBuffer(); - SendCommandMIX(CMD_LF_T55XX_WAKEUP, password, flags, 0, NULL, 0); + SendCommandNG(CMD_LF_T55XX_WAKEUP, (uint8_t *)&payload, sizeof(payload)); + if (!WaitForResponseTimeout(CMD_LF_T55XX_WAKEUP, NULL, 1000)) { + PrintAndLogEx(WARNING, "command execution time out"); + return PM3_ETIMEOUT; + } + PrintAndLogEx(SUCCESS, "Wake up command sent. Try read now"); - return PM3_SUCCESS; } @@ -1506,7 +1495,7 @@ static void printT5x7KnownBlock0(uint32_t b0) { snprintf(s + strlen(s), sizeof(s) - strlen(s), "FDXB "); break; case T55X7_HID_26_CONFIG_BLOCK: - snprintf(s + strlen(s), sizeof(s) - strlen(s), "HID 26b "); + snprintf(s + strlen(s), sizeof(s) - strlen(s), "HID 26b (ProxCard) "); break; case T55X7_PYRAMID_CONFIG_BLOCK: snprintf(s + strlen(s), sizeof(s) - strlen(s), "Pyramid "); @@ -2073,7 +2062,7 @@ static int CmdResetRead(const char *Cmd) { } static int CmdT55xxWipe(const char *Cmd) { - char writeData[20] = {0}; + char writeData[36] = {0}; char *ptrData = writeData; uint32_t password = 0; bool usepwd = false; @@ -2116,12 +2105,9 @@ static int CmdT55xxWipe(const char *Cmd) { } if (Q5) - snprintf(ptrData + strlen(ptrData), sizeof(writeData) - strlen(ptrData), "d 6001F004"); + snprintf(ptrData + strlen(writeData), sizeof(writeData) - strlen(writeData), "d 6001F004"); else - snprintf(ptrData + strlen(ptrData), sizeof(writeData) - strlen(ptrData), "d 000880E0"); - - PrintAndLogEx(INFO, "%s", ptrData); - return 0; + snprintf(ptrData + strlen(writeData), sizeof(writeData) - strlen(writeData), "d 000880E0"); if (CmdT55xxWriteBlock(ptrData) != PM3_SUCCESS) PrintAndLogEx(WARNING, "Warning: error writing blk 0"); @@ -2167,12 +2153,10 @@ static int CmdT55xxChkPwds(const char *Cmd) { return usage_t55xx_chk(); case 'r': downlink_mode = param_get8ex(Cmd, cmdp + 1, 0, 10); - if (downlink_mode == 4) + if (downlink_mode >= 4) { try_all_dl_modes = true; - - if (downlink_mode > 3) - downlink_mode = 0; - + downlink_mode = 4; + } cmdp += 2; break; case 'm': From 64d2e435928ed0b74a779d07e8fda56f808f85cf Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 13 Sep 2019 00:36:25 +0200 Subject: [PATCH 340/347] CmdFSKsimTAG: avoid padding with very short cycles, this confused lf io sim --- armsrc/lfops.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 3277100b0..b535e155a 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -941,7 +941,7 @@ static void fcSTT(int *n) { } // compose fc/X fc/Y waveform (FSKx) -static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) { +static uint8_t fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) { uint8_t *dest = BigBuf_get_addr(); uint8_t halfFC = fc >> 1; uint8_t wavesPerClock = clock / fc; @@ -966,12 +966,15 @@ static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) { *n += fc; } } +/* This code interfers with FSK2 and I don't see any example of FSK1 simulation in the code... if (!modAdjOk) { //fsk1 memset(dest + (*n), 0, mod - (mod >> 1)); memset(dest + (*n) + (mod - (mod >> 1)), 1, mod >> 1); *n += mod; } +*/ } + return mod; } // prepare a waveform pattern in the buffer based on the ID given then @@ -1059,17 +1062,17 @@ void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, int n = 0, i = 0; uint16_t modCnt = 0; + uint8_t mod = 0; if (separator) { //int fsktype = ( fchigh == 8 && fclow == 5) ? 1 : 2; //fcSTT(&n); } - for (i = 0; i < bitslen; i++) { if (bits[i]) - fcAll(fclow, &n, clk, &modCnt); + mod = fcAll(fclow, &n, clk+mod, &modCnt); else - fcAll(fchigh, &n, clk, &modCnt); + mod = fcAll(fchigh, &n, clk+mod, &modCnt); } WDT_HIT(); From 59ea79b5834d366e92b4e882e1204376d556d1da Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 13 Sep 2019 00:38:04 +0200 Subject: [PATCH 341/347] CmdFSKsimTAG: swap fcH/fcL back, fix lf io/awid/pyramid sim --- armsrc/lfops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index b535e155a..e5204a5a5 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -1070,9 +1070,9 @@ void CmdFSKsimTAG(uint8_t fchigh, uint8_t fclow, uint8_t separator, uint8_t clk, } for (i = 0; i < bitslen; i++) { if (bits[i]) - mod = fcAll(fclow, &n, clk+mod, &modCnt); - else mod = fcAll(fchigh, &n, clk+mod, &modCnt); + else + mod = fcAll(fclow, &n, clk+mod, &modCnt); } WDT_HIT(); From 05e9ac97ae21fd438c955c2b3e460ce97fa14e31 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 13 Sep 2019 00:39:08 +0200 Subject: [PATCH 342/347] fix lf awid sim doc: must be digits --- client/cmdlfawid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index b574af772..2360906a4 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -58,7 +58,7 @@ static int usage_lf_awid_sim(void) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf awid sim 26 224 1337"); - PrintAndLogEx(NORMAL, " lf awid sim 50 2001 deadc0de"); + PrintAndLogEx(NORMAL, " lf awid sim 50 2001 13371337"); return PM3_SUCCESS; } From 5e4243e5a1b83d8e8ea3601b580e62c2f40b7dac Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 13 Sep 2019 00:51:18 +0200 Subject: [PATCH 343/347] Disable lf paradox sim, which needs non-existing GetParadoxBits --- client/cmdlfparadox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 8a1a940c5..74e7ce6a1 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -161,7 +161,7 @@ static command_t CommandTable[] = { {"demod", CmdParadoxDemod, AlwaysAvailable, "Demodulate a Paradox FSK tag from the GraphBuffer"}, {"read", CmdParadoxRead, IfPm3Lf, "Attempt to read and Extract tag data from the antenna"}, // {"clone", CmdParadoxClone, IfPm3Lf, "clone paradox tag"}, - {"sim", CmdParadoxSim, IfPm3Lf, "simulate paradox tag"}, +// {"sim", CmdParadoxSim, IfPm3Lf, "simulate paradox tag"}, {NULL, NULL, NULL, NULL} }; From f1b36c0b5a2262259abcae4ae3c4222358a86e47 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 13 Sep 2019 07:30:03 +0200 Subject: [PATCH 344/347] fix paradox sim compilation... --- client/cmdlfparadox.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/cmdlfparadox.c b/client/cmdlfparadox.c index 74e7ce6a1..5ef21992b 100644 --- a/client/cmdlfparadox.c +++ b/client/cmdlfparadox.c @@ -22,7 +22,7 @@ #include "cmdlf.h" #include "lfdemod.h" static int CmdHelp(const char *Cmd); - +/* static int usage_lf_paradox_sim(void) { PrintAndLogEx(NORMAL, "Enables simulation of Paradox card with specified card number."); PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued."); @@ -38,6 +38,7 @@ static int usage_lf_paradox_sim(void) { PrintAndLogEx(NORMAL, " lf paradox sim 123 11223"); return PM3_SUCCESS; } +*/ //by marshmellow //Paradox Prox demod - FSK2a RF/50 with preamble of 00001111 (then manchester encoded) @@ -111,8 +112,12 @@ static int CmdParadoxRead(const char *Cmd) { return CmdParadoxDemod(Cmd); } -static int CmdParadoxSim(const char *Cmd) { +static int CmdParadoxSim(const char *Cmd) { + PrintAndLogEx(INFO," To be implemented, feel free to contribute!"); + return PM3_SUCCESS; +} +/* char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_paradox_sim(); @@ -155,13 +160,13 @@ static int CmdParadoxSim(const char *Cmd) { return resp.status; return PM3_SUCCESS; } - +*/ static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"demod", CmdParadoxDemod, AlwaysAvailable, "Demodulate a Paradox FSK tag from the GraphBuffer"}, {"read", CmdParadoxRead, IfPm3Lf, "Attempt to read and Extract tag data from the antenna"}, // {"clone", CmdParadoxClone, IfPm3Lf, "clone paradox tag"}, -// {"sim", CmdParadoxSim, IfPm3Lf, "simulate paradox tag"}, + {"sim", CmdParadoxSim, IfPm3Lf, "simulate paradox tag"}, {NULL, NULL, NULL, NULL} }; From a4421dfc37efb1022f94d15fd1b33024d67a48d4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 13 Sep 2019 07:38:07 +0200 Subject: [PATCH 345/347] fix wrong spelling --- armsrc/Standalone/hf_colin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index 4997f775e..6a0d9a19d 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -636,7 +636,7 @@ failtag: cjTabulize(); DbprintfEx(FLAG_NEWLINE, "%s[ FAIL ]%s\r\n->did not found all the keys :'(", _XRED_, _XWHITE_); cjSetCursLeft(); - SpinErr(LEB_B, 100, 8); + SpinErr(LED_B, 100, 8); SpinOff(100); return; } From 680d1db9ec1a761bb7c77504bf9ef9cf647c1411 Mon Sep 17 00:00:00 2001 From: Iceman Date: Fri, 13 Sep 2019 09:38:09 +0200 Subject: [PATCH 346/347] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6680f5333..22221abe6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# RRG / Iceman repo - Proxmark3 RDV4.0 and other Proxmark3 platforms. +# RRG / Iceman repo - Proxmark3 This repo is based on iceman fork for Proxmark3. It supports other Proxmark3 platforms as well. From cb23de969461df4c8572ce29c3f1514138f02b2e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 13 Sep 2019 10:04:59 +0200 Subject: [PATCH 347/347] chg: feedback after successful operation. led flashes twice. and whitespace removed --- armsrc/Standalone/lf_samyrun.c | 47 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index 5e1a35c73..f71fef393 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -41,14 +41,14 @@ void RunMod() { #define STATE_READ 0 #define STATE_SIM 1 -#define STATE_CLONE 2 +#define STATE_CLONE 2 uint8_t state = STATE_READ; - + for (;;) { - + WDT_HIT(); - + // exit from SamyRun, send a usbcommand. if (data_available()) break; @@ -65,70 +65,71 @@ void RunMod() { if ( state == STATE_READ ) { if (selected == 0) { - LED_A_ON(); + LED_A_ON(); LED_B_OFF(); - } else { - LED_B_ON(); + } else { + LED_B_ON(); LED_A_OFF(); } - + LED_C_OFF(); LED_D_OFF(); WAIT_BUTTON_RELEASED(); - + // record DbpString("[=] starting recording"); - // findone, high, low, no ledcontrol (A) + // findone, high, low, no ledcontrol (A) uint32_t hi = 0, lo = 0; CmdHIDdemodFSK(1, &hi, &lo, 0); high[selected] = hi; low[selected] = lo; - + Dbprintf("[=] recorded bank %x | %x%08x", selected, high[selected], low[selected]); // got nothing. blink and loop. if ( hi == 0 && lo == 0 ) { - SpinErr( (selected == 0) ? LED_A : LED_B, 100, 12); + SpinErr( (selected == 0) ? LED_A : LED_B, 100, 12); Dbprintf("[=] recorded nothing, looping"); continue; } - + + SpinErr( (select==0) ? LED_A : LED_B, 250, 2); state = STATE_SIM; continue; } else if ( state == STATE_SIM ) { - - LED_C_ON(); // Simulate + + LED_C_ON(); // Simulate LED_D_OFF(); WAIT_BUTTON_RELEASED(); - + Dbprintf("[=] simulating %x | %x%08x", selected, high[selected], low[selected]); // high, low, no led control(A) no time limit - CmdHIDsimTAGEx(high[selected], low[selected], false, -1); + CmdHIDsimTAGEx(high[selected], low[selected], false, -1); + SpinErr( LED_C, 250, 2); state = STATE_CLONE; continue; - + } else if ( state == STATE_CLONE ) { LED_C_OFF(); - LED_D_ON(); // clone + LED_D_ON(); // clone WAIT_BUTTON_RELEASED(); - + Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]); // high2, high, low, no longFMT CopyHIDtoT55x7(0, high[selected], low[selected], 0); state = STATE_READ; - + SpinErr( LED_D, 250, 2); selected = (selected + 1) % OPTS; - LEDsoff(); } } - DbpString("[=] exiting samyrun"); + DbpString("[=] exiting samyrun"); LEDsoff(); }