mirror of
https://github.com/bettercap/bettercap
synced 2025-08-13 18:26:57 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
1f39e200a1
commit
626c274e5d
1 changed files with 40 additions and 19 deletions
|
@ -143,7 +143,7 @@ func (w *WiFiRecon) getRow(station *WiFiStation) []string {
|
||||||
traffic = humanize.Bytes(bytes)
|
traffic = humanize.Bytes(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{
|
row := []string{
|
||||||
bssid,
|
bssid,
|
||||||
station.ESSID(),
|
station.ESSID(),
|
||||||
station.Vendor,
|
station.Vendor,
|
||||||
|
@ -151,6 +151,17 @@ func (w *WiFiRecon) getRow(station *WiFiStation) []string {
|
||||||
traffic,
|
traffic,
|
||||||
seen,
|
seen,
|
||||||
}
|
}
|
||||||
|
if w.isApSelected() {
|
||||||
|
row = []string{
|
||||||
|
bssid,
|
||||||
|
station.Vendor,
|
||||||
|
strconv.Itoa(station.Channel),
|
||||||
|
traffic,
|
||||||
|
seen,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
func mhz2chan(freq int) int {
|
func mhz2chan(freq int) int {
|
||||||
|
@ -189,6 +200,14 @@ func (w *WiFiRecon) showTable(header []string, rows [][]string) {
|
||||||
table.Render()
|
table.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WiFiRecon) isApSelected() bool {
|
||||||
|
return len(w.accessPoint) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WiFiRecon) isClientSelected() bool {
|
||||||
|
return len(w.client) > 0
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WiFiRecon) Show(by string) error {
|
func (w *WiFiRecon) Show(by string) error {
|
||||||
if w.wifi == nil {
|
if w.wifi == nil {
|
||||||
return errors.New("WiFi is not yet initialized.")
|
return errors.New("WiFi is not yet initialized.")
|
||||||
|
@ -206,7 +225,14 @@ func (w *WiFiRecon) Show(by string) error {
|
||||||
rows = append(rows, w.getRow(s))
|
rows = append(rows, w.getRow(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
w.showTable([]string{"BSSID", "SSID", "Vendor", "Channel", "Traffic", "Last Seen"}, rows)
|
columns := []string{"BSSID", "SSID", "Vendor", "Channel", "Traffic", "Last Seen"}
|
||||||
|
if w.isApSelected() {
|
||||||
|
// these are clients
|
||||||
|
columns = []string{"MAC", "Vendor", "Channel", "Traffic", "Last Seen"}
|
||||||
|
fmt.Printf("\n%s clients:\n", w.accessPoint.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
w.showTable(columns, rows)
|
||||||
|
|
||||||
w.Session.Refresh()
|
w.Session.Refresh()
|
||||||
|
|
||||||
|
@ -260,10 +286,8 @@ func (w *WiFiRecon) sendDeauthPacket(ap net.HardwareAddr, client net.HardwareAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFiRecon) startDeauth() error {
|
func (w *WiFiRecon) startDeauth() error {
|
||||||
isTargetingAP := len(w.accessPoint) > 0
|
if w.isApSelected() {
|
||||||
if isTargetingAP {
|
if w.isClientSelected() {
|
||||||
isTargetingCLI := len(w.client) > 0
|
|
||||||
if isTargetingCLI {
|
|
||||||
// deauth a specific client
|
// deauth a specific client
|
||||||
w.sendDeauthPacket(w.accessPoint, w.client)
|
w.sendDeauthPacket(w.accessPoint, w.client)
|
||||||
} else {
|
} else {
|
||||||
|
@ -300,22 +324,19 @@ func (w *WiFiRecon) discoverAccessPoints(radiotapLayer gopacket.Layer, dot11 *la
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFiRecon) discoverClients(radiotapLayer gopacket.Layer, dot11 *layers.Dot11, bs net.HardwareAddr, packet gopacket.Packet) {
|
func (w *WiFiRecon) discoverClients(radiotapLayer gopacket.Layer, dot11 *layers.Dot11, ap net.HardwareAddr, packet gopacket.Packet) {
|
||||||
|
// only check data packets of connected stations
|
||||||
if dot11.Type.MainType() != layers.Dot11TypeData {
|
if dot11.Type.MainType() != layers.Dot11TypeData {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
toDS := dot11.Flags.ToDS()
|
src := dot11.Address2
|
||||||
fromDS := dot11.Flags.FromDS()
|
bssid := dot11.Address1
|
||||||
if toDS && !fromDS {
|
// packet going to this specific BSSID?
|
||||||
src := dot11.Address2
|
if bytes.Compare(bssid, ap) == 0 {
|
||||||
bssid := dot11.Address1
|
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
||||||
// packet going to this specific BSSID?
|
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
||||||
if bytes.Compare(bssid, bs) == 0 {
|
w.wifi.AddIfNew("", src.String(), false, channel)
|
||||||
radiotap, _ := radiotapLayer.(*layers.RadioTap)
|
|
||||||
channel := mhz2chan(int(radiotap.ChannelFrequency))
|
|
||||||
w.wifi.AddIfNew("", src.String(), false, channel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +384,7 @@ func (w *WiFiRecon) Start() error {
|
||||||
|
|
||||||
w.updateStats(dot11, packet)
|
w.updateStats(dot11, packet)
|
||||||
|
|
||||||
if len(w.accessPoint) == 0 {
|
if w.isApSelected() == false {
|
||||||
// no access point bssid selected, keep scanning for other aps
|
// no access point bssid selected, keep scanning for other aps
|
||||||
w.discoverAccessPoints(radiotapLayer, dot11, packet)
|
w.discoverAccessPoints(radiotapLayer, dot11, packet)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue