Cracker unusable after stopping capture — keep Backend alive via stop_radio
Browse files at this commit50b1686b18722940f96c08bc88b957f51265e01fParent: 795bcd1- fix
- cracker unusable after stopping capture — keep Backend alive via stop_radio
- gate attacks on live radio
3 changed files +48 -12
- src/backend.rs +21 -0
- src/ui/app.rs +16 -7
- src/ui/attacks.rs +11 -5
src/backend.rsmodified+21 -0
| @@ -293,6 +293,27 @@ impl Backend { | ||
| 293 | 293 | }); |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | + /// Stop radio work (scanner + attack workers) and restore managed | |
| 297 | + /// mode, but KEEP the Backend alive so the cracker can still run | |
| 298 | + /// afterwards: the UI keeps `Some(backend)` after "Stop capture". | |
| 299 | + /// A still-running crack job is untouched (it has no radio use). | |
| 300 | + /// Idempotent; a later `start_scan` simply replaces this Backend. | |
| 301 | + pub fn stop_radio(&self) { | |
| 302 | + self.stop.store(true, Ordering::Release); | |
| 303 | + if let Some(mon) = &self.mon_ifname { | |
| 304 | + if let Err(e) = iface::to_managed(mon) { | |
| 305 | + eprintln!("wifilab: to_managed({mon}) failed: {e:#}"); | |
| 306 | + } | |
| 307 | + } | |
| 308 | + // Safe to join radio handles here: the UI disables the capture | |
| 309 | + // toggle while a crack runs, so no unfinished crack thread sits | |
| 310 | + // in this list. | |
| 311 | + let handles = std::mem::take(&mut *self.handles.lock().expect("handles poisoned")); | |
| 312 | + for h in handles { | |
| 313 | + let _ = h.join(); | |
| 314 | + } | |
| 315 | + } | |
| 316 | + | |
| 296 | 317 | /// Stop every worker, restore the original interface to managed mode |
| 297 | 318 | /// (deleting the `<orig>mon` vif if one was created), and join all |
| 298 | 319 | /// threads. Idempotent: safe to call more than once / from `Drop`. |
src/ui/app.rsmodified+16 -7
| @@ -238,14 +238,18 @@ impl AppRoot { | ||
| 238 | 238 | cx.notify(); |
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | - if let Some(be) = self.backend.take() { | |
| 241 | + if self.state.iface_running { | |
| 242 | + // STOP: release the radio but KEEP the Backend alive — the | |
| 243 | + // cracker needs it (cracking has no radio use). `stop_radio` | |
| 244 | + // restores managed mode and joins the radio workers only. | |
| 245 | + if let Some(be) = &self.backend { | |
| 246 | + self.state.push_log("ui: stopping capture, restoring managed mode…"); | |
| 247 | + cx.notify(); | |
| 248 | + be.stop_radio(); | |
| 249 | + self.state | |
| 250 | + .push_log("ui: capture stopped, interface restored (cracker stays available)"); | |
| 251 | + } | |
| 242 | 252 | self.state.iface_running = false; |
| 243 | - // The crack job (if any) has its own stop flag and keeps | |
| 244 | - // running; it never touches the radio. | |
| 245 | - self.state.push_log("ui: stopping capture, restoring managed mode…"); | |
| 246 | - cx.notify(); | |
| 247 | - be.shutdown(); | |
| 248 | - self.state.push_log("ui: capture stopped, interface restored"); | |
| 249 | 253 | cx.notify(); |
| 250 | 254 | } else { |
| 251 | 255 | if !self.is_root { |
| @@ -271,6 +275,11 @@ impl AppRoot { | ||
| 271 | 275 | "NetworkManager is active — only your connected network may be visible; stop it from the header".into(), |
| 272 | 276 | ); |
| 273 | 277 | } |
| 278 | + // A Backend kept alive for the cracker from a previous capture | |
| 279 | + // would tear down our new monitor mode in its `Drop` (it | |
| 280 | + // restores managed mode). Drop it BEFORE the fresh | |
| 281 | + // `start_scan` switches the interface up in monitor mode. | |
| 282 | + self.backend = None; | |
| 274 | 283 | let ifname = self.state.ifname.clone(); |
| 275 | 284 | match Backend::start_scan(&ifname, self.tx.clone()) { |
| 276 | 285 | Ok(be) => { |
src/ui/attacks.rsmodified+11 -5
| @@ -115,9 +115,9 @@ fn capture_handshake(view: &Entity<AppRoot>, _window: &mut Window, cx: &mut gpui | ||
| 115 | 115 | if app.attacking_handshake { |
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | - if !app.is_mock && app.backend.is_none() { | |
| 118 | + if !app.is_mock && !app.state.iface_running { | |
| 119 | 119 | app.state |
| 120 | - .push_log("handshake: start capture first (the backend owns the radio)"); | |
| 120 | + .push_log("handshake: start capture first (attacks need the radio in monitor mode)"); | |
| 121 | 121 | cx.notify(); |
| 122 | 122 | return; |
| 123 | 123 | } |
| @@ -203,9 +203,9 @@ fn pmkid_attack(view: &Entity<AppRoot>, _window: &mut Window, cx: &mut gpui::App | ||
| 203 | 203 | if app.attacking_pmkid { |
| 204 | 204 | return; |
| 205 | 205 | } |
| 206 | - if !app.is_mock && app.backend.is_none() { | |
| 206 | + if !app.is_mock && !app.state.iface_running { | |
| 207 | 207 | app.state |
| 208 | - .push_log("pmkid: start capture first (the backend owns the radio)"); | |
| 208 | + .push_log("pmkid: start capture first (attacks need the radio in monitor mode)"); | |
| 209 | 209 | cx.notify(); |
| 210 | 210 | return; |
| 211 | 211 | } |
| @@ -276,6 +276,12 @@ fn deauth(view: &Entity<AppRoot>, _window: &mut Window, cx: &mut gpui::App) { | ||
| 276 | 276 | .unwrap_or(16); |
| 277 | 277 | |
| 278 | 278 | if !app.is_mock { |
| 279 | + if !app.state.iface_running { | |
| 280 | + app.state | |
| 281 | + .push_log("deauth: start capture first (injection needs monitor mode)"); | |
| 282 | + cx.notify(); | |
| 283 | + return; | |
| 284 | + } | |
| 279 | 285 | let Some(be) = &app.backend else { |
| 280 | 286 | app.state |
| 281 | 287 | .push_log("deauth: start capture first (the backend owns the radio)"); |
| @@ -390,7 +396,7 @@ pub fn render( | ||
| 390 | 396 | let no_target = app.selected.is_none(); |
| 391 | 397 | // Real mode without a running capture has no radio: block the buttons |
| 392 | 398 | // (a matching hint sits next to them). |
| 393 | - let no_backend = !app.is_mock && app.backend.is_none(); | |
| 399 | + let no_backend = !app.is_mock && !app.state.iface_running; | |
| 394 | 400 | let blocked = no_target || no_backend; |
| 395 | 401 | let hs_running = app.attacking_handshake; |
| 396 | 402 | let pm_running = app.attacking_pmkid; |