From dd05670e1f55b5dffb70297345df43e186f8a075 Mon Sep 17 00:00:00 2001 From: Nelson Murilo Date: Thu, 13 Mar 2025 14:03:10 -0400 Subject: [PATCH 1/4] Update net_linux.go Code Review --- network/net_linux.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/network/net_linux.go b/network/net_linux.go index f73f6b3f..04fcd123 100644 --- a/network/net_linux.go +++ b/network/net_linux.go @@ -41,7 +41,9 @@ func SetInterfaceChannel(iface string, channel int) error { if core.HasBinary("iw") { // Debug("SetInterfaceChannel(%s, %d) iw based", iface, channel) - out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)}) + // out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)}) + out, err := core.Exec("iw", []string{"dev", iface, "set", "freq", fmt.Sprintf("%d", Dot11Chan2Freq(channel))}) + if err != nil { return fmt.Errorf("iw: out=%s err=%s", out, err) } else if out != "" { @@ -89,7 +91,8 @@ func iwlistSupportedFrequencies(iface string) ([]int, error) { } var iwPhyParser = regexp.MustCompile(`^\s*wiphy\s+(\d+)$`) -var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\s+MHz.+dBm.+$`) +// var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\s+MHz.+dBm.+$`) +var iwFreqParser = regexp.MustCompile(`^\s+\*\s+(\d+)\.\d+\s+MHz.+dBm.+$`) func iwSupportedFrequencies(iface string) ([]int, error) { // first determine phy index @@ -140,10 +143,11 @@ func iwSupportedFrequencies(iface string) ([]int, error) { func GetSupportedFrequencies(iface string) ([]int, error) { // give priority to iwlist because of https://github.com/bettercap/bettercap/issues/881 - if core.HasBinary("iwlist") { - return iwlistSupportedFrequencies(iface) - } else if core.HasBinary("iw") { + // UPDATE: Changed the priority due iwlist doesn't support 6GHz + if core.HasBinary("iw") { return iwSupportedFrequencies(iface) + } else if core.HasBinary("iwlist") { + return iwlistSupportedFrequencies(iface) } return nil, fmt.Errorf("no iw or iwlist binaries found in $PATH") From f9ab25aa8b0d773eb8cfc11d6e656cba06d56a83 Mon Sep 17 00:00:00 2001 From: Nelson Murilo Date: Thu, 13 Mar 2025 15:33:09 -0400 Subject: [PATCH 2/4] Update wifi.go --- network/wifi.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/network/wifi.go b/network/wifi.go index 2ec4b435..4bec1648 100644 --- a/network/wifi.go +++ b/network/wifi.go @@ -25,6 +25,8 @@ func Dot11Freq2Chan(freq int) int { return ((freq - 5035) / 5) + 7 } else if freq >= 5875 && freq <= 5895 { return 177 + } else if freq >= 5955 && freq <= 7115 { + return ((freq - 5955) / 5) + 1 } return 0 } From 6d75d9e8e2680a2689290d23b0037c3d425a4695 Mon Sep 17 00:00:00 2001 From: Nelson Murilo Date: Thu, 13 Mar 2025 16:18:51 -0400 Subject: [PATCH 3/4] Added 6GHz stuff --- network/wifi.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/network/wifi.go b/network/wifi.go index 4bec1648..37eaec2b 100644 --- a/network/wifi.go +++ b/network/wifi.go @@ -25,24 +25,30 @@ func Dot11Freq2Chan(freq int) int { return ((freq - 5035) / 5) + 7 } else if freq >= 5875 && freq <= 5895 { return 177 - } else if freq >= 5955 && freq <= 7115 { + } else if freq >= 5955 && freq <= 7115 { // 6GHz return ((freq - 5955) / 5) + 1 } return 0 } - func Dot11Chan2Freq(channel int) int { - if channel <= 13 { - return ((channel - 1) * 5) + 2412 - } else if channel == 14 { - return 2484 - } else if channel <= 173 { - return ((channel - 7) * 5) + 5035 - } else if channel == 177 { - return 5885 - } - - return 0 + if channel <= 13 { + return ((channel - 1) * 5) + 2412 + } else if channel == 14 { + return 2484 + } else if channel == 36 || channel == 40 || channel == 44 || channel == 48 || + channel == 52 || channel == 56 || channel == 60 || channel == 64 || + channel == 68 || channel == 72 || channel == 60 || channel == 64 || + channel == 100 || channel == 104 || channel == 108 || channel == 112 || + channel == 116 || channel == 120 || channel == 124 || channel == 128 || + channel == 132 || channel == 136 || channel == 140 || channel == 144 || + channel == 149 || channel == 153 || channel == 157 || channel == 161 || + channel == 165 || channel == 169 || channel == 173 || channel == 177 { + return ((channel - 7) * 5) + 5035 +// 6GHz - Skipped 1-13 to avoid 2Ghz channels conflict + } else if channel >= 17 && channel <= 253 { + return ((channel - 1) * 5) + 5955 + } + return 0 } type APNewCallback func(ap *AccessPoint) From 93554a8448f9e31984d00c41b9df0c1e098afcc0 Mon Sep 17 00:00:00 2001 From: Nelson Murilo Date: Thu, 13 Mar 2025 16:19:51 -0400 Subject: [PATCH 4/4] Update wifi.go --- network/wifi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/wifi.go b/network/wifi.go index 37eaec2b..29e374d0 100644 --- a/network/wifi.go +++ b/network/wifi.go @@ -37,7 +37,7 @@ func Dot11Chan2Freq(channel int) int { return 2484 } else if channel == 36 || channel == 40 || channel == 44 || channel == 48 || channel == 52 || channel == 56 || channel == 60 || channel == 64 || - channel == 68 || channel == 72 || channel == 60 || channel == 64 || + channel == 68 || channel == 72 || channel == 76 || channel == 80 || channel == 100 || channel == 104 || channel == 108 || channel == 112 || channel == 116 || channel == 120 || channel == 124 || channel == 128 || channel == 132 || channel == 136 || channel == 140 || channel == 144 ||