Skip to content

Commit

Permalink
Mass Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
arrase committed Apr 1, 2017
1 parent eedd9f8 commit c009374
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
Binary file removed hid-gadget-test
Binary file not shown.
21 changes: 19 additions & 2 deletions hid.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash

# modprobe libcomposite
. /etc/raspiducky/raspiducky.conf

# KEYBOARD
cd /sys/kernel/config/usb_gadget/
mkdir -p g1
cd g1
Expand All @@ -15,6 +14,8 @@ echo "fedcba9876543210" > strings/0x409/serialnumber
echo "Parasite Team" > strings/0x409/manufacturer
echo "Raspiducky" > strings/0x409/product
N="usb0"

# KEYBOARD
mkdir -p functions/hid.$N
echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
Expand All @@ -27,5 +28,21 @@ echo 250 > configs/c.$C/MaxPower
ln -s functions/hid.$N configs/c.$C/
# End KEYBOARD

# STORAGE
if [ -e $STORAGE_FILE ]
then
[ -d $STORAGE_MOUNT ] || mkdir $STORAGE_MOUNT
mount -o loop,rw -t vfat $STORAGE_FILE $STORAGE_MOUNT
mkdir -p functions/mass_storage.usb0
echo 1 > functions/mass_storage.usb0/stall
echo 0 > functions/mass_storage.usb0/lun.0/removable
echo 0 > functions/mass_storage.usb0/lun.0/cdrom
echo 0 > functions/mass_storage.usb0/lun.0/ro
echo 0 > functions/mass_storage.usb0/lun.0/nofua
echo $STORAGE_FILE > functions/mass_storage.usb0/lun.0/file
ln -s functions/mass_storage.usb0 configs/c.$C/
fi
# End STORAGE

ls /sys/class/udc > UDC

30 changes: 30 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

INSTALL_DIR=/home/pi

gcc hid-gadget-test.c -o $INSTALL_DIR/hid-gadget-test
cp usleep $INSTALL_DIR/
cp duckpi.sh $INSTALL_DIR/
cp hid.sh $INSTALL_DIR/
cp run_payload.sh $INSTALL_DIR

chmod 777 $INSTALL_DIR/hid-gadget-test
chmod 777 $INSTALL_DIR/usleep
chmod 777 $INSTALL_DIR/duckpi.sh
chmod 777 $INSTALL_DIR/hid.sh
chmod 777 $INSTALL_DIR/run_payload.sh

[ -d /etc/raspiducky ] || sudo mkdir /etc/raspiducky
[ -f /etc/raspiducky/raspiducky.conf ] || sudo cp raspiducky.conf /etc/raspiducky/raspiducky.conf

sudo echo "dtoverlay=dwc2" >> /boot/config.txt
sudo echo "dwc2" >> /etc/modules
sudo echo "libcomposite" >> /etc/modules

cat /etc/rc.local | awk '/exit\ 0/ && c == 0 {c = 0; print "\n/home/pi/hid.sh\nsleep 3\n/home/pi/run_payload.sh\n"}; {print}' /etc/rc.local

if ! [ -e /home/pi/usbdisk.img ]
then
dd if=/dev/zero of=/home/pi/usbdisk.img bs=1024 count=10000
mkfs.vfat /home/pi/usbdisk.img
fi
2 changes: 2 additions & 0 deletions raspiducky.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
STORAGE_FILE=/home/pi/usbdisk.img
STORAGE_MOUNT=/media/storage

0 comments on commit c009374

Please sign in to comment.