misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-03-12 15:58:45 +01:00
parent 63a07cf262
commit 0a8b8548b6
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
6 changed files with 39 additions and 38 deletions

View file

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/bettercap/bettercap/log" "github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets" "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 { if ap, found := w.Session.WiFi.Get(bssid); found == true {
clients := ap.Clients() clients := ap.Clients()
log.Info("Deauthing %d clients from AP %s ...", len(clients), ap.ESSID()) 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 { for _, c := range clients {
if w.Running() == false { if w.Running() == false {
break break
@ -81,7 +82,7 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error {
break break
} else if c, found := ap.Get(bssid); found == true { } else if c, found := ap.Get(bssid); found == true {
log.Info("Deauthing client %s from AP %s ...", c.HwAddress, ap.ESSID()) 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) w.sendDeauthPacket(ap.HW, c.HW)
}) })
return nil return nil

View file

@ -7,18 +7,6 @@ import (
"github.com/bettercap/bettercap/network" "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()) { func (w *WiFiModule) onChannel(channel int, cb func()) {
prev := w.stickChan prev := w.stickChan
w.stickChan = channel w.stickChan = channel
@ -49,7 +37,7 @@ func (w *WiFiModule) channelHopper() {
} }
for _, frequency := range w.frequencies { for _, frequency := range w.frequencies {
channel := mhz2chan(frequency) channel := network.Dot11Freq2Chan(frequency)
// stick to the access point channel as long as it's selected // stick to the access point channel as long as it's selected
// or as long as we're deauthing on it // or as long as we're deauthing on it
if w.stickChan != 0 { if w.stickChan != 0 {

View file

@ -76,7 +76,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
return err return err
} else if ap, found := w.Session.WiFi.Get(bssid.String()); found == true { } else if ap, found := w.Session.WiFi.Get(bssid.String()); found == true {
w.ap = ap w.ap = ap
w.stickChan = mhz2chan(ap.Frequency) w.stickChan = network.Dot11Freq2Chan(ap.Frequency)
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])
@ -202,29 +202,12 @@ func (w *WiFiModule) Configure() error {
return nil 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) { func (w *WiFiModule) discoverAccessPoints(radiotap *layers.RadioTap, dot11 *layers.Dot11, packet gopacket.Packet) {
// search for Dot11InformationElementIDSSID // search for Dot11InformationElementIDSSID
if ok, ssid := packets.Dot11ParseIDSSID(packet); ok == true { if ok, ssid := packets.Dot11ParseIDSSID(packet); ok == true {
if isZeroBSSID(dot11.Address3) == false && isBroadcastBSSID(dot11.Address3) == false { from := dot11.Address3
bssid := dot11.Address3.String() if network.IsZeroMac(from) == false && network.IsBroadcastMac(from) == false {
bssid := from.String()
frequency := int(radiotap.ChannelFrequency) frequency := int(radiotap.ChannelFrequency)
w.Session.WiFi.AddIfNew(ssid, bssid, frequency, radiotap.DBMAntennaSignal) w.Session.WiFi.AddIfNew(ssid, bssid, frequency, radiotap.DBMAntennaSignal)
} }

View file

@ -66,7 +66,7 @@ func (w *WiFiModule) getRow(station *network.Station) []string {
fmt.Sprintf("%d dBm", station.RSSI), fmt.Sprintf("%d dBm", station.RSSI),
bssid, bssid,
/* station.Vendor, */ /* station.Vendor, */
strconv.Itoa(mhz2chan(station.Frequency)), strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
sent, sent,
recvd, recvd,
seen, seen,
@ -88,7 +88,7 @@ func (w *WiFiModule) getRow(station *network.Station) []string {
ssid, ssid,
/* station.Vendor, */ /* station.Vendor, */
encryption, encryption,
strconv.Itoa(mhz2chan(station.Frequency)), strconv.Itoa(network.Dot11Freq2Chan(station.Frequency)),
clients, clients,
sent, sent,
recvd, recvd,

View file

@ -26,6 +26,24 @@ var (
IPv4Validator = regexp.MustCompile("^[0-9\\.]+/?\\d*$") 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 { func NormalizeMac(mac string) string {
var parts []string var parts []string
if strings.ContainsRune(mac, '-') { if strings.ContainsRune(mac, '-') {

View file

@ -7,6 +7,17 @@ import (
"time" "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 APNewCallback func(ap *AccessPoint)
type APLostCallback func(ap *AccessPoint) type APLostCallback func(ap *AccessPoint)