From a3d6b353fe0f747b6e698e7c5b9214e25c073f77 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Fri, 8 Feb 2019 12:45:04 +0100 Subject: [PATCH] fix: fixed a bug which made the wifi channel hopper react slowly to wifi.recon.channel N commands --- modules/wifi.go | 4 ++++ modules/wifi_hopping.go | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/wifi.go b/modules/wifi.go index 621d64fa..ca3050f3 100644 --- a/modules/wifi.go +++ b/modules/wifi.go @@ -28,6 +28,7 @@ type WiFiModule struct { source string channel int hopPeriod time.Duration + hopChanges chan bool frequencies []int ap *network.AccessPoint stickChan int @@ -55,6 +56,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule { channel: 0, stickChan: 0, hopPeriod: 250 * time.Millisecond, + hopChanges: make(chan bool), ap: nil, skipBroken: true, apRunning: false, @@ -101,6 +103,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule { w.ap = nil w.stickChan = 0 w.frequencies, err = network.GetSupportedFrequencies(w.Session.Interface.Name()) + w.hopChanges <- true return err })) @@ -232,6 +235,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule { } w.frequencies = freqs + w.hopChanges <- true return nil })) diff --git a/modules/wifi_hopping.go b/modules/wifi_hopping.go index 8174c1ac..4ce6ba83 100644 --- a/modules/wifi_hopping.go +++ b/modules/wifi_hopping.go @@ -41,6 +41,8 @@ func (w *WiFiModule) channelHopper() { } frequencies := w.frequencies + + loopCurrentChannels: for _, frequency := range frequencies { channel := network.Dot11Freq2Chan(frequency) // stick to the access point channel as long as it's selected @@ -57,9 +59,14 @@ func (w *WiFiModule) channelHopper() { } w.chanLock.Unlock() - time.Sleep(delay) - if !w.Running() { - return + select { + case _ = <-w.hopChanges: + log.Debug("hop changed") + break loopCurrentChannels + case <-time.After(delay): + if !w.Running() { + return + } } } }