simple_wifi

Crates.iosimple_wifi
lib.rssimple_wifi
version0.1.6
sourcesrc
created_at2024-01-20 21:22:15.058227
updated_at2024-05-11 00:55:31.732911
descriptionSimple 802.11 Wi-Fi packet parser.
homepage
repository
max_upload_size
id1106818
size37,947
(paulmillo)

documentation

https://docs.rs/simple_wifi

README

simple_wifi is a module for a quick decoding of 802.11 Wi-Fi Packets

simple_wifi takes the raw packet and provides the Name of the packet, packet type, packet subtype, toDS, FromDS, signal, channel, address1, address2, address3, address4, SSID. It also gives you the ability to write the packet to a pcap file as well.

Updates

Now you have the ability to write packets that have errored while decoding to a pcap file. More RadioTap Header Lengths have been added for decoding. Added the decoding for a DMG Beacon. Packet Type: 3 Subtype: 0. Added another ssid to see if all the characters are null. If so then the ssid will be "U_n_k_n_o_w_n".

Testing

simple_wifi was tested on Linux Debian Distro using Alpha Wi-Fi card. Using the module pnet to open the socket and sniff the packets from the Wi-Fi card.

Example

# extern crate pnet;
# extern crate simple_wifi;
use pnet::datalink::{ self, NetworkInterface, Channel::Ethernet};
use simple_wifi::*;
use std::process;

fn main() {
    // Wi-Fi card to sniff packets with.//!
    let wifi_card: &str = "wlo1";

    // Finding the interface that matches the wifi_card. So it can be used for sniffing.
    let interface: NetworkInterface = datalink::interfaces()
        .into_iter()
        .filter(|iface: &NetworkInterface| iface.name == wifi_card)
        .next()
        .unwrap();

    // Setting up the channel to the interface so you can sniff Wi-Fi packets.
    let (_, mut rx) = match datalink::channel(&interface, Default::default()) {
        Ok(Ethernet(tx, rx)) => (tx, rx),
        Ok(_) => {
            println!("\x1b[38;5;9mUnhandled channel type\x1b[0m");
            process::exit(0);
        },
        Err(e) => {
            println!("\x1b[38;5;9mAn error occurred when creating the datalink channel: {e}\x1b[0m");
            process::exit(0);
        }

    };

    loop {
        let pkt: &[u8] = match rx.next() {
            Ok(pkt) => pkt,
            Err(_) => continue
        };

        let pkt_info: Packet = match Packet::new(pkt) {
            Ok(t) => t,
            Err(e) => {
                println!("\x1b[38;5;9m{e}\x1b[0m");
                let _ = write_pcap(&pkt.to_vec(), "/home/user/error.pcap");
                continue;
            }
        };

        println!("{pkt_info:#?}");
        println!(
            "Address1: {}, Address2: {}\nAddress3: {}, Address4: {}",
            pkt_info.addr1, pkt_info.addr2, pkt_info.addr3, pkt_info.addr4
        )
    }
}
Commit count: 0

cargo fmt