airgorah 0.6.0

A WiFi auditing software that can perform deauth attacks and passwords cracking
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
use crate::backend;
use crate::frontend::interfaces::*;
use crate::frontend::*;
use crate::globals;
use crate::list_store_get;
use crate::types::*;

use glib::clone;
use glib::ControlFlow;
use gtk4::gdk_pixbuf::Pixbuf;
use gtk4::prelude::*;
use gtk4::*;
use std::io::BufReader;
use std::rc::Rc;
use std::time::Duration;

fn list_store_find(storage: &ListStore, pos: i32, to_match: &str) -> Option<TreeIter> {
    let mut iter = storage.iter_first();

    while let Some(it) = iter {
        let value = list_store_get!(storage, &it, pos, String);

        if value == to_match {
            return Some(it);
        }

        iter = match storage.iter_next(&it) {
            true => Some(it),
            false => None,
        }
    }

    None
}

fn connect_about_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .about_button
        .connect_clicked(clone!(@strong app_data => move |_| {
        let ico = Pixbuf::from_read(BufReader::new(globals::APP_ICON)).unwrap();
        let des = "A WiFi auditing software that can perform deauth attacks and passwords cracking";

        AboutDialog::builder()
            .program_name("Airgorah")
            .version(globals::VERSION)
            .authors(vec!["Martin OLIVIER (martin.olivier@live.fr)".to_string()])
            .copyright("Copyright (c) Martin OLIVIER")
            .license_type(License::MitX11)
            .logo(&Picture::for_pixbuf(&ico).paintable().unwrap())
            .comments(des)
            .website_label("https://github.com/martin-olivier/airgorah")
            .transient_for(&app_data.app_gui.window)
            .modal(true)
            .build()
            .show();
        }));
}

fn connect_update_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .update_button
        .connect_clicked(clone!(@strong app_data => move |_| {
            let version = globals::VERSION;
            let new_version = globals::NEW_VERSION.lock().unwrap();

            let new_version = match new_version.as_ref() {
                Some(result) => result.clone(),
                None => "unknown".to_string(),
            };

            UpdateDialog::spawn(&app_data.app_gui.window, version, &new_version);
        }));
}

fn connect_decrypt_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .decrypt_button
        .connect_clicked(clone!(@strong app_data => move |_| {
            app_data.decrypt_gui.show(None);
        }));
}

fn connect_settings_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .settings_button
        .connect_clicked(clone!(@strong app_data => move |_| {
            app_data.settings_gui.show();
        }));
}

fn connect_hopping_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .hopping_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            app_data.app_gui.channel_filter_entry.set_text("");
        }));
}

fn connect_focus_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .focus_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            if let Some((_, iter)) = app_data.app_gui.aps_view.selection().selected() {
                let channel = list_store_get!(app_data.app_gui.aps_model, &iter, 3, i32);
                app_data.app_gui.channel_filter_entry.set_text(&channel.to_string());
            }
        }));
}

fn connect_previous_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .previous_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            let iter = match app_data.app_gui.aps_view.selection().selected() {
                Some((_, iter)) => iter,
                None => return,
            };

            let prev_iter = iter;
            if !app_data.app_gui.aps_model.iter_previous(&prev_iter) {
                return;
            }

            let path = app_data.app_gui.aps_model.path(&prev_iter);
            app_data.app_gui.aps_view.selection().select_iter(&prev_iter);
            app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
            app_data.app_gui.cli_model.clear();

            app_data.app_gui.focus_but.set_sensitive(true);
            app_data.app_gui.deauth_but.set_sensitive(true);
        }));
}

fn connect_next_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .next_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            let iter = match app_data.app_gui.aps_view.selection().selected() {
                Some((_, iter)) => iter,
                None => return,
            };

            let next_iter = iter;
            if !app_data.app_gui.aps_model.iter_next(&next_iter) {
                return;
            }

            let path = app_data.app_gui.aps_model.path(&next_iter);
            app_data.app_gui.aps_view.selection().select_iter(&next_iter);
            app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
            app_data.app_gui.cli_model.clear();

            app_data.app_gui.focus_but.set_sensitive(true);
            app_data.app_gui.deauth_but.set_sensitive(true);
        }));
}

fn connect_top_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .top_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            let first_iter = match app_data.app_gui.aps_model.iter_first() {
                Some(iter) => iter,
                None => return,
            };

            let path = app_data.app_gui.aps_model.path(&first_iter);
            app_data.app_gui.aps_view.selection().select_iter(&first_iter);
            app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
            app_data.app_gui.cli_model.clear();

            app_data.app_gui.focus_but.set_sensitive(true);
            app_data.app_gui.deauth_but.set_sensitive(true);
        }));
}

fn connect_bottom_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .bottom_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            let iter = match app_data.app_gui.aps_model.iter_first() {
                Some(iter) => iter,
                None => return,
            };

            let mut last_iter = iter;

            while app_data.app_gui.aps_model.iter_next(&iter) {
                last_iter = iter;
            }

            let path = app_data.app_gui.aps_model.path(&last_iter);
            app_data.app_gui.aps_view.selection().select_iter(&last_iter);
            app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
            app_data.app_gui.cli_model.clear();

            app_data.app_gui.focus_but.set_sensitive(true);
            app_data.app_gui.deauth_but.set_sensitive(true);
        }));
}

fn start_app_refresh(app_data: Rc<AppData>) {
    glib::timeout_add_local(
        Duration::from_millis(100),
        clone!(@strong app_data => move || {
            match app_data.app_gui.aps_view.selection().selected() {
                Some((_, iter)) => {
                    let bssid = list_store_get!(app_data.app_gui.aps_model, &iter, 1, String);
                    let attack_pool = backend::get_attack_pool();

                    match attack_pool.contains_key(&bssid) {
                        true => {
                            app_data.app_gui.deauth_but.set_icon(globals::STOP_ICON);
                        }
                        false => {
                            app_data.app_gui.deauth_but.set_icon(globals::DEAUTH_ICON);
                        }
                    }

                    match backend::get_aps()[&bssid].handshake {
                        true => app_data.app_gui.capture_but.set_sensitive(true),
                        false => app_data.app_gui.capture_but.set_sensitive(false),
                    }
                }
                None => {
                    app_data.app_gui.deauth_but.set_icon(globals::DEAUTH_ICON);
                }
            };

            match backend::get_aps().is_empty() {
                true => {
                    app_data.app_gui.restart_but.set_sensitive(false);
                    app_data.app_gui.export_but.set_sensitive(false);
                    app_data.app_gui.report_but.set_sensitive(false);
                    app_data.app_gui.top_but.set_sensitive(false);
                    app_data.app_gui.bottom_but.set_sensitive(false);
                    app_data.app_gui.previous_but.set_sensitive(false);
                    app_data.app_gui.next_but.set_sensitive(false);
                }
                false => {
                    app_data.app_gui.restart_but.set_sensitive(true);
                    app_data.app_gui.export_but.set_sensitive(true);
                    app_data.app_gui.report_but.set_sensitive(true);
                    app_data.app_gui.top_but.set_sensitive(true);
                    app_data.app_gui.bottom_but.set_sensitive(true);
                    app_data.app_gui.previous_but.set_sensitive(true);
                    app_data.app_gui.next_but.set_sensitive(true);
                }
            }

            let aps = backend::get_airodump_data();

            for (bssid, ap) in aps.iter() {
                if !backend::get_settings().display_hidden_ap && ap.hidden {
                    if let Some(iter) =
                        list_store_find(app_data.app_gui.aps_model.as_ref(), 1, bssid.as_str())
                    {
                        app_data.app_gui.aps_model.remove(&iter);
                    }
                    continue;
                }

                let it = match list_store_find(app_data.app_gui.aps_model.as_ref(), 1, bssid.as_str()) {
                    Some(it) => it,
                    None => app_data.app_gui.aps_model.append(),
                };

                let background_color = match backend::get_attack_pool().contains_key(bssid) {
                    true => gdk::RGBA::RED,
                    false => gdk::RGBA::new(0.0, 0.0, 0.0, 0.0),
                };

                let handshake_status = match ap.handshake {
                    true => "Captured",
                    false => "",
                };

                app_data.app_gui.aps_model.set(
                    &it,
                    &[
                        (0, &ap.essid),
                        (1, &ap.bssid),
                        (2, &ap.band),
                        (3, &ap.channel.parse::<i32>().unwrap_or(-1)),
                        (4, &ap.speed.parse::<i32>().unwrap_or(-1)),
                        (5, &ap.power.parse::<i32>().unwrap_or(-1)),
                        (6, &ap.privacy),
                        (7, &(ap.clients.len() as i32)),
                        (8, &ap.first_time_seen),
                        (9, &ap.last_time_seen),
                        (10, &handshake_status),
                        (11, &background_color.to_str()),
                    ],
                );
            }

            if let Some((_, iter)) = app_data.app_gui.aps_view.selection().selected() {
                let bssid = list_store_get!(app_data.app_gui.aps_model, &iter, 1, String);
                let clients = &aps[&bssid].clients;

                for (_, cli) in clients.iter() {
                    let it =
                        match list_store_find(app_data.app_gui.cli_model.as_ref(), 0, cli.mac.as_str())
                        {
                            Some(it) => it,
                            None => app_data.app_gui.cli_model.append(),
                        };

                    let background_color = match backend::get_attack_pool().get(&bssid) {
                        Some((_, attack_target)) => match &attack_target {
                            AttackedClients::All(_) => gdk::RGBA::RED,
                            AttackedClients::Selection(selection) => {
                                let mut color = gdk::RGBA::new(0.0, 0.0, 0.0, 0.0);

                                for (sel, _) in selection.iter() {
                                    if sel == cli.mac.as_str() {
                                        color = gdk::RGBA::RED;
                                    }
                                }
                                color
                            }
                        },
                        None => gdk::RGBA::new(0.0, 0.0, 0.0, 0.0),
                    };

                    app_data.app_gui.cli_model.set(
                        &it,
                        &[
                            (0, &cli.mac),
                            (1, &cli.packets.parse::<i32>().unwrap_or(-1)),
                            (2, &cli.power.parse::<i32>().unwrap_or(-1)),
                            (3, &cli.first_time_seen),
                            (4, &cli.last_time_seen),
                            (5, &background_color.to_str()),
                        ],
                    );

                    if app_data.deauth_gui.window.is_visible() && list_store_find(app_data.deauth_gui.store.as_ref(), 1, cli.mac.as_str()).is_none() {
                        app_data.deauth_gui.store.set(&app_data.deauth_gui.store.append(), &[(0, &false), (1, &cli.mac)]);
                    }
                }
            }

            ControlFlow::Continue
        }),
    );

    glib::timeout_add_local(
        Duration::from_millis(1000),
        clone!(@strong app_data => move || {
            let mut updater = globals::UPDATE_PROC.lock().unwrap();

            if let Some(proc) = updater.as_mut() {
                if proc.is_finished() {
                    if updater.take().unwrap().join().unwrap_or(false) {
                        app_data.app_gui.update_button.show();
                    }
                    return ControlFlow::Break;
                }
            }
            ControlFlow::Continue
        }),
    );
}

fn start_handshake_refresh() {
    std::thread::spawn(|| loop {
        backend::update_handshakes().ok();
        std::thread::sleep(Duration::from_millis(1500));
    });
}

fn start_update_checker() {
    globals::UPDATE_PROC
        .lock()
        .unwrap()
        .replace(std::thread::spawn(|| {
            let update = backend::check_update(globals::VERSION);

            match update {
                Some(update) => {
                    *globals::NEW_VERSION.lock().unwrap() = Some(update);
                    true
                }
                None => false,
            }
        }));
}

fn connect_deauth_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .deauth_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            let iter = match app_data.app_gui.aps_view.selection().selected() {
                Some((_, iter)) => iter,
                None => return,
            };

            let bssid = list_store_get!(app_data.app_gui.aps_model, &iter, 1, String);
            let channel = list_store_get!(app_data.app_gui.aps_model, &iter, 3, i32);
            let under_attack = backend::get_attack_pool().contains_key(&bssid);

            match under_attack {
                true => backend::stop_deauth_attack(&bssid),
                false => {
                    app_data.app_gui.channel_filter_entry.set_text(&channel.to_string());
                    app_data.deauth_gui.show(backend::get_aps()[&bssid].clone());
                }
            }
        }));
}

fn connect_capture_button(app_data: Rc<AppData>) {
    app_data
        .app_gui
        .capture_but
        .connect_clicked(clone!(@strong app_data => move |_| {
            let iter = match app_data.app_gui.aps_view.selection().selected() {
                Some((_, iter)) => iter,
                None => return,
            };

            let essid = list_store_get!(app_data.app_gui.aps_model, &iter, 0, String);
            let bssid = list_store_get!(app_data.app_gui.aps_model, &iter, 1, String);

            let ap = match backend::get_aps().get(&bssid) {
                Some(ap) => ap.clone(),
                None => return,
            };

            if !ap.handshake {
                return;
            }

            if let Some(ref cap) = ap.saved_handshake {
                return app_data.decrypt_gui.show(Some((cap.clone(), bssid)));
            }

            let was_scanning = backend::is_scan_process();

            if was_scanning {
                app_data.app_gui.scan_but.emit_clicked();
            }

            let file_chooser_dialog = FileChooserDialog::new(
                Some("Save Capture"),
                Some(&app_data.app_gui.window),
                FileChooserAction::Save,
                &[("Save", ResponseType::Accept)],
            );

            file_chooser_dialog.set_current_name(&format!("{}.cap", essid));
            file_chooser_dialog.run_async(clone!(@strong app_data => move |this, response| {
                if response == ResponseType::Accept {
                    this.close();

                    let gio_file = match this.file() {
                        Some(file) => file,
                        None => return,
                    };
                    let path = gio_file.path().unwrap().to_str().unwrap().to_string();

                    if let Err(e) = backend::save_capture(&path) {
                        return ErrorDialog::spawn(&app_data.app_gui.window, "Save failed", &e.to_string());
                    }

                    for (_, ap) in backend::get_aps().iter_mut() {
                        if ap.handshake {
                            ap.saved_handshake = Some(path.to_owned());
                        }
                    }

                    app_data.decrypt_gui.show(Some((path, bssid)));
                }

                if was_scanning {
                    app_data.app_gui.scan_but.emit_clicked();
                }
            }));
        }));
}

pub fn connect(app_data: Rc<AppData>) {
    connect_about_button(app_data.clone());
    connect_update_button(app_data.clone());
    connect_decrypt_button(app_data.clone());
    connect_settings_button(app_data.clone());

    connect_previous_button(app_data.clone());
    connect_next_button(app_data.clone());
    connect_top_button(app_data.clone());
    connect_bottom_button(app_data.clone());

    start_app_refresh(app_data.clone());
    start_handshake_refresh();
    start_update_checker();

    connect_hopping_button(app_data.clone());
    connect_focus_button(app_data.clone());
    connect_deauth_button(app_data.clone());
    connect_capture_button(app_data);
}