From 50b1686b18722940f96c08bc88b957f51265e01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 12 Oct 2026 19:59:54 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20cracker=20unusable=20after=20stopping=20?= =?UTF-8?q?capture=20=E2=80=94=20keep=20Backend=20alive=20via=20stop=5Frad?= =?UTF-8?q?io;=20gate=20attacks=20on=20live=20radio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend.rs | 21 +++++++++++++++++++++ src/ui/app.rs | 23 ++++++++++++++++------- src/ui/attacks.rs | 16 +++++++++++----- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/backend.rs b/src/backend.rs index 9563e39..9b81c96 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -293,6 +293,27 @@ impl Backend { }); } + /// Stop radio work (scanner + attack workers) and restore managed + /// mode, but KEEP the Backend alive so the cracker can still run + /// afterwards: the UI keeps `Some(backend)` after "Stop capture". + /// A still-running crack job is untouched (it has no radio use). + /// Idempotent; a later `start_scan` simply replaces this Backend. + pub fn stop_radio(&self) { + self.stop.store(true, Ordering::Release); + if let Some(mon) = &self.mon_ifname { + if let Err(e) = iface::to_managed(mon) { + eprintln!("wifilab: to_managed({mon}) failed: {e:#}"); + } + } + // Safe to join radio handles here: the UI disables the capture + // toggle while a crack runs, so no unfinished crack thread sits + // in this list. + let handles = std::mem::take(&mut *self.handles.lock().expect("handles poisoned")); + for h in handles { + let _ = h.join(); + } + } + /// Stop every worker, restore the original interface to managed mode /// (deleting the `mon` vif if one was created), and join all /// threads. Idempotent: safe to call more than once / from `Drop`. diff --git a/src/ui/app.rs b/src/ui/app.rs index 1143492..4114ac2 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -238,14 +238,18 @@ impl AppRoot { cx.notify(); return; } - if let Some(be) = self.backend.take() { + if self.state.iface_running { + // STOP: release the radio but KEEP the Backend alive — the + // cracker needs it (cracking has no radio use). `stop_radio` + // restores managed mode and joins the radio workers only. + if let Some(be) = &self.backend { + self.state.push_log("ui: stopping capture, restoring managed mode…"); + cx.notify(); + be.stop_radio(); + self.state + .push_log("ui: capture stopped, interface restored (cracker stays available)"); + } self.state.iface_running = false; - // The crack job (if any) has its own stop flag and keeps - // running; it never touches the radio. - self.state.push_log("ui: stopping capture, restoring managed mode…"); - cx.notify(); - be.shutdown(); - self.state.push_log("ui: capture stopped, interface restored"); cx.notify(); } else { if !self.is_root { @@ -271,6 +275,11 @@ impl AppRoot { "NetworkManager is active — only your connected network may be visible; stop it from the header".into(), ); } + // A Backend kept alive for the cracker from a previous capture + // would tear down our new monitor mode in its `Drop` (it + // restores managed mode). Drop it BEFORE the fresh + // `start_scan` switches the interface up in monitor mode. + self.backend = None; let ifname = self.state.ifname.clone(); match Backend::start_scan(&ifname, self.tx.clone()) { Ok(be) => { diff --git a/src/ui/attacks.rs b/src/ui/attacks.rs index bb6e3ec..aaa6ec8 100644 --- a/src/ui/attacks.rs +++ b/src/ui/attacks.rs @@ -115,9 +115,9 @@ fn capture_handshake(view: &Entity, _window: &mut Window, cx: &mut gpui if app.attacking_handshake { return; } - if !app.is_mock && app.backend.is_none() { + if !app.is_mock && !app.state.iface_running { app.state - .push_log("handshake: start capture first (the backend owns the radio)"); + .push_log("handshake: start capture first (attacks need the radio in monitor mode)"); cx.notify(); return; } @@ -203,9 +203,9 @@ fn pmkid_attack(view: &Entity, _window: &mut Window, cx: &mut gpui::App if app.attacking_pmkid { return; } - if !app.is_mock && app.backend.is_none() { + if !app.is_mock && !app.state.iface_running { app.state - .push_log("pmkid: start capture first (the backend owns the radio)"); + .push_log("pmkid: start capture first (attacks need the radio in monitor mode)"); cx.notify(); return; } @@ -276,6 +276,12 @@ fn deauth(view: &Entity, _window: &mut Window, cx: &mut gpui::App) { .unwrap_or(16); if !app.is_mock { + if !app.state.iface_running { + app.state + .push_log("deauth: start capture first (injection needs monitor mode)"); + cx.notify(); + return; + } let Some(be) = &app.backend else { app.state .push_log("deauth: start capture first (the backend owns the radio)"); @@ -390,7 +396,7 @@ pub fn render( let no_target = app.selected.is_none(); // Real mode without a running capture has no radio: block the buttons // (a matching hint sits next to them). - let no_backend = !app.is_mock && app.backend.is_none(); + let no_backend = !app.is_mock && !app.state.iface_running; let blocked = no_target || no_backend; let hs_running = app.attacking_handshake; let pm_running = app.attacking_pmkid;