RepoPilotOpen in app →

brandonlw/Psychson

Phison 2251-03 (2303) Custom Firmware & Existing Firmware Patches (BadUSB)

Mixed

Stale — last commit 5y ago

worst of 4 axes
Use as dependencyMixed

last commit was 5y ago; no CI workflows detected

Fork & modifyHealthy

Has a license, tests, and CI — clean foundation to fork and modify.

Learn fromHealthy

Documented and popular — useful reference codebase to read through.

Deploy as-isMixed

last commit was 5y ago; no CI workflows detected

  • 2 active contributors
  • MIT licensed
  • Tests present
Show 4 more →
  • Stale — last commit 5y ago
  • Small team — 2 contributors active in recent commits
  • Concentrated ownership — top contributor handles 60% of recent commits
  • No CI workflows detected
What would change the summary?
  • Use as dependency MixedHealthy if: 1 commit in the last 365 days
  • Deploy as-is MixedHealthy if: 1 commit in the last 180 days

Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Forkable" badge

Paste into your README — live-updates from the latest cached analysis.

Variant:
RepoPilot: Forkable
[![RepoPilot: Forkable](https://repopilot.app/api/badge/brandonlw/psychson?axis=fork)](https://repopilot.app/r/brandonlw/psychson)

Paste at the top of your README.md — renders inline like a shields.io badge.

Preview social card (1200×630)

This card auto-renders when someone shares https://repopilot.app/r/brandonlw/psychson on X, Slack, or LinkedIn.

Onboarding doc

Onboarding: brandonlw/Psychson

Generated by RepoPilot · 2026-05-10 · Source

🤖Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/brandonlw/Psychson shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

🎯Verdict

WAIT — Stale — last commit 5y ago

  • 2 active contributors
  • MIT licensed
  • Tests present
  • ⚠ Stale — last commit 5y ago
  • ⚠ Small team — 2 contributors active in recent commits
  • ⚠ Concentrated ownership — top contributor handles 60% of recent commits
  • ⚠ No CI workflows detected

<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>

Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live brandonlw/Psychson repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale — regenerate it at repopilot.app/r/brandonlw/Psychson.

What it runs against: a local clone of brandonlw/Psychson — the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in brandonlw/Psychson | Confirms the artifact applies here, not a fork | | 2 | License is still MIT | Catches relicense before you depend on it | | 3 | Default branch master exists | Catches branch renames | | 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code | | 5 | Last commit ≤ 1786 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> — paste this script from inside your clone of <code>brandonlw/Psychson</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of brandonlw/Psychson. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/brandonlw/Psychson.git
#   cd Psychson
#
# Then paste this script. Every check is read-only — no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of brandonlw/Psychson and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "brandonlw/Psychson(\\.git)?\\b" \\
  && ok "origin remote is brandonlw/Psychson" \\
  || miss "origin remote is not brandonlw/Psychson (artifact may be from a fork)"

# 2. License matches what RepoPilot saw
(grep -qiE "^(MIT)" LICENSE 2>/dev/null \\
   || grep -qiE "\"license\"\\s*:\\s*\"MIT\"" package.json 2>/dev/null) \\
  && ok "license is MIT" \\
  || miss "license drift — was MIT at generation time"

# 3. Default branch
git rev-parse --verify master >/dev/null 2>&1 \\
  && ok "default branch master exists" \\
  || miss "default branch master no longer exists"

# 4. Critical files exist
test -f "Injector/Injector/Injector.csproj" \\
  && ok "Injector/Injector/Injector.csproj" \\
  || miss "missing critical file: Injector/Injector/Injector.csproj"
test -f "Injector/Injector/FirmwareImage.cs" \\
  && ok "Injector/Injector/FirmwareImage.cs" \\
  || miss "missing critical file: Injector/Injector/FirmwareImage.cs"
test -f "DriveCom/DriveCom/PhisonDevice.cs" \\
  && ok "DriveCom/DriveCom/PhisonDevice.cs" \\
  || miss "missing critical file: DriveCom/DriveCom/PhisonDevice.cs"
test -f "firmware/main.c" \\
  && ok "firmware/main.c" \\
  || miss "missing critical file: firmware/main.c"
test -f "firmware/usb.c" \\
  && ok "firmware/usb.c" \\
  || miss "missing critical file: firmware/usb.c"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 1786 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~1756d)"
else
  miss "last commit was $days_since_last days ago — artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) — safe to trust"
else
  echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/brandonlw/Psychson"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

TL;DR

Psychson is a custom firmware and patching toolkit for Phison 2251-03 (2303) USB flash drive controllers, enabling BadUSB attacks by injecting HID payloads into the drive's 8051 microcontroller. It provides tools to dump firmware, inject malicious code, and flash modified binaries back to Phison-based drives, transforming them into automated keystroke injection devices. Multi-tool monorepo: DriveCom/ (C# PC-side device communication), EmbedPayload/ (C# Rubber Ducky script embedding), Injector/ (C# firmware address extraction and patching), firmware/ (8051 C source for custom firmware), patch/ (8051 C patch code snippets), and templates/ (dummy binary templates for testing).

👥Who it's for

Security researchers, penetration testers, and firmware hackers who need to demonstrate BadUSB vulnerabilities on Phison-based USB drives. Contributors are embedded systems developers comfortable with 8051 assembly/C cross-compilation and PC-side C# tooling for device communication.

🌱Maturity & risk

Experimental and unmaintained. The repo has no visible CI/CD pipeline, uses outdated Visual Studio project files (v11.suo from ~2012 era), and explicitly warns that firmware patches are only tested against PS2251-03 firmware version 1.03.53 on 8K eD3 NAND. No recent commits visible in provided data; this appears to be a historical security research project rather than a supported product.

High risk for data loss and hardware damage. The README explicitly states 'This is experimental software...may cause loss of data, or even permanent damage to devices.' Heavy dependency on correctly obtaining burner images (undocumented external process), firmware version-specific patches with no version detection logic, and single-maintainer legacy codebase with no tests or validation harnesses.

Active areas of work

No active development visible. This is a frozen historical repository with no apparent ongoing PRs, commits, or maintenance. The project served its purpose as a proof-of-concept for BadUSB attacks on Phison controllers circa 2013-2015.

🚀Get running

Clone the repo with git clone https://github.com/brandonlw/Psychson.git. Install SDCC (Small Device C Compiler) to C:\Program Files\SDCC (hardcoded path in build.bat). Open DriveCom/DriveCom.sln, EmbedPayload/EmbedPayload.sln, or Injector/Injector.sln in Visual Studio 2012+. Build the solution, then run the compiled .exe tools.

Daily commands: No standard dev server. Instead: (1) firmware\build.bat compiles custom 8051 firmware to .bin with SDCC. (2) patch\build.bat compiles 8051 patch code. (3) Build C# solutions in Visual Studio. (4) Execute tools\DriveCom.exe /drive=E /action=DumpFirmware /burner=BN03V104M.BIN /firmware=fw.bin to dump firmware, or /action=FlashFirmware to flash.

🗺️Map of the codebase

  • Injector/Injector/Injector.csproj — Entry point for firmware patching tool; orchestrates extraction and injection of custom code into Phison firmware images.
  • Injector/Injector/FirmwareImage.cs — Core abstraction for parsing and manipulating Phison firmware binary structure; essential for all patching operations.
  • DriveCom/DriveCom/PhisonDevice.cs — USB communication layer with Phison controller; required for device enumeration and firmware flashing.
  • firmware/main.c — Main entry point of custom 8051 firmware; defines initialization, interrupt handlers, and core system behavior.
  • firmware/usb.c — USB protocol implementation for custom firmware; critical for device enumeration and HID payload delivery.
  • EmbedPayload/EmbedPayload/Startup.cs — Payload embedding orchestrator that integrates Rubber Ducky scripts into custom firmware for automated execution.
  • patch/base.c — Base patch code template for modifying existing OEM firmware; defines hooks and callback structure for injection points.

🛠️How to make changes

Add custom SCSI command handler to firmware

  1. Define new SCSI command opcode constant in firmware/defs.h (firmware/defs.h)
  2. Add case statement in SCSI command dispatcher (firmware/scsi.c) to handle new command ID (firmware/scsi.c)
  3. Implement command handler logic with device response generation (firmware/scsi.c)
  4. Rebuild custom firmware via firmware/build.bat and test with DriveCom tool (firmware/build.bat)

Embed new Rubber Ducky payload into custom firmware

  1. Create Ducky script (inject.bin format) with desired keyboard input sequence (firmware/main.c)
  2. Run EmbedPayload application pointing to custom firmware binary and inject.bin script (EmbedPayload/EmbedPayload/Startup.cs)
  3. EmbedPayload writes payload offset and size into firmware section headers (EmbedPayload/EmbedPayload/Startup.cs)
  4. Flash modified firmware to device using DriveCom/PhisonDevice USB interface (DriveCom/DriveCom/PhisonDevice.cs)

Inject patch code into existing OEM firmware without recompilation

  1. Create patch source file referencing OEM firmware addresses from defs.h equates (e.g., patch/base.c) (patch/base.c)
  2. Compile patch via patch/build.bat; generates relocatable binary with hook metadata (patch/build.bat)
  3. Use Injector tool to parse OEM firmware and identify injection point offsets (Injector/Injector/FirmwareImage.cs)
  4. Injector embeds patch binary and redirects function calls to patch hooks in OEM firmware (Injector/Injector/Startup.cs)
  5. Flash patched firmware to device (DriveCom/DriveCom/PhisonDevice.cs)

🔧Why these technologies

  • .NET C# for host tools — Windows-only USB communication via Windows HID/WinUSB APIs; simple GUI and CLI tooling without cross-platform requirement
  • 8051 assembly & C for firmware — Phison 2251-03 is an 8051-compatible microcontroller; C provides readable custom firmware while assembly handles performance-critical USB and timer code
  • Binary patching via code injection — Avoids need to recompile OEM firmware (often unavailable); patch code inserted at runtime using existing function hooks and memory relocation
  • HID keyboard emulation — Rubber Ducky compatibility; USB drive masquerades as keyboard to inject keystrokes without driver installation on target host

⚖️Trade-offs already made

  • Separate custom firmware (firmware/) vs. patch approach (patch/)

    • Why: Custom firmware offers full control and features; patch approach works on unmodified OEM firmware but with limited hook points
    • Consequence: Users must choose between compatibility (OEM + patch) and flexibility (custom firmware); custom firmware risks brick if bootloader differs across variants
  • Firmware version lock to PS2251-03 v1.03.53

    • Why: Memory layout and hook offsets are firmware-version-specific; testing on single version ensures reliability
    • Consequence: Patches will fail on other firmware versions; users must downgrade OEM firmware, which voids warranty and risks incompatibility with newer NAND chips
  • Embedded payload via binary offset rather than firmware recompile

    • Why: EmbedPayload tool works without C compiler or rebuild; faster iteration for Ducky script changes
    • Consequence: Payload size limited by firmware memory layout; no runtime validation of script syntax before device execution
  • Windows-only host tools (no cross-platform)

    • Why: USB HID/WinUSB APIs simplest on Windows; Visual Studio project files are Windows-native
    • Consequence: Linux/macOS users cannot use DriveCom or Injector tools; must use alternative USB communication libraries or reverse-engineer protocol

🚫Non-goals (don't propose these)

  • Linux or macOS host tool support (Windows-only via .NET Framework)
  • Multiple Phison controller types (2251-03 only; 2303 label is OEM variant)
  • Runtime firmware update mechanism (must reflash via USB boot mode)
  • Payload obfuscation or anti-forensics (scripts embedded in plaintext)
  • Compatibility with firmware versions other than 1.03.53 without recalibration

🪤Traps & gotchas

Hardcoded path C:\Program Files\SDCC in build.bat will fail on non-Windows or non-standard SDCC installations. Burner image (BN03V104M.BIN) is external and undocumented to obtain. Firmware patches are version-locked to 1.03.53 with no auto-detection; flashing to wrong version silently bricks the drive. Visual Studio project files reference absolute paths in .csproj.user files. No error handling for partial firmware flashes or power loss during flashing.

🏗️Architecture

💡Concepts to learn

  • 8051 Microcontroller Architecture — Phison 2251-03 uses an 8051 core; understanding its memory segmentation (code, XRAM, SFR), interrupt model, and instruction set is mandatory for firmware modification
  • USB HID (Human Interface Device) Protocol — BadUSB payloads exploit HID keyboard emulation to inject keystrokes; firmware/usb.c implements the HID report descriptor and state machine required to masquerade as a trusted input device
  • Cross-Compilation (SDCC for 8051) — Firmware is compiled for 8051 from C code on x86/x64 machines; SDCC's code generation, memory model selection, and linker script configuration directly impact binary size and execution
  • Firmware Binary Patching & Code Injection — Injector tool rewrites firmware binaries at fixed offsets to insert patch code without recompiling; requires understanding of relocation, offset calculations, and avoiding address conflicts in the 8051 address space
  • USB Mass Storage Class (MSC) & SCSI Emulation — Phison controllers present as USB drives via MSC; firmware/scsi.c intercepts SCSI commands, allowing firmware to hide BadUSB payloads in unused sectors or execute them during enumeration
  • WinUSB Driver & Device Communication — DriveCom uses WinUSB (Windows native USB driver) to communicate with Phison bootloader; understanding USB control transfers, bulk endpoints, and timeout handling is critical for reliable burner upload and firmware dump
  • adamcaudill/Psychson — Original upstream Psychson repo by adamcaudill (Psychson wiki references point here); this brandonlw fork appears to be a snapshot of an earlier or variant version
  • usbarmory/usbarmory — USB Armory is a similar hardware security research platform with open firmware; shares the same pentesting/BadUSB threat model
  • Seytonic/Duckduino — Arduino-based Rubber Ducky alternative; related BadUSB injection technique using different hardware (8051 vs Arduino)
  • mame82/P4wnP1 — Raspberry Pi BadUSB/HID payload framework; represents modern successor to Phison-based BadUSB with better documentation and active maintenance
  • spaniakos/SDCC_8051_Tutorial — Community SDCC 8051 cross-compiler tutorials and examples; required reading for modifying firmware/patch C code

🪄PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add cross-platform build automation for firmware compilation

The firmware/ and patch/ directories contain build.bat files (Windows-only batch scripts), but there's no Linux/macOS support. Given that this is a security tool with community contributions, adding a build.sh script and documenting the exact SDT/compiler requirements (implied but not explicit) would lower the barrier for contributors on non-Windows systems and enable CI/CD.

  • [ ] Create firmware/build.sh as a POSIX equivalent to firmware/build.bat
  • [ ] Create patch/build.sh as a POSIX equivalent to patch/build.bat
  • [ ] Document the required 8051 compiler toolchain (SDCC?) and version in README.md's prerequisites section
  • [ ] Test both scripts on Linux and macOS in a CI environment (GitHub Actions)

Create integration tests for DriveCom/PhisonDevice.cs USB communication layer

PhisonDevice.cs is the core interface for communicating with Phison drives, but there are no visible unit or integration tests in the repo. Adding tests would catch regressions in firmware upload/patching flows and make it safer for contributors to modify the critical communication code.

  • [ ] Create DriveCom/DriveCom.Tests/ directory with xUnit or NUnit test project
  • [ ] Add test fixtures for PhisonDevice.cs methods (e.g., test USB vendor/product ID matching, command/response serialization)
  • [ ] Add integration test workflow in .github/workflows/ to run tests on Windows (since USB Phison device interaction is Windows-specific)
  • [ ] Document test setup instructions in README.md (mock device vs. real hardware testing)

Document firmware patch injection workflow and add validation tests for Injector.exe

The Injector tool extracts addresses from firmware and patches code, but the README doesn't explain the end-to-end workflow or validation. The FirmwareImage.cs and FirmwareSection.cs classes lack inline documentation. Adding a docs/PATCHING_WORKFLOW.md with concrete examples and unit tests for Injector would help contributors understand and safely extend the patching mechanism.

  • [ ] Create docs/PATCHING_WORKFLOW.md documenting: firmware extraction → address enumeration → patch injection → verification steps with example command lines
  • [ ] Add XML doc comments to Injector/FirmwareImage.cs and Injector/FirmwareSection.cs explaining struct layout and patching logic
  • [ ] Create Injector/Injector.Tests/ with unit tests for address extraction and binary patch insertion (using test firmware templates already in repo)
  • [ ] Add a docs/FIRMWARE_STRUCTURE.md explaining the binary format of PS2251-03 firmware sections

🌿Good first issues

  • Add a firmware version detector in DriveCom/PhisonDevice.cs that reads the version from the drive before patching/flashing and warns if mismatched against the hardcoded 1.03.53 requirement
  • Create a standalone burner image validator tool to check burner image format/size before DriveCom attempts to upload it, reducing silent failures
  • Write integration tests for Injector/FirmwareImage.cs and Injector/FirmwareSection.cs that parse the dummy templates in templates/ and verify patch injection offsets are correct

Top contributors

Click to expand

📝Recent commits

Click to expand
  • 4522989 — Update README.md (adam-caudill)
  • bf588bf — Update README.md (adam-caudill)
  • 9f487e8 — Add no-boot-mode patch (brandonlw)
  • 34d76ee — Update README.md (adam-caudill)
  • d03bcce — Update README.md (adam-caudill)
  • 9a14b71 — Update README.md (adam-caudill)
  • 69bdce8 — Update README.md (adam-caudill)
  • 783f1a4 — Whoops (brandonlw)
  • c4de427 — Update README.md (adam-caudill)
  • 5db2631 — Update README.md (brandonlw)

🔒Security observations

  • Critical · BadUSB Firmware Exploitation Capability — EmbedPayload/, firmware/, patch/. The codebase is explicitly designed to create custom firmware for USB devices that can execute arbitrary HID (Human Interface Device) payloads, effectively creating a BadUSB attack vector. The EmbedPayload tool embeds Rubber Ducky scripts into firmware for execution on the drive, allowing keystroke injection and malicious command execution on any computer the device is connected to. Fix: This is a research/proof-of-concept tool. Implement strict access controls, code signing, and distribution restrictions. Consider adding warnings and licensing agreements that prohibit malicious use. This tool should only be used in controlled security research environments.
  • High · Lack of Input Validation in Firmware Injection Tools — Injector/Injector/FirmwareImage.cs, Injector/Injector/FirmwareSection.cs. The Injector and EmbedPayload applications (FirmwareImage.cs, FirmwareSection.cs) manipulate firmware binaries without apparent input validation. These tools could be exploited to inject arbitrary code at memory addresses extracted from firmware, potentially bypassing security controls or injecting additional malicious payloads. Fix: Implement strict input validation for firmware files including: file size checks, magic number verification, CRC/signature validation, and bounds checking on all extracted addresses and injection points.
  • High · Insecure Direct Device Communication — DriveCom/DriveCom/PhisonDevice.cs. The DriveCom application enables direct communication with Phison USB devices via PhisonDevice.cs without apparent authentication or authorization checks. This allows any user with device access to read/write firmware and extract device secrets. Fix: Implement device authentication, access control lists, audit logging for all device operations, and consider requiring elevated privileges for sensitive firmware operations.
  • High · Unencrypted Firmware Binaries — firmware/, templates/. Firmware binaries (CFW.bin, templates/FWdummy.bin, templates/BNdummy.bin) are stored as plaintext binary files without encryption or integrity verification, making them susceptible to tampering and reverse engineering. Fix: Implement firmware signing and verification using cryptographic signatures. Consider encrypting sensitive firmware sections. Add integrity checks before firmware execution.
  • Medium · Missing Security Headers in Visual Studio Project Files — .gitignore, DriveCom/DriveCom.v11.suo, DriveCom/DriveCom/DriveCom.csproj.user, etc.. Multiple .suo (Solution User Options) and .csproj.user files are present in version control, which may contain sensitive build information, local paths, and user-specific configurations that could leak environment details. Fix: Add .suo, .csproj.user, and other IDE-specific files to .gitignore. Remove any existing sensitive IDE files from version control history using git-filter-branch or BFG Repo-Cleaner.
  • Medium · No Apparent Code Signing or Verification — tools/hex2bin.exe, tools/sfk.exe. The compiled binaries (hex2bin.exe, sfk.exe) in the tools directory lack visible code signing certificates or integrity verification mechanisms, making them vulnerable to man-in-the-middle attacks or substitution. Fix: Code sign all executables with a trusted certificate. Implement signature verification in applications that load or execute these tools. Provide SHA256 checksums for all distributed binaries.
  • Medium · Firmware Version Hardcoding and Limited Compatibility — README.md, patch/, firmware/. The README indicates firmware patches are only tested against PS2251-03 firmware version 1.03.53. There is no apparent version checking mechanism, which could lead to firmware corruption or unexpected behavior if applied to incompatible versions. Fix: Implement firmware version detection and validation before applying patches. Add checksums or version markers to prevent misapplication. Provide clear error messages for incompatible versions.
  • Low · Debug/Test Build Artifacts in Repository — firmware/test.bat, firmware/. The presence of test.bat and build.bat files suggests debug builds may be created and committed. These could contain debug symbols or unoptimized code with potential information disclosure. Fix: undefined

LLM-derived; treat as a starting point, not a security audit.


Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.

Mixed signals · brandonlw/Psychson — RepoPilot