Enhance analyze_pcap function to track SSID encryption status and improve handling of hidden SSIDs
This commit is contained in:
parent
0129ddeaa2
commit
ddc27d9313
1 changed files with 15 additions and 12 deletions
27
enrich.py
27
enrich.py
|
@ -318,6 +318,8 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
|
|||
except Exception:
|
||||
continue
|
||||
|
||||
ssid_encryption_status = {}
|
||||
|
||||
for packet in filtered_packets:
|
||||
try:
|
||||
if 'radiotap' not in packet or 'wlan' not in packet:
|
||||
|
@ -333,30 +335,28 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
|
|||
packet_channel = get_channel_from_freq(packet_freq)
|
||||
|
||||
subtype = int(getattr(wlan, 'type_subtype', 0), 16)
|
||||
if subtype not in (5, 8): # Probe Response or Beacon
|
||||
if subtype not in (5, 8): # Beacon or Probe Response
|
||||
continue
|
||||
|
||||
# Grab management layer once
|
||||
try:
|
||||
mgt = packet.get_multiple_layers('wlan.mgt')[0]
|
||||
tags = mgt._all_fields.get('wlan.tagged.all', {}).get('wlan.tag', [])
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
ssid = None
|
||||
hidden_ssid = False
|
||||
is_open = True # Assume open until proven encrypted
|
||||
|
||||
is_open = True
|
||||
capabilities = getattr(wlan, 'capabilities', None)
|
||||
|
||||
if capabilities:
|
||||
try:
|
||||
cap_int = int(capabilities, 16)
|
||||
if cap_int & 0x0010 == 0:
|
||||
if (cap_int & 0x0010): # Privacy bit set = not open
|
||||
is_open = False
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
for tag in tags:
|
||||
tag_number = tag.get('wlan.tag.number')
|
||||
|
||||
|
@ -379,7 +379,6 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
|
|||
cisco_ssid_clients[ssid].append(num_clients)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
if ssid:
|
||||
ssid_hidden_status[ssid] = hidden_ssid
|
||||
ssid_packet_counts[ssid] += 1
|
||||
|
@ -391,14 +390,17 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
|
|||
cisco_reported_clients.append(num_clients)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
if not ssid:
|
||||
continue
|
||||
|
||||
ssid_hidden_status[ssid] = hidden_ssid
|
||||
ssid_encryption_status[ssid] = is_open
|
||||
ssid_packet_counts[ssid] += 1
|
||||
|
||||
bssid = getattr(wlan, 'bssid', '').lower()
|
||||
if not bssid or bssid == 'ff:ff:ff:ff:ff:ff':
|
||||
continue
|
||||
|
||||
|
||||
bssid_to_ssid[bssid] = ssid
|
||||
ssid_to_bssids[ssid].add(bssid)
|
||||
|
||||
|
@ -406,9 +408,10 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
|
|||
if signal:
|
||||
ssid_signals[ssid].append(int(signal))
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
|
||||
our_ssid = bssid_to_ssid.get(ap_bssid, None)
|
||||
|
||||
clients_on_ap = get_clients_on_ap(filtered_packets, ap_bssid)
|
||||
|
@ -430,7 +433,7 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel):
|
|||
ssid_summary.append({
|
||||
'SSID': ssid,
|
||||
'Hidden': ssid == '',
|
||||
'Open': is_open,
|
||||
'Open': ssid_encryption_status.get(ssid, True),
|
||||
'BSSID_Count': len(bssids),
|
||||
'BSSIDs': ";".join(sorted(bssids)),
|
||||
'Avg_Signal': mean(signals) if signals else 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue