diff --git a/src/eros/eros.go b/src/eros/eros.go index c92af24..81d32b1 100644 --- a/src/eros/eros.go +++ b/src/eros/eros.go @@ -7,6 +7,10 @@ package eros // Raw Advertisement Packet (Advertisement) // Services UUIDs (Services) +// TODO: +// Output to report +// + import ( "encoding/json" "time" @@ -28,10 +32,11 @@ type Characteristic struct { // Device will hold details about the discoverd device type Device struct { - Name string - MAC string - RSSIlast int16 - RSSIhist map[time.Time]int16 + Name string + MAC string + Manufacturer string + RSSIlast int16 + RSSIhist map[time.Time]int16 // Services - see Service struct Services []Service @@ -56,7 +61,7 @@ var deviceDb *bitcask.Bitcask // attackDb will hold details about exploits to be used against BLE devices var attackDb *bitcask.Bitcask -// serviceDb will hold definitions of various bluetook services and will ultimately be updated via an HTTP repository +// serviceDb will hold definitions of various bluetook services and will ultimately be updated via an HTTP repository var serviceDb *bitcask.Bitcask var err error diff --git a/src/scanStuff/scanStuff.go b/src/scanStuff/scanStuff.go index c8b707f..711e013 100644 --- a/src/scanStuff/scanStuff.go +++ b/src/scanStuff/scanStuff.go @@ -33,6 +33,7 @@ type Meta struct { // BLEScans map[int]*BLEScan // LoraScans map[int]*LoraScan // ZigScans map[int]*ZigScan + // WiFiScans map[int]*WiFiScan } type Scan struct { @@ -74,6 +75,24 @@ func (m *Meta) NewScan() *Scan { return scan } +func (s *Scan) NewDevice(name string, addr string, manuf string, rssi int16) *eros.Device { + newid := len(s.Devices) - 1 + s.Devices[newid] = &eros.Device{ + Name: name, + MAC: addr, + Manufacturer: manuf, + RSSIlast: rssi, + } + + s.Count = len(s.Devices) + return s.Devices[newid] +} + +func ManfCheck(bluetooth.UUID) string { + + return "Place Holder" +} + // resultHandler is called by the bluetooth library upon device discovery to handle the result func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.ScanResult) { projVars.ScanAdapter.SetConnectHandler(func(result bluetooth.Addresser, connected bool) { @@ -85,41 +104,34 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc payload := result.AdvertisementPayload addr := result.Address.String() lname := result.LocalName() + manuf := "ManuF Place Holder" //adbytes := payload.Bytes() uuids := payload.ServiceUUIDOut() rssi := result.RSSI var sublog zerolog.Logger + + //Services level logging + // TODO: + // Fix Loggin output here -- Prob shouldnt output this much info + // for each service discovered + // only each device sublog = log.With().Int("Scan_ID", s.ID). Str("LocalName", lname).Str("MAC", addr). - Int16("RSSI", rssi).Logger() - - - // Skipping duplicate results unless tracking mode enabled (to store RSSI as devices move) - if projVars.TrackingMode == false { - for _, dev := range s.Devices { - if addr == dev.MAC { - return - } - } - } + Str("ManuF", manuf).Int16("RSSI", rssi).Logger() // Upon finding new and valid info we update the time for last activity + s.Activity = time.Now() - dev := s.NewDevice(lname, addr, rssi) + dev := s.NewDevice(lname, addr, manuf, rssi) //AdvServBuf := make([]byte, 255) // Record all the services advertised, append them into the nested struct within Device - sublog.Debug().Msg("DEVICE_DISCOVERED") for _, uuid := range uuids { svc := &eros.Service{ UUID: uuid.String(), } - sublog.Info().Str("Service UUID", svc.UUID). - //Str("Value", string(AdvServBuf[:advServPos])). - Msg("GATT_SERVICE") - dev.Services = append(dev.Services, *svc) sublog.Debug().Str("UUID", svc.UUID).Msg("SERVICE_DISCOVERED") } @@ -142,14 +154,12 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc Msg("EROS_RECALL") } - if !projVars.AttackMode { layToRest(dev) sublog.Debug().Msg("Skipping device connection") return } - //////////////////////////////////////////////////////////////////////// //var PreTargetHandling type @@ -162,39 +172,14 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc sublog.Info().Str("Adapter", "Attempting Connection").Msg("ADAPTER_STATUS") var ( - connectError error conTimeOut time.Duration - tick <-chan time.Time + tick <-chan time.Time + err error ) TargetDevice, connectError := projVars.ScanAdapter.Connect(result.Address, bluetooth.ConnectionParams{}) - conTimeOut = 50 * time.Millisecond - - if tick == nil { - endTime := time.After(conTimeOut) - select { - case <-endTime: - sublog.Warn().Str("Adapter", "Connection Timeout").Msg("ADAPTER_STATUS") - TargetDevice.Disconnect() - endTime = nil - return - default: - if connectError != nil { - sublog.Err(connectError).Msg("CONNECTION_ERROR") - return - } - sublog.Info().Str("Adapter", "Working...").Msg("ADAPTER_STATUS") - } - } - - if !projVars.ConnectedToTarget { - layToRest(dev) - return - } - var targetServices []bluetooth.DeviceService - var err error sublog.Info(). Str("status", "Attempting to Read Target Services"). @@ -212,10 +197,20 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc TargetDevice.Disconnect() endTime = nil default: + if connectError != nil { + sublog.Error().Err(connectError).Msg("CONNECT_ERROR") + layToRest(dev) + return + } sublog.Debug().Str("Status", "Connecting...").Msg("ADAPTER_STATUS") } } + if !projVars.ConnectedToTarget { + layToRest(dev) + return + } + ServBuf := make([]byte, 255) Charbuf := make([]byte, 255) @@ -258,27 +253,7 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc layToRest(dev) - //projVars.ScanAdapter.Connect(result.Address, bluetooth.ConnectionParams{}) - - //TODO: stop scan and call bluestuff func and pass it the local name value *********** - - //scanAdapter.Scan() - //time.Sleep(10 * time.Second) - - //time.Sleep(20 * time.Millisecond) - -} - -func (s *Scan) NewDevice(name string, addr string, rssi int16) *eros.Device { - newid := len(s.Devices) - 1 - s.Devices[newid] = &eros.Device{ - Name: name, - MAC: addr, - RSSIlast: rssi, - } - - s.Count = len(s.Devices) - return s.Devices[newid] + //TODO: stop scan and call bluestuff func and pass it the local name value } func (s *Scan) Start() error {