1 / 8 23.4.2017 17:36 g_{hid,ether,serial,*}
2 / 8 23.4.2017 17:36 $ sudo BRANCH=next rpi-update $ echo "dtoverlay=dwc2" sudo tee -a /boot/config.txt $ echo "dwc2" sudo tee -a /etc/modules libcomposite $ sudo echo "libcomposite" sudo tee -a /etc/modules /sys/
3 / 8 23.4.2017 17:36 isticktoit_usb /usr/bin/ $ sudo touch /usr/bin/isticktoit_usb #create the file $ sudo chmod +x /usr/bin/isticktoit_usb #make it executable $ sudo nano /usr/bin/isticktoit_usb #edit the file rc.local /etc/rc.local $ sudo nano /etc/rc.local GNU nano 1.2.3 File: /etc/rc.local... /usr/bin/isticktoit_usb # libcomposite configuration exit #!/bin/bash cd /sys/kernel/config/usb_gadget/ mkdir -p isticktoit cd isticktoit echo 0x1d6b > idvendor # Linux Foundation echo 0x0104 > idproduct # Multifunction Composite Gadget echo 0x0100 > bcddevice # v1.0.0 echo 0x0200 > bcdusb # USB2 mkdir -p strings/0x409 echo "fedcba9876543210" > strings/0x409/serialnumber echo "Tobias Girstmair" > strings/0x409/manufacturer echo "isticktoit.net USB Device" > strings/0x409/product mkdir -p configs/c.1/strings/0x409 echo "Config 1: ECM network" > configs/c.1/strings/0x409 /configuration echo 250 > configs/c.1/maxpower
4 / 8 23.4.2017 17:36 # see gadget configurations below # End functions ls /sys/class/udc > UDC mkdir -p functions/acm.usb0 ln -s functions/acm.usb0 configs/c.1/ # End functions $ sudo systemctl enable getty@ttygs0.service install screen screen sudo apt-get $ sudo screen /dev/ttyacm0 115200 $ dmesg grep "USB ACM device" $ sudo nano /usr/bin/isticktoit_usb
5 / 8 23.4.2017 17:36 mkdir -p functions/ecm.usb0 # first byte of address must be even HOST="48:6f:73:74:50:43" # "HostPC" SELF="42:61:64:55:53:42" # "BadUSB" echo $HOST > functions/ecm.usb0/host_addr echo $SELF > functions/ecm.usb0/dev_addr ln -s functions/ecm.usb0 configs/c.1/ # End functions ls /sys/class/udc > UDC #put this at the very end of the file: ifconfig usb0 10.0.0.1 netmask 255.255.255.252 up route add -net default gw 10.0.0.2 $ dmesg grep cdc_ether [13890.668557] cdc_ether 1-1:1.2 eth0: register 'cdc_ether' at usb-0000:00:14.0-1, CDC Ethernet Device, 48:6f:73:74:50:43 [13890.674117] usbcore: registered new interface driver cdc_ether [13890.687619] cdc_ether 1-1:1.2 enp0s20u1i2: renamed from eth0 $ sudo ifconfig enp0s20u1i2 10.0.0.2 netmask 255.255.255.252 up $ ssh 10.0.0.1 -l pi $ sudo nano /usr/bin/isticktoit_usb
6 / 8 23.4.2017 17:36 mkdir -p functions/hid.usb0 echo 1 > functions/hid.0/protocol echo 1 > functions/hid.0/subclass echo 8 > functions/hid.0/report_length echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0 \\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02 \\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08 \\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03 \\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00 \\x29\\x65\\x81\\x00\\xc0 > functions/hid.0/report_desc ln -s functions/hid.usb0 configs/c.1/ # End functions $ sudo su # echo -ne "\0\0\x4\0\0\0\0\0" > /dev/hidg0 #press the A-button # echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0 #release all keys $ cd PATH_TO_HARDPASS_REPO $ make #compile the program $ echo -n "hello world!" sudo./scan /dev/hidg0 1 2 count=1024
7 / 8 23.4.2017 17:36 $ dd if=/dev/zero of=~/usbdisk.img bs=1024 count=1024 $ mkdosfs ~/usbdisk.img sudo nano /usr/bin/isticktoit_usb FILE=/home/pi/usbdisk.img mkdir -p ${FILE/img/d} # mount -o loop,ro,offset=1048576 -t ext4 $FILE ${FILE/img/d} # FOR OLD WAY OF MAKING THE IMAGE mount -o loop,ro, -t vfat $FILE ${FILE/img/d} # FOR IMAGE CREATED WITH DD mkdir -p functions/mass_storage.usb0 echo 1 > functions/mass_storage.usb0/stall 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 $FILE > functions/mass_storage.usb0/lun.0/file ln -s functions/mass_storage.usb0 configs/c.1/ # End functions$
8 / 8 23.4.2017 17:36 Article Revisions 1.000: Initial article 1.001: Added 'Hi, Hackaday' 1.010: Fixed configuration script ('') (thanks, Hans) 1.011: Fixed and simplified a few things (thanks, Tom) 1.100: Fixed the 'press A-button' example (missing `-ne`) (thanks, Jim)