mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
refact: refactored wifi.deauth logic code
This commit is contained in:
parent
4d8270fe82
commit
0f5beb72dd
1 changed files with 19 additions and 49 deletions
|
@ -1,6 +1,7 @@
|
||||||
package modules
|
package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -52,59 +53,28 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
|
||||||
w.writes.Add(1)
|
w.writes.Add(1)
|
||||||
defer w.writes.Done()
|
defer w.writes.Done()
|
||||||
|
|
||||||
// deauth all the things!
|
isBcast := network.IsBroadcastMac(to)
|
||||||
if network.IsBroadcastMac(to) {
|
found := isBcast
|
||||||
aps := w.Session.WiFi.List()
|
for _, ap := range w.Session.WiFi.List() {
|
||||||
for _, ap := range aps {
|
for _, client := range ap.Clients() {
|
||||||
clients := ap.Clients()
|
doDeauth := isBcast ||
|
||||||
if numClients := len(clients); numClients > 0 {
|
bytes.Equal(ap.HW, to) ||
|
||||||
w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() {
|
bytes.Equal(client.HW, to)
|
||||||
for _, c := range clients {
|
|
||||||
if !w.Running() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
log.Info("Broadcast deauth client %s from AP %s ...", c.String(), ap.ESSID())
|
|
||||||
w.sendDeauthPacket(ap.HW, c.HW)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
if doDeauth {
|
||||||
}
|
found = true
|
||||||
|
if w.Running() {
|
||||||
return nil
|
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)
|
||||||
bssid := to.String()
|
})
|
||||||
|
|
||||||
// are we deauthing every client of a given access point?
|
|
||||||
if ap, found := w.Session.WiFi.Get(bssid); found {
|
|
||||||
clients := ap.Clients()
|
|
||||||
log.Info("Deauthing %d clients from AP %s ...", len(clients), ap.ESSID())
|
|
||||||
w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() {
|
|
||||||
for _, c := range clients {
|
|
||||||
if !w.Running() {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
w.sendDeauthPacket(ap.HW, c.HW)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// search for a client
|
|
||||||
aps := w.Session.WiFi.List()
|
|
||||||
for _, ap := range aps {
|
|
||||||
if !w.Running() {
|
|
||||||
break
|
|
||||||
} else if c, found := ap.Get(bssid); found {
|
|
||||||
log.Info("Deauthing client %s from AP %s ...", c.HwAddress, ap.ESSID())
|
|
||||||
w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() {
|
|
||||||
w.sendDeauthPacket(ap.HW, c.HW)
|
|
||||||
})
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("%s is an unknown BSSID.", bssid)
|
if found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%s is an unknown BSSID.", to.String())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue