Go 程序 ( Bettercap 2 ) 出错,具体取决于运行 ble 扫描时我在 Ubuntu/Raspberry Pi 操作系统上使用的蓝牙适配器

Jim*_*mmy 7 bluetooth go bluez nrf52 segger-jlink

我在 Ubuntu 20.04 和 Raspberry Pi OS 5.10 上使用它,但这不是与 Linux 相关的问题。

当我使用名为 Bettercap 2 的 Go 程序( https://www.bettercap.org/和存储库: https: //github.com/bettercap/bettercap)扫描蓝牙设备时,我遇到了问题” ble.recon on”使用不同的蓝牙适配器。

当我使用 Realtek RTL8761b 驱动程序 ( MPOW MPBH456AB ) 与适配器一起使用时,您可以在亚马逊上找到它,效果很好,但是当我使用 NordicSemi nrf52840 适配器时 ( https://www.nordicsemi.com/Products/Development-hardware/nrf52840 -dongle这是我的目标,用Zephyr RTOS的hci_usb示例(https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/hci_usb)进行闪烁,该示例应该使用蓝牙来打开任何微控制器进入任何计算机都应该识别的常规蓝牙适配器时,它会抛出以下错误:

>> ble.recon on
   panic: runtime error: slice bounds out of range [:1] with capacity 0

   goroutine 1 [running]:
   github.com/bettercap/gatt/linux/cmd.(*Cmd).SendAndCheckResp(0x1c637c0, 0xa0c760, 0x1c64fe8, 0x1c6501c, 0x1, 0x1, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/cmd/cmd.go:98 +0x1b4
   github.com/bettercap/gatt/linux.(*HCI).resetDevice(0x18ac0a0, 0x93dc10, 0x18ac0a0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/hci.go:273 +0x2f0
   github.com/bettercap/gatt/linux.NewHCI(0xffffffff, 0x184fd01, 0xff, 0x2, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/linux/hci.go:90 +0x4c0
   github.com/bettercap/gatt.NewDevice(0x184fd1c, 0x2, 0x2, 0x3c, 0x184fd24, 0x1, 0x1)
    /home/pi/go/pkg/mod/github.com/bettercap/gatt@v0.0.0-20210514133428-df6e615f2f67/device_linux.go:57 +0x114
   github.com/bettercap/bettercap/modules/ble.(*BLERecon).Configure(0x18a2780, 0x0, 0x4)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:165 +0x1cc
   github.com/bettercap/bettercap/modules/ble.(*BLERecon).Start(0x18a2780, 0x1, 0x1b2c001)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:183 +0x1c
   github.com/bettercap/bettercap/modules/ble.NewBLERecon.func1(0x0, 0x0, 0x0, 0x84f358, 0xc)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/modules/ble/ble_recon.go:56 +0x1c
   github.com/bettercap/bettercap/session.(*ModuleHandler).Exec(0x1b2c0c0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/session/module_handler.go:74 +0x80
   github.com/bettercap/bettercap/session.(*Session).Run(0x18fb2c0, 0x1c64e30, 0xc, 0x1, 0x1)
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/session/session.go:416 +0x284
   main.main()
    /home/pi/go/pkg/mod/github.com/bettercap/bettercap@v2.24.1+incompatible/main.go:94 +0x8c8
Run Code Online (Sandbox Code Playgroud)

我不知道这意味着什么,因为我不是 Go 开发人员,也从未使用过这种语言,我查看了错误,它似乎在代码中,但不了解 Go,我更喜欢在修改任何内容之前询问。

问题仅在我使用 nrf 加密狗时出现,否则它可以与主机的蓝牙和其他 realtek 加密狗配合使用。

nrf 加密狗与 BlueZ 堆栈配合使用,结果如下:

bluetoothctl(有BD地址)扫描确实有效

$ sudo bluetoothctl
  Agent registered
  [bluetooth]# list
  Controller EB:XX:XX:XX:XX:XX BlueZ 5.50 [default]
Run Code Online (Sandbox Code Playgroud)

btmgmt(找到控制器)扫描确实有效

$ sudo btmgmt --index 0
   [hci0]# auto-power
   Found controller with index 0
   [hci0]# find -l
Run Code Online (Sandbox Code Playgroud)

但是,虽然已弃用,但 hciconfig 和 hcitool 可以识别 Realtek 加密狗,但对于此加密狗,结果如下:

hciconfig(无BD地址)

$ hciconfig
  hci0:   Type: Primary  Bus: USB
    BD Address: 00:00:00:00:00:00  ACL MTU: 27:7  SCO MTU: 0:0
    UP RUNNING
    RX bytes:1593 acl:0 sco:0 events:88 errors:0
    TX bytes:285 acl:0 sco:0 commands:51 errors:0
Run Code Online (Sandbox Code Playgroud)

hcitool(找不到控制器)

$ hcitool scan
  Scanning ...
  Inquiry failed: Operation not supported
Run Code Online (Sandbox Code Playgroud)

因此,我认为加密狗与 BlueZ 配合良好,作为 Linux 官方蓝牙堆栈,这是一个好兆头,但我认为 Bettercap 也在使用 BlueZ,从这个意义上说,加密狗应该可以工作。

我不认为该加密狗需要安装任何驱动程序,因为当它闪烁(J-Link)时,它会变成一个通用的蓝牙加密狗。

您知道问题出在哪里吗?

Gar*_*ngh 3

我相信错误来自https://github.com/bettercap/gatt/blob/master/linux/cmd/cmd.go#L98

该程序正在尝试向设备写入内容,并期望只要没有发送错误,它就会收到响应。但显然 Send 调用成功但收到空响应。

我建议在那里打开一个问题并提出你的问题。