forge
Explore
Log in

Don't you dare go Hollow

scanner: parser-independent BSSID histogram in 10s heartbeat

Browse files at this commit

5d9149d3eec486be33db53371a55019dfad2c8c5Ahmet Kaan GümüşParent: e3ca548
src/scanner.rsmodified+33 -2
@@ -220,6 +220,12 @@ struct ScanStats {
220220 /// Beacons/probe-responses that ingested an AP row (created or already
221221 /// known — i.e. recognised AP-producing frames).
222222 beacons_ap_ingested: u64,
223+ /// Frames with beacon/probe-response FC byte, REGARDLESS of whether the
224+ /// IE walk later succeeded — the parser-independent RX witness.
225+ beacon_fc_rx: u64,
226+ /// addr3 histogram of beacon_fc frames: answers "are other BSSIDs even
227+ /// reaching the card" without trusting any parser.
228+ bssid_hist: std::collections::BTreeMap<crate::common::MacAddr, u64>,
223229 }
224230
225231 /// Blocking channel-hop passive scan on an interface the caller already put
@@ -270,6 +276,18 @@ pub fn run(cfg: ScannerConfig, tx: Sender<Event>, stop: Arc<AtomicBool>) -> Resu
270276 let now = now_ms();
271277 if let Some((meta, frame)) = radiotap::strip(&buf[..n]) {
272278 stats.radiotap_strip_ok += 1;
279+ // Parser-independent witness: beacon (0x80) and
280+ // probe-response (0x50) frames carry the transmitter
281+ // BSSID at addr3 (bytes 16..22) before any IE parse.
282+ if frame.len() >= 24 && (frame[0] == 0x80 || frame[0] == 0x50) {
283+ stats.beacon_fc_rx += 1;
284+ let mut mac = [0u8; 6];
285+ mac.copy_from_slice(&frame[16..22]);
286+ *stats
287+ .bssid_hist
288+ .entry(crate::common::MacAddr(mac))
289+ .or_insert(0) += 1;
290+ }
273291 if dot11::parse_beacon_or_probe(frame).is_some() {
274292 stats.mgmt_80211_parsed += 1;
275293 stats.beacons_ap_ingested += 1;
@@ -306,12 +324,25 @@ pub fn run(cfg: ScannerConfig, tx: Sender<Event>, stop: Arc<AtomicBool>) -> Resu
306324 // report says "only my own AP shows up".
307325 if last_stats_log.elapsed() >= Duration::from_secs(10) {
308326 last_stats_log = Instant::now();
327+ let top: String = {
328+ let mut v: Vec<(crate::common::MacAddr, u64)> =
329+ stats.bssid_hist.iter().map(|(m, c)| (*m, *c)).collect();
330+ v.sort_unstable_by(|a, b| b.1.cmp(&a.1));
331+ v.truncate(4);
332+ v.iter()
333+ .map(|(m, c)| format!("{m}({c})"))
334+ .collect::<Vec<_>>()
335+ .join(", ")
336+ };
309337 let _ = tx.send(Event::Log(format!(
310- "scan: {} rx frames, {} beacons -> {} APs live (ch {})",
338+ "scan: rx={} strip={} beaconfc={} beacons={} aps={} ch={} top=[{}]",
311339 stats.raw_frames_received,
340+ stats.radiotap_strip_ok,
341+ stats.beacon_fc_rx,
312342 stats.beacons_ap_ingested,
313343 scanner.aps.len(),
314- cur_ch
344+ cur_ch,
345+ top
315346 )));
316347 }
317348