#packet-parser #wifi #packet #parser #scapy

simple_wifi

Simple 802.11 Wi-Fi packet parser

2 releases

0.1.4 Jan 29, 2024
0.1.3 Jan 24, 2024
0.1.2 Jan 23, 2024
0.1.1 Jan 23, 2024
0.1.0 Jan 20, 2024

#1718 in Network programming

Download history 23/week @ 2024-01-19 6/week @ 2024-01-26 3/week @ 2024-02-16 9/week @ 2024-02-23 1/week @ 2024-03-01 10/week @ 2024-03-08 10/week @ 2024-03-15 45/week @ 2024-03-29

65 downloads per month

MIT license

38KB
661 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.

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

~340KB