author | mjm <mjm> | 2002-11-12 22:12:33 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-11-12 22:12:33 (UTC) |
commit | eaecbed44924ece119c5b41db2828b4554f263d2 (patch) (unidiff) | |
tree | b87dd3d049ea1768b20192f6c674f8684a41282c | |
parent | 15bc80dffd7a4c52985a742cb3a439da42692478 (diff) | |
download | opie-eaecbed44924ece119c5b41db2828b4554f263d2.zip opie-eaecbed44924ece119c5b41db2828b4554f263d2.tar.gz opie-eaecbed44924ece119c5b41db2828b4554f263d2.tar.bz2 |
pre-alpha version, most things does not work yet.
todo: communication protocol with GUI and implementation of sniffer
16 files changed, 437 insertions, 93 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/Makefile b/noncore/net/wellenreiter/daemon/source/Makefile new file mode 100644 index 0000000..dc459af --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/Makefile | |||
@@ -0,0 +1,31 @@ | |||
1 | # $Id$ | ||
2 | |||
3 | CPP = g++ | ||
4 | |||
5 | CFLAGS= | ||
6 | OPTIMFLAGS= -g | ||
7 | WARNFLAGS= -Wall -pedantic -DDEBUG | ||
8 | LDFLAGS = | ||
9 | LIBS = -lpcap | ||
10 | OBJ = daemon.o log.o sendgui.o getgui.o sniffer.o | ||
11 | |||
12 | .SUFFIXES: | ||
13 | .PHONY: all wellenreiterd clean distclean realclean | ||
14 | |||
15 | %.o : %.cc | ||
16 | $(CPP) $(CFLAGS) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@ | ||
17 | |||
18 | all:wellenreiterd | ||
19 | |||
20 | wellenreiterd:$(OBJ) | ||
21 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(CFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@ | ||
22 | @echo Build wellenreiterd | ||
23 | |||
24 | clean distclean realclean: | ||
25 | @rm -rf wellenreiterd *~ *.o | ||
26 | @echo All dependent files have been removed. | ||
27 | |||
28 | wellenreiterd.o:config.hh | ||
29 | serve.o: config.hh | ||
30 | log.o: config.hh | ||
31 | sendgui.o: config.hh | ||
diff --git a/noncore/net/wellenreiter/daemon/source/README b/noncore/net/wellenreiter/daemon/source/README deleted file mode 100644 index 249d950..0000000 --- a/noncore/net/wellenreiter/daemon/source/README +++ b/dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | compile it using: | ||
2 | |||
3 | gcc -o sniffer ./sniffer.c -lpcap | ||
4 | |||
5 | |||
diff --git a/noncore/net/wellenreiter/daemon/source/TODO b/noncore/net/wellenreiter/daemon/source/TODO new file mode 100644 index 0000000..39b1a05 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/TODO | |||
@@ -0,0 +1,5 @@ | |||
1 | implement communication protocol | ||
2 | security analysis | ||
3 | implement sniffer (last step) | ||
4 | security analysis | ||
5 | code cleanup \ No newline at end of file | ||
diff --git a/noncore/net/wellenreiter/daemon/source/config.hh b/noncore/net/wellenreiter/daemon/source/config.hh new file mode 100644 index 0000000..b124f41 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/config.hh | |||
@@ -0,0 +1,22 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Global configuration for wellenreiter | ||
4 | * | ||
5 | * $Id$ | ||
6 | * | ||
7 | * Written by Martin J. Muench <mjm@codito.de> | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #ifndef CONFIG_HH | ||
12 | #define CONFIG_HH | ||
13 | |||
14 | #define PROGNAME "wellenreiter" /* Name of program (for syslog et.al.) */ | ||
15 | #define VERSION "0.2" /* Version of wellenreiter */ | ||
16 | |||
17 | #define DAEMONPORT 37772 /* Port of Daemon */ | ||
18 | |||
19 | #define GUIADDR "127.0.0.1" /* Adress of GUI, later specified in configfile */ | ||
20 | #define GUIPORT 37773 /* Port of GUI, " " */ | ||
21 | |||
22 | #endif /* CONFIG_HH */ | ||
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc new file mode 100644 index 0000000..7972c0f --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * Startup functions of wellenreiter | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "config.hh" | ||
8 | #include "daemon.hh" | ||
9 | #include "log.hh" | ||
10 | #include "sendgui.hh" | ||
11 | #include "getgui.hh" | ||
12 | |||
13 | /* Main function of wellenreiterd */ | ||
14 | int main(int argc, char **argv) | ||
15 | { | ||
16 | int sock, maxfd; | ||
17 | struct sockaddr_in *cliaddr; | ||
18 | socklen_t len=sizeof(struct sockaddr); | ||
19 | char buffer[128]; | ||
20 | FILE *fp=stdin; /* Will be replaced with sniffer */ | ||
21 | fd_set rset; | ||
22 | |||
23 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | ||
24 | |||
25 | /* Setup socket for incoming commands */ | ||
26 | if(!commsock(&sock)) | ||
27 | return 0; | ||
28 | |||
29 | log_info("Set up socket '%d' for GUI communication", sock); | ||
30 | |||
31 | FD_ZERO(&rset); | ||
32 | |||
33 | /* Start main loop */ | ||
34 | log_info("Starting main loop"); | ||
35 | while(1) | ||
36 | { | ||
37 | |||
38 | FD_SET(sock, &rset); | ||
39 | FD_SET(fileno(fp), &rset); | ||
40 | maxfd=sock+fileno(fp)+1; | ||
41 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | ||
42 | { | ||
43 | log_err("Error calling select: %s", strerror(errno)); | ||
44 | break; | ||
45 | } | ||
46 | |||
47 | /* Got data on local socket from GUI */ | ||
48 | if(FD_ISSET(sock, &rset)) | ||
49 | { | ||
50 | memset(buffer, 0, sizeof(buffer)); | ||
51 | if(recvfrom(sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) | ||
52 | { | ||
53 | log_err("Cannot read from socket: %s", strerror(errno)); | ||
54 | break; | ||
55 | } | ||
56 | log_info("Received command from '%s': %s", inet_ntoa(cliaddr->sin_addr), buffer); | ||
57 | |||
58 | /* Pass string to analyze function */ | ||
59 | commstring(buffer); | ||
60 | |||
61 | } | ||
62 | |||
63 | /* Will be replaced with sniffer ... later */ | ||
64 | if(FD_ISSET(fileno(fp), &rset)) | ||
65 | { | ||
66 | memset(buffer, 0, sizeof(buffer)); | ||
67 | if(fgets(buffer, sizeof(buffer) - 1, fp) == NULL) | ||
68 | { | ||
69 | log_err("Cannot read from stdin: %s", strerror(errno)); | ||
70 | break; | ||
71 | } | ||
72 | |||
73 | /* Send string to GUI */ | ||
74 | sendgui("%d: %s", 1234, buffer); | ||
75 | |||
76 | } | ||
77 | |||
78 | } | ||
79 | |||
80 | close(sock); | ||
81 | return 0; | ||
82 | } | ||
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.hh b/noncore/net/wellenreiter/daemon/source/daemon.hh new file mode 100644 index 0000000..6776d37 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/daemon.hh | |||
@@ -0,0 +1,16 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | #ifndef DAEMON_HH | ||
4 | #define DAEMON_HH | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <string.h> | ||
8 | #include <sys/types.h> | ||
9 | #include <sys/time.h> | ||
10 | #include <sys/socket.h> | ||
11 | #include <netinet/in.h> | ||
12 | #include <arpa/inet.h> | ||
13 | #include <unistd.h> | ||
14 | #include <errno.h> | ||
15 | |||
16 | #endif /* DAEMON_HH */ | ||
diff --git a/noncore/net/wellenreiter/daemon/source/extract.h b/noncore/net/wellenreiter/daemon/source/extract.hh index c1bcdcd..21dcffa 100644 --- a/noncore/net/wellenreiter/daemon/source/extract.h +++ b/noncore/net/wellenreiter/daemon/source/extract.hh | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $Id */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 | 3 | * Copyright (c) 1992, 1993, 1994, 1995, 1996 |
3 | *The Regents of the University of California. All rights reserved. | 4 | *The Regents of the University of California. All rights reserved. |
@@ -17,12 +18,12 @@ | |||
17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED | 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | 19 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
20 | * | ||
21 | * @(#) $Header$ (LBL) | ||
22 | */ | 21 | */ |
23 | |||
24 | /* Network to host order macros */ | 22 | /* Network to host order macros */ |
25 | 23 | ||
24 | #ifndef EXTRACT_HH | ||
25 | #define EXTRACT_HH | ||
26 | |||
26 | #ifdef LBL_ALIGN | 27 | #ifdef LBL_ALIGN |
27 | #define EXTRACT_16BITS(p) \ | 28 | #define EXTRACT_16BITS(p) \ |
28 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ | 29 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ |
@@ -55,3 +56,5 @@ | |||
55 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ | 56 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ |
56 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 57 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
57 | (u_int32_t)*((const u_int8_t *)(p) + 0))) | 58 | (u_int32_t)*((const u_int8_t *)(p) + 0))) |
59 | |||
60 | #endif /* EXTRACT_HH */ | ||
diff --git a/noncore/net/wellenreiter/daemon/source/getgui.cc b/noncore/net/wellenreiter/daemon/source/getgui.cc new file mode 100644 index 0000000..f56f40b --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/getgui.cc | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * Setup UDP socket for commands | ||
3 | * Misc wrapper functions for incoming commands | ||
4 | * | ||
5 | * $Id$ | ||
6 | */ | ||
7 | |||
8 | #include "config.hh" | ||
9 | #include "getgui.hh" | ||
10 | #include "log.hh" | ||
11 | |||
12 | struct sockaddr_in saddr; | ||
13 | |||
14 | /* Setup UDP Socket for incoming commands */ | ||
15 | int commsock(int *sock) | ||
16 | { | ||
17 | |||
18 | if((*sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0) | ||
19 | { | ||
20 | log_err("Cannot set up socket: %s", strerror(errno)); | ||
21 | return 0; | ||
22 | } | ||
23 | |||
24 | memset(&saddr, 0, sizeof(saddr)); | ||
25 | saddr.sin_family = PF_INET; | ||
26 | saddr.sin_port = htons(DAEMONPORT); | ||
27 | saddr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
28 | |||
29 | if(bind(*sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0) | ||
30 | { | ||
31 | log_err("Cannot bind socket: %s", strerror(errno)); | ||
32 | close(*sock); | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | return 1; | ||
37 | } | ||
38 | |||
39 | int commstring(const char *input) | ||
40 | { | ||
41 | |||
42 | return 1; | ||
43 | } | ||
diff --git a/noncore/net/wellenreiter/daemon/source/getgui.hh b/noncore/net/wellenreiter/daemon/source/getgui.hh new file mode 100644 index 0000000..f5a37f9 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/getgui.hh | |||
@@ -0,0 +1,16 @@ | |||
1 | /* $id */ | ||
2 | |||
3 | #ifndef GETGUI_HH | ||
4 | #define GETGUI_HH | ||
5 | |||
6 | #include <sys/types.h> | ||
7 | #include <sys/socket.h> | ||
8 | #include <netinet/in.h> | ||
9 | #include <string.h> | ||
10 | #include <unistd.h> | ||
11 | #include <errno.h> | ||
12 | |||
13 | int commsock(int *); | ||
14 | int commstring(const char *); | ||
15 | |||
16 | #endif /* GETGUI_HH */ | ||
diff --git a/noncore/net/wellenreiter/daemon/source/ieee802_11.h b/noncore/net/wellenreiter/daemon/source/ieee802_11.hh index 497e6ed..3cc5343 100644 --- a/noncore/net/wellenreiter/daemon/source/ieee802_11.h +++ b/noncore/net/wellenreiter/daemon/source/ieee802_11.hh | |||
@@ -1,4 +1,4 @@ | |||
1 | /* @(#) $Header$ (LBL) */ | 1 | /* $Id$ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 | 3 | * Copyright (c) 2001 |
4 | *Fortress Technologies | 4 | *Fortress Technologies |
@@ -21,6 +21,9 @@ | |||
21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef IEEE802_11_HH | ||
25 | #define IEEE802_11_HH | ||
26 | |||
24 | #define IEEE802_11_FC_LEN2 | 27 | #define IEEE802_11_FC_LEN2 |
25 | 28 | ||
26 | #define T_MGMT 0x0 /* management */ | 29 | #define T_MGMT 0x0 /* management */ |
@@ -243,3 +246,5 @@ struct ctrl_end_ack_t { | |||
243 | #define IV_IV(iv)((iv) & 0xFFFFFF) | 246 | #define IV_IV(iv)((iv) & 0xFFFFFF) |
244 | #define IV_PAD(iv)(((iv) >> 24) & 0x3F) | 247 | #define IV_PAD(iv)(((iv) >> 24) & 0x3F) |
245 | #define IV_KEYID(iv)(((iv) >> 30) & 0x03) | 248 | #define IV_KEYID(iv)(((iv) >> 30) & 0x03) |
249 | |||
250 | #endif /* IEEE802_11_HH */ | ||
diff --git a/noncore/net/wellenreiter/daemon/source/log.cc b/noncore/net/wellenreiter/daemon/source/log.cc new file mode 100644 index 0000000..47589d2 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/log.cc | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * Small functions to log to syslog | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "config.hh" | ||
8 | #include "log.hh" | ||
9 | |||
10 | /* Log to syslog INFO */ | ||
11 | void log_info(const char *fmt,...) | ||
12 | { | ||
13 | |||
14 | char buffer[4096]; | ||
15 | va_list ap; | ||
16 | |||
17 | memset(buffer, 0, sizeof(buffer)), | ||
18 | va_start(ap, fmt); | ||
19 | vsnprintf(buffer, sizeof(buffer)-1, fmt, ap); | ||
20 | va_end(ap); | ||
21 | |||
22 | openlog(PROGNAME, LOG_PID, LOG_SYSLOG); | ||
23 | syslog(LOG_INFO, "(info) %s", buffer); | ||
24 | closelog(); | ||
25 | |||
26 | #ifdef DEBUG | ||
27 | fprintf(stderr, "(info) %s\n", buffer); | ||
28 | #endif | ||
29 | |||
30 | } | ||
31 | |||
32 | /* Log to syslog ERR */ | ||
33 | void log_err(const char *fmt,...) | ||
34 | { | ||
35 | |||
36 | char buffer[4096]; | ||
37 | va_list ap; | ||
38 | |||
39 | memset(buffer, 0, sizeof(buffer)); | ||
40 | va_start(ap, fmt); | ||
41 | vsnprintf(buffer, sizeof(buffer)-1, fmt, ap); | ||
42 | va_end(ap); | ||
43 | |||
44 | openlog(PROGNAME, LOG_PID, LOG_SYSLOG); | ||
45 | syslog(LOG_INFO, "(err) %s", buffer); | ||
46 | closelog(); | ||
47 | |||
48 | #ifdef DEBUG | ||
49 | fprintf(stderr, "(err) %s\n", buffer); | ||
50 | #endif | ||
51 | |||
52 | } | ||
diff --git a/noncore/net/wellenreiter/daemon/source/log.hh b/noncore/net/wellenreiter/daemon/source/log.hh new file mode 100644 index 0000000..bdea7e4 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/log.hh | |||
@@ -0,0 +1,14 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | #ifndef LOG_HH | ||
4 | #define LOG_HH | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <syslog.h> | ||
8 | #include <stdarg.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | void log_info(const char *, ...); | ||
12 | void log_err(const char *, ...); | ||
13 | |||
14 | #endif /* LOG_HH */ | ||
diff --git a/noncore/net/wellenreiter/daemon/source/sendgui.cc b/noncore/net/wellenreiter/daemon/source/sendgui.cc new file mode 100644 index 0000000..48ad5b8 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/sendgui.cc | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * Send string to GUI | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "config.hh" | ||
8 | #include "sendgui.hh" | ||
9 | #include "log.hh" | ||
10 | |||
11 | /* Simple dummy for alarm timer */ | ||
12 | static void alarmdummy(int signo) | ||
13 | { | ||
14 | alarm (0); | ||
15 | } | ||
16 | |||
17 | /* Connect to given IP on given port */ | ||
18 | int connect_server(int *sock, unsigned int ipaddr, int port) | ||
19 | { | ||
20 | struct sockaddr_in saddr; | ||
21 | int retval=0; | ||
22 | |||
23 | *sock = socket (PF_INET, SOCK_STREAM, 0); | ||
24 | saddr.sin_family = PF_INET; | ||
25 | saddr.sin_port = htons (port); | ||
26 | saddr.sin_addr.s_addr = ipaddr; | ||
27 | |||
28 | signal (SIGALRM, alarmdummy); | ||
29 | siginterrupt (SIGALRM, 1); | ||
30 | |||
31 | alarm(5); | ||
32 | retval=connect (*sock, (struct sockaddr *) &saddr, sizeof (saddr)); | ||
33 | alarm(0); | ||
34 | |||
35 | if(retval < 0) | ||
36 | { | ||
37 | close (*sock); | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | return 1; | ||
42 | } | ||
43 | |||
44 | /* Send a string to the GUI */ | ||
45 | int sendgui(const char *string, ...) | ||
46 | { | ||
47 | int sock=0; | ||
48 | char buffer[4096]; | ||
49 | va_list ap; | ||
50 | |||
51 | /* Generate string */ | ||
52 | memset(buffer, 0, sizeof(buffer)); | ||
53 | va_start(ap, string); | ||
54 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); | ||
55 | va_end(ap); | ||
56 | |||
57 | if(!connect_server(&sock, inet_addr(GUIADDR), GUIPORT)) | ||
58 | { | ||
59 | log_err("Connect to GUI at '%s' failed: %s", GUIADDR, strerror(errno)); | ||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | if(write(sock, buffer, sizeof(buffer)) < 0) | ||
64 | { | ||
65 | log_err("Cannot write to socket: %s", strerror(errno)); | ||
66 | close(sock); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | if(close(sock) < 0) | ||
71 | log_err("Cannot close socket: %s", strerror(errno)); | ||
72 | |||
73 | return 1; | ||
74 | } | ||
75 | |||
diff --git a/noncore/net/wellenreiter/daemon/source/sendgui.hh b/noncore/net/wellenreiter/daemon/source/sendgui.hh new file mode 100644 index 0000000..e083704 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/sendgui.hh | |||
@@ -0,0 +1,20 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | #ifndef SENDGUI_HH | ||
4 | #define SENDGUI_HH | ||
5 | |||
6 | #include <sys/types.h> | ||
7 | #include <sys/socket.h> | ||
8 | #include <netinet/in.h> | ||
9 | #include <arpa/inet.h> | ||
10 | #include <signal.h> | ||
11 | #include <errno.h> | ||
12 | #include <string.h> | ||
13 | #include <stdio.h> | ||
14 | #include <unistd.h> | ||
15 | #include <stdlib.h> | ||
16 | |||
17 | int connect_server(int *, unsigned int, int); | ||
18 | int sendgui(const char *string, ...); | ||
19 | |||
20 | #endif /* SENDGUI_HH */ | ||
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.c b/noncore/net/wellenreiter/daemon/source/sniffer.cc index 31a5d13..c837505 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.c +++ b/noncore/net/wellenreiter/daemon/source/sniffer.cc | |||
@@ -1,32 +1,28 @@ | |||
1 | /* Its just a simple rfmon mode sniffer | 1 | /* |
2 | i hope my C is at last a bit better then in my | 2 | * rfmon mode sniffer |
3 | early days :-). | 3 | * This works only with cisco wireless cards with an rfmon |
4 | This works only with cisco wireless cards with an rfmon | 4 | * able driver and not with wifi stuff. |
5 | able driver and not with wifi stuff. | 5 | * |
6 | Btw. did i mention that i hate C? | 6 | * $Id$ |
7 | 7 | */ | |
8 | To compile use: | 8 | |
9 | gcc sniffer.c -o wlan-sniffer -lpcap | 9 | #include "config.hh" |
10 | 10 | #include "sniffer.hh" | |
11 | */ | 11 | #include "ieee802_11.hh" |
12 | #include "sniffer.h" | 12 | #include "extract.hh" |
13 | 13 | ||
14 | int main(int argc, char **argv) | 14 | int sniffer(void) |
15 | { | 15 | { |
16 | int ret; /* return code */ | 16 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) |
17 | ret = card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG); | 17 | return 0; |
18 | if (ret == -1) | ||
19 | { | ||
20 | exit(-1); | ||
21 | } | ||
22 | start_sniffing (SNIFFER_DEVICE); | 18 | start_sniffing (SNIFFER_DEVICE); |
23 | 19 | ||
24 | return 0; | 20 | return 1; |
25 | } | 21 | } |
26 | 22 | ||
27 | int card_into_monitormode (char * device, int cardtype) | 23 | int card_into_monitormode (char *device, int cardtype) |
28 | { | 24 | { |
29 | int ret = -1; | 25 | |
30 | int datalink; /* used for getting the pcap datalink type */ | 26 | int datalink; /* used for getting the pcap datalink type */ |
31 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | 27 | char CiscoRFMON[35] = "/proc/driver/aironet/"; |
32 | FILE *CISCO_CONFIG_FILE; | 28 | FILE *CISCO_CONFIG_FILE; |
@@ -37,7 +33,7 @@ int card_into_monitormode (char * device, int cardtype) | |||
37 | if(device == NULL) | 33 | if(device == NULL) |
38 | { | 34 | { |
39 | printf ("Fatal error i did not have any interfaces to sniff on\n"); | 35 | printf ("Fatal error i did not have any interfaces to sniff on\n"); |
40 | exit(1); | 36 | return 0; |
41 | } | 37 | } |
42 | 38 | ||
43 | /* Setting the prmiscous and up flag to the interface */ | 39 | /* Setting the prmiscous and up flag to the interface */ |
@@ -61,10 +57,10 @@ int card_into_monitormode (char * device, int cardtype) | |||
61 | { | 57 | { |
62 | char wlanngcmd[62]; | 58 | char wlanngcmd[62]; |
63 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); | 59 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); |
64 | if (ret = (system (wlanngcmd)) != 0) | 60 | if (system (wlanngcmd) != 0) |
65 | { | 61 | { |
66 | printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); | 62 | printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); |
67 | exit(1); | 63 | return 0; |
68 | } | 64 | } |
69 | } | 65 | } |
70 | else if (cardtype == CARD_TYPE_HOSTAP) | 66 | else if (cardtype == CARD_TYPE_HOSTAP) |
@@ -82,15 +78,15 @@ int card_into_monitormode (char * device, int cardtype) | |||
82 | if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | 78 | if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ |
83 | { | 79 | { |
84 | printf ("Your successfully listen on %s in 802.11 raw mode\n",device); | 80 | printf ("Your successfully listen on %s in 802.11 raw mode\n",device); |
85 | pcap_close(handle); | 81 | pcap_close(handle); |
86 | return (0); | 82 | return 0; |
87 | 83 | ||
88 | } | 84 | } |
89 | else | 85 | else |
90 | { | 86 | { |
91 | printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); | 87 | printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); |
92 | pcap_close(handle); | 88 | pcap_close(handle); |
93 | exit(1); | 89 | return 0; |
94 | } | 90 | } |
95 | } | 91 | } |
96 | 92 | ||
@@ -103,21 +99,19 @@ int card_set_promisc_up (char * device) | |||
103 | if (ret > 0) | 99 | if (ret > 0) |
104 | { | 100 | { |
105 | printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); | 101 | printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); |
106 | exit(1); | 102 | return 0; |
107 | } | 103 | } |
108 | return(0); | 104 | return 1; |
109 | } | 105 | } |
110 | 106 | ||
111 | int start_sniffing (char * device) | 107 | int start_sniffing (char * device) |
112 | { | 108 | { |
113 | int ret; /* return code */ | 109 | |
114 | pcap_t *handletopcap; | 110 | pcap_t *handletopcap; |
115 | char errbuf[PCAP_ERRBUF_SIZE]; | 111 | char errbuf[PCAP_ERRBUF_SIZE]; |
116 | struct pcap_pkthdr header; /* The header that pcap gives us */ | ||
117 | const u_char *packet; /* The actual packet */ | ||
118 | 112 | ||
119 | /* opening the pcap for sniffing */ | 113 | /* opening the pcap for sniffing */ |
120 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); | 114 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); |
121 | 115 | ||
122 | /* Next few lines a taken out of kismet */ | 116 | /* Next few lines a taken out of kismet */ |
123 | #ifdef HAVE_PCAP_NONBLOCK | 117 | #ifdef HAVE_PCAP_NONBLOCK |
@@ -125,10 +119,10 @@ int start_sniffing (char * device) | |||
125 | #endif | 119 | #endif |
126 | 120 | ||
127 | /*start scanning */ | 121 | /*start scanning */ |
128 | pcap_loop(handletopcap,-1,process_packets,NULL); | 122 | pcap_loop(handletopcap,-1,process_packets,NULL); |
129 | 123 | ||
130 | printf("\nDone processing packets... wheew!\n"); | 124 | printf("\nDone processing packets... wheew!\n"); |
131 | return 0; | 125 | return 1; |
132 | } | 126 | } |
133 | 127 | ||
134 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) | 128 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) |
@@ -137,9 +131,7 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch | |||
137 | u_int length = pkthdr->len; | 131 | u_int length = pkthdr->len; |
138 | u_int16_t fc; | 132 | u_int16_t fc; |
139 | u_int HEADER_LENGTH; | 133 | u_int HEADER_LENGTH; |
140 | u_short extracted_ethertype; | 134 | |
141 | int snapend; | ||
142 | int ret; | ||
143 | /* pinfo holds all interresting information for us */ | 135 | /* pinfo holds all interresting information for us */ |
144 | struct packetinfo pinfo; | 136 | struct packetinfo pinfo; |
145 | struct packetinfo *pinfoptr; | 137 | struct packetinfo *pinfoptr; |
@@ -263,17 +255,15 @@ void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_ch | |||
263 | all the infos is placed into the packetinfo structure */ | 255 | all the infos is placed into the packetinfo structure */ |
264 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) | 256 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) |
265 | { | 257 | { |
266 | char * ret; | ||
267 | char testme[16]; | ||
268 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; | 258 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; |
269 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); | 259 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); |
270 | 260 | ||
271 | /* Get the sender, bssid and dest mac address */ | 261 | /* Get the sender, bssid and dest mac address */ |
272 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); | 262 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); |
273 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); | 263 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); |
274 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); | 264 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); |
275 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); | 265 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); |
276 | return(0); | 266 | return 0; |
277 | } | 267 | } |
278 | 268 | ||
279 | 269 | ||
@@ -295,7 +285,6 @@ void etheraddr_string(register const u_char *ep,char * text) | |||
295 | } | 285 | } |
296 | *cp = '\0'; | 286 | *cp = '\0'; |
297 | strcpy(text,buf); | 287 | strcpy(text,buf); |
298 | return; | ||
299 | } | 288 | } |
300 | 289 | ||
301 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | 290 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) |
@@ -328,13 +317,13 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
328 | { | 317 | { |
329 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; | 318 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; |
330 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | 319 | pbody.ssid.ssid[pbody.ssid.length]='\0'; |
331 | if (strcmp(pbody.ssid.ssid,"")==0) | 320 | if (strcmp((char *)pbody.ssid.ssid,"")==0) |
332 | { | 321 | { |
333 | ppinfo->ssid = NONBROADCASTING; | 322 | ppinfo->ssid = NONBROADCASTING; |
334 | } | 323 | } |
335 | else | 324 | else |
336 | { | 325 | { |
337 | ppinfo->ssid = pbody.ssid.ssid; | 326 | ppinfo->ssid = (char *)pbody.ssid.ssid; |
338 | } | 327 | } |
339 | ppinfo->ssid_len = pbody.ssid.length; | 328 | ppinfo->ssid_len = pbody.ssid.length; |
340 | } | 329 | } |
@@ -370,17 +359,12 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
370 | } | 359 | } |
371 | break; | 360 | break; |
372 | default: | 361 | default: |
373 | #if 0 | 362 | |
374 | printf("(1) unhandled element_id (%d) ", *(p+offset) ); | ||
375 | #endif | ||
376 | offset+= *(p+offset+1) + 2; | 363 | offset+= *(p+offset+1) + 2; |
377 | break; | 364 | break; |
378 | } /* end of switch*/ | 365 | } /* end of switch*/ |
379 | } /* end of for loop */ | 366 | } /* end of for loop */ |
380 | return(0); | 367 | return 1; |
381 | |||
382 | |||
383 | |||
384 | 368 | ||
385 | } /* End of handle_beacon */ | 369 | } /* End of handle_beacon */ |
386 | 370 | ||
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.h b/noncore/net/wellenreiter/daemon/source/sniffer.hh index b880b68..7f45be6 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.h +++ b/noncore/net/wellenreiter/daemon/source/sniffer.hh | |||
@@ -1,4 +1,7 @@ | |||
1 | // Wellenreiter-sniffer-code header file | 1 | /* $Id$ */ |
2 | |||
3 | #ifndef SNIFFER_HH | ||
4 | #define SNIFFER_HH | ||
2 | 5 | ||
3 | #include <string.h> | 6 | #include <string.h> |
4 | #include <stdio.h> | 7 | #include <stdio.h> |
@@ -9,8 +12,6 @@ | |||
9 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
10 | #include <arpa/inet.h> | 13 | #include <arpa/inet.h> |
11 | #include <net/bpf.h> | 14 | #include <net/bpf.h> |
12 | #include "ieee802_11.h" | ||
13 | #include "extract.h" | ||
14 | 15 | ||
15 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 16 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
16 | #define CARD_TYPE_CISCO1 | 17 | #define CARD_TYPE_CISCO1 |
@@ -47,40 +48,18 @@ struct packetinfo | |||
47 | 48 | ||
48 | 49 | ||
49 | /* Prototypes */ | 50 | /* Prototypes */ |
50 | int card_into_monitormode (char * device, int cardtype); | ||
51 | 51 | ||
52 | int sniffer(void); | ||
53 | int card_into_monitormode (char * device, int cardtype); | ||
52 | int card_set_promisc_up (char * device); | 54 | int card_set_promisc_up (char * device); |
53 | |||
54 | int start_sniffing (char * device); | 55 | int start_sniffing (char * device); |
55 | |||
56 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); | 56 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); |
57 | |||
58 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); | 57 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); |
59 | |||
60 | void etheraddr_string(register const u_char *ep,char * text); | 58 | void etheraddr_string(register const u_char *ep,char * text); |
61 | |||
62 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | 59 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); |
63 | 60 | ||
64 | static int GetHeaderLength(u_int16_t fc); | 61 | static int GetHeaderLength(u_int16_t fc); |
65 | 62 | ||
66 | static const char *subtype_text[]={ | ||
67 | "Assoc Request", | ||
68 | "Assoc Response", | ||
69 | "ReAssoc Request", | ||
70 | "ReAssoc Response", | ||
71 | "Probe Request", | ||
72 | "Probe Response", | ||
73 | "RESERVED", | ||
74 | "RESERVED", | ||
75 | "Beacon", | ||
76 | "ATIM", | ||
77 | "Disassociation", | ||
78 | "Authentication", | ||
79 | "DeAuthentication", | ||
80 | "RESERVED", | ||
81 | "RESERVED" | ||
82 | }; | ||
83 | |||
84 | /* | 63 | /* |
85 | * True if "l" bytes of "var" were captured. | 64 | * True if "l" bytes of "var" were captured. |
86 | * | 65 | * |
@@ -100,3 +79,5 @@ static const char *subtype_text[]={ | |||
100 | 79 | ||
101 | /* Bail if "var" was not captured */ | 80 | /* Bail if "var" was not captured */ |
102 | #define TCHECK(var) TCHECK2(var, sizeof(var)) | 81 | #define TCHECK(var) TCHECK2(var, sizeof(var)) |
82 | |||
83 | #endif /* SNIFFER_HH */ | ||