登录
首页 >  Golang >  Go问答

在 Ubuntu/Raspberry Pi 操作系统上使用的蓝牙适配器导致 Bettercap 2 的 Go 程序出错

来源:stackoverflow

时间:2024-02-12 18:54:23 144浏览 收藏

IT行业相对于一般传统行业,发展更新速度更快,一旦停止了学习,很快就会被行业所淘汰。所以我们需要踏踏实实的不断学习,精进自己的技术,尤其是初学者。今天golang学习网给大家整理了《在 Ubuntu/Raspberry Pi 操作系统上使用的蓝牙适配器导致 Bettercap 2 的 Go 程序出错》,聊聊,我们一起来看看吧!

问题内容

我在 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/[email protected]/linux/cmd/cmd.go:98 +0x1b4
   github.com/bettercap/gatt/linux.(*hci).resetdevice(0x18ac0a0, 0x93dc10, 0x18ac0a0)
    /home/pi/go/pkg/mod/github.com/bettercap/[email protected]/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/[email protected]/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/[email protected]/device_linux.go:57 +0x114
   github.com/bettercap/bettercap/modules/ble.(*blerecon).configure(0x18a2780, 0x0, 0x4)
    /home/pi/go/pkg/mod/github.com/bettercap/[email protected]+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/[email protected]+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/[email protected]+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/[email protected]+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/[email protected]+incompatible/session/session.go:416 +0x284
   main.main()
    /home/pi/go/pkg/mod/github.com/bettercap/[email protected]+incompatible/main.go:94 +0x8c8

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

只有当我使用 nrf dongle 时才会出现问题,否则它可以与主机的蓝牙和其他 realtek dongle 配合使用。

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

bluetoothctl(有 bd 地址) 扫描有效

$ sudo bluetoothctl
  agent registered
  [bluetooth]# list
  controller eb:xx:xx:xx:xx:xx bluez 5.50 [default]

btmgmt(查找控制器) 扫描有效

$ sudo btmgmt --index 0
   [hci0]# auto-power
   found controller with index 0
   [hci0]# find -l

但是,尽管已弃用,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

hcitool(未找到控制器)

$ hcitool scan
  Scanning ...
  Inquiry failed: Operation not supported

所以,我认为加密狗与 bluez 配合得很好,作为 linux 官方蓝牙堆栈,这是一个好兆头,但我认为 bettercap 也在使用 bluez,从这个意义上说,加密狗应该可以工作。

我认为无需为加密狗安装任何驱动程序,因为当它闪烁(j-link)时,它会变成通用的蓝牙加密狗。

您知道问题出在哪里吗?


正确答案


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

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

我建议打开一个问题 over there 并提出您的问题。

终于介绍完啦!小伙伴们,这篇关于《在 Ubuntu/Raspberry Pi 操作系统上使用的蓝牙适配器导致 Bettercap 2 的 Go 程序出错》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>