# suryaganthan-r/badusb architecture

> Architecture diagram of the GitHub repository suryaganthan-r/badusb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suryaganthan-r/badusb
- Repository: https://github.com/suryaganthan-r/badusb

## Overview

The repository implements a Raspberry Pi Zero 2 W BadUSB: setup configures a USB keyboard gadget, while Python code translates and injects keyboard reports. The main workflow lets an operator select a Ducky script (or starts the documented default in non-interactive mode), parses its commands, and sends keystrokes to a connected host. The README also describes Wi-Fi exfiltration and persistent execution; payload details beyond filenames were not inspected, so those capabilities are shown at the collection level.

Main entry points: [`ducky_runner.py`](https://github.com/suryaganthan-r/badusb/blob/main/ducky_runner.py) (Ducky Runner), [`attack.py`](https://github.com/suryaganthan-r/badusb/blob/main/attack.py) (Direct HID Payload), [`setup_gadget.sh`](https://github.com/suryaganthan-r/badusb/blob/main/setup_gadget.sh) (Gadget Setup), [`ducky_scripts`](https://github.com/suryaganthan-r/badusb/tree/main/ducky_scripts) (Ducky Scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hardware["USB Gadget Setup"]
  node_setup["Gadget Setup<br/>[setup_gadget.sh]"]
end

subgraph group_runtime["Payload Runtime"]
  node_runner["Ducky Runner<br/>[ducky_runner.py]"]
  node_keymap["HID Keymap<br/>[keymap.py]"]
end

subgraph group_input["Payload Library"]
  node_scripts["Ducky Scripts"]
end

subgraph group_demo["Standalone Demo"]
  node_attack["Direct HID Payload<br/>[attack.py]"]
end

node_operator(("Operator"))
node_hid{{"USB HID Keyboard"}}
node_target(("Target Host"))
node_configfs["Linux ConfigFS"]

node_operator -->|"selects payload"| node_runner
node_runner -->|"lists and reads"| node_scripts
node_runner -->|"looks up keys"| node_keymap
node_runner -->|"writes reports"| node_hid
node_hid -->|"injects keystrokes"| node_target
node_setup -->|"configures gadget"| node_configfs
node_runner -->|"starts on non-interactive run"| node_setup
node_attack -->|"looks up keys"| node_keymap
node_attack -->|"writes reports"| node_hid
node_attack -->|"injects keystrokes"| node_target
node_scripts -.->|"includes exfil payload"| node_target

click node_runner "https://github.com/suryaganthan-r/badusb/blob/main/ducky_runner.py"
click node_keymap "https://github.com/suryaganthan-r/badusb/blob/main/keymap.py"
click node_setup "https://github.com/suryaganthan-r/badusb/blob/main/setup_gadget.sh"
click node_scripts "https://github.com/suryaganthan-r/badusb/tree/main/ducky_scripts"
click node_attack "https://github.com/suryaganthan-r/badusb/blob/main/attack.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_setup toneBlue
class node_runner,node_keymap toneAmber
class node_scripts toneMint
class node_attack toneRose
class node_operator,node_hid,node_target,node_configfs toneIndigo
```

## Components

### USB Gadget Setup

- [Gadget Setup](https://github.com/suryaganthan-r/badusb/blob/main/setup_gadget.sh): `setup_gadget.sh`

### Payload Runtime

- [Ducky Runner](https://github.com/suryaganthan-r/badusb/blob/main/ducky_runner.py): `ducky_runner.py`
- [HID Keymap](https://github.com/suryaganthan-r/badusb/blob/main/keymap.py): `keymap.py`

### Payload Library

- [Ducky Scripts](https://github.com/suryaganthan-r/badusb/tree/main/ducky_scripts): `ducky_scripts`

### Standalone Demo

- [Direct HID Payload](https://github.com/suryaganthan-r/badusb/blob/main/attack.py): `attack.py`

### Other components

- **Operator**
- **USB HID Keyboard**
- **Target Host**
- **Linux ConfigFS**

## Connections

- Operator → Ducky Runner: selects payload (evidence: `ducky_runner.py`)
- Ducky Runner → Ducky Scripts: lists and reads (evidence: `ducky_runner.py`)
- Ducky Runner → HID Keymap: looks up keys (evidence: `ducky_runner.py`)
- Ducky Runner → USB HID Keyboard: writes reports (evidence: `ducky_runner.py`)
- USB HID Keyboard → Target Host: injects keystrokes (evidence: `README.md`)
- Gadget Setup → Linux ConfigFS: configures gadget (evidence: `README.md`)
- Ducky Runner → Gadget Setup: starts on non-interactive run (evidence: `ducky_runner.py`)
- Direct HID Payload → HID Keymap: looks up keys (evidence: `attack.py`)
- Direct HID Payload → USB HID Keyboard: writes reports (evidence: `attack.py`)
- Direct HID Payload → Target Host: injects keystrokes (evidence: `README.md`)
- Ducky Scripts → Target Host: includes exfil payload (evidence: `README.md`)
