USB ํค์คํธ๋กํฌ
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
If you have a pcap containing the communication via USB of a keyboard like the following one:
.png)
USB keyboards usually speak the HID boot protocol, so every interrupt transfer towards the host is only 8 bytes long: one byte of modifier bits (Ctrl/Shift/Alt/Super), one reserved byte, and up to six keycodes per report. Decoding those bytes is enough to rebuild everything that was typed.
USB HID report basics
The typical IN report looks like:
| Byte | ์๋ฏธ |
|---|---|
| 0 | Modifier bitmap (0x02 = Left Shift, 0x20 = Right Alt, etc.). Multiple bits can be set simultaneously. |
| 1 | Reserved/padding but often reused by gaming keyboards for vendor data. |
| 2-7 | Up to six concurrent keycodes in USB usage ID format (0x04 = a, 0x1E = 1). 0x00 means โno keyโ. |
Keyboards without NKRO usually send 0x01 in byte 2 when more than six keys are pressed to signal โrolloverโ. Understanding this layout helps when you only have the raw usb.capdata bytes.
Extracting HID data from a PCAP
Wireshark workflow
- Isolate the device: filter on interrupt IN traffic from the keyboard, e.g.
usb.transfer_type == 0x01 && usb.endpoint_address.direction == "IN" && usb.device_address == 3. - Add useful columns: right-click the
Leftover Capture Datafield (usb.capdata) and your preferredusbhid.*fields (e.g.usbhid.boot_report.keyboard.keycode_1) to follow keystrokes without opening every frame. - Hide empty reports: apply
!(usb.capdata == 00:00:00:00:00:00:00:00)to drop idle frames. - Export for post-processing:
File -> Export Packet Dissections -> As CSV, includeframe.number,usb.src,usb.capdata, andusbhid.modifiersto script the reconstruction later.
Command-line workflow
ctf-usb-keyboard-parser already automates the classic tshark + sed pipeline:
tshark -r ./usb.pcap -Y 'usb.capdata && usb.data_len == 8' -T fields -e usb.capdata | sed 's/../:&/g2' > keystrokes.txt
python3 usbkeyboard.py ./keystrokes.txt
์ต์ ์บก์ฒ์์๋ ์ฅ์น๋ณ๋ก ๋ฐฐ์น ์ฒ๋ฆฌํ์ฌ usb.capdata์ ๋ ํ๋ถํ usbhid.data ํ๋ ๋ ๋ค ์ ์งํ ์ ์์ต๋๋ค:
tshark -r usb.pcapng -Y "usb.capdata || usbhid.data" -T fields -e usb.src -e usb.capdata -e usbhid.data | \
sort -s -k1,1 | \
awk '{ printf "%s", (NR==1 ? $1 : pre!=$1 ? "\n" $1 : "") " " $2; pre=$1 }' | \
awk '{ for (i=2; i<=NF; i++) print $i > "usbdata-" $1 ".txt" }'
๊ทธ ์ฅ์น๋ณ ํ์ผ๋ค์ ์ด๋ค decoder์๋ ๋ฐ๋ก ๋ฃ์ ์ ์์ต๋๋ค. ์บก์ฒ๊ฐ GATT๋ก ํฐ๋๋ง๋ BLE ํค๋ณด๋์์ ์๋ค๋ฉด, btatt.value && frame.len == 20๋ก ํํฐ๋งํ๊ณ ๋์ฝ๋ฉํ๊ธฐ ์ ์ hex payloads๋ฅผ ๋คํํ์ธ์.
๋์ฝ๋ฉ ์๋ํ
- ctf-usb-keyboard-parser๋ ๋น ๋ฅธ CTF ๊ณผ์ ์ ์ ์ฉํ๋ฉฐ ์ด๋ฏธ ๋ฆฌํฌ์งํ ๋ฆฌ์ ํฌํจ๋์ด ์์ต๋๋ค.
- CTF-Usb_Keyboard_Parser (
main.py)๋pcap๊ณผpcapngํ์ผ์ ๋ค์ดํฐ๋ธ๋ก ํ์ฑํ๊ณLinkTypeUsbLinuxMmapped/LinkTypeUsbPcap์ ์ดํดํ๋ฉฐ tshark๊ฐ ํ์ ์์ด์ ๊ฒฉ๋ฆฌ๋ ์๋๋ฐ์ค์์๋ ์ ์๋ํฉ๋๋ค. - USB-HID-decoders๋ ํค๋ณด๋, ๋ง์ฐ์ค, ํ๋ธ๋ฆฟ์ฉ ์๊ฐํ๊ธฐ๋ฅผ ์ถ๊ฐํฉ๋๋ค.
extract_hid_data.shํฌํผ(tshark ๋ฐฑ์๋)๋extract_hid_data.py(scapy ๋ฐฑ์๋)๋ฅผ ์คํํ ๋ค์ ์์ฑ๋ ํ ์คํธ ํ์ผ์ decoder ๋๋ replay ๋ชจ๋์ ๋ฃ์ด ํค ์ ๋ ฅ์ด ์ฌ์๋๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
๋น ๋ฅธ Python decoder
#!/usr/bin/env python3
import sys
HID = {0x04:'a',0x05:'b',0x06:'c',0x07:'d',0x08:'e',0x09:'f',0x0a:'g',0x1c:'y',0x1d:'z',0x28:'\n'}
for raw in sys.stdin:
raw = raw.strip().replace(':', '')
if len(raw) != 16:
continue
keycode = int(raw[4:6], 16)
modifier = int(raw[0:2], 16)
if keycode:
char = HID.get(keycode, '?')
if modifier & 0x02:
char = char.upper()
sys.stdout.write(char)
์ด์ ์ ๋คํํ 16์ง์(hex) ๋ผ์ธ๋ค์ ์ ๋ ฅํ๋ฉด ์ ์ฒด ํ์๋ฅผ ํ๊ฒฝ์ ๋ถ๋ฌ์ค์ง ์๊ณ ๋ ์ฆ์ ๋๋ต์ ์ธ ๋ณต์์ ์ป์ ์ ์์ต๋๋ค.
๋ฌธ์ ํด๊ฒฐ ํ
- Wireshark์ด
usbhid.*ํ๋๋ฅผ ์ฑ์ฐ์ง ์๋๋ค๋ฉด, HID report descriptor๊ฐ ์๋ง ์บก์ฒ๋์ง ์์์ต๋๋ค. ์บก์ฒ ์ค์ ํค๋ณด๋๋ฅผ ์ฌ์ฐ๊ฒฐํ๊ฑฐ๋ ์์usb.capdata๋ก ๋๋์๊ฐ์ธ์. - Windows ์บก์ฒ๋ USBPcap extcap ์ธํฐํ์ด์ค๋ฅผ ํ์๋ก ํฉ๋๋ค; Wireshark ์ ๊ทธ๋ ์ด๋ ํ์๋ ํด๋น ์ธํฐํ์ด์ค๊ฐ ์ ์ง๋์๋์ง ํ์ธํ์ธ์. extcap์ด ์์ผ๋ฉด ์ฅ์น ๋ชฉ๋ก์ด ๋น์ด ์๊ฒ ๋ฉ๋๋ค.
- ๋์ฝ๋ฉ์ ํ๊ธฐ ์ ์ ํญ์
usb.bus_id:device:interface(์:1.9.1)๋ฅผ ์ํธ ์ฐ๊ด์์ผ ํ์ธํ์ธ์ โ ์ฌ๋ฌ ํค๋ณด๋๋ ์คํ ๋ฆฌ์ง ์ฅ์น๋ฅผ ์์ด ๋ถ์ํ๋ฉด ๋ฌด์๋ฏธํ ํค์คํธ๋กํฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ฐธ๊ณ ์๋ฃ
- https://github.com/TeamRocketIst/ctf-usb-keyboard-parser
- https://github.com/tanc7/HacktheBox_Deadly_Arthropod_Writeup
- https://github.com/5h4rrk/CTF-Usb_Keyboard_Parser
- https://github.com/Nissen96/USB-HID-decoders
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


