DC34 Badge Image Flasher
Put a 128×128 image on your DEF CON 34 badge from the browser.
→ freeqaz.github.io/defcon34b
No Python, no pipx, no Pillow, no hunting for /dev/ttyACM0. Plug the badge in,
pick an image, click flash. The Zellic logo and the badge’s original DEF CON
logo are both built in, so you can brand a badge and put it back the way you
found it.
Everything runs locally. No image is uploaded anywhere.
What this is
A browser port of bunnie/dc34-image,
the Python CLI for loading images onto the badge. Same wire protocol, same
retry behaviour — verified byte-for-byte against the original (see Testing).
Browser support
Flashing needs a Chromium-based browser — Chrome, Edge, Brave or Opera.
Firefox and Safari implement neither Web Serial nor WebUSB, and every browser on
iOS is Safari underneath, so iPhones and iPads cannot flash at all. Those
browsers can still load images and preview them; only the flash button is
unavailable.
There are two transports, and which one works depends on the platform:
|
Desktop (Linux/macOS/Windows) |
Android |
| Web Serial — Connect badge |
works |
Chrome 148+, and only on phones whose OS ships the Android Serial API |
| WebUSB — Connect over WebUSB |
fails: interface busy |
works |
The split is about who owns the USB interface. The badge exposes a CDC-ACM
function, and on a desktop the OS binds its own class driver to it at
enumeration time (cdc_acm, usbser.sys, AppleUSBCDC). Chrome will not take
an interface away from a kernel driver, so claimInterface() fails and Web
Serial — the API built for devices the OS has already bound — is the right
choice. Android binds no such driver, so WebUSB can claim the interface
directly, which makes it the transport that actually works on a phone.
Measured on this badge, same machine, same Chrome:
cdc_acm bound requestDevice ok, open() ok,
claimInterface(3) -> NetworkError: Unable to claim interface
cdc_acm unbound claimInterface(2) and (3) both succeed, bulk IO works
Windows deserves a specific note: WebUSB there would need the device to
advertise WinUSB through MS OS 2.0 descriptors. It does not — its BOS
descriptor is 12 bytes carrying a single USB 2.0 Extension capability and
nothing else — so usbser.sys wins unconditionally. Use Web Serial on Windows.
Linux permissions
Chrome talks to /dev/ttyACM0 as your user, so the same group membership the
Python tool needs applies here:
sudo usermod -aG dialout $USER # or 'uucp' on Arch and derivatives
Log out and back in afterwards. Check which group your system uses with
ls -l /dev/ttyACM0.
Speed, and what to do when it’s slow
A flash normally takes about 3 seconds. If it’s taking 30, the badge is the
reason, not the link — and there’s a one-second fix.
Put the badge on its instructions or main screen before flashing. Not a
submenu, not mid-animation, not three seconds after power-on.
The reason is in the firmware. A chunk arrives over the wire as the text
image <base64>, and the badge feeds it to its console by injecting each
character into the keyboard queue one at a time
(usb-bao1x), fanning every one out to every registered keyboard listener
(bao1x-hal-service/src/servers/keyboard.rs). The vault UI is one of those
listeners and does real work per key. So each chunk lands as ~104 keypresses
aimed at the badge’s user interface, and whether that interface can absorb them
decides everything. When it can’t, keys are dropped and each drop logs
Input overflow to 17, dropping keys! back out of the very same serial port,
which is what actually eats the time.
Measured on one badge, same code, six chunks, 200 ms apart:
| badge screen |
per-chunk round trip |
log lines |
| busy |
34 / 585 / 1236 / 347 / 1501 / 1254 ms |
249 |
| instructions |
35 / 39 / 40 / 18 / 19 / 13 ms |
0 |
Two consequences worth knowing:
- A freshly booted badge is busy. The first flash after power-on can take
~13 seconds. Give it a moment and it drops to ~3.
- Turning the delay slider down does not help a slow badge. It makes it
worse — a badge that’s already behind falls further behind (~40 s at 50 ms
against ~30 s at 200 ms). The app detects this and slows itself to 200 ms for
the rest of the transfer, so the slider is rarely worth touching.
Caveat on the table above: “busy” and “instructions” are the two states that
were actually measured. Which other screens behave which way hasn’t been
surveyed — if a flash crawls, the instructions screen is the known-good state to
go back to.
The protocol
Ported from the sender in dc34-image and cross-checked against the firmware
receiver in dc34-console
(src/cmds/image.rs).
- 1 000 000 baud, 8N1, 4 s response timeout
- 128×128 pixels = 16 384 bits = 2048 bytes, sent as 32 chunks of 64 bytes
- Each chunk, before base64:
u16 index (BE) ‖ 64 B data ‖ u32 CRC-32 (BE),
the CRC covering the first 66 bytes
- Host sends
image <base64>\n; the badge replies OK, ERR, or SUCCESS
once all 32 slots are filled. Lines starting with [console] are the REPL
echoing you back and are ignored.
image clear\n → CLEAR wipes the stored image; the badge then falls back to
the DEF CON logo on its own.
Bit packing, which is the easy part to get subtly wrong: flip the image
horizontally, black → 1, pack MSB-first into 512 u32s, reverse each group
of four words, serialize big-endian.
Layout
index.html the page
src/packer.js bit packing, CRC-32, chunk framing (no DOM — Node-testable)
src/image.js canvas: decode → 128×128 → dither → 1-bit
src/serial.js the badge console protocol, plus the Web Serial transport
src/usb.js the WebUSB transport (CDC by hand — the Android path)
src/app.js UI wiring
assets/ the two preset images
tools/gen_assets.py regenerates assets/ and the golden test vectors
tools/clone-refs.sh clones the upstream repos into vendor/ (gitignored)
tools/webusb-test-env.sh unbind cdc_acm so the WebUSB path can be tested on Linux
test/ see below
Testing
The risk with a port like this is producing 2048 plausible-looking bytes that
are quietly wrong. So the packer is pinned against two independent references:
the Python sender, and the firmware’s own copy of the stock logo
(dc34-vault/src/bitmaps/dc_logo.rs, a [u32; 512] literal authored by
neither this code nor the Python).
Unit tests — no dependencies, no npm install:
node --test test/pack.test.mjs
Browser tests — the image pipeline and both transports, run headless. Each
drives the real transport code against a fake badge that reimplements the
firmware’s receive logic, covering the retry, timeout, cancel and echo-skipping
paths that are otherwise impossible to trigger on demand. usb.test.js does the
same one layer down, with a fake USBDevice carrying the badge’s real
descriptor layout, so interface discovery, line coding, DTR and bulk framing are
checked without hardware:
python3 -m http.server 8765 &
chromium --headless --remote-debugging-port=9222 --user-data-dir=/tmp/cdp about:blank &
node test/cdp.mjs http://127.0.0.1:8765/test/browser/blank.html test/browser/serial.test.js
node test/cdp.mjs http://127.0.0.1:8765/test/browser/blank.html test/browser/usb.test.js
Testing the WebUSB path against real hardware on Linux. A mock cannot prove
Chrome will claim a real interface, and on a desktop cdc_acm normally prevents
it. tools/webusb-test-env.sh reproduces Android’s driver situation locally by
unbinding cdc_acm and opening up the usbfs node — both undone by teardown,
and by simply replugging the badge:
./tools/webusb-test-env.sh setup # then use "Connect over WebUSB" in the page
./tools/webusb-test-env.sh teardown # restores /dev/ttyACM0
Note that the browser caches ES modules between runs, so test/cdp.mjs disables
the HTTP cache — without it, editing src/ and re-running silently retests the
previous build.
Regenerating assets and vectors (needs Pillow and the upstream clones):
./tools/clone-refs.sh
python3 tools/gen_assets.py
Credits
Badge, firmware and the original uploader by bunnie
and the DEF CON 34 badge team. Badge documentation at
defcon.org/34b.
评论