3 # Usage: run option -h to get help
6 # Shall we look for white HC-06-USB dongle ?
8 # Shall we look for rfcomm interface ?
10 # Shall we look for registered BT device ? (Linux only)
13 PM3PATH
=$
(dirname "$0")
14 FULLIMAGE
="fullimage.elf"
15 BOOTIMAGE
="bootrom.elf"
16 # try pm3 dirs in current repo workdir
17 if [ -d "$PM3PATH/client/" ]; then
18 CLIENT
="$PM3PATH/client/proxmark3"
20 elif [ -x "$PM3PATH/proxmark3" ]; then
21 CLIENT
="$PM3PATH/proxmark3"
23 # hope it's installed somehow, still not sure where fw images are...
30 function get_pm3_list_Linux
{
33 if [ ! -c "/dev/tty0" ]; then
34 echo >&2 "[!!] Script cannot access /dev/ttyXXX files, insufficient privileges"
37 for DEV
in $
(find /dev
/ttyACM
* 2>/dev
/null
); do
38 if which udevadm
>/dev
/null
; then
39 if udevadm info
-q property
-n "$DEV" |
grep -q "ID_VENDOR=proxmark.org"; then
41 if [ ${#PM3LIST[*]} -ge "$N" ]; then
46 if grep -q "proxmark.org" "/sys/class/tty/${DEV#/dev/}/../../../manufacturer" 2>/dev
/null
; then
48 if [ ${#PM3LIST[*]} -ge "$N" ]; then
54 if $FINDBTDONGLE; then
55 # check if the HC-06-USB white dongle is present (still, that doesn't tell us if it's paired with a Proxmark3...)
56 for DEV
in $
(find /dev
/ttyUSB
* 2>/dev
/null
); do
57 if which udevadm
>/dev
/null
; then
58 if udevadm info
-q property
-n "$DEV" |
grep -q "ID_MODEL=CP2104_USB_to_UART_Bridge_Controller"; then
60 if [ ${#PM3LIST[*]} -ge "$N" ]; then
65 if grep -q "DRIVER=cp210x" "/sys/class/tty/${DEV#/dev/}/../../uevent" 2>/dev
/null
; then
67 if [ ${#PM3LIST[*]} -ge "$N" ]; then
74 if $FINDBTRFCOMM; then
75 # check if the MAC of a Proxmark3 was bound to a local rfcomm interface
76 # (on OSes without deprecated rfcomm and hcitool, the loop will be simply skipped)
77 for DEVMAC
in $
(rfcomm
-a 2>/dev
/null |
grep " 20:19:0[45]" |
sed 's/^\(.*\): \([0-9:]*\) .*/\1@\2/'); do
80 # check which are Proxmark3 and, side-effect, if they're actually present
81 if hcitool name
"$MAC" |
grep -q "PM3"; then
82 PM3LIST
+=("/dev/$DEV")
83 if [ ${#PM3LIST[*]} -ge "$N" ]; then
89 if $FINDBTDIRECT; then
90 # check if the MAC of a Proxmark3 was registered in the known devices
91 for MAC
in $
(dbus-send
--system --print-reply --type=method_call
--dest='org.bluez' '/' org.freedesktop.DBus.ObjectManager.GetManagedObjects
2>/dev
/null|\
92 awk '/"Address"/{getline;gsub(/"/,"",$3);a=$3}/Name/{getline;if (/PM3_RDV4/) print a}'); do
95 # we don't probe the device so there is no guarantee the device is actually present
99 function get_pm3_list_macOS
{
102 for DEV
in $
(ioreg
-r -c "IOUSBHostDevice" -l |
awk -F '"' '
103 $2=="USB Vendor Name"{b=($4=="proxmark.org")}
104 b==1 && $2=="IODialinDevice"{print $4}'); do
106 if [ ${#PM3LIST[*]} -ge "$N" ]; then
112 function get_pm3_list_Windows
{
115 # Need to look for this first, the call to Win32_serialport "crashes" then native bt serial port. Don't ask why.
116 #BT direct SERIAL PORTS (COM)
117 if $FINDBTRFCOMM; then
118 for DEV
in $
(powershell.exe
-command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev
/null |
awk '$0 ~ /COM/{print substr($6,2,4)}'); do
121 if [ ${#PM3LIST[*]} -ge "$N" ]; then
127 # Normal SERIAL PORTS (COM)
128 for DEV
in $
(powershell.exe
-command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_9AC4&PID_4B8F*' | Select DeviceID" 2>/dev
/null |
awk '/^COM/{print $1}'); do
131 if [ ${#PM3LIST[*]} -ge "$N" ]; then
136 #white BT dongle SERIAL PORTS (COM)
137 if $FINDBTDONGLE; then
138 for DEV
in $
(powershell.exe
-command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev
/null |
awk '/^COM/{print $1}'); do
141 if [ ${#PM3LIST[*]} -ge "$N" ]; then
148 function get_pm3_list_WSL
{
152 # Need to look for this first, the call to Win32_serialport "crashes" then native bt serial port. Don't ask why.
153 #BT direct SERIAL PORTS (COM)
154 if $FINDBTRFCOMM; then
155 for DEV
in $
(powershell.exe
-command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev
/null |
awk '$0 ~ /COM/{print substr($6,2,4)}'); do
158 DEV
="/dev/ttyS${DEV#COM}"
159 # ttyS counterpart takes some more time to appear
160 if [ -e "$DEV" ]; then
162 if [ ! -w "$DEV" ]; then
163 echo "[!] Let's give users read/write access to $DEV"
164 sudo
chmod 666 "$DEV"
166 if [ ${#PM3LIST[*]} -ge "$N" ]; then
174 # Normal SERIAL PORTS (COM)
175 for DEV
in $
(powershell.exe
-command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_9AC4&PID_4B8F*' | Select DeviceID" 2>/dev
/null |
awk '/^COM/{print $1}'); do
177 DEV
="/dev/ttyS${DEV#COM}"
178 # ttyS counterpart takes some more time to appear
179 if [ -e "$DEV" ]; then
181 if [ ! -w "$DEV" ]; then
182 echo "[!] Let's give users read/write access to $DEV"
183 sudo
chmod 666 "$DEV"
185 if [ ${#PM3LIST[*]} -ge "$N" ]; then
191 #white BT dongle SERIAL PORTS (COM)
192 if $FINDBTDONGLE; then
193 for DEV
in $
(powershell.exe
-command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev
/null |
awk '/^COM/{print $1}'); do
195 DEV
="/dev/ttyS${DEV#COM}"
196 # ttyS counterpart takes some more time to appear
197 if [ -e "$DEV" ]; then
199 if [ ! -w "$DEV" ]; then
200 echo "[!] Let's give users read/write access to $DEV"
201 sudo
chmod 666 "$DEV"
203 if [ ${#PM3LIST[*]} -ge "$N" ]; then
212 SCRIPT
=$
(basename -- "$0")
214 if [ "$SCRIPT" = "pm3" ]; then
215 CMD
() { $CLIENT "$@"; }
218 Quick helper script for proxmark3 client when working with a Proxmark3 device connected via USB
221 The usage is the same as for the proxmark3 client, with the following differences:
222 * the correct port name will be automatically guessed;
223 * the script will wait for a Proxmark to be connected (same as option -w of the client).
224 You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
225 Don't use this script if you want to work offline or with the BT addon.
226 To see a list of available ports, use --list.
229 $SCRIPT [-n <N>] [-f] [-c <command>]|[-l <lua_script_file>]|[-s <cmd_script_file>] [-i]
232 See "$CLIENT -h" for more details on options.
235 elif [ "$SCRIPT" = "pm3-flash" ]; then
240 ARGS
=("--port" "$1" "--flash")
242 while [ "$1" != "" ]; do
243 if [ "$1" == "-b" ]; then
244 ARGS
+=("--unlock-bootloader")
246 ARGS
+=("--image" "$1")
250 $CLIENT "${ARGS[@]}";
254 Quick helper script for flashing a Proxmark device via USB
257 The usage is similar to the old proxmark3-flasher binary, except that the correct port name will be automatically guessed.
258 You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
259 If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
260 To see a list of available ports, use --list.
263 $SCRIPT [-n <N>] [-b] image.elf [image.elf...]
267 -b Enable flashing of bootloader area (DANGEROUS)
270 $SCRIPT -b bootrom.elf fullimage.elf
273 elif [ "$SCRIPT" = "pm3-flash-all" ]; then
277 CMD
() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; }
280 Quick helper script for flashing a Proxmark device via USB
283 The correct port name will be automatically guessed and the stock bootloader and firmware image will be flashed.
284 You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
285 If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
286 To see a list of available ports, use --list.
293 elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then
297 CMD
() { $CLIENT "--port" "$1" "--flash" "--image" "$FULLIMAGE"; }
300 Quick helper script for flashing a Proxmark device via USB
303 The correct port name will be automatically guessed and the stock firmware image will be flashed.
304 You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
305 If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
306 To see a list of available ports, use --list.
313 elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then
317 CMD
() { $CLIENT "--port" "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; }
320 Quick helper script for flashing a Proxmark device via USB
323 The correct port name will be automatically guessed and the stock bootloader will be flashed.
324 You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
325 If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
326 To see a list of available ports, use --list.
334 echo >&2 "[!!] Script ran under unknown name, abort: $SCRIPT"
337 if [ "$1" == "-h" ] ||
[ "$1" == "--help" ]; then
342 # if a port is already provided, let's just run the command as such
344 if [ "$ARG" == "-p" ]; then
350 if [ "$1" == "--list" ]; then
352 if [ "$1" != "" ]; then
353 echo >&2 "[!!] Option --list must be used alone"
359 # Number of the proxmark3 we're interested in
361 if [ "$1" == "-n" ]; then
363 if [ "$1" -ge 1 ] && [ "$1" -lt 10 ]; then
367 echo >&2 "[!!] Option -n requires a number between 1 and 9, got \"$1\""
372 HOSTOS
=$
(uname |
awk '{print toupper($0)}')
373 if [ "$HOSTOS" = "LINUX" ]; then
374 if uname
-a|
grep -q Microsoft
; then
375 # Test presence of wmic
376 if ! wmic.exe computersystem get name
>/dev
/null
2>&1; then
377 echo >&2 "[!!] Cannot run wmic.exe, are you sure your WSL is authorized to run Windows processes? (cf WSL interop flag)"
380 GETPM3LIST
=get_pm3_list_WSL
382 GETPM3LIST
=get_pm3_list_Linux
384 elif [ "$HOSTOS" = "DARWIN" ]; then
385 GETPM3LIST
=get_pm3_list_macOS
386 elif [[ "$HOSTOS" =~ MINGW
(32|
64)_NT
* ]]; then
387 GETPM3LIST
=get_pm3_list_Windows
389 echo >&2 "[!!] Host OS not recognized, abort: $HOSTOS"
394 # Probe for up to 9 devs
396 if [ ${#PM3LIST} -lt 1 ]; then
397 echo >&2 "[!!] No port found"
401 for DEV
in "${PM3LIST[@]}"
409 # Wait till we get at least N proxmark3 devices
411 if [ ${#PM3LIST} -lt "$N" ]; then
412 echo >&2 "[=] Waiting for Proxmark3 to appear..."
415 if [ ${#PM3LIST[*]} -ge "$N" ]; then
422 if [ ${#PM3LIST} -lt "$N" ]; then
423 echo >&2 "[!!] No port found, abort"
427 CMD
"${PM3LIST[$((N-1))]}" "$@"