Hijacking USB port from the host [Fedora 27] for VM [Debian9] by VMM [Virtual Box]

This is for discussing general topics about how to use VirtualBox.
Post Reply
_nobody_
Posts: 25
Joined: 8. Oct 2016, 20:34

Hijacking USB port from the host [Fedora 27] for VM [Debian9] by VMM [Virtual Box]

Post by _nobody_ »

Hello to everybody,

I have an interesting question, since I would like to hijack (does this hijacking Virtual Box people call pass-through?) one particular host USB port, and pass it for exclusive use to VM (Debian9)?

Here is what I have on host, considering USB devices (the device which is to me interesting for pass-through is AX88772):

Code: Select all

[vuser@localhost]$ vboxmanage list usbhost
Host USB Devices:

UUID:               083bb8da-e3ba-4777-897a-b416575cff6f
VendorId:           0x17ef (17EF)
ProductId:          0x600e (600E)
Revision:           1.0 (0100)
Port:               3
USB version/speed:  1/Low
Manufacturer:       Lenovo
Product:            Lenovo Optical Mouse
Address:            sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb2/2-4//device:/dev/vboxusb/002/004
Current State:      Busy

UUID:               439acdaf-e514-46b7-9877-c46a1050ea01
VendorId:           0x138a (138A)
ProductId:          0x003f (003F)
Revision:           1.4 (0104)
Port:               4
USB version/speed:  1/Full
Manufacturer:       Validity Sensors, Inc.
Product:            VFS495 Fingerprint Reader
SerialNumber:       003064de5080
Address:            sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb2/2-5//device:/dev/vboxusb/002/005
Current State:      Available

UUID:               fb039ef3-8dd4-46f6-be66-4b62384a2549
VendorId:           0x0b95 (0B95)
ProductId:          0x7720 (7720)
Revision:           0.1 (0001)
Port:               1
USB version/speed:  2/High
Manufacturer:       ASIX Electronics Corp.
Product:            AX88772
SerialNumber:       00EA12
Address:            sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2//device:/dev/vboxusb/002/002
Current State:      Busy

UUID:               75ddec50-a468-47ad-a27f-8cfc50319f97
VendorId:           0x05c8 (05C8)
ProductId:          0x0369 (0369)
Revision:           1.8 (0108)
Port:               6
USB version/speed:  2/High
Manufacturer:       SunplusIT INC.
Product:            HP HD Webcam
Address:            sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb2/2-7//device:/dev/vboxusb/002/006
Current State:      Busy
And here is what this [AX88772] device represents from host's dmesg (device enp0s20u2):

Code: Select all

[ 1054.707694] device vboxnet0 entered promiscuous mode
[ 1054.741450] vboxdrv: ffffffffc011c020 VBoxDDR0.r0
[ 1054.794558] vboxdrv: ffffffffc013d020 VBoxEhciR0.r0
[ 1165.542765] usb 2-2: USB disconnect, device number 2
[ 1165.543089] asix 2-2:1.0 enp0s20u2: unregister 'asix' usb-0000:00:14.0-2, ASIX AX88772 USB 2.0 Ethernet
[ 1167.690675] usb 2-2: new high-speed USB device number 7 using xhci_hcd
[ 1167.838952] usb 2-2: New USB device found, idVendor=0b95, idProduct=7720
[ 1167.838959] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1167.838963] usb 2-2: Product: AX88772
[ 1167.838968] usb 2-2: SerialNumber: 00EA12
[ 1168.082158] asix 2-2:1.0 eth0: register 'asix' at usb-0000:00:14.0-2, ASIX AX88772 USB 2.0 Ethernet, 00:10:60:31:d3:9b
[ 1168.128586] asix 2-2:1.0 enp0s20u2: renamed from eth0
[ 1168.140885] IPv6: ADDRCONF(NETDEV_UP): enp0s20u2: link is not ready
[ 1168.142215] IPv6: ADDRCONF(NETDEV_UP): enp0s20u2: link is not ready
[ 1230.095608] IPv6: ADDRCONF(NETDEV_CHANGE): enp0s20u2: link becomes ready
[ 1230.097697] asix 2-2:1.0 enp0s20u2: link up, 100Mbps, full-duplex, lpa 0xCDE1
In other words. the host's ifconfig is:

Code: Select all

[vuser@localhost]$ ifconfig
enp0s25: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 30:8d:99:be:7b:15  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xd0800000-d0820000

enp0s20u2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500 <<============================================
        ether 00:10:60:31:d3:9b  txqueuelen 1000  (Ethernet)
        RX packets 22  bytes 1881 (1.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 26  bytes 4140 (4.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 4794  bytes 753645 (735.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4794  bytes 753645 (735.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vboxnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.15.1  netmask 255.255.255.0  broadcast 192.168.15.255
        inet6 fe80::800:27ff:fe00:0  prefixlen 64  scopeid 0x20<link>
        ether 0a:00:27:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 73  bytes 10299 (10.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.178.28  netmask 255.255.255.0  broadcast 192.168.178.255
        inet6 fd00::3d97:2dbd:8092:6220  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::3b40:e5ee:53e7:4879  prefixlen 64  scopeid 0x20<link>
        inet6 2001:a61:3804:7a01:8ba9:f86e:b1dd:5ee0  prefixlen 64  scopeid 0x0<global>
        ether ac:fd:ce:78:94:2f  txqueuelen 1000  (Ethernet)
        RX packets 240310  bytes 346174713 (330.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 83055  bytes 8759438 (8.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
So, I would like to put AX88772 to be part of the Virtual Machine (ideally private network ETH1 or ETH2):

Code: Select all

root@stretch:# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fe8d:c04d  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:8d:c0:4d  txqueuelen 1000  (Ethernet)
        RX packets 1638  bytes 173122 (169.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1118  bytes 152781 (149.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.15.2  netmask 255.255.255.0  broadcast 192.168.15.255
        inet6 fe80::a00:27ff:fe52:5de3  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:52:5d:e3  txqueuelen 1000  (Ethernet)
        RX packets 4  bytes 1830 (1.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 25  bytes 3548 (3.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 1790  bytes 525770 (513.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1790  bytes 525770 (513.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
And to make private networks ETH1 or ETH2 to have default route (it looks now like this):

Code: Select all

root@stretch:# ip route
default dev eth0 scope link
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
192.168.15.0/24 dev eth1 proto kernel scope link src 192.168.15.2
root@stretch:#
I am 100% sure Virtual Machine Monitor/VMM - Virtual Box has set of the VBoxManage CLI commands which can do this in few (maybe 2 to 4 steps), but I am not a Virtual Box CLI wiz.

Please, help! :mrgreen:

Thank you,
_nobody_
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Hijacking USB port from the host [Fedora 27] for VM [Debian9] by VMM [Virtual Box]

Post by socratis »

I won't worry about your network configuration at this point, but you need to create a USB filter. See USB basics and troubleshooting, all of the posts. If you still have a problem after reading through the whole thing, please follow the advice of the last post, #8: Asking for help, mainly the "showvminfo" part.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
_nobody_
Posts: 25
Joined: 8. Oct 2016, 20:34

Re: Hijacking USB port from the host [Fedora 27] for VM [Debian9] by VMM [Virtual Box]

Post by _nobody_ »

With all due respect, I am a hack guy. I like to check the gfacts just by poking around. And let me see what I did and found, using your #8: Asking for help.

Here is what I did using your set of the commands (not only, I have added the following command: vboxmanage controlvm <VM_UUID> usb attach/detach <USB_UUID>):
[vuser@localhost cip-b_at_d-generic]$ VBoxManage list usbfilters
Global USB Device Filters:

<none>

[vuser@localhost cip-b_at_d-generic]$ vboxmanage controlvm 5ab6fc93-4ee4-43df-977a-5bcd8b705e0d usbattach 98a7a044-0471-4d45-9138-46b3f6f5c45d
VBoxManage: error: USB device 'ASIX Electronics Corp. AX88772 ' with UUID {98a7a044-0471-4d45-9138-46b3f6f5c45d} is already captured by the virtual machine 'cip-b_at_d-generic_default_1517315220261_38849'

VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component HostUSBDeviceWrap, interface IHostUSBDevice, callee nsISupports
VBoxManage: error: Context: "AttachUSBDevice(usbId.raw(), captureFilename.raw())" at line 1387 of file VBoxManageControlVM.cpp
[vuser@localhost cip-b_at_d-generic]$ vboxmanage controlvm 5ab6fc93-4ee4-43df-977a-5bcd8b705e0d usbdetach 98a7a044-0471-4d45-9138-46b3f6f5c45d
[vuser@localhost cip-b_at_d-generic]$ VBoxManage list usbfilters
Global USB Device Filters:

<none>

[vuser@localhost cip-b_at_d-generic]$ vboxmanage controlvm 5ab6fc93-4ee4-43df-977a-5bcd8b705e0d usbattach 98a7a044-0471-4d45-9138-46b3f6f5c45d
[vuser@localhost cip-b_at_d-generic]$ VBoxManage list usbfilters
Global USB Device Filters:

<none> (STRANGE, isn't it???)


[vuser@localhost cip-b_at_d-generic]$ vboxmanage controlvm 5ab6fc93-4ee4-43df-977a-5bcd8b705e0d usbattach 98a7a044-0471-4d45-9138-46b3f6f5c45d
VBoxManage: error: USB device 'ASIX Electronics Corp. AX88772 ' with UUID {98a7a044-0471-4d45-9138-46b3f6f5c45d} is already captured by the virtual machine 'cip-b_at_d-generic_default_1517315220261_38849'
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component HostUSBDeviceWrap, interface IHostUSBDevice, callee nsISupports
VBoxManage: error: Context: "AttachUSBDevice(usbId.raw(), captureFilename.raw())" at line 1387 of file VBoxManageControlVM.cpp
[vuser@localhost cip-b_at_d-generic]$
At least, the good thing is that Virtual Box does NOT allow on CLI level USB filter to be duplicated, which is NOT the case on VirtualBox GUI.

So here we already have two serious bugs with Virtual Box: :idea:
[1] VBoxManage list usbfilters command does not work!?
[2] GUI adds usbfilters multiple times, although beneath there is NO addition of the same filter.

And, almost forgot:

Code: Select all

[vuser@localhost cip-b_at_d-generic]$ vboxmanage --version
5.2.6r120293
[vuser@localhost cip-b_at_d-generic]$ vboxmanage list extpacks
Extension Packs: 1
Pack no. 0:   Oracle VM VirtualBox Extension Pack
Version:      5.2.6
Revision:     120293
Edition:      
Description:  USB 2.0 and USB 3.0 Host Controller, Host Webcam, VirtualBox RDP, PXE ROM, Disk Encryption, NVMe.
VRDE Module:  VBoxVRDP
Usable:       true 
Why unusable: 
[vuser@localhost cip-b_at_d-generic]$ 
Any further actions with Virtual Box developers to fix these bugs? :roll: :mrgreen:

Thank you,
_nobody_
_nobody_
Posts: 25
Joined: 8. Oct 2016, 20:34

Re: Hijacking USB port from the host [Fedora 27] for VM [Debian9] by VMM [Virtual Box]

Post by _nobody_ »

Now, I have request for some reason to hijack two usb devices:
[1] USB/ETH (well known use case, described above);
[2] Serial/USB: serial over usb, which I need to deliver to the VM application over TCP/IP port (yet new use case)!

And here is what I have after the pass-through magic:

Code: Select all

[vuser@localhost ~]$ vboxmanage list vms
"cip-b_at_d-generic_default_1517315220261_38849" {5ab6fc93-4ee4-43df-977a-5bcd8b705e0d}

[vuser@localhost ~]$ vboxmanage list usbhost
Host USB Devices:

[SNAP]

UUID:               4f747808-882d-4a92-a6af-7d076d05981f
VendorId:           0x0b95 (0B95)
ProductId:          0x7720 (7720)
Revision:           0.1 (0001)
Port:               0
USB version/speed:  2/High
Manufacturer:       ASIX Electronics Corp.
Product:            AX88772 
SerialNumber:       00EAC9
Address:            sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.1//device:/dev/vboxusb/001/004
Current State:      Captured

UUID:               fe3a8388-5db2-404e-ab08-badaa76e1aaf
VendorId:           0x067b (067B)
ProductId:          0x2303 (2303)
Revision:           3.0 (0300)
Port:               2
USB version/speed:  1/Full
Manufacturer:       Prolific Technology Inc.
Product:            USB-Serial Controller
Address:            sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.3//device:/dev/vboxusb/001/007
Current State:      Captured

[SNAP]

[vuser@localhost ~]$ vboxmanage controlvm 5ab6fc93-4ee4-43df-977a-5bcd8b705e0d usbattach fe3a8388-5db2-404e-ab08-badaa76e1aaf
VBoxManage: error: USB device 'Prolific Technology Inc. USB-Serial Controller' with UUID {fe3a8388-5db2-404e-ab08-badaa76e1aaf} is already captured by the virtual machine 'cip-b_at_d-generic_default_1517315220261_38849'
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component HostUSBDeviceWrap, interface IHostUSBDevice, callee nsISupports
VBoxManage: error: Context: "AttachUSBDevice(usbId.raw(), captureFilename.raw())" at line 1387 of file VBoxManageControlVM.cpp

[vuser@localhost ~]$ vboxmanage controlvm 5ab6fc93-4ee4-43df-977a-5bcd8b705e0d usbattach 4f747808-882d-4a92-a6af-7d076d05981f
VBoxManage: error: USB device 'ASIX Electronics Corp. AX88772 ' with UUID {4f747808-882d-4a92-a6af-7d076d05981f} is already captured by the virtual machine 'cip-b_at_d-generic_default_1517315220261_38849'
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component HostUSBDeviceWrap, interface IHostUSBDevice, callee nsISupports
VBoxManage: error: Context: "AttachUSBDevice(usbId.raw(), captureFilename.raw())" at line 1387 of file VBoxManageControlVM.cpp

[vuser@localhost ~]$ vboxmanage list usbfilters
Global USB Device Filters:

<none>

[vuser@localhost ~]$
So, as we see from the logs, pass-through USB devices are already captured by Virtual Box VMM.

vboxmanage list usbfilters command does NOT show/detect any of these, although GUI USB filter clearly shows both of them hijacked!

I found that on the previous versions of Virtual Box VMMs this command worked. What The Heck?! :shock:

Any take/explanation on this chaos??? :mrgreen:

_nobody_
Post Reply