From 7f905f48812d8c26110804c9dbf4fd83f650fe8c Mon Sep 17 00:00:00 2001 From: evilsocket Date: Thu, 2 Aug 2018 17:03:11 +0200 Subject: [PATCH] fix: fixed a race condition while doing wifi channel hopping --- modules/wifi.go | 2 ++ modules/wifi_hopping.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/wifi.go b/modules/wifi.go index 0c7ff512..b1360e13 100644 --- a/modules/wifi.go +++ b/modules/wifi.go @@ -36,6 +36,7 @@ type WiFiModule struct { apConfig packets.Dot11ApConfig writes *sync.WaitGroup reads *sync.WaitGroup + chanLock *sync.Mutex } func NewWiFiModule(s *session.Session) *WiFiModule { @@ -49,6 +50,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule { apRunning: false, writes: &sync.WaitGroup{}, reads: &sync.WaitGroup{}, + chanLock: &sync.Mutex{}, } w.AddHandler(session.NewModuleHandler("wifi.recon on", "", diff --git a/modules/wifi_hopping.go b/modules/wifi_hopping.go index 558b590b..49bec764 100644 --- a/modules/wifi_hopping.go +++ b/modules/wifi_hopping.go @@ -8,6 +8,9 @@ import ( ) func (w *WiFiModule) onChannel(channel int, cb func()) { + w.chanLock.Lock() + defer w.chanLock.Unlock() + prev := w.stickChan w.stickChan = channel @@ -46,11 +49,13 @@ func (w *WiFiModule) channelHopper() { 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 { log.Warning("Error while hopping to channel %d: %s", channel, err) } + w.chanLock.Unlock() time.Sleep(delay) if !w.Running() {