1 diff -Nur dsniff-2.3/dns.c dsniff-2.3.patched/dns.c
2 --- dsniff-2.3/dns.c 1970-01-01 01:00:00.000000000 +0100
3 +++ dsniff-2.3.patched/dns.c 2005-06-09 14:06:36.000000000 +0200
6 + * Copyright (c) 1985, 1993
7 + * The Regents of the University of California. All rights reserved.
9 + * Redistribution and use in source and binary forms, with or without
10 + * modification, are permitted provided that the following conditions
12 + * 1. Redistributions of source code must retain the above copyright
13 + * notice, this list of conditions and the following disclaimer.
14 + * 2. Redistributions in binary form must reproduce the above copyright
15 + * notice, this list of conditions and the following disclaimer in the
16 + * documentation and/or other materials provided with the distribution.
17 + * 4. Neither the name of the University nor the names of its contributors
18 + * may be used to endorse or promote products derived from this software
19 + * without specific prior written permission.
21 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 + * Portions Copyright (c) 1993 by Digital Equipment Corporation.
37 + * Permission to use, copy, modify, and distribute this software for any
38 + * purpose with or without fee is hereby granted, provided that the above
39 + * copyright notice and this permission notice appear in all copies, and that
40 + * the name of Digital Equipment Corporation not be used in advertising or
41 + * publicity pertaining to distribution of the document or software without
42 + * specific, written prior permission.
44 + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
45 + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
46 + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
47 + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
48 + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
49 + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
50 + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 + * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
57 + * Permission to use, copy, modify, and distribute this software for any
58 + * purpose with or without fee is hereby granted, provided that the above
59 + * copyright notice and this permission notice appear in all copies.
61 + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
62 + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
63 + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
64 + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
65 + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
66 + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
67 + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
72 + * Copyright (c) 1996,1999 by Internet Software Consortium.
74 + * Permission to use, copy, modify, and distribute this software for any
75 + * purpose with or without fee is hereby granted, provided that the above
76 + * copyright notice and this permission notice appear in all copies.
78 + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
79 + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
80 + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
81 + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
82 + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
83 + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
84 + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
90 + * DNS helper functions not implemented in uclibc
95 +#include <sys/types.h>
96 +#include <sys/param.h>
97 +#include <netinet/in.h>
98 +#include <arpa/nameser.h>
105 +static const char digits[] = "0123456789";
109 +static int special(int);
110 +static int printable(int);
111 +static int dn_find(const u_char *, const u_char *,
112 + const u_char * const *,
113 + const u_char * const *);
117 + * ns_name_ntop(src, dst, dstsiz)
118 + * Convert an encoded domain name to printable ascii as per RFC1035.
120 + * Number of bytes written to buffer, or -1 (with errno set)
122 + * The root is returned as "."
123 + * All other domains are returned in non absolute form
126 +ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
134 + eom = dst + dstsiz;
136 + while ((n = *cp++) != 0) {
137 + if ((n & NS_CMPRSFLGS) != 0) {
138 + /* Some kind of compression pointer. */
147 + if (dn + n >= eom) {
150 + for ((void)NULL; n > 0; n--) {
153 + if (dn + 1 >= eom) {
158 + } else if (!printable(c)) {
159 + if (dn + 3 >= eom) {
163 + *dn++ = digits[c / 100];
164 + *dn++ = digits[(c % 100) / 10];
165 + *dn++ = digits[c % 10];
188 + * ns_name_pton(src, dst, dstsiz)
189 + * Convert a ascii string into an encoded domain name as per RFC1035.
192 + * 1 if string was fully qualified
193 + * 0 is string was not fully qualified
195 + * Enforces label and domain length limits.
199 +ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
200 + u_char *label, *bp, *eom;
206 + eom = dst + dstsiz;
209 + while ((c = *src++) != 0) {
211 + if ((cp = strchr(digits, c)) != NULL) {
212 + n = (cp - digits) * 100;
213 + if ((c = *src++) == 0 ||
214 + (cp = strchr(digits, c)) == NULL) {
217 + n += (cp - digits) * 10;
218 + if ((c = *src++) == 0 ||
219 + (cp = strchr(digits, c)) == NULL) {
222 + n += (cp - digits);
229 + } else if (c == '\\') {
232 + } else if (c == '.') {
233 + c = (bp - label - 1);
234 + if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
237 + if (label >= eom) {
241 + /* Fully qualified ? */
242 + if (*src == '\0') {
249 + if ((bp - dst) > MAXCDNAME) {
254 + if (c == 0 || *src == '.') {
265 + c = (bp - label - 1);
266 + if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
269 + if (label >= eom) {
279 + if ((bp - dst) > MAXCDNAME) { /* src too big */
286 + * ns_name_ntol(src, dst, dstsiz)
287 + * Convert a network strings labels into all lowercase.
289 + * Number of bytes written to buffer, or -1 (with errno set)
291 + * Enforces label and domain length limits.
295 +ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) {
303 + eom = dst + dstsiz;
305 + while ((n = *cp++) != 0) {
306 + if ((n & NS_CMPRSFLGS) != 0) {
307 + /* Some kind of compression pointer. */
311 + if (dn + n >= eom) {
314 + for ((void)NULL; n > 0; n--) {
317 + *dn++ = tolower(c);
327 + * ns_name_unpack(msg, eom, src, dst, dstsiz)
328 + * Unpack a domain name from a message, source may be compressed.
330 + * -1 if it fails, or consumed octets if it succeeds.
333 +ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
334 + u_char *dst, size_t dstsiz)
336 + const u_char *srcp, *dstlim;
338 + int n, len, checked;
344 + dstlim = dst + dstsiz;
345 + if (srcp < msg || srcp >= eom) {
348 + /* Fetch next label in domain name. */
349 + while ((n = *srcp++) != 0) {
350 + /* Check for indirection. */
351 + switch (n & NS_CMPRSFLGS) {
353 + /* Limit checks. */
354 + if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
359 + memcpy(dstp, srcp, n);
369 + len = srcp - src + 1;
370 + srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
371 + if (srcp < msg || srcp >= eom) { /* Out of range. */
376 + * Check for loops in the compressed name;
377 + * if we've looked at the whole message,
378 + * there must be a loop.
380 + if (checked >= eom - msg) {
386 + return (-1); /* flag error */
396 + * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
397 + * Pack domain name 'domain' into 'comp_dn'.
399 + * Size of the compressed name, or -1.
401 + * 'dnptrs' is an array of pointers to previous compressed names.
402 + * dnptrs[0] is a pointer to the beginning of the message. The array
404 + * 'lastdnptr' is a pointer to the end of the array pointed to
407 + * The list of pointers in dnptrs is updated for labels inserted into
408 + * the message as we compress the name. If 'dnptr' is NULL, we don't
409 + * try to compress names. If 'lastdnptr' is NULL, we don't update the
413 +ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
414 + const u_char **dnptrs, const u_char **lastdnptr)
417 + const u_char **cpp, **lpp, *eob, *msg;
418 + const u_char *srcp;
419 + int n, l, first = 1;
423 + eob = dstp + dstsiz;
425 + if (dnptrs != NULL) {
426 + if ((msg = *dnptrs++) != NULL) {
427 + for (cpp = dnptrs; *cpp != NULL; cpp++)
429 + lpp = cpp; /* end of list to search */
434 + /* make sure the domain we are about to add is legal */
438 + if ((n & NS_CMPRSFLGS) != 0) {
442 + if (l > MAXCDNAME) {
448 + /* from here on we need to reset compression pointer array on error */
451 + /* Look to see if we can use pointers. */
453 + if (n != 0 && msg != NULL) {
454 + l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
455 + (const u_char * const *)lpp);
457 + if (dstp + 1 >= eob) {
460 + *dstp++ = (l >> 8) | NS_CMPRSFLGS;
462 + return (dstp - dst);
464 + /* Not found, save it. */
465 + if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
466 + (dstp - msg) < 0x4000 && first) {
472 + /* copy label to buffer */
473 + if (n & NS_CMPRSFLGS) { /* Should not happen. */
476 + if (dstp + 1 + n >= eob) {
479 + memcpy(dstp, srcp, n + 1);
490 + return (dstp - dst);
494 + * ns_name_uncompress(msg, eom, src, dst, dstsiz)
495 + * Expand compressed domain name to presentation format.
497 + * Number of bytes read out of `src', or -1 (with errno set).
499 + * Root domain returns as "." not "".
502 +ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
503 + char *dst, size_t dstsiz)
505 + u_char tmp[NS_MAXCDNAME];
508 + if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
510 + if (ns_name_ntop(tmp, dst, dstsiz) == -1)
516 + * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
517 + * Compress a domain name into wire format, using compression pointers.
519 + * Number of bytes consumed in `dst' or -1 (with errno set).
521 + * 'dnptrs' is an array of pointers to previous compressed names.
522 + * dnptrs[0] is a pointer to the beginning of the message.
523 + * The list ends with NULL. 'lastdnptr' is a pointer to the end of the
524 + * array pointed to by 'dnptrs'. Side effect is to update the list of
525 + * pointers for labels inserted into the message as we compress the name.
526 + * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
527 + * is NULL, we don't update the list.
530 +ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
531 + const u_char **dnptrs, const u_char **lastdnptr)
533 + u_char tmp[NS_MAXCDNAME];
535 + if (ns_name_pton(src, tmp, sizeof tmp) == -1)
537 + return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr));
542 + * Thinking in noninternationalized USASCII (per the DNS spec),
543 + * is this characted special ("in need of quoting") ?
550 + case 0x22: /* '"' */
551 + case 0x2E: /* '.' */
552 + case 0x3B: /* ';' */
553 + case 0x5C: /* '\\' */
554 + /* Special modifiers in zone files. */
555 + case 0x40: /* '@' */
556 + case 0x24: /* '$' */
565 + * Thinking in noninternationalized USASCII (per the DNS spec),
566 + * is this character visible and not a space when printed ?
572 + return (ch > 0x20 && ch < 0x7f);
576 + * Thinking in noninternationalized USASCII (per the DNS spec),
577 + * convert this character to lower case if it's upper case.
581 + if (ch >= 0x41 && ch <= 0x5A)
582 + return (ch + 0x20);
587 + * dn_find(domain, msg, dnptrs, lastdnptr)
588 + * Search for the counted-label name in an array of compressed names.
590 + * offset from msg if found, or -1.
592 + * dnptrs is the pointer to the first name on the list,
593 + * not the pointer to the start of the message.
596 +dn_find(const u_char *domain, const u_char *msg,
597 + const u_char * const *dnptrs,
598 + const u_char * const *lastdnptr)
600 + const u_char *dn, *cp, *sp;
601 + const u_char * const *cpp;
604 + for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
607 + * terminate search on:
609 + * compression pointer
612 + while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 &&
613 + (sp - msg) < 0x4000) {
616 + while ((n = *cp++) != 0) {
618 + * check for indirection
620 + switch (n & NS_CMPRSFLGS) {
621 + case 0: /* normal case, n == len */
624 + for ((void)NULL; n > 0; n--)
625 + if (mklower(*dn++) !=
628 + /* Is next root for both ? */
629 + if (*dn == '\0' && *cp == '\0')
635 + case NS_CMPRSFLGS: /* indirection */
636 + cp = msg + (((n & 0x3f) << 8) | *cp);
639 + default: /* illegal type */
651 + * Expand compressed domain name 'comp_dn' to full domain name.
652 + * 'msg' is a pointer to the begining of the message,
653 + * 'eomorig' points to the first location after the message,
654 + * 'exp_dn' is a pointer to a buffer of size 'length' for the result.
655 + * Return size of compressed name or -1 if there was an error.
658 +dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
659 + char *dst, int dstsiz)
661 + int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
663 + if (n > 0 && dst[0] == '.')
669 + * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
670 + * Return the size of the compressed name or -1.
671 + * 'length' is the size of the array pointed to by 'comp_dn'.
674 +dn_comp(const char *src, u_char *dst, int dstsiz,
675 + u_char **dnptrs, u_char **lastdnptr)
677 + return (ns_name_compress(src, dst, (size_t)dstsiz,
678 + (const u_char **)dnptrs,
679 + (const u_char **)lastdnptr));
682 diff -Nur dsniff-2.3/Makefile.in dsniff-2.3.patched/Makefile.in
683 --- dsniff-2.3/Makefile.in 2000-12-15 21:03:26.000000000 +0100
684 +++ dsniff-2.3.patched/Makefile.in 2005-06-09 14:03:18.000000000 +0200
686 pathnames.h pcaputil.h record.h rpc.h tcp_raw.h trigger.h \
689 -SRCS = asn1.c base64.c buf.c hex.c magic.c mount.c pcaputil.c rpc.c \
690 +SRCS = asn1.c base64.c buf.c dns.c hex.c magic.c mount.c pcaputil.c rpc.c \
691 tcp_raw.c trigger.c record.c dsniff.c decode.c decode_aim.c \
692 decode_citrix.c decode_cvs.c decode_ftp.c decode_hex.c \
693 decode_http.c decode_icq.c decode_imap.c decode_irc.c \
695 arpspoof: arpspoof.o arp.o
696 $(CC) $(LDFLAGS) -o $@ arpspoof.o arp.o $(LIBS) $(PCAPLIB) $(LNETLIB)
698 -dnsspoof: dnsspoof.o pcaputil.o
699 - $(CC) $(LDFLAGS) -o $@ dnsspoof.o pcaputil.o $(LIBS) $(PCAPLIB) $(LNETLIB)
700 +dnsspoof: dnsspoof.o pcaputil.o dns.o
701 + $(CC) $(LDFLAGS) -o $@ dnsspoof.o pcaputil.o dns.o $(LIBS) $(PCAPLIB) $(LNETLIB)
703 filesnarf: nfs_prot.o filesnarf.o pcaputil.o rpc.o
704 $(CC) $(LDFLAGS) -o $@ filesnarf.o nfs_prot.o pcaputil.o rpc.o $(LIBS) $(NIDSLIB) $(PCAPLIB) $(LNETLIB)