forge
Explore
Log in

Don't you dare go Hollow

Cracker unusable after stopping capture — keep Backend alive via stop_radio

Browse files at this commit

50b1686b18722940f96c08bc88b957f51265e01fAhmet Kaan GümüşParent: 795bcd1
  • fix
    • cracker unusable after stopping capture — keep Backend alive via stop_radio
    • gate attacks on live radio
Show full message
fix: cracker unusable after stopping capture — keep Backend alive via stop_radio; gate attacks on live radio
src/backend.rsmodified+21 -0
@@ -293,6 +293,27 @@ impl Backend {
293293 });
294294 }
295295
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+
296317 /// Stop every worker, restore the original interface to managed mode
297318 /// (deleting the `<orig>mon` vif if one was created), and join all
298319 /// threads. Idempotent: safe to call more than once / from `Drop`.
src/ui/app.rsmodified+16 -7
@@ -238,14 +238,18 @@ impl AppRoot {
238238 cx.notify();
239239 return;
240240 }
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+ }
242252 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");
249253 cx.notify();
250254 } else {
251255 if !self.is_root {
@@ -271,6 +275,11 @@ impl AppRoot {
271275 "NetworkManager is active — only your connected network may be visible; stop it from the header".into(),
272276 );
273277 }
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;
274283 let ifname = self.state.ifname.clone();
275284 match Backend::start_scan(&ifname, self.tx.clone()) {
276285 Ok(be) => {
src/ui/attacks.rsmodified+11 -5
@@ -115,9 +115,9 @@ fn capture_handshake(view: &Entity<AppRoot>, _window: &mut Window, cx: &mut gpui
115115 if app.attacking_handshake {
116116 return;
117117 }
118- if !app.is_mock && app.backend.is_none() {
118+ if !app.is_mock && !app.state.iface_running {
119119 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)");
121121 cx.notify();
122122 return;
123123 }
@@ -203,9 +203,9 @@ fn pmkid_attack(view: &Entity<AppRoot>, _window: &mut Window, cx: &mut gpui::App
203203 if app.attacking_pmkid {
204204 return;
205205 }
206- if !app.is_mock && app.backend.is_none() {
206+ if !app.is_mock && !app.state.iface_running {
207207 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)");
209209 cx.notify();
210210 return;
211211 }
@@ -276,6 +276,12 @@ fn deauth(view: &Entity<AppRoot>, _window: &mut Window, cx: &mut gpui::App) {
276276 .unwrap_or(16);
277277
278278 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+ }
279285 let Some(be) = &app.backend else {
280286 app.state
281287 .push_log("deauth: start capture first (the backend owns the radio)");
@@ -390,7 +396,7 @@ pub fn render(
390396 let no_target = app.selected.is_none();
391397 // Real mode without a running capture has no radio: block the buttons
392398 // (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;
394400 let blocked = no_target || no_backend;
395401 let hs_running = app.attacking_handshake;
396402 let pm_running = app.attacking_pmkid;