bettercap / gatt Goto Github PK
View Code? Open in Web Editor NEWThis project forked from cksmith/gatt
Gatt is a Go package for building Bluetooth Low Energy peripherals
License: BSD 3-Clause "New" or "Revised" License
This project forked from cksmith/gatt
Gatt is a Go package for building Bluetooth Low Energy peripherals
License: BSD 3-Clause "New" or "Revised" License
I'm not too familiar with this library but I saw this question on SO, which highlight an issue in the function
func (c *Cmd) SendAndCheckResp(cp CmdParam, exp []byte) error {
rsp, err := c.Send(cp)
if err != nil {
return err
}
// Don't care about the response
if len(exp) == 0 {
return nil
}
// Check the if status is one of the expected value
if !bytes.Contains(exp, rsp[0:1]) {
return fmt.Errorf("HCI command: '0x%04x' return 0x%02X, expect: [%X] ", cp.Opcode(), rsp[0], exp)
}
return nil
}
when the rsp is empty, or have capacity zero. The problem seems to be when trying to access the first two elements on rsp on line
if !bytes.Contains(exp, rsp[0:1]) {
....
I think this issue could be avoided just checking if len(rsp) == 0
, and respond appropriately, but again I'm not familiar with the library so a better solution could be suggested by another person. I just thought is worth to report the issue.
A bug in this library breaks the build of bettercap:
LC_ALL=en_US.utf8 go get github.com/bettercap/bettercap
# github.com/bettercap/gatt/linux/socket
go/src/github.com/bettercap/gatt/linux/socket/asm.s:5:10: fatal error: textflag.h: No such file or directory
#include "textflag.h"
^~~~~~~~~~~~
compilation terminated.
╭─ ~/gopath/src/gith….com/bett…rcap/gatt
╰─ go build .
# github.com/bettercap/gatt/xpc
xpc_wrapper_darwin.c:41:9: warning: implicit declaration of function 'Block_copy' is invalid in C99 [-Wimplicit-function-declaration]
xpc_wrapper_darwin.c:41:9: error: invalid block pointer conversion passing 'int' to parameter of type 'xpc_handler_t _Nonnull' (aka 'void (^)(xpc_object_t _Nonnull)')
/usr/include/xpc/connection.h:318:16: note: passing argument to parameter 'handler' here
The library is hanging on macOS High Sierra (latest), after some debugging, this message is correctly sent but no response is received on this channel, probably some of those XPC constants/structures/types changed.
idk ¯\_(ツ)_/¯
OS: Ubuntu 18.04.1 LTS
GO VERSION: go1.11.12 linux/amd64
When I used "go get github.com/bettercap/gatt", it will throw error:
root:/home/root/code/tmp1/ipc#go get github.com/bettercap/gatt
go build github.com/mgutz/logxi/v1: no Go files in
xpc and gioctl are bundled. Distribution packages should depend on other packages rather than on bundled code.
Do you have any plan to un-bundle them?
I always get the error "requested write 42 bytes, 22 available" and I can't find a way to increase the available data size.
Hi,
I use this on Ubuntu 20.04 and Raspberry Pi OS 5.10 but this is not a Linux related issue.
I'm having an issue when I use ble.recon on with a different bluetooth dongle.
When I use it with a dongle using Realtek RTL8761b drivers ( MPOW MPBH456AB ) it works well, but when I use a NordicSemi nrf52840 dongle ( https://www.nordicsemi.com/Products/Development-hardware/nrf52840-dongle ) which is my goal, flashed with Zephyr RTOS' hci_usb sample ( https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/hci_usb ) which is supposed to turn any micro controller using bluetooth into a regular bluetooth dongle that any computer is supposed to recognize as, it throws this error:
>> 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
The problem is only when I'm using the nrf dongle, otherwise it works with the host's bluetooth and the other realtek dongle.
The nrf dongle works with the BlueZ stack, here are the results:
bluetoothctl ( has a BD address ) Scan does work
$ sudo bluetoothctl
Agent registered
[bluetooth]# list
Controller EB:XX:XX:XX:XX:XX BlueZ 5.50 [default]
btmgmt ( finds the controller ) Scan does work
$ sudo btmgmt --index 0
[hci0]# auto-power
Found controller with index 0
[hci0]# find -l
So, I assume the dongle works well with BlueZ, being the Linux official bluetooth stack it's a good sign, but I thought that Bettercap was also using BlueZ and in that sense the dongle should work.
The problem seems to come from https://github.com/bettercap/gatt/blob/master/linux/cmd/cmd.go#L98
Thank you so much for your help !
Running FreeBSD 11.2-RELEASE, and using go.1.11.1 amd64.
After running:
go get -v github.com/bettercap/bettercap
I receive the following error:
github.com/bettercap/bettercap
# github.com/bettercap/gantt
go/src/github.com/bettercap/gantt/central.go:118:11: undefined: central
This is a fresh install of FreeBSD and go.
Any suggestions?
Thanks,
Pete
Getting an invalid memory address or nil pointer dereference error when using ble.enum.
Note: this error happened in previous versions as well.
Please provide:
Bettercap Version: v2.23 (latest release)
OS: Ubuntu 18
Go version: n/a
cmd-line argument: sudo bettercap --debug
caplet: n/a
full debug output:
...
» ble.enum aa:bb:cc:dd:ee:ff
[13:14:19] [sys.log] [dbg] ble.recon [gatt.log] got 1 devices
[13:14:19] [sys.log] [dbg] ble.recon initializing device (id:-1) ...
[13:14:19] [sys.log] [dbg] ble.recon [gatt.log] dev: hci0 up
[13:14:19] [sys.log] [dbg] ble.recon [gatt.log] dev: hci0 reset
[13:14:19] [sys.log] [dbg] ble.recon [gatt.log] dev: hci0 down
[13:14:19] [sys.log] [dbg] ble.recon [gatt.log] dev: hci0 opened
[13:14:19] [sys.log] [dbg] ble.recon [gatt.log] hci.mainLoop started
[13:14:19] [sys.log] [inf] ble.recon connecting to aa:bb:cc:dd:ee:ff ...
[13:14:19] [sys.log] [dbg] ble.recon state changed to PoweredOn
[13:14:19] [sys.log] [dbg] ble.recon current device was not cleaned: &{ **** }
» panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x9d4702]goroutine 3354 [running]:
github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux.(*HCI).handleConnection(0xc0000b4ab0, 0xc000612003, 0x13, 0xffd)
/path/to/go/src/github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux/hci.go:364 +0x232
created by github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux.(*HCI).handleLEMeta
/path/to/go/src/github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux/hci.go:411 +0x206
sudo bettercap --debug
I imagine this will be hard to reproduce as this is not a strange use-case...
Expected behavior: Not a crash
Actual behavior: This crash
Hi,
does anyone know from where we will get the callback or listeners.
goroutine 314289 [running]:
github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt.(*Advertisement).unmarshall.func1(0x0, 0x0, 0x0, 0xc000764016, 0x7, 0x1a, 0x10, 0xc000a9a530, 0xa96687, 0xc000a9a570)
/root/gocode/src/github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/adv.go:1986 +0x14f
github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt.(*Advertisement).unmarshall(0xc0018061a0, 0xc000764014, 0x9, 0x1c, 0x14, 0x30)
/root/gocode/src/github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/adv.go:2021 +0x448
github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt.(*device).Init.func3(0xc000e7c550)
/root/gocode/src/github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/device_linux.go:97 +0x6d
github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux.(*HCI).handleAdvertisement(0xc0008a0120, 0xc000dc2003, 0x15, 0xffd)
/root/gocode/src/github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux/hci.go:299 +0x2e7
created by github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux.(*HCI).handleLEMeta
/root/gocode/src/github.com/bettercap/bettercap/vendor/github.com/bettercap/gatt/linux/hci.go:415 +0x16b
Line 2000 in df6e615
Shouldn't this line be:
copy(serviceData.Data, d[w:])
Seems like copy
is indexing some bytes of the UUID in cases typeServiceData32
(Service Data 32-bit UUID) and typeServiceData128
(Service Data 128-bit UUID).
I am running a custom service for BLE device. While trying to connect my mobile app with GATT server, it throws following log:
ignore l2cap signal:[ 06 00 05 00 13 02 02 00 00 00 ]
No communication is further carried out after this log message appears.
Please, before creating this issue make sure that you read the README, that you are running the latest stable version and that you already searched other issues to see if your problem or request was already reported.
Description of the bug or feature request
Please provide:
bettercap -debug ...
).Expected behavior: What you expected to happen
I expected it to show information on the bluetooth device.
Actual behavior: What actually happened
ble.enum 59:a6:91:88:3e:8e
[18:43:21] [sys.log] [inf] ble.recon connecting to 59:a6:91:88:3e:8e ...
» panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x9bf0c2]
♥ ANY INCOMPLETE REPORT WILL BE CLOSED RIGHT AWAY ♥
panic: runtime error: slice bounds out of range [2:0]
How to reproduce: Run the discoverer.go
example, and have some BLE device nearby that has a 255 byte-long advertisement data, so that
Lines 2008 to 2013 in df6e615
1 + l
to overflow to 0.
I also received this error from the ble.recon
bettercap module.
Fixes: I am not familiar with the bluetooth spec, so I am not sure if such a length is valid. Nor am I sure what device was causing the error.
If this is not standard and should not be allowed, then adding a check and returning an error would solve the problem. Otherwise, l, t := uint(b[0]), b[1]
prevents the overflow.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.