Back to Momentum Firmware

BadUSB File Format {#badusb_file_format}

documentation/file_formats/BadUsbScriptFormat.md

latest9.2 KB
Original Source

BadUSB File Format {#badusb_file_format}

Command syntax

BadUsb app uses extended Duckyscript syntax. It is compatible with classic USB Rubber Ducky 1.0 scripts but provides some additional commands and features, such as custom USB ID, ALT+Numpad input method, SYSRQ command, and more functional keys.

Script file format

BadUsb app can execute only text scripts from .txt files, no compilation is required. Both \n and \r\n line endings are supported. Empty lines are allowed. You can use spaces or tabs for line indentation.

Command set

Comment line

Just a single comment line. The interpreter will ignore all text after the REM command.

CommandParametersNotes
REMComment text

Delay

Pause script execution by a defined time.

CommandParametersNotes
DELAYDelay value in msSingle delay
DEFAULT_DELAYDelay value in msAdd delay before every next command
DEFAULTDELAYDelay value in msSame as DEFAULT_DELAY

Special keys

CommandNotes
DOWNARROW / DOWN
LEFTARROW / LEFT
RIGHTARROW / RIGHT
UPARROW / UP
ENTER
DELETE
BACKSPACE
END
HOME
ESCAPE / ESC
INSERT
PAGEUP
PAGEDOWN
CAPSLOCK
NUMLOCK
SCROLLLOCK
PRINTSCREEN
BREAKPause/Break key
PAUSEPause/Break key
SPACE
TAB
MENUContext menu key
APPSame as MENU
FxF1-F12 keys

Modifier keys

The following modifier keys are recognized:

CommandNotes
CTRL
CONTROLSame as CTRL
SHIFT
ALT
GUI
WINDOWSSame as GUI

You can chain multiple modifier keys together using hyphens (-) or spaces.

Key hold and release

Up to 5 keys can be hold simultaneously.

CommandParametersNotes
HOLDSpecial key or single characterPress and hold key until RELEASE command
RELEASESpecial key or single characterRelease key

String

CommandParametersNotes
STRINGText stringPrint text string
STRINGLNText stringPrint text string and press enter after it

String delay

Delay between keypresses.

CommandParametersNotes
STRING_DELAYDelay value in msApplied once to next appearing STRING command
STRINGDELAYDelay value in msSame as STRING_DELAY
DEFAULT_STRING_DELAYDelay value in msApply to every appearing STRING command
DEFAULTSTRINGDELAYDelay value in msSame as DEFAULT_STRING_DELAY

Repeat

CommandParametersNotes
REPEATNumber of additional repeatsRepeat previous command

ALT+Numpad input

On Windows and some Linux systems, you can print characters by holding ALT key and entering its code on Numpad.

CommandParametersNotes
ALTCHARCharacter codePrint single character
ALTSTRINGText stringPrint text string using ALT+Numpad method
ALTCODEText stringSame as ALTSTRING, presents in some Duckyscript implementations

SysRq

Send SysRq command

CommandParametersNotes
SYSRQSingle character

Media keys

Some Media/Consumer Control keys can be pressed with "MEDIA" command

CommandParametersNotes
MEDIAMedia key, see list below
Key nameNotes
POWER
REBOOT
SLEEP
LOGOFF
EXIT
HOME
BACK
FORWARD
REFRESH
SNAPSHOTTake photo in a camera app
PLAY
PAUSE
PLAY_PAUSE
NEXT_TRACK
PREV_TRACK
STOP
EJECT
MUTE
VOLUME_UP
VOLUME_DOWN
FNFn/Globe key on Mac keyboard
BRIGHT_UPIncrease display brightness
BRIGHT_DOWNDecrease display brightness

Fn/Globe key commands (Mac/iPad)

CommandParametersNotes
GLOBESpecial key or single character

Wait for button press

Will wait indefinitely for a button to be pressed

CommandParametersNotes
WAIT_FOR_BUTTON_PRESSNoneWill wait for the user to press a button to continue script execution

Device ID

You can set the custom ID of the Flipper HID device. This command must be in the first line of script, it is executed before script run.

CommandParametersExampleNotes
IDVID:PID Manufacturer:ProductID 1234:abcd Flipper Devices:Flipper ZeroFor USB connection mode
BLE_IDMAC:Addr Device NameBLE_ID AA:BB:CC:DD:EE:FF Smart FridgeFor Bluetooth connection mode
BT_IDMAC:Addr Device NameBT_ID AA:BB:CC:DD:EE:FF Smart FridgeSame as BLE_ID

For ID, VID and PID are hex codes and are mandatory, while Manufacturer and Product are text strings and are optional.

For BLE_ID and BT_ID, MAC address is a 6 byte hex sequence, and both MAC address and device name are mandatory.

When opening a script with one of these commands on the first line, the connection mode will be automatically switched to the one specified by the command. You can then manually switch back to the other connection mode.

Mouse Commands

Mouse movement and click commands. Mouse click commands support HOLD functionality.

CommandParametersNotes
LEFTCLICKNone
LEFT_CLICKNonefunctionally same as LEFTCLICK
RIGHTCLICKNone
RIGHT_CLICKNonefunctionally same as RIGHTCLICK
MOUSEMOVEx y: int move mount/direction
MOUSE_MOVEx y: int move mount/directionfunctionally same as MOUSEMOVE
MOUSESCROLLdelta: int scroll distance
MOUSE_SCROLLdelta: int scroll distancefunctionally same as MOUSESCROLL