Removed
Link Here
|
1 |
--- ./src/knockd.c.orig 2005-06-27 07:11:34.000000000 +0200 |
2 |
+++ ./src/knockd.c 2011-08-17 13:24:16.000000000 +0200 |
3 |
@@ -1,8 +1,8 @@ |
4 |
/* |
5 |
* knockd.c |
6 |
- * |
7 |
+ * |
8 |
* Copyright (c) 2004-2005 by Judd Vinet <jvinet@zeroflux.org> |
9 |
- * |
10 |
+ * |
11 |
* This program is free software; you can redistribute it and/or modify |
12 |
* it under the terms of the GNU General Public License as published by |
13 |
* the Free Software Foundation; either version 2 of the License, or |
14 |
@@ -15,7 +15,7 @@ |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19 |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
20 |
* USA. |
21 |
*/ |
22 |
|
23 |
@@ -28,6 +28,11 @@ |
24 |
#include <ctype.h> |
25 |
#include <string.h> |
26 |
#include <fcntl.h> |
27 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
28 |
+#include <limits.h> |
29 |
+#include <sys/socket.h> |
30 |
+#include <netinet/in_systm.h> |
31 |
+#endif |
32 |
#include <netinet/in.h> |
33 |
#include <netinet/if_ether.h> |
34 |
#include <netinet/ip.h> |
35 |
@@ -35,8 +40,9 @@ |
36 |
#include <netinet/udp.h> |
37 |
#include <netinet/ip_icmp.h> |
38 |
#include <net/if.h> |
39 |
+#if !defined(__FreeBSD__) && !defined(__APPLE__) |
40 |
#include <bits/time.h> |
41 |
-#include <sys/socket.h> |
42 |
+#endif |
43 |
#include <sys/types.h> |
44 |
#include <sys/wait.h> |
45 |
#include <sys/ioctl.h> |
46 |
@@ -48,7 +54,7 @@ |
47 |
#include <errno.h> |
48 |
#include "list.h" |
49 |
|
50 |
-static char version[] = "0.5"; |
51 |
+static char version[] = "#VERSION#"; |
52 |
|
53 |
#define SEQ_TIMEOUT 25 /* default knock timeout in seconds */ |
54 |
#define CMD_TIMEOUT 10 /* default timeout in seconds between start and stop commands */ |
55 |
@@ -131,7 +137,7 @@ |
56 |
int o_daemon = 0; |
57 |
int o_lookup = 0; |
58 |
char o_int[32] = ""; /* default (eth0) is set after parseconfig() */ |
59 |
-char o_cfg[PATH_MAX] = "/etc/knockd.conf"; |
60 |
+char o_cfg[PATH_MAX] = "%%PREFIX%%/etc/knockd.conf"; |
61 |
char o_pidfile[PATH_MAX] = "/var/run/knockd.pid"; |
62 |
char o_logfile[PATH_MAX] = ""; |
63 |
|
64 |
@@ -193,7 +199,11 @@ |
65 |
} |
66 |
} |
67 |
|
68 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
69 |
+ cap = pcap_open_live(o_int, 65535, 0, 1, pcapErr); |
70 |
+#else |
71 |
cap = pcap_open_live(o_int, 65535, 0, 0, pcapErr); |
72 |
+#endif |
73 |
if(strlen(pcapErr)) { |
74 |
fprintf(stderr, "could not open %s: %s\n", o_int, pcapErr); |
75 |
} |
76 |
@@ -212,7 +222,10 @@ |
77 |
case DLT_RAW: |
78 |
dprint("raw interface detected, no encapsulation\n"); |
79 |
break; |
80 |
- default: |
81 |
+ case DLT_NULL: |
82 |
+ dprint("tun interface detected. pppoe on freebsd\n"); |
83 |
+ break; |
84 |
+ default: |
85 |
fprintf(stderr, "error: unsupported link-layer type: %d\n", lltype); |
86 |
cleanup(1); |
87 |
break; |
88 |
@@ -301,9 +314,9 @@ |
89 |
struct tm *tm; |
90 |
t = time(NULL); |
91 |
tm = localtime(&t); |
92 |
- |
93 |
- fprintf(logfd, "[%04d-%02d-%02d %02d:%02d] %s\n", tm->tm_year+1900, |
94 |
- tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, msg); |
95 |
+ |
96 |
+ fprintf(logfd, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n", tm->tm_year+1900, |
97 |
+ tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, msg); |
98 |
fflush(logfd); |
99 |
} |
100 |
} |
101 |
@@ -420,7 +433,7 @@ |
102 |
if(pch != str) { |
103 |
memmove(str, pch, (strlen(pch) + 1)); |
104 |
} |
105 |
- |
106 |
+ |
107 |
pch = (char*)(str + (strlen(str) - 1)); |
108 |
while(isspace(*pch)) { |
109 |
pch--; |
110 |
@@ -503,7 +516,7 @@ |
111 |
dprint("config: usesyslog\n"); |
112 |
} else { |
113 |
fprintf(stderr, "config: line %d: syntax error\n", linenum); |
114 |
- return(1); |
115 |
+ return(1); |
116 |
} |
117 |
} else { |
118 |
trim(ptr); |
119 |
@@ -681,7 +694,7 @@ |
120 |
return(1); |
121 |
} |
122 |
dprint_sequence(door, "new sequence for door %s: ", door->name); |
123 |
- |
124 |
+ |
125 |
return(0); |
126 |
} |
127 |
|
128 |
@@ -694,7 +707,7 @@ |
129 |
{ |
130 |
char line[PATH_MAX+1]; |
131 |
int pos; |
132 |
- |
133 |
+ |
134 |
pos = ftell(door->one_time_sequences_fd); |
135 |
while(fgets(line, PATH_MAX, door->one_time_sequences_fd)) { |
136 |
trim(line); |
137 |
@@ -746,7 +759,7 @@ |
138 |
|
139 |
rewind(door->one_time_sequences_fd); |
140 |
pseudo_door.one_time_sequences_fd = door->one_time_sequences_fd; |
141 |
- |
142 |
+ |
143 |
pos = get_next_one_time_sequence(&pseudo_door); |
144 |
while(pos >= 0) { |
145 |
if(door->seqcount == pseudo_door.seqcount) { |
146 |
@@ -769,10 +782,10 @@ |
147 |
void generate_pcap_filter() |
148 |
{ |
149 |
/* NOTE: We're doing string manipulations in a daemon -- use defensive programming! */ |
150 |
- |
151 |
+ |
152 |
PMList *lp; |
153 |
opendoor_t *door; |
154 |
- char *buffer = NULL; /* temporary buffer to create the individual filter strings */ |
155 |
+ char *buffer = NULL; /* temporary buffer to create the individual filter strings */ |
156 |
size_t bufsize = 0; /* size of buffer */ |
157 |
char port_str[10]; /* used by snprintf to convert unsigned short --> string */ |
158 |
short head_set = 0; /* flag indicating if protocol head is set (i.e. "((tcp dst port") */ |
159 |
@@ -781,7 +794,7 @@ |
160 |
unsigned int i; |
161 |
short modified_filters = 0; /* flag indicating if at least one filter has changed --> recompile the filter */ |
162 |
struct bpf_program bpf_prog; /* compiled BPF filter program */ |
163 |
- |
164 |
+ |
165 |
/* generate subfilters for each door having a NULL pcap_filter_exp |
166 |
* |
167 |
* Example filter for one single door: |
168 |
@@ -796,11 +809,11 @@ |
169 |
|
170 |
/* if we get here at least one door had a pcap_filter_exp == NULL */ |
171 |
modified_filters = 1; |
172 |
- |
173 |
+ |
174 |
head_set = 0; |
175 |
tcp_present = 0; |
176 |
udp_present = 0; |
177 |
- |
178 |
+ |
179 |
/* allocate memory for buffer if needed. |
180 |
* The first allocation will be 200 Bytes (should be large enough for common sequences). If there is |
181 |
* not enough space, a call to realloc_strcat() will eventually increase its size. The buffer will be |
182 |
@@ -913,7 +926,7 @@ |
183 |
if(udp_present) { |
184 |
bufsize = realloc_strcat(&buffer, ")", bufsize); /* close parentheses of UDP ports */ |
185 |
} |
186 |
- |
187 |
+ |
188 |
/* test if in any of the precedent calls to realloc_strcat() failed. We can do this safely here because |
189 |
* realloc_strcat() returns 0 on failure and if a buffer size of 0 is passed to it, the function does |
190 |
* nothing but returning 0 again. Because we never read buffer in the above code, it is secure to test |
191 |
@@ -930,7 +943,7 @@ |
192 |
perror("malloc"); |
193 |
cleanup(1); |
194 |
} |
195 |
- strcpy(door->pcap_filter_exp, buffer); |
196 |
+ strcpy(door->pcap_filter_exp, buffer); |
197 |
|
198 |
buffer[0] = '\0'; /* "clear" the buffer */ |
199 |
} |
200 |
@@ -941,7 +954,7 @@ |
201 |
* Note that we don't check if a port is included in multiple doors, we simply concatenate the individual door |
202 |
* filters and rely on pcap's optimization capabilities. |
203 |
* |
204 |
- * Example filter for two doors with sequences 8000:tcp,4000:udp,8001:tcp,4001:udp,8002:tcp (syn) and |
205 |
+ * Example filter for two doors with sequences 8000:tcp,4000:udp,8001:tcp,4001:udp,8002:tcp (syn) and |
206 |
* 1234:tcp,4567:tcp,8901:tcp (syn,ack) : |
207 |
* dst host the.hosts.ip.address and ( |
208 |
* ((tcp dst port 8000 or 8001 or 8002) and tcp[tcpflags] & tcp-syn != 0) or (udp dst port 4000 or 4001) |
209 |
@@ -1005,7 +1018,7 @@ |
210 |
|
211 |
needed_size = strlen(*dest) + strlen(src) + 1; /* '+ 1' for '\0' */ |
212 |
new_size = size; |
213 |
- |
214 |
+ |
215 |
while(needed_size > new_size) { |
216 |
new_size *= 2; |
217 |
} |
218 |
@@ -1018,7 +1031,7 @@ |
219 |
|
220 |
/* now dest is large enough to strcat() the src */ |
221 |
strcat(*dest, src); |
222 |
- |
223 |
+ |
224 |
return new_size; |
225 |
} |
226 |
|
227 |
@@ -1059,7 +1072,11 @@ |
228 |
} |
229 |
buf[0] = '\0'; |
230 |
|
231 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
232 |
s = socket(AF_INET, SOCK_DGRAM, 0); |
233 |
+#else |
234 |
+ s = socket(PF_PACKET, SOCK_DGRAM, 0); |
235 |
+#endif |
236 |
if(s < 0) { |
237 |
return(NULL); |
238 |
} |
239 |
@@ -1161,12 +1178,17 @@ |
240 |
void sniff(u_char* arg, const struct pcap_pkthdr* hdr, const u_char* packet) |
241 |
{ |
242 |
/* packet structs */ |
243 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
244 |
+ struct ether_header* eth = NULL; |
245 |
+ struct ip* ip = NULL; |
246 |
+#else |
247 |
struct ethhdr* eth = NULL; |
248 |
struct iphdr* ip = NULL; |
249 |
+#endif |
250 |
struct tcphdr* tcp = NULL; |
251 |
struct udphdr* udp = NULL; |
252 |
char proto[8]; |
253 |
- /* TCP/IP data */ |
254 |
+ /* TCP/IP data */ |
255 |
struct in_addr inaddr; |
256 |
unsigned short sport, dport; |
257 |
char srcIP[16], dstIP[16]; |
258 |
@@ -1179,23 +1201,46 @@ |
259 |
knocker_t *attempt = NULL; |
260 |
|
261 |
if(lltype == DLT_EN10MB) { |
262 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
263 |
+ eth = (struct ether_header*)packet; |
264 |
+ if(ntohs(eth->ether_type) != ETHERTYPE_IP) { |
265 |
+ return; |
266 |
+ } |
267 |
+ |
268 |
+ ip = (struct ip*)(packet + sizeof(struct ether_header)); |
269 |
+ } else if(lltype == DLT_LINUX_SLL) { |
270 |
+ ip = (struct ip*)((u_char*)packet + 16); |
271 |
+ } else if(lltype == DLT_RAW) { |
272 |
+ ip = (struct ip*)((u_char*)packet); |
273 |
+ } else if(lltype == DLT_NULL) { |
274 |
+ ip = (struct ip*)((u_char*)packet + 4); |
275 |
+ } |
276 |
+ |
277 |
+ if(ip->ip_v != 4) { |
278 |
+#else |
279 |
eth = (struct ethhdr*)packet; |
280 |
if(ntohs(eth->h_proto) != ETH_P_IP) { |
281 |
return; |
282 |
} |
283 |
+ |
284 |
ip = (struct iphdr*)(packet + sizeof(struct ethhdr)); |
285 |
} else if(lltype == DLT_LINUX_SLL) { |
286 |
ip = (struct iphdr*)((u_char*)packet + 16); |
287 |
} else if(lltype == DLT_RAW) { |
288 |
ip = (struct iphdr*)((u_char*)packet); |
289 |
} |
290 |
- |
291 |
+ |
292 |
if(ip->version != 4) { |
293 |
+#endif |
294 |
/* no IPv6 yet */ |
295 |
dprint("packet is not IPv4, ignoring...\n"); |
296 |
return; |
297 |
} |
298 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
299 |
+ if(ip->ip_p == IPPROTO_ICMP) { |
300 |
+#else |
301 |
if(ip->protocol == IPPROTO_ICMP) { |
302 |
+#endif |
303 |
/* we don't do ICMP */ |
304 |
return; |
305 |
} |
306 |
@@ -1207,12 +1252,30 @@ |
307 |
fprintf(stderr, "error: could not understand IP address: %s\n", myip); |
308 |
return; |
309 |
} |
310 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
311 |
+ if(ip->ip_dst.s_addr != inaddr.s_addr) { |
312 |
+#else |
313 |
if(ip->daddr != inaddr.s_addr) { |
314 |
+#endif |
315 |
dprint("packet destined for another host, ignoring...\n"); |
316 |
return; |
317 |
} |
318 |
- |
319 |
+ |
320 |
sport = dport = 0; |
321 |
+ |
322 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
323 |
+ if(ip->ip_p == IPPROTO_TCP) { |
324 |
+ strncpy(proto, "tcp", sizeof(proto)); |
325 |
+ tcp = (struct tcphdr*)((u_char*)ip + (ip->ip_hl *4)); |
326 |
+ sport = ntohs(tcp->th_sport); |
327 |
+ dport = ntohs(tcp->th_dport); |
328 |
+ } |
329 |
+ if(ip->ip_p == IPPROTO_UDP) { |
330 |
+ strncpy(proto, "udp", sizeof(proto)); |
331 |
+ udp = (struct udphdr*)((u_char*)ip + (ip->ip_hl * 4)); |
332 |
+ sport = ntohs(udp->uh_sport); |
333 |
+ dport = ntohs(udp->uh_dport); |
334 |
+#else |
335 |
if(ip->protocol == IPPROTO_TCP) { |
336 |
strncpy(proto, "tcp", sizeof(proto)); |
337 |
tcp = (struct tcphdr*)((u_char*)ip + (ip->ihl * 4)); |
338 |
@@ -1224,6 +1287,7 @@ |
339 |
udp = (struct udphdr*)((u_char*)ip + (ip->ihl * 4)); |
340 |
sport = ntohs(udp->source); |
341 |
dport = ntohs(udp->dest); |
342 |
+#endif |
343 |
} |
344 |
|
345 |
/* get the date/time */ |
346 |
@@ -1234,10 +1298,17 @@ |
347 |
pkt_tm->tm_sec); |
348 |
|
349 |
/* convert IPs from binary to string */ |
350 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
351 |
+ inaddr.s_addr = ip->ip_src.s_addr; |
352 |
+ strncpy(srcIP, inet_ntoa(inaddr), sizeof(srcIP)-1); |
353 |
+ srcIP[sizeof(srcIP)-1] = '\0'; |
354 |
+ inaddr.s_addr = ip->ip_dst.s_addr; |
355 |
+#else |
356 |
inaddr.s_addr = ip->saddr; |
357 |
strncpy(srcIP, inet_ntoa(inaddr), sizeof(srcIP)-1); |
358 |
srcIP[sizeof(srcIP)-1] = '\0'; |
359 |
inaddr.s_addr = ip->daddr; |
360 |
+#endif |
361 |
strncpy(dstIP, inet_ntoa(inaddr), sizeof(dstIP)-1); |
362 |
dstIP[sizeof(dstIP)-1] = '\0'; |
363 |
|
364 |
@@ -1297,6 +1368,73 @@ |
365 |
/* if tcp, check the flags to ignore the packets we don't want |
366 |
* (don't even use it to cancel sequences) |
367 |
*/ |
368 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
369 |
+ if(ip->ip_p == IPPROTO_TCP) { |
370 |
+ if(attempt->door->flag_fin != DONT_CARE) { |
371 |
+ if(attempt->door->flag_fin == SET && !(tcp->th_flags & TH_FIN)) { |
372 |
+ dprint("packet is not FIN, ignoring...\n"); |
373 |
+ flagsmatch = 0; |
374 |
+ } |
375 |
+ if(attempt->door->flag_fin == NOT_SET && (tcp->th_flags & TH_FIN)) { |
376 |
+ dprint("packet is not !FIN, ignoring...\n"); |
377 |
+ flagsmatch = 0; |
378 |
+ } |
379 |
+ } |
380 |
+ if(attempt->door->flag_syn != DONT_CARE) { |
381 |
+ if(attempt->door->flag_syn == SET && !(tcp->th_flags & TH_SYN)) { |
382 |
+ dprint("packet is not SYN, ignoring...\n"); |
383 |
+ flagsmatch = 0; |
384 |
+ } |
385 |
+ if(attempt->door->flag_syn == NOT_SET && (tcp->th_flags & TH_SYN)) { |
386 |
+ dprint("packet is not !SYN, ignoring...\n"); |
387 |
+ flagsmatch = 0; |
388 |
+ } |
389 |
+ } |
390 |
+ if(attempt->door->flag_rst != DONT_CARE) { |
391 |
+ if(attempt->door->flag_rst == SET && !(tcp->th_flags & TH_RST)) { |
392 |
+ dprint("packet is not RST, ignoring...\n"); |
393 |
+ flagsmatch = 0; |
394 |
+ } |
395 |
+ if(attempt->door->flag_rst == NOT_SET && (tcp->th_flags & TH_RST)) { |
396 |
+ dprint("packet is not !RST, ignoring...\n"); |
397 |
+ flagsmatch = 0; |
398 |
+ } |
399 |
+ } |
400 |
+ if(attempt->door->flag_psh != DONT_CARE) { |
401 |
+ if(attempt->door->flag_psh == SET && !(tcp->th_flags & TH_PUSH)) { |
402 |
+ dprint("packet is not PSH, ignoring...\n"); |
403 |
+ flagsmatch = 0; |
404 |
+ } |
405 |
+ if(attempt->door->flag_psh == NOT_SET && (tcp->th_flags & TH_PUSH)) { |
406 |
+ dprint("packet is not !PSH, ignoring...\n"); |
407 |
+ flagsmatch = 0; |
408 |
+ } |
409 |
+ } |
410 |
+ if(attempt->door->flag_ack != DONT_CARE) { |
411 |
+ if(attempt->door->flag_ack == SET && !(tcp->th_flags & TH_ACK)) { |
412 |
+ dprint("packet is not ACK, ignoring...\n"); |
413 |
+ flagsmatch = 0; |
414 |
+ } |
415 |
+ if(attempt->door->flag_ack == NOT_SET && !(tcp->th_flags & TH_ACK)) { |
416 |
+ dprint("packet is not !ACK, ignoring...\n"); |
417 |
+ flagsmatch = 0; |
418 |
+ } |
419 |
+ } |
420 |
+ if(attempt->door->flag_urg != DONT_CARE) { |
421 |
+ if(attempt->door->flag_urg == SET && !(tcp->th_flags & TH_URG)) { |
422 |
+ dprint("packet is not URG, ignoring...\n"); |
423 |
+ flagsmatch = 0; |
424 |
+ } |
425 |
+ if(attempt->door->flag_urg == NOT_SET && !(tcp->th_flags & TH_URG)) { |
426 |
+ dprint("packet is not !URG, ignoring...\n"); |
427 |
+ flagsmatch = 0; |
428 |
+ } |
429 |
+ } |
430 |
+ } |
431 |
+ if(flagsmatch && ip->ip_p == attempt->door->protocol[attempt->stage] && |
432 |
+ dport == attempt->door->sequence[attempt->stage]) { |
433 |
+ |
434 |
+#else |
435 |
if(ip->protocol == IPPROTO_TCP) { |
436 |
if(attempt->door->flag_fin != DONT_CARE) { |
437 |
if(attempt->door->flag_fin == SET && tcp->fin != 1) { |
438 |
@@ -1361,6 +1499,7 @@ |
439 |
} |
440 |
if(flagsmatch && ip->protocol == attempt->door->protocol[attempt->stage] && |
441 |
dport == attempt->door->sequence[attempt->stage]) { |
442 |
+#endif |
443 |
/* level up! */ |
444 |
attempt->stage++; |
445 |
if(attempt->srchost) { |
446 |
@@ -1387,7 +1526,7 @@ |
447 |
size_t cmd_len = 0; |
448 |
|
449 |
setsid(); |
450 |
- |
451 |
+ |
452 |
/* parse start and stop command and check if the parsed commands fit in the given buffer. Don't |
453 |
* execute any command if one of them has been truncated */ |
454 |
cmd_len = parse_cmd(parsed_start_cmd, sizeof(parsed_start_cmd), attempt->door->start_command, attempt->src); |
455 |
@@ -1419,7 +1558,7 @@ |
456 |
} |
457 |
exec_cmd(parsed_stop_cmd, attempt->door->name); |
458 |
} |
459 |
- |
460 |
+ |
461 |
exit(0); /* exit child */ |
462 |
} |
463 |
} |
464 |
@@ -1451,6 +1590,36 @@ |
465 |
for(lp = doors; lp; lp = lp->next) { |
466 |
opendoor_t *door = (opendoor_t*)lp->data; |
467 |
/* if we're working with TCP, try to match the flags */ |
468 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
469 |
+ if(ip->ip_p == IPPROTO_TCP){ |
470 |
+ if(door->flag_fin != DONT_CARE) { |
471 |
+ if(door->flag_fin == SET && !(tcp->th_flags & TH_FIN)) {dprint("packet is not FIN, ignoring...\n");continue;} |
472 |
+ if(door->flag_fin == NOT_SET && (tcp->th_flags & TH_FIN)) {dprint("packet is not !FIN, ignoring...\n");continue;} |
473 |
+ } |
474 |
+ if(door->flag_syn != DONT_CARE) { |
475 |
+ if(door->flag_syn == SET && !(tcp->th_flags & TH_SYN)) {dprint("packet is not SYN, ignoring...\n");continue;} |
476 |
+ if(door->flag_syn == NOT_SET && (tcp->th_flags & TH_SYN)) {dprint("packet is not !SYN, ignoring...\n");continue;} |
477 |
+ } |
478 |
+ if(door->flag_rst != DONT_CARE) { |
479 |
+ if(door->flag_rst == SET && !(tcp->th_flags & TH_RST)) {dprint("packet is not RST, ignoring...\n");continue;} |
480 |
+ if(door->flag_rst == NOT_SET && (tcp->th_flags & TH_RST)) {dprint("packet is not !RST, ignoring...\n");continue;} |
481 |
+ } |
482 |
+ if(door->flag_psh != DONT_CARE) { |
483 |
+ if(door->flag_psh == SET && !(tcp->th_flags & TH_PUSH)) {dprint("packet is not PSH, ignoring...\n");continue;} |
484 |
+ if(door->flag_psh == NOT_SET && (tcp->th_flags & TH_PUSH)) {dprint("packet is not !PSH, ignoring...\n");continue;} |
485 |
+ } |
486 |
+ if(door->flag_ack != DONT_CARE) { |
487 |
+ if(door->flag_ack == SET && !(tcp->th_flags & TH_ACK)) {dprint("packet is not ACK, ignoring...\n");continue;} |
488 |
+ if(door->flag_ack == NOT_SET && (tcp->th_flags & TH_ACK)) {dprint("packet is not !ACK, ignoring...\n");continue;} |
489 |
+ } |
490 |
+ if(door->flag_urg != DONT_CARE) { |
491 |
+ if(door->flag_urg == SET && !(tcp->th_flags & TH_URG)) {dprint("packet is not URG, ignoring...\n");continue;} |
492 |
+ if(door->flag_urg == NOT_SET && (tcp->th_flags & TH_URG)) {dprint("packet is not !URG, ignoring...\n");continue;} |
493 |
+ } |
494 |
+ } |
495 |
+ |
496 |
+ if(ip->ip_p == door->protocol[0] && dport == door->sequence[0]) { |
497 |
+#else |
498 |
if(ip->protocol == IPPROTO_TCP){ |
499 |
if(door->flag_fin != DONT_CARE) { |
500 |
if(door->flag_fin == SET && tcp->fin != 1) {dprint("packet is not FIN, ignoring...\n");continue;} |
501 |
@@ -1479,6 +1648,7 @@ |
502 |
} |
503 |
|
504 |
if(ip->protocol == door->protocol[0] && dport == door->sequence[0]) { |
505 |
+#endif |
506 |
struct hostent *he; |
507 |
/* create a new entry */ |
508 |
attempt = (knocker_t*)malloc(sizeof(knocker_t)); |
509 |
@@ -1490,7 +1660,11 @@ |
510 |
strcpy(attempt->src, srcIP); |
511 |
/* try a reverse lookup if enabled */ |
512 |
if (o_lookup) { |
513 |
+#if defined(__FreeBSD__) || defined(__APPLE__) |
514 |
+ inaddr.s_addr = ip->ip_src.s_addr; |
515 |
+#else |
516 |
inaddr.s_addr = ip->saddr; |
517 |
+#endif |
518 |
he = gethostbyaddr((void *)&inaddr, sizeof(inaddr), AF_INET); |
519 |
if(he) { |
520 |
attempt->srchost = strdup(he->h_name); |