2020-02-17 23:49:29 +00:00
#!/usr/bin/env bash
2017-10-23 18:15:02 -04:00
2019-09-09 12:58:11 +02:00
# Usage: run option -h to get help
2020-04-29 15:15:25 +02:00
# BT auto detection
2020-04-21 12:01:26 +02:00
# Shall we look for white HC-06-USB dongle ?
FINDBTDONGLE = true
# Shall we look for rfcomm interface ?
2020-04-29 15:15:25 +02:00
FINDBTRFCOMM = true
# Shall we look for registered BT device ? (Linux only)
2020-04-21 12:01:26 +02:00
FINDBTDIRECT = true
2019-07-14 18:20:41 +02:00
PM3PATH = $( dirname " $0 " )
2020-11-14 00:44:18 +01:00
EVALENV = ""
2019-09-09 19:55:27 +02:00
FULLIMAGE = "fullimage.elf"
BOOTIMAGE = "bootrom.elf"
2020-12-29 16:38:02 +01:00
#Skip check if --list is used
if [ ! " $1 " == "--list" ] ; then
2021-06-04 22:08:32 +02:00
# try pm3 dirs in current repo workdir
if [ -d " $PM3PATH /client/" ] ; then
if [ -x " $PM3PATH /client/proxmark3" ] ; then
CLIENT = " $PM3PATH /client/proxmark3"
elif [ -x " $PM3PATH /client/build/proxmark3" ] ; then
CLIENT = " $PM3PATH /client/build/proxmark3"
else
echo >& 2 "[!!] In devel workdir but no executable found, did you compile it?"
exit 1
fi
# try install dir
elif [ -x " $PM3PATH /proxmark3" ] ; then
CLIENT = " $PM3PATH /proxmark3"
else
# hope it's installed somehow, still not sure where fw images and pm3.py are...
CLIENT = "proxmark3"
fi
2019-08-30 23:35:29 +02:00
fi
2020-12-29 16:38:02 +01:00
2020-10-07 02:05:16 +02:00
# LeakSanitizer suppressions
if [ -e .lsan_suppressions ] ; then
2020-11-14 00:44:18 +01:00
EVALENV += " LSAN_OPTIONS=suppressions=.lsan_suppressions"
fi
if [ " $EVALENV " != "" ] ; then
EVALENV = "export $EVALENV "
2020-10-07 02:05:16 +02:00
fi
2019-09-30 18:30:10 +02:00
PM3LIST =()
2020-04-21 12:01:26 +02:00
SHOWLIST = false
2019-09-30 18:30:10 +02:00
function get_pm3_list_Linux {
2020-04-21 17:11:18 +02:00
N = $1
2019-09-30 18:30:10 +02:00
PM3LIST =()
2020-05-18 01:05:49 +02:00
if [ ! -c "/dev/tty0" ] ; then
echo >& 2 "[!!] Script cannot access /dev/ttyXXX files, insufficient privileges"
exit 1
fi
2019-09-30 18:30:10 +02:00
for DEV in $( find /dev/ttyACM* 2>/dev/null) ; do
2021-09-05 00:34:26 +02:00
if command -v udevadm >/dev/null; then
2022-11-12 01:52:44 +01:00
# WSL1 detection
2020-05-16 14:24:21 +02:00
if udevadm info -q property -n " $DEV " | grep -q "ID_VENDOR=proxmark.org" ; then
PM3LIST +=( " $DEV " )
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2020-05-16 14:24:21 +02:00
return
fi
fi
2022-11-12 01:52:44 +01:00
fi
# WSL2 with usbipd detection - doesn't report same things as WSL1
if grep -q "proxmark.org" "/sys/class/tty/ ${ DEV #/dev/ } /../../../manufacturer" 2>/dev/null; then
2023-02-19 01:44:15 -08:00
if echo " ${ PM3LIST [*] } " | grep -qv " ${ DEV } " ; then
2023-02-18 23:48:08 -08:00
PM3LIST +=( " $DEV " )
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
return
fi
2020-04-21 17:11:18 +02:00
fi
2019-07-14 18:20:41 +02:00
fi
2019-03-09 11:10:22 +01:00
done
2020-04-21 12:01:26 +02:00
if $FINDBTDONGLE ; then
2020-04-21 12:30:33 +02:00
# check if the HC-06-USB white dongle is present (still, that doesn't tell us if it's paired with a Proxmark3...)
2020-04-21 12:01:26 +02:00
for DEV in $( find /dev/ttyUSB* 2>/dev/null) ; do
2021-09-05 00:34:26 +02:00
if command -v udevadm >/dev/null; then
2020-05-18 01:16:29 +02:00
if udevadm info -q property -n " $DEV " | grep -q "ID_MODEL=CP2104_USB_to_UART_Bridge_Controller" ; then
PM3LIST +=( " $DEV " )
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
return
fi
fi
else
if grep -q "DRIVER=cp210x" "/sys/class/tty/ ${ DEV #/dev/ } /../../uevent" 2>/dev/null; then
PM3LIST +=( " $DEV " )
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
return
fi
2020-04-21 17:11:18 +02:00
fi
2020-04-21 12:01:26 +02:00
fi
done
fi
2020-04-29 15:15:25 +02:00
if $FINDBTRFCOMM ; then
2020-04-21 12:30:33 +02:00
# check if the MAC of a Proxmark3 was bound to a local rfcomm interface
2020-04-29 15:15:25 +02:00
# (on OSes without deprecated rfcomm and hcitool, the loop will be simply skipped)
2020-04-29 14:07:26 +02:00
for DEVMAC in $( rfcomm -a 2>/dev/null | grep " 20:19:0[45]" | sed 's/^\(.*\): \([0-9:]*\) .*/\1@\2/' ) ; do
2020-04-21 12:30:33 +02:00
DEV = ${ DEVMAC /@*/ }
MAC = ${ DEVMAC /*@/ }
2020-04-29 15:15:25 +02:00
# check which are Proxmark3 and, side-effect, if they're actually present
2020-04-21 12:30:33 +02:00
if hcitool name " $MAC " | grep -q "PM3" ; then
PM3LIST +=( "/dev/ $DEV " )
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2020-04-21 17:11:18 +02:00
return
fi
2020-04-21 12:30:33 +02:00
fi
2020-04-21 12:01:26 +02:00
done
fi
2020-04-29 15:15:25 +02:00
if $FINDBTDIRECT ; then
# check if the MAC of a Proxmark3 was registered in the known devices
2020-04-29 15:29:34 +02:00
for MAC in $( dbus-send --system --print-reply --type= method_call --dest= 'org.bluez' '/' org.freedesktop.DBus.ObjectManager.GetManagedObjects 2>/dev/null| \
2023-05-28 08:24:06 +02:00
awk '/"Address"/{getline;gsub(/"/,"",$3);a=$3}/Name/{getline;if (/PM3_RDV4/ || /Proxmark3 SE/) print a}' ) ; do
2020-04-29 15:15:25 +02:00
PM3LIST +=( "bt: $MAC " )
done
# we don't probe the device so there is no guarantee the device is actually present
fi
2017-10-23 18:15:02 -04:00
}
2019-09-30 18:30:10 +02:00
function get_pm3_list_macOS {
2020-04-21 17:11:18 +02:00
N = $1
2019-09-30 18:30:10 +02:00
PM3LIST =()
2020-04-29 14:07:26 +02:00
for DEV in $( ioreg -r -c "IOUSBHostDevice" -l | awk -F '"' '
2019-11-18 13:11:28 +01:00
$2=="USB Vendor Name"{b=($4=="proxmark.org")}
b==1 && $2=="IODialinDevice"{print $4}' ) ; do
2019-09-30 18:30:10 +02:00
PM3LIST +=( " $DEV " )
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2020-04-21 17:11:18 +02:00
return
fi
2019-03-09 11:10:22 +01:00
done
2018-08-17 00:22:54 +10:00
}
2019-09-30 18:30:10 +02:00
function get_pm3_list_Windows {
2020-04-21 17:11:18 +02:00
N = $1
2019-09-30 18:30:10 +02:00
PM3LIST =()
2021-10-16 23:44:46 +02:00
2021-12-13 00:42:02 +01:00
# Normal SERIAL PORTS (COM)
2025-05-19 22:27:50 +02:00
for DEV in $( $PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object {\$_.PNPDeviceID -like '*VID_9AC4&PID_4B8F*' -or \$_.PNPDeviceID -like '*VID_2D2D&PID_504D*'} | Select -expandproperty DeviceID" 2>/dev/null) ; do
_comport = $DEV
2021-09-19 01:31:17 +02:00
#prevent soft bricking when using pm3-flash-all on an outdated bootloader
if [ $( basename -- " $0 " ) = "pm3-flash-all" ] ; then
2025-05-23 10:52:09 +02:00
2025-05-19 22:27:50 +02:00
line = $( $PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object {\$_.DeviceID -eq ' $_comport '} | Select -expandproperty PNPDeviceID" 2>/dev/null) ;
2025-05-23 10:52:09 +02:00
2023-06-16 05:33:35 +02:00
if [[ ! $line = ~ ^"USB\VID_9AC4&PID_4B8F\ICEMAN" ]] ; then
2021-09-19 01:31:17 +02:00
echo -e "\033[0;31m[!] Using pm3-flash-all on an oudated bootloader, use pm3-flash-bootrom first!"
exit 1
fi
fi
PM3LIST +=( " $DEV " )
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
return
fi
done
2021-10-16 23:44:46 +02:00
2020-04-29 14:07:26 +02:00
#BT direct SERIAL PORTS (COM)
2020-04-29 15:15:25 +02:00
if $FINDBTRFCOMM ; then
2025-05-19 22:27:50 +02:00
for DEV in $( $PSHEXE -command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2>/dev/null) ; do
2020-04-29 12:00:49 +02:00
PM3LIST +=( " $DEV " )
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2020-04-29 12:00:49 +02:00
return
fi
done
fi
2020-04-29 14:07:26 +02:00
#white BT dongle SERIAL PORTS (COM)
if $FINDBTDONGLE ; then
2025-05-23 10:52:09 +02:00
2025-05-19 22:27:50 +02:00
for DEV in $( $PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select -expandproperty DeviceID" 2>/dev/null) ; do
2020-04-29 12:00:49 +02:00
PM3LIST +=( " $DEV " )
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2020-04-29 12:00:49 +02:00
return
fi
2020-04-29 14:07:26 +02:00
done
2020-04-29 12:00:49 +02:00
fi
2019-07-03 14:16:16 +02:00
}
2019-09-30 18:30:10 +02:00
function get_pm3_list_WSL {
2020-04-29 12:00:49 +02:00
N = $1
2019-09-30 18:30:10 +02:00
PM3LIST =()
2021-10-16 23:44:46 +02:00
2021-12-13 00:42:02 +01:00
# Normal SERIAL PORTS (COM)
2023-02-18 15:01:39 +01:00
for DEV in $( $PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object {\$_.PNPDeviceID -like '*VID_9AC4&PID_4B8F*' -or \$_.PNPDeviceID -like '*VID_2D2D&PID_504D*'} | Select -expandproperty DeviceID" 2>/dev/null) ; do
DEV = $( echo $DEV | tr -dc '[:print:]' )
2021-09-19 01:31:17 +02:00
_comport = $DEV
DEV = $( echo $DEV | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p' )
# ttyS counterpart takes some more time to appear
if [ -e " $DEV " ] ; then
2023-06-16 05:33:35 +02:00
2021-09-19 01:31:17 +02:00
#prevent soft bricking when using pm3-flash-all on an outdated bootloader
if [ $( basename -- " $0 " ) = "pm3-flash-all" ] ; then
2023-06-16 05:33:35 +02:00
line = $( $PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object {\$_.DeviceID -eq ' $_comport '} | Select -expandproperty PNPDeviceID" 2>/dev/null | tr -dc '[:print:]' ) ;
if [[ ! $line = ~ ^"USB\VID_9AC4&PID_4B8F\ICEMAN" ]] ; then
2021-09-19 01:31:17 +02:00
echo -e "\033[0;31m[!] Using pm3-flash-all on an oudated bootloader, use pm3-flash-bootrom first!"
exit 1
fi
fi
PM3LIST +=( " $DEV " )
if [ ! -w " $DEV " ] ; then
echo "[!] Let's give users read/write access to $DEV "
sudo chmod 666 " $DEV "
fi
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
return
fi
fi
done
2020-04-29 14:07:26 +02:00
#BT direct SERIAL PORTS (COM)
2020-04-29 15:15:25 +02:00
if $FINDBTRFCOMM ; then
2020-10-10 03:37:09 +02:00
for DEV in $( $PSHEXE -command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev/null | sed -nr 's#.*\bCOM([0-9]+)\b.*#/dev/ttyS\1#p' ) ; do
2020-04-29 14:07:26 +02:00
# ttyS counterpart takes some more time to appear
if [ -e " $DEV " ] ; then
PM3LIST +=( " $DEV " )
if [ ! -w " $DEV " ] ; then
2020-05-17 12:12:13 +02:00
echo "[!] Let's give users read/write access to $DEV "
2020-04-29 14:07:26 +02:00
sudo chmod 666 " $DEV "
fi
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2020-04-29 14:07:26 +02:00
return
fi
fi
done
fi
#white BT dongle SERIAL PORTS (COM)
2020-04-29 12:00:49 +02:00
if $FINDBTDONGLE ; then
2020-10-10 03:37:09 +02:00
for DEV in $( $PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev/null | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p' ) ; do
2020-04-29 12:00:49 +02:00
# ttyS counterpart takes some more time to appear
if [ -e " $DEV " ] ; then
PM3LIST +=( " $DEV " )
if [ ! -w " $DEV " ] ; then
2020-05-17 12:12:13 +02:00
echo "[!] Let's give users read/write access to $DEV "
2020-04-29 12:00:49 +02:00
sudo chmod 666 " $DEV "
fi
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2020-04-29 12:00:49 +02:00
return
fi
fi
done
fi
2019-07-13 00:06:19 +02:00
}
2019-04-27 11:25:07 +02:00
SCRIPT = $( basename -- " $0 " )
2018-08-17 00:22:54 +10:00
2019-08-30 23:35:29 +02:00
if [ " $SCRIPT " = "pm3" ] ; then
2020-10-07 02:05:16 +02:00
CMD() { eval " $EVALENV " ; $CLIENT " $@ " ; }
2019-09-09 12:58:11 +02:00
HELP() {
cat << EOF
2020-06-05 11:43:27 +02:00
Quick helper script for proxmark3 client when working with a Proxmark3 device
2019-09-09 12:58:11 +02:00
Description:
The usage is the same as for the proxmark3 client, with the following differences:
* the correct port name will be automatically guessed;
2023-02-18 15:13:15 +01:00
* the script will wait for a Proxmark3 to be connected (same as option -w of the client).
2020-06-05 11:43:27 +02:00
You can also specify a first option -n N to access the Nth Proxmark3 connected.
2020-04-21 12:05:47 +02:00
To see a list of available ports, use --list.
2019-09-09 12:58:11 +02:00
Usage:
2021-06-04 22:27:18 +02:00
$SCRIPT [-n <N>] [<any other proxmark3 client option>]
$SCRIPT [--list] [-h|--help] [-hh|--helpclient]
2021-06-04 22:50:05 +02:00
$SCRIPT [-o|--offline]
2020-06-05 11:43:27 +02:00
Arguments:
2021-06-04 22:27:18 +02:00
-h/--help this help
-hh/--helpclient proxmark3 client help (the script will forward these options)
2020-06-05 11:43:27 +02:00
--list list all detected com ports
2021-06-04 22:27:18 +02:00
-n <N> connect device referred to the N:th number on the --list output
2021-06-04 22:50:05 +02:00
-o/--offline shortcut to use directly the proxmark3 client without guessing ports
2020-06-05 11:43:27 +02:00
Samples:
./$SCRIPT -- Auto detect/ select com port in the following order BT, USB/CDC, BT DONGLE
./$SCRIPT -p /dev/ttyACM0 -- connect to port /dev/ttyACM0
./$SCRIPT -n 2 -- use second item from the --list output
./$SCRIPT -c 'lf search' -i -- run command and stay in client once completed
2019-09-09 12:58:11 +02:00
EOF
}
2019-09-09 01:07:46 +02:00
elif [ " $SCRIPT " = "pm3-flash" ] ; then
2020-04-21 12:01:26 +02:00
FINDBTDONGLE = false
2020-04-29 15:15:25 +02:00
FINDBTRFCOMM = false
2020-04-21 12:01:26 +02:00
FINDBTDIRECT = false
2019-09-09 01:07:46 +02:00
CMD() {
2019-09-30 18:30:10 +02:00
ARGS =( "--port" " $1 " "--flash" )
2019-09-09 01:07:46 +02:00
shift;
while [ " $1 " != "" ] ; do
if [ " $1 " == "-b" ] ; then
ARGS +=( "--unlock-bootloader" )
2022-02-25 00:35:30 +01:00
elif [ " $1 " == "--force" ] ; then
ARGS +=( "--force" )
2019-09-09 01:07:46 +02:00
else
ARGS +=( "--image" " $1 " )
fi
shift;
done
2020-05-17 12:23:03 +02:00
$CLIENT " ${ ARGS [@] } " ;
2019-09-09 01:07:46 +02:00
}
2019-09-09 12:58:11 +02:00
HELP() {
cat << EOF
2023-02-18 15:13:15 +01:00
Quick helper script for flashing a Proxmark3 device via USB
2019-09-09 12:58:11 +02:00
Description:
The usage is similar to the old proxmark3-flasher binary, except that the correct port name will be automatically guessed.
2019-09-30 18:30:10 +02:00
You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
2019-09-09 12:58:11 +02:00
If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
2020-04-21 12:05:47 +02:00
To see a list of available ports, use --list.
2019-09-09 12:58:11 +02:00
Usage:
2019-09-30 18:30:10 +02:00
$SCRIPT [-n <N>] [-b] image.elf [image.elf...]
2020-04-21 12:05:47 +02:00
$SCRIPT --list
2019-09-09 12:58:11 +02:00
Options:
-b Enable flashing of bootloader area (DANGEROUS)
Example:
2019-09-09 13:24:45 +02:00
$SCRIPT -b bootrom.elf fullimage.elf
2019-09-09 12:58:11 +02:00
EOF
}
2019-08-30 23:35:29 +02:00
elif [ " $SCRIPT " = "pm3-flash-all" ] ; then
2020-04-21 12:01:26 +02:00
FINDBTDONGLE = false
2020-04-29 15:15:25 +02:00
FINDBTRFCOMM = false
2020-04-21 12:01:26 +02:00
FINDBTDIRECT = false
2022-02-25 00:35:30 +01:00
CMD() {
ARGS =( "--port" " $1 " "--flash" "--unlock-bootloader" "--image" " $BOOTIMAGE " "--image" " $FULLIMAGE " )
shift;
while [ " $1 " != "" ] ; do
if [ " $1 " == "--force" ] ; then
ARGS +=( "--force" )
fi
shift;
done
$CLIENT " ${ ARGS [@] } " ;
}
2019-09-09 12:58:11 +02:00
HELP() {
cat << EOF
2023-02-18 15:13:15 +01:00
Quick helper script for flashing a Proxmark3 device via USB
2019-09-09 12:58:11 +02:00
Description:
The correct port name will be automatically guessed and the stock bootloader and firmware image will be flashed.
2019-09-30 18:30:10 +02:00
You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
2019-09-09 12:58:11 +02:00
If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
2020-04-21 12:05:47 +02:00
To see a list of available ports, use --list.
2019-09-09 12:58:11 +02:00
Usage:
2019-09-30 18:30:10 +02:00
$SCRIPT [-n <N>]
2020-04-21 12:05:47 +02:00
$SCRIPT --list
2019-09-09 12:58:11 +02:00
EOF
}
2019-08-30 23:35:29 +02:00
elif [ " $SCRIPT " = "pm3-flash-fullimage" ] ; then
2020-04-21 12:01:26 +02:00
FINDBTDONGLE = false
2020-04-29 15:15:25 +02:00
FINDBTRFCOMM = false
2020-04-21 12:01:26 +02:00
FINDBTDIRECT = false
2022-02-25 00:35:30 +01:00
CMD() {
ARGS =( "--port" " $1 " "--flash" "--image" " $FULLIMAGE " )
shift;
while [ " $1 " != "" ] ; do
if [ " $1 " == "--force" ] ; then
ARGS +=( "--force" )
fi
shift;
done
$CLIENT " ${ ARGS [@] } " ;
}
2019-09-09 12:58:11 +02:00
HELP() {
cat << EOF
2023-02-18 15:13:15 +01:00
Quick helper script for flashing a Proxmark3 device via USB
2019-09-09 12:58:11 +02:00
Description:
The correct port name will be automatically guessed and the stock firmware image will be flashed.
2019-09-30 18:30:10 +02:00
You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
2019-09-09 12:58:11 +02:00
If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
2020-04-21 12:05:47 +02:00
To see a list of available ports, use --list.
2019-09-09 12:58:11 +02:00
Usage:
2019-09-30 18:30:10 +02:00
$SCRIPT [-n <N>]
2020-04-21 12:05:47 +02:00
$SCRIPT --list
2019-09-09 12:58:11 +02:00
EOF
}
2019-08-30 23:35:29 +02:00
elif [ " $SCRIPT " = "pm3-flash-bootrom" ] ; then
2020-04-21 12:01:26 +02:00
FINDBTDONGLE = false
2020-04-29 15:15:25 +02:00
FINDBTRFCOMM = false
2020-04-21 12:01:26 +02:00
FINDBTDIRECT = false
2022-02-25 00:35:30 +01:00
CMD() {
ARGS =( "--port" " $1 " "--flash" "--unlock-bootloader" "--image" " $BOOTIMAGE " )
shift;
while [ " $1 " != "" ] ; do
if [ " $1 " == "--force" ] ; then
ARGS +=( "--force" )
fi
shift;
done
$CLIENT " ${ ARGS [@] } " ;
}
2019-09-09 12:58:11 +02:00
HELP() {
cat << EOF
2023-02-18 15:13:15 +01:00
Quick helper script for flashing a Proxmark3 device via USB
2019-09-09 12:58:11 +02:00
Description:
The correct port name will be automatically guessed and the stock bootloader will be flashed.
2019-09-30 18:30:10 +02:00
You can also specify a first option -n N to access the Nth Proxmark3 connected on USB.
2019-09-09 12:58:11 +02:00
If this doesn't work, you'll have to use manually the proxmark3 client, see "$CLIENT -h".
2020-04-21 12:05:47 +02:00
To see a list of available ports, use --list.
2019-09-09 12:58:11 +02:00
Usage:
2019-09-30 18:30:10 +02:00
$SCRIPT [-n <N>]
2020-04-21 12:05:47 +02:00
$SCRIPT --list
2019-09-09 12:58:11 +02:00
EOF
}
2019-04-27 11:25:07 +02:00
else
2020-05-17 12:12:13 +02:00
echo >& 2 "[!!] Script ran under unknown name, abort: $SCRIPT "
2019-04-27 11:25:07 +02:00
exit 1
2018-08-17 00:22:54 +10:00
fi
2019-09-30 18:30:10 +02:00
2021-06-04 22:50:05 +02:00
# priority to the help options
for ARG; do
2025-11-13 09:23:37 +01:00
if [ " $ARG " == "--" ] ; then
break
fi
2021-06-04 22:50:05 +02:00
if [ " $ARG " == "-h" ] || [ " $ARG " == "--help" ] ; then
HELP
exit 0
fi
if [ " $ARG " == "-hh" ] || [ " $ARG " == "--helpclient" ] ; then
CMD "-h"
exit 0
fi
done
# if offline, bypass the script and forward all other args
for ARG; do
shift
if [ " $ARG " == "-o" ] || [ " $ARG " == "--offline" ] ; then
CMD " $@ "
exit $?
fi
set -- " $@ " " $ARG "
done
2021-06-04 22:27:18 +02:00
2019-09-30 18:30:10 +02:00
# if a port is already provided, let's just run the command as such
2021-06-04 22:50:05 +02:00
for ARG; do
2023-02-03 14:41:23 +01:00
shift
2019-09-30 18:30:10 +02:00
if [ " $ARG " == "-p" ] ; then
CMD " $@ "
exit $?
fi
2023-02-17 16:37:03 +01:00
set -- " $@ " " $ARG "
2019-09-30 18:30:10 +02:00
done
2020-04-21 12:01:26 +02:00
if [ " $1 " == "--list" ] ; then
shift
if [ " $1 " != "" ] ; then
2020-05-17 12:12:13 +02:00
echo >& 2 "[!!] Option --list must be used alone"
2020-04-21 12:01:26 +02:00
exit 1
fi
SHOWLIST = true
fi
2023-02-18 15:13:15 +01:00
# Number of the Proxmark3 we're interested in
2019-09-30 18:30:10 +02:00
N = 1
if [ " $1 " == "-n" ] ; then
shift
if [ " $1 " -ge 1 ] && [ " $1 " -lt 10 ] ; then
N = $1
shift
else
2020-05-17 12:12:13 +02:00
echo >& 2 "[!!] Option -n requires a number between 1 and 9, got \" $1 \""
2019-09-30 18:30:10 +02:00
exit 1
fi
fi
2020-06-24 11:53:00 +02:00
HOSTOS = $( uname | awk '{print toupper($0)}' )
2019-04-27 11:25:07 +02:00
if [ " $HOSTOS " = "LINUX" ] ; then
2023-02-19 01:44:15 -08:00
# Detect when running under WSL1 (but exclude WSL2)
if uname -a | grep -qi Microsoft && uname -a | grep -qvi WSL2; then
2020-10-10 03:37:09 +02:00
# First try finding it using the PATH environment variable
2021-09-05 00:34:26 +02:00
PSHEXE = $( command -v powershell.exe 2>/dev/null)
2020-10-10 03:37:09 +02:00
# If it fails (such as if WSLENV is not set), try using the default installation path
if [ -z " $PSHEXE " ] ; then
PSHEXE = /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
fi
# Finally test if PowerShell is working
if ! " $PSHEXE " exit >/dev/null 2>& 1; then
echo >& 2 "[!!] Cannot run powershell.exe, are you sure your WSL is authorized to run Windows processes? (cf WSL interop flag)"
2019-09-30 18:30:10 +02:00
exit 1
fi
2020-10-10 03:37:09 +02:00
2019-09-30 18:30:10 +02:00
GETPM3LIST = get_pm3_list_WSL
2019-07-13 00:06:19 +02:00
else
2019-09-30 18:30:10 +02:00
GETPM3LIST = get_pm3_list_Linux
2019-07-13 00:06:19 +02:00
fi
2019-04-27 11:25:07 +02:00
elif [ " $HOSTOS " = "DARWIN" ] ; then
2019-09-30 18:30:10 +02:00
GETPM3LIST = get_pm3_list_macOS
2019-07-03 14:16:16 +02:00
elif [[ " $HOSTOS " = ~ MINGW( 32| 64) _NT* ]] ; then
2025-05-19 22:27:50 +02:00
# First try finding it using the PATH environment variable
PSHEXE = $( command -v powershell.exe 2>/dev/null)
# If it fails (such as if WSLENV is not set), try using the default installation path
if [ -z " $PSHEXE " ] ; then
PSHEXE = /cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe
fi
# Finally test if PowerShell is working
if ! " $PSHEXE " exit >/dev/null 2>& 1; then
echo >& 2 "[!!] Cannot run powershell.exe in your MINGW environment"
exit 1
fi
2019-09-30 18:30:10 +02:00
GETPM3LIST = get_pm3_list_Windows
2019-04-27 11:25:07 +02:00
else
2020-05-17 12:12:13 +02:00
echo >& 2 "[!!] Host OS not recognized, abort: $HOSTOS "
2019-04-27 11:25:07 +02:00
exit 1
fi
2019-09-30 18:30:10 +02:00
2020-04-21 12:01:26 +02:00
if $SHOWLIST ; then
2020-04-21 17:11:18 +02:00
# Probe for up to 9 devs
$GETPM3LIST 9
2020-04-21 12:01:26 +02:00
if [ ${# PM3LIST } -lt 1 ] ; then
2020-05-17 12:12:13 +02:00
echo >& 2 "[!!] No port found"
2020-05-17 12:06:39 +02:00
exit 1
2020-04-21 12:01:26 +02:00
fi
n = 1
2020-05-17 12:23:03 +02:00
for DEV in " ${ PM3LIST [@] } "
2020-04-21 12:01:26 +02:00
do
echo " $n : $DEV "
n = $(( n+1))
done
exit 0
fi
2023-02-18 15:13:15 +01:00
# Wait till we get at least N Proxmark3 devices
2020-05-17 12:23:03 +02:00
$GETPM3LIST " $N "
if [ ${# PM3LIST } -lt " $N " ] ; then
2020-04-21 12:01:26 +02:00
echo >& 2 "[=] Waiting for Proxmark3 to appear..."
fi
2019-09-30 18:30:10 +02:00
while true; do
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST [*] } -ge " $N " ] ; then
2019-09-30 18:30:10 +02:00
break
fi
sleep .1
2020-05-17 12:23:03 +02:00
$GETPM3LIST " $N "
2019-09-30 18:30:10 +02:00
done
2020-05-17 12:23:03 +02:00
if [ ${# PM3LIST } -lt " $N " ] ; then
2020-06-05 11:43:27 +02:00
HELP() {
cat << EOF
[!!] No port found, abort
[?] Hint: try '$SCRIPT --list' to see list of available ports, and use the -n command like below
[?] $SCRIPT [-n <N>]
2021-06-04 21:57:41 +02:00
2020-06-05 11:43:27 +02:00
EOF
}
HELP
2019-04-27 11:25:07 +02:00
exit 1
fi
2019-09-30 18:30:10 +02:00
CMD " ${ PM3LIST [ $(( N-1)) ] } " " $@ "
2019-04-27 11:25:07 +02:00
exit $?