This document contains end-to-end instructions on how to set up Raw Gadget on a Raspberri Pi board. The instructions were tested on Raspberry Pi Zero, Raspberry Pi Zero W, and Raspberry Pi 4 B, but they should be easily adaptable to other boards.
- Raspberry Pi board;
- SD card;
- USB UART adapter with jumper cables (or a Pi-specific adapter);
- USB Ethernet adapter (or Wi-Fi support on the board);
- USB cables.
-
Download the latest
Raspberry Pi OS with desktop
image; -
Extract the downloaded image and flash it into an SD card:
unxz 2024-03-15-raspios-bookworm-armhf.img.xz sudo dd if=2024-03-15-raspios-bookworm-armhf.img of=/dev/sdb bs=4M conv=fsync
-
Create a user
pi
with the passwordraspberry
by creating abootfs/userconf.txt
file with the following contents:pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0
-
Enable UART by appending
enable_uart=1
to the end of thebootfs/config.txt
file; -
Boot the board and get a shell over UART.
For this step, you will need a USB UART adapter with jumper cables.
Here are the instructions for Raspberry Pi Zero.
Note that getting the login prompt over UART takes a few minutes when you boot the board for the first time.
Getting a shell over SSH is also fine as long as the USB OTG port on the board remains available. Thus, on Raspberry Pi Zero (without Wi-Fi) you will have to get a shell over UART, as the USB Ethernet cable takes up the USB OTG port;
-
Get the board connected to the internet by plugging in a USB Ethernet adapter or use Wi-Fi on a Wi-Fi–enabled board;
-
Update the packages:
sudo apt-get update && sudo apt-get dist-upgrade && sudo rpi-update && sudo reboot
; -
Install useful packages:
sudo apt-get install vim git
; -
Install the Linux kernel header by following these instructions Linux kernel headers;
-
Setup the dwc2 UDC driver:
echo "dtoverlay=dwc2" | sudo tee -a /boot/firmware/config.txt echo "dwc2" | sudo tee -a /etc/modules sudo reboot
-
Clone the Raw Gadget repository;
-
Build and load the USB Raw Gadget module following these instructions;
-
Connect the Raspberry Pi USB OTG port to a USB host.
On Raspberry Pi Zero, this port is titled
USB
on the board. You will need to unplug the USB Ethernet adapter for this step if you have it plugged in.On Raspberry Pi 4 B, the OTG port is the Type-C one titled
POWER IN
. It can be used for both powering the board and emulating USB devices at the same time. You might need to power off the board to reconnect it to the USB host; -
Build and run the Raw Gadget keyboard emulator program:
cd raw-gadget/examples make sudo ./keyboard 20980000.usb 20980000.usb
You might need to change the UDC device and driver names;
-
Make sure that you see the letter
x
being entered on the host.With this step, you confirmed that Raw Gadget is working properly.
To turn a Raspberry Pi Zero W into a drive-by USB attack tool:
-
Set up a Wi-Fi hotspot;
-
Enable SSH server;
-
Solder Zero Stem onto the board.
You can now connect the board to any USB port, wait for it to boot, join its Wi-Fi network, ssh
onto it, and emulate arbitrary USB devices via Raw Gadget or other Linux USB Gadget interfaces.