diff --git a/Makefile b/Makefile index 5083edd..c8e2804 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: src/flash_bash.c - gcc -g -lwiringPi -Wall -o flash_bash src/flash_bash.c + gcc -Wall -pthread -o flash_bash src/flash_bash.c -lpigpio -lrt clean: rm -rf flash_bash flash_bash.dSYM/ \ No newline at end of file diff --git a/README.md b/README.md index 010fda0..4ee0501 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,31 @@ # Flash-BASH -Flash-BASH is a Raspberry Pi based tool that uses a multiplexer to "glitch" a target device into a privileged open state. +

+ Flash Bash Logo +

+ +Flash-BASH is a Raspberry Pi based tool that uses a multiplexer to "glitch" a target device into a privileged open shell. ## Usage See our blog post at https://www.riverloopsecurity.com/blog/2021/09/introducing-flash-bash/ for information on usage. ## Install/Compile -The easiest way to use this tool without any tweaks is with a Raspberry Pi Model 3 B+. +The easiest way to use this tool without any tweaks is with a Raspberry Pi Type 3 (Model A+, B+, Pi Zero, Pi Zero W, Pi2B, Pi3B, Pi4B). However, with minor tweaks to the code, any Raspberry Pi, Arduino, or micro-controller should work fine. -Secondly, this tool is based on the dependency Wiring Pi which you can install like so: +Secondly, this tool is based on the dependency pigpio which should be automatically installed on latest version of Raspberry Pi OS but can be installed with: ``` -sudo apt-get install wiringpi +sudo apt-get install pigpio python-pigpio python3-pigpio ``` +Please visit https://abyz.me.uk/rpi/pigpio for more information on the library. -Third, you will need the Pi Hat and components that are included in the CAD folder in this repository. You could also wire this with jumpers and a breadboard or a prototype-hat, but it will not be as organized! +Third, you will need the Pi Hat and components that are included in the CAD folder in this repository. You could also wire this with jumpers and a breadboard or a prototype-hat. Last, you will need to compile this pointing to the Wiring Pi library like this ``` -gcc -o flash_bash flash_bash.c -lwiringPi +gcc -Wall -pthread -o flash_bash flash_bash.c -lpigpio -lrt ``` +or you can just run make in this directory. That should get you started all you have to do now is run the program! ``` diff --git a/cad/BOM b/cad/BOM new file mode 100644 index 0000000..c023be7 --- /dev/null +++ b/cad/BOM @@ -0,0 +1,6 @@ +"Reference","Value","Datasheet","Footprint","Qty","DNP" +"C1","1uF","~","Capacitor_SMD:C_0805_2012Metric","1","" +"J1","GPIO","","Connector_PinSocket_2.54mm:PinSocket_2x20_P2.54mm_Vertical","1","" +"J2,J3,J5","Conn_01x03","~","Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical","3","" +"J4","Conn_02x03_Odd_Even","~","Connector_PinHeader_2.54mm:PinHeader_2x03_P2.54mm_Vertical","1","" +"U1","TMUX1133PWR","TMUX1133PWR","TMUX1133PWR:PW0016A-MFG","1","" diff --git a/cad/CAMOutputs.zip b/cad/CAMOutputs.zip deleted file mode 100755 index 5ce6b2e..0000000 Binary files a/cad/CAMOutputs.zip and /dev/null differ diff --git a/cad/FAB.zip b/cad/FAB.zip new file mode 100644 index 0000000..b7cd83b Binary files /dev/null and b/cad/FAB.zip differ diff --git a/cad/FlashBash.zip b/cad/FlashBash.zip new file mode 100644 index 0000000..abefc33 Binary files /dev/null and b/cad/FlashBash.zip differ diff --git a/cad/README.md b/cad/README.md index 6d15023..35f8ba6 100644 --- a/cad/README.md +++ b/cad/README.md @@ -1,2 +1,12 @@ # Flash-BASH Pi HAT Files -Included are Eagle 9.6.1 CAD files so that you can make modifications. Also included are ready-to-fab gerber files in the CAMOutputs.zip file. \ No newline at end of file +

+ Flash Bash Logo +

