Plug in a USB stick and you assume the computer sees a disk. But USB lets one physical device claim to be almost anything, and the most dangerous thing it can claim to be is a keyboard. The Hak5 USB Rubber Ducky is the best-known example: a device that looks like a flash drive but registers as a keyboard and "types" a prepared script at machine speed the instant it is plugged in. It belongs to the broader class of attacks known as BadUSB.
This post explains why the trick works, what the real tools in this family are, and, most usefully, how to defend against them. It is written for defenders and stays at the level of how the attack class behaves; it deliberately does not include working payloads. An earlier draft of this article embedded a functioning reverse-shell command, a persistence registry edit and an exfiltration URL, which have been removed.
1. The HID Attack: Why computers trust keyboards implicitly
A keyboard is a Human Interface Device (HID), and operating systems trust HIDs completely and silently. There is no prompt when you attach a keyboard, no permission dialog, no scan, because a computer with no working keyboard is hard to use, so the design assumes any device that says "I am a keyboard" is one. Whatever that device "types" is treated as if the logged-in user typed it, with exactly their privileges.
That is the whole vulnerability. The attack does not break any software; it abuses a trust decision baked into the USB and HID standards. A malicious device simply exercises the access the user already has, which is why it can work against an otherwise well-patched machine.
2. Ducky Script: Automated keystroke injection
The Rubber Ducky is programmed in a small scripting language, DuckyScript, designed to describe keystrokes: wait for a moment, type some literal text, press a special key such as Enter or the Windows key. That is deliberately all it is, a way to write down "what a very fast typist would do," which is enough because a keyboard can launch and drive anything the user can.
The significance is the automation and speed, not any single command. A person typing is slow and visible; a device replaying a script does in a fraction of a second what would take a human many seconds of obvious activity. This post describes the language's purpose rather than providing a payload, because the danger is in a complete working script, not in the idea that such a language exists.
3. Payloads: What this class of attack aims to do
At a conceptual level, keystroke-injection payloads pursue the same goals as other post-access attacks: open a shell or terminal, run commands as the current user, establish some way back in, and move or copy data. Because everything runs as the logged-in user, nothing needs to defeat authentication; the device is acting as that user.
This post does not provide the commands that accomplish those goals. The defensive point is the one that matters: a device that can type as you can do anything you can do, so the controls that help are the ones that limit what gets to type in the first place (sections 7 and 8), not after-the-fact detection of a specific command.
4. Cheap Alternatives: Digispark and Raspberry Pi Pico
The threat is not tied to one product. Any programmable microcontroller with USB can be made to present as a keyboard, and very cheap boards, the Digispark (an ATtiny85 board) and the Raspberry Pi Pico among them, can be flashed to do exactly what a Rubber Ducky does for a few dollars. The Pico in particular, with widely available HID firmware, has made the capability nearly free.
For a defender this is the important fact: you cannot recognize the threat by its shape. It is not about banning a branded gadget, because the same behavior fits inside a board smaller than a coin, or inside the devices in the next two sections.
5. O.MG Cable: Hiding the attack inside a cable
The O.MG Cable takes the idea to its unsettling conclusion: it is a working charging or data cable with a tiny microcontroller and often a Wi-Fi radio hidden in the connector. It looks and functions like an ordinary cable, charges a phone, transfers data, while being able to inject keystrokes, and in some versions it can be controlled remotely over Wi-Fi.
This collapses the old advice to "only plug in cables you trust," because a malicious cable is visually identical to a safe one. It is the strongest argument that the real defenses have to be systemic (what devices the OS will accept) and physical (control of the ports), not visual inspection.
6. The Bash Bunny: From keyboard emulation to a multi-tool
Hak5's Bash Bunny is a more capable device in the same family. It can present as a keyboard, but also as other USB device types, such as a network adapter or storage, and switch between them. Presenting as a network adapter is especially potent: a machine will often route traffic to a freshly attached USB "network card," which opens the door to traffic interception, not just typing.
The lesson is that "it's just pretending to be a keyboard" understates the class. USB lets a device claim to be many kinds of peripheral, and each kind the OS trusts automatically is a separate avenue. Keystroke injection is the most famous case, not the only one.
7. Software Defense: Controlling which USB devices the OS accepts
The direct defense is device control: decide which USB devices a machine will talk to instead of trusting all of them. On Linux, USBGuard lets an administrator write an allowlist of permitted devices by their descriptors and block the rest by default. Windows offers device-installation and removable-storage policies through Group Policy and Intune, and managed endpoints can restrict or alert on newly attached HIDs.
No single control is perfect, since a malicious device can copy the identifiers of a legitimate one, so the useful posture is layered: device allowlisting where feasible, endpoint detection tuned to flag a "keyboard" that appears and types a burst of commands within milliseconds of being attached, and, in high-security environments, physically disabling or filling unused ports. The aim is to remove the default of automatic trust.
8. Physical Security: An unlocked workstation is an owned workstation
Every attack in this family needs two things: physical access to a port and an active session to act in. Keystroke injection does its work as the logged-in user, so a locked screen stops most of it cold, there is no session for the injected keystrokes to command. The classic failure is the machine left unlocked and unattended, where seconds of access are enough.
So the oldest advice is also the most effective: lock the screen whenever you step away, set a short automatic lock timeout, and treat control of the physical ports as part of security rather than a separate concern. Device control (section 7) raises the bar, but an attacker who can type as an unattended, logged-in user has already won most of the fight.
Conclusion
The Rubber Ducky and its relatives are a lesson about trust, not about any one gadget. USB was built to make peripherals effortless, and that effortlessness is the vulnerability: a device that declares itself a keyboard is believed, and a keyboard can do anything its user can. The attack breaks no code; it uses the access the session already grants.
Because the threat can hide in a coin-sized board or an ordinary-looking cable, the defenses that work are structural: lock sessions, shorten timeouts, control which USB devices the operating system will accept, and watch for a "keyboard" that behaves like a script. Treat the USB port as a gate that should demand to know what is on the other side, not an open door.