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
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue