From 7e1d8ac68f62467736925bbae5abfffb3cc42fb3 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 24 Feb 2019 13:20:41 +0100 Subject: [PATCH] misc: small fix or general refactoring i did not bother commenting --- session/session.go | 111 --------------------------------- session/session_completers.go | 113 ++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 111 deletions(-) create mode 100644 session/session_completers.go diff --git a/session/session.go b/session/session.go index f019838b..65da22be 100644 --- a/session/session.go +++ b/session/session.go @@ -155,117 +155,6 @@ func (s *Session) Unlock() { s.WiFi.Unlock() } -func (s *Session) LANCompleter(prefix string) []string { - macs := []string{""} - s.Lan.EachHost(func(mac string, e *network.Endpoint) { - if prefix == "" || strings.HasPrefix(mac, prefix) { - macs = append(macs, mac) - } - }) - return macs -} - -func (s *Session) WiFiCompleter(prefix string) []string { - macs := []string{""} - s.WiFi.EachAccessPoint(func(mac string, ap *network.AccessPoint) { - if prefix == "" || strings.HasPrefix(mac, prefix) { - macs = append(macs, mac) - } - }) - return macs -} - -func (s *Session) WiFiCompleterFull(prefix string) []string { - macs := []string{""} - s.WiFi.EachAccessPoint(func(mac string, ap *network.AccessPoint) { - if prefix == "" || strings.HasPrefix(mac, prefix) { - macs = append(macs, mac) - } - ap.EachClient(func(mac string, c *network.Station) { - if prefix == "" || strings.HasPrefix(mac, prefix) { - macs = append(macs, mac) - } - }) - }) - return macs -} - -func (s *Session) BLECompleter(prefix string) []string { - macs := []string{""} - s.BLE.EachDevice(func(mac string, dev *network.BLEDevice) { - if prefix == "" || strings.HasPrefix(mac, prefix) { - macs = append(macs, mac) - } - }) - return macs -} - -func (s *Session) HIDCompleter(prefix string) []string { - macs := []string{""} - s.HID.EachDevice(func(mac string, dev *network.HIDDevice) { - if prefix == "" || strings.HasPrefix(mac, prefix) { - macs = append(macs, mac) - } - }) - return macs -} - -func (s *Session) EventsCompleter(prefix string) []string { - events := []string{""} - all := []string{ - "sys.log", - "session.started", - "session.closing", - "update.available", - "mod.started", - "mod.stopped", - "endpoint.new", - "endpoint.lost", - "wifi.client.lost", - "wifi.client.probe", - "wifi.client.new", - "wifi.client.handshake", - "wifi.ap.new", - "wifi.ap.lost", - "ble.device.service.discovered", - "ble.device.characteristic.discovered", - "ble.device.connected", - "ble.device.new", - "ble.device.lost", - "ble.connection.timeout", - "hid.device.new", - "hid.device.lost", - "http.spoofed-request", - "http.spoofed-response", - "https.spoofed-request", - "https.spoofed-response", - "syn.scan", - "net.sniff.mdns", - "net.sniff.mdns", - "net.sniff.dot11", - "net.sniff.tcp", - "net.sniff.upnp", - "net.sniff.ntlm", - "net.sniff.ftp", - "net.sniff.udp", - "net.sniff.krb5", - "net.sniff.dns", - "net.sniff.teamviewer", - "net.sniff.http.request", - "net.sniff.http.response", - "net.sniff.sni", - } - - for _, e := range all { - if prefix == "" || strings.HasPrefix(e, prefix) { - events = append(events, e) - } - - } - - return events -} - func (s *Session) Module(name string) (err error, mod Module) { for _, m := range s.Modules { if m.Name() == name { diff --git a/session/session_completers.go b/session/session_completers.go new file mode 100644 index 00000000..dcf2d0fd --- /dev/null +++ b/session/session_completers.go @@ -0,0 +1,113 @@ +package session + +import ( + "strings" + + "github.com/bettercap/bettercap/network" +) + +func prefixMatches(prefix, what string) bool { + return prefix == "" || strings.HasPrefix(what, prefix) +} + +func addIfMatches(to *[]string, prefix string, what string) { + if prefixMatches(prefix, what) { + *to = append(*to, what) + } +} + +func (s *Session) LANCompleter(prefix string) []string { + macs := []string{""} + s.Lan.EachHost(func(mac string, e *network.Endpoint) { + addIfMatches(&macs, prefix, mac) + }) + return macs +} + +func (s *Session) WiFiCompleter(prefix string) []string { + macs := []string{""} + s.WiFi.EachAccessPoint(func(mac string, ap *network.AccessPoint) { + addIfMatches(&macs, prefix, mac) + }) + return macs +} + +func (s *Session) WiFiCompleterFull(prefix string) []string { + macs := []string{""} + s.WiFi.EachAccessPoint(func(mac string, ap *network.AccessPoint) { + addIfMatches(&macs, prefix, mac) + ap.EachClient(func(mac string, c *network.Station) { + addIfMatches(&macs, prefix, mac) + }) + }) + return macs +} + +func (s *Session) BLECompleter(prefix string) []string { + macs := []string{""} + s.BLE.EachDevice(func(mac string, dev *network.BLEDevice) { + addIfMatches(&macs, prefix, mac) + }) + return macs +} + +func (s *Session) HIDCompleter(prefix string) []string { + macs := []string{""} + s.HID.EachDevice(func(mac string, dev *network.HIDDevice) { + addIfMatches(&macs, prefix, mac) + }) + return macs +} + +func (s *Session) EventsCompleter(prefix string) []string { + events := []string{""} + all := []string{ + "sys.log", + "session.started", + "session.closing", + "update.available", + "mod.started", + "mod.stopped", + "endpoint.new", + "endpoint.lost", + "wifi.client.lost", + "wifi.client.probe", + "wifi.client.new", + "wifi.client.handshake", + "wifi.ap.new", + "wifi.ap.lost", + "ble.device.service.discovered", + "ble.device.characteristic.discovered", + "ble.device.connected", + "ble.device.new", + "ble.device.lost", + "ble.connection.timeout", + "hid.device.new", + "hid.device.lost", + "http.spoofed-request", + "http.spoofed-response", + "https.spoofed-request", + "https.spoofed-response", + "syn.scan", + "net.sniff.mdns", + "net.sniff.mdns", + "net.sniff.dot11", + "net.sniff.tcp", + "net.sniff.upnp", + "net.sniff.ntlm", + "net.sniff.ftp", + "net.sniff.udp", + "net.sniff.krb5", + "net.sniff.dns", + "net.sniff.teamviewer", + "net.sniff.http.request", + "net.sniff.http.response", + "net.sniff.sni", + } + + for _, e := range all { + addIfMatches(&events, prefix, e) + } + + return events +}