proxmark3/pm3

202 lines
5.7 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2019-09-09 18:58:11 +08:00
# Usage: run option -h to get help
2019-07-15 00:20:41 +08:00
PM3PATH=$(dirname "$0")
# 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
2018-08-17 00:31:12 +08:00
function wait4proxmark_Linux {
2019-08-19 01:25:09 +08:00
echo >&2 "[=] Waiting for Proxmark3 to appear..."
2019-07-15 00:20:41 +08:00
while true; do
PM3=$(find /dev/pm3-* /dev/ttyACM* 2>/dev/null | head -1)
if [[ $PM3 != "" ]]; then
break
fi
2019-03-09 18:10:22 +08:00
sleep .1
done
2019-07-15 00:20:41 +08:00
echo "$PM3"
}
function wait4proxmark_macOS {
2019-08-19 01:25:09 +08:00
echo >&2 "[=] Waiting for Proxmark3 to appear..."
2019-03-09 18:10:22 +08:00
while true; do
PM3=$(find /dev/pm3-* /dev/tty.usbmodem* 2>/dev/null | head -1)
2019-03-09 18:10:22 +08:00
if [[ $PM3 != "" ]]; then
break
fi
sleep .1
done
2019-07-15 00:20:41 +08:00
echo "$PM3"
}
function wait4proxmark_Windows {
2019-08-19 01:25:09 +08:00
echo >&2 "[=] Waiting for Proxmark3 to appear..."
while true; do
2019-07-06 21:31:32 +08:00
device=$(wmic path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2')
if [[ $device != "" ]]; then
PM3=${device/ */}
break
fi
sleep .1
done
2019-07-15 00:20:41 +08:00
echo "$PM3"
}
2019-07-13 06:06:19 +08:00
function wait4proxmark_WSL {
2019-08-19 01:25:09 +08:00
echo >&2 "[=] Waiting for Proxmark3 to appear..."
2019-07-13 06:06:19 +08:00
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
PM3=${device/ */}
PM3="/dev/ttyS${PM3#COM}"
break
fi
sleep .1
done
2019-07-15 00:20:41 +08:00
if [ -e "$PM3" ] && [ ! -w "$PM3" ]; then
2019-08-13 04:31:27 +08:00
echo "[!!] We need to give current user read/write access to $PM3"
sudo chmod 666 "$PM3"
fi
2019-07-15 00:20:41 +08:00
echo "$PM3"
2019-07-13 06:06:19 +08:00
}
SCRIPT=$(basename -- "$0")
if [ "$SCRIPT" = "pm3" ]; then
CMD() { $CLIENT "$@"; }
2019-09-09 18:58:11 +08:00
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 <command>]|[-l <lua_script_file>]|[-s <cmd_script_file>] [-i]
See "$CLIENT -h" for more details on options.
EOF
}
2019-09-09 07:07:46 +08:00
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[@]};
}
2019-09-09 18:58:11 +08:00
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:
2019-09-09 19:24:45 +08:00
$SCRIPT -b bootrom.elf fullimage.elf
2019-09-09 18:58:11 +08:00
EOF
}
elif [ "$SCRIPT" = "pm3-flash-all" ]; then
2019-09-09 07:07:46 +08:00
CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; }
2019-09-09 18:58:11 +08:00
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
2019-09-09 07:07:46 +08:00
CMD() { $CLIENT "$1" "--flash" "--image" "$FULLIMAGE"; }
2019-09-09 18:58:11 +08:00
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
2019-09-09 07:07:46 +08:00
CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; }
2019-09-09 18:58:11 +08:00
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
2019-08-13 04:31:27 +08:00
echo "[!!] Script ran under unknown name, abort: $SCRIPT"
exit 1
fi
2019-09-09 18:58:11 +08:00
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
HELP
exit 0
fi
HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then
2019-07-13 06:06:19 +08:00
if uname -a|grep -q Microsoft; then
PORT=$(wait4proxmark_WSL)
else
PORT=$(wait4proxmark_Linux)
fi
elif [ "$HOSTOS" = "DARWIN" ]; then
PORT=$(wait4proxmark_macOS)
elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
PORT=$(wait4proxmark_Windows)
else
2019-08-13 04:31:27 +08:00
echo "[!!] Host OS not recognized, abort: $HOSTOS"
exit 1
fi
if [ "$PORT" = "" ]; then
2019-08-13 04:31:27 +08:00
echo "[!!] No port, abort"
exit 1
fi
2019-07-15 00:20:41 +08:00
CMD "$PORT" "$@"
exit $?