Hacktricks-skills usb-keystroke-decoder

Decode USB keyboard keystrokes from PCAP captures. Use this skill whenever you need to extract typed text from USB traffic, analyze keyboard HID reports, or investigate USB-based keylogging. Trigger on any mention of USB keyboard analysis, PCAP keystroke extraction, HID report decoding, USB traffic forensics, or recovering typed input from network captures.

install
source · Clone the upstream repo
git clone https://github.com/abelrguezr/hacktricks-skills
manifest: skills/generic-methodologies-and-resources/basic-forensic-methodology/pcap-inspection/usb-keystrokes/SKILL.MD
source content

USB Keystroke Decoder

Extract and decode typed keystrokes from USB HID traffic captured in PCAP files. This skill handles the USB boot protocol format used by most keyboards.

How USB Keyboards Work

USB keyboards use the HID boot protocol. Each interrupt transfer to the host is 8 bytes:

ByteMeaning
0Modifier bitmap (Shift, Ctrl, Alt, etc.)
1Reserved/padding
2-7Up to 6 keycodes in USB usage ID format

Keycode

0x00
means no key. Keyboards without NKRO send
0x01
in byte 2 when more than 6 keys are pressed.

Quick Start

Method 1: Use the bundled decoder script

# Extract raw USB data from PCAP
tshark -r capture.pcap -Y 'usb.capdata && usb.data_len == 8' -T fields -e usb.capdata | \
  sed 's/../:&/g' > keystrokes.txt

# Decode to text
python3 scripts/usb_decoder.py keystrokes.txt

Method 2: Use Wireshark

  1. Filter keyboard traffic:
    usb.transfer_type == 0x01 && usb.endpoint_address.direction == "IN"
  2. Add columns: Right-click
    usb.capdata
    and
    usbhid.boot_report.keyboard.keycode_1
    fields
  3. Hide empty reports:
    !(usb.capdata == 00:00:00:00:00:00:00:00)
  4. Export: File → Export Packet Dissections → As CSV

Common Modifier Bits

HexModifier
0x01Left Ctrl
0x02Left Shift
0x04Left Alt
0x08Left GUI (Super/Windows)
0x10Right Ctrl
0x20Right Shift
0x40Right Alt
0x80Right GUI

Common Keycodes

HexKeyHexKeyHexKey
0x04a0x05b0x06c
0x07d0x08e0x09f
0x0Ag0x0Bh0x0Ci
0x0Dj0x0Ek0x0Fl
0x10;0x11'0x12`
0x13\0x14Enter0x15Esc
0x16Backspace0x17Tab0x18Space
0x19-0x1A=0x1B[
0x1C]0x1D#0x1E1
0x1F20x2030x214
0x2250x2360x247
0x2580x2690x270
0x28Return0x29Caps Lock0x2AF1
0x2BF20x2CF30x2DF4
0x2EF50x2FF60x30F7
0x31F80x32F90x33F10
0x34F110x35F120x36Scroll Lock

Troubleshooting

Wireshark shows no usbhid.* fields

The HID report descriptor wasn't captured. Try:

  • Replug the keyboard while capturing
  • Fall back to raw
    usb.capdata
    decoding

Windows captures show empty device list

USBPcap extcap interface may be missing after Wireshark upgrades. Reinstall USBPcap.

Nonsense output

You may be mixing multiple devices. Always correlate by

usb.bus_id:device:interface
(e.g.,
1.9.1
) before decoding.

BLE keyboards

Filter on

btatt.value && frame.len == 20
and dump hex payloads before decoding.

External Tools

  • ctf-usb-keyboard-parser: Quick CTF challenges
  • CTF-Usb_Keyboard_Parser: Native pcap/pcapng support, no tshark required
  • USB-HID-decoders: Keyboard, mouse, and tablet visualizers

References