From 605361daa289628b7ddb92e6c613300c07cb021e Mon Sep 17 00:00:00 2001 From: evilsocket Date: Wed, 6 Feb 2019 13:53:44 +0100 Subject: [PATCH] fix: fixed a bug in wifi.recon.channel --- modules/wifi.go | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/wifi.go b/modules/wifi.go index b0b533a3..9e4e5a13 100644 --- a/modules/wifi.go +++ b/modules/wifi.go @@ -4,7 +4,6 @@ import ( "fmt" "net" "strconv" - "strings" "sync" "time" @@ -18,6 +17,7 @@ import ( "github.com/google/gopacket/pcap" "github.com/evilsocket/islazy/fs" + "github.com/evilsocket/islazy/str" "github.com/evilsocket/islazy/tui" ) @@ -177,29 +177,28 @@ func NewWiFiModule(s *session.Session) *WiFiModule { w.AddHandler(session.NewModuleHandler("wifi.recon.channel", `wifi\.recon\.channel[\s]+([0-9]+(?:[, ]+[0-9]+)*|clear)`, "WiFi channels (comma separated) or 'clear' for channel hopping.", - func(args []string) error { - newfrequencies := w.frequencies[:0] + func(args []string) (err error) { + freqs := []int{} - if len(args) > 0 && args[0] != "clear" { - channels := strings.Split(args[0], ",") - for _, c := range channels { - trimmed := strings.Trim(c, " ") - channel, err := strconv.Atoi(trimmed) - if err != nil { + if args[0] != "clear" { + log.Info("setting hopping channels to %s", args[0]) + for _, s := range str.Comma(args[0]) { + if ch, err := strconv.Atoi(s); err != nil { return err + } else { + freqs = append(freqs, network.Dot11Chan2Freq(ch)) } - newfrequencies = append(newfrequencies, network.Dot11Chan2Freq(channel)) - } - } else { - // No channels setted, retrieve frequencies supported by the card - if frequencies, err := network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil { - return err - } else { - newfrequencies = frequencies } } - w.frequencies = newfrequencies + if len(freqs) == 0 { + log.Info("resetting hopping channels") + if freqs, err = network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil { + return err + } + } + + w.frequencies = freqs return nil }))