fix: fixed a bug in wifi.recon.channel

This commit is contained in:
evilsocket 2019-02-06 13:53:44 +01:00
commit 605361daa2
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"net" "net"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
@ -18,6 +17,7 @@ import (
"github.com/google/gopacket/pcap" "github.com/google/gopacket/pcap"
"github.com/evilsocket/islazy/fs" "github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/str"
"github.com/evilsocket/islazy/tui" "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)`, 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.", "WiFi channels (comma separated) or 'clear' for channel hopping.",
func(args []string) error { func(args []string) (err error) {
newfrequencies := w.frequencies[:0] freqs := []int{}
if len(args) > 0 && args[0] != "clear" { if args[0] != "clear" {
channels := strings.Split(args[0], ",") log.Info("setting hopping channels to %s", args[0])
for _, c := range channels { for _, s := range str.Comma(args[0]) {
trimmed := strings.Trim(c, " ") if ch, err := strconv.Atoi(s); err != nil {
channel, err := strconv.Atoi(trimmed)
if err != nil {
return err
}
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 return err
} else { } else {
newfrequencies = frequencies freqs = append(freqs, network.Dot11Chan2Freq(ch))
}
} }
} }
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 return nil
})) }))