fix: fixed a race condition while doing wifi channel hopping

This commit is contained in:
evilsocket 2018-08-02 17:03:11 +02:00
commit 7f905f4881
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 8 additions and 1 deletions

View file

@ -36,6 +36,7 @@ type WiFiModule struct {
apConfig packets.Dot11ApConfig apConfig packets.Dot11ApConfig
writes *sync.WaitGroup writes *sync.WaitGroup
reads *sync.WaitGroup reads *sync.WaitGroup
chanLock *sync.Mutex
} }
func NewWiFiModule(s *session.Session) *WiFiModule { func NewWiFiModule(s *session.Session) *WiFiModule {
@ -49,6 +50,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
apRunning: false, apRunning: false,
writes: &sync.WaitGroup{}, writes: &sync.WaitGroup{},
reads: &sync.WaitGroup{}, reads: &sync.WaitGroup{},
chanLock: &sync.Mutex{},
} }
w.AddHandler(session.NewModuleHandler("wifi.recon on", "", w.AddHandler(session.NewModuleHandler("wifi.recon on", "",

View file

@ -8,6 +8,9 @@ import (
) )
func (w *WiFiModule) onChannel(channel int, cb func()) { func (w *WiFiModule) onChannel(channel int, cb func()) {
w.chanLock.Lock()
defer w.chanLock.Unlock()
prev := w.stickChan prev := w.stickChan
w.stickChan = channel w.stickChan = channel
@ -46,11 +49,13 @@ func (w *WiFiModule) channelHopper() {
channel = w.stickChan channel = w.stickChan
} }
log.Debug("Hopping on channel %d", channel) log.Info("Hopping on channel %d", channel)
w.chanLock.Lock()
if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil { if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil {
log.Warning("Error while hopping to channel %d: %s", channel, err) log.Warning("Error while hopping to channel %d: %s", channel, err)
} }
w.chanLock.Unlock()
time.Sleep(delay) time.Sleep(delay)
if !w.Running() { if !w.Running() {