events_view_wifi.go 3.9 KB

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