Skip to content

A WiFi security auditing software

feat: version 0.7.2 (#108)

Martin Olivierf9ba50859329
diff --git a/.fpm b/.fpm
index d0ebc71..075ef3a 100644
--- a/.fpm
+++ b/.fpm
@@ -1,7 +1,7 @@
-s dir ./target/release/airgorah ./icons/app_icon.png package README.md LICENSE
--name airgorah
--license MIT
---version 0.7.1
+--version 0.7.2
--description "A WiFi auditing software that can perform deauth attacks and passwords cracking"
--url "https://github.com/martin-olivier/airgorah"
--maintainer "Martin Olivier <[email protected]>"
@@ -10,6 +10,7 @@
--conflicts airgorah
--depends bash
+--depends xterm
--depends iw
--depends macchanger
--depends aircrack-ng
diff --git a/.github/assets/illustration.png b/.github/assets/illustration.png
index d6d432d..c4f587c 100755
Binary files a/.github/assets/illustration.png and b/.github/assets/illustration.png differ
diff --git a/Cargo.lock b/Cargo.lock
index 55d7732..ede51bb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -19,7 +19,7 @@ dependencies = [
[[package]]
name = "airgorah"
-version = "0.7.1"
+version = "0.7.2"
dependencies = [
"chrono",
"csv",
@@ -34,6 +34,7 @@ dependencies = [
"serde",
"serde_json",
"sudo",
+ "thiserror",
"toml",
"ureq",
"which",
diff --git a/Cargo.toml b/Cargo.toml
index f10d8eb..5dc3d36 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,9 +1,9 @@
[package]
name = "airgorah"
-version = "0.7.1"
+version = "0.7.2"
edition = "2021"
license = "MIT"
-description = "A WiFi auditing software that can perform deauth attacks and passwords cracking"
+description = "A WiFi security auditing software mainly based on aircrack-ng tools suite"
authors = ["Martin Olivier <[email protected]>"]
homepage = "https://github.com/martin-olivier/airgorah"
repository = "https://github.com/martin-olivier/airgorah"
@@ -29,6 +29,7 @@ nix = { version = "0.28", features = ["signal"] }
ureq = { version = "2.9", features = ["json"] }
log = "0.4"
env_logger = "0.11"
+thiserror = "1"
[build-dependencies]
serde = { version = "1", features = ["derive"] }
diff --git a/README.md b/README.md
index 3eabd28..652cdfb 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
Airgorah</h1>
<p align="center">
- <span>A WiFi auditing software that can perform deauth attacks and passwords cracking</span>
+ <span>A WiFi security auditing software mainly based on <a href="https://github.com/aircrack-ng/aircrack-ng">aircrack-ng</a> tools suite</span>
</p>
<p align="center">
@@ -20,9 +20,9 @@ Airgorah</h1>
[![aur](https://img.shields.io/aur/version/airgorah)](https://aur.archlinux.org/packages/airgorah)
[![ci](https://github.com/martin-olivier/airgorah/actions/workflows/CI.yml/badge.svg)](https://github.com/martin-olivier/airgorah/actions/workflows/CI.yml)
-`Airgorah` is a WiFi auditing software that can discover the clients connected to an access point, perform deauthentication attacks against specific clients, capture WPA handshakes, and crack the password of the access point.
+`Airgorah` is a WiFi security auditing software that can capture nearby WiFi traffic, discover clients connected to access points, perform deauthentication attacks, capture handshakes, and crack the password of access points.
-It is written in Rust and uses [GTK4](https://github.com/gtk-rs/gtk4-rs) for the graphical part. The software is mainly based on [aircrack-ng](https://github.com/aircrack-ng/aircrack-ng) tools suite.
+It is written in Rust and uses [GTK4](https://github.com/gtk-rs/gtk4-rs) for the graphical part.
`⭐ Don't forget to put a star if you like the project!`
diff --git a/src/backend/app.rs b/src/backend/app.rs
index ed2b6ef..0cb7f98 100755
--- a/src/backend/app.rs
+++ b/src/backend/app.rs
@@ -1,19 +1,29 @@
use super::*;
-use crate::error::Error;
use crate::globals::*;
-/// Check if the user is root, and if all the dependencies are installed
-pub fn app_setup() -> Result<(), Error> {
+#[derive(thiserror::Error, Debug)]
+pub enum AppError {
+ #[error("Could not setup Ctrl-C (SIGINT) handler: {0}")]
+ SigintHandler(#[from] ctrlc::Error),
+
+ #[error("Airgorah need root privilege to run")]
+ NotRoot,
+
+ #[error("Missing required dependency: {0}")]
+ MissingDependency(String),
+}
+
+/// Check if the user is root, load settings, and check if all the required dependencies are installed
+pub fn app_setup() -> Result<(), AppError> {
app_cleanup();
ctrlc::set_handler(move || {
app_cleanup();
std::process::exit(1);
- })
- .expect("Error setting Ctrl-C handler");
+ })?;
if sudo::check() != sudo::RunningAs::Root {
- return Err(Error::new("Airgorah need root privilege to run"));
+ return Err(AppError::NotRoot);
}
load_settings();
@@ -23,6 +33,7 @@ pub fn app_setup() -> Result<(), Error> {
"ip",
"iw",
"awk",
+ "xterm",
"airmon-ng",
"airodump-ng",
"aireplay-ng",
@@ -53,13 +64,10 @@ pub fn has_dependency(dep: &str) -> bool {
}
/// Check if all the required dependencies are installed
-pub fn check_required_dependencies(deps: &[&str]) -> Result<(), Error> {
+pub fn check_required_dependencies(deps: &[&str]) -> Result<(), AppError> {
for dep in deps {
if !has_dependency(dep) {
- return Err(Error::new(&format!(
- "Missing required dependency: \"{}\"",
- dep,
- )));
+ return Err(AppError::MissingDependency(dep.to_string()));
}
}
Ok(())
diff --git a/src/backend/capture.rs b/src/backend/capture.rs
index d6cd7f1..6d338ce 100755
--- a/src/backend/capture.rs
+++ b/src/backend/capture.rs
@@ -1,12 +1,33 @@
use super::*;
-use crate::error::Error;
use crate::globals::*;
+use crate::types::*;
use regex::Regex;
+use serde::Serialize;
+use std::fs::File;
+use std::io::Write;
use std::process::Command;
+#[derive(Debug, Serialize)]
+struct Report {
+ pub access_points: Vec<AP>,
+ pub unlinked_clients: Vec<Client>,
+}
+
+#[derive(thiserror::Error, Debug)]
+pub enum CapError {
+ #[error("Input/Output error: {0}")]
+ IoError(#[from] std::io::Error),
+
+ #[error("Regex error: {0}")]
+ BadRegex(#[from] regex::Error),
+
+ #[error("Json error: {0}")]
+ JsonError(#[from] serde_json::Error),
+}
+
/// Update the handshake capture status of all APs
-pub fn update_handshakes() -> Result<(), Error> {
+pub fn update_handshakes() -> Result<(), CapError> {
let handshakes = get_handshakes([
&(LIVE_SCAN_PATH.to_string() + "-01.cap"),
&(OLD_SCAN_PATH.to_string() + "-01.cap"),
@@ -26,7 +47,7 @@ pub fn update_handshakes() -> Result<(), Error> {
}
/// Get the access points infos of the handshakes contained in the capture file
-pub fn get_handshakes<I, S>(args: I) -> Result<Vec<(String, String)>, Error>
+pub fn get_handshakes<I, S>(args: I) -> Result<Vec<(String, String)>, CapError>
where
I: IntoIterator<Item = S>,
S: AsRef<std::ffi::OsStr>,
@@ -64,10 +85,33 @@ where
}
/// Save the current capture to a file
-pub fn save_capture(path: &str) -> Result<(), Error> {
+pub fn save_capture(path: &str) -> Result<(), CapError> {
std::fs::copy(OLD_SCAN_PATH.to_string() + "-01.cap", path)?;
- log::info!("capture saved to \"{}\"", path);
+ log::info!("capture saved to '{}'", path);
+
+ Ok(())
+}
+
+/// Save the capture report to a file
+pub fn save_report(path: &str) -> Result<(), CapError> {
+ let access_points = get_aps().values().cloned().collect::<Vec<AP>>();
+ let unlinked_clients = get_unlinked_clients()
+ .values()
+ .cloned()
+ .collect::<Vec<Client>>();
+
+ let report = Report {
+ access_points,
+ unlinked_clients,
+ };
+
+ let json_data = serde_json::to_string::<Report>(&report)?;
+
+ let mut file = File::create(path)?;
+ file.write_all(json_data.as_bytes())?;
+
+ log::info!("report saved to '{}'", path);
Ok(())
}
diff --git a/src/backend/deauth.rs b/src/backend/deauth.rs
index 579c648..1205289 100755
--- a/src/backend/deauth.rs
+++ b/src/backend/deauth.rs
@@ -1,16 +1,21 @@
-use crate::error::Error;
use crate::globals::*;
use crate::types::*;
use std::process::{Command, Stdio};
use std::sync::MutexGuard;
+#[derive(thiserror::Error, Debug)]
+pub enum DeathError {
+ #[error("Input/Output error: {0}")]
+ IoError(#[from] std::io::Error),
+}
+
/// Launch a deauth attack on a specific AP
pub fn launch_deauth_attack(
iface: &str,
ap: AP,
specific_clients: Option<Vec<String>>,
software: AttackSoftware,
-) -> Result<(), Error> {
+) -> Result<(), DeathError> {
let mut attack_pool = get_attack_pool();
let attack_targets = match specific_clients {
diff --git a/src/backend/decrypt.rs b/src/backend/decrypt.rs
index 2b8502b..ee9f39f 100755
--- a/src/backend/decrypt.rs
+++ b/src/backend/decrypt.rs
@@ -1,5 +1,3 @@
-use super::*;
-use crate::error::Error;
use std::process::{Command, Stdio};
const CRUNCH_LOWERCASE: &str = "abcdefghijklmnopqrstuvwxyz";
@@ -7,55 +5,10 @@ const CRUNCH_UPPERCASE: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const CRUNCH_NUMBERS: &str = "0123456789";
const CRUNCH_SYMBOLS: &str = " @!#$%^&*()-_+=~`[]{}|:;<>,.?/\\";
-/// Get the terminal emulator
-pub fn build_terminal(title: String, command: String) -> Result<Command, Error> {
- let err_msg = Error::new("No supported terminal found, please install one of the following:\nxfce4-terminal, gnome-terminal, konsole");
-
- if has_dependency("xfce4-terminal") {
- let mut process = Command::new("xfce4-terminal");
- process.stdin(Stdio::piped());
- process.args([
- "--hide-menubar",
- "--hide-toolbar",
- "--hide-scrollbar",
- "--hold",
- "-T",
- &title,
- "-e",
- &format!("sh -c \"{}\"", command),
- ]);
- Ok(process)
- } else if has_dependency("gnome-terminal") {
- let mut process = Command::new("gnome-terminal");
- process.stdin(Stdio::piped());
- process.args([
- "--hide-menubar",
- "--title",
- &title,
- "--",
- "sh",
- "-c",
- &format!("{} ; exec sh", command),
- ]);
- Ok(process)
- } else if has_dependency("konsole") {
- let mut process = Command::new("konsole");
- process.stdin(Stdio::piped());
- process.args([
- "--hide-menubar",
- "--hide-tabbar",
- "--hold",
- "-p",
- &format!("title={}", title),
- "-e",
- "sh",
- "-c",
- &command,
- ]);
- Ok(process)
- } else {
- Err(err_msg)
- }
+#[derive(thiserror::Error, Debug)]
+pub enum DecryptError {
+ #[error("Input/Output error: {0}")]
+ IoError(#[from] std::io::Error),
}
/// Launch a new terminal window to run aircrack-ng to decrypt a handshake with the specified wordlist
@@ -64,18 +17,24 @@ pub fn run_decrypt_wordlist_process(
bssid: &str,
essid: &str,
wordlist: &str,
-) -> Result<(), Error> {
+) -> Result<(), DecryptError> {
let title = format!("Handshake Decryption ({})", essid);
- let cmd = format!(
- "aircrack-ng '{}' -b '{}' -w '{}'",
- handshake, bssid, wordlist
- );
-
- let mut process = build_terminal(title, cmd)?;
- std::thread::spawn(move || {
- process.output().unwrap();
- });
+ Command::new("xterm")
+ .stdin(Stdio::null())
+ .args([
+ "-hold",
+ "-T",
+ &title,
+ "-e",
+ "aircrack-ng",
+ handshake,
+ "-b",
+ bssid,
+ "-w",
+ wordlist,
+ ])
+ .spawn()?;
Ok(())
}
@@ -89,7 +48,7 @@ pub fn run_decrypt_bruteforce_process(
up: bool,
num: bool,
sym: bool,
-) -> Result<(), Error> {
+) -> Result<(), DecryptError> {
let charset = format!(
"{}{}{}{}",
match low {
@@ -115,11 +74,10 @@ pub fn run_decrypt_bruteforce_process(
charset, bssid, handshake
);
- let mut process = build_terminal(title, cmd)?;
-
- std::thread::spawn(move || {
- process.output().unwrap();
- });
+ Command::new("xterm")
+ .stdin(Stdio::null())
+ .args(["-hold", "-T", &title, "-e", "sh", "-c", &cmd])
+ .spawn()?;
Ok(())
}
diff --git a/src/backend/interface.rs b/src/backend/interface.rs
index 9750d2e..bef8402 100644
--- a/src/backend/interface.rs
+++ b/src/backend/interface.rs
@@ -1,16 +1,51 @@
use super::*;
-use crate::error::Error;
use crate::globals::*;
use std::process::{Command, Stdio};
+#[derive(thiserror::Error, Debug)]
+pub enum IfaceError {
+ #[error("Input/Output error: {0}")]
+ IoError(#[from] std::io::Error),
+
+ #[error("Failed to retreive interfaces list")]
+ IfaceList,
+
+ #[error("Utf8 conversion error")]
+ Utf8Error(#[from] std::string::FromUtf8Error),
+
+ #[error("PHY parsing error")]
+ PhyParsing,
+
+ #[error("PHY '{0}' could not be found")]
+ PhyNotFound(String),
+
+ #[error("Interface '{0}' could not be found")]
+ IfaceNotFound(String),
+
+ #[error("Could not change MAC address: interface not in monitor mode")]
+ IfaceNotMonitor,
+
+ #[error("MAC address is invalid: change its value in the settings page.")]
+ InvalidMac,
+
+ #[error("Could not enable monitor mode on '{0}':\n{1}")]
+ MonitorFailed(String, String),
+
+ #[error("Could not disable monitor mode on '{0}':\n{1}")]
+ ManagedFailed(String, String),
+
+ #[error("systemctl is required to kill/restore network managers")]
+ MissingSystemd,
+}
+
/// Get the available interfaces
-pub fn get_interfaces() -> Result<Vec<String>, Error> {
+pub fn get_interfaces() -> Result<Vec<String>, IfaceError> {
let cmd = Command::new("sh")
.args(["-c", "iw dev | awk \'$1==\"Interface\"{print $2}\'"])
.output()?;
if !cmd.status.success() {
- return Err(Error::new("Failed to get interfaces"));
+ return Err(IfaceError::IfaceList);
}
let out = String::from_utf8(cmd.stdout)?;
@@ -19,19 +54,19 @@ pub fn get_interfaces() -> Result<Vec<String>, Error> {
}
/// Check if an interface supports 5GHz
-pub fn is_5ghz_supported(iface: &str) -> Result<bool, Error> {
+pub fn is_5ghz_supported(iface: &str) -> Result<bool, IfaceError> {
let phy_path = format!("/sys/class/net/{}/phy80211", iface);
let phy_link = std::fs::read_link(phy_path)?;
let phy_name = match phy_link.file_name() {
Some(name) => name,
- None => return Err(Error::new("phy parsing error")),
+ None => return Err(IfaceError::PhyParsing),
};
let phy_name_str = match phy_name.to_str() {
Some(name) => name,
- None => return Err(Error::new("phy parsing error")),
+ None => return Err(IfaceError::PhyParsing),
};
let check_band_cmd = Command::new("iw")
@@ -39,7 +74,7 @@ pub fn is_5ghz_supported(iface: &str) -> Result<bool, Error> {
.output()?;
if !check_band_cmd.status.success() {
- return Err(Error::new(&format!("{}: No such phy", phy_name_str)));
+ return Err(IfaceError::PhyNotFound(phy_name_str.to_string()));
}
let check_band_output = String::from_utf8(check_band_cmd.stdout)?;
@@ -52,11 +87,11 @@ pub fn is_5ghz_supported(iface: &str) -> Result<bool, Error> {
}
/// Check if an interface is in monitor mode
-pub fn is_monitor_mode(iface: &str) -> Result<bool, Error> {
+pub fn is_monitor_mode(iface: &str) -> Result<bool, IfaceError> {
let check_monitor_cmd = Command::new("iw").args(["dev", iface, "info"]).output()?;
if !check_monitor_cmd.status.success() {
- return Err(Error::new(&format!("{}: No such interface", iface)));
+ return Err(IfaceError::IfaceNotFound(iface.to_string()));
}
let check_monitor_output = String::from_utf8(check_monitor_cmd.stdout)?;
@@ -69,11 +104,9 @@ pub fn is_monitor_mode(iface: &str) -> Result<bool, Error> {
}
// Set the MAC address of an interface
-pub fn set_mac_address(iface: &str) -> Result<(), Error> {
+pub fn set_mac_address(iface: &str) -> Result<(), IfaceError> {
if !is_monitor_mode(iface)? {
- return Err(Error::new(
- "Can't change MAC address, interface is not in monitor mode",
- ));
+ return Err(IfaceError::IfaceNotMonitor);
}
Command::new("ip")
@@ -101,9 +134,7 @@ pub fn set_mac_address(iface: &str) -> Result<(), Error> {
.output()?;
if !success {
- return Err(Error::new(
- "The MAC address is invalid. Change the value in the settings page.",
- ));
+ return Err(IfaceError::InvalidMac);
}
log::info!(
@@ -116,7 +147,7 @@ pub fn set_mac_address(iface: &str) -> Result<(), Error> {
}
/// enable monitor mode on an interface
-pub fn enable_monitor_mode(iface: &str) -> Result<String, Error> {
+pub fn enable_monitor_mode(iface: &str) -> Result<String, IfaceError> {
kill_network_manager()?;
if is_monitor_mode(iface)? {
@@ -132,12 +163,10 @@ pub fn enable_monitor_mode(iface: &str) -> Result<String, Error> {
.output()?;
if !enable_monitor_cmd.status.success() {
- return Err(Error::new(&format!(
- "Could not enable monitor mode on '{}':\n{}",
- iface,
- String::from_utf8(enable_monitor_cmd.stdout)
- .unwrap_or("Invalid output returned by airmon-ng".to_string())
- )));
+ return Err(IfaceError::MonitorFailed(
+ iface.to_string(),
+ String::from_utf8(enable_monitor_cmd.stdout).unwrap_or_default(),
+ ));
}
log::info!("{}: monitor mode enabled", iface);
@@ -149,12 +178,10 @@ pub fn enable_monitor_mode(iface: &str) -> Result<String, Error> {
match is_monitor_mode(&(iface.to_string() + "mon")) {
Ok(res) => match res {
true => Ok(iface.to_string() + "mon"),
- false => Err(Error::new(&format!(
- "Could not enable monitor mode on '{}':\n{}",
- iface,
- String::from_utf8(enable_monitor_cmd.stdout)
- .unwrap_or("Invalid output returned by airmon-ng".to_string())
- ))),
+ false => Err(IfaceError::MonitorFailed(
+ iface.to_string(),
+ String::from_utf8(enable_monitor_cmd.stdout).unwrap_or_default(),
+ )),
},
Err(_) => {
let new_interface_list = get_interfaces()?;
@@ -165,22 +192,20 @@ pub fn enable_monitor_mode(iface: &str) -> Result<String, Error> {
}
}
- Err(Error::new(&format!(
- "Could not enable monitor mode on '{}':\n{}",
- iface,
- String::from_utf8(enable_monitor_cmd.stdout)
- .unwrap_or("Invalid output returned by airmon-ng".to_string())
- )))
+ Err(IfaceError::MonitorFailed(
+ iface.to_string(),
+ String::from_utf8(enable_monitor_cmd.stdout).unwrap_or_default(),
+ ))
}
}
}
/// disable monitor mode on an interface
-pub fn disable_monitor_mode(iface: &str) -> Result<(), Error> {
+pub fn disable_monitor_mode(iface: &str) -> Result<(), IfaceError> {
let check_monitor_cmd = Command::new("iw").args(["dev", iface, "info"]).output()?;
if !check_monitor_cmd.status.success() {
- return Err(Error::new("Failed to get current interface"));
+ return Err(IfaceError::IfaceNotFound(iface.to_string()));
}
let check_monitor_output = String::from_utf8(check_monitor_cmd.stdout)?;
@@ -195,8 +220,9 @@ pub fn disable_monitor_mode(iface: &str) -> Result<(), Error> {
match disable_monitor_cmd.status.success() {
true => Ok(()),
- false => Err(Error::new(
- "Failed to disable monitor mode on current interface",
+ false => Err(IfaceError::ManagedFailed(
+ iface.to_string(),
+ String::from_utf8(disable_monitor_cmd.stdout).unwrap_or_default(),
)),
}
}
@@ -235,27 +261,29 @@ const INTERFERENCE_SERVICES: [&str; 19] = [
];
/// Kill the network manager to avoid channel hopping conflicts
-pub fn kill_network_manager() -> Result<(), Error> {
- if get_settings().kill_network_manager {
- if !has_dependency("systemctl") {
- return Err(Error::new("systemctl is required to kill network managers"));
- }
+pub fn kill_network_manager() -> Result<(), IfaceError> {
+ if !get_settings().kill_network_manager {
+ return Ok(());
+ }
- for service in INTERFERENCE_SERVICES {
- let is_service_running = Command::new("systemctl")
- .args(["is-active", service])
- .output()?;
+ if !has_dependency("systemctl") {
+ return Err(IfaceError::MissingSystemd);
+ }
+
+ for service in INTERFERENCE_SERVICES {
+ let is_service_running = Command::new("systemctl")
+ .args(["is-active", service])
+ .output()?;
- if is_service_running.status.success() {
- Command::new("systemctl").args(["stop", service]).output()?;
+ if is_service_running.status.success() {
+ Command::new("systemctl").args(["stop", service]).output()?;
- SERVICES_TO_RESTORE
- .lock()
- .unwrap()
- .push(service.to_string());
+ SERVICES_TO_RESTORE
+ .lock()
+ .unwrap()
+ .push(service.to_string());
- log::warn!("killed '{}'", service);
- }
+ log::warn!("killed '{}'", service);
}
}
@@ -263,15 +291,13 @@ pub fn kill_network_manager() -> Result<(), Error> {
}
/// Restore the network manager
-pub fn restore_network_manager() -> Result<(), Error> {
+pub fn restore_network_manager() -> Result<(), IfaceError> {
if !get_settings().kill_network_manager {
return Ok(());
}
if !has_dependency("systemctl") {
- return Err(Error::new(
- "systemctl is required to restore network managers",
- ));
+ return Err(IfaceError::MissingSystemd);
};
let services_to_restore: Vec<_> = SERVICES_TO_RESTORE.lock().unwrap().drain(..).collect();
diff --git a/src/backend/scan.rs b/src/backend/scan.rs
index d87fd3b..e794c60 100644
--- a/src/backend/scan.rs
+++ b/src/backend/scan.rs
@@ -4,7 +4,6 @@ use std::process::{Command, Stdio};
use std::sync::MutexGuard;
use super::*;
-use crate::error::Error;
use crate::globals::*;
use crate::types::*;
@@ -67,6 +66,18 @@ struct RawClient {
probes: String,
}
+#[derive(thiserror::Error, Debug)]
+pub enum ScanError {
+ #[error("Could not setup scan process: no band selected")]
+ NoBandSelected,
+
+ #[error("Input/Output error: {0}")]
+ IoError(#[from] std::io::Error),
+
+ #[error("Kill error: errno code: {0}")]
+ KillError(#[from] nix::errno::Errno),
+}
+
/// Check if a scan is currently running
pub fn is_scan_process() -> bool {
SCAN_PROC.lock().unwrap().is_some()
@@ -119,9 +130,9 @@ pub fn set_scan_process(
ghz_2_4: bool,
ghz_5: bool,
channel_filter: Option<String>,
-) -> Result<(), Error> {
+) -> Result<(), ScanError> {
if !ghz_2_4 && !ghz_5 {
- return Err(Error::new("No band selected"));
+ return Err(ScanError::NoBandSelected);
}
stop_scan_process()?;
@@ -177,7 +188,7 @@ pub fn set_scan_process(
}
/// Stop the scan process
-pub fn stop_scan_process() -> Result<(), Error> {
+pub fn stop_scan_process() -> Result<(), ScanError> {
if let Some(child) = SCAN_PROC.lock().unwrap().as_mut() {
let child_pid = Pid::from_raw(child.id() as i32);
@@ -299,7 +310,16 @@ pub fn get_airodump_data() -> HashMap<String, AP> {
channel: result.channel.trim_start().to_string(),
speed: result.speed.trim_start().to_string(),
power: result.power.trim_start().to_string(),
- privacy: result.privacy.trim_start().to_string(),
+ privacy: match result.privacy.trim_start() {
+ "" => "Unknown".to_string(),
+ e => {
+ let array = e
+ .split_whitespace()
+ .map(|s| s.to_string())
+ .collect::<Vec<String>>();
+ array.first().unwrap_or(&"Unknown".to_string()).to_string()
+ }
+ },
hidden,
handshake: {
match old_ap_data {
@@ -311,7 +331,12 @@ pub fn get_airodump_data() -> HashMap<String, AP> {
Some(ap) => ap.saved_handshake.clone(),
None => None,
},
- first_time_seen: result.first_time_seen.trim_start().to_string(),
+ first_time_seen: {
+ match old_ap_data {
+ Some(ap) => ap.first_time_seen.clone(),
+ None => result.first_time_seen.trim_start().to_string(),
+ }
+ },
last_time_seen: result.last_time_seen.trim_start().to_string(),
clients: HashMap::new(),
},
@@ -323,22 +348,53 @@ pub fn get_airodump_data() -> HashMap<String, AP> {
}
for result in cli_reader.deserialize::<RawClient>().flatten() {
- if let Some(ap) = aps.get_mut(result.bssid.trim_start()) {
- let mac = result.station_mac.trim_start().to_string();
- let client_vendor = super::find_vendor(&mac);
-
- ap.clients.insert(
- mac.clone(),
- Client {
- mac,
- packets: result.packets.trim_start().to_string(),
- power: result.power.trim_start().to_string(),
- first_time_seen: result.first_time_seen.trim_start().to_string(),
- last_time_seen: result.last_time_seen.trim_start().to_string(),
- vendor: client_vendor,
- probes: result.probes.trim_start().to_string(),
- },
- );
+ let mac = result.station_mac.trim_start().to_string();
+ let client_vendor = super::find_vendor(&mac);
+
+ match aps.get_mut(result.bssid.trim_start()) {
+ Some(ap) => {
+ let old_client = ap.clients.get(&mac);
+
+ ap.clients.insert(
+ mac.clone(),
+ Client {
+ mac,
+ packets: result.packets.trim_start().to_string(),
+ power: result.power.trim_start().to_string(),
+ first_time_seen: {
+ match old_client {
+ Some(client) => client.first_time_seen.clone(),
+ None => result.first_time_seen.trim_start().to_string(),
+ }
+ },
+ last_time_seen: result.last_time_seen.trim_start().to_string(),
+ vendor: client_vendor,
+ probes: result.probes.trim_start().to_string(),
+ },
+ );
+ }
+ None => {
+ let unlinked_clients = get_unlinked_clients().clone();
+ let old_client = unlinked_clients.get(&mac);
+
+ get_unlinked_clients().insert(
+ mac.clone(),
+ Client {
+ mac,
+ packets: result.packets.trim_start().to_string(),
+ power: result.power.trim_start().to_string(),
+ first_time_seen: {
+ match old_client {
+ Some(client) => client.first_time_seen.clone(),
+ None => result.first_time_seen.trim_start().to_string(),
+ }
+ },
+ last_time_seen: result.last_time_seen.trim_start().to_string(),
+ vendor: client_vendor,
+ probes: result.probes.trim_start().to_string(),
+ },
+ );
+ }
}
}
@@ -353,3 +409,8 @@ pub fn get_airodump_data() -> HashMap<String, AP> {
pub fn get_aps() -> MutexGuard<'static, HashMap<String, AP>> {
APS.lock().unwrap()
}
+
+/// Get unlinked clients
+pub fn get_unlinked_clients() -> MutexGuard<'static, HashMap<String, Client>> {
+ UNLINKED_CLIENTS.lock().unwrap()
+}
diff --git a/src/error.rs b/src/error.rs
deleted file mode 100644
index 39e1e73..0000000
--- a/src/error.rs
+++ /dev/null
@@ -1,56 +0,0 @@
-#[derive(Debug)]
-pub struct Error {
- pub message: String,
-}
-
-impl Error {
- pub fn new(message: &str) -> Self {
- Self {
- message: message.to_string(),
- }
- }
-}
-
-impl std::error::Error for Error {
- fn description(&self) -> &str {
- &self.message
- }
-}
-
-impl std::fmt::Display for Error {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(f, "{}", self.message)
- }
-}
-
-impl From<std::io::Error> for Error {
- fn from(error: std::io::Error) -> Error {
- Error {
- message: error.to_string(),
- }
- }
-}
-
-impl From<std::string::FromUtf8Error> for Error {
- fn from(error: std::string::FromUtf8Error) -> Error {
- Error {
- message: error.to_string(),
- }
- }
-}
-
-impl From<regex::Error> for Error {
- fn from(error: regex::Error) -> Error {
- Error {
- message: error.to_string(),
- }
- }
-}
-
-impl From<nix::errno::Errno> for Error {
- fn from(error: nix::errno::Errno) -> Error {
- Error {
- message: error.to_string(),
- }
- }
-}
diff --git a/src/frontend/connections/app.rs b/src/frontend/connections/app.rs
index 0a44123..c188bc1 100755
--- a/src/frontend/connections/app.rs
+++ b/src/frontend/connections/app.rs
@@ -33,18 +33,19 @@ fn list_store_find(storage: &ListStore, pos: i32, to_match: &str) -> Option<Tree
None
}
-fn connect_controller(app_data: Rc<AppData>) {
+fn connect_window_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.app_gui.focus_but.set_sensitive(false);
- app_data.app_gui.deauth_but.set_sensitive(false);
- app_data.app_gui.capture_but.set_sensitive(false);
+ update_buttons_sensitivity(&app_data);
- app_data.app_gui.aps_view.selection().unselect_all();
+ app_data.app_gui.cli_view.selection().unselect_all();
- app_data.app_gui.cli_model.clear();
+ if app_data.app_gui.aps_view.selection().selected().is_some() {
+ app_data.app_gui.aps_view.selection().unselect_all();
+ app_data.app_gui.cli_model.clear();
+ }
}
glib::Propagation::Proceed
@@ -53,6 +54,130 @@ fn connect_controller(app_data: Rc<AppData>) {
app_data.app_gui.window.add_controller(controller);
}
+fn connect_aps_controller(app: &Application, app_data: Rc<AppData>) {
+ let gesture = GestureClick::new();
+ gesture.set_button(gdk::ffi::GDK_BUTTON_SECONDARY as u32);
+ gesture.connect_pressed(clone!(@strong app_data => move |gesture, _, x, y| {
+ gesture.set_state(EventSequenceState::Claimed);
+
+ if app_data.app_gui.aps_view.selection().selected().is_some() {
+ let pos = gdk::Rectangle::new(x as i32, y as i32, 0, 0);
+
+ app_data.app_gui.aps_menu.set_pointing_to(Some(&pos));
+ app_data.app_gui.aps_menu.popup();
+ }
+ }));
+
+ app_data.app_gui.aps_scroll.add_controller(gesture);
+
+ let copy_bssid = gio::SimpleAction::new("copy_bssid", None);
+ copy_bssid.connect_activate(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);
+
+ if let Some(display) = gdk::Display::default() {
+ display.clipboard().set_text(&bssid);
+ }
+ }));
+ app.add_action(&copy_bssid);
+
+ let copy_essid = gio::SimpleAction::new("copy_essid", None);
+ copy_essid.connect_activate(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);
+
+ if let Some(display) = gdk::Display::default() {
+ display.clipboard().set_text(&essid);
+ }
+ }));
+ app.add_action(&copy_essid);
+
+ let copy_channel = gio::SimpleAction::new("copy_channel", None);
+ copy_channel.connect_activate(clone!(@strong app_data => move |_, _| {
+ let iter = match app_data.app_gui.aps_view.selection().selected() {
+ Some((_, iter)) => iter,
+ None => return,
+ };
+
+ let channel = list_store_get!(app_data.app_gui.aps_model, &iter, 3, i32);
+
+ if let Some(display) = gdk::Display::default() {
+ display.clipboard().set_text(&channel.to_string());
+ }
+ }));
+ app.add_action(&copy_channel);
+}
+
+fn connect_cli_controller(app: &Application, app_data: Rc<AppData>) {
+ let gesture = GestureClick::new();
+ gesture.set_button(gdk::ffi::GDK_BUTTON_SECONDARY as u32);
+ gesture.connect_pressed(clone!(@strong app_data => move |gesture, _, x, y| {
+ gesture.set_state(EventSequenceState::Claimed);
+
+ if app_data.app_gui.cli_view.selection().selected().is_some() {
+ let pos = gdk::Rectangle::new(x as i32, y as i32, 0, 0);
+
+ app_data.app_gui.cli_menu.set_pointing_to(Some(&pos));
+ app_data.app_gui.cli_menu.popup();
+ }
+ }));
+
+ app_data.app_gui.cli_scroll.add_controller(gesture);
+
+ let copy_mac = gio::SimpleAction::new("copy_mac", None);
+ copy_mac.connect_activate(clone!(@strong app_data => move |_, _| {
+ let iter = match app_data.app_gui.cli_view.selection().selected() {
+ Some((_, iter)) => iter,
+ None => return,
+ };
+
+ let mac = list_store_get!(app_data.app_gui.cli_model, &iter, 0, String);
+
+ if let Some(display) = gdk::Display::default() {
+ display.clipboard().set_text(&mac);
+ }
+ }));
+ app.add_action(&copy_mac);
+
+ let copy_vendor = gio::SimpleAction::new("copy_vendor", None);
+ copy_vendor.connect_activate(clone!(@strong app_data => move |_, _| {
+ let iter = match app_data.app_gui.cli_view.selection().selected() {
+ Some((_, iter)) => iter,
+ None => return,
+ };
+
+ let vendor = list_store_get!(app_data.app_gui.cli_model, &iter, 5, String);
+
+ if let Some(display) = gdk::Display::default() {
+ display.clipboard().set_text(&vendor);
+ }
+ }));
+ app.add_action(&copy_vendor);
+
+ let copy_probes = gio::SimpleAction::new("copy_probes", None);
+ copy_probes.connect_activate(clone!(@strong app_data => move |_, _| {
+ let iter = match app_data.app_gui.cli_view.selection().selected() {
+ Some((_, iter)) => iter,
+ None => return,
+ };
+
+ let probes = list_store_get!(app_data.app_gui.cli_model, &iter, 6, String);
+
+ if let Some(display) = gdk::Display::default() {
+ display.clipboard().set_text(&probes);
+ }
+ }));
+ app.add_action(&copy_probes);
+}
+
fn connect_about_button(app_data: Rc<AppData>) {
app_data
.app_gui
@@ -139,6 +264,71 @@ fn connect_focus_button(app_data: Rc<AppData>) {
}));
}
+pub fn update_buttons_sensitivity(app_data: &Rc<AppData>) {
+ let iter = match app_data.app_gui.aps_view.selection().selected() {
+ Some((_, iter)) => iter,
+ None => {
+ app_data.app_gui.focus_but.set_sensitive(false);
+ app_data.app_gui.deauth_but.set_sensitive(false);
+ app_data.app_gui.capture_but.set_sensitive(false);
+
+ app_data.app_gui.previous_but.set_sensitive(false);
+ app_data.app_gui.next_but.set_sensitive(false);
+
+ match app_data.app_gui.aps_model.iter_first() {
+ Some(_) => {
+ app_data.app_gui.top_but.set_sensitive(true);
+ app_data.app_gui.bottom_but.set_sensitive(true);
+ }
+ None => {
+ app_data.app_gui.top_but.set_sensitive(false);
+ app_data.app_gui.bottom_but.set_sensitive(false);
+ }
+ }
+
+ return;
+ }
+ };
+
+ let channel = list_store_get!(app_data.app_gui.aps_model, &iter, 3, i32);
+ match channel
+ == app_data
+ .app_gui
+ .channel_filter_entry
+ .text()
+ .parse::<i32>()
+ .unwrap_or(-1)
+ {
+ true => app_data.app_gui.focus_but.set_sensitive(false),
+ false => app_data.app_gui.focus_but.set_sensitive(true),
+ }
+ app_data.app_gui.deauth_but.set_sensitive(true);
+
+ let prev_iter = iter;
+ match app_data.app_gui.aps_model.iter_previous(&prev_iter) {
+ true => {
+ app_data.app_gui.previous_but.set_sensitive(true);
+ app_data.app_gui.top_but.set_sensitive(true);
+ }
+ false => {
+ app_data.app_gui.previous_but.set_sensitive(false);
+ app_data.app_gui.top_but.set_sensitive(false);
+ }
+ }
+
+ let next_iter = iter;
+ match app_data.app_gui.aps_model.iter_next(&next_iter) {
+ true => {
+ app_data.app_gui.next_but.set_sensitive(true);
+ app_data.app_gui.bottom_but.set_sensitive(true);
+ }
+ false => {
+ app_data.app_gui.next_but.set_sensitive(false);
+ app_data.app_gui.bottom_but.set_sensitive(false);
+ }
+ }
+}
+
fn connect_previous_button(app_data: Rc<AppData>) {
app_data
.app_gui
@@ -146,12 +336,12 @@ fn connect_previous_button(app_data: Rc<AppData>) {
.connect_clicked(clone!(@strong app_data => move |_| {
let iter = match app_data.app_gui.aps_view.selection().selected() {
Some((_, iter)) => iter,
- None => return,
+ None => return update_buttons_sensitivity(&app_data),
};
let prev_iter = iter;
if !app_data.app_gui.aps_model.iter_previous(&prev_iter) {
- return;
+ return update_buttons_sensitivity(&app_data);
}
let path = app_data.app_gui.aps_model.path(&prev_iter);
@@ -159,17 +349,7 @@ fn connect_previous_button(app_data: Rc<AppData>) {
app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
app_data.app_gui.cli_model.clear();
- if let Some((_, it)) = app_data.app_gui.aps_view.selection().selected() {
- let channel = list_store_get!(app_data.app_gui.aps_model, &it, 3, i32);
- match channel == app_data.app_gui.channel_filter_entry.text().parse::<i32>().unwrap_or(-1) {
- true => app_data.app_gui.focus_but.set_sensitive(false),
- false => app_data.app_gui.focus_but.set_sensitive(true),
- }
- } else {
- app_data.app_gui.focus_but.set_sensitive(false);
- }
-
- app_data.app_gui.deauth_but.set_sensitive(true);
+ update_buttons_sensitivity(&app_data);
}));
}
@@ -180,12 +360,12 @@ fn connect_next_button(app_data: Rc<AppData>) {
.connect_clicked(clone!(@strong app_data => move |_| {
let iter = match app_data.app_gui.aps_view.selection().selected() {
Some((_, iter)) => iter,
- None => return,
+ None => return update_buttons_sensitivity(&app_data),
};
let next_iter = iter;
if !app_data.app_gui.aps_model.iter_next(&next_iter) {
- return;
+ return update_buttons_sensitivity(&app_data);
}
let path = app_data.app_gui.aps_model.path(&next_iter);
@@ -193,17 +373,7 @@ fn connect_next_button(app_data: Rc<AppData>) {
app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
app_data.app_gui.cli_model.clear();
- if let Some((_, it)) = app_data.app_gui.aps_view.selection().selected() {
- let channel = list_store_get!(app_data.app_gui.aps_model, &it, 3, i32);
- match channel == app_data.app_gui.channel_filter_entry.text().parse::<i32>().unwrap_or(-1) {
- true => app_data.app_gui.focus_but.set_sensitive(false),
- false => app_data.app_gui.focus_but.set_sensitive(true),
- }
- } else {
- app_data.app_gui.focus_but.set_sensitive(false);
- }
-
- app_data.app_gui.deauth_but.set_sensitive(true);
+ update_buttons_sensitivity(&app_data);
}));
}
@@ -214,7 +384,7 @@ fn connect_top_button(app_data: Rc<AppData>) {
.connect_clicked(clone!(@strong app_data => move |_| {
let first_iter = match app_data.app_gui.aps_model.iter_first() {
Some(iter) => iter,
- None => return,
+ None => return update_buttons_sensitivity(&app_data),
};
let path = app_data.app_gui.aps_model.path(&first_iter);
@@ -222,17 +392,7 @@ fn connect_top_button(app_data: Rc<AppData>) {
app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
app_data.app_gui.cli_model.clear();
- if let Some((_, it)) = app_data.app_gui.aps_view.selection().selected() {
- let channel = list_store_get!(app_data.app_gui.aps_model, &it, 3, i32);
- match channel == app_data.app_gui.channel_filter_entry.text().parse::<i32>().unwrap_or(-1) {
- true => app_data.app_gui.focus_but.set_sensitive(false),
- false => app_data.app_gui.focus_but.set_sensitive(true),
- }
- } else {
- app_data.app_gui.focus_but.set_sensitive(false);
- }
-
- app_data.app_gui.deauth_but.set_sensitive(true);
+ update_buttons_sensitivity(&app_data);
}));
}
@@ -243,7 +403,7 @@ fn connect_bottom_button(app_data: Rc<AppData>) {
.connect_clicked(clone!(@strong app_data => move |_| {
let iter = match app_data.app_gui.aps_model.iter_first() {
Some(iter) => iter,
- None => return,
+ None => return update_buttons_sensitivity(&app_data),
};
let mut last_iter = iter;
@@ -257,17 +417,7 @@ fn connect_bottom_button(app_data: Rc<AppData>) {
app_data.app_gui.aps_view.scroll_to_cell(Some(&path), None, false, 0.0, 0.0);
app_data.app_gui.cli_model.clear();
- if let Some((_, it)) = app_data.app_gui.aps_view.selection().selected() {
- let channel = list_store_get!(app_data.app_gui.aps_model, &it, 3, i32);
- match channel == app_data.app_gui.channel_filter_entry.text().parse::<i32>().unwrap_or(-1) {
- true => app_data.app_gui.focus_but.set_sensitive(false),
- false => app_data.app_gui.focus_but.set_sensitive(true),
- }
- } else {
- app_data.app_gui.focus_but.set_sensitive(false);
- }
-
- app_data.app_gui.deauth_but.set_sensitive(true);
+ update_buttons_sensitivity(&app_data);
}));
}
@@ -299,27 +449,6 @@ fn start_app_refresh(app_data: Rc<AppData>) {
}
};
- 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() {
@@ -408,8 +537,38 @@ fn start_app_refresh(app_data: Rc<AppData>) {
app_data.deauth_gui.store.set(&app_data.deauth_gui.store.append(), &[(0, &false), (1, &cli.mac)]);
}
}
+ } else {
+ let clients = backend::get_unlinked_clients().clone();
+
+ for (_, cli) in clients {
+ 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(),
+ };
+
+ 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, &cli.vendor),
+ (6, &cli.probes),
+ (7, &gdk::RGBA::new(0.0, 0.0, 0.0, 0.0).to_str()),
+ ],
+ );
+ }
}
+ if !backend::get_aps().is_empty() {
+ app_data.app_gui.export_but.set_sensitive(true);
+ app_data.app_gui.report_but.set_sensitive(true);
+ }
+
+ update_buttons_sensitivity(&app_data);
+
ControlFlow::Continue
}),
);
@@ -559,8 +718,11 @@ fn connect_capture_button(app_data: Rc<AppData>) {
}));
}
-pub fn connect(app_data: Rc<AppData>) {
- connect_controller(app_data.clone());
+pub fn connect(app: &Application, app_data: Rc<AppData>) {
+ connect_window_controller(app_data.clone());
+
+ connect_aps_controller(app, app_data.clone());
+ connect_cli_controller(app, app_data.clone());
connect_about_button(app_data.clone());
connect_update_button(app_data.clone());
diff --git a/src/frontend/connections/deauth.rs b/src/frontend/connections/deauth.rs
index 18f560a..839072c 100755
--- a/src/frontend/connections/deauth.rs
+++ b/src/frontend/connections/deauth.rs
@@ -122,7 +122,7 @@ fn connect_attack_but(app_data: Rc<AppData>) {
return ErrorDialog::spawn(
&app_data.deauth_gui.window,
"Deauth attack failed",
- &format!("Could not start deauth process:\n\n{}", e),
+ e.to_string().as_str(),
);
};
diff --git a/src/frontend/connections/interface.rs b/src/frontend/connections/interface.rs
index f945d86..0fbf40c 100644
--- a/src/frontend/connections/interface.rs
+++ b/src/frontend/connections/interface.rs
@@ -76,9 +76,14 @@ fn connect_interface_select(app_data: Rc<AppData>) {
}
backend::set_iface(res.clone());
+ app_data.app_gui.restart_but.set_sensitive(true);
+ app_data.app_gui.iface_ico.set_sensitive(true);
+ app_data.app_gui.iface_label.set_sensitive(true);
app_data.app_gui.iface_label.set_text(&res);
app_data.app_gui.channel_filter_entry.set_sensitive(true);
+ app_data.app_gui.scan_but.emit_clicked();
+
match backend::is_5ghz_supported(&iface).unwrap_or(false) {
true => {
app_data.app_gui.ghz_2_4_but.set_sensitive(true);
@@ -91,7 +96,6 @@ fn connect_interface_select(app_data: Rc<AppData>) {
}
app_data.interface_gui.window.hide();
- app_data.app_gui.scan_but.emit_clicked();
}
Err(e) => {
backend::restore_network_manager().ok();
@@ -101,7 +105,7 @@ fn connect_interface_select(app_data: Rc<AppData>) {
ErrorDialog::spawn(
&app_data.interface_gui.window,
"Monitor mode failed",
- &e.message,
+ &e.to_string(),
);
}
};
diff --git a/src/frontend/connections/mod.rs b/src/frontend/connections/mod.rs
index 6672468..ee961b9 100644
--- a/src/frontend/connections/mod.rs
+++ b/src/frontend/connections/mod.rs
@@ -8,8 +8,8 @@ mod settings;
use crate::frontend::interfaces::AppData;
use std::rc::Rc;
-pub fn connect(app_data: Rc<AppData>) {
- app::connect(app_data.clone());
+pub fn connect(app: &gtk4::Application, app_data: Rc<AppData>) {
+ app::connect(app, app_data.clone());
scan::connect(app_data.clone());
interface::connect(app_data.clone());
deauth::connect(app_data.clone());
diff --git a/src/frontend/connections/scan.rs b/src/frontend/connections/scan.rs
index faa781b..3f68cfc 100644
--- a/src/frontend/connections/scan.rs
+++ b/src/frontend/connections/scan.rs
@@ -2,13 +2,10 @@ use crate::backend;
use crate::frontend::interfaces::*;
use crate::frontend::*;
use crate::list_store_get;
-use crate::types::*;
use glib::clone;
use gtk4::prelude::*;
use gtk4::*;
-use std::fs::File;
-use std::io::Write;
use std::rc::Rc;
use chrono::Local;
@@ -40,11 +37,7 @@ fn run_scan(app_data: &AppData) {
};
if let Err(e) = backend::set_scan_process(&iface, ghz_2_4, ghz_5, channel_filter) {
- return ErrorDialog::spawn(
- &app_data.app_gui.window,
- "Error",
- &format!("Could not start scan process:\n\n{}", e),
- );
+ return ErrorDialog::spawn(&app_data.app_gui.window, "Error", e.to_string().as_str());
}
app_data
@@ -71,15 +64,14 @@ fn connect_restart_button(app_data: Rc<AppData>) {
app_data
.app_gui
.restart_but
- .connect_clicked(clone!(@strong app_data => move |this| {
+ .connect_clicked(clone!(@strong app_data => move |_| {
backend::stop_scan_process().ok();
backend::get_aps().clear();
+ backend::get_unlinked_clients().clear();
app_data.app_gui.aps_model.clear();
app_data.app_gui.cli_model.clear();
- this.set_sensitive(false);
-
run_scan(&app_data);
}));
}
@@ -150,10 +142,6 @@ fn connect_report_button(app_data: Rc<AppData>) {
return;
}
- let aps = backend::get_aps().values().cloned().collect::<Vec<AP>>();
-
- let json_data = serde_json::to_string::<Vec<AP>>(&aps).unwrap();
-
let file_chooser_dialog = Rc::new(FileChooserDialog::new(
Some("Save capture report"),
Some(&app_data.app_gui.window),
@@ -165,17 +153,22 @@ fn connect_report_button(app_data: Rc<AppData>) {
let date = local.format("%Y-%m-%d-%Hh%M");
file_chooser_dialog.set_current_name(&format!("report_{}.json", date));
- file_chooser_dialog.run_async(move |this, response| {
+ 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 mut file = File::create(gio_file.path().unwrap()).unwrap();
- file.write_all(json_data.as_bytes()).unwrap();
+
+ let path = gio_file.path().unwrap().to_str().unwrap().to_string();
+
+ if let Err(e) = backend::save_report(&path) {
+ return ErrorDialog::spawn(&app_data.app_gui.window, "Save failed", &e.to_string());
+ }
}
- this.close();
- });
+ }));
}));
}
@@ -184,18 +177,24 @@ fn connect_ghz_2_4_button(app_data: Rc<AppData>) {
.app_gui
.ghz_2_4_but
.connect_toggled(clone!(@strong app_data => move |this| {
- if backend::is_scan_process() {
- if !this.is_active() && !app_data.app_gui.ghz_5_but.is_active() {
- ErrorDialog::spawn(
- &app_data.app_gui.window,
- "Error",
- "You need to select at least one frequency band",
- );
- return this.set_active(true);
+ if !this.is_active() && !app_data.app_gui.ghz_5_but.is_active() {
+ if backend::is_scan_process() {
+ app_data.app_gui.scan_but.emit_clicked();
}
- run_scan(&app_data);
+ app_data.app_gui.scan_but.set_sensitive(false);
+ app_data.app_gui.restart_but.set_sensitive(false);
+
+ let filter = app_data.app_gui.channel_filter_entry.text();
+ app_data.app_gui.channel_filter_entry.set_text(&filter);
+
+ return;
}
+ run_scan(&app_data);
+
+ app_data.app_gui.scan_but.set_sensitive(true);
+ app_data.app_gui.restart_but.set_sensitive(true);
+
let filter = app_data.app_gui.channel_filter_entry.text();
app_data.app_gui.channel_filter_entry.set_text(&filter);
}));
@@ -220,18 +219,24 @@ pub fn connect_ghz_5_button(app_data: Rc<AppData>) {
return this.set_active(false);
}
- if backend::is_scan_process() {
- if !this.is_active() && !app_data.app_gui.ghz_2_4_but.is_active() {
- ErrorDialog::spawn(
- &app_data.app_gui.window,
- "Error",
- "You need to select at least one frequency band",
- );
- return this.set_active(true);
+ if !this.is_active() && !app_data.app_gui.ghz_2_4_but.is_active() {
+ if backend::is_scan_process() {
+ app_data.app_gui.scan_but.emit_clicked();
}
- run_scan(&app_data);
+ app_data.app_gui.scan_but.set_sensitive(false);
+ app_data.app_gui.restart_but.set_sensitive(false);
+
+ let filter = app_data.app_gui.channel_filter_entry.text();
+ app_data.app_gui.channel_filter_entry.set_text(&filter);
+
+ return;
}
+ run_scan(&app_data);
+
+ app_data.app_gui.scan_but.set_sensitive(true);
+ app_data.app_gui.restart_but.set_sensitive(true);
+
let filter = app_data.app_gui.channel_filter_entry.text();
app_data.app_gui.channel_filter_entry.set_text(&filter);
}));
@@ -255,16 +260,7 @@ fn connect_channel_entry(app_data: Rc<AppData>) {
false => app_data.app_gui.hopping_but.set_sensitive(true),
}
- match app_data.app_gui.aps_view.selection().selected() {
- Some((_, it)) => {
- let channel = list_store_get!(app_data.app_gui.aps_model, &it, 3, i32);
- match channel == app_data.app_gui.channel_filter_entry.text().parse::<i32>().unwrap_or(-1) {
- true => app_data.app_gui.focus_but.set_sensitive(false),
- false => app_data.app_gui.focus_but.set_sensitive(true),
- }
- }
- None => app_data.app_gui.focus_but.set_sensitive(false),
- }
+ super::app::update_buttons_sensitivity(&app_data);
let ghz_2_4_but = app_data.app_gui.ghz_2_4_but.is_active();
let ghz_5_but = app_data.app_gui.ghz_5_but.is_active();
@@ -287,44 +283,31 @@ fn connect_cursor_changed(app_data: Rc<AppData>) {
.app_gui
.aps_view
.connect_cursor_changed(clone!(@strong app_data => move |this| {
- match this.selection().selected() {
- Some((_, it)) => {
- let channel = list_store_get!(app_data.app_gui.aps_model, &it, 3, i32);
- match channel == app_data.app_gui.channel_filter_entry.text().parse::<i32>().unwrap_or(-1) {
- true => app_data.app_gui.focus_but.set_sensitive(false),
- false => app_data.app_gui.focus_but.set_sensitive(true),
- }
- app_data.app_gui.deauth_but.set_sensitive(true);
+ super::app::update_buttons_sensitivity(&app_data);
- let (_, ap_iter) = this.selection().selected().unwrap();
- let bssid = list_store_get!(app_data.app_gui.aps_model, &ap_iter, 1, String);
- let aps = backend::get_aps();
+ if let Some((_, it)) = this.selection().selected() {
+ let bssid = list_store_get!(app_data.app_gui.aps_model, &it, 1, String);
+ let aps = backend::get_aps();
- let mut clients = match aps.get(&bssid) {
- Some(ap) => ap.clients.keys().clone(),
- None => return,
- };
- let mut cli_iter = app_data.app_gui.cli_model.iter_first();
+ let mut clients = match aps.get(&bssid) {
+ Some(ap) => ap.clients.keys().clone(),
+ None => return,
+ };
+ let mut cli_iter = app_data.app_gui.cli_model.iter_first();
- while let Some(it) = cli_iter {
- let mac_val = list_store_get!(app_data.app_gui.cli_model, &it, 0, String);
+ while let Some(it) = cli_iter {
+ let mac_val = list_store_get!(app_data.app_gui.cli_model, &it, 0, String);
- if !clients.any(|x| &mac_val == x) {
- break;
- }
+ if !clients.any(|x| &mac_val == x) {
+ break;
+ }
- cli_iter = match app_data.app_gui.cli_model.iter_next(&it) {
- true => Some(it),
- false => return,
- }
+ cli_iter = match app_data.app_gui.cli_model.iter_next(&it) {
+ true => Some(it),
+ false => return,
}
}
- None => {
- app_data.app_gui.focus_but.set_sensitive(false);
- app_data.app_gui.deauth_but.set_sensitive(false);
- app_data.app_gui.capture_but.set_sensitive(false);
- }
- };
+ }
app_data.app_gui.cli_model.clear();
}));
}
diff --git a/src/frontend/interfaces/app.rs b/src/frontend/interfaces/app.rs
index b08ad20..f5f2739 100755
--- a/src/frontend/interfaces/app.rs
+++ b/src/frontend/interfaces/app.rs
@@ -120,6 +120,7 @@ fn build_window(app: &Application) -> ApplicationWindow {
.default_height(620)
.build();
+ window.set_size_request(500, 500);
window.connect_close_request(|_| {
backend::app_cleanup();
glib::Propagation::Proceed
@@ -196,6 +197,7 @@ fn build_aps_view() -> TreeView {
view.append_column(&column);
}
+
view
}
@@ -207,6 +209,20 @@ fn build_aps_scroll() -> ScrolledWindow {
aps_scroll
}
+fn build_aps_menu() -> PopoverMenu {
+ let copy_bssid_item = gio::MenuItem::new(Some("Copy BSSID"), Some("app.copy_bssid"));
+ let copy_essid_item = gio::MenuItem::new(Some("Copy ESSID"), Some("app.copy_essid"));
+ let copy_channel_item = gio::MenuItem::new(Some("Copy Channel"), Some("app.copy_channel"));
+
+ let submenu = gio::Menu::new();
+
+ submenu.append_item(&copy_bssid_item);
+ submenu.append_item(&copy_essid_item);
+ submenu.append_item(&copy_channel_item);
+
+ PopoverMenu::from_model(Some(&submenu))
+}
+
fn build_cli_model() -> ListStore {
ListStore::new(&[
glib::Type::STRING, // Station MAC
@@ -214,8 +230,8 @@ fn build_cli_model() -> ListStore {
glib::Type::I32, // Power
glib::Type::STRING, // First time seen
glib::Type::STRING, // Last time seen
- glib::Type::STRING, // Probes
glib::Type::STRING, // Vendor
+ glib::Type::STRING, // Probes
glib::Type::STRING, // <color>
])
}
@@ -259,6 +275,7 @@ fn build_cli_view() -> TreeView {
view.append_column(&column);
}
+
view
}
@@ -269,6 +286,20 @@ fn build_cli_scroll() -> ScrolledWindow {
aps_scroll
}
+fn build_cli_menu() -> PopoverMenu {
+ let copy_mac_item = gio::MenuItem::new(Some("Copy MAC"), Some("app.copy_mac"));
+ let copy_vendor_item = gio::MenuItem::new(Some("Copy Vendor"), Some("app.copy_vendor"));
+ let copy_probes_item = gio::MenuItem::new(Some("Copy Probes"), Some("app.copy_probes"));
+
+ let submenu = gio::Menu::new();
+
+ submenu.append_item(&copy_mac_item);
+ submenu.append_item(&copy_vendor_item);
+ submenu.append_item(&copy_probes_item);
+
+ PopoverMenu::from_model(Some(&submenu))
+}
+
pub struct AppGui {
// Header bar
pub about_button: Button,
@@ -280,8 +311,13 @@ pub struct AppGui {
pub window: ApplicationWindow,
pub aps_model: ListStore,
pub aps_view: TreeView,
+ pub aps_scroll: ScrolledWindow,
+ pub aps_menu: PopoverMenu,
pub cli_model: ListStore,
pub cli_view: TreeView,
+ pub cli_scroll: ScrolledWindow,
+ pub cli_menu: PopoverMenu,
+ pub iface_ico: Image,
pub iface_label: Label,
pub ghz_2_4_but: CheckButton,
pub ghz_5_but: CheckButton,
@@ -330,7 +366,9 @@ impl AppGui {
// Interface Display
let iface_ico = Image::from_icon_name("network-wired");
+ iface_ico.set_sensitive(false);
let iface_label = Label::new(Some("None"));
+ iface_label.set_sensitive(false);
iface_label.set_tooltip_text(Some("Wireless interface used for scans and attacks"));
// Scan filters
@@ -426,14 +464,18 @@ impl AppGui {
let aps_model = build_aps_model();
let aps_view = build_aps_view();
let aps_scroll = build_aps_scroll();
+ let aps_menu = build_aps_menu();
+ aps_menu.set_parent(&aps_scroll);
aps_scroll.set_child(Some(&aps_view));
aps_view.set_model(Some(&aps_model));
let cli_model = build_cli_model();
let cli_view = build_cli_view();
let cli_scroll = build_cli_scroll();
+ let cli_menu = build_cli_menu();
+ cli_menu.set_parent(&cli_scroll);
cli_scroll.set_child(Some(&cli_view));
cli_view.set_model(Some(&cli_model));
@@ -456,8 +498,13 @@ impl AppGui {
window,
aps_model,
aps_view,
+ aps_scroll,
+ aps_menu,
cli_model,
cli_view,
+ cli_scroll,
+ cli_menu,
+ iface_ico,
iface_label,
ghz_2_4_but,
ghz_5_but,
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs
index 51845b6..ced1287 100644
--- a/src/frontend/mod.rs
+++ b/src/frontend/mod.rs
@@ -22,7 +22,7 @@ pub fn build_ui(app: &Application) {
gui_data.interface_gui.window.show();
- connections::connect(gui_data);
+ connections::connect(app, gui_data);
}
#[macro_export]
diff --git a/src/globals.rs b/src/globals.rs
index c83f4c2..088aad7 100644
--- a/src/globals.rs
+++ b/src/globals.rs
@@ -7,7 +7,7 @@ use std::sync::Mutex;
use std::thread::JoinHandle;
pub static APP_ID: &str = "com.molivier.airgorah";
-pub static VERSION: &str = "v0.7.1";
+pub static VERSION: &str = "v0.7.2";
pub static LIVE_SCAN_PATH: &str = "/tmp/airgorah_live_scan";
pub static OLD_SCAN_PATH: &str = "/tmp/airgorah_old_scan";
@@ -27,6 +27,7 @@ lazy_static! {
pub static ref UPDATE_PROC: Mutex<Option<JoinHandle<bool>>> = Mutex::new(None);
pub static ref SCAN_PROC: Mutex<Option<Child>> = Mutex::new(None);
pub static ref APS: Mutex<HashMap<String, AP>> = Mutex::new(HashMap::new());
+ pub static ref UNLINKED_CLIENTS: Mutex<HashMap<String, Client>> = Mutex::new(HashMap::new());
pub static ref ATTACK_POOL: Mutex<AttackPool> = Mutex::new(HashMap::new());
pub static ref VENDORS_CACHE: Mutex<HashMap<String, String>> = Mutex::new(HashMap::new());
pub static ref SETTINGS: Mutex<Settings> = Mutex::new(Settings::default());
diff --git a/src/main.rs b/src/main.rs
index 198a293..c97f14e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,6 @@ use gtk4::prelude::*;
use gtk4::{Application, Settings};
mod backend;
-mod error;
mod frontend;
mod globals;
mod types;