| 1 | package events_stream |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "github.com/bettercap/bettercap/modules/wifi" |
| 6 | "io" |
| 7 | "strings" |
| 8 | |
| 9 | "github.com/bettercap/bettercap/network" |
| 10 | "github.com/bettercap/bettercap/session" |
| 11 | |
| 12 | "github.com/evilsocket/islazy/tui" |
| 13 | ) |
| 14 | |
| 15 | func (mod *EventsStream) viewWiFiApEvent(output io.Writer, e session.Event) { |
| 16 | ap := e.Data.(*network.AccessPoint) |
| 17 | vend := "" |
| 18 | if ap.Vendor != "" { |
| 19 | vend = fmt.Sprintf(" (%s)", ap.Vendor) |
| 20 | } |
| 21 | rssi := "" |
| 22 | if ap.RSSI != 0 { |
| 23 | rssi = fmt.Sprintf(" (%d dBm)", ap.RSSI) |
| 24 | } |
| 25 | |
| 26 | if e.Tag == "wifi.ap.new" { |
| 27 | fmt.Fprintf(output, "[%s] [%s] wifi access point %s%s detected as %s%s.\n", |
| 28 | e.Time.Format(mod.timeFormat), |
| 29 | tui.Green(e.Tag), |
| 30 | tui.Bold(ap.ESSID()), |
| 31 | tui.Dim(tui.Yellow(rssi)), |
| 32 | tui.Green(ap.BSSID()), |
| 33 | tui.Dim(vend)) |
| 34 | } else if e.Tag == "wifi.ap.lost" { |
| 35 | fmt.Fprintf(output, "[%s] [%s] wifi access point %s (%s) lost.\n", |
| 36 | e.Time.Format(mod.timeFormat), |
| 37 | tui.Green(e.Tag), |
| 38 | tui.Red(ap.ESSID()), |
| 39 | ap.BSSID()) |
| 40 | } else { |
| 41 | fmt.Fprintf(output, "[%s] [%s] %s\n", |
| 42 | e.Time.Format(mod.timeFormat), |
| 43 | tui.Green(e.Tag), |
| 44 | ap.String()) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func (mod *EventsStream) viewWiFiClientProbeEvent(output io.Writer, e session.Event) { |
| 49 | probe := e.Data.(wifi.ProbeEvent) |
| 50 | desc := "" |
| 51 | if probe.FromAlias != "" { |
| 52 | desc = fmt.Sprintf(" (%s)", probe.FromAlias) |
| 53 | } else if probe.FromVendor != "" { |
| 54 | desc = fmt.Sprintf(" (%s)", probe.FromVendor) |
| 55 | } |
| 56 | rssi := "" |
| 57 | if probe.RSSI != 0 { |
| 58 | rssi = fmt.Sprintf(" (%d dBm)", probe.RSSI) |
| 59 | } |
| 60 | |
| 61 | fmt.Fprintf(output, "[%s] [%s] station %s%s is probing for SSID %s%s\n", |
| 62 | e.Time.Format(mod.timeFormat), |
| 63 | tui.Green(e.Tag), |
| 64 | probe.FromAddr, |
| 65 | tui.Dim(desc), |
| 66 | tui.Bold(probe.SSID), |
| 67 | tui.Yellow(rssi)) |
| 68 | } |
| 69 | |
| 70 | func (mod *EventsStream) viewWiFiHandshakeEvent(output io.Writer, e session.Event) { |
| 71 | hand := e.Data.(wifi.HandshakeEvent) |
| 72 | |
| 73 | from := hand.Station |
| 74 | to := hand.AP |
| 75 | what := "handshake" |
| 76 | |
| 77 | if ap, found := mod.Session.WiFi.Get(hand.AP); found { |
| 78 | to = fmt.Sprintf("%s (%s)", tui.Bold(ap.ESSID()), tui.Dim(ap.BSSID())) |
| 79 | what = fmt.Sprintf("%s handshake", ap.Encryption) |
| 80 | } |
| 81 | |
| 82 | if hand.PMKID != nil { |
| 83 | what = "RSN PMKID" |
| 84 | } else if hand.Full { |
| 85 | what += " (full)" |
| 86 | } else if hand.Half { |
| 87 | what += " (half)" |
| 88 | } |
| 89 | |
| 90 | fmt.Fprintf(output, "[%s] [%s] captured %s -> %s %s to %s\n", |
| 91 | e.Time.Format(mod.timeFormat), |
| 92 | tui.Green(e.Tag), |
| 93 | from, |
| 94 | to, |
| 95 | tui.Red(what), |
| 96 | hand.File) |
| 97 | } |
| 98 | |
| 99 | func (mod *EventsStream) viewWiFiClientEvent(output io.Writer, e session.Event) { |
| 100 | ce := e.Data.(wifi.ClientEvent) |
| 101 | |
| 102 | ce.Client.Alias = mod.Session.Lan.GetAlias(ce.Client.BSSID()) |
| 103 | |
| 104 | if e.Tag == "wifi.client.new" { |
| 105 | fmt.Fprintf(output, "[%s] [%s] new station %s detected for %s (%s)\n", |
| 106 | e.Time.Format(mod.timeFormat), |
| 107 | tui.Green(e.Tag), |
| 108 | ce.Client.String(), |
| 109 | tui.Bold(ce.AP.ESSID()), |
| 110 | tui.Dim(ce.AP.BSSID())) |
| 111 | } else if e.Tag == "wifi.client.lost" { |
| 112 | fmt.Fprintf(output, "[%s] [%s] station %s disconnected from %s (%s)\n", |
| 113 | e.Time.Format(mod.timeFormat), |
| 114 | tui.Green(e.Tag), |
| 115 | ce.Client.String(), |
| 116 | tui.Bold(ce.AP.ESSID()), |
| 117 | tui.Dim(ce.AP.BSSID())) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func (mod *EventsStream) viewWiFiDeauthEvent(output io.Writer, e session.Event) { |
| 122 | deauth := e.Data.(wifi.DeauthEvent) |
| 123 | |
| 124 | fmt.Fprintf(output, "[%s] [%s] a1=%s a2=%s a3=%s reason=%s (%d dBm)\n", |
| 125 | e.Time.Format(mod.timeFormat), |
| 126 | tui.Green(e.Tag), |
| 127 | deauth.Address1, |
| 128 | deauth.Address2, |
| 129 | deauth.Address3, |
| 130 | tui.Bold(deauth.Reason), |
| 131 | deauth.RSSI) |
| 132 | } |
| 133 | |
| 134 | func (mod *EventsStream) viewWiFiEvent(output io.Writer, e session.Event) { |
| 135 | if strings.HasPrefix(e.Tag, "wifi.ap.") { |
| 136 | mod.viewWiFiApEvent(output, e) |
| 137 | } else if e.Tag == "wifi.deauthentication" { |
| 138 | mod.viewWiFiDeauthEvent(output, e) |
| 139 | } else if e.Tag == "wifi.client.probe" { |
| 140 | mod.viewWiFiClientProbeEvent(output, e) |
| 141 | } else if e.Tag == "wifi.client.handshake" { |
| 142 | mod.viewWiFiHandshakeEvent(output, e) |
| 143 | } else if e.Tag == "wifi.client.new" || e.Tag == "wifi.client.lost" { |
| 144 | mod.viewWiFiClientEvent(output, e) |
| 145 | } else { |
| 146 | fmt.Fprintf(output, "[%s] [%s] %#v\n", e.Time.Format(mod.timeFormat), tui.Green(e.Tag), e) |
| 147 | } |
| 148 | } |