Home page logo
/

pen-test logo Penetration Testing mailing list archives

RE: Converting raw 802.11 (rfmon) capture file to standard libpcap
From: "Jerry Shenk" <jshenk () decommunications com>
Date: Wed, 14 Jan 2004 12:47:14 -0500

Netstumbler is a windows-based utility that sends out a probe and looks
for a response.  Netstumbler doesn't store and data to disk.
Netstumbler finds Access Points sending the probe and logging the
response.  If an AP doesn't respond, Netstumbler won't know about it.

In my testing, I normally use Kismet which is a Linux-based utility.
Kismet is a totally passive program that just watches for incoming
traffic and then it logs it all to disk.  Since it's passive, it's
nearly impossible to detect.  Kismet puts the wireless card into rfmon
mode.  That is similar to promiscuous mode on a regular Ethernet card
except that it's at the 802.11 layer instead of the Ethernet layer.
With kismet or anything else running in rfmon mode, the Ethernet frame
as well as it's associated 802.11 header is stored to disk.  That's
great for some things...if a wireless client sends a probe request and
the AP responds, Kismet will log that information and determine the SSID
of an AP even if the broadcast was turned off.  It will also enable the
determination of MAC addresses on an encrypted network and all sorts of
other interesting info.  The downside is that most utilities aren't
written to understand rfmon captures (what I initially called raw -
that's not really the right word).  Chris just wrote this utility that
will convert these rfmon packets to Ethernet packets.  Now we can
analyze this new packet with 'normal' tools including tcpreplay which
will allow me to send this captured traffic over my test network and
analyze it with any tool that can monitor the wire or any tool that can
read a pcap file.  ....and if it can't read a pcap file, I can use
tethereal to convert it to some other format.

-----Original Message-----
From: Miller, Ari [mailto:ari.miller () eds com] 
Sent: Wednesday, January 14, 2004 12:30 PM
To: 'cseagle () redshift com'; 'jshenk () decommunications com'
Subject: FW: Converting raw 802.11 (rfmon) capture file to standard
libpcap


Chris or Jerry,
I'm just starting to get involved with some penetration testing and came
across this e-mail thread regarding the formatting of wireless captures.
I
don't have a lot of experience with wireless, but have used netstumbler,
ethereal, etc. a little.  I'm not really familiar with "rfmon"...  Can
either of you explain to me what the script below is doing exactly?  I
really didn't want to bog the list down with this question...  If you
have a
phone number and it is easier, I'd be happy to call you as well.

Thanks!
Ari


-----Original Message-----
From: Jerry Shenk [mailto:jshenk () decommunications com]
Sent: Wednesday, January 14, 2004 9:33 AM
To: pen-test () securityfocus com
Subject: RE: Converting raw 802.11 (rfmon) capture file to standard
libpcap


That works for me too!!! That's awesome!  That's gonna make wireless pen
testing a lot faster...in fact, I just ran it through a could old dump
files.  Tcpdump works, snort works, tcpreplay works...everything I've
tested.  p0f works and looks accurate...I thought that might end up with
'goofy' results but it seems right.

-----Original Message-----
From: Chris Eagle [mailto:cseagle () redshift com] 
Sent: Wednesday, January 14, 2004 12:13 AM
To: Jerry Shenk; pen-test () securityfocus com
Subject: RE: Converting raw 802.11 (rfmon) capture file to standard
libpcap


Jerry Shenk wrote:

That is exactly what I want...

Ok I cobbled this up.  It's rough but it seems to work for me:

# gcc -o wifi2eth wifi2eth.c -lpcap
# ./wifi2eth raw.dat eth.dat

--------------------------------------------------------------
/*
  File: wifi2eth.c

  Copyright (c) 2004 Chris Eagle <cseagle at redshift d0t c0m>

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
"Software"),
  to deal in the Software without restriction, including without
limitation
  the rights to use, copy, modify, merge, publish, distribute,
sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be
included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL
THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS
  IN THE SOFTWARE.
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pcap.h>

#define FC80211_DATA       0x08
#define FC80211_TYPE_MASK  0x0C

#define PRISM_OFFSET 144

struct p80211_hdr_data {
   unsigned short frame_control __attribute__ ((packed));
   unsigned short duration_id __attribute__ ((packed));
   unsigned char addr1[6] __attribute__ ((packed));
   unsigned char addr2[6] __attribute__ ((packed));
   unsigned char addr3[6] __attribute__ ((packed));
   unsigned short seq_ctrl __attribute__ ((packed));
   unsigned char addr4[6] __attribute__ ((packed));
};

struct p8022_hdr {
   unsigned int snap;
   unsigned short dummy;
   unsigned short ethertype;
   unsigned char data[0];
};

#define TCPDUMP_MAGIC 0xa1b2c3d4

int PKT_OFFSET = PRISM_OFFSET;

void usage(void) {
   fprintf(stderr, "Version: 0.01\nUsage: wifi2eth inputfile
outputfile\n");
   exit(1);
}

void *destMac(struct p80211_hdr_data *wh) {
   if (wh->frame_control & 0x0100) {
      return wh->addr3;
   }
   return wh->addr1;
}

void *sourceMac(struct p80211_hdr_data *wh) {
   switch (wh->frame_control & 0x0300) {
      case 0x0000: //AD_HOC
      case 0x0100: //TO_DS
         return wh->addr2;
      case 0x0200: //FROM_DS
         return wh->addr3;
      case 0x0300:
         return wh->addr4;
   }
}

int hdrLen(struct p80211_hdr_data *wh) {
   return ((wh->frame_control & 0x0300) == 0x0300) ? 30 : 24;
}

int usesWep(struct p8022_hdr *eh) {
   return eh->snap != 0x0003AAAA;  //only works for little endian!! }

int isData(struct p80211_hdr_data *wh) {
   return (wh->frame_control & FC80211_TYPE_MASK) == FC80211_DATA; }

void packetCallback(u_char *user, struct pcap_pkthdr *pph, u_char
*pdata){
   struct p80211_hdr_data *wh;
   struct p8022_hdr *eh;
   int start802, outfile;
   outfile = (int) user;
   //the 24 below is a minimum data frame header
   if (pph->len < (PKT_OFFSET + 24)) return;  //simple safety check
   wh = (struct p80211_hdr_data*) (pdata + PKT_OFFSET);
   start802 = PKT_OFFSET + hdrLen(wh);
   //if we don't have an 802.2 header then we have no useful data
   if (pph->len < (start802 + sizeof(struct p8022_hdr))) return;
   eh = (struct p8022_hdr*)(pdata + start802);
   switch (wh->frame_control & FC80211_TYPE_MASK) {
      case FC80211_DATA:
         if (!usesWep(eh)) {
            //the 8 here is for the SNAP/OID bytes.  The result should
be
the
            //length of the IP packet
            int datalen = pph->len - start802 - 8;
            pph->len = datalen + 14;
            pph->caplen = pph->len;
            write(outfile, pph, sizeof(struct pcap_pkthdr));
            write(outfile, destMac(wh), 6);
            write(outfile, sourceMac(wh), 6);
            write(outfile, &eh->ethertype, 2);
            write(outfile, &eh->data, datalen);
         }
         break;
   }
}

int open_dump(char *fname) {
   int fd = -1;
   struct pcap_file_header pfh = {TCPDUMP_MAGIC, PCAP_VERSION_MAJOR,
                                  PCAP_VERSION_MINOR, 8, 0, 1514,
                                  DLT_EN10MB };
   fd = open(fname, O_WRONLY | O_CREAT, 0644);
   write(fd, &pfh, sizeof(pfh));
   return fd;
}

int main (int argc, char * argv[]) {
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_t* descr;
    char *dev;
    int outfile, dl;
    if (argc != 3) usage();
    descr = pcap_open_offline(argv[1], errbuf);
    dl = pcap_datalink(descr);
    if (dl == DLT_IEEE802_11) {
       PKT_OFFSET = 0;
    }
    else if (dl != DLT_PRISM_HEADER) {
       pcap_close(descr);
       fprintf(stderr, "%s does not appear to be an 802.11 capture
file\n",
               argv[1]);
       exit(1);
    }
    outfile = open_dump(argv[2]);

    pcap_dispatch(descr, -1, (pcap_handler)packetCallback, (u_char
*)outfile);
    pcap_close(descr);
    close(outfile);

    return 0;
}



------------------------------------------------------------------------
---
------------------------------------------------------------------------
----


---------------------------------------------------------------------------
----------------------------------------------------------------------------


  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]