new: new WPS parsing capabilities and wifi.show.wps command

This commit is contained in:
evilsocket 2019-01-27 14:52:59 +01:00
commit 50bf22af9c
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
4 changed files with 224 additions and 23 deletions

View file

@ -141,6 +141,12 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
"true",
"If true, the fake access point will use WPA2, otherwise it'll result as an open AP."))
w.AddHandler(session.NewModuleHandler("wifi.show.wps BSSID", "wifi.show.wps ((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))",
"Show WPS information about a given station.",
func(args []string) error {
return w.ShowWPS(args[0])
}))
w.AddHandler(session.NewModuleHandler("wifi.show", "",
"Show current wireless stations list (default sorting by essid).",
func(args []string) error {
@ -266,6 +272,23 @@ func (w *WiFiModule) Configure() error {
return nil
}
func (w *WiFiModule) updateInfo(dot11 *layers.Dot11, packet gopacket.Packet) {
if ok, enc, cipher, auth := packets.Dot11ParseEncryption(packet, dot11); ok {
bssid := dot11.Address3.String()
if station, found := w.Session.WiFi.Get(bssid); found {
station.Encryption = enc
station.Cipher = cipher
station.Authentication = auth
}
}
if ok, bssid, info := packets.Dot11ParseWPS(packet, dot11); ok {
if station, found := w.Session.WiFi.Get(bssid.String()); found {
station.WPS = info
}
}
}
func (w *WiFiModule) updateStats(dot11 *layers.Dot11, packet gopacket.Packet) {
// collect stats from data frames
if dot11.Type.MainType() == layers.Dot11TypeData {
@ -281,15 +304,6 @@ func (w *WiFiModule) updateStats(dot11 *layers.Dot11, packet gopacket.Packet) {
station.Sent += bytes
}
}
if ok, enc, cipher, auth := packets.Dot11ParseEncryption(packet, dot11); ok {
bssid := dot11.Address3.String()
if station, found := w.Session.WiFi.Get(bssid); found {
station.Encryption = enc
station.Cipher = cipher
station.Authentication = auth
}
}
}
func (w *WiFiModule) Start() error {
@ -331,6 +345,7 @@ func (w *WiFiModule) Start() error {
w.discoverProbes(radiotap, dot11, packet)
w.discoverAccessPoints(radiotap, dot11, packet)
w.discoverClients(radiotap, dot11, packet)
w.updateInfo(dot11, packet)
w.updateStats(dot11, packet)
}
}

View file

@ -78,7 +78,6 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
return []string{
fmt.Sprintf("%d dBm", station.RSSI),
bssid,
/* station.Vendor, */
strconv.Itoa(station.Channel()),
sent,
recvd,
@ -95,12 +94,29 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
}
}
wps := ""
if station.HasWPS() {
if ver, found := station.WPS["Version"]; found {
wps = ver
} else {
wps = "✔"
}
if state, found := station.WPS["State"]; found {
if state == "Not Configured" {
wps += " (not configured)"
}
}
wps = tui.Dim(tui.Yellow(wps))
}
return []string{
fmt.Sprintf("%d dBm", station.RSSI),
bssid,
ssid,
/* station.Vendor, */
encryption,
wps,
strconv.Itoa(station.Channel()),
clients,
sent,
@ -199,13 +215,17 @@ func (w *WiFiModule) colDecorate(colNames []string, name string, dir string) {
}
}
func (w *WiFiModule) colNames(nrows int) []string {
func (w *WiFiModule) colNames(nrows int, withWPS bool) []string {
columns := []string(nil)
if !w.isApSelected() {
columns = []string{"RSSI", "BSSID", "SSID", "Encryption", "Channel", "Clients", "Sent", "Recvd", "Last Seen"}
if withWPS {
columns = []string{"RSSI", "BSSID", "SSID", "Encryption", "WPS", "Ch", "Clients", "Sent", "Recvd", "Last Seen"}
} else {
columns = []string{"RSSI", "BSSID", "SSID", "Encryption", "Ch", "Clients", "Sent", "Recvd", "Last Seen"}
}
} else if nrows > 0 {
columns = []string{"RSSI", "MAC", "Channel", "Sent", "Received", "Last Seen"}
columns = []string{"RSSI", "MAC", "Ch", "Sent", "Received", "Last Seen"}
fmt.Printf("\n%s clients:\n", w.ap.HwAddress)
} else {
fmt.Printf("\nNo authenticated clients detected for %s.\n", w.ap.HwAddress)
@ -220,7 +240,7 @@ func (w *WiFiModule) colNames(nrows int) []string {
case "bssid":
w.colDecorate(columns, "BSSID", w.selector.SortSymbol)
case "channel":
w.colDecorate(columns, "Channel", w.selector.SortSymbol)
w.colDecorate(columns, "Ch", w.selector.SortSymbol)
case "clients":
w.colDecorate(columns, "Clients", w.selector.SortSymbol)
case "encryption":
@ -243,15 +263,19 @@ func (w *WiFiModule) Show() (err error) {
return
}
hasWPS := false
rows := make([][]string, 0)
for _, s := range stations {
if row, include := w.getRow(s); include {
if len(s.WPS) > 0 {
hasWPS = true
}
rows = append(rows, row)
}
}
nrows := len(rows)
if nrows > 0 {
tui.Table(os.Stdout, w.colNames(nrows), rows)
tui.Table(os.Stdout, w.colNames(nrows, hasWPS), rows)
}
w.Session.Queue.Stats.RLock()
@ -270,3 +294,42 @@ func (w *WiFiModule) Show() (err error) {
return nil
}
func (w *WiFiModule) ShowWPS(bssid string) (err error) {
toShow := []*network.AccessPoint{}
if bssid == network.BroadcastMac {
for _, station := range w.Session.WiFi.List() {
if station.HasWPS() {
toShow = append(toShow, station)
}
}
} else {
if station, found := w.Session.WiFi.Get(bssid); found {
if station.HasWPS() {
toShow = append(toShow, station)
}
}
}
if len(toShow) == 0 {
return fmt.Errorf("no WPS enabled access points matched the criteria")
}
for _, station := range toShow {
ssid := station.ESSID()
if ssid == "<hidden>" {
ssid = tui.Dim(ssid)
}
fmt.Println()
fmt.Printf("* %s (%s ch:%d):\n", tui.Bold(ssid), tui.Dim(station.BSSID()), station.Channel())
for name, value := range station.WPS {
fmt.Printf(" %s: %s\n", name, tui.Yellow(value))
}
}
fmt.Println()
return nil
}