mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 10:46:57 -07:00
new: ble.enum and ble.write now support autocompletion
This commit is contained in:
parent
742e7fd8bb
commit
49e2116d46
4 changed files with 55 additions and 12 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
golog "log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/modules/utils"
|
||||
|
@ -63,7 +64,7 @@ func NewBLERecon(s *session.Session) *BLERecon {
|
|||
return mod.Show()
|
||||
}))
|
||||
|
||||
mod.AddHandler(session.NewModuleHandler("ble.enum MAC", "ble.enum "+network.BLEMacValidator,
|
||||
enum := session.NewModuleHandler("ble.enum MAC", "ble.enum "+network.BLEMacValidator,
|
||||
"Enumerate services and characteristics for the given BLE device.",
|
||||
func(args []string) error {
|
||||
if mod.isEnumerating() {
|
||||
|
@ -74,9 +75,13 @@ func NewBLERecon(s *session.Session) *BLERecon {
|
|||
mod.writeUUID = nil
|
||||
|
||||
return mod.enumAllTheThings(network.NormalizeMac(args[0]))
|
||||
}))
|
||||
})
|
||||
|
||||
mod.AddHandler(session.NewModuleHandler("ble.write MAC UUID HEX_DATA", "ble.write "+network.BLEMacValidator+" ([a-fA-F0-9]+) ([a-fA-F0-9]+)",
|
||||
enum.Complete("ble.enum", mod.macCompleter)
|
||||
|
||||
mod.AddHandler(enum)
|
||||
|
||||
write := session.NewModuleHandler("ble.write MAC UUID HEX_DATA", "ble.write "+network.BLEMacValidator+" ([a-fA-F0-9]+) ([a-fA-F0-9]+)",
|
||||
"Write the HEX_DATA buffer to the BLE device with the specified MAC address, to the characteristics with the given UUID.",
|
||||
func(args []string) error {
|
||||
mac := network.NormalizeMac(args[0])
|
||||
|
@ -90,7 +95,11 @@ func NewBLERecon(s *session.Session) *BLERecon {
|
|||
}
|
||||
|
||||
return mod.writeBuffer(mac, uuid, data)
|
||||
}))
|
||||
})
|
||||
|
||||
write.Complete("ble.write", mod.macCompleter)
|
||||
|
||||
mod.AddHandler(write)
|
||||
|
||||
return mod
|
||||
}
|
||||
|
@ -107,6 +116,16 @@ func (mod BLERecon) Author() string {
|
|||
return "Simone Margaritelli <evilsocket@gmail.com>"
|
||||
}
|
||||
|
||||
func (mod *BLERecon) macCompleter(prefix string) []string {
|
||||
macs := []string{""}
|
||||
mod.Session.BLE.EachDevice(func(mac string, dev *network.BLEDevice) {
|
||||
if prefix == "" || strings.HasPrefix(mac, prefix) {
|
||||
macs = append(macs, mac)
|
||||
}
|
||||
})
|
||||
return macs
|
||||
}
|
||||
|
||||
func (mod *BLERecon) isEnumerating() bool {
|
||||
return mod.currDevice != nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue