A WiFi security auditing software
decrypt: add advanced bruteforce settings (#173)
Martin Olivier29a05c489c4e
diff --git a/src/backend/decrypt.rs b/src/backend/decrypt.rsindex 0e998c4..fd88e38 100755--- a/src/backend/decrypt.rs+++ b/src/backend/decrypt.rs@@ -1,3 +1,4 @@+use crate::types::*;use std::process::{Command, Stdio};const CRUNCH_LOWERCASE: &str = "abcdefghijklmnopqrstuvwxyz";@@ -44,32 +45,37 @@ pub fn run_decrypt_bruteforce_process(handshake: &str,bssid: &str,essid: &str,- low: bool,- up: bool,- num: bool,- sym: bool,+ charset: &BruteforceCharset,+ min: u64,+ max: u64,) -> Result<(), DecryptError> {- let charset = format!(- "{}{}{}{}",- match low {- true => CRUNCH_LOWERCASE,- false => "",- },- match up {- true => CRUNCH_UPPERCASE,- false => "",- },- match num {- true => CRUNCH_NUMBERS,- false => "",- },- match sym {- true => CRUNCH_SYMBOLS,- false => "",- },- );+ let charset_str = match charset {+ BruteforceCharset::Params(settings) => {+ format!(+ "{}{}{}{}",+ match settings.lowercase {+ true => CRUNCH_LOWERCASE,+ false => "",+ },+ match settings.uppercase {+ true => CRUNCH_UPPERCASE,+ false => "",+ },+ match settings.numbers {+ true => CRUNCH_NUMBERS,+ false => "",+ },+ match settings.symbols {+ true => CRUNCH_SYMBOLS,+ false => "",+ },+ )+ }+ BruteforceCharset::Specific(custom) => custom.to_owned(),+ };let title = format!("Handshake Decryption ({essid})");- let cmd = format!("crunch 8 64 '{charset}' | aircrack-ng -w - -b '{bssid}' '{handshake}'");+ let cmd =+ format!("crunch {min} {max} '{charset_str}' | aircrack-ng -w - -b '{bssid}' '{handshake}'");Command::new("xterm").stdin(Stdio::null())diff --git a/src/frontend/connections/decrypt.rs b/src/frontend/connections/decrypt.rsindex 5dccd86..03dd4bf 100755--- a/src/frontend/connections/decrypt.rs+++ b/src/frontend/connections/decrypt.rs@@ -1,10 +1,12 @@use crate::backend;use crate::frontend::interfaces::*;use crate::frontend::widgets::ErrorDialog;+use crate::types::*;use crate::*;use glib::clone;use gtk4::*;+use std::collections::HashSet;use std::rc::Rc;fn connect_controller(app_data: Rc<AppData>) {@@ -21,6 +23,24 @@ fn connect_controller(app_data: Rc<AppData>) {app_data.decrypt_gui.window.add_controller(controller);}+fn connect_settings_controller(app_data: Rc<AppData>) {+ let controller = gtk4::EventControllerKey::new();++ controller.connect_key_pressed(clone!(@strong app_data => move |_, key, _, _| {+ if key == gdk::Key::Escape {+ app_data.decrypt_gui.settings_gui.window.hide();+ }++ glib::Propagation::Proceed+ }));++ app_data+ .decrypt_gui+ .settings_gui+ .window+ .add_controller(controller);+}+fn update_decrypt_button_status(app_data: Rc<AppData>) {if app_data.decrypt_gui.handshake_entry.text_length() == 0 {return app_data.decrypt_gui.decrypt_but.set_sensitive(false);@@ -33,12 +53,13 @@ fn update_decrypt_button_status(app_data: Rc<AppData>) {return app_data.decrypt_gui.decrypt_but.set_sensitive(false);}} else {+ let custom = !app_data.decrypt_gui.settings_gui.charset.text().is_empty();let low = app_data.decrypt_gui.lowercase_but.is_active();let up = app_data.decrypt_gui.uppercase_but.is_active();let num = app_data.decrypt_gui.numbers_but.is_active();let sym = app_data.decrypt_gui.symbols_but.is_active();- if !low && !up && !num && !sym {+ if !low && !up && !num && !sym && !custom {return app_data.decrypt_gui.decrypt_but.set_sensitive(false);}}@@ -108,6 +129,63 @@ fn connect_stack_notify(app_data: Rc<AppData>) {}));}+fn connect_settings_button(app_data: Rc<AppData>) {+ app_data+ .decrypt_gui+ .settings_but+ .connect_clicked(clone!(@strong app_data => move |_| {+ app_data.decrypt_gui.settings_gui.show();+ }));+}++fn connect_password_len_buttons(app_data: Rc<AppData>) {+ app_data+ .decrypt_gui+ .settings_gui+ .min_but+ .connect_value_changed(clone!(@strong app_data => move |min_but| {+ let min_value = min_but.value();++ if min_value > app_data.decrypt_gui.settings_gui.max_but.value() {+ app_data.decrypt_gui.settings_gui.max_but.set_value(min_value);+ }+ }));++ app_data+ .decrypt_gui+ .settings_gui+ .max_but+ .connect_value_changed(clone!(@strong app_data => move |max_but| {+ let max_value = max_but.value();++ if max_value < app_data.decrypt_gui.settings_gui.min_but.value() {+ app_data.decrypt_gui.settings_gui.min_but.set_value(max_value);+ }+ }));+}++fn connect_charset_entry(app_data: Rc<AppData>) {+ app_data.decrypt_gui.settings_gui.charset.connect_text_notify(+ clone!(@strong app_data => move |this| {+ let mut nodup_set = HashSet::new();+ let nodup_str = this.text().chars().filter(|&c| nodup_set.insert(c)).collect::<String>();++ if nodup_str != this.text() {+ return this.set_text(&nodup_str);+ }++ let buttons_state = this.text().is_empty();++ app_data.decrypt_gui.lowercase_but.set_sensitive(buttons_state);+ app_data.decrypt_gui.uppercase_but.set_sensitive(buttons_state);+ app_data.decrypt_gui.symbols_but.set_sensitive(buttons_state);+ app_data.decrypt_gui.numbers_but.set_sensitive(buttons_state);++ update_decrypt_button_status(app_data.clone());+ }),+ );+}+fn connect_wordlist_button(app_data: Rc<AppData>) {app_data.decrypt_gui.wordlist_but.connect_clicked(clone!(@strong app_data => move |_| {@@ -176,10 +254,19 @@ fn connect_decrypt_button(app_data: Rc<AppData>) {let handshake_entry = app_data.decrypt_gui.handshake_entry.text();let wordlist_entry = app_data.decrypt_gui.wordlist_entry.text();- let low = app_data.decrypt_gui.lowercase_but.is_active();- let up = app_data.decrypt_gui.uppercase_but.is_active();- let num = app_data.decrypt_gui.numbers_but.is_active();- let sym = app_data.decrypt_gui.symbols_but.is_active();+ let charset = match app_data.decrypt_gui.settings_gui.charset.text().as_str() {+ "" => BruteforceCharset::Params(+ BruteforceCharsetParams {+ lowercase: app_data.decrypt_gui.lowercase_but.is_active(),+ uppercase: app_data.decrypt_gui.uppercase_but.is_active(),+ numbers: app_data.decrypt_gui.numbers_but.is_active(),+ symbols: app_data.decrypt_gui.symbols_but.is_active(),+ }),+ custom => BruteforceCharset::Specific(custom.to_string()),+ };++ let min = app_data.decrypt_gui.settings_gui.min_but.value() as u64;+ let max = app_data.decrypt_gui.settings_gui.max_but.value() as u64;let iter = match app_data.decrypt_gui.target_view.active_iter() {Some(iter) => iter,@@ -209,10 +296,9 @@ fn connect_decrypt_button(app_data: Rc<AppData>) {&handshake_entry,&bssid,&essid,- low,- up,- num,- sym+ &charset,+ min,+ max,) {return ErrorDialog::spawn(&app_data.decrypt_gui.window, "Failed to run decryption", &e.to_string());}@@ -224,9 +310,13 @@ fn connect_decrypt_button(app_data: Rc<AppData>) {pub fn connect(app_data: Rc<AppData>) {connect_controller(app_data.clone());+ connect_settings_controller(app_data.clone());connect_handshake_button(app_data.clone());connect_stack_notify(app_data.clone());+ connect_settings_button(app_data.clone());+ connect_charset_entry(app_data.clone());+ connect_password_len_buttons(app_data.clone());connect_wordlist_button(app_data.clone());connect_bruteforce_buttons(app_data.clone());connect_decrypt_button(app_data);diff --git a/src/frontend/interfaces/decrypt.rs b/src/frontend/interfaces/decrypt.rsindex 2fe5070..791739c 100644--- a/src/frontend/interfaces/decrypt.rs+++ b/src/frontend/interfaces/decrypt.rs@@ -23,6 +23,81 @@ fn build_ap_view(model: &ListStore) -> ComboBox {combo}+pub struct DecryptSettingsGui {+ pub window: Window,+ pub charset: Entry,+ pub min_but: SpinButton,+ pub max_but: SpinButton,+}++impl DecryptSettingsGui {+ pub fn new(parent: &impl IsA<Window>) -> Self {+ let window = Window::builder()+ .title("Bruteforce advanced settings")+ .hide_on_close(true)+ .default_width(360)+ .default_height(160)+ .resizable(false)+ .transient_for(parent)+ .modal(true)+ .build();++ let charset = Entry::builder()+ .placeholder_text("ex: 123456789AB#*")+ .margin_start(4)+ .margin_end(4)+ .margin_bottom(4)+ .build();++ let charset_frame = Frame::new(Some("Custom charset"));+ charset_frame.set_child(Some(&charset));++ let min_label = Label::new(Some("minimum"));+ let max_label = Label::new(Some("maximum"));++ let min_adjustment = Adjustment::new(8.0, 8.0, 64.0, 1.0, 10.0, 0.0);+ let max_adjustment = Adjustment::new(10.0, 8.0, 64.0, 1.0, 10.0, 0.0);++ let min_but = SpinButton::new(Some(&min_adjustment), 1.0, 0);+ let max_but = SpinButton::new(Some(&max_adjustment), 1.0, 0);++ let password_lenght_frame = Frame::new(Some("Password lenght"));++ let password_lenght_box = Box::new(Orientation::Horizontal, 4);+ password_lenght_box.set_margin_start(4);+ password_lenght_box.set_margin_end(4);+ password_lenght_box.set_margin_bottom(4);+ password_lenght_box.append(&min_label);+ password_lenght_box.append(&min_but);+ password_lenght_box.append(&max_label);+ password_lenght_box.append(&max_but);++ password_lenght_frame.set_child(Some(&password_lenght_box));++ let vbox = Box::new(Orientation::Vertical, 10);+ vbox.set_margin_top(10);+ vbox.set_margin_end(10);+ vbox.set_margin_start(10);+ vbox.set_margin_bottom(10);++ vbox.append(&charset_frame);+ vbox.append(&password_lenght_frame);++ window.set_child(Some(&vbox));++ Self {+ window,+ charset,+ min_but,+ max_but,+ }+ }++ pub fn show(&self) {+ self.window.show();+ }+}+pub struct DecryptGui {pub window: Window,pub handshake_but: Button,@@ -36,7 +111,9 @@ pub struct DecryptGui {pub uppercase_but: CheckButton,pub numbers_but: CheckButton,pub symbols_but: CheckButton,+ pub settings_but: Button,pub decrypt_but: Button,+ pub settings_gui: DecryptSettingsGui,}impl DecryptGui {@@ -44,7 +121,7 @@ impl DecryptGui {let window = Window::builder().title("Decrypt Handshake").hide_on_close(true)- .default_width(500)+ .default_width(440).default_height(200).resizable(false).transient_for(parent)@@ -74,10 +151,11 @@ impl DecryptGui {//- let lowercase_but = CheckButton::with_label("Lowercase [a-z]");- let uppercase_but = CheckButton::with_label("Uppercase [A-Z]");- let numbers_but = CheckButton::with_label("Numbers [0-9]");- let symbols_but = CheckButton::with_label("Symbols [!-#]");+ let lowercase_but = CheckButton::with_label("Lowercase");+ let uppercase_but = CheckButton::with_label("Uppercase");+ let numbers_but = CheckButton::with_label("Numbers");+ let symbols_but = CheckButton::with_label("Symbols");+ let settings_but = Button::from_icon_name("emblem-system-symbolic");//@@ -91,6 +169,7 @@ impl DecryptGui {bruteforce_box.append(&uppercase_but);bruteforce_box.append(&numbers_but);bruteforce_box.append(&symbols_but);+ bruteforce_box.append(&settings_but);bruteforce_frame.set_child(Some(&bruteforce_box));@@ -159,6 +238,8 @@ impl DecryptGui {window.set_child(Some(&vbox));+ let settings_gui = DecryptSettingsGui::new(&window);+Self {window,handshake_but,@@ -172,7 +253,9 @@ impl DecryptGui {uppercase_but,numbers_but,symbols_but,+ settings_but,decrypt_but,+ settings_gui,}}diff --git a/src/types.rs b/src/types.rsindex 1da3979..b3048c3 100644--- a/src/types.rs+++ b/src/types.rs@@ -13,6 +13,18 @@ pub enum AttackSoftware {Mdk4,}+pub struct BruteforceCharsetParams {+ pub lowercase: bool,+ pub uppercase: bool,+ pub numbers: bool,+ pub symbols: bool,+}++pub enum BruteforceCharset {+ Params(BruteforceCharsetParams),+ Specific(String),+}+#[derive(Clone, Debug, Serialize, Deserialize)]pub struct AP {pub essid: String,