Skip to content

Instantly share code, notes, and snippets.

@lucian303
Created September 12, 2021 06:57
Show Gist options
  • Save lucian303/ea64b6ccdf6175db8fa132aa6acc56ce to your computer and use it in GitHub Desktop.
Save lucian303/ea64b6ccdf6175db8fa132aa6acc56ce to your computer and use it in GitHub Desktop.
#! /bin/bash
# Load libcomposite
modprobe libcomposite
# Create a gadget called usb-gadgets
cd /sys/kernel/config/usb_gadget/
mkdir -p usb-gadgets
cd usb-gadgets
# Configure our gadget details
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 "Phenotype" > strings/0x409/manufacturer
echo "Phenotype X" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Phenotype MIDI" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
echo 0xEF > bDeviceClass
echo 0x02 > bDeviceSubClass
echo 0x01 > bDeviceProtocol
# Ethernet gadget
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/
# MIDI
mkdir -p functions/midi.usb0
echo "Phenotype X" > functions/midi.usb0/id
#echo "1" > functions/midi.usb0/index
echo "16" > functions/midi.usb0/in_ports
echo "16" > functions/midi.usb0/out_ports
ln -s functions/midi.usb0 configs/c.1/
# Mass Storage
FILE=/root/usbdisk.img
mkdir -p ${FILE/img/d}
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
#ls /sys/class/udc > UDC
name="$(ls /sys/class/udc)"
echo "$name" > UDC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment