Configuring a USB dongle for OpenVZ

March 3 2016

# # # #

In order to setup a USB forwarding to a OpenVZ container, you would need to ensure that you have the following packages installed


Some device drives connect by default in USB Mass Storage mode. This allows them to load a basic setup like rom from where you can install the telecom provider's software. The software then does a mode switch on the hardware by sending it a command on the usb bus.

This changes the usb from Mass Storeage mode to a USB modem.

  • usb_modeswitch software allows you to do the same from linux.
  • usb_modeswitch-data contains a list of vendor and products for which this settings are hard coded.

Run a lsusb command.

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Among this, the important fields are marked by the ID. Those are the vendor ID and product ID respectively. In the above case, the vendor ID is 0x1d6b and product ID is 0x0002

Now run a modeswitch command to the USB device.

usb_modeswitch -c /etc/usb_modeswitch.d/1d6b\:0002 -v 0x1d6b -p 0x0002

Note: This are values corresponding to a USB hub. Actual values will be different

This loads the configuration from pre-defined modeswitch files and issues a command to execute it in the way as defined by the modeswitch. When a device is switched, its product ID may change to a different value. The vendor ID will remain unchanged. This can be seen in the output of lsusb.

This should load a /dev/ttyUSB0.

To forward a devnode in OpenVZ, you have to run the following command.

vzctl set CTID --devnodes ttyUSB0:rw

USB is still a bit of voodoo magic with pre-defined special commands made to give some pre-defined output.

In order to forward the bus, so that the device comes properly in container when you run lsusb, you have to forward in addition, the usb bus devnode as well.

In the above lsusb sample, the Bus and Device are specified and are 003 and 001 which means that the bus is /dev/bus/003/001

We now forward to the container. For doing that we need to know the major ID and the minor ID of the device.

$ ls -l /dev/bus/usb/003/001
crw-rw-r-- 1 root root 189, 256 Feb 26 15:13 /dev/bus/usb/003/001

The major and minor id are printed here, and in this case they are 189 and 256.

Note: This are values corresponding to a USB hub. Actual values will be different

vzctl set CTID --devices c:189:256:rw --save

This grants the ability to run mknod for this device. For lsusb to work properly, you have to make an identical /dev/bus/usb structure in the guest as in the host.

mkdir -p /dev/bus/usb/003
mknod /dev/bus/usb/003/001 c 189 256

Now your lsusb should reflect the real data for the forwarded USB device as well.

Recommended Reading

ANSI Sequences in Output Without a TTY

# # # #

ANSI Sequences or ansi escape codes are special formatting characters used to inform a receiving terminal about special colors and formatting to use when displaying text. These sequences still remain in use to this day, with a lot of utilities supporting...


Recommended Reading

Breaking Random Number Generators with Chosen Seed

# # # #

Find the flag.

Source is as follows

#!/usr/bin/env python3

import random
import time
import string
import signal

# use secure seed

with open('flag.txt') as f:
	flag =

# large constant prime
p = 174807157365465092731323561678522236549173502913317875393564963123330281052524687450754910240009920154525635325209526987433833785499384204819179549544106498491589834195860008906875039418684191252537604123129659746721614402346449135195832955793815709136053198207712511838753919608894095907732099313139446299843