mirror of
https://github.com/bettercap/bettercap
synced 2025-07-15 09:33:40 -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
|
return err
|
||||||
} else if ap, found := w.Session.WiFi.Get(bssid.String()); found {
|
} else if ap, found := w.Session.WiFi.Get(bssid.String()); found {
|
||||||
w.ap = ap
|
w.ap = ap
|
||||||
w.stickChan = network.Dot11Freq2Chan(ap.Frequency)
|
w.stickChan = ap.Channel()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Could not find station with BSSID %s", args[0])
|
return fmt.Errorf("Could not find station with BSSID %s", args[0])
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/log"
|
"github.com/bettercap/bettercap/log"
|
||||||
|
@ -53,25 +54,45 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
|
||||||
w.writes.Add(1)
|
w.writes.Add(1)
|
||||||
defer w.writes.Done()
|
defer w.writes.Done()
|
||||||
|
|
||||||
|
type flow struct {
|
||||||
|
Ap *network.AccessPoint
|
||||||
|
Client *network.Station
|
||||||
|
}
|
||||||
|
|
||||||
|
toDeauth := make([]flow, 0)
|
||||||
isBcast := network.IsBroadcastMac(to)
|
isBcast := network.IsBroadcastMac(to)
|
||||||
found := isBcast
|
|
||||||
for _, ap := range w.Session.WiFi.List() {
|
for _, ap := range w.Session.WiFi.List() {
|
||||||
isAP := bytes.Equal(ap.HW, to)
|
isAP := bytes.Equal(ap.HW, to)
|
||||||
for _, client := range ap.Clients() {
|
for _, client := range ap.Clients() {
|
||||||
if isBcast || isAP || bytes.Equal(client.HW, to) {
|
if isBcast || isAP || bytes.Equal(client.HW, to) {
|
||||||
found = true
|
toDeauth = append(toDeauth, flow{Ap: ap, Client: client})
|
||||||
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)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if found {
|
if len(toDeauth) == 0 {
|
||||||
|
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
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s is an unknown BSSID.", to.String())
|
|
||||||
}
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
|
||||||
fmt.Sprintf("%d dBm", station.RSSI),
|
fmt.Sprintf("%d dBm", station.RSSI),
|
||||||
bssid,
|
bssid,
|
||||||
/* station.Vendor, */
|
/* station.Vendor, */
|
||||||
strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
|
strconv.Itoa(station.Channel()),
|
||||||
sent,
|
sent,
|
||||||
recvd,
|
recvd,
|
||||||
seen,
|
seen,
|
||||||
|
@ -100,7 +100,7 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
|
||||||
ssid,
|
ssid,
|
||||||
/* station.Vendor, */
|
/* station.Vendor, */
|
||||||
encryption,
|
encryption,
|
||||||
strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
|
strconv.Itoa(station.Channel()),
|
||||||
clients,
|
clients,
|
||||||
sent,
|
sent,
|
||||||
recvd,
|
recvd,
|
||||||
|
|
|
@ -43,3 +43,7 @@ func (s Station) BSSID() string {
|
||||||
func (s *Station) ESSID() string {
|
func (s *Station) ESSID() string {
|
||||||
return s.Hostname
|
return s.Hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Station) Channel() int {
|
||||||
|
return Dot11Freq2Chan(s.Frequency)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue