mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
582e1ae81e
commit
63a07cf262
2 changed files with 69 additions and 61 deletions
69
modules/wifi_hopping.go
Normal file
69
modules/wifi_hopping.go
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
package modules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/bettercap/bettercap/log"
|
||||||
|
"github.com/bettercap/bettercap/network"
|
||||||
|
)
|
||||||
|
|
||||||
|
func mhz2chan(freq int) int {
|
||||||
|
// ambo!
|
||||||
|
if freq <= 2472 {
|
||||||
|
return ((freq - 2412) / 5) + 1
|
||||||
|
} else if freq == 2484 {
|
||||||
|
return 14
|
||||||
|
} else if freq >= 5035 && freq <= 5865 {
|
||||||
|
return ((freq - 5035) / 5) + 7
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WiFiModule) onChannel(channel int, cb func()) {
|
||||||
|
prev := w.stickChan
|
||||||
|
w.stickChan = channel
|
||||||
|
|
||||||
|
if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil {
|
||||||
|
log.Warning("Error while hopping to channel %d: %s", channel, err)
|
||||||
|
} else {
|
||||||
|
log.Debug("Hopped on channel %d", channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
cb()
|
||||||
|
|
||||||
|
w.stickChan = prev
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WiFiModule) channelHopper() {
|
||||||
|
w.reads.Add(1)
|
||||||
|
defer w.reads.Done()
|
||||||
|
|
||||||
|
log.Info("Channel hopper started.")
|
||||||
|
for w.Running() == true {
|
||||||
|
delay := w.hopPeriod
|
||||||
|
// if we have both 2.4 and 5ghz capabilities, we have
|
||||||
|
// more channels, therefore we need to increase the time
|
||||||
|
// we hop on each one otherwise me lose information
|
||||||
|
if len(w.frequencies) > 14 {
|
||||||
|
delay = 500 * time.Millisecond
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, frequency := range w.frequencies {
|
||||||
|
channel := mhz2chan(frequency)
|
||||||
|
// stick to the access point channel as long as it's selected
|
||||||
|
// or as long as we're deauthing on it
|
||||||
|
if w.stickChan != 0 {
|
||||||
|
channel = w.stickChan
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil {
|
||||||
|
log.Warning("Error while hopping to channel %d: %s", channel, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(delay)
|
||||||
|
if w.Running() == false {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -138,18 +138,6 @@ func (w WiFiModule) Author() string {
|
||||||
return "Gianluca Braga <matrix86@protonmail.com> && Simone Margaritelli <evilsocket@protonmail.com>>"
|
return "Gianluca Braga <matrix86@protonmail.com> && Simone Margaritelli <evilsocket@protonmail.com>>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func mhz2chan(freq int) int {
|
|
||||||
// ambo!
|
|
||||||
if freq <= 2472 {
|
|
||||||
return ((freq - 2412) / 5) + 1
|
|
||||||
} else if freq == 2484 {
|
|
||||||
return 14
|
|
||||||
} else if freq >= 5035 && freq <= 5865 {
|
|
||||||
return ((freq - 5035) / 5) + 7
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WiFiModule) Configure() error {
|
func (w *WiFiModule) Configure() error {
|
||||||
var hopPeriod int
|
var hopPeriod int
|
||||||
var err error
|
var err error
|
||||||
|
@ -214,21 +202,6 @@ func (w *WiFiModule) Configure() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFiModule) onChannel(channel int, cb func()) {
|
|
||||||
prev := w.stickChan
|
|
||||||
w.stickChan = channel
|
|
||||||
|
|
||||||
if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil {
|
|
||||||
log.Warning("Error while hopping to channel %d: %s", channel, err)
|
|
||||||
} else {
|
|
||||||
log.Debug("Hopped on channel %d", channel)
|
|
||||||
}
|
|
||||||
|
|
||||||
cb()
|
|
||||||
|
|
||||||
w.stickChan = prev
|
|
||||||
}
|
|
||||||
|
|
||||||
func isZeroBSSID(bssid net.HardwareAddr) bool {
|
func isZeroBSSID(bssid net.HardwareAddr) bool {
|
||||||
for _, b := range bssid {
|
for _, b := range bssid {
|
||||||
if b != 0x00 {
|
if b != 0x00 {
|
||||||
|
@ -331,40 +304,6 @@ func (w *WiFiModule) updateStats(dot11 *layers.Dot11, packet gopacket.Packet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFiModule) channelHopper() {
|
|
||||||
w.reads.Add(1)
|
|
||||||
defer w.reads.Done()
|
|
||||||
|
|
||||||
log.Info("Channel hopper started.")
|
|
||||||
for w.Running() == true {
|
|
||||||
delay := w.hopPeriod
|
|
||||||
// if we have both 2.4 and 5ghz capabilities, we have
|
|
||||||
// more channels, therefore we need to increase the time
|
|
||||||
// we hop on each one otherwise me lose information
|
|
||||||
if len(w.frequencies) > 14 {
|
|
||||||
delay = 500 * time.Millisecond
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, frequency := range w.frequencies {
|
|
||||||
channel := mhz2chan(frequency)
|
|
||||||
// stick to the access point channel as long as it's selected
|
|
||||||
// or as long as we're deauthing on it
|
|
||||||
if w.stickChan != 0 {
|
|
||||||
channel = w.stickChan
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := network.SetInterfaceChannel(w.Session.Interface.Name(), channel); err != nil {
|
|
||||||
log.Warning("Error while hopping to channel %d: %s", channel, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(delay)
|
|
||||||
if w.Running() == false {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WiFiModule) stationPruner() {
|
func (w *WiFiModule) stationPruner() {
|
||||||
w.reads.Add(1)
|
w.reads.Add(1)
|
||||||
defer w.reads.Done()
|
defer w.reads.Done()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue