mirror of
https://github.com/bettercap/bettercap
synced 2025-07-15 01:23:42 -07:00
misc: wifi.deauth has been optimized by sorting frames to send by channel in order to minimize the amount of channel hops
This commit is contained in:
parent
148122e8fa
commit
49beed239f
4 changed files with 39 additions and 14 deletions
|
@ -73,7 +73,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
|||
return err
|
||||
} else if ap, found := w.Session.WiFi.Get(bssid.String()); found {
|
||||
w.ap = ap
|
||||
w.stickChan = network.Dot11Freq2Chan(ap.Frequency)
|
||||
w.stickChan = ap.Channel()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Could not find station with BSSID %s", args[0])
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/log"
|
||||
|
@ -53,25 +54,45 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
|
|||
w.writes.Add(1)
|
||||
defer w.writes.Done()
|
||||
|
||||
type flow struct {
|
||||
Ap *network.AccessPoint
|
||||
Client *network.Station
|
||||
}
|
||||
|
||||
toDeauth := make([]flow, 0)
|
||||
isBcast := network.IsBroadcastMac(to)
|
||||
found := isBcast
|
||||
for _, ap := range w.Session.WiFi.List() {
|
||||
isAP := bytes.Equal(ap.HW, to)
|
||||
for _, client := range ap.Clients() {
|
||||
if isBcast || isAP || bytes.Equal(client.HW, to) {
|
||||
found = true
|
||||
if w.Running() {
|
||||
log.Info("Deauthing client %s from AP %s ...", client.String(), ap.ESSID())
|
||||
w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() {
|
||||
w.sendDeauthPacket(ap.HW, client.HW)
|
||||
})
|
||||
}
|
||||
toDeauth = append(toDeauth, flow{Ap: ap, Client: client})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
return nil
|
||||
if len(toDeauth) == 0 {
|
||||
return fmt.Errorf("%s is an unknown BSSID.", to.String())
|
||||
|
||||
}
|
||||
return fmt.Errorf("%s is an unknown BSSID.", to.String())
|
||||
|
||||
// since we need to change the wifi adapter channel for each
|
||||
// deauth packet, let's sort by channel so we do the minimum
|
||||
// amount of hops possible
|
||||
sort.Slice(toDeauth, func(i, j int) bool {
|
||||
return toDeauth[i].Ap.Channel() < toDeauth[j].Ap.Channel()
|
||||
})
|
||||
|
||||
// send the deauth frames
|
||||
for _, deauth := range toDeauth {
|
||||
client := deauth.Client
|
||||
ap := deauth.Ap
|
||||
if w.Running() {
|
||||
log.Info("deauthing client %s from AP %s (channel %d)", client.String(), ap.ESSID(), ap.Channel())
|
||||
w.onChannel(ap.Channel(), func() {
|
||||
w.sendDeauthPacket(ap.HW, client.HW)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
|
|||
fmt.Sprintf("%d dBm", station.RSSI),
|
||||
bssid,
|
||||
/* station.Vendor, */
|
||||
strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
|
||||
strconv.Itoa(station.Channel()),
|
||||
sent,
|
||||
recvd,
|
||||
seen,
|
||||
|
@ -100,7 +100,7 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
|
|||
ssid,
|
||||
/* station.Vendor, */
|
||||
encryption,
|
||||
strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
|
||||
strconv.Itoa(station.Channel()),
|
||||
clients,
|
||||
sent,
|
||||
recvd,
|
||||
|
|
|
@ -43,3 +43,7 @@ func (s Station) BSSID() string {
|
|||
func (s *Station) ESSID() string {
|
||||
return s.Hostname
|
||||
}
|
||||
|
||||
func (s *Station) Channel() int {
|
||||
return Dot11Freq2Chan(s.Frequency)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue