Forensics
Medium
120 points
Mouse Cap
Recuite 2025 - HCMUS
6 tháng 10, 2025
USB
PCAP
Mouse Movements
HID

Forensics
Mouse Cap - Writeup#
Challenge Information#
- Category: Forensics
- Difficulty: Medium
- Files: capture.pcapng
- Hint: "Did you know you can capture USB traffic?"
Analysis#
USB HID Mouse Protocol#
Gói dữ liệu di chuyển chuột USB được truyền dưới dạng packet 4 byte:
- Byte 0: Trạng thái nút (0=none, 1=left, 2=right)
- Byte 1: Dịch chuyển X (signed byte, -127 đến 127)
- Byte 2: Dịch chuyển Y (signed byte, -127 đến 127)
PCAPNG Structure#
Gói USB trong pcapng:
- Header: 28 bytes (0x1c) metadata
- Leftover Capture Data: Dữ liệu USB thực tế (phần sau header)
Solution#
Extract USB Mouse Data#
pythonfrom scapy.all import *
packets = rdpcap('capture.pcapng')
mouse_movements = []
for packet in packets:
if packet.haslayer(Raw):
raw_data = bytes(packet[Raw].load)
if len(raw_data) > 28:
leftover = raw_data[27:]
if len(leftover) in [4,5,6,7,8]: # Mouse data
button = leftover[0]
x = leftover[1] if leftover[1] < 128 else leftover[1] - 256
y = leftover[2] if leftover[2] < 128 else leftover[2] - 256
mouse_movements.append({'button': button, 'x': x, 'y': y})
Reconstruct Path#
pythonx, y = 0, 0
path = [(0, 0)]
for move in mouse_movements:
x += move['x']
y += move['y']
path.append((x, y))
Visualize#
pythonimport matplotlib.pyplot as plt
x_coords = [p[0] for p in path]
y_coords = [p[1] for p in path]
plt.plot(x_coords, y_coords, 'b-')
plt.gca().invert_yaxis() # Tọa độ màn hình: đảo trục Y
plt.savefig('mouse_path.png', dpi=300)
Results#
- Total packets: 29,040
- Mouse movements: 14,399
- Path range: X=[-133, 1714], Y=[-902, 339]
- Flag visible khi plot đường đi chuột!
Flag#
BPCTF{usb_mouse_is_so_ez}
Key Takeaways#
Technical Lessons#
- USB HID dùng gói đơn giản 4 byte cho chuột.
- PCAPNG cho USB thường có header ~28 byte trước dữ liệu USB.
- Chuyển đổi signed byte:
x if x < 128 else x - 256. - Di chuyển chuột là relative — cần cộng dồn để dựng đường đi.
Security Implications#
- Lưu lượng USB có thể bị capture và phân tích.
- Di chuyển chuột có thể tiết lộ hành vi người dùng.
- Thiết bị HID có thể dùng cho truyền dữ liệu bí mật (covert channels).
- USB keylogger / mouse logger là mối đe dọa nghiêm trọng.
Defense#
- Giám sát các kết nối USB bất thường.
- Whitelist thiết bị USB được phép.
- Hệ thống endpoint detection tracking hoạt động USB.
120
Points
Medium
Difficulty
Forensics
Category