自研BUSHOUND工具USBHound开发调试笔记-USB控制传输的数据抓包实现
2022-07-29
645
13
本想着搞一个自研的BUSHOUND应该是一件比较简单的事,但没想到也麻烦了。
搞了一天upperfilter,最终还是投降,换成了lowerfilter.
前面搞的时候,对系统中所有USB设备进行过滤,导致系统中的数据打印太多,无法分清谁是谁。当然也可以分清,每个设备的地址不一样,并且设备栈也是明确的,但如果要对着一大堆的十六进制数,虽然本人看的多也习惯了,但也抗不住啊。
所以,为了化繁为简,本人使用的是一个USB音箱来测试的,只对这个音箱来进行类过滤。过滤的方法也就很简单粗爆,就是通过硬件ID来实现。
BOOLEAN isFind = FALSE;
WCHAR PropertyBuffer[64] = { 0 };
ULONG ResultLength = 0;
status = IoGetDeviceProperty(PhysicalDeviceObject, DevicePropertyHardwareID, sizeof(PropertyBuffer), PropertyBuffer, &ResultLength);
if (status == STATUS_SUCCESS)
{
KdPrint(("DevicePropertyHardwareID:%S\n", PropertyBuffer));
if (wcsstr(PropertyBuffer, L"USB\\VID_1908&PID_2070&REV_0100") != NULL)
{
isFind = TRUE;
}
}
所以最终通过!devstack查看到的设备栈如下:
1: kd> !devstack FFFFB5801529B270
!DevObj !DrvObj !DevExt ObjectName
ffffb58012950060 \Driver\usbccgp ffffb580129501b0 0000005f
> ffffb5801529b270 \Driver\USBHound ffffb5801529b3c0
ffffb5801530d8e0 \Driver\USBHUB3 ffffb580152d4e70 USBPDO-15
可以看到,我们的设备ffffb5801529b270是usbccgp驱动ffffb58012950060的下层过滤驱动,但又为了HUB创建的ffffb5801530d8e0之上。这样就可以对该设备ffffb58012950060进行数据过滤了。
延用昨天的代码,后面完善了一下UrbFunctionControlTransfer的代码:
NTSTATUS UrbFunctionControlTransfer(PDEVICE_OBJECT DeviceObject, PURB Urb)
{
PFILTER_DEVICE_EXTENSION DeviceExtension = (PFILTER_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
PUCHAR buffer = GetTransferBuffer(Urb->UrbControlTransfer);
ULONG nLength = GetTransferLength(Urb->UrbControlTransfer);
UNREFERENCED_PARAMETER(DeviceExtension);
UNREFERENCED_PARAMETER(buffer);
UNREFERENCED_PARAMETER(nLength);
KdPrint(("DeviceObject:%p\n", DeviceObject));
KdPrint(("DeviceExtension:%p\n", DeviceExtension));
KdPrint(("UrbFunctionControlTransfer:\n"));
DumpUsbCtrlCmd(Urb->UrbControlTransfer.SetupPacket, sizeof(Urb->UrbControlTransfer.SetupPacket));
if (Urb->UrbControlTransfer.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
{
KdPrint(("IN:"));
}
else
{
KdPrint(("OUT:"));
}
if (Urb->UrbControlTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK)
{
DumpHex(buffer, nLength);
}
else
{
KdPrint(("USTS %08x\n", Urb->UrbControlTransfer.Hdr.Status));
}
return STATUS_SUCCESS;
}
插入设备之后,通过windbg打印出的数据信息如下:
Urb=FFFFB580151E77E0,urb2=FFFFB580151E77E0
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 80 06 00 01 00 00 12 00
IN:12 01 10 01 00 00 00 40 08 19 70 20 00 01 01 02
03 01
Urb=FFFFB580151E77E0,urb2=FFFFB580151E77E0
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 80 06 00 02 00 00 09 00
IN:09 02 6E 00 02 01 00 80 C8
Urb=FFFFB580151E77E0,urb2=FFFFB580151E77E0
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 80 06 00 02 00 00 6E 00
IN:09 02 6E 00 02 01 00 80 C8 09 04 00 00 00 01 01
00 00 09 24 01 00 01 28 00 01 01 0C 24 02 01 01
01 00 02 03 00 00 00 0A 24 06 02 01 01 03 00 00
00 09 24 03 03 01 03 00 02 00 09 04 01 00 00 01
02 00 00 09 04 01 01 01 01 02 00 00 07 24 01 01
01 01 00 0B 24 02 01 02 02 10 01 80 BB 00 09 05
02 09 C0 00 01 00 00 07 25 01 01 01 01 00
Urb=FFFFB58015272910,urb2=FFFFB58015272910
Urb->UrbHeader.Function=0
Urb=FFFFB5801581D310,urb2=FFFFB5801581D310
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 80 06 02 03 09 04 04 00
IN:1C 03 55 00
Urb=FFFFB5801581D310,urb2=FFFFB5801581D310
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 80 06 02 03 09 04 1C 00
IN:1C 03 55 00 53 00 42 00 32 00 2E 00 30 00 20 00
44 00 65 00 76 00 69 00 63 00 65 00
580151BFBB0
UsbSleepStudy_DeviceD0Entry: Exit Handle 0XFFFFB580151BFBB0
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 80 06 02 03 09 04 04 00
IN:1C 03 55 00
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 80 06 02 03 09 04 1C 00
IN:1C 03 55 00 53 00 42 00 32 00 2E 00 30 00 20 00
44 00 65 00 76 00 69 00 63 00 65 00
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: A1 81 00 01 00 02 01 00
IN:00
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: A1 81 00 02 00 02 02 00
IN:78 80
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: A1 82 00 02 00 02 02 00
IN:00 80
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: A1 83 00 02 00 02 02 00
IN:FF 80
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: A1 84 00 02 00 02 02 00
IN:01 00
Urb=FFFFB580155F4710,urb2=FFFFB580155F4710
Urb->UrbHeader.Function=1
UrbFunctionSelectInterface:
InterfaceNumber:01
AlternateSetting:00
Class:01
NumberOfPipes:00
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 21 01 00 01 00 02 01 00
OUT:00
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 21 01 00 02 00 02 02 00
OUT:6E 80
Urb=FFFFB580148A1C00,urb2=FFFFB580148A1C00
Urb->UrbHeader.Function=1
UrbFunctionSelectInterface:
InterfaceNumber:01
AlternateSetting:01
Class:01
NumberOfPipes:01
Urb=FFFFB58014F00880,urb2=FFFFB58014F00880
Urb->UrbHeader.Function=8
DeviceObject:FFFFB5801529B270
DeviceExtension:FFFFB5801529B3C0
UrbFunctionControlTransfer:
CTL: 22 01 00 01 02 00 03 00
OUT:80 BB 00
这个数据的显示竟然和BUSHOUND抓到的包一致(不一致就怪了),那就兴奋一下,可以过一个美好的周末了。
不过话说回来,今年的进展确实够慢。不过技术就是个探索的过程。
本人大概研究了一下BUSHOUND的原理,不过没有研究明白,他是类过滤驱动但是没有对设备进行类驱动栈的增加,系统只也只有一个控制设备。而我的就不样了。
BUSHOUND设备栈
USBHound设备栈
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936