From 4428ac4da7e28ea6b1b10483ec30f5f800054160 Mon Sep 17 00:00:00 2001 From: kayos Date: Wed, 30 Jun 2021 20:40:33 -0700 Subject: [PATCH] Work on command line interface, add arboghast --- cmd.go | 39 ++++++++++++++++++++-------- main.go | 1 + src/arboghast/arboghast.go | 52 ++++++++++++++++++++++++++++++++++++++ src/arboghast/entropy.go | 34 +++++++++++++++++++++++++ src/eros/eros.go | 21 ++++++--------- src/protogen/ble_scan.go | 34 ++++++++++++------------- src/protogen/structs.go | 8 +++--- src/wrath/wrath.go | 3 +-- 8 files changed, 145 insertions(+), 47 deletions(-) create mode 100644 src/arboghast/arboghast.go create mode 100644 src/arboghast/entropy.go diff --git a/cmd.go b/cmd.go index d552124..b4f0569 100644 --- a/cmd.go +++ b/cmd.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog/log" "os" "protomolecule/src/eros" -// "protomolecule/src/wrath" + // "protomolecule/src/wrath" projVars "protomolecule/src/vars" "strings" ) @@ -32,10 +32,17 @@ var suggestions = []cli.Suggest{ {"eros recall all", "Retrieve info on all devices"}, -/* - {"wrath", - "attack by address"}, -*/ + + {"eros backup", + "Backup all databases to the supplied directory"}, + + {"arboghast start", + "Start entropic fuzzing via advertising"}, + + /* + {"wrath", + "attack by address"}, + */ {"exit", "Exit ProtoMolecule"}, @@ -138,7 +145,17 @@ func executor(cmd string) { Int16("Current_RSSI", fromEros.RSSIlast). Int("Service_Count", len(fromEros.Services)). Msg("EROS_RECALL") + + case "backup": + if len(args) < 3 { + getHelp("eros backup") + return + } + if err := eros.Backup(args[3]); err != nil { + log.Error().Err(err).Msg("Failed to backup databases!") + } } + } case "help": @@ -232,12 +249,12 @@ func executor(cmd string) { } /* - case "wrath": - if len(args) < 2 { - getHelp("wrath") - return - } - wrath(args[1]) + case "wrath": + if len(args) < 2 { + getHelp("wrath") + return + } + wrath(args[1]) */ case "clear": diff --git a/main.go b/main.go index 8fd729f..c217c6e 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,7 @@ func cliFlags() { } if *projVars.DFlag { + projVars.Debug = true zerolog.SetGlobalLevel(zerolog.DebugLevel) } diff --git a/src/arboghast/arboghast.go b/src/arboghast/arboghast.go new file mode 100644 index 0000000..fb265ee --- /dev/null +++ b/src/arboghast/arboghast.go @@ -0,0 +1,52 @@ +// arboghast is a package focused on fuzzing BLE devices +package arboghast + +import ( + projVars "protomolecule/src/vars" + bluetooth "git.tcp.direct/kayos/prototooth" + "sync" +) + +type Circus struct { + Trick map[int]*Fuzzy + uuid_pool []bluetooth.UUID + mu *sync.Mutex +} + +type Fuzzy struct { + config *bluetooth.AdvertisementOptions + ad *bluetooth.Advertisement + mu *sync.Mutex +} + +var circus *Circus + +func Awaken() { + circus = &Circus{ + Trick: make(map[int]*Fuzzy), + uuid_pool: []bluetooth.UUID{}, + mu: &sync.Mutex{}, + } +} + +func NewEntropicFuzzer() *Fuzzy { + options := &bluetooth.AdvertisementOptions{ + LocalName: RandomAlpha(16), + + // Interval: + } + mutex := &sync.Mutex{} + + ad := projVars.ScanAdapter.DefaultAdvertisement() + ad.Configure(options) + + return &Fuzzy{ + config: options, + ad: ad, + mu: mutex, + } +} + +func (f *Fuzzy) StartAd() { + f.ad.Start() +} diff --git a/src/arboghast/entropy.go b/src/arboghast/entropy.go new file mode 100644 index 0000000..f61b6c9 --- /dev/null +++ b/src/arboghast/entropy.go @@ -0,0 +1,34 @@ +package arboghast + +import ( + "math/rand" + "time" + "unsafe" +) + +var src = rand.NewSource(time.Now().UnixNano()) + +const ( + letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1<= 0; { + if remain == 0 { + cache, remain = src.Int63(), letterIdxMax + } + if idx := int(cache & letterIdxMask); idx < len(letterBytes) { + b[i] = letterBytes[idx] + i-- + } + cache >>= letterIdxBits + remain-- + } + + return *(*string)(unsafe.Pointer(&b)) +} diff --git a/src/eros/eros.go b/src/eros/eros.go index e4b60f3..93ecda2 100644 --- a/src/eros/eros.go +++ b/src/eros/eros.go @@ -1,5 +1,3 @@ -package eros - // Eros controls the Bitcask db that holds the devices captured during scanning // // Addr (Key) @@ -10,6 +8,7 @@ package eros // TODO: // Output to report // +package eros import ( "bufio" @@ -27,15 +26,11 @@ import ( ) var ( - // devices will hold details about devices discovered - // exploits will hold details about exploits to be used against BLE devices - // services will hold definitions of various bluetook services and will ultimately be updated via an HTTP repository - // manufacturers will hold manufacturer to UUID correlations dbs = []string{ - "devices", - "exploits", - "services", - "manufacturers", + "devices", // details about devices discovered + "exploits", // details about exploits to be used against BLE devices + "services", // definitions of various bluetook services and will ultimately be updated via an HTTP repository + "manufacturers", // manufacturer to UUID correlations and info } err error @@ -239,16 +234,16 @@ func Recall(Addr string) (Device, error) { return member, err } -func Backup(path string) { +func Backup(path string) error { for _, db := range DB { db.Merge() db.Sync() err := db.Backup(path) if err != nil { - panic(err.Error()) + return err } } - + return nil } // Hypnosis - retrieve new exploits/attacks from a remote http repository diff --git a/src/protogen/ble_scan.go b/src/protogen/ble_scan.go index aa217bc..ae026e4 100644 --- a/src/protogen/ble_scan.go +++ b/src/protogen/ble_scan.go @@ -15,23 +15,23 @@ import ( // ScanMgr will keep track of concurrently running scans var ScanMgr *Meta + +// NewScan - here we are creating an "anonymous" instance of a Scan struct +// You'll notice it doesn't contain most of the data that actually is supposed to live within that struct +// +// This works because the integer ID is being used as a key that will have a global scope +// +// See: Remember function as it is defined in eros/eros.go +// Remember usage in this file (scanStuff/scanStuff.go +// +// In these examples we are sending an instance of a struct with some data to eros; allowing it to finish filling out the rest +// This can be done with just structs, but becomes problematic when trying to refer to them later +// +//TODO: implement Mutex locking from sync in most of these structs to prevent concurrent read/write operations from causing a race w̶a̶r̶ condition +// ref: https://gobyexample.com/mutexes +// ref: https://golang.org/pkg/sync/#Mutex +// ref: https://www.geeksforgeeks.org/mutex-in-golang-with-examples/ func (m *Meta) NewScan() *Scan { - // Here we are creating an "anonymous" instance of a Scan struct - // You'll notice it doesn't contain most of the data that actually is supposed to live within that struct - - // This works because the integer ID is being used as a key that will have a global scope - // - // See: Remember function as it is defined in eros/eros.go - // Remember usage in this file (scanStuff/scanStuff.go - // - // In these examples we are sending an instance of a struct with some data to eros; allowing it to finish filling out the rest - // This can be done with just structs, but becomes problematic when trying to refer to them later - // - //TODO: implement Mutex locking from sync in most of these structs to prevent concurrent read/write operations from causing a race w̶a̶r̶ condition - // ref: https://gobyexample.com/mutexes - // ref: https://golang.org/pkg/sync/#Mutex - // ref: https://www.geeksforgeeks.org/mutex-in-golang-with-examples/ - newid := len(m.Scans) m.Scans[newid] = &Scan{ @@ -141,7 +141,7 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc log.Info(). Str("Name", fromEros.Name). Str("Addr", fromEros.Addr). - Str("ManuF", EnumedManuf). //needs to be changed back to fromEros.Manufacturer + Str("ManuF", fromEros.Manufacturer). //needs to be changed back to fromEros.Manufacturer Int16("Current_RSSI", fromEros.RSSIlast). Int("Service_Count", len(fromEros.Services)). Msg("EROS_RECALL") diff --git a/src/protogen/structs.go b/src/protogen/structs.go index b31af47..9f8479a 100644 --- a/src/protogen/structs.go +++ b/src/protogen/structs.go @@ -7,11 +7,11 @@ import ( ) /* - Why the Meta struct? This shit is a fucking maze. -Well in theory we will have multiple types of scans in the future, -if that's the case this is going to become necessary very quickly +Why the Meta struct? + In theory we will have multiple types of scans in the future, + if that's the case this is going to become necessary very quickly -I've mocked up some commented out examples below. + I've mocked up some commented out examples in the source code below. */ type Meta struct { Count int diff --git a/src/wrath/wrath.go b/src/wrath/wrath.go index 5a13cbd..17900c1 100644 --- a/src/wrath/wrath.go +++ b/src/wrath/wrath.go @@ -2,8 +2,8 @@ package wrath import ( bluetooth "git.tcp.direct/kayos/prototooth" - "github.com/rs/zerolog/log" "github.com/rs/zerolog" + "github.com/rs/zerolog/log" projVars "protomolecule/src/vars" "tinygo.org/x/bluetooth/rawterm" ) @@ -157,5 +157,4 @@ func Start() { } } } - }