Skip to content

Commit

Permalink
misc: small fix or general refactoring i did not bother commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Feb 24, 2019
1 parent 7e4cfbe commit 7e1d8ac
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 111 deletions.
111 changes: 0 additions & 111 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
113 changes: 113 additions & 0 deletions session/session_completers.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7e1d8ac

Please sign in to comment.