mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
new: added wifi.show clients and encryption sorting
This commit is contained in:
parent
573cb17735
commit
58738b7723
3 changed files with 43 additions and 36 deletions
|
@ -148,7 +148,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
w.selector = ViewSelectorFor(&w.SessionModule, "wifi.show",
|
w.selector = ViewSelectorFor(&w.SessionModule, "wifi.show",
|
||||||
[]string{"rssi", "bssid", "essid", "channel", "encryption", "seen", "sent", "rcvd"}, "rssi")
|
[]string{"rssi", "bssid", "essid", "channel", "encryption", "clients", "seen", "sent", "rcvd"}, "rssi")
|
||||||
|
|
||||||
w.AddHandler(session.NewModuleHandler("wifi.recon.channel", `wifi\.recon\.channel[\s]+([0-9]+(?:[, ]+[0-9]+)*|clear)`,
|
w.AddHandler(session.NewModuleHandler("wifi.recon.channel", `wifi\.recon\.channel[\s]+([0-9]+(?:[, ]+[0-9]+)*|clear)`,
|
||||||
"WiFi channels (comma separated) or 'clear' for channel hopping.",
|
"WiFi channels (comma separated) or 'clear' for channel hopping.",
|
||||||
|
|
|
@ -146,7 +146,6 @@ func (w *WiFiModule) doSelection() (err error, stations []*network.Station) {
|
||||||
}
|
}
|
||||||
stations = filtered
|
stations = filtered
|
||||||
|
|
||||||
// "encryption"}, "rssi"
|
|
||||||
switch w.selector.SortBy {
|
switch w.selector.SortBy {
|
||||||
case "seen":
|
case "seen":
|
||||||
sort.Sort(ByWiFiSeenSorter(stations))
|
sort.Sort(ByWiFiSeenSorter(stations))
|
||||||
|
@ -156,6 +155,10 @@ func (w *WiFiModule) doSelection() (err error, stations []*network.Station) {
|
||||||
sort.Sort(ByBssidSorter(stations))
|
sort.Sort(ByBssidSorter(stations))
|
||||||
case "channel":
|
case "channel":
|
||||||
sort.Sort(ByChannelSorter(stations))
|
sort.Sort(ByChannelSorter(stations))
|
||||||
|
case "clients":
|
||||||
|
sort.Sort(ByClientsSorter(stations))
|
||||||
|
case "encryption":
|
||||||
|
sort.Sort(ByEncryptionSorter(stations))
|
||||||
case "sent":
|
case "sent":
|
||||||
sort.Sort(ByWiFiSentSorter(stations))
|
sort.Sort(ByWiFiSentSorter(stations))
|
||||||
case "rcvd":
|
case "rcvd":
|
||||||
|
|
|
@ -2,7 +2,6 @@ package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bettercap/bettercap/network"
|
"github.com/bettercap/bettercap/network"
|
||||||
"github.com/bettercap/bettercap/packets"
|
|
||||||
"github.com/bettercap/bettercap/session"
|
"github.com/bettercap/bettercap/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,7 +10,10 @@ type ByRSSISorter []*network.Station
|
||||||
func (a ByRSSISorter) Len() int { return len(a) }
|
func (a ByRSSISorter) Len() int { return len(a) }
|
||||||
func (a ByRSSISorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a ByRSSISorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a ByRSSISorter) Less(i, j int) bool {
|
func (a ByRSSISorter) Less(i, j int) bool {
|
||||||
return a[i].RSSI < a[j].RSSI
|
if a[i].RSSI == a[j].RSSI {
|
||||||
|
return a[i].HwAddress < a[j].HwAddress
|
||||||
|
}
|
||||||
|
return a[i].RSSI > a[j].RSSI
|
||||||
}
|
}
|
||||||
|
|
||||||
type ByChannelSorter []*network.Station
|
type ByChannelSorter []*network.Station
|
||||||
|
@ -22,6 +24,17 @@ func (a ByChannelSorter) Less(i, j int) bool {
|
||||||
return a[i].Frequency < a[j].Frequency
|
return a[i].Frequency < a[j].Frequency
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ByEncryptionSorter []*network.Station
|
||||||
|
|
||||||
|
func (a ByEncryptionSorter) Len() int { return len(a) }
|
||||||
|
func (a ByEncryptionSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
func (a ByEncryptionSorter) Less(i, j int) bool {
|
||||||
|
if a[i].Encryption == a[j].Encryption {
|
||||||
|
return a[i].HwAddress < a[j].HwAddress
|
||||||
|
}
|
||||||
|
return a[i].Encryption < a[j].Encryption
|
||||||
|
}
|
||||||
|
|
||||||
type ByBssidSorter []*network.Station
|
type ByBssidSorter []*network.Station
|
||||||
|
|
||||||
func (a ByBssidSorter) Len() int { return len(a) }
|
func (a ByBssidSorter) Len() int { return len(a) }
|
||||||
|
@ -54,22 +67,7 @@ type ByWiFiSentSorter []*network.Station
|
||||||
func (a ByWiFiSentSorter) Len() int { return len(a) }
|
func (a ByWiFiSentSorter) Len() int { return len(a) }
|
||||||
func (a ByWiFiSentSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a ByWiFiSentSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a ByWiFiSentSorter) Less(i, j int) bool {
|
func (a ByWiFiSentSorter) Less(i, j int) bool {
|
||||||
session.I.Queue.Lock()
|
return a[i].Sent < a[j].Sent
|
||||||
defer session.I.Queue.Unlock()
|
|
||||||
|
|
||||||
var found bool = false
|
|
||||||
var aTraffic *packets.Traffic = nil
|
|
||||||
var bTraffic *packets.Traffic = nil
|
|
||||||
|
|
||||||
if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; !found {
|
|
||||||
aTraffic = &packets.Traffic{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found {
|
|
||||||
bTraffic = &packets.Traffic{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bTraffic.Sent > aTraffic.Sent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ByWiFiRcvdSorter []*network.Station
|
type ByWiFiRcvdSorter []*network.Station
|
||||||
|
@ -77,20 +75,26 @@ type ByWiFiRcvdSorter []*network.Station
|
||||||
func (a ByWiFiRcvdSorter) Len() int { return len(a) }
|
func (a ByWiFiRcvdSorter) Len() int { return len(a) }
|
||||||
func (a ByWiFiRcvdSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a ByWiFiRcvdSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a ByWiFiRcvdSorter) Less(i, j int) bool {
|
func (a ByWiFiRcvdSorter) Less(i, j int) bool {
|
||||||
session.I.Queue.Lock()
|
return a[i].Received < a[j].Received
|
||||||
defer session.I.Queue.Unlock()
|
}
|
||||||
|
|
||||||
var found bool = false
|
type ByClientsSorter []*network.Station
|
||||||
var aTraffic *packets.Traffic = nil
|
|
||||||
var bTraffic *packets.Traffic = nil
|
func (a ByClientsSorter) Len() int { return len(a) }
|
||||||
|
func (a ByClientsSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; !found {
|
func (a ByClientsSorter) Less(i, j int) bool {
|
||||||
aTraffic = &packets.Traffic{}
|
left := 0
|
||||||
}
|
right := 0
|
||||||
|
|
||||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found {
|
if ap, found := session.I.WiFi.Get(a[i].HwAddress); found {
|
||||||
bTraffic = &packets.Traffic{}
|
left = ap.NumClients()
|
||||||
}
|
}
|
||||||
|
if ap, found := session.I.WiFi.Get(a[j].HwAddress); found {
|
||||||
return bTraffic.Received > aTraffic.Received
|
right = ap.NumClients()
|
||||||
|
}
|
||||||
|
|
||||||
|
if left == right {
|
||||||
|
return a[i].HwAddress < a[j].HwAddress
|
||||||
|
}
|
||||||
|
return left < right
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue