Skip to main content
Version: FILS English

RustyDucky

USB HID Attack Device with Discord Exfiltration

info

Project Description

RustyDucky is a USB-based penetration testing tool built with Rust on the Raspberry Pi Pico W. The device emulates a USB keyboard, that is recognized by the computer as a HID Keyboard to automatically execute commands on target systems and exfiltrates captured data via Discord webhook.

Motivation

This project combines interests in cybersecurity (my passion), embedded systems, and Rust programming. It applies course knowledge including GPIO control, asynchronous programming, USB protocols, and real-time command execution in a practical security research context.

Details of the implementation - Block Diagram & Components

Architecture

Block Diagram

┌─────────────────────────────────┐
│ Raspberry Pi Pico W (RP2040) │
│ ┌───────────────────────────┐ │
│ │ USB HID Keyboard Emulator │◄─┼── Target Computer
│ └───────────────────────────┘ │
│ ┌───────────────────────────┐ │
│ │ Payload Execution Engine │ │
│ └───────────────────────────┘ │
│ ┌───────────────────────────┐ │
│ │ Status Indicators │ │
│ │ (3× LEDs + Buzzer) │ │
│ └───────────────────────────┘ │
└─────────────────────────────────┘

┌─────────────────────────────────┐
│ Discord Webhook │
│ (Data Exfiltration) │
└─────────────────────────────────┘

Components

  • USB HID Module: Implements USB keyboard protocol using usbd-hid crate
  • Payload Engine: Executes automated attack sequence with timing control
  • GPIO Interface: Controls status LEDs and buzzer for visual/audio feedback
  • Data Exfiltration: HTTP POST via curl to Discord webhook

Log

WeekDate RangeWork Done
Week 117-23 NovProject research and documentation setup
Week 224-30 NovHardware selection, ordered Raspberry Pi Pico 2 W
Week 31-7 DecResearch on USB Rubber Ducky concepts and attack vectors
Week 48-14 DecHardware arrived, studied component specifications and project architecture
Week 515-21 DecDevelopment environment setup, initial code structure
Week 622-28 DecComponent assembly, GitHub repository setup, serial communication testing
Week 7Jan 29-4Project research on Raspberry Pico 2w
Week 8Jan 5-11Libraries and code switched to Raspberry Pi Pico W
Week 9Jan 12-18Successful USB HID keyboard implementation and testing and discord webhook exfiltration, 3LEDs and buzzer indicators, final hardware integration

Hardware

Here is the final assembled device: Hardware Device

Electrical Schematics

Electrical Schematic The Raspberry Pi Pico W integrates primary components. Breadboard adds status indicators.

Pinout Description:

Raspberry Pi Pico W
├── RP2040 (Dual Cortex-M0+, 133MHz)
├── USB Port (Micro USB)
├── CYW43439 WiFi Module (not used)
└── 2MB Flash Storage

Breadboard (Status Indicators)
├── LED 1 (GP2) - Win+R stage
├── LED 2 (GP3) - Command collection
├── LED 3 (GP5) - Discord upload
└── Buzzer (GP4) - Upload alert

Bill of Materials

ComponentUsageNotes
Raspberry Pi Pico WMain microcontrollerRP2040 dual core
Micro USB CableProgramming & deploymentStandard USB-A to Micro-B
BreadboardCircuit prototypingFor LEDs and buzzer
3× LEDsStatus indicatorsAny color, standard 20mA
3× 220Ω ResistorsLED current limitingFor 3.3V GPIO
Active Buzzer (3.3V)Payload alertConnected to GP4
Jumper WiresConnectionsStandard breadboard jumpers

Details of the implementation - Technologies & Payload Execution Flow

Software

Technologies

  • Rust (embassy-rp framework)
  • usbd-hid (USB keyboard emulation)
  • embassy-usb (USB device stack)
  • Static cell (memory management)

Software Architecture

src/main.rs - Main
├── USB HID keyboard initialization
├── Payload execution engine
├── GPIO control (LEDs + Buzzer)
└── Timing and synchronization

Payload Execution Flow

Stage 1 (LED 1 - GP2 ON):

  • Wait 3 seconds for user preparation
  • Press Win+R
  • LED 1 turns on

Stage 2 (LED 2 - GP3 ON):

  • Type "cmd" and press Enter
  • Wait for CMD to open (2 seconds)
  • Type collection command: whoami > %temp%\info.txt && hostname >> %temp%\info.txt && ipconfig >> %temp%\info.txt
  • LED 2 turns on

Stage 3 (LED 3 + Buzzer ON):

  • Press Enter (file collection runs, 3 seconds)
  • Type Discord webhook curl command
  • LED 3 + Buzzer activate on command completion
  • Press Enter (file uploads to Discord)

Total Execution Time: ~8-10 seconds

Results

Here is the final Result: Hardware Device

Completed:

  • USB HID keyboard enumeration on Windows
  • Automated command execution via keystrokes
  • System information collection (whoami, hostname, ipconfig)
  • File-based data exfiltration to Discord
  • Status LED indicators (3 stages)
  • Buzzer audio alert to mark it done
  • Hardware assembly and testing
  • GitHub repository with full source

Tested & Working:

  • Device recognized as USB keyboard
  • Commands execute reliably on target
  • Data appears in Discord channel within seconds
  • LEDs light up at correct stages
  • Cross-platform (tested on Windows)

Technical Achievements

  1. Character Mapping: Full US keyboard layout support (a-z, A-Z, 0-9, special chars, @, /, :, -, _, |, ., &, $, (, ), =, ', `, ,, >)
  2. Timing Synchronization: Precise delays between stages to ensure OS readiness
  3. Minimal Code Footprint: 300 lines of Rust (comments removed per requirements)
  4. Real Hardware Integration: 3 status LEDs + buzzer for user feedback
  5. Zero Manual Intervention: Completely automated from plug-in to Discord notification

Conclusions

RustyDucky demonstrates practical application of embedded Rust for security research. The project successfully implements a USB HID attack device with automated command execution and data exfiltration to Discord. All components tested and validated on hardware.

  1. BadUSB Attack Explanation
  2. USB Rubber Ducky Payloads
  3. Raspberry Pi Pico Documentation
  4. embassy-rs Book
  5. usbd-hid Crate
  6. Discord Webhooks API