new: ble.enum and ble.write now support autocompletion

This commit is contained in:
evilsocket 2019-02-18 13:06:41 +01:00
commit 49e2116d46
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
4 changed files with 55 additions and 12 deletions

View file

@ -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
}