Skip to content

Commit

Permalink
Merge pull request #8 from arrase/config_over_usb
Browse files Browse the repository at this point in the history
Config over usb
  • Loading branch information
arrase authored Apr 2, 2017
2 parents e1abc5e + bbf5ef1 commit 34408d3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 21 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,34 @@ A Keyboard emulator like Rubber Ducky build over Raspberry Pi Zero

* Flash Raspbian
* Login as pi, use a screen over HDMI and a keyboard over usb port
* Connect the raspberry to internet over wifi
* Clone the repository

git clone https://github.com/arrase/Raspiducky.git

* Run install script

cd Raspiducky
chmod 777 install.sh
./install.sh

* Install a payload
* Delete the install folder and reboot

cd ..
rm -rf Raspiducky
sudo reboot

### First boot

When Raspiducky boots for first time the configuration is exposed over usb emulation

* Run a payload on boot

sudo cat payloads-db/open_terminal/open_mint_terminal.dd payloads-db/backdoor/bind_shell.dd > onboot_payload/payload.dd

* Flash drive options

sudo cat payloads/open_terminal/open_mint_terminal.dd payloads/backdoor/bind_shell.dd > /boot/payload.dd
vim etc/raspiducky.conf

### Resources:

Expand Down
17 changes: 12 additions & 5 deletions hid.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. /etc/raspiducky/raspiducky.conf
. /home/pi/config/etc/raspiducky.conf

cd /sys/kernel/config/usb_gadget/
mkdir -p g1
Expand Down Expand Up @@ -29,17 +29,24 @@ ln -s functions/hid.$N configs/c.$C/
# End KEYBOARD

# STORAGE
if [ -e $STORAGE_FILE ]
if [ $STORAGE_MODE != "none" ]
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

if [ $STORAGE_MODE = "disk" ]
then
[ -d $STORAGE_MOUNT ] || mkdir $STORAGE_MOUNT
mount -o loop,rw -t vfat $STORAGE_FILE $STORAGE_MOUNT
echo $STORAGE_FILE > functions/mass_storage.usb0/lun.0/file
else
echo $STORAGE_CONFIG > functions/mass_storage.usb0/lun.0/file
fi

ln -s functions/mass_storage.usb0 configs/c.$C/
fi
# End STORAGE
Expand Down
40 changes: 29 additions & 11 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash

INSTALL_DIR=/home/pi
USERID=1000
GROUPID=1000
FLASH_DISK_SIZE=100000 # 100MB

# EXEC FILES

gcc hid-gadget-test.c -o $INSTALL_DIR/hid-gadget-test
cp usleep $INSTALL_DIR/
Expand All @@ -14,17 +19,30 @@ 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
# APP CONFIG

dd if=/dev/zero of=$INSTALL_DIR/.confdisk.img bs=1024 count=10000
mkfs.vfat $INSTALL_DIR/.confdisk.img

[ -d $INSTALL_DIR/config ] || mkdir $INSTALL_DIR/config
sudo mount $INSTALL_DIR/.confdisk.img $INSTALL_DIR/config -o loop,rw,uid=$USERID,gid=$GROUPID

[ -d $INSTALL_DIR/config/etc ] || mkdir $INSTALL_DIR/config/etc
[ -f $INSTALL_DIR/config/etc/raspiducky.conf ] || cp raspiducky.conf $INSTALL_DIR/config/etc/raspiducky.conf
[ -d $INSTALL_DIR/config/payloads-db ] || cp -r payloads $INSTALL_DIR/config/payloads-db
[ -d $INSTALL_DIR/config/onboot_payload ] || mkdir $INSTALL_DIR/config/onboot_payload
echo "$INSTALL_DIR/.confdisk.img $INSTALL_DIR/config vfat loop,rw 0 2" | sudo tee --append /etc/fstab
sudo umount $INSTALL_DIR/config

# BOOT CONFIG

echo "dtoverlay=dwc2" | sudo tee --append /boot/config.txt
echo "dwc2" | sudo tee --append /etc/modules
echo "libcomposite" | sudo tee --append /etc/modules

sudo echo "dtoverlay=dwc2" >> /boot/config.txt
sudo echo "dwc2" >> /etc/modules
sudo echo "libcomposite" >> /etc/modules
cat /etc/rc.local | sudo 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

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
# FLASH DRIVE

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
dd if=/dev/zero of=$INSTALL_DIR/.usbdisk.img bs=1024 count=$FLASH_DISK_SIZE
mkfs.vfat $INSTALL_DIR/.usbdisk.img
12 changes: 10 additions & 2 deletions raspiducky.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
STORAGE_FILE=/home/pi/usbdisk.img
STORAGE_MOUNT=/media/storage
INSTALL_DIR=/home/pi

# Available modes are 'config' , 'disk' or 'none'
STORAGE_MODE=config

STORAGE_FILE=$INSTALL_DIR/.usbdisk.img
STORAGE_MOUNT=$INSTALL_DIR/storage

STORAGE_CONFIG=$INSTALL_DIR/.confdisk.img
STORAGE_CONFIG_MOUNT=$INSTALL_DIR/config
2 changes: 1 addition & 1 deletion run_payload.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

cat /boot/payload.dd > /home/pi/payload.dd
cat /home/pi/config/onboot_payload/payload.dd > /home/pi/payload.dd
tr -d '\r' < /home/pi/payload.dd > /home/pi/payload2.dd
/home/pi/duckpi.sh /home/pi/payload2.dd

0 comments on commit 34408d3

Please sign in to comment.