Payload configuration

Often for more complex payloads you will want to give the user (or even just yourself) a simple way to change the payload behavior.

The easiest way to accomplish this is with standard variables.


Variables are assigned in payloads by setting a name to the value; for instance:


Variables can be set to strings or numbers, or even the output of other commands:

# Set the variable SPACE to the output of the USB_FREE command

More examples of advanced variable use are in the chapter "Quotes and Expansions": Variables are extremely powerful!

Simple tests

To actually use the results of a configuration option, there are multiple ways to test how it is set.

The simplest test is to compare if a variable is equal to a fixed value:


if [ ${SETTING_ONE} = "Y" ]; then

This can, of course, also be combined with the else construct:


if [ ${SETTING_ONE} = "Y" ]; then

Complex tests

More complex tests can be created with the case statement:


case "${SETTING_ONE}" in
        echo "Option A"
        echo "Option B"
        echo "Option C"
        echo "Unknown option"

The case test allows us to match multiple options with a default final option if nothing else matches.

Check the chapter "Flow Control" for more detailed information about the if and case tests!

Payload configuration

When making a payload that accepts configuration options, we recommend placing all the options at the top of the payload so that they are easy to find. This way, users of your payload (or your own future self who has forgotten all the complexities of the payload) can easily change the setup.

It's also a good idea to include a description of the configuration variable, and how to use it, as a comment.

Whenever possible, provide a default value that makes sense.


# Title: Demo options
# Description: Generic demo payload 

# Configuration options

# REPEAT_COUNT - How many times do we attempt the payload?

# NETWORK_INTERFACE - What network interface do we use?

Since a payload does not typically run interactively (the user will never see the output of echo or similar), the LED command is the primary way to communicate errors. For example continuing the payload from above,

if [ "$REPEAT_COUNT" -le 3 ]; then
    exit 1

Here we confirm the user has entered a sane configuration option, set the LED to error state, and exit the payload entirely.

Configuration names

There is no strict requirement when it comes to the naming of configuration variables, however it is a good idea to:

  • Keep them entirely upper case. This makes it easy to spot them in the code.

  • Give them meaningful names. This helps you remember them during the rest of the payload. Naming configuration variables A, B, and so on is certainly possible, but don't.

Last updated