mirror of
https://github.com/bettercap/bettercap
synced 2025-07-15 01:23:42 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
63a07cf262
commit
0a8b8548b6
6 changed files with 39 additions and 38 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/log"
|
||||
"github.com/bettercap/bettercap/network"
|
||||
"github.com/bettercap/bettercap/packets"
|
||||
)
|
||||
|
||||
|
@ -62,7 +63,7 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
|
|||
if ap, found := w.Session.WiFi.Get(bssid); found == true {
|
||||
clients := ap.Clients()
|
||||
log.Info("Deauthing %d clients from AP %s ...", len(clients), ap.ESSID())
|
||||
w.onChannel(mhz2chan(ap.Frequency), func() {
|
||||
w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() {
|
||||
for _, c := range clients {
|
||||
if w.Running() == false {
|
||||
break
|
||||
|
@ -81,7 +82,7 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
|
|||
break
|
||||
} else if c, found := ap.Get(bssid); found == true {
|
||||
log.Info("Deauthing client %s from AP %s ...", c.HwAddress, ap.ESSID())
|
||||
w.onChannel(mhz2chan(ap.Frequency), func() {
|
||||
w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() {
|
||||
w.sendDeauthPacket(ap.HW, c.HW)
|
||||
})
|
||||
return nil
|
||||
|
|
|
@ -7,18 +7,6 @@ import (
|
|||
"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
|
||||
|
@ -49,7 +37,7 @@ func (w *WiFiModule) channelHopper() {
|
|||
}
|
||||
|
||||
for _, frequency := range w.frequencies {
|
||||
channel := mhz2chan(frequency)
|
||||
channel := network.Dot11Freq2Chan(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 {
|
||||
|
|
|
@ -76,7 +76,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
|||
return err
|
||||
} else if ap, found := w.Session.WiFi.Get(bssid.String()); found == true {
|
||||
w.ap = ap
|
||||
w.stickChan = mhz2chan(ap.Frequency)
|
||||
w.stickChan = network.Dot11Freq2Chan(ap.Frequency)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Could not find station with BSSID %s", args[0])
|
||||
|
@ -202,29 +202,12 @@ func (w *WiFiModule) Configure() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func isZeroBSSID(bssid net.HardwareAddr) bool {
|
||||
for _, b := range bssid {
|
||||
if b != 0x00 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isBroadcastBSSID(bssid net.HardwareAddr) bool {
|
||||
for _, b := range bssid {
|
||||
if b != 0xff {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *WiFiModule) discoverAccessPoints(radiotap *layers.RadioTap, dot11 *layers.Dot11, packet gopacket.Packet) {
|
||||
// search for Dot11InformationElementIDSSID
|
||||
if ok, ssid := packets.Dot11ParseIDSSID(packet); ok == true {
|
||||
if isZeroBSSID(dot11.Address3) == false && isBroadcastBSSID(dot11.Address3) == false {
|
||||
bssid := dot11.Address3.String()
|
||||
from := dot11.Address3
|
||||
if network.IsZeroMac(from) == false && network.IsBroadcastMac(from) == false {
|
||||
bssid := from.String()
|
||||
frequency := int(radiotap.ChannelFrequency)
|
||||
w.Session.WiFi.AddIfNew(ssid, bssid, frequency, radiotap.DBMAntennaSignal)
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ func (w *WiFiModule) getRow(station *network.Station) []string {
|
|||
fmt.Sprintf("%d dBm", station.RSSI),
|
||||
bssid,
|
||||
/* station.Vendor, */
|
||||
strconv.Itoa(mhz2chan(station.Frequency)),
|
||||
strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
|
||||
sent,
|
||||
recvd,
|
||||
seen,
|
||||
|
@ -88,7 +88,7 @@ func (w *WiFiModule) getRow(station *network.Station) []string {
|
|||
ssid,
|
||||
/* station.Vendor, */
|
||||
encryption,
|
||||
strconv.Itoa(mhz2chan(station.Frequency)),
|
||||
strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
|
||||
clients,
|
||||
sent,
|
||||
recvd,
|
||||
|
|
|
@ -26,6 +26,24 @@ var (
|
|||
IPv4Validator = regexp.MustCompile("^[0-9\\.]+/?\\d*$")
|
||||
)
|
||||
|
||||
func IsZeroMac(mac net.HardwareAddr) bool {
|
||||
for _, b := range mac {
|
||||
if b != 0x00 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsBroadcastMac(mac net.HardwareAddr) bool {
|
||||
for _, b := range mac {
|
||||
if b != 0xff {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func NormalizeMac(mac string) string {
|
||||
var parts []string
|
||||
if strings.ContainsRune(mac, '-') {
|
||||
|
|
|
@ -7,6 +7,17 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func Dot11Freq2Chan(freq int) int {
|
||||
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
|
||||
}
|
||||
|
||||
type APNewCallback func(ap *AccessPoint)
|
||||
type APLostCallback func(ap *AccessPoint)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue