]> hackdaworld.org Git - my-code/hdw-sniff.git/commitdiff
second day
authorhackbard <hackbard>
Fri, 6 Sep 2002 04:21:35 +0000 (04:21 +0000)
committerhackbard <hackbard>
Fri, 6 Sep 2002 04:21:35 +0000 (04:21 +0000)
Makefile [new file with mode: 0644]
hdw-sniff.c
ieee80211.h [new file with mode: 0644]
ieee802_11.h [new file with mode: 0644]
rc4/rc4_ksaproc.pdf [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..8a234aa
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+#!/usr/bin/make
+
+CC = gcc
+CFLAGS = -O3
+LDFLAGS = -lpcap
+
+TARGETS = hdw-sniff
+
+all: $(TARGETS)
+
+hdw-sniff:
+       $(CC) $(CFLAGS) -Wall hdw-sniff.c $(LDFLAGS) -o hdw-sniff 
+
index 2757d6a02b775d5fd36bd5100cbc0a17b7dcfbfc..174e00f7d20b7e46092051154a5674fb98f80245 100644 (file)
@@ -6,12 +6,89 @@
 
 #include <stdio.h>
 #include <pcap.h>
+
+/* IEEE 802.3 stuff -- i will concentrate on .11 stuff before! */
+#include <netinet/if_ether.h>
+
+/* IEEE 802.11 stuff -- will become one include later ... */
+#include "ieee80211.h" /* from hunz's aeolus, short hostap_wlan.h */
+#include "ieee802_11.h" /* from pcmcia-cs */
+
 #include "hdw-sniff.h" /* my functions */
 
 int main(int argc, char *argv[]) {
-       
-       int count;
 
+       int i;
+       char pcap_error[PCAP_ERRBUF_SIZE];
+       pcap_t *pcap_handle;
+       const u_char *package;
+       struct pcap_pkthdr pcap_header;
+       struct ethhdr *e_hdr;
+       struct ieee802_11_hdr *w_hdr;
+       
        /* parse the arguments */
-       for(i=1;i<argc,++i) {
-                       
+       if(argc<2) {
+               printf("usage: %s <interface> <logfile>\n",argv[0]);
+               return 0;
+       }
+       if(argc!=3) {
+               printf("no logfile specified, writing to stdout ...\n");
+       }
+       
+       /* start pcap session */
+       pcap_handle=pcap_open_live(argv[1],BUFSIZ,1,-1,pcap_error);
+       if(pcap_handle==NULL) {
+               printf("%s: %s\n",argv[0],pcap_error);
+               return 1;
+       }
+       
+       /* grab a package until user breaks */
+       while (1) {
+       printf("\n");
+
+       printf("----| new package |----| hdw - sniff |----\n");
+       if((package=pcap_next(pcap_handle,&pcap_header))!=NULL) {
+               printf("package received at: %s",
+                       ctime((const time_t*)&pcap_header.ts.tv_sec));
+               printf("pcap header: ");
+               printf("capture length=%d ",pcap_header.caplen);
+               printf("length(off wire)=%d\n",pcap_header.len);
+       }
+       
+       /* 802.11 or 802.3 -- not quite sure about 'D' & '\0' */
+       if(*package=='D') {
+               printf("ieee802.11: ");
+       }
+       else if(*package=='\0') {
+               printf("ethernet: ");
+               /* reading ethernet header */
+               e_hdr=(struct ethhdr *)package;
+               /* what types ? */
+               printf("types = ");
+               // for(i=0;i<2;i++)
+               printf("%x %x\n",
+                       /* i==0?"0x":" ", */
+                       *(e_hdr->h_proto)
+                       /* i==1?"\n":"" */
+               );
+               printf("dest_addr = ");
+               for(i=0;i<ETH_ALEN;i++)
+               printf("%x%s",*(e_hdr->h_dest+i),((i==ETH_ALEN-1)?" ":":"));
+               printf(" src_addr = ");
+               for(i=0;i<ETH_ALEN;i++)
+               printf("%x%s",*(e_hdr->h_source+i),((i==ETH_ALEN-1)?"\n":":"));
+               printf("rest:\n");
+               for(i=sizeof(struct ethhdr);i<pcap_header.caplen;i++)
+                       printf("%x ",*(package+i));
+               printf("\n");
+       }
+       else {
+               printf("unknown: ");
+               /* print the whole package in hex */
+               for(i=0;i<=pcap_header.caplen;i++) printf("%x ",*(package+i));
+               printf("\n");
+               printf("%c <- identifier for unknown!\n",*package);
+       }
+       }
+       printf("just beacon frames, ha? - wake up early! :)");
+}
diff --git a/ieee80211.h b/ieee80211.h
new file mode 100644 (file)
index 0000000..d3b2453
--- /dev/null
@@ -0,0 +1,141 @@
+#ifndef IEEE80211_H
+#define IEEE80211_H
+
+typedef unsigned int u32;
+typedef unsigned short u16;
+typedef unsigned char u8;
+
+#include <endian.h>
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define le_to_host16(n) (n)
+#define host_to_le32(n) (n)
+#else
+#include <byteswap.h>
+#define le_to_host16(n) bswap_16(n)
+#define host_to_le32(n) bswap_32(n)
+#endif
+
+struct linux_wlan_ng_val {
+        u32 did;
+        u16 status, len;
+        u32 data;
+} __attribute__ ((packed));
+
+struct linux_wlan_ng_prism_hdr {
+        u32 msgcode, msglen;
+        char devname[16];
+        struct linux_wlan_ng_val hosttime, mactime, channel, rssi, sq, signal,
+                noise, rate, istx, frmlen;
+} __attribute__ ((packed));
+
+#define BIT(x) (1 << (x))
+
+#define WLAN_FC_PVER (BIT(1) | BIT(0))
+#define WLAN_FC_TODS BIT(8)
+#define WLAN_FC_FROMDS BIT(9)
+#define WLAN_FC_MOREFRAG BIT(10)
+#define WLAN_FC_RETRY BIT(11)
+#define WLAN_FC_PWRMGT BIT(12)
+#define WLAN_FC_MOREDATA BIT(13)
+#define WLAN_FC_ISWEP BIT(14)
+#define WLAN_FC_ORDER BIT(15)
+
+#define WLAN_FC_GET_TYPE(fc) (((fc) & (BIT(3) | BIT(2))) >> 2)
+#define WLAN_FC_GET_STYPE(fc) \
+        (((fc) & (BIT(7) | BIT(6) | BIT(5) | BIT(4))) >> 4)
+
+#define WLAN_GET_SEQ_FRAG(seq) ((seq) & (BIT(3) | BIT(2) | BIT(1) | BIT(0)))
+#define WLAN_GET_SEQ_SEQ(seq) \
+        (((seq) & (~(BIT(3) | BIT(2) | BIT(1) | BIT(0)))) >> 4)
+
+#define WLAN_FC_TYPE_MGMT 0
+#define WLAN_FC_TYPE_CTRL 1
+#define WLAN_FC_TYPE_DATA 2
+
+/* management */
+#define WLAN_FC_STYPE_ASSOC_REQ 0
+#define WLAN_FC_STYPE_ASSOC_RESP 1
+#define WLAN_FC_STYPE_REASSOC_REQ 2
+#define WLAN_FC_STYPE_REASSOC_RESP 3
+#define WLAN_FC_STYPE_PROBE_REQ 4
+#define WLAN_FC_STYPE_PROBE_RESP 5
+#define WLAN_FC_STYPE_BEACON 8
+#define WLAN_FC_STYPE_ATIM 9
+#define WLAN_FC_STYPE_DISASSOC 10
+#define WLAN_FC_STYPE_AUTH 11
+#define WLAN_FC_STYPE_DEAUTH 12
+
+/* control */
+#define WLAN_FC_STYPE_PSPOLL 10
+#define WLAN_FC_STYPE_RTS 11
+#define WLAN_FC_STYPE_CTS 12
+#define WLAN_FC_STYPE_ACK 13
+#define WLAN_FC_STYPE_CFEND 14
+#define WLAN_FC_STYPE_CFENDACK 15
+
+/* data */
+#define WLAN_FC_STYPE_DATA 0
+#define WLAN_FC_STYPE_DATA_CFACK 1
+#define WLAN_FC_STYPE_DATA_CFPOLL 2
+#define WLAN_FC_STYPE_DATA_CFACKPOLL 3
+#define WLAN_FC_STYPE_NULLFUNC 4
+#define WLAN_FC_STYPE_CFACK 5
+#define WLAN_FC_STYPE_CFPOLL 6
+#define WLAN_FC_STYPE_CFACKPOLL 7
+
+/* Authentication algorithms */
+#define WLAN_AUTH_OPEN 0
+#define WLAN_AUTH_SHARED_KEY 1
+
+#define WLAN_AUTH_CHALLENGE_LEN 128
+
+#define WLAN_CAPABILITY_ESS BIT(0)
+#define WLAN_CAPABILITY_IBSS BIT(1)
+#define WLAN_CAPABILITY_CF_POLLABLE BIT(2)
+#define WLAN_CAPABILITY_CF_POLL_REQUEST BIT(3)
+#define WLAN_CAPABILITY_PRIVACY BIT(4)
+
+/* Status codes */
+#define WLAN_STATUS_SUCCESS 0
+#define WLAN_STATUS_UNSPECIFIED_FAILURE 1
+#define WLAN_STATUS_CAPS_UNSUPPORTED 10
+#define WLAN_STATUS_REASSOC_NO_ASSOC 11
+#define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
+#define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
+#define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
+#define WLAN_STATUS_CHALLENGE_FAIL 15
+#define WLAN_STATUS_AUTH_TIMEOUT 16
+#define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
+#define WLAN_STATUS_ASSOC_DENIED_RATES 18
+/* 802.11b */
+#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
+#define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
+#define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
+
+/* Reason codes */
+#define WLAN_REASON_UNSPECIFIED 1
+#define WLAN_REASON_PREV_AUTH_NOT_VALID 2
+#define WLAN_REASON_DEAUTH_LEAVING 3
+#define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
+#define WLAN_REASON_DISASSOC_AP_BUSY 5
+#define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
+#define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
+#define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
+#define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
+
+
+/* Information Element IDs */
+#define WLAN_EID_SSID 0
+#define WLAN_EID_SUPP_RATES 1
+#define WLAN_EID_FH_PARAMS 2
+#define WLAN_EID_DS_PARAMS 3
+#define WLAN_EID_CF_PARAMS 4
+#define WLAN_EID_TIM 5
+#define WLAN_EID_IBSS_PARAMS 6
+#define WLAN_EID_CHALLENGE 16
+
+
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
+
+#endif
diff --git a/ieee802_11.h b/ieee802_11.h
new file mode 100644 (file)
index 0000000..e399f13
--- /dev/null
@@ -0,0 +1,73 @@
+#ifndef _IEEE802_11_H
+#define _IEEE802_11_H
+
+#define IEEE802_11_DATA_LEN            2304
+/* Actually, the standard seems to be inconsistent about what the
+   maximum frame size really is.  S6.2.1.1.2 says 2304 octets, but the
+   figure in section 7.1.2 says 2312 octects. */
+#define IEEE802_11_HLEN                        30
+#define IEEE802_11_FRAME_LEN           (IEEE802_11_DATA_LEN + IEEE802_11_HLEN)
+
+struct ieee802_11_hdr {
+       u16 frame_ctl;
+       u16 duration_id;
+       u8 addr1[ETH_ALEN];
+       u8 addr2[ETH_ALEN];
+       u8 addr3[ETH_ALEN];
+       u16 seq_ctl;
+       u8 addr4[ETH_ALEN];
+} __attribute__ ((packed));
+
+/* Frame control field constants */
+#define IEEE802_11_FCTL_VERS           0x0002
+#define IEEE802_11_FCTL_FTYPE          0x000c
+#define IEEE802_11_FCTL_STYPE          0x00f0
+#define IEEE802_11_FCTL_TODS           0x0100
+#define IEEE802_11_FCTL_FROMDS         0x0200
+#define IEEE802_11_FCTL_MOREFRAGS      0x0400
+#define IEEE802_11_FCTL_RETRY          0x0800
+#define IEEE802_11_FCTL_PM             0x1000
+#define IEEE802_11_FCTL_MOREDATA       0x2000
+#define IEEE802_11_FCTL_WEP            0x4000
+#define IEEE802_11_FCTL_ORDER          0x8000
+
+#define IEEE802_11_FTYPE_MGMT          0x0000
+#define IEEE802_11_FTYPE_CTL           0x0004
+#define IEEE802_11_FTYPE_DATA          0x0008
+
+/* management */
+#define IEEE802_11_STYPE_ASSOC_REQ     0x0000
+#define IEEE802_11_STYPE_ASSOC_RESP    0x0010
+#define IEEE802_11_STYPE_REASSOC_REQ   0x0020
+#define IEEE802_11_STYPE_REASSOC_RESP  0x0030
+#define IEEE802_11_STYPE_PROBE_REQ     0x0040
+#define IEEE802_11_STYPE_PROBE_RESP    0x0050
+#define IEEE802_11_STYPE_BEACON                0x0080
+#define IEEE802_11_STYPE_ATIM          0x0090
+#define IEEE802_11_STYPE_DISASSOC      0x00A0
+#define IEEE802_11_STYPE_AUTH          0x00B0
+#define IEEE802_11_STYPE_DEAUTH                0x00C0
+
+/* control */
+#define IEEE802_11_STYPE_PSPOLL                0x00A0
+#define IEEE802_11_STYPE_RTS           0x00B0
+#define IEEE802_11_STYPE_CTS           0x00C0
+#define IEEE802_11_STYPE_ACK           0x00D0
+#define IEEE802_11_STYPE_CFEND         0x00E0
+#define IEEE802_11_STYPE_CFENDACK      0x00F0
+
+/* data */
+#define IEEE802_11_STYPE_DATA          0x0000
+#define IEEE802_11_STYPE_DATA_CFACK    0x0010
+#define IEEE802_11_STYPE_DATA_CFPOLL   0x0020
+#define IEEE802_11_STYPE_DATA_CFACKPOLL        0x0030
+#define IEEE802_11_STYPE_NULLFUNC      0x0040
+#define IEEE802_11_STYPE_CFACK         0x0050
+#define IEEE802_11_STYPE_CFPOLL                0x0060
+#define IEEE802_11_STYPE_CFACKPOLL     0x0070
+
+#define IEEE802_11_SCTL_FRAG           0x000F
+#define IEEE802_11_SCTL_SEQ            0xFFF0
+
+#endif /* _IEEE802_11_H */
+
diff --git a/rc4/rc4_ksaproc.pdf b/rc4/rc4_ksaproc.pdf
new file mode 100644 (file)
index 0000000..02e7bea
Binary files /dev/null and b/rc4/rc4_ksaproc.pdf differ