AKM suites, assoc/reassoc parsing, seq/IE-fingerprint/WPS UUID-E correlation hooks
Browse files at this commit2974a5408e0493a05c32a099707746804fcbd75bParent: 62d713b- feat
- AKM suites, assoc/reassoc parsing, seq/IE-fingerprint/WPS UUID-E correlation hooks
2 changed files +671 -17
- src/common.rs +208 -14
- src/dot11.rs +463 -3
src/common.rsmodified+208 -14
| @@ -4,6 +4,9 @@ | ||
| 4 | 4 | //! serializes through `serde_json` lines. Signatures and field meanings are |
| 5 | 5 | //! FIXED; implementations must conform exactly. Times are `last_seen_ms` |
| 6 | 6 | //! (millis since the process-local epoch, see [`now_ms`]), RSSI in dBm. |
| 7 | +//! Fields added after the wire format froze carry serde defaults so older | |
| 8 | +//! records deserialize losslessly (e.g. `ClientInfo.connected`, serde | |
| 9 | +//! default true). | |
| 7 | 10 | |
| 8 | 11 | use std::fmt; |
| 9 | 12 | use std::time::Instant; |
| @@ -95,6 +98,32 @@ impl Security { | ||
| 95 | 98 | } |
| 96 | 99 | } |
| 97 | 100 | |
| 101 | +/// Authentication key-management suites parsed from the RSN/WPA IE. | |
| 102 | +#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)] | |
| 103 | +pub enum Akm { | |
| 104 | + Psk, | |
| 105 | + Sae, | |
| 106 | + Owe, | |
| 107 | + FtPsk, | |
| 108 | + PskSha256, | |
| 109 | + OneX, | |
| 110 | + Other(u8), | |
| 111 | +} | |
| 112 | + | |
| 113 | +impl Akm { | |
| 114 | + pub fn label(self) -> &'static str { | |
| 115 | + match self { | |
| 116 | + Akm::Psk => "PSK", | |
| 117 | + Akm::Sae => "SAE", | |
| 118 | + Akm::Owe => "OWE", | |
| 119 | + Akm::FtPsk => "FT-PSK", | |
| 120 | + Akm::PskSha256 => "PSK-SHA256", | |
| 121 | + Akm::OneX => "802.1X", | |
| 122 | + Akm::Other(_) => "other", | |
| 123 | + } | |
| 124 | + } | |
| 125 | +} | |
| 126 | + | |
| 98 | 127 | /// A discovered access point. Live-updated by the scanner. |
| 99 | 128 | #[derive(Clone, Debug, Serialize, Deserialize)] |
| 100 | 129 | pub struct AccessPoint { |
| @@ -107,6 +136,10 @@ pub struct AccessPoint { | ||
| 107 | 136 | /// Millis since the process-local epoch ([`now_ms`]) of the last frame |
| 108 | 137 | /// seen from this AP. Age display = `now_ms() - last_seen_ms`. |
| 109 | 138 | pub last_seen_ms: u64, |
| 139 | + /// AKM suites advertised in the RSN/WPA IE; empty = unknown (old peers, | |
| 140 | + /// non-RSN APs). | |
| 141 | + #[serde(default)] | |
| 142 | + pub akms: Vec<Akm>, | |
| 110 | 143 | } |
| 111 | 144 | |
| 112 | 145 | /// A discovered client station. |
| @@ -120,6 +153,25 @@ pub struct ClientInfo { | ||
| 120 | 153 | /// Millis since the process-local epoch ([`now_ms`]) of the last frame |
| 121 | 154 | /// seen from this station. |
| 122 | 155 | pub last_seen_ms: u64, |
| 156 | + /// Station liveness: true while the station is active/associated; the | |
| 157 | + /// scanner flips it false when it observes a deauth/disassoc affecting | |
| 158 | + /// the station, and any later frame from the station flips it back | |
| 159 | + /// true. Serde default is true so pre-field wire records deserialize | |
| 160 | + /// as connected. | |
| 161 | + #[serde(default = "crate::common::default_true")] | |
| 162 | + pub connected: bool, | |
| 163 | + /// MAC-randomization pairing: device-group id from the scanner | |
| 164 | + /// (`Event::ClientIdent`), when this MAC was correlated. | |
| 165 | + #[serde(default)] | |
| 166 | + pub ident_group: Option<u64>, | |
| 167 | + #[serde(default)] | |
| 168 | + pub ident_conf: Option<IdentConfidence>, | |
| 169 | +} | |
| 170 | + | |
| 171 | +/// Serde `default` for fields whose absent wire value means `true` | |
| 172 | +/// ([`ClientInfo::connected`]). | |
| 173 | +pub fn default_true() -> bool { | |
| 174 | + true | |
| 123 | 175 | } |
| 124 | 176 | |
| 125 | 177 | /// A complete, crackable WPA 4-way handshake capture (M1+M2 minimum). |
| @@ -177,6 +229,56 @@ pub struct PmkidCapture { | ||
| 177 | 229 | pub pmkid: [u8; 16], |
| 178 | 230 | } |
| 179 | 231 | |
| 232 | +/// Cumulative per-channel frame counters (scanner → UI snapshot). | |
| 233 | +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 234 | +pub struct ChannelStat { | |
| 235 | + pub channel: u8, | |
| 236 | + pub frames: u64, | |
| 237 | + pub beacons: u64, | |
| 238 | +} | |
| 239 | + | |
| 240 | +/// One observed probe request (client asking for a network). | |
| 241 | +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 242 | +pub struct ProbeInfo { | |
| 243 | + pub client: MacAddr, | |
| 244 | + /// SSID of the probe; `None` for broadcast/wildcard probes. | |
| 245 | + pub ssid: Option<String>, | |
| 246 | + pub rssi_dbm: i8, | |
| 247 | + /// Millis since the process-local epoch ([`now_ms`]). | |
| 248 | + pub at_ms: u64, | |
| 249 | +} | |
| 250 | + | |
| 251 | +/// Strength of a MAC-randomization pairing decision ([`Event::ClientIdent`]). | |
| 252 | +/// Ordered weakest→strongest; UI displays it as `?`/`~`/`=` per `label()`. | |
| 253 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] | |
| 254 | +pub enum IdentConfidence { | |
| 255 | + /// Only the ordered-IE fingerprint matched — driver-class witness. | |
| 256 | + Probable, | |
| 257 | + /// Fingerprint match plus a per-frame witness: shared probed SSID or | |
| 258 | + /// uninterrupted 802.11 sequence numbers across the rotation. | |
| 259 | + Strong, | |
| 260 | + /// WPS UUID-E matched — the device identifies itself. | |
| 261 | + Exact, | |
| 262 | +} | |
| 263 | + | |
| 264 | +impl IdentConfidence { | |
| 265 | + pub fn label(self) -> &'static str { | |
| 266 | + match self { | |
| 267 | + IdentConfidence::Probable => "?", | |
| 268 | + IdentConfidence::Strong => "~", | |
| 269 | + IdentConfidence::Exact => "=", | |
| 270 | + } | |
| 271 | + } | |
| 272 | +} | |
| 273 | + | |
| 274 | +/// Which of the two capture kinds was imported from a file (store::StoredCapture | |
| 275 | +/// stays in store.rs; common must not depend on store). | |
| 276 | +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 277 | +pub enum ImportedCapture { | |
| 278 | + Handshake(Box<HandshakeCapture>), | |
| 279 | + Pmkid(PmkidCapture), | |
| 280 | +} | |
| 281 | + | |
| 180 | 282 | /// Events flowing from worker threads to the UI. In the real architecture |
| 181 | 283 | /// the privileged service serializes them as `serde_json` lines on the |
| 182 | 284 | /// child's stdout; in mock mode a thread pushes them onto a |
| @@ -186,6 +288,9 @@ pub enum Event { | ||
| 186 | 288 | ApUpdated(AccessPoint), |
| 187 | 289 | ApLost(MacAddr), |
| 188 | 290 | ClientUpdated(ClientInfo), |
| 291 | + /// Station silent past the scanner's client-expiry window — the UI | |
| 292 | + /// drops it from the clients table. | |
| 293 | + ClientLost(MacAddr), | |
| 189 | 294 | /// Progress while collecting 4-way messages. |
| 190 | 295 | HandshakeProgress { |
| 191 | 296 | ap: MacAddr, |
| @@ -197,16 +302,46 @@ pub enum Event { | ||
| 197 | 302 | PmkidCaptured(PmkidCapture), |
| 198 | 303 | /// Count of deauth/disassoc frames actually written to the wire. |
| 199 | 304 | DeauthSent { ap: MacAddr, target: MacAddr, count: u64 }, |
| 200 | - /// Candidates checked so far (`done`) and current throughput (`hps`) | |
| 201 | - /// of a running crack job. | |
| 202 | - CrackProgress { done: u64, hps: f64 }, | |
| 305 | + /// Candidates checked so far (`done`), current throughput (`hps`), | |
| 306 | + /// and the worst-case candidate total (`total`, when the attack | |
| 307 | + /// mode's space is countable) of a running crack job. Worst-case | |
| 308 | + /// remaining time = (total - done) / hps. | |
| 309 | + CrackProgress { done: u64, hps: f64, total: Option<u64> }, | |
| 203 | 310 | /// A crack job recovered the passphrase. |
| 204 | 311 | CrackFound { password: String }, |
| 205 | 312 | /// The active crack job ended: `found` distinguishes success from |
| 206 | 313 | /// exhaustion/user-stop (emitted after [`Event::CrackFound`] too). |
| 207 | 314 | CrackStopped { found: bool }, |
| 315 | + /// Throughput of a rainbow-table build job (PMKs written so far); | |
| 316 | + /// `total` is the wordlist's line count (worst-case table size). | |
| 317 | + RainbowProgress { done: u64, hps: f64, total: Option<u64> }, | |
| 318 | + /// A rainbow-table build job ended (always exactly one; `entries` is | |
| 319 | + /// what actually landed in `path`, 0 on failure). | |
| 320 | + RainbowBuilt { path: String, entries: u64 }, | |
| 208 | 321 | Log(String), |
| 209 | 322 | Error(String), |
| 323 | + /// Cumulative per-channel counters snapshot (emitted every ~2 s). | |
| 324 | + ChannelStats(Vec<ChannelStat>), | |
| 325 | + /// A novel probe request was observed. | |
| 326 | + ProbeObserved(ProbeInfo), | |
| 327 | + /// Deauth/disassoc storm detected on a (source, target) pair that we | |
| 328 | + /// did not cause — a foreign deauth attack in progress. | |
| 329 | + DeauthAlert { | |
| 330 | + source: MacAddr, | |
| 331 | + target: MacAddr, | |
| 332 | + count: u32, | |
| 333 | + }, | |
| 334 | + /// A capture was imported from an external file (pcap / hc22000). | |
| 335 | + CaptureImported(ImportedCapture), | |
| 336 | + /// `mac` was correlated with a device group (MAC-randomization pairing): | |
| 337 | + /// every MAC witnessed on the same physical radio shares `group`. | |
| 338 | + ClientIdent { | |
| 339 | + mac: MacAddr, | |
| 340 | + group: u64, | |
| 341 | + confidence: IdentConfidence, | |
| 342 | + }, | |
| 343 | + /// Crack-speed benchmark finished. | |
| 344 | + BenchmarkDone { gpu_hps: Option<f64>, cpu_hps: f64 }, | |
| 210 | 345 | } |
| 211 | 346 | |
| 212 | 347 | /// Channel list for hopper: all enabled 2.4 GHz + 5 GHz UNII channels of the |
| @@ -256,15 +391,35 @@ pub enum Cmd { | ||
| 256 | 391 | /// instead of hopping). `None`/empty = full hop list. |
| 257 | 392 | #[serde(default)] |
| 258 | 393 | channels: Option<Vec<u8>>, |
| 394 | + /// Pcap spool file for the scan: every received raw frame (with | |
| 395 | + /// radiotap header) is appended to it. `None` = no spooling. | |
| 396 | + #[serde(default)] | |
| 397 | + spool: Option<std::path::PathBuf>, | |
| 398 | + /// Truncate the spool file on scan start (`false` = append if it | |
| 399 | + /// exists). UI sets `true` on a fresh scan from toggle_monitor, | |
| 400 | + /// `false` when re-parking channels mid-scan. | |
| 401 | + #[serde(default)] | |
| 402 | + fresh_spool: bool, | |
| 259 | 403 | }, |
| 260 | 404 | /// Stop the scanner, restore managed mode. |
| 261 | 405 | StopScan, |
| 262 | - /// Blast `count` deauth rounds at `target` (broadcast allowed) from | |
| 263 | - /// `ap`, after tuning to `channel`. | |
| 406 | + /// Blast `count` deauth rounds per `(bssid, channel)` entry at | |
| 407 | + /// `target` (broadcast allowed). Multiple entries cover dual-band | |
| 408 | + /// networks: the worker walks the list sequentially (one channel at a | |
| 409 | + /// time is all a single radio can do). | |
| 264 | 410 | Deauth { |
| 265 | - ap: MacAddr, | |
| 411 | + aps: Vec<(MacAddr, u8)>, | |
| 266 | 412 | target: MacAddr, |
| 413 | + count: u32, | |
| 414 | + }, | |
| 415 | + /// Deauth every client of one AP at once: pins the channel, blasts | |
| 416 | + /// `count` rounds at each target in `targets`, then one broadcast | |
| 417 | + /// blast. `ap` is also recorded so the service's foreign-deauth | |
| 418 | + /// detector suppresses its own frames. | |
| 419 | + DeauthAll { | |
| 420 | + ap: MacAddr, | |
| 267 | 421 | channel: u8, |
| 422 | + targets: Vec<MacAddr>, | |
| 268 | 423 | count: u32, |
| 269 | 424 | }, |
| 270 | 425 | /// Clientless PMKID grab against `ap`. |
| @@ -273,10 +428,12 @@ pub enum Cmd { | ||
| 273 | 428 | channel: u8, |
| 274 | 429 | essid: String, |
| 275 | 430 | }, |
| 276 | - /// Park on `ap`'s channel and track its 4-way handshakes. | |
| 431 | + /// Track 4-way handshakes of every BSSID in `targets` (dual-band | |
| 432 | + /// networks send the exchange on whichever band the client chose — the | |
| 433 | + /// parked SCANNER hops the union of channels, so a single listen | |
| 434 | + /// covers all bands). One channel → the worker pins it itself. | |
| 277 | 435 | CaptureHs { |
| 278 | - ap: MacAddr, | |
| 279 | - channel: u8, | |
| 436 | + targets: Vec<(MacAddr, u8)>, | |
| 280 | 437 | essid: String, |
| 281 | 438 | }, |
| 282 | 439 | /// Stop NetworkManager/wpa_supplicant so they stop pinning the radio. |
| @@ -298,6 +455,7 @@ mod tests { | ||
| 298 | 455 | rssi_dbm: -42, |
| 299 | 456 | beacons: 7, |
| 300 | 457 | last_seen_ms: 123_456, |
| 458 | + akms: vec![Akm::Psk], | |
| 301 | 459 | } |
| 302 | 460 | } |
| 303 | 461 | |
| @@ -308,6 +466,9 @@ mod tests { | ||
| 308 | 466 | rssi_dbm: -55, |
| 309 | 467 | frames: 3, |
| 310 | 468 | last_seen_ms: 654_321, |
| 469 | + connected: true, | |
| 470 | + ident_group: Some(7), | |
| 471 | + ident_conf: Some(IdentConfidence::Strong), | |
| 311 | 472 | } |
| 312 | 473 | } |
| 313 | 474 | |
| @@ -369,14 +530,41 @@ mod tests { | ||
| 369 | 530 | target: MacAddr::BROADCAST, |
| 370 | 531 | count: 64, |
| 371 | 532 | }, |
| 372 | - Event::CrackProgress { done: 1000, hps: 1234.5 }, | |
| 533 | + Event::CrackProgress { done: 1000, hps: 1234.5, total: Some(5000) }, | |
| 373 | 534 | Event::CrackFound { |
| 374 | 535 | password: "hunter2".into(), |
| 375 | 536 | }, |
| 376 | 537 | Event::CrackStopped { found: true }, |
| 377 | 538 | Event::CrackStopped { found: false }, |
| 539 | + Event::RainbowProgress { done: 42, hps: 9.5, total: None }, | |
| 540 | + Event::RainbowBuilt { | |
| 541 | + path: "/tmp/t.pmk".into(), | |
| 542 | + entries: 7, | |
| 543 | + }, | |
| 378 | 544 | Event::Log("hello".into()), |
| 379 | 545 | Event::Error("boom".into()), |
| 546 | + Event::ChannelStats(vec![ | |
| 547 | + ChannelStat { channel: 6, frames: 1234, beacons: 56 }, | |
| 548 | + ChannelStat { channel: 36, frames: 78, beacons: 9 }, | |
| 549 | + ]), | |
| 550 | + Event::ProbeObserved(ProbeInfo { | |
| 551 | + client: MacAddr([0x42; 6]), | |
| 552 | + ssid: Some("HOME-WIFI".into()), | |
| 553 | + rssi_dbm: -61, | |
| 554 | + at_ms: 987_654, | |
| 555 | + }), | |
| 556 | + Event::DeauthAlert { | |
| 557 | + source: MacAddr([0xde; 6]), | |
| 558 | + target: MacAddr::BROADCAST, | |
| 559 | + count: 17, | |
| 560 | + }, | |
| 561 | + Event::CaptureImported(ImportedCapture::Handshake(Box::new(handshake_obj()))), | |
| 562 | + Event::ClientIdent { | |
| 563 | + mac: MacAddr([0x02, 0xa0, 0xb1, 0xc2, 0xd3, 0xe4]), | |
| 564 | + group: 42, | |
| 565 | + confidence: IdentConfidence::Exact, | |
| 566 | + }, | |
| 567 | + Event::BenchmarkDone { gpu_hps: Some(1_250_000.0), cpu_hps: 310_000.0 }, | |
| 380 | 568 | ]; |
| 381 | 569 | for ev in &cases { |
| 382 | 570 | let json = serde_json::to_string(ev).expect("serialize"); |
| @@ -413,12 +601,13 @@ mod tests { | ||
| 413 | 601 | Cmd::StartScan { |
| 414 | 602 | ifname: "wlp14s0".into(), |
| 415 | 603 | channels: None, |
| 604 | + spool: None, | |
| 605 | + fresh_spool: false, | |
| 416 | 606 | }, |
| 417 | 607 | Cmd::StopScan, |
| 418 | 608 | Cmd::Deauth { |
| 419 | - ap: MacAddr([1; 6]), | |
| 609 | + aps: vec![(MacAddr([1; 6]), 6)], | |
| 420 | 610 | target: MacAddr::BROADCAST, |
| 421 | - channel: 6, | |
| 422 | 611 | count: 16, |
| 423 | 612 | }, |
| 424 | 613 | Cmd::Pmkid { |
| @@ -427,12 +616,17 @@ mod tests { | ||
| 427 | 616 | essid: "corp-wpa3".into(), |
| 428 | 617 | }, |
| 429 | 618 | Cmd::CaptureHs { |
| 430 | - ap: MacAddr([3; 6]), | |
| 431 | - channel: 11, | |
| 619 | + targets: vec![(MacAddr([3; 6]), 11), (MacAddr([4; 6]), 60)], | |
| 432 | 620 | essid: "coffeeshop".into(), |
| 433 | 621 | }, |
| 434 | 622 | Cmd::StopNetworkManager, |
| 435 | 623 | Cmd::Shutdown, |
| 624 | + Cmd::DeauthAll { | |
| 625 | + ap: MacAddr([5; 6]), | |
| 626 | + channel: 44, | |
| 627 | + targets: vec![MacAddr([6; 6]), MacAddr([7; 6])], | |
| 628 | + count: 8, | |
| 629 | + }, | |
| 436 | 630 | ]; |
| 437 | 631 | for cmd in &cases { |
| 438 | 632 | let json = serde_json::to_string(cmd).expect("serialize"); |
src/dot11.rsmodified+463 -3
| @@ -5,15 +5,15 @@ | ||
| 5 | 5 | //! captures may or may not include one — parsers simply ignore trailing |
| 6 | 6 | //! bytes beyond what they need). |
| 7 | 7 | |
| 8 | -use crate::common::{MacAddr, Security}; | |
| 8 | +use crate::common::{Akm, MacAddr, Security}; | |
| 9 | 9 | |
| 10 | 10 | /// LLC/SNAP header prefixing an EAPOL payload inside a data frame. |
| 11 | 11 | const SNAP_EAPOL: [u8; 8] = [0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e]; |
| 12 | 12 | |
| 13 | -const IE_SSID: u8 = 0; | |
| 13 | +pub(crate) const IE_SSID: u8 = 0; | |
| 14 | 14 | const IE_DS_PARAM: u8 = 3; |
| 15 | 15 | const IE_RSN: u8 = 48; |
| 16 | -const IE_VENDOR: u8 = 221; | |
| 16 | +pub(crate) const IE_VENDOR: u8 = 221; | |
| 17 | 17 | |
| 18 | 18 | /// Microsoft (WPA) vendor IE OUI+type prefix. |
| 19 | 19 | const WPA_OUI: [u8; 4] = [0x00, 0x50, 0xf2, 0x01]; |
| @@ -65,6 +65,40 @@ pub struct MgmtInfo { | ||
| 65 | 65 | pub ssid: Option<String>, // None if hidden/zero-len |
| 66 | 66 | pub channel: Option<u8>, // DS parameter set IE |
| 67 | 67 | pub security: Security, // from RSN/WPA IEs + capability privacy bit |
| 68 | + /// AKM suites from the RSN/WPA IE; empty for open/WEP or unparsed frames. | |
| 69 | + pub akms: Vec<Akm>, | |
| 70 | +} | |
| 71 | + | |
| 72 | +/// Map an RSN AKM suite type byte to `Akm`. | |
| 73 | +fn akm_from_type(t: u8) -> Akm { | |
| 74 | + match t { | |
| 75 | + 2 => Akm::Psk, | |
| 76 | + 8 => Akm::Sae, | |
| 77 | + 18 => Akm::Owe, | |
| 78 | + 4 => Akm::FtPsk, | |
| 79 | + 6 => Akm::PskSha256, | |
| 80 | + 1 => Akm::OneX, | |
| 81 | + other => Akm::Other(other), | |
| 82 | + } | |
| 83 | +} | |
| 84 | + | |
| 85 | +/// Walk the AKM suite list of an RSN IE body, collecting mapped `Akm`s. | |
| 86 | +/// Layout: version(2) group(4) pairwise_cnt(2) pairwise[4n] akm_cnt(2) akm[4m]. | |
| 87 | +fn rsn_akms(body: &[u8], out: &mut Vec<Akm>) { | |
| 88 | + let Some(pair_cnt) = u16le(body, 6).map(|c| c as usize) else { | |
| 89 | + return; | |
| 90 | + }; | |
| 91 | + let mut o = 8usize + 4 * pair_cnt; | |
| 92 | + let Some(akm_cnt) = u16le(body, o).map(|c| c as usize) else { | |
| 93 | + return; | |
| 94 | + }; | |
| 95 | + o += 2; | |
| 96 | + for i in 0..akm_cnt { | |
| 97 | + let Some(suite) = body.get(o + 4 * i..o + 4 * i + 4) else { | |
| 98 | + break; | |
| 99 | + }; | |
| 100 | + out.push(akm_from_type(suite[3])); | |
| 101 | + } | |
| 68 | 102 | } |
| 69 | 103 | |
| 70 | 104 | /// True if the RSN IE body lists AKM suite 00:0f:ac:8 (SAE → WPA3). |
| @@ -109,6 +143,7 @@ pub fn parse_beacon_or_probe(f: &[u8]) -> Option<MgmtInfo> { | ||
| 109 | 143 | let mut has_rsn = false; |
| 110 | 144 | let mut has_sae = false; |
| 111 | 145 | let mut has_wpa = false; |
| 146 | + let mut akms = Vec::new(); | |
| 112 | 147 | walk_ies(f, 36, |id, body| match id { |
| 113 | 148 | IE_SSID => { |
| 114 | 149 | if !body.is_empty() { |
| @@ -121,10 +156,13 @@ pub fn parse_beacon_or_probe(f: &[u8]) -> Option<MgmtInfo> { | ||
| 121 | 156 | IE_RSN => { |
| 122 | 157 | has_rsn = true; |
| 123 | 158 | has_sae |= rsn_has_akm(body, 8); |
| 159 | + rsn_akms(body, &mut akms); | |
| 124 | 160 | } |
| 125 | 161 | IE_VENDOR => { |
| 126 | 162 | if body.len() >= 4 && body[..4] == WPA_OUI { |
| 127 | 163 | has_wpa = true; |
| 164 | + // WPA1 vendor IE: only PSK key management exists. | |
| 165 | + akms.push(Akm::Psk); | |
| 128 | 166 | } |
| 129 | 167 | } |
| 130 | 168 | _ => {} |
| @@ -140,12 +178,23 @@ pub fn parse_beacon_or_probe(f: &[u8]) -> Option<MgmtInfo> { | ||
| 140 | 178 | Security::Open |
| 141 | 179 | }; |
| 142 | 180 | |
| 181 | + // An AP advertising WPA (vendor IE) AND WPA2 (RSN IE, e.g. mixed or | |
| 182 | + // transition mode) otherwise surfaces PSK twice. First-seen order wins. | |
| 183 | + let mut uniq: Vec<Akm> = Vec::with_capacity(akms.len()); | |
| 184 | + for a in akms { | |
| 185 | + if !uniq.contains(&a) { | |
| 186 | + uniq.push(a); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + let akms = uniq; | |
| 190 | + | |
| 143 | 191 | Some(MgmtInfo { |
| 144 | 192 | bssid: mac_at(f, 16)?, |
| 145 | 193 | transmitter: mac_at(f, 10)?, |
| 146 | 194 | ssid, |
| 147 | 195 | channel, |
| 148 | 196 | security, |
| 197 | + akms, | |
| 149 | 198 | }) |
| 150 | 199 | } |
| 151 | 200 | |
| @@ -169,6 +218,179 @@ pub fn parse_probe_req(f: &[u8]) -> Option<(MacAddr, Option<String>)> { | ||
| 169 | 218 | Some((sta, ssid)) |
| 170 | 219 | } |
| 171 | 220 | |
| 221 | +/// Association/reassociation request → (station, bssid, ssid). | |
| 222 | +/// None for other/broken frames. SSID is None for hidden (`\0`-padded or | |
| 223 | +/// empty) networks. | |
| 224 | +pub fn parse_assoc_req(f: &[u8]) -> Option<(MacAddr, MacAddr, Option<String>)> { | |
| 225 | + let fc = u16le(f, 0)?; | |
| 226 | + let (ty, st) = type_subtype(fc); | |
| 227 | + // subtype 0 = assoc request, 1 = reassoc request; mgmt type only. | |
| 228 | + if ty != 0 || st > 1 { | |
| 229 | + return None; | |
| 230 | + } | |
| 231 | + let bssid = mac_at(f, 4)?; // addr1 | |
| 232 | + let sta = mac_at(f, 10)?; // addr2 | |
| 233 | + // Fixed params: capability(2) + listen interval(2) at offset 24, so IEs | |
| 234 | + // start at 28; reassoc adds current-AP MAC(6) → IEs start at 34. | |
| 235 | + let ie_off = if st == 0 { 28 } else { 34 }; | |
| 236 | + let mut ssid = None; | |
| 237 | + walk_ies(f, ie_off, |id, body| { | |
| 238 | + if id == IE_SSID { | |
| 239 | + // hidden networks send a zero or NUL-padded SSID | |
| 240 | + let s: &[u8] = body; | |
| 241 | + let meaningful = s.iter().take_while(|&&b| b != 0).count(); | |
| 242 | + if meaningful > 0 { | |
| 243 | + ssid = Some(String::from_utf8_lossy(&s[..meaningful]).into_owned()); | |
| 244 | + } | |
| 245 | + } | |
| 246 | + }); | |
| 247 | + // ensure the fixed params fit (frames shorter than ie_off are bogus) | |
| 248 | + if f.len() < ie_off { | |
| 249 | + return None; | |
| 250 | + } | |
| 251 | + Some((sta, bssid, ssid)) | |
| 252 | +} | |
| 253 | + | |
| 254 | +// --------------------------------------------------------------------------- | |
| 255 | +// device correlation (pairing rotated/randomized MACs of one radio) | |
| 256 | +// --------------------------------------------------------------------------- | |
| 257 | + | |
| 258 | +/// 12-bit per-transmitter sequence number (bytes 22-24, high nibble is the | |
| 259 | +/// fragment number). A device's sequence counter survives MAC rotation, so | |
| 260 | +/// near-continuity between two MACs' frames is a strong pairing witness. | |
| 261 | +pub fn seq_of(f: &[u8]) -> Option<u16> { | |
| 262 | + Some(u16le(f, 22)? >> 4) | |
| 263 | +} | |
| 264 | + | |
| 265 | +fn fnv_add(h: &mut u32, b: u8) { | |
| 266 | + *h ^= b as u32; | |
| 267 | + *h = h.wrapping_mul(0x0100_0193); | |
| 268 | +} | |
| 269 | + | |
| 270 | +/// Ordered-IE device fingerprint (probe/assoc request frames): FNV-1a over | |
| 271 | +/// the (tag, len) sequence, plus full payloads of the rate tags and the | |
| 272 | +/// OUI+type tuple of vendor IEs. Stable per driver/firmware build and | |
| 273 | +/// independent of the station's (possibly randomized) MAC and of which | |
| 274 | +/// SSIDs it is probing. Different drivers of the same model usually share | |
| 275 | +/// it, so it is a *probable* witness, not identity — pair it with UUID-E or | |
| 276 | +/// sequence continuity for certainty. | |
| 277 | +pub fn ie_fingerprint(f: &[u8], ie_off: usize) -> Option<u32> { | |
| 278 | + let mut h = 0x811c_9dc5u32; | |
| 279 | + let mut n = 0u32; | |
| 280 | + walk_ies(f, ie_off, |id, body| { | |
| 281 | + fnv_add(&mut h, id); | |
| 282 | + // SSID tag: content-agnostic. Directed and wildcard probes of the | |
| 283 | + // same radio alternate freely and differ only in this length; the | |
| 284 | + // probed-network signal comes from the group's SSID set instead. | |
| 285 | + if id != IE_SSID { | |
| 286 | + fnv_add(&mut h, body.len() as u8); | |
| 287 | + } | |
| 288 | + match id { | |
| 289 | + // rates + extended rates: full payload is model-specific | |
| 290 | + 1 | 50 => body.iter().for_each(|&b| fnv_add(&mut h, b)), | |
| 291 | + // vendor IE: OUI+type+len, not the (device-varying) payload | |
| 292 | + IE_VENDOR if body.len() >= 4 => body[..4].iter().for_each(|&b| fnv_add(&mut h, b)), | |
| 293 | + _ => {} | |
| 294 | + } | |
| 295 | + n += 1; | |
| 296 | + }); | |
| 297 | + (n > 0).then_some(h) | |
| 298 | +} | |
| 299 | + | |
| 300 | +/// WPS UUID-E (attribute 0x1047) from a WPS vendor IE, if present. A stable | |
| 301 | +/// per-device identifier leaked in probe requests by devices with WPS on — | |
| 302 | +/// an exact pairing witness across MAC rotation. | |
| 303 | +pub fn wps_uuid_e(f: &[u8], ie_off: usize) -> Option<[u8; 16]> { | |
| 304 | + // WPS vendor IE: OUI 00:50:f2, type 0x04; attributes are BE (id, len). | |
| 305 | + const WPS_OUI: [u8; 4] = [0x00, 0x50, 0xf2, 0x04]; | |
| 306 | + const ATTR_UUID_E: u16 = 0x1047; | |
| 307 | + let mut out = None; | |
| 308 | + walk_ies(f, ie_off, |id, body| { | |
| 309 | + if id != IE_VENDOR || body.len() < 4 || body[..4] != WPS_OUI { | |
| 310 | + return; | |
| 311 | + } | |
| 312 | + let mut cur = 4; | |
| 313 | + while cur + 4 <= body.len() { | |
| 314 | + let attr = u16::from_be_bytes([body[cur], body[cur + 1]]); | |
| 315 | + let len = u16::from_be_bytes([body[cur + 2], body[cur + 3]]) as usize; | |
| 316 | + let Some(val) = body.get(cur + 4..cur + 4 + len) else { | |
| 317 | + break; | |
| 318 | + }; | |
| 319 | + if attr == ATTR_UUID_E && len == 16 { | |
| 320 | + out = Some(val.try_into().expect("len checked")); | |
| 321 | + } | |
| 322 | + cur += 4 + len; | |
| 323 | + } | |
| 324 | + }); | |
| 325 | + out | |
| 326 | +} | |
| 327 | + | |
| 328 | +/// Device-correlation material parsed from a probe request. | |
| 329 | +#[derive(Clone, Debug, PartialEq, Eq)] | |
| 330 | +pub struct ProbeIdent { | |
| 331 | + pub sta: MacAddr, | |
| 332 | + pub ssid: Option<String>, // None for the wildcard probe | |
| 333 | + pub fingerprint: u32, | |
| 334 | + pub uuid: Option<[u8; 16]>, | |
| 335 | +} | |
| 336 | + | |
| 337 | +/// Same, from an association/reassociation request (adds the target bssid). | |
| 338 | +#[derive(Clone, Debug, PartialEq, Eq)] | |
| 339 | +pub struct AssocIdent { | |
| 340 | + pub sta: MacAddr, | |
| 341 | + pub bssid: MacAddr, | |
| 342 | + pub ssid: Option<String>, | |
| 343 | + pub fingerprint: u32, | |
| 344 | + pub uuid: Option<[u8; 16]>, | |
| 345 | +} | |
| 346 | + | |
| 347 | +/// Probe request with device-correlation material; None for other frames or | |
| 348 | +/// probes with an empty/malformed IE chain (fingerprint impossible). | |
| 349 | +pub fn parse_probe_ident(f: &[u8]) -> Option<ProbeIdent> { | |
| 350 | + let fc = u16le(f, 0)?; | |
| 351 | + if type_subtype(fc) != (0, 4) { | |
| 352 | + return None; | |
| 353 | + } | |
| 354 | + let sta = mac_at(f, 10)?; | |
| 355 | + let fingerprint = ie_fingerprint(f, 24)?; | |
| 356 | + let mut ssid = None; | |
| 357 | + walk_ies(f, 24, |id, body| { | |
| 358 | + if id == IE_SSID && !body.is_empty() { | |
| 359 | + ssid = Some(String::from_utf8_lossy(body).into_owned()); | |
| 360 | + } | |
| 361 | + }); | |
| 362 | + let uuid = wps_uuid_e(f, 24); | |
| 363 | + Some(ProbeIdent { sta, ssid, fingerprint, uuid }) | |
| 364 | +} | |
| 365 | + | |
| 366 | +/// Assoc/reassoc request with device-correlation material; None for other | |
| 367 | +/// frames. SSID is None for hidden (empty/NUL-padded) networks. | |
| 368 | +pub fn parse_assoc_ident(f: &[u8]) -> Option<AssocIdent> { | |
| 369 | + let fc = u16le(f, 0)?; | |
| 370 | + let (ty, st) = type_subtype(fc); | |
| 371 | + if ty != 0 || st > 1 { | |
| 372 | + return None; | |
| 373 | + } | |
| 374 | + let ie_off = if st == 0 { 28 } else { 34 }; | |
| 375 | + if f.len() < ie_off { | |
| 376 | + return None; | |
| 377 | + } | |
| 378 | + let bssid = mac_at(f, 4)?; | |
| 379 | + let sta = mac_at(f, 10)?; | |
| 380 | + let fingerprint = ie_fingerprint(f, ie_off)?; | |
| 381 | + let mut ssid = None; | |
| 382 | + walk_ies(f, ie_off, |id, body| { | |
| 383 | + if id == IE_SSID { | |
| 384 | + let meaningful = body.iter().take_while(|&&b| b != 0).count(); | |
| 385 | + if meaningful > 0 { | |
| 386 | + ssid = Some(String::from_utf8_lossy(&body[..meaningful]).into_owned()); | |
| 387 | + } | |
| 388 | + } | |
| 389 | + }); | |
| 390 | + let uuid = wps_uuid_e(f, ie_off); | |
| 391 | + Some(AssocIdent { sta, bssid, ssid, fingerprint, uuid }) | |
| 392 | +} | |
| 393 | + | |
| 172 | 394 | /// Parse deauth/disassoc → (from-ap MacAddr as transmitter, target addr1). |
| 173 | 395 | pub fn parse_deauth(f: &[u8]) -> Option<(MacAddr, MacAddr)> { |
| 174 | 396 | let fc = u16le(f, 0)?; |
| @@ -333,6 +555,19 @@ pub fn build_disassoc(ap: &MacAddr, target: &MacAddr, reason: u16) -> Vec<u8> { | ||
| 333 | 555 | v |
| 334 | 556 | } |
| 335 | 557 | |
| 558 | +/// Probe request sta → broadcast: empty `ssid` = wildcard (every AP on | |
| 559 | +/// the channel should answer with a probe response), otherwise directed. | |
| 560 | +/// Used by the injection canary: a response proves injected frames | |
| 561 | +/// actually radiate. | |
| 562 | +pub fn build_probe_req(ssid: &[u8], sa: &MacAddr) -> Vec<u8> { | |
| 563 | + let mut v = hdr3(0x40, &MacAddr::BROADCAST, sa, &MacAddr::BROADCAST, 0); | |
| 564 | + v.push(IE_SSID); | |
| 565 | + v.push(ssid.len().min(32) as u8); | |
| 566 | + v.extend_from_slice(&ssid[..ssid.len().min(32)]); | |
| 567 | + v.extend_from_slice(&[0x01, 0x04, 0x82, 0x84, 0x8b, 0x96]); // supported rates | |
| 568 | + v | |
| 569 | +} | |
| 570 | + | |
| 336 | 571 | /// Open-system authentication request sta → ap (algo 0, transaction 1). |
| 337 | 572 | pub fn build_auth_open(ap: &MacAddr, sta: &MacAddr, seq: u16) -> Vec<u8> { |
| 338 | 573 | let mut v = hdr3(0xB0, ap, sta, ap, seq); |
| @@ -414,6 +649,219 @@ mod tests { | ||
| 414 | 649 | assert_eq!(info.security, Security::Wpa2); |
| 415 | 650 | } |
| 416 | 651 | |
| 652 | + /// RSN IE with several AKM suites listed in order. | |
| 653 | + fn rsn_ie_multi(akm_types: &[u8]) -> Vec<u8> { | |
| 654 | + let mut b = vec![ | |
| 655 | + 0x01, 0x00, // version | |
| 656 | + 0x00, 0x0f, 0xac, 0x04, // group cipher CCMP | |
| 657 | + 0x01, 0x00, // pairwise count | |
| 658 | + 0x00, 0x0f, 0xac, 0x04, // pairwise CCMP | |
| 659 | + ]; | |
| 660 | + b.extend_from_slice(&(akm_types.len() as u16).to_le_bytes()); | |
| 661 | + for &t in akm_types { | |
| 662 | + b.extend_from_slice(&[0x00, 0x0f, 0xac, t]); | |
| 663 | + } | |
| 664 | + b.extend_from_slice(&[0x00, 0x00]); // rsn capabilities | |
| 665 | + let b = b.split_off(0); | |
| 666 | + ie(IE_RSN, &b) | |
| 667 | + } | |
| 668 | + | |
| 669 | + /// Beacon like `parafin_beacon` but with the RSN IE replaced by `rsn`. | |
| 670 | + fn beacon_with_rsn(rsn: Vec<u8>) -> Vec<u8> { | |
| 671 | + let mut v = parafin_beacon(); | |
| 672 | + v.splice(v.len() - rsn_ie(2).len().., rsn); | |
| 673 | + v | |
| 674 | + } | |
| 675 | + | |
| 676 | + #[test] | |
| 677 | + fn akm_list_parsed() { | |
| 678 | + // WPA2/WPA3 transition: PSK + SAE both advertised. | |
| 679 | + let f = beacon_with_rsn(rsn_ie_multi(&[2, 8])); | |
| 680 | + let info = parse_beacon_or_probe(&f).expect("beacon parses"); | |
| 681 | + assert_eq!(info.akms, vec![Akm::Psk, Akm::Sae]); | |
| 682 | + // security label logic untouched: SAE present → Wpa3 | |
| 683 | + assert_eq!(info.security, Security::Wpa3); | |
| 684 | + | |
| 685 | + // OWE (type 18) | |
| 686 | + let f = beacon_with_rsn(rsn_ie_multi(&[18])); | |
| 687 | + let info = parse_beacon_or_probe(&f).unwrap(); | |
| 688 | + assert_eq!(info.akms, vec![Akm::Owe]); | |
| 689 | + // no SAE → Wpa2 label | |
| 690 | + assert_eq!(info.security, Security::Wpa2); | |
| 691 | + | |
| 692 | + // unknown suite type → Other, PSK still mapped | |
| 693 | + let f = beacon_with_rsn(rsn_ie_multi(&[2, 99])); | |
| 694 | + let info = parse_beacon_or_probe(&f).unwrap(); | |
| 695 | + assert_eq!(info.akms, vec![Akm::Psk, Akm::Other(99)]); | |
| 696 | + | |
| 697 | + // plain WPA2-PSK beacon: single PSK entry | |
| 698 | + let info = parse_beacon_or_probe(¶fin_beacon()).unwrap(); | |
| 699 | + assert_eq!(info.akms, vec![Akm::Psk]); | |
| 700 | + | |
| 701 | + // open network: no security IEs → empty akms | |
| 702 | + let mut f = parafin_beacon(); | |
| 703 | + f.truncate(36); | |
| 704 | + f.extend_from_slice(&ie(IE_SSID, b"cafe")); | |
| 705 | + f[34] = 0x01; // clear privacy bit | |
| 706 | + f[35] = 0x04; | |
| 707 | + let info = parse_beacon_or_probe(&f).unwrap(); | |
| 708 | + assert_eq!(info.security, Security::Open); | |
| 709 | + assert_eq!(info.akms, Vec::<Akm>::new()); | |
| 710 | + } | |
| 711 | + | |
| 712 | + #[test] | |
| 713 | + fn wpa1_vendor_ie_yields_psk_akm() { | |
| 714 | + let mut f = parafin_beacon(); | |
| 715 | + f.truncate(36); | |
| 716 | + f.extend_from_slice(&ie(IE_SSID, b"legacy")); | |
| 717 | + // WPA_OUI vendor IE: oui+type, then version(2) — content beyond the | |
| 718 | + // OUI is not inspected, so the minimal fixture suffices. | |
| 719 | + f.extend_from_slice(&ie(IE_VENDOR, &[0x00, 0x50, 0xf2, 0x01, 0x01, 0x00])); | |
| 720 | + let info = parse_beacon_or_probe(&f).unwrap(); | |
| 721 | + assert_eq!(info.security, Security::Wpa); | |
| 722 | + assert_eq!(info.akms, vec![Akm::Psk]); | |
| 723 | + } | |
| 724 | + | |
| 725 | + #[test] | |
| 726 | + fn akms_deduped_across_wpa_and_rsn_ies() { | |
| 727 | + // Mixed WPA/WPA2 AP: RSN IE with PSK plus the WPA vendor IE — the | |
| 728 | + // vendor arm must not surface a duplicate PSK. | |
| 729 | + let mut f = beacon_with_rsn(rsn_ie_multi(&[2])); | |
| 730 | + f.extend_from_slice(&ie(IE_VENDOR, &[0x00, 0x50, 0xf2, 0x01, 0x01, 0x00])); | |
| 731 | + let info = parse_beacon_or_probe(&f).unwrap(); | |
| 732 | + assert_eq!(info.akms, vec![Akm::Psk], "no PSK+PSK duplication"); | |
| 733 | + } | |
| 734 | + | |
| 735 | + #[test] | |
| 736 | + fn seq_number_extracted() { | |
| 737 | + let mut f = parafin_beacon(); | |
| 738 | + // seq field at bytes 22-24: seq<<4 | frag | |
| 739 | + f[22] = 0x30; // seq 3, frag 0 | |
| 740 | + f[23] = 0x02; // → 0x230 >> 4 = 0x23 = 35 | |
| 741 | + assert_eq!(seq_of(&f), Some(0x23)); | |
| 742 | + assert_eq!(seq_of(&f[..20]), None); | |
| 743 | + } | |
| 744 | + | |
| 745 | + /// Probe builder mirroring the scanner tests' shape. | |
| 746 | + fn probe_with(sta: &MacAddr, ssid: Option<&str>, ies: &[Vec<u8>], seq: u16) -> Vec<u8> { | |
| 747 | + let mut v = Vec::new(); | |
| 748 | + v.extend_from_slice(&0x0040u16.to_le_bytes()); | |
| 749 | + v.extend_from_slice(&0u16.to_le_bytes()); | |
| 750 | + v.extend_from_slice(&MacAddr::BROADCAST.0); | |
| 751 | + v.extend_from_slice(&sta.0); | |
| 752 | + v.extend_from_slice(&MacAddr::BROADCAST.0); | |
| 753 | + v.extend_from_slice(&(seq << 4).to_le_bytes()); | |
| 754 | + match ssid { | |
| 755 | + Some(s) => v.extend_from_slice(&ie(IE_SSID, s.as_bytes())), | |
| 756 | + None => v.extend_from_slice(&ie(IE_SSID, b"")), | |
| 757 | + } | |
| 758 | + for b in ies { | |
| 759 | + v.extend_from_slice(b); | |
| 760 | + } | |
| 761 | + v | |
| 762 | + } | |
| 763 | + | |
| 764 | + #[test] | |
| 765 | + fn fingerprint_stable_directed_vs_wildcard() { | |
| 766 | + // The same radio alternating directed/wildcard probes must hash | |
| 767 | + // identically; a different IE chain must not. | |
| 768 | + let rates = ie(1, &[0x82, 0x84, 0x8b, 0x96]); | |
| 769 | + let f1 = probe_with(&STA, Some("parafin"), &[rates.clone()], 7); | |
| 770 | + let f2 = probe_with(&STA, None, &[rates.clone()], 8); | |
| 771 | + let i1 = parse_probe_ident(&f1).expect("parses"); | |
| 772 | + let i2 = parse_probe_ident(&f2).expect("parses"); | |
| 773 | + assert_eq!(i1.fingerprint, i2.fingerprint); | |
| 774 | + assert_eq!(i1.ssid.as_deref(), Some("parafin")); | |
| 775 | + assert_eq!(i2.ssid, None); | |
| 776 | + | |
| 777 | + let other = probe_with(&STA, None, &[ie(1, &[0x82, 0x84])], 9); | |
| 778 | + let i3 = parse_probe_ident(&other).expect("parses"); | |
| 779 | + assert_ne!(i1.fingerprint, i3.fingerprint); | |
| 780 | + | |
| 781 | + // Off a probe frame entirely → None. | |
| 782 | + assert!(parse_probe_ident(¶fin_beacon()).is_none()); | |
| 783 | + } | |
| 784 | + | |
| 785 | + #[test] | |
| 786 | + fn wps_uuid_e_parsed_from_probe() { | |
| 787 | + let uuid = [0xabu8; 16]; | |
| 788 | + let mut wps_body = vec![0x00, 0x50, 0xf2, 0x04]; | |
| 789 | + wps_body.extend_from_slice(&0x1047u16.to_be_bytes()); | |
| 790 | + wps_body.extend_from_slice(&16u16.to_be_bytes()); | |
| 791 | + wps_body.extend_from_slice(&uuid); | |
| 792 | + let wps = ie(IE_VENDOR, &wps_body); | |
| 793 | + let f = probe_with(&STA, None, &[wps], 7); | |
| 794 | + let ident = parse_probe_ident(&f).expect("parses"); | |
| 795 | + assert_eq!(ident.uuid, Some(uuid)); | |
| 796 | + // Truncated attribute body → no uuid, no panic. | |
| 797 | + let short = ie(IE_VENDOR, &[0x00, 0x50, 0xf2, 0x04, 0x10, 0x47, 0x00, 0x10, 0xaa, 0xbb]); | |
| 798 | + let f = probe_with(&STA, None, &[short], 7); | |
| 799 | + assert_eq!(parse_probe_ident(&f).unwrap().uuid, None); | |
| 800 | + } | |
| 801 | + | |
| 802 | + #[test] | |
| 803 | + fn assoc_ident_parsed() { | |
| 804 | + let f = build_assoc_req(&AP, &STA, b"testap"); | |
| 805 | + let ident = parse_assoc_ident(&f).expect("assoc ident parses"); | |
| 806 | + assert_eq!(ident.sta, STA); | |
| 807 | + assert_eq!(ident.bssid, AP); | |
| 808 | + assert_eq!(ident.ssid.as_deref(), Some("testap")); | |
| 809 | + assert_eq!(ident.uuid, None); | |
| 810 | + assert!(parse_assoc_ident(¶fin_beacon()).is_none()); | |
| 811 | + for cut in 0..f.len() { | |
| 812 | + let _ = parse_assoc_ident(&f[..cut]); | |
| 813 | + } | |
| 814 | + } | |
| 815 | + | |
| 816 | + #[test] | |
| 817 | + fn assoc_req_parsed() { | |
| 818 | + // assoc request: addr1=bssid(AP), addr2=sta, ssid "testap" | |
| 819 | + let f = build_assoc_req(&AP, &STA, b"testap"); | |
| 820 | + let (sta, bssid, ssid) = parse_assoc_req(&f).expect("assoc-req parses"); | |
| 821 | + assert_eq!(sta, STA); | |
| 822 | + assert_eq!(bssid, AP); | |
| 823 | + assert_eq!(ssid.as_deref(), Some("testap")); | |
| 824 | + | |
| 825 | + // reassoc request (subtype 1): extra current-AP field before IEs | |
| 826 | + let mut r = hdr3(0x10, &AP, &STA, &AP, 0); | |
| 827 | + r.extend_from_slice(&0x0431u16.to_le_bytes()); // capability | |
| 828 | + r.extend_from_slice(&10u16.to_le_bytes()); // listen interval | |
| 829 | + r.extend_from_slice(&STA.0); // current AP (assoc) — arbitrary MAC here | |
| 830 | + r.extend_from_slice(&ie(IE_SSID, b"home-net")); | |
| 831 | + let (sta, bssid, ssid) = parse_assoc_req(&r).expect("reassoc-req parses"); | |
| 832 | + assert_eq!(sta, STA); | |
| 833 | + assert_eq!(bssid, AP); | |
| 834 | + assert_eq!(ssid.as_deref(), Some("home-net")); | |
| 835 | + | |
| 836 | + // empty SSID → None (hidden/wildcard attempt) | |
| 837 | + let mut g = hdr3(0x00, &AP, &STA, &AP, 0); | |
| 838 | + g.extend_from_slice(&0x0431u16.to_le_bytes()); | |
| 839 | + g.extend_from_slice(&10u16.to_le_bytes()); | |
| 840 | + g.extend_from_slice(&ie(IE_SSID, b"")); | |
| 841 | + let (_, _, ssid) = parse_assoc_req(&g).unwrap(); | |
| 842 | + assert_eq!(ssid, None); | |
| 843 | + | |
| 844 | + // NUL-padded SSID → None | |
| 845 | + let mut h = hdr3(0x00, &AP, &STA, &AP, 0); | |
| 846 | + h.extend_from_slice(&0x0431u16.to_le_bytes()); | |
| 847 | + h.extend_from_slice(&10u16.to_le_bytes()); | |
| 848 | + h.extend_from_slice(&ie(IE_SSID, &[0x00, 0x00, 0x00])); | |
| 849 | + let (_, _, ssid) = parse_assoc_req(&h).unwrap(); | |
| 850 | + assert_eq!(ssid, None); | |
| 851 | + | |
| 852 | + // truncated frames: header cut anywhere → None or no panic | |
| 853 | + for cut in 0..f.len() { | |
| 854 | + let _ = parse_assoc_req(&f[..cut]); | |
| 855 | + } | |
| 856 | + // frame too short to hold the fixed params → None | |
| 857 | + assert_eq!(parse_assoc_req(&f[..24]), None); | |
| 858 | + | |
| 859 | + // non-assoc frames rejected | |
| 860 | + assert_eq!(parse_assoc_req(¶fin_beacon()), None); | |
| 861 | + let pr = build_probe_req(b"x", &STA); | |
| 862 | + assert_eq!(parse_assoc_req(&pr), None); | |
| 863 | + } | |
| 864 | + | |
| 417 | 865 | #[test] |
| 418 | 866 | fn beacon_security_matrix() { |
| 419 | 867 | // WPA3: same beacon but SAE AKM |
| @@ -499,6 +947,18 @@ mod tests { | ||
| 499 | 947 | let (sta, ssid) = parse_probe_req(&f).unwrap(); |
| 500 | 948 | assert_eq!(sta, STA); |
| 501 | 949 | assert_eq!(ssid.as_deref(), Some("parafin")); |
| 950 | + } | |
| 951 | + | |
| 952 | + #[test] | |
| 953 | + fn build_probe_req_roundtrips_wildcard_and_directed() { | |
| 954 | + let wild = build_probe_req(&[], &STA); | |
| 955 | + let (sta, ssid) = parse_probe_req(&wild).unwrap(); | |
| 956 | + assert_eq!(sta, STA); | |
| 957 | + assert_eq!(ssid, None, "wildcard SSID (len 0) parses as None"); | |
| 958 | + let dir = build_probe_req(b"parafin", &STA); | |
| 959 | + let (sta, ssid) = parse_probe_req(&dir).unwrap(); | |
| 960 | + assert_eq!(sta, STA); | |
| 961 | + assert_eq!(ssid.as_deref(), Some("parafin")); | |
| 502 | 962 | |
| 503 | 963 | // broadcast probe: zero-len SSID → None |
| 504 | 964 | let mut b = hdr3(0x40, &MacAddr::BROADCAST, &STA, &MacAddr::BROADCAST, 0); |