forked from bettercap/bettercap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: ble.enum and ble.write now support autocompletion
- Loading branch information
1 parent
742e7fd
commit 49e2116
Showing
4 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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])) | ||
})) | ||
}) | ||
|
||
enum.Complete("ble.enum", mod.macCompleter) | ||
|
||
mod.AddHandler(enum) | ||
|
||
mod.AddHandler(session.NewModuleHandler("ble.write MAC UUID HEX_DATA", "ble.write "+network.BLEMacValidator+" ([a-fA-F0-9]+) ([a-fA-F0-9]+)", | ||
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 <[email protected]>" | ||
} | ||
|
||
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters