simple_wifi

Simple 802.11 Wi-Fi packet parser

3 releases

0.1.6 May 11, 2024
0.1.5 May 11, 2024
0.1.4 Jan 29, 2024

47 downloads per month

MIT license

38KB
670 lines

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
        )
    }
}

Dependencies

~345KB