3

使用 Proxmox VE 抓 USB 数据包

 1 year ago
source link: https://www.sskaje.me/2023/07/25/usb-capture-with-proxmox-ve/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

使用 Proxmox VE 抓 USB 数据包


试过 Windows + USBPcap,Windows + VirtualBox,Mac + VirtualBox,都各种问题。

本来目标是监测一个设备的 usb 刷写过程,用笔记本电脑的方案里最靠近成功的是 Mac + VirtualBox,需要使用 root 启动 VirtualBox,相关命令如下

/Applications/VirtualBox.app/Contents/MacOS/VBoxManage list usbhost
sudo /Applications/VirtualBox.app/Contents/MacOS/VBoxManage controlvm "Win10-USB" usbattach "p=0xXXXX;v=0xXXXX;s=0x0006a003ecaab3f0;l=0x14200000" --capturefile /tmp/esXXXX.pcap

其中Address 里的s=,或者 UUID 每次都不一样,导致刷写过程的 USB 断开之后,下一次就没法自动发现了。

因为按VirtualBox 文档要求,需要手动 usbattach,所以还没办法用 USB filter 来自动操作。

而,文档里介绍的抓 Root Hub 的方法,在我的 mac 上无效,而我试图 Windows + VirtualBox,崩。所以转过来看qemu 的方案。

搜到了 qemu 的官方文档。

https://qemu-project.gitlab.io/qemu/system/devices/usb.html

All usb devices have support for recording the usb traffic. This can be enabled using the pcap=<file> property, for example:

-device usb-mouse,pcap=mouse.pcap

于是赶紧去看 Proxmox VE 的 USB 选项,配置之后,可以正常发现设备,虚拟机里的软件也能正常识别。

image.png

ssh 到 pve 宿主机上,我的虚拟机 ID 102

qm showcmd 102

去掉 USB 再来一次,对比了一下命令参数,和 pve 的文档一致 https://pve.proxmox.com/wiki/USB_Devices_in_Virtual_Machines

操作方式是 qm monitor,web ui里去掉usb设备,手动添加,把showcmd 里拿到的设备参数处理一下,命令如下

root@pve:~# qm monitor 102 
Entering QEMU Monitor for VM 102 - type 'help' for help
qm> device_add qemu-xhci,p2=15,p3=15,id=xhci,bus=pci.1,addr=0x1b
qm> device_add usb-host,bus=xhci.0,port=1,vendorid=0xXXXX,productid=0xXXXX,id=usb0,pcap=/tmp/esXXXX.pcap
qm> quit

其中,VID 和 PID 我替换成 XXXX了,根据自己实际情况来。

然后,把 pcap 拿回来,Wireshark 打开,分析。

但是,数据包没抓全。

Frame 114: 8267 bytes on wire (66136 bits), 320 bytes captured (2560 bits)

调查了一下,

https://github.com/qemu/qemu/blob/master/hw/usb/pcap.c#L73

https://github.com/qemu/qemu/blob/master/hw/usb/pcap.c#L185

源码这两处定义了最大数据长度 256,正好和拿下里的pcap文件里的一致。

就这样吧,等有需求的时候,再build一个qemu自己抓完整包,就是不知道性能风险有多大。

另外一个可能的方案:https://fedoraproject.org/wiki/Usbmon


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK