Skip to content

Commit

Permalink
v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragnt committed Jan 20, 2024
1 parent e4d5df5 commit 83a345f
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 176 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["libs/libwifi", "libs/libwifi_macros", "libs/pcap-file"]

[workspace.package]
version = "0.7.8"
version = "0.8.0"
authors = ["Ryan Butler"]
description = "80211 Attack Tool"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion libs/libwifi/src/frame/components/mac_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rand::{thread_rng, Rng, RngCore};
/// // -> true
/// ```
///
#[derive(Clone, Debug, Eq, PartialEq, Copy)]
#[derive(Clone, Debug, Eq, PartialEq, Copy, Ord, PartialOrd)]
pub struct MacAddress(pub [u8; 6]);

impl Hash for MacAddress {
Expand Down
45 changes: 29 additions & 16 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,14 @@ impl HandshakeSessionKey {
#[derive(Debug, Clone)]
pub struct HandshakeStorage {
handshakes: HashMap<HandshakeSessionKey, Vec<FourWayHandshake>>,
handshakes_sorted: Vec<FourWayHandshake>,
}

impl HandshakeStorage {
pub fn new() -> Self {
HandshakeStorage {
handshakes: HashMap::new(),
handshakes_sorted: Vec::new(),
}
}

Expand All @@ -666,6 +668,27 @@ impl HandshakeStorage {
})
}

pub fn sort_handshakes(&mut self) {
// Make our handshakes list
let mut print_handshakes: Vec<FourWayHandshake> = Vec::new();

let binding = self.get_handshakes();
for handshake_list in binding.values() {
for handshake in handshake_list {
print_handshakes.push(handshake.clone());
}
}

print_handshakes.sort_by(|a, b| {
b.last_msg
.clone()
.unwrap()
.timestamp
.cmp(&a.last_msg.clone().unwrap().timestamp)
});
self.handshakes_sorted = print_handshakes;
}

pub fn add_or_update_handshake(
&mut self,
ap_mac: &MacAddress,
Expand Down Expand Up @@ -738,22 +761,8 @@ impl HandshakeStorage {
];

// Make our handshakes list
let mut print_handshakes: Vec<&FourWayHandshake> = Vec::new();

let binding = self.get_handshakes();
for handshake_list in binding.values() {
for handshake in handshake_list {
print_handshakes.push(handshake);
}
}

print_handshakes.sort_by(|a, b| {
b.last_msg
.clone()
.unwrap()
.timestamp
.cmp(&a.last_msg.clone().unwrap().timestamp)
});
self.sort_handshakes();
let print_handshakes = &self.handshakes_sorted;

let mut rows: Vec<(Vec<String>, u16)> = Vec::new();

Expand Down Expand Up @@ -807,6 +816,10 @@ impl HandshakeStorage {
}
(headers, rows)
}

pub fn get_sorted(&self) -> &Vec<FourWayHandshake> {
&self.handshakes_sorted
}
}

fn add_handshake_header_row(hs_row: Vec<String>) -> Vec<String> {
Expand Down
199 changes: 103 additions & 96 deletions src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,15 @@ impl Station {
#[derive(Clone, Debug, Default)]
pub struct WiFiDeviceList<T: WiFiDeviceType> {
devices: HashMap<MacAddress, T>,
devices_sorted: Vec<T>,
}

// Common functions for any type of device
impl<T: WiFiDeviceType> WiFiDeviceList<T> {
pub fn new() -> Self {
WiFiDeviceList {
devices: HashMap::new(),
devices_sorted: Vec::new(),
}
}

Expand Down Expand Up @@ -561,6 +563,75 @@ impl WiFiDeviceList<AccessPoint> {
all_clients
}

pub fn sort_devices(&mut self, sort: u8, sort_reverse: bool) {
let mut access_points: Vec<AccessPoint> = self
.get_devices()
.iter()
.map(|(_, access_point)| access_point.clone())
.collect();

match sort {
0 => access_points.sort_by(|a, b| {
// TGT
match (
a.is_target(),
a.is_whitelisted(),
b.is_target(),
b.is_whitelisted(),
) {
// Highest priority: is_target() = true, is_whitelist() = false
(true, false, _, _) => std::cmp::Ordering::Less,
(_, _, true, false) => std::cmp::Ordering::Greater,

// Middle priority: is_target() = false, is_whitelist() = false
(false, false, false, true) => std::cmp::Ordering::Less,
(false, true, false, false) => std::cmp::Ordering::Greater,

// Lowest priority: is_target() = false, is_whitelist() = true
// This case is covered implicitly by the previous matches

// Fallback for equal cases
_ => std::cmp::Ordering::Equal,
}
}),
1 => access_points.sort_by(|a, b| b.channel.cmp(&a.channel)), // CH
2 => access_points.sort_by(|a, b| {
// RSSI
let a_val = a.last_signal_strength.value;
let b_val = b.last_signal_strength.value;

match (a_val, b_val) {
// If both values are the same (and it doesn't matter if they are zero or not)
_ if a_val == b_val => std::cmp::Ordering::Equal,

// Prioritize any non-zero value over zero
(0, _) => std::cmp::Ordering::Greater, // A is worse if it's zero
(_, 0) => std::cmp::Ordering::Less, // B is worse if it's zero

// Otherwise, just do a normal comparison
_ => b_val.cmp(&a_val),
}
}),
3 => access_points.sort_by(|a, b| b.last_recv.cmp(&a.last_recv)), // Last
4 => access_points.sort_by(|a, b| b.client_list.size().cmp(&a.client_list.size())), // Clients
5 => access_points.sort_by(|a, b| b.interactions.cmp(&a.interactions)), // Tx
6 => access_points.sort_by(|a, b| b.has_hs.cmp(&a.has_hs)), // HS
7 => access_points.sort_by(|a, b| b.has_pmkid.cmp(&a.has_pmkid)), // PM
_ => {
access_points.sort_by(|a, b| b.last_recv.cmp(&a.last_recv));
}
}

if sort_reverse {
access_points.reverse();
}
self.devices_sorted = access_points;
}

pub fn get_devices_sorted(&self) -> &Vec<AccessPoint> {
&self.devices_sorted
}

pub fn clear_all_interactions(&mut self) {
for dev in self.devices.values_mut() {
dev.interactions = 0;
Expand Down Expand Up @@ -621,8 +692,6 @@ impl WiFiDeviceList<AccessPoint> {
selected_row: Option<usize>,
sort: u8,
sort_reverse: bool,
copys: bool,
copyl: bool,
) -> (Vec<String>, Vec<(Vec<String>, u16)>) {
// Header fields
let headers = vec![
Expand All @@ -638,66 +707,8 @@ impl WiFiDeviceList<AccessPoint> {
"PMKID".to_string(),
];

let mut access_points: Vec<_> = self
.get_devices()
.iter()
.map(|(_, access_point)| access_point)
.collect();
match sort {
0 => access_points.sort_by(|a, b| {
// TGT
match (
a.is_target(),
a.is_whitelisted(),
b.is_target(),
b.is_whitelisted(),
) {
// Highest priority: is_target() = true, is_whitelist() = false
(true, false, _, _) => std::cmp::Ordering::Less,
(_, _, true, false) => std::cmp::Ordering::Greater,

// Middle priority: is_target() = false, is_whitelist() = false
(false, false, false, true) => std::cmp::Ordering::Less,
(false, true, false, false) => std::cmp::Ordering::Greater,

// Lowest priority: is_target() = false, is_whitelist() = true
// This case is covered implicitly by the previous matches

// Fallback for equal cases
_ => std::cmp::Ordering::Equal,
}
}),
1 => access_points.sort_by(|a, b| b.channel.cmp(&a.channel)), // CH
2 => access_points.sort_by(|a, b| {
// RSSI
let a_val = a.last_signal_strength.value;
let b_val = b.last_signal_strength.value;

match (a_val, b_val) {
// If both values are the same (and it doesn't matter if they are zero or not)
_ if a_val == b_val => std::cmp::Ordering::Equal,

// Prioritize any non-zero value over zero
(0, _) => std::cmp::Ordering::Greater, // A is worse if it's zero
(_, 0) => std::cmp::Ordering::Less, // B is worse if it's zero

// Otherwise, just do a normal comparison
_ => b_val.cmp(&a_val),
}
}),
3 => access_points.sort_by(|a, b| b.last_recv.cmp(&a.last_recv)), // Last
4 => access_points.sort_by(|a, b| b.client_list.size().cmp(&a.client_list.size())), // Clients
5 => access_points.sort_by(|a, b| b.interactions.cmp(&a.interactions)), // Tx
6 => access_points.sort_by(|a, b| b.has_hs.cmp(&a.has_hs)), // HS
7 => access_points.sort_by(|a, b| b.has_pmkid.cmp(&a.has_pmkid)), // PM
_ => {
access_points.sort_by(|a, b| b.last_recv.cmp(&a.last_recv));
}
}

if sort_reverse {
access_points.reverse();
}
self.sort_devices(sort, sort_reverse);
let access_points = &self.devices_sorted;

let mut rows: Vec<(Vec<String>, u16)> = Vec::new();
for (idx, ap) in access_points.iter().enumerate() {
Expand Down Expand Up @@ -746,12 +757,7 @@ impl WiFiDeviceList<AccessPoint> {
ap_row = merged;
height += 1;
}
if copys {
terminal_clipboard::set_string(ap.mac_address.to_string()).unwrap();
}
if copyl {
terminal_clipboard::set_string(ap.to_json_str()).unwrap();
}

}
rows.push((ap_row, height));
}
Expand Down Expand Up @@ -851,31 +857,11 @@ fn add_probe_rows(

// Functions specific to a WiFiDeviceList holding Stations
impl WiFiDeviceList<Station> {
pub fn get_table(
&mut self,
selected_row: Option<usize>,
sort: u8,
sort_reverse: bool,
copys: bool,
copyl: bool,
) -> (Vec<String>, Vec<(Vec<String>, u16)>) {
// Header fields
//"MAC Address", "RSSI", "Last", Tx, "Probes"
let headers = vec![
"MAC Address".to_string(),
"RSSI".to_string(),
"Last".to_string(),
"Tx".to_string(),
"Rogue M2".to_string(),
"Probes".to_string(),
];

// Make our stations object

pub fn sort_devices(&mut self, sort: u8, sort_reverse: bool) {
let mut stations: Vec<_> = self
.get_devices()
.iter()
.map(|(_, access_point)| access_point)
.map(|(_, station)| station.clone())
.collect();

match sort {
Expand Down Expand Up @@ -914,6 +900,33 @@ impl WiFiDeviceList<Station> {
if sort_reverse {
stations.reverse();
}
self.devices_sorted = stations;
}

pub fn get_devices_sorted(&self) -> &Vec<Station> {
&self.devices_sorted
}

pub fn get_table(
&mut self,
selected_row: Option<usize>,
sort: u8,
sort_reverse: bool
) -> (Vec<String>, Vec<(Vec<String>, u16)>) {
// Header fields
//"MAC Address", "RSSI", "Last", Tx, "Probes"
let headers = vec![
"MAC Address".to_string(),
"RSSI".to_string(),
"Last".to_string(),
"Tx".to_string(),
"Rogue M2".to_string(),
"Probes".to_string(),
];

// Make our stations object
self.sort_devices(sort, sort_reverse);
let stations = &self.devices_sorted;

let mut rows: Vec<(Vec<String>, u16)> = Vec::new();
for (idx, station) in stations.iter().enumerate() {
Expand Down Expand Up @@ -954,12 +967,6 @@ impl WiFiDeviceList<Station> {
height += 1;
}
}
if copys {
terminal_clipboard::set_string(station.mac_address.to_string()).unwrap();
}
if copyl {
terminal_clipboard::set_string(station.to_json_str()).unwrap();
}
}
rows.push((cl_row, height));
}
Expand Down
5 changes: 4 additions & 1 deletion src/eventhandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ impl EventHandler {
KeyCode::Char('Y') => tx.send(EventType::Key(event)),
KeyCode::Char('c') => tx.send(EventType::Key(event)),
KeyCode::Char('C') => tx.send(EventType::Key(event)),
_ => Ok({}),
KeyCode::Char('t') => tx.send(EventType::Key(event)),
KeyCode::Char('T') => tx.send(EventType::Key(event)),
KeyCode::Char('k') => tx.send(EventType::Key(event)),
_ => Ok(()),
};
}
} else if let Event::Mouse(mouse) = event {
Expand Down
Loading

0 comments on commit 83a345f

Please sign in to comment.