| 1 | package session |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | |
| 6 | "github.com/bettercap/bettercap/network" |
| 7 | ) |
| 8 | |
| 9 | func prefixMatches(prefix, what string) bool { |
| 10 | return prefix == "" || strings.HasPrefix(what, prefix) |
| 11 | } |
| 12 | |
| 13 | func addIfMatches(to *[]string, prefix string, what string) { |
| 14 | if prefixMatches(prefix, what) { |
| 15 | *to = append(*to, what) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func (s *Session) LANCompleter(prefix string) []string { |
| 20 | macs := []string{""} |
| 21 | s.Lan.EachHost(func(mac string, e *network.Endpoint) { |
| 22 | addIfMatches(&macs, prefix, mac) |
| 23 | }) |
| 24 | return macs |
| 25 | } |
| 26 | |
| 27 | func (s *Session) WiFiCompleter(prefix string) []string { |
| 28 | macs := []string{""} |
| 29 | s.WiFi.EachAccessPoint(func(mac string, ap *network.AccessPoint) { |
| 30 | addIfMatches(&macs, prefix, mac) |
| 31 | }) |
| 32 | return macs |
| 33 | } |
| 34 | |
| 35 | func (s *Session) WiFiCompleterFull(prefix string) []string { |
| 36 | macs := []string{""} |
| 37 | s.WiFi.EachAccessPoint(func(mac string, ap *network.AccessPoint) { |
| 38 | addIfMatches(&macs, prefix, mac) |
| 39 | ap.EachClient(func(mac string, c *network.Station) { |
| 40 | addIfMatches(&macs, prefix, mac) |
| 41 | }) |
| 42 | }) |
| 43 | return macs |
| 44 | } |
| 45 | |
| 46 | func (s *Session) BLECompleter(prefix string) []string { |
| 47 | macs := []string{""} |
| 48 | s.BLE.EachDevice(func(mac string, dev *network.BLEDevice) { |
| 49 | addIfMatches(&macs, prefix, mac) |
| 50 | }) |
| 51 | return macs |
| 52 | } |
| 53 | |
| 54 | func (s *Session) HIDCompleter(prefix string) []string { |
| 55 | macs := []string{""} |
| 56 | s.HID.EachDevice(func(mac string, dev *network.HIDDevice) { |
| 57 | addIfMatches(&macs, prefix, mac) |
| 58 | }) |
| 59 | return macs |
| 60 | } |
| 61 | |
| 62 | func (s *Session) EventsCompleter(prefix string) []string { |
| 63 | events := []string{""} |
| 64 | all := []string{ |
| 65 | "sys.log", |
| 66 | "session.started", |
| 67 | "session.closing", |
| 68 | "update.available", |
| 69 | "mod.started", |
| 70 | "mod.stopped", |
| 71 | "endpoint.new", |
| 72 | "endpoint.lost", |
| 73 | "wifi.client.lost", |
| 74 | "wifi.client.probe", |
| 75 | "wifi.client.new", |
| 76 | "wifi.client.handshake", |
| 77 | "wifi.ap.new", |
| 78 | "wifi.ap.lost", |
| 79 | "ble.device.service.discovered", |
| 80 | "ble.device.characteristic.discovered", |
| 81 | "ble.device.connected", |
| 82 | "ble.device.new", |
| 83 | "ble.device.lost", |
| 84 | "ble.connection.timeout", |
| 85 | "hid.device.new", |
| 86 | "hid.device.lost", |
| 87 | "http.spoofed-request", |
| 88 | "http.spoofed-response", |
| 89 | "https.spoofed-request", |
| 90 | "https.spoofed-response", |
| 91 | "syn.scan", |
| 92 | "net.sniff.mdns", |
| 93 | "net.sniff.mdns", |
| 94 | "net.sniff.dot11", |
| 95 | "net.sniff.tcp", |
| 96 | "net.sniff.upnp", |
| 97 | "net.sniff.ntlm", |
| 98 | "net.sniff.ftp", |
| 99 | "net.sniff.udp", |
| 100 | "net.sniff.krb5", |
| 101 | "net.sniff.dns", |
| 102 | "net.sniff.teamviewer", |
| 103 | "net.sniff.http.request", |
| 104 | "net.sniff.http.response", |
| 105 | "net.sniff.sni", |
| 106 | } |
| 107 | |
| 108 | for _, e := range all { |
| 109 | addIfMatches(&events, prefix, e) |
| 110 | } |
| 111 | |
| 112 | return events |
| 113 | } |