From 0a8b8548b6feab701acdfe77d2d38665ad3da09f Mon Sep 17 00:00:00 2001 From: evilsocket Date: Mon, 12 Mar 2018 15:58:45 +0100 Subject: [PATCH] misc: small fix or general refactoring i did not bother commenting --- modules/wifi_deauth.go | 5 +++-- modules/wifi_hopping.go | 14 +------------- modules/wifi_recon.go | 25 ++++--------------------- modules/wifi_show.go | 4 ++-- network/net.go | 18 ++++++++++++++++++ network/wifi.go | 11 +++++++++++ 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/modules/wifi_deauth.go b/modules/wifi_deauth.go index 90cf8cc9..8ecb17c0 100644 --- a/modules/wifi_deauth.go +++ b/modules/wifi_deauth.go @@ -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 diff --git a/modules/wifi_hopping.go b/modules/wifi_hopping.go index 79d9b454..aa742d8c 100644 --- a/modules/wifi_hopping.go +++ b/modules/wifi_hopping.go @@ -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 { diff --git a/modules/wifi_recon.go b/modules/wifi_recon.go index 6f2839b4..8e32c073 100644 --- a/modules/wifi_recon.go +++ b/modules/wifi_recon.go @@ -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) } diff --git a/modules/wifi_show.go b/modules/wifi_show.go index f84ed639..3272b75c 100644 --- a/modules/wifi_show.go +++ b/modules/wifi_show.go @@ -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, diff --git a/network/net.go b/network/net.go index 1c463aec..bc85ec82 100644 --- a/network/net.go +++ b/network/net.go @@ -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, '-') { diff --git a/network/wifi.go b/network/wifi.go index c7ba2481..d3b22314 100644 --- a/network/wifi.go +++ b/network/wifi.go @@ -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)