| 1 | package networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/" |
| 5 | "syncscip-go gomod github.com/golang/go/src go1.16 sync/" |
| 6 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 7 | |
| 8 | "github.com/evilsocket/islazy/datascip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/data`/" |
| 9 | ) |
| 10 | |
| 11 | type AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint# struct { |
| 12 | *Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#Station. |
| 13 | syncscip-go gomod github.com/golang/go/src go1.16 sync/.RWMutexscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#RWMutex. |
| 14 | |
| 15 | aliasesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#aliases. *datascip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/data`/.UnsortedKVscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/data`/UnsortedKV# |
| 16 | clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients. map[string]*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station# |
| 17 | withKeyMaterialscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#withKeyMaterial. bool |
| 18 | } |
| 19 | |
| 20 | type apJSONscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON# struct { |
| 21 | *Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Station. |
| 22 | Clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Clients. []*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station# `json:"clients"` |
| 23 | Handshakescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Handshake. bool `json:"handshake"` |
| 24 | } |
| 25 | |
| 26 | func NewAccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NewAccessPoint().(essid, bssid string, frequency int, rssi int8, aliases *datascip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/data`/.UnsortedKVscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/data`/UnsortedKV#) *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint# { |
| 27 | return &AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#{ |
| 28 | Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#Station.: NewStationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NewStation().(essid, bssid, frequency, rssi), |
| 29 | aliasesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#aliases.: aliases, |
| 30 | clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients.: make(map[string]*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) MarshalJSONscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#MarshalJSON().() ([]byte, error) { |
| 35 | ap.RLockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RLock().() |
| 36 | defer ap.RUnlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RUnlock().() |
| 37 | |
| 38 | doc := apJSONscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#{ |
| 39 | Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Station.: ap.Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#Station., |
| 40 | Clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Clients.: make([]*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#, 0, len(ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients.)), |
| 41 | Handshakescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Handshake.: ap.withKeyMaterialscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#withKeyMaterial., |
| 42 | } |
| 43 | |
| 44 | for _, c := range ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients. { |
| 45 | doc.Clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Clients. = append(doc.Clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/apJSON#Clients., c) |
| 46 | } |
| 47 | |
| 48 | return jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Marshal().(doc) |
| 49 | } |
| 50 | |
| 51 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) Getscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#Get().(bssid string) (*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#, bool) { |
| 52 | ap.RLockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RLock().() |
| 53 | defer ap.RUnlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RUnlock().() |
| 54 | |
| 55 | bssid = NormalizeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NormalizeMac().(bssid) |
| 56 | if s, found := ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients.[bssid]; found { |
| 57 | return s, true |
| 58 | } |
| 59 | return nil, false |
| 60 | } |
| 61 | |
| 62 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) RemoveClientscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#RemoveClient().(mac string) { |
| 63 | ap.Lockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Lock().() |
| 64 | defer ap.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Unlock().() |
| 65 | |
| 66 | bssid := NormalizeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NormalizeMac().(mac) |
| 67 | delete(ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients., bssid) |
| 68 | } |
| 69 | |
| 70 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) AddClientIfNewscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#AddClientIfNew().(bssid string, frequency int, rssi int8) (*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#, bool) { |
| 71 | ap.Lockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Lock().() |
| 72 | defer ap.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Unlock().() |
| 73 | |
| 74 | bssid = NormalizeMacscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NormalizeMac().(bssid) |
| 75 | alias := ap.aliasesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#aliases..GetOrscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/data`/UnsortedKV#GetOr().(bssid, "") |
| 76 | |
| 77 | if s, found := ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients.[bssid]; found { |
| 78 | // update |
| 79 | s.Frequencyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#Frequency. = frequency |
| 80 | s.RSSIscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#RSSI. = rssi |
| 81 | s.LastSeenscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#LastSeen. = timescip-go gomod github.com/golang/go/src go1.16 time/.Nowscip-go gomod github.com/golang/go/src go1.16 time/Now().() |
| 82 | |
| 83 | if alias != "" { |
| 84 | s.Aliasscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#Alias. = alias |
| 85 | } |
| 86 | |
| 87 | return s, false |
| 88 | } |
| 89 | |
| 90 | s := NewStationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/NewStation().("", bssid, frequency, rssi) |
| 91 | s.Aliasscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#Alias. = alias |
| 92 | ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients.[bssid] = s |
| 93 | |
| 94 | return s, true |
| 95 | } |
| 96 | |
| 97 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) NumClientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#NumClients().() int { |
| 98 | ap.RLockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RLock().() |
| 99 | defer ap.RUnlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RUnlock().() |
| 100 | return len(ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients.) |
| 101 | } |
| 102 | |
| 103 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) Clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#Clients().() (list []*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#) { |
| 104 | ap.RLockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RLock().() |
| 105 | defer ap.RUnlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RUnlock().() |
| 106 | |
| 107 | list = make([]*Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#, 0, len(ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients.)) |
| 108 | for _, c := range ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients. { |
| 109 | list = append(list, c) |
| 110 | } |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) EachClientscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#EachClient().(cb func(mac string, station *Stationscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#)) { |
| 115 | ap.Lockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Lock().() |
| 116 | defer ap.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Unlock().() |
| 117 | |
| 118 | for m, station := range ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients. { |
| 119 | cb(m, station) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) WithKeyMaterialscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#WithKeyMaterial().(state bool) { |
| 124 | ap.Lockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Lock().() |
| 125 | defer ap.Unlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#Unlock().() |
| 126 | |
| 127 | ap.withKeyMaterialscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#withKeyMaterial. = state |
| 128 | } |
| 129 | |
| 130 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) HasKeyMaterialscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#HasKeyMaterial().() bool { |
| 131 | ap.RLockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RLock().() |
| 132 | defer ap.RUnlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RUnlock().() |
| 133 | |
| 134 | return ap.withKeyMaterialscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#withKeyMaterial. |
| 135 | } |
| 136 | |
| 137 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) NumHandshakesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#NumHandshakes().() int { |
| 138 | ap.RLockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RLock().() |
| 139 | defer ap.RUnlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RUnlock().() |
| 140 | |
| 141 | sum := 0 |
| 142 | |
| 143 | for _, c := range ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients. { |
| 144 | if c.Handshakescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#Handshake..Completescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Handshake#Complete().() { |
| 145 | sum++ |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return sum |
| 150 | } |
| 151 | |
| 152 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) HasHandshakesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#HasHandshakes().() bool { |
| 153 | return ap.NumHandshakesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#NumHandshakes().() > 0 |
| 154 | } |
| 155 | |
| 156 | func (ap *AccessPointscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#) HasPMKIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#HasPMKID().() bool { |
| 157 | ap.RLockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RLock().() |
| 158 | defer ap.RUnlockscip-go gomod github.com/golang/go/src go1.16 sync/RWMutex#RUnlock().() |
| 159 | |
| 160 | for _, c := range ap.clientsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/AccessPoint#clients. { |
| 161 | if c.Handshakescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Station#Handshake..HasPMKIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Handshake#HasPMKID().() { |
| 162 | return true |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return false |
| 167 | } |