mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
new: parsing encryption in wifi.recon module ( ref #53 )
This commit is contained in:
parent
0ad426024f
commit
9b81e5b96a
3 changed files with 64 additions and 19 deletions
|
@ -142,7 +142,12 @@ func (w *WiFiRecon) getRow(station *WiFiStation) []string {
|
||||||
seen = core.Dim(seen)
|
seen = core.Dim(seen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssid := station.ESSID()
|
||||||
|
|
||||||
encryption := w.stats.EncryptionOf(station.HW)
|
encryption := w.stats.EncryptionOf(station.HW)
|
||||||
|
if encryption == "OPEN" {
|
||||||
|
encryption = core.Green(encryption)
|
||||||
|
}
|
||||||
|
|
||||||
sent := ""
|
sent := ""
|
||||||
bytes := w.stats.SentFrom(station.HW)
|
bytes := w.stats.SentFrom(station.HW)
|
||||||
|
@ -159,7 +164,7 @@ func (w *WiFiRecon) getRow(station *WiFiStation) []string {
|
||||||
row := []string{
|
row := []string{
|
||||||
fmt.Sprintf("%d dBm", station.RSSI),
|
fmt.Sprintf("%d dBm", station.RSSI),
|
||||||
bssid,
|
bssid,
|
||||||
station.ESSID(),
|
ssid,
|
||||||
station.Vendor,
|
station.Vendor,
|
||||||
encryption,
|
encryption,
|
||||||
strconv.Itoa(station.Channel),
|
strconv.Itoa(station.Channel),
|
||||||
|
@ -227,15 +232,23 @@ func (w *WiFiRecon) Show(by string) error {
|
||||||
for _, s := range stations {
|
for _, s := range stations {
|
||||||
rows = append(rows, w.getRow(s))
|
rows = append(rows, w.getRow(s))
|
||||||
}
|
}
|
||||||
|
nrows := len(rows)
|
||||||
|
|
||||||
columns := []string{"RSSI", "BSSID", "SSID", "Vendor", "Encryption", "Channel", "Sent", "Recvd", "Last Seen"}
|
columns := []string{"RSSI", "BSSID", "SSID", "Vendor", "Encryption", "Channel", "Sent", "Recvd", "Last Seen"}
|
||||||
if w.isApSelected() {
|
if w.isApSelected() {
|
||||||
// these are clients
|
// these are clients
|
||||||
columns = []string{"RSSI", "MAC", "Vendor", "Channel", "Sent", "Received", "Last Seen"}
|
columns = []string{"RSSI", "MAC", "Vendor", "Channel", "Sent", "Received", "Last Seen"}
|
||||||
fmt.Printf("\n%s clients:\n", w.accessPoint.String())
|
|
||||||
|
if nrows == 0 {
|
||||||
|
fmt.Printf("\nNo authenticated clients detected for %s.\n", w.accessPoint.String())
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\n%s clients:\n", w.accessPoint.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.showTable(columns, rows)
|
if nrows > 0 {
|
||||||
|
w.showTable(columns, rows)
|
||||||
|
}
|
||||||
|
|
||||||
w.Session.Refresh()
|
w.Session.Refresh()
|
||||||
|
|
||||||
|
@ -265,7 +278,7 @@ func (w *WiFiRecon) Configure() error {
|
||||||
} else {
|
} else {
|
||||||
w.channel = 0
|
w.channel = 0
|
||||||
// we need to start somewhere, this is just to check if
|
// we need to start somewhere, this is just to check if
|
||||||
// this OS support switching channel programmatically.
|
// this OS supports switching channel programmatically.
|
||||||
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), 1); err != nil {
|
if err = network.SetInterfaceChannel(w.Session.Interface.Name(), 1); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -369,6 +382,7 @@ func (w *WiFiRecon) updateStats(dot11 *layers.Dot11, packet gopacket.Packet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok, enc := packets.Dot11ParseEncryption(packet, dot11); ok == true {
|
if ok, enc := packets.Dot11ParseEncryption(packet, dot11); ok == true {
|
||||||
|
w.stats.ResetEncryption(dot11.Address3)
|
||||||
for _, e := range enc {
|
for _, e := range enc {
|
||||||
w.stats.CollectEncryption(dot11.Address3, e)
|
w.stats.CollectEncryption(dot11.Address3, e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,16 @@ func (s *WiFiStats) CollectReceived(station net.HardwareAddr, bytes uint64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *WiFiStats) ResetEncryption(station net.HardwareAddr) {
|
||||||
|
s.Lock()
|
||||||
|
defer s.Unlock()
|
||||||
|
|
||||||
|
bssid := station.String()
|
||||||
|
if sstats, found := s.stats[bssid]; found == true {
|
||||||
|
sstats.Encryption = make(map[string]bool)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *WiFiStats) CollectEncryption(station net.HardwareAddr, enc string) {
|
func (s *WiFiStats) CollectEncryption(station net.HardwareAddr, enc string) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
|
@ -49,26 +49,47 @@ func Dot11Parse(packet gopacket.Packet) (ok bool, radiotap *layers.RadioTap, dot
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dot11ParseIDSSID(packet gopacket.Packet) (bool, string) {
|
func Dot11ParseIDSSID(packet gopacket.Packet) (bool, string) {
|
||||||
dot11infoLayer := packet.Layer(layers.LayerTypeDot11InformationElement)
|
for _, layer := range packet.Layers() {
|
||||||
if dot11infoLayer == nil {
|
if layer.LayerType() == layers.LayerTypeDot11InformationElement {
|
||||||
return false, ""
|
dot11info, ok := layer.(*layers.Dot11InformationElement)
|
||||||
|
if ok == true && dot11info.ID == layers.Dot11InformationElementIDSSID && len(dot11info.Info) > 0 {
|
||||||
|
return true, string(dot11info.Info)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dot11info, ok := dot11infoLayer.(*layers.Dot11InformationElement)
|
return false, ""
|
||||||
if ok == false || (dot11info.ID != layers.Dot11InformationElementIDSSID) {
|
|
||||||
return false, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(dot11info.Info) == 0 {
|
|
||||||
return false, ""
|
|
||||||
} else {
|
|
||||||
return true, string(dot11info.Info)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dot11ParseEncryption(packet gopacket.Packet, dot11 *layers.Dot11) (bool, []string) {
|
func Dot11ParseEncryption(packet gopacket.Packet, dot11 *layers.Dot11) (bool, []string) {
|
||||||
// TODO :(
|
enc := make([]string, 0)
|
||||||
return false, nil
|
found := false
|
||||||
|
|
||||||
|
if dot11.Flags.WEP() {
|
||||||
|
found = true
|
||||||
|
enc = append(enc, "WEP")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, layer := range packet.Layers() {
|
||||||
|
if layer.LayerType() == layers.LayerTypeDot11InformationElement {
|
||||||
|
info, ok := layer.(*layers.Dot11InformationElement)
|
||||||
|
if ok == true {
|
||||||
|
found = true
|
||||||
|
if info.ID == layers.Dot11InformationElementIDRSNInfo {
|
||||||
|
enc = append(enc, "WPA2")
|
||||||
|
} else if info.ID == layers.Dot11InformationElementIDVendor && bytes.Index(info.Info, []byte{0, 0x50, 0xf2, 1, 1, 0}) == 0 {
|
||||||
|
enc = append(enc, "WPA")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if found && len(enc) == 0 {
|
||||||
|
enc = append(enc, "OPEN")
|
||||||
|
}
|
||||||
|
|
||||||
|
return found, enc
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dot11IsDataFor(dot11 *layers.Dot11, station net.HardwareAddr) bool {
|
func Dot11IsDataFor(dot11 *layers.Dot11, station net.HardwareAddr) bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue