> For the complete documentation index, see [llms.txt](https://documentation.hak5.org/lan-turtle-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.hak5.org/lan-turtle-hub/payload-development/duckyscript-for-lan-turtle/usb.md).

# USB

The LAN Turtle Hub has three USB ports. &#x20;

The USB port closest to the USB-C cable can be configured to connect to the LAN Turtle Hub itself, or to the device the LAN Turtle Hub is plugged into via USB-C, as if it were a traditional USB hub.

When the USB port is connected to the LAN Turtle Hub, it can be used for USB storage.

## USB\_POWER\_OFF

Turn off the power on the controllable USB port.  This will power off any device which is plugged into the port (unless an externally powered hub is involved).

This command can be used when the port is claimed by the LAN Turtle Hub *or* when the USB port is passed to the host computer.

## USB\_POWER\_ON

Power on the controllable USB port. &#x20;

This command can be used when the port is claimed by the LAN Turtle Hub *or* when the USB port is passed to the host computer.

## USB\_CLAIM\_DEVICE

Claim the controllable USB port.  This connects the USB port to the LAN Turtle Hub.

## USB\_PASSTHROUGH\_DEVICE

Pass the controllable USB port to the host system.   This disconnects the USB port and any devices on it from the LAN Turtle Hub.

## USB\_EJECT

Safely disconnect any USB storage attached to the LAN Turtle Hub.

## USB\_STORAGE

Exit with a return code of `0` if USB storage is present, or non-zero if no USB storage is present.

This command is meant for use in automated payloads.

## USB\_WAIT

The `USB_WAIT` command pauses until USB storage is attached. Payloads which require USB storage can use this to wait until a USB drive is connected.

### Options <a href="#options" id="options"></a>

By default, `USB_WAIT` controls the LED to indicate that it is waiting for input; by setting the `NO_LED` environment variable first, `USB_WAIT` can be told to leave the LED alone:

```
NO_LED=1 USB_WAIT
```

By default, `USB_WAIT` also delays infinitely for a USB drive to be attached.  To continue a payload even when USB has not been connected, the `USB_TIMEOUT` environment variable can be used:

```
USB_TIMEOUT=10 USB_WAIT
```

### Examples <a href="#examples" id="examples"></a>

Payloads can delay indefinitely until USB storage is attached using the `USB_WAIT` command.

```bash
#!/bin/bash​

# Title: USB_WAIT demo
# Description: Wait until USB storage is attached.​

USB_WAIT​

LED G SINGLE
```

## USB\_FREE

`USB_FREE` returns the available free space on an attached USB drive, in bytes.

```bash
#!/bin/bash

SPACE=$(USB_FREE)

if [ $SPACE = 0 ]; then
    # no USB device, blink red
    LED R SINGLE
elif [ $SPACE -lt $((1024*1024)) ]; then 
    # Less than 1 MB free, blink magenta
    LED M DOUBLE
else
    # USB attached with more than a meg
    LED G SINGLE
fi

```