+ +Included are KiCAD 8.0.4 CAD files in the FlashBash.zip so that you can make modifications. + +Also included are ready-to-fab gerber files in FAB.zip. + +Please also see the footprint and schematic symbol for the multiplexer in the TMUX1133PWR.zip. + +Lastly you can verify other components in the BOM csv file. \ No newline at end of file diff --git a/cad/RasPi-BplusHAT.brd b/cad/RasPi-BplusHAT.brd deleted file mode 100755 index e3ca9b5..0000000 --- a/cad/RasPi-BplusHAT.brd +++ /dev/null @@ -1,1135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TOP -BOTTOM - - - - - - - - - - - - - - - - - - - - -RLS -+5V -GND -GND -+3.3V -DATA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1 ->VALUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - -<b>RESISTOR</b><p> -MELF 0.10 W - - - - - - - - ->NAME ->VALUE - - - - - -<b>Ceramic Chip Capacitor KEMET 0805 Reflow solder</b><p> -Metric Code Size 2012 - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - - - - - ->VALUE ->NAME - - - - - - - - - - - - - - - - - - - - -<b>Pin Header Connectors</b><p> -<author>Created by librarian@cadsoft.de</author> - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - -PIN HEADER - - - - - -PIN HEADER - - - - - - - - - - - - - - - - -<b>EAGLE Design Rules</b> -<p> -Die Standard-Design-Rules sind so gewählt, dass sie für -die meisten Anwendungen passen. Sollte ihre Platine -besondere Anforderungen haben, treffen Sie die erforderlichen -Einstellungen hier und speichern die Design Rules unter -einem neuen Namen ab. -<b>EAGLE Design Rules</b> -<p> -The default Design Rules have been set to cover -a wide range of applications. Your particular design -may have different requirements, so please make the -necessary adjustments and save your customized -design rules under a new name. -<b>Seeed Studio EAGLE Design Rules</b> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Since Version 8.2, EAGLE supports online libraries. The ids -of those online libraries will not be understood (or retained) -with this version. - - -Since Version 8.3, EAGLE supports URNs for individual library -assets (packages, symbols, and devices). The URNs of those assets -will not be understood (or retained) with this version. - - -Since Version 8.3, EAGLE supports the association of 3D packages -with devices in libraries, schematics, and board files. Those 3D -packages will not be understood (or retained) with this version. - - - diff --git a/cad/RasPi-BplusHAT.sch b/cad/RasPi-BplusHAT.sch deleted file mode 100755 index b6a3d6d..0000000 --- a/cad/RasPi-BplusHAT.sch +++ /dev/null @@ -1,5830 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<b>Frames for Sheet and Layout</b> - - - - - - - - - - - - - - - - - - - - - - - ->DRAWING_NAME ->LAST_DATE_TIME ->SHEET -Sheet: - - - - - -<b>FRAME</b><p> -DIN A3, landscape with location and doc. field - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1 ->VALUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - -WEIDMULLER - PM5.08/2/90 - TERMINAL BLOCK, SIDE ENTRY, 2WAY - - ->NAME ->VALUE - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->VALUE ->NAME - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -chip, wave soldering - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.10 W - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.25 W - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.12 W - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.10 W - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.25 W - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.25 W - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.12 W - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -MELF 0.25 W - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -type 0204, grid 5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0204, grid 7.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0204, grid 2.5 mm - - - - - - ->NAME ->VALUE - - -<b>RESISTOR</b><p> -type 0207, grid 10 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0207, grid 12 mm - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - -<b>RESISTOR</b><p> -type 0207, grid 15mm - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - -<b>RESISTOR</b><p> -type 0207, grid 2.5 mm - - - - - - - ->NAME ->VALUE - - -<b>RESISTOR</b><p> -type 0207, grid 5 mm - - - - - - - ->NAME ->VALUE - - -<b>RESISTOR</b><p> -type 0207, grid 7.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0309, grid 10mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0309, grid 12.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0309, grid 2.5 mm - - - - - - ->NAME ->VALUE - - - - - -<b>RESISTOR</b><p> -type 0411, grid 12.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0411, grid 15 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0411, grid 3.81 mm - - - - - - ->NAME ->VALUE - - - -<b>RESISTOR</b><p> -type 0414, grid 15 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0414, grid 5 mm - - - - - - ->NAME ->VALUE - - - -<b>RESISTOR</b><p> -type 0617, grid 17.5 mm - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0617, grid 22.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0617, grid 5 mm - - - - - - ->NAME ->VALUE - - - -<b>RESISTOR</b><p> -type 0922, grid 22.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - -<b>RESISTOR</b><p> -type 0613, grid 5 mm - - - - - - ->NAME ->VALUE - - - -<b>RESISTOR</b><p> -type 0613, grid 15 mm - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type 0817, grid 22.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE -0817 - - - - -<b>RESISTOR</b><p> -type 0817, grid 6.35 mm - - - - - - ->NAME ->VALUE -0817 - - - -<b>RESISTOR</b><p> -type V234, grid 12.5 mm - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type V235, grid 17.78 mm - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>RESISTOR</b><p> -type V526-0, grid 2.5 mm - - - - - - - - - - ->NAME ->VALUE - - -<b>CECC Size RC2211</b> Reflow Soldering<p> -source Beyschlag - - - - - - ->NAME ->VALUE - - -<b>CECC Size RC2211</b> Wave Soldering<p> -source Beyschlag - - - - - - ->NAME ->VALUE - - -<b>CECC Size RC3715</b> Reflow Soldering<p> -source Beyschlag - - - - - - ->NAME ->VALUE - - -<b>CECC Size RC3715</b> Wave Soldering<p> -source Beyschlag - - - - - - ->NAME ->VALUE - - -<b>CECC Size RC6123</b> Reflow Soldering<p> -source Beyschlag - - - - - - ->NAME ->VALUE - - -<b>CECC Size RC6123</b> Wave Soldering<p> -source Beyschlag - - - - - - ->NAME ->VALUE - - -<b>RESISTOR</b><p> -type 0922, grid 7.5 mm - - - - - - ->NAME ->VALUE -0922 - - - -<b>RESISTOR</b><p> -type RDH, grid 15 mm - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE -RDH - - - - -<b>Mini MELF 0102 Axial</b> - - - - ->NAME ->VALUE - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -chip - - - - - - - - ->NAME ->VALUE - - - - - -<b>CAPACITOR</b><p> -grid 2.5 mm, outline 2.4 x 4.4 mm - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 mm, outline 2.5 x 5 mm - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 mm, outline 3 x 5 mm - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 mm, outline 4 x 5 mm - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 mm, outline 5 x 5 mm - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 mm, outline 6 x 5 mm - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 mm + 5 mm, outline 2.4 x 7 mm - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 + 5 mm, outline 2.5 x 7.5 mm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 + 5 mm, outline 3.5 x 7.5 mm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 + 5 mm, outline 4.5 x 7.5 mm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 2.5 + 5 mm, outline 5.5 x 7.5 mm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 2.4 x 4.4 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 2.5 x 7.5 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 4.5 x 7.5 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 3 x 7.5 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 5 x 7.5 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 5.5 x 7.5 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 7.5 x 7.5 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -Horizontal, grid 5 mm, outline 7.5 x 7.5 mm - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - -<b>CAPACITOR</b><p> -grid 7.5 mm, outline 3.2 x 10.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 7.5 mm, outline 4.2 x 10.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 7.5 mm, outline 5.2 x 10.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 10.2 mm, outline 4.3 x 13.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 10.2 mm, outline 5.4 x 13.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 10.2 mm, outline 6.4 x 13.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 10.2 mm + 15.2 mm, outline 6.2 x 18.4 mm - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 15 mm, outline 5.4 x 18.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 15 mm, outline 6.4 x 18.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 15 mm, outline 7.2 x 18.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 15 mm, outline 8.4 x 18.3 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 15 mm, outline 9.1 x 18.2 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 22.5 mm, outline 6.2 x 26.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 22.5 mm, outline 7.4 x 26.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 22.5 mm, outline 8.7 x 26.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 22.5 mm, outline 10.8 x 26.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 22.5 mm, outline 11.3 x 26.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 27.5 mm, outline 9.3 x 31.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 27.5 mm, outline 11.3 x 31.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 27.5 mm, outline 13.4 x 31.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 27.5 mm, outline 20.5 x 31.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 32.5 mm, outline 13.7 x 37.4 mm - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 32.5 mm, outline 16.2 x 37.4 mm - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 32.5 mm, outline 18.2 x 37.4 mm - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 37.5 mm, outline 19.2 x 41.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 37.5 mm, outline 20.3 x 41.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 5 mm, outline 3.5 x 7.5 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 37.5 mm, outline 15.5 x 41.8 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 7.5 mm, outline 6.3 x 10.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 27.5 mm, outline 15.4 x 31.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>CAPACITOR</b><p> -grid 27.5 mm, outline 17.3 x 31.6 mm - - - - - - - - - - - - - - - - ->NAME ->VALUE - - -<b>Ceramic Chip Capacitor KEMET 0204 Reflow solder</b><p> -Metric Code Size 1005 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 0603 Reflow solder</b><p> -Metric Code Size 1608 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 0805 Reflow solder</b><p> -Metric Code Size 2012 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 1206 Reflow solder</b><p> -Metric Code Size 3216 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 1210 Reflow solder</b><p> -Metric Code Size 3225 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 1812 Reflow solder</b><p> -Metric Code Size 4532 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 1825 Reflow solder</b><p> -Metric Code Size 4564 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 2220 Reflow solder</b><p> -Metric Code Size 5650 - - - - ->NAME ->VALUE - - - - -<b>Ceramic Chip Capacitor KEMET 2225 Reflow solder</b><p> -Metric Code Size 5664 - - - - ->NAME ->VALUE - - - - - - - - - - ->NAME ->VALUE - - - - - - ->NAME ->VALUE - - - - - - - - -<B>RESISTOR</B>, European symbol - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<B>CAPACITOR</B>, European symbol - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->VALUE - - - - - ->VALUE - - - - - ->VALUE - - - - - -<b>SUPPLY SYMBOL</b> - - - - - - - - - - - - -<b>SUPPLY SYMBOL</b> - - - - - - - - - - - - -<b>SUPPLY SYMBOL</b> - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->VALUE ->NAME - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<b>Pin Header Connectors</b><p> -<author>Created by librarian@cadsoft.de</author> - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - - - - - - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - -PIN HEADER - - - - - -PIN HEADER - - - - - -PIN HEADER - - - - - -PIN HEADER - - - - - - - - - - - ->NAME ->VALUE - - - - - - - - - - - - - - - - ->NAME ->VALUE - - - - - - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<b>PIN HEADER</b> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Drawn by: -Checked by: -FLYFISH TECHNOLOGIES d.o.o. -Ivan Zilic -v0.1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Since Version 8.2, EAGLE supports online libraries. The ids -of those online libraries will not be understood (or retained) -with this version. - - -Since Version 8.3, EAGLE supports URNs for individual library -assets (packages, symbols, and devices). The URNs of those assets -will not be understood (or retained) with this version. - - -Since Version 8.3, EAGLE supports the association of 3D packages -with devices in libraries, schematics, and board files. Those 3D -packages will not be understood (or retained) with this version. - - - diff --git a/cad/TMUX1133PWR.zip b/cad/TMUX1133PWR.zip new file mode 100644 index 0000000..2f652b3 Binary files /dev/null and b/cad/TMUX1133PWR.zip differ diff --git a/images/FlashBash.jpg b/images/FlashBash.jpg new file mode 100644 index 0000000..e8694bd Binary files /dev/null and b/images/FlashBash.jpg differ diff --git a/images/logo.png b/images/logo.png new file mode 100644 index 0000000..c1b5e9a Binary files /dev/null and b/images/logo.png differ diff --git a/src/flash_bash.c b/src/flash_bash.c index 1b80e2e..c8412aa 100755 --- a/src/flash_bash.c +++ b/src/flash_bash.c @@ -1,7 +1,12 @@ /* * flash_bash.c * - * Author: Cristian + * Flash BASH is a Raspberry Pi based tool to automate glitching into privileged shells like bootloader shells. + * This code utilizes the pigpio library to interface with the RPi's GPIO pins that will be used either as an input trigger or output trigger to initiate glitching. + * Please visit https://github.com/cristian-vences/flash-bash for more detail. + * + * Author: Cristian Vences + * Updated September 2024 */ #include //getchar,printf @@ -10,14 +15,11 @@ #include //strlen #include //strerror -#include //wiringPi -#include //serialOpen +#include //pigpio library -#define PIN7 7 //pin for glitching -#define PIN11 0 //pin for glitching +#define PIN7 4 //pin for glitching, broadcom number 4 +#define PIN11 17 //pin for glitching, broadcom number 17 -#define FLAT_LINE 1 //number definition -#define MORSE_CODE 2 //number definition #define TIMED 1 //number definition #define SERIAL 2 //number definition @@ -26,30 +28,82 @@ int main(void) { - int fd; //file descriptor - char start_trigger[100]; //glitch start trigger - char stop_trigger[100]; //glitch stop trigger - char buff[100]; //buffer for incoming serial - char device[100]; //device name from /dev - int i, n, n2, in; //for loops, for stringlength, for storing incoming serial - int choice; //for choosing glitch style - int baud; //stores baud rate - int val = 1; //value from string comparison - int count = 0; //simple count for how many times buff has been changed - int attack_type = 0; //attack style - int start_time = 0; //time for startup before glitching - int stop_time = 0; //time for tool to stop glitching + // Initialization variables + unsigned version; //store pigpio version + unsigned int hwRevision; //store hardware revision + char hwBuff[32]; //buffer for formatting unsigned int in hex + int gpioResult = 0; //store result from pigpio calls + + // Configuration variables + int choice; //for choosing glitch style + int attackType = 0; //attack style + + // Serial attack variables + int fd; //file descriptor + char startTrigger[100]; //glitch start trigger string + char stopTrigger[100]; //glitch stop trigger string + char buff[100]; //buffer for incoming serial characters + char device[100]; //device name from /dev + int i, n, n2, in; //for loops, for stringlength, for storing incoming serial + int baud; //stores baud rate + int val = 1; //value from string comparison + int count = 0; //simple count for how many times buff has been changed + + // Time attack variables + int startTime = 0; //time for startup before glitching + int stopTime = 0; //time for tool to stop glitching // Welcome printf("Welcome to Flash BASH!\n\n"); - printf("****CONFIGURATION*****\n\n"); - - // Initialize WiringPi - if (wiringPiSetup() == -1) - { - fprintf(stdout, "Unable to start wiringPi: %s\n", strerror(errno)); - return 1; - } + printf(" #############:: ########### \n"); + printf(" ########### ::: *########## \n"); + printf(" ########## :::: #####*##### \n"); + printf(" ###### ::::::::::*##*## \n"); + printf(" ####*# :::-::--::: *##### \n"); + printf(" ###### ::::::-:::: ###### \n"); + printf(" ###### ::::--::::: ###### \n"); + printf(" ######-:::::::::: ###### \n"); + printf(" ########### :::: ########## \n"); + printf(" ########### ::: ########### \n"); + printf(" ########### :: ############ \n"); + printf(" \n"); + printf(" ::::: : :: :: :: : \n"); + printf(" :::::: -:: :::- :::::: :: ::: \n"); + printf(" ::::: -:: ::::: :::::: ::::::: \n"); + printf(" ::: -:: :::::: ::-::: :: ::: \n"); + printf(" ::: :::::: :: ::: ::::: :: ::: \n"); + printf(" \n"); + printf(" ############### ###### ###############* ##### #####\n"); + printf("################# ######### ################ ##### #####\n"); + printf(" ##### #*######### ##### ################\n"); + printf("################ ###### *###### ################# ################\n"); + printf("##### ####* ##### #####* ####* #####******#####\n"); + printf("################# ###### ############ ################# ##### #####\n"); + printf("################ #####*################*################* ##### #####\n"); + + // Print versions + printf("\n****CHECKING VERSIONS*****\n\n"); + version = gpioVersion(); //call for pigpio version + printf("Using pigpio version: %u\n", version); + + hwRevision = gpioHardwareRevision(); //call for hardware revision https://abyz.me.uk/rpi/pigpio/cif.html#gpioHardwareRevision + snprintf(hwBuff, sizeof(hwBuff), "%x", hwRevision); //securely format the hardware revision as a hex string + printf("Running on: %s\n", hwBuff); + + // Initialize pigpio + printf("Initializing pigpio. . ."); + gpioResult = gpioInitialise(); + + if (gpioResult == PI_INIT_FAILED) { + printf("ERROR\n Unable to initialize pigpio.\n"); + printf("Error value = %d\n", gpioResult); + return -1; // Return -1 value to indicate an error + } + + printf(" SUCCESS\n"); + + // Begin configuration + printf("\n****CONFIGURATION*****\n\n"); // Get attack style selection from user printf("What type of attack? TIMED [1] or SERIAL [2]: "); @@ -57,33 +111,57 @@ int main(void) if ((choice != 1) && (choice != 2)) { printf("Invalid selection, expect 1 or 2.\n"); - return 1; + return -1; } else if (choice == 1) { - attack_type = TIMED; + attackType = TIMED; printf("Attack style: TIMED\n\n"); } else { - attack_type = SERIAL; + attackType = SERIAL; printf("Attack style: SERIAL\n\n"); } - // Go through set up for serial attack - if (attack_type == SERIAL) + // Configure the GPIO pin attached to the MUX as an output pin + // PI_OUTPUT is defined within the pigpio library + gpioResult = gpioSetMode(PIN7, PI_OUTPUT); + + // Check the result to ensure the GPIO pin could be properly configured + if (gpioResult != 0) // A value of 0 = OK { - // Initialize wiringPi - pinMode(PIN7, OUTPUT); //sets pin mode to output - digitalWrite(PIN7, HIGH); //initially sets it to high + // Error handling + switch (gpioResult) + { + case PI_BAD_GPIO: + printf("%d is a bad gpio pin\n", PIN7); + return -1; + case PI_BAD_MODE: + printf("Bad mode specified for gpio pin %d\n", PIN7); + return -1; + + default: + printf("Unexpected error encountered when setting mode specified for gpio pin %d\n", PIN7); + printf("Result = %d\n", gpioResult); + return -1; + } + } + + // Initially set PIN7 to high + gpioWrite(PIN7, PI_ON); + + // Go through set up for serial attack + if (attackType == SERIAL) + { // Get Baud rate from user printf("What BAUD (9600, 115200, 38400, etc): "); scanf("%d", &baud); if ((baud <= 0) && (baud >= 250001)) { printf("Invalid baud rate entry (expects 1 to 250000 baud).\n"); - return 1; + return -1; } else { @@ -91,168 +169,294 @@ int main(void) } // Get serial device from user - printf("Enter serial device descriptor:\n"); + printf("Enter serial device descriptor: "); scanf("%99s", device); printf("Device descriptor = `%s`\n\n", device); // Initialize serial communication - if ((fd = serialOpen(device, baud)) == -1) + if ((fd = serOpen(device, baud, 0)) < 0) // A value of 0 >= OK { - fprintf(stderr, "Unable to open serial devices: %s\n", strerror(errno)); - return 1; + // Error handling + switch (fd) + { + case PI_NO_HANDLE: + printf("No handle available: %d\n", fd); + return -1; + + case PI_SER_OPEN_FAILED: + printf("Can't open serial device: %d\n", fd); + return -1; + + default: + printf("Unexpected error encountered when setting mode specified for gpio pin %d\n", fd); + printf("Result = %d\n", gpioResult); + return -1; + } } - // Obtain glitch trigger 1 from user + // Obtain start trigger for glitching from user printf("What phrase would you like to start glitching on? (no longer than 99 characters):\n"); - scanf("%99s", start_trigger); - n = strlen(start_trigger); + scanf("%99s", startTrigger); + n = strlen(startTrigger); printf("Trigger string length = %d\n", n); - printf("Glitch string = %s\n\n", start_trigger); + printf("Glitch string = '%s'\n\n", startTrigger); - // Obtain glitch trigger 2 from user + // Obtain stop trigger for glitching from user printf("What phrase would you like to stop glitching on? (no longer than 99 characters):\n"); - scanf("%99s", stop_trigger); - n2 = strlen(stop_trigger); - printf("Stirng length = %d\n", n2); - printf("Glitch string = %s\n", stop_trigger); + scanf("%99s", stopTrigger); + n2 = strlen(stopTrigger); + printf("Trigger tirng length = %d\n", n2); + printf("Glitch string = '%s'\n", stopTrigger); // This buffer is filled by the serial output from target device. - // The buffer is compared to start_trigger and stop_trigger. All 3 are of size 100. + // The buffer is compared to startTrigger and stopTrigger. All 3 are of size 100. // Once buffer is equal to a trigger it either grounds the pin or releases // Fill in buffer once from serial for (i = 0; i < n; i++) { - in = serialGetchar(fd); - serialPutchar(fd, in); - buff[i] = in; + // Begin reading from serial input + if ((in = serReadByte(fd)) < 0) // A value of 0 >= is a legit character + { + // Error handling + switch (in) + { + case PI_BAD_HANDLE: + printf("Bad handle provided: %d\n", in); + return -1; + + case PI_SER_READ_FAILED: + printf("Serial read failed: %d\n", in); + return -1; + + case PI_SER_READ_NO_DATA: + break; + + default: + printf("Unexpected error encountered when reading byte: %d\n", in); + return -1; + } + } else { + buff[i] = in; + } } buff[i] = '\0'; #ifdef SHOW_OUTPUT printf("%d: buff = %s\n", count, buff); #endif - val = strcmp(buff, start_trigger); //compare the buffer to the trigger + val = strcmp(buff, startTrigger); //compare the buffer to the trigger // Start loop to compare strings // NOTE: This code could be made faster for efficiency and accuracy of // triggering, however in basic glitching scenarios this is good enough. while (val != 0) { //run loop until buff and trigger are the same - in = serialGetchar(fd); - fflush(stdout); - // This loop 'shifts' the buffer down to make space for the incoming - // byte, as we do a rolling comparison byte-by-byte. - for (i = 0; i < n - 1; i++) + if ((in = serReadByte(fd)) < 0) // A value of 0 >= is a legit character { - buff[i] = buff[i + 1]; - } - buff[i] = in; - buff[i + 1] = '\0'; - count++; + // Error handling + switch (in) + { + case PI_BAD_HANDLE: + printf("Bad handle provided: %d\n", in); + return -1; + + case PI_SER_READ_FAILED: + printf("Serial read failed: %d\n", in); + return -1; + + case PI_SER_READ_NO_DATA: + break; + + default: + printf("Unexpected error encountered when reading byte: %d\n", in); + return -1; + } + } else { + fflush(stdout); + // This loop 'shifts' the buffer down to make space for the incoming + // byte, as we do a rolling comparison byte-by-byte. + for (i = 0; i < n - 1; i++) + { + buff[i] = buff[i + 1]; + } + buff[i] = in; + buff[i + 1] = '\0'; + count++; #ifdef SHOW_OUTPUT printf("%d: buff = %s\n", count, buff); #endif - // If start_trigger == buff, break out of this loop: - val = strcmp(buff, start_trigger); + // If startTrigger == buff, break out of this loop: + val = strcmp(buff, startTrigger); + } } // Print success statement and trigger glitching printf("\n\n\n\n\nGLITCHING INITIATED!\n\n\n\n\n"); //buff and trigger == - digitalWrite(PIN7, LOW); //tigger MUX + gpioWrite(PIN7, PI_OFF); //trigger MUX val = 1; //reset loop breaker count = 0; //reset buffer count + // Begin comparing target output to stopTrigger to cease glitching // Fill in buffer once from serial for (i = 0; i < n2; i++) { - in = serialGetchar(fd); - serialPutchar(fd, in); - buff[i] = in; + if ((in = serReadByte(fd)) < 0) // A value of 0 >= is a legit character + { + // Error handling + switch (in) + { + case PI_BAD_HANDLE: + printf("Bad handle provided: %d\n", in); + return -1; + + case PI_SER_READ_FAILED: + printf("Serial read failed: %d\n", in); + return -1; + + case PI_SER_READ_NO_DATA: + break; + + default: + printf("Unexpected error encountered when reading byte: %d\n", in); + return -1; + } + } else { + buff[i] = in; + } } buff[i] = '\0'; #ifdef SHOW_OUTPUT printf("%d: buff = %s\n", count, buff); #endif - val = strcmp(buff, stop_trigger); //compare the buffer to the trigger + val = strcmp(buff, stopTrigger); //compare the buffer to the trigger // Start loop to compare strings while (val != 0) - { - //run loop until buff and trigger are the same - in = serialGetchar(fd); - fflush(stdout); - for (i = 0; i < n2 - 1; i++) + { //run loop until buff and trigger are the same + if ((in = serReadByte(fd)) < 0) // A value of 0 >= is a legit character { - buff[i] = buff[i + 1]; - } - buff[i] = in; - buff[i + 1] = '\0'; - count++; + switch (in) + { + case PI_BAD_HANDLE: + printf("Bad handle provided: %d\n", in); + return -1; + + case PI_SER_READ_FAILED: + printf("Serial read failed: %d\n", in); + return -1; + + case PI_SER_READ_NO_DATA: + break; + + default: + printf("Unexpected error encountered when reading byte: %d\n", in); + return -1; + } + } else { + fflush(stdout); + // This loop 'shifts' the buffer down to make space for the incoming + // byte, as we do a rolling comparison byte-by-byte. + for (i = 0; i < n2 - 1; i++) + { + buff[i] = buff[i + 1]; + } + buff[i] = in; + buff[i + 1] = '\0'; + count++; #ifdef SHOW_OUTPUT printf("%d: buff = %s\n", count, buff); #endif - val = strcmp(buff, stop_trigger); + // If stopTrigger == buff, break out of this loop: + val = strcmp(buff, stopTrigger); + } } // Print success statement and trigger glitching printf("\n\n\n\nGLITCHED\n\n\n\n"); //buff and trigger == - digitalWrite(PIN7, HIGH); //tigger MUX + gpioWrite(PIN7, PI_ON); //trigger MUX val = 1; count = 0; // Close serial port - serialClose(fd); + serClose(fd); } else { // Set up timed glitch attack - pinMode(PIN11, INPUT); //sets pin mode to INPUT + + // Configure the GPIO pin attached to the target VCC as an input pin + // PI_INPUT is defined within the pigpio library + gpioResult = gpioSetMode(PIN11, PI_INPUT); + + // Check the result to ensure the GPIO pin could be properly configured + if (gpioResult != 0) // A value of 0 = OK + { + // Error handling + switch (gpioResult) + { + case PI_BAD_GPIO: + printf("%d is a bad gpio pin\n", PIN11); + return -1; + + case PI_BAD_MODE: + printf("Bad mode specified for gpio pin %d\n", PIN11); + return -1; + + default: + printf("Unexpected error encountered when setting mode specified for gpio pin %d\n", PIN11); + printf("Result = %d\n", gpioResult); + return -1; + } + } // Get time variable from user printf("How long after boot to start glitching (1 - 300 secs): "); - scanf("%d", &start_time); - if ((start_time <= 0) && (start_time >= 301)) + scanf("%d", &startTime); + if ((startTime <= 0) && (startTime >= 301)) { printf("Invalid time entry (expects 1 to 300 secs).\n"); - return 1; + return -1; } else { - printf("start_time = %d\n\n", start_time); + printf("startTime = %d\n\n", startTime); } printf("How long after glitching has started to stop (1 - 300 secs): "); - scanf("%d", &stop_time); - if ((stop_time <= 0) && (stop_time >= 301)) + scanf("%d", &stopTime); + if ((stopTime <= 0) && (stopTime >= 301)) { printf("Invalid time entry (expects 1 to 300 secs).\n"); - return 1; + return -1; } else { - printf("stop_time = %d\n\n", stop_time); + printf("stopTime = %d\n\n", stopTime); } printf("Please turn on target device now!\n\n"); - while (digitalRead(PIN11) != 1) + while (gpioRead(PIN11) != 1) { // Wait for device to turn on, as PIN11 is sensing device VCC. } - // NOTE: Percision of this is not optimal as OS may not give us accurate timing, + // NOTE: Precision of this is not optimal as OS may not give us accurate timing, // users who need more precision should update this. - sleep(start_time); + sleep(startTime); - digitalWrite(PIN7, LOW); //tigger MUX + gpioWrite(PIN7, PI_OFF); //trigger MUX printf("\n\n\n\n\nGLITCHING INITIATED!\n\n\n\n\n"); //buff and trigger == // NOTE: See above (lack of) precision note. - sleep(stop_time); + sleep(stopTime); - digitalWrite(PIN7, HIGH); //tigger MUX + gpioWrite(PIN7, PI_ON); //trigger MUX printf("\n\n\n\nGLITCHING CEASED\n\n\n\n"); //time elapsed } + // Terminate the pigpio library to clean up + gpioTerminate(); + return 0; -} +} \ No newline at end of file