USB composite working on Mac OS (Debian 8.0, credit to ckuethe)

1,257 views
Skip to first unread message

Brendan Smithyman

unread,
Aug 27, 2015, 11:07:05 PM8/27/15
to USB armory
Hi All,

I received my USB Armory today and have been playing around with USB gadget configurations on Mac OS. Unlike Linux, Mac OS doesn't seem to play nicely with the g_multi.ko module, and so using USB Ethernet alongside any other mode is problematic. However, Chris Kuethe has some code on GitHub that seems to work pretty well. This is based on that code, with a bit of extra configuration to get things working on Debian 8.0 (Jessie) with systemd.

Installation:
root@usbarmory:/# systemctl enable usb-composite
Created symlink from /etc/systemd/system/usb-composite.service to /lib/systemd/system/usb-composite.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/usb-composite.service to /lib/systemd/system/usb-composite.service.

Reboot, and you should have support for a simple USB host device (image stored in /root/backingstore.img), USB ethernet, serial port, etc. Hopefully this is helpful to people, and please let me know if there are obvious improvements (I'm new to the USB gadget interface, and there are probably some gotchas). Confirmed working on a MBP Retina with OS X Yosemite.

Cheers,
Brendan

--

/lib/systemd/system/usb-composite.service
[Unit]
Description=Configuration for USB composite device
Before=network.target

[Service]
ExecStart=/usr/local/sbin/usb-composite.sh

[Install]
WantedBy=multi-user.target
Alias=usb-composite.service

/etc/modules (note no "g_ether" or "g_multi")
ledtrig_heartbeat
ci_hdrc_imx

/usr/local/sbin/usb-composite.sh (based almost exclusively on ckuethe's configuration)
#!/bin/bash

# assumes a disk image exists here...
FILE=/root/backingstore.img
N="usb0"

modprobe -r g_ether

modprobe usb_f_mass_storage
modprobe usb_f_acm
modprobe usb_f_hid
modprobe usb_f_rndis
modprobe usb_f_ecm
modprobe usb_f_serial

cd /sys/kernel/config/usb_gadget/

mkdir -p usbarmory
cd usbarmory
#echo '' > UDC

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 "Inverse Path" > strings/0x409/manufacturer
echo "USB Armory" > strings/0x409/product

mkdir -p functions/acm.$N
mkdir -p functions/ecm.$N
mkdir -p functions/hid.$N
mkdir -p functions/mass_storage.$N

# first byte of address must be even
HOST="1a:55:89:a2:69:42" # "HostPC"
SELF="1a:55:89:a2:69:41" # "BadUSB"
echo $HOST > functions/ecm.$N/host_addr
echo $SELF > functions/ecm.$N/dev_addr

echo 1 > functions/mass_storage.$N/stall
echo 0 > functions/mass_storage.$N/lun.0/cdrom
echo 0 > functions/mass_storage.$N/lun.0/ro
echo 0 > functions/mass_storage.$N/lun.0/nofua
echo $FILE > functions/mass_storage.$N/lun.0/file

echo 1 > functions/hid.0/protocol
echo 1 > functions/hid.0/subclass

szabob...@gmail.com

unread,
Sep 3, 2015, 11:22:15 AM9/3/15
to USB armory
It does not work ... the led blinks but I can not connect to it trough ssh or mass storage... there is something that is missing here?

Andrea Barisani

unread,
Sep 3, 2015, 11:32:55 AM9/3/15
to szabob...@gmail.com, USB armory
On Thu, Sep 3, 2015 at 5:22 PM, <szabob...@gmail.com> wrote:
It does not work ... the led blinks but I can not connect to it trough ssh or mass storage... there is something that is missing here?


Do you see the RNDIS/CDC interface in your OS X network configuration dialog ?

We encountered an OS X bug where, on MAC address changes, you would see the interface up and running as "green" but no IP address is actually assigned.

Please ensure that you can see the interface, with the right IP address, on both the OS X network dialog as well as from the command line ("sudo ifconfig -a", it should be one of the en* interfaces).
 

--
You received this message because you are subscribed to the Google Groups "USB armory" group.
To unsubscribe from this group and stop receiving emails from it, send an email to usbarmory+...@googlegroups.com.
To post to this group, send email to usba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/usbarmory/fe7eef3d-6cea-4673-9e84-b68f57878dde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brendan Smithyman

unread,
Sep 3, 2015, 11:35:35 AM9/3/15
to szabob...@gmail.com, USB armory
I’m actually still working on a fully stable configuration myself, but the most likely issue is if you haven’t created the USB Mass Storage file that’s asked for in the script (/root/backingstore.img). I think it may not load in that case. You could comment out the line that says:
echo $FILE > functions/mass_storage.$N/lun.0/file
and try again from there. I had not problem getting things up and running in my first tests, but building this into a default configuration is turning out to be pickier than I thought. So call it it a work in progress, I guess.

Brendan Smithyman

unread,
Sep 3, 2015, 12:15:51 PM9/3/15
to szabob...@gmail.com, USB armory
My current configuration is below. But, to be fair, I haven’t managed to get it to startup nicely on my latest build. However, booting with g_ether enabled and then issuing systemctl start usb-composite does seem to transition over okay:

#!/bin/bash

N="usb0"

modprobe -r g_ether

modprobe usb_f_mass_storage
modprobe usb_f_acm
modprobe usb_f_hid
modprobe usb_f_rndis
modprobe usb_f_ecm
modprobe usb_f_serial

sleep 1s

cd /sys/kernel/config/usb_gadget/

mkdir -p usbarmory
cd usbarmory

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 "Inverse Path" > strings/0x409/manufacturer
echo "USB Armory" > strings/0x409/product

mkdir -p functions/acm.$N
mkdir -p functions/ecm.$N
mkdir -p functions/hid.$N
mkdir -p functions/mass_storage.$N

HOST="1a:55:89:a2:69:42" # "HostPC"
SELF="1a:55:89:a2:69:41" # "BadUSB"
echo $HOST > functions/ecm.$N/host_addr
echo $SELF > functions/ecm.$N/dev_addr

echo 1 > functions/mass_storage.$N/stall

echo 0 > functions/mass_storage.$N/lun.0/cdrom
echo 0 > functions/mass_storage.$N/lun.0/ro
echo 0 > functions/mass_storage.$N/lun.0/nofua
echo 1 > functions/mass_storage.$N/lun.0/removable

echo 1 > functions/hid.usb0/protocol
echo 1 > functions/hid.usb0/subclass
echo 8 > functions/hid.usb0/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.usb0/report_desc

C=1
mkdir -p configs/c.$C/strings/0x409
echo "Config $C: ECM network" > configs/c.$C/strings/0x409/configuration
echo 250 > configs/c.$C/MaxPower
ln -s functions/acm.$N configs/c.$C/
ln -s functions/ecm.$N configs/c.$C/
ln -s functions/mass_storage.$N configs/c.$C/
ln -s functions/hid.$N configs/c.$C/

ls /sys/class/udc > UDC

chmod 666 /dev/hidg0

systemctl restart isc-dhcp-server
systemctl restart dnsmasq


On Sep 3, 2015, at 11:22 AM, szabob...@gmail.com wrote:

szabob...@gmail.com

unread,
Sep 3, 2015, 12:20:11 PM9/3/15
to USB armory, szabob...@gmail.com
I created `/root/backingstore.img` as 1gb file ext4. And I can not see any RNDIS/CDC interface... there is any way to see where is the problem?

Brendan Smithyman

unread,
Sep 3, 2015, 9:04:03 PM9/3/15
to USB armory, szabob...@gmail.com
It's definitely picky in Mac OS (I've also managed to kernel panic Yosemite a dozen times in the last few days, when shutting down the USB Armory). That being said, it's probably something not coming up correctly on the USB end. Can you run the commands in order via a serial terminal? You may get more useful responses then (e.g., if there are permissions issues or modules blocking the setup). 

AJ

unread,
Aug 30, 2017, 4:46:17 AM8/30/17
to USB armory
Hi, I have managed to configure usb gadget to work with lan and mass storage and the configuration works completely without any problem in linux. on Mac only the usb storage is working [lan is not working, no connected device in network configuration]. In windows 10, neither of the 2 are working. 
my config:

/etc/modules
ledtrig_heartbeat
ci_hdrc_imx
#g_ether
g_multi

the config file for modules has the following line (forgotten the file location) has the g_multi along with Mac address and file location for the storage file.

please help

AJ

unread,
Aug 30, 2017, 6:03:53 AM8/30/17
to USB armory
Ok, so I got it working on my Mac. There was a driver conflict from the old USB armory network configuration. I installed the latest version of the driver and it started working. Haven't tested it on Win 10 yet.
Reply all
Reply to author
Forward
0 new messages