From d746847d134f9272c4c7565e9242c38b32e990a3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 17:58:47 +0200 Subject: [PATCH 1/7] proxmark3.sh for WSL: handle case when chmod is needed --- .../Windows-Installation-Instructions.md | 1 + proxmark3.sh | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md index eacdc4b62..db9a9084f 100644 --- a/doc/md/Installation_Instructions/Windows-Installation-Instructions.md +++ b/doc/md/Installation_Instructions/Windows-Installation-Instructions.md @@ -166,3 +166,4 @@ Or, by specifying the COM port manually: client/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/proxmark3.sh b/proxmark3.sh index 39eb80779..b45887a23 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -51,6 +51,10 @@ function wait4proxmark_WSL { fi sleep .1 done + if [ -e "$PM3" ] && ! [ -w "$PM3" ]; then + echo "We need to give current user read/write access to $PM3" + sudo chmod 666 "$PM3" + fi echo $PM3 } From 82e0568e65abf13af613f28c4ed418de4b78f8e5 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 18:20:41 +0200 Subject: [PATCH 2/7] shellcheck bash scripts --- flash-all.sh | 3 ++- flash-bootrom.sh | 3 ++- flash-fullimage.sh | 3 ++- proxmark3.sh | 40 +++++++++++++++++++--------------------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/flash-all.sh b/flash-all.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-all.sh +++ b/flash-all.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/flash-bootrom.sh b/flash-bootrom.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-bootrom.sh +++ b/flash-bootrom.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/flash-fullimage.sh b/flash-fullimage.sh index 27e1fb526..d4fcdc975 100755 --- a/flash-fullimage.sh +++ b/flash-fullimage.sh @@ -1,4 +1,5 @@ #!/bin/bash -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 . proxmark3.sh diff --git a/proxmark3.sh b/proxmark3.sh index b45887a23..b8d6acabb 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -3,28 +3,31 @@ FULLIMAGE="armsrc/obj/fullimage.elf" BOOTIMAGE="bootrom/obj/bootrom.elf" -cd $(dirname "$0") +PM3PATH=$(dirname "$0") +cd "$PM3PATH" || exit 1 function wait4proxmark_Linux { echo >&2 "Waiting for Proxmark to appear..." - while [ ! -c /dev/ttyACM? -a ! -c /dev/pm3-? ]; do + while true; do + PM3=$(find /dev/pm3-* /dev/ttyACM* 2>/dev/null | head -1) + if [[ $PM3 != "" ]]; then + break + fi sleep .1 done - local PM3=`ls -1 /dev/pm3-? /dev/ttyACM? 2>/dev/null | head -1` - echo $PM3 + echo "$PM3" } function wait4proxmark_macOS { echo >&2 "Waiting for Proxmark to appear..." while true; do - PM3=$(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) + PM3=$(find /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1) if [[ $PM3 != "" ]]; then - #echo >&2 -e "Found proxmark on $(ls /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1)\n" break fi sleep .1 done - echo $PM3 + echo "$PM3" } function wait4proxmark_Windows { @@ -37,7 +40,7 @@ function wait4proxmark_Windows { fi sleep .1 done - echo $PM3 + echo "$PM3" } function wait4proxmark_WSL { @@ -51,27 +54,23 @@ function wait4proxmark_WSL { fi sleep .1 done - if [ -e "$PM3" ] && ! [ -w "$PM3" ]; then + if [ -e "$PM3" ] && [ ! -w "$PM3" ]; then echo "We need to give current user read/write access to $PM3" sudo chmod 666 "$PM3" fi - echo $PM3 + echo "$PM3" } SCRIPT=$(basename -- "$0") if [ "$SCRIPT" = "proxmark3.sh" ]; then - CMD=client/proxmark3 + CMD() { client/proxmark3 "$@"; } elif [ "$SCRIPT" = "flash-all.sh" ]; then - CMD=client/flasher - ARG1="-b $BOOTIMAGE" - ARG2="$FULLIMAGE" -elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then - CMD=client/flasher - ARG2="$FULLIMAGE" + CMD() { client/flasher "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; } +elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then CMD=client/flasher + CMD() { client/flasher "$1" "$FULLIMAGE"; } elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then - CMD=client/flasher - ARG1="-b $BOOTIMAGE" + CMD() { client/flasher "$1" -b "$BOOTIMAGE"; } else echo "Script ran under unknown name, abort: $SCRIPT" exit 1 @@ -96,6 +95,5 @@ if [ "$PORT" = "" ]; then exit 1 fi -#echo Running "$CMD" "$PORT" $ARG1 $ARG2 "$@" -"$CMD" "$PORT" $ARG1 $ARG2 "$@" +CMD "$PORT" "$@" exit $? From fee9c0ef847b8b7471d7e7af3cbf17fcb9fa4ee8 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 18:26:04 +0200 Subject: [PATCH 3/7] silent uart_close error message as it can be called from uart_open failing modes, e.g. when waiting for port to appear --- uart/uart_posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 22cc75207..ea535fd73 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -238,7 +238,8 @@ void uart_close(const serial_port sp) { // Does the system allows us to place a lock on this file descriptor int err = fcntl(spu->fd, F_SETLK, &fl); if (err == -1) { - printf("[!] UART error while closing port\n"); + //silent error message as it can be called from uart_open failing modes, e.g. when waiting for port to appear + //printf("[!] UART error while closing port\n"); } close(spu->fd); free(sp); From 383d3327be40c3a276971bd0b371d9b3520b1dac Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 18:42:11 +0200 Subject: [PATCH 4/7] remove spurious changes in make style --- Makefile | 4 ++-- client/fpga_compress.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 910aa62f6..64dbea4eb 100644 --- a/Makefile +++ b/Makefile @@ -145,12 +145,12 @@ style: # Make sure astyle is installed @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 ) # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile - find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ + find . \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \ -exec perl -pi -e 's/[ \t]+$$//' {} \; \ -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \ -exec sh -c "echo >> {}" \; # Apply astyle on *.c, *.h, *.cpp - find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \ + find . \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) \) -exec astyle --formatted --mode=c --suffix=none \ --indent=spaces=4 --indent-switches \ --keep-one-line-blocks --max-instatement-indent=60 \ --style=google --pad-oper --unpad-paren --pad-header \ diff --git a/client/fpga_compress.c b/client/fpga_compress.c index 7cd4652e1..a030afe81 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -375,7 +375,7 @@ static void print_version_info_preamble(FILE *outfile, int num_infiles) { fprintf(outfile, "\n"); fprintf(outfile, "\n"); fprintf(outfile, "const int fpga_bitstream_num = %d;\n", num_infiles); - fprintf(outfile, "const char* const fpga_version_information[%d] = {\n", num_infiles); + fprintf(outfile, "const char *const fpga_version_information[%d] = {\n", num_infiles); } static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int num_infiles, FILE *outfile) { @@ -386,7 +386,7 @@ static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int for (int i = 0; i < num_infiles; i++) { FpgaGatherVersion(infile[i], infile_names[i], version_string, sizeof(version_string)); - fprintf(outfile, "\t\" %s\"", version_string); + fprintf(outfile, " \" %s\"", version_string); if (i != num_infiles - 1) { fprintf(outfile, ","); } From f6f7e7a9f62de7ef37e44b2001a50f4c6900219b Mon Sep 17 00:00:00 2001 From: Eloff Date: Sun, 14 Jul 2019 23:12:39 +0300 Subject: [PATCH 5/7] hf_mf_sim. Really tags not respond NACK on invalid authentication --- armsrc/mifaresim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 8f21882be..36f5c3593 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -1036,8 +1036,9 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { ); } cardAUTHKEY = AUTHKEYNONE; // not authenticated - EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA)); cardSTATE_TO_IDLE(); + // Really tags not respond NACK on invalid authentication + LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true); break; } From 055efaff88b5f387d2cbaaee1bf2dcd1045d7b1e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 14 Jul 2019 22:13:40 +0200 Subject: [PATCH 6/7] proxmark.sh: remove leftover var --- proxmark3.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxmark3.sh b/proxmark3.sh index b8d6acabb..4cd6d76bc 100755 --- a/proxmark3.sh +++ b/proxmark3.sh @@ -67,7 +67,7 @@ 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 +elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then CMD() { client/flasher "$1" "$FULLIMAGE"; } elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then CMD() { client/flasher "$1" -b "$BOOTIMAGE"; } From a28e359095f395ee7153c1eeda39d825bb35be97 Mon Sep 17 00:00:00 2001 From: Eloff Date: Sun, 14 Jul 2019 23:18:07 +0300 Subject: [PATCH 7/7] Fix. More flexible anti-collision frame check --- armsrc/mifaresim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index 8f21882be..f17381ecd 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -625,7 +625,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) { } // Incoming anti-collision frame - if (receivedCmd_len >= 2 && receivedCmd_len <= 6 && receivedCmd[1] == 0x50) { + // receivedCmd[1] indicates number of byte and bit collision, supports only for bit collision is zero + if (receivedCmd_len >= 3 && receivedCmd_len <= 6 && (receivedCmd[1] & 0x0f) == 0) { // we can process only full-byte frame anti-collision procedure if (memcmp(&receivedCmd[2], responses[uid_index].response, receivedCmd_len - 2) == 0) { // response missing part of UID via relative array index