/* * Copyright (C) 2002 scott campbell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * ----------------------------------------------------------------------- * sp_dns_head.h version 1.0, March 13, 2002 * */ #ifndef __SP_DNS_HEAD_H__ #define __SP_DNS_HEAD_H__ #include "snort.h" #include #include #include #include #include "decode.h" #include "plugbase.h" #include "parser.h" #include "log.h" #include "debug.h" #include "mstring.h" #include "generators.h" #include "detect.h" #include "util.h" #define PLUGIN_DNS_HEAD 27 /* series of defines for working w/ dns data struct */ #define DNS_QUERY 1 #define DNS_QUERY_Q 11 #define DNS_QUERY_R 12 #define DNS_OPCODE 2 #define DNS_OPCODE_SQ 21 #define DNS_OPCODE_IQ 22 #define DNS_OPCODE_SS 23 #define DNS_OPCODE_OTHER 24 #define DNS_AA 3 #define DNS_AA_N 31 #define DNS_AA_Y 32 #define DNS_TC 4 #define DNS_TC_Y 41 #define DNS_TC_N 42 #define DNS_RD 5 #define DNS_RD_Y 51 #define DNS_RD_N 52 #define DNS_RA 6 #define DNS_RA_Y 61 #define DNS_RA_N 62 #define DNS_ZERO 7 #define DNS_ZERO_CHECK 71 #define DNS_RCODE 8 #define DNS_RCODE_NOERR 81 #define DNS_RCODE_FORMERR 82 #define DNS_RCODE_SERFAIL 83 #define DNS_RCODE_NAMEERR 84 #define DNS_RCODE_NOIMP 85 #define DNS_RCODE_REFUSED 86 #define DNS_RCODE_RESERVED 87 #define DNS_QTYPE 9 #define DNS_QTYPE_A 91 #define DNS_QTYPE_NS 92 #define DNS_QTYPE_CNAME 93 #define DNS_QTYPE_PTR 94 #define DNS_QTYPE_HINFO 95 #define DNS_QTYPE_MX 96 #define DNS_QTYPE_AXFR 97 #define DNS_QTYPE_ANY 98 #define DNS_QTYPE_SOA 99 #define DNS_QCLASS 10 #define DNS_QCLASS_I 101 #define DNS_QCLASS_X 102 #define DNS_TTL 11 /* series of defs from spp_dns here */ //#define PLUGIN_TEMPLATE_NUMBER 0 #define QFIXEDSZ 4 /* #/bytes of fixed data in query */ #define NS_MAXDNAME 1025 /* maximum domain name */ #define MAXDNAME NS_MAXDNAME #define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ #define DNS_LABELTYPE_BITSTRING 0x41 #define NS_TYPE_ELT 0x40 /* EDNS0 extended label type */ #define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */ #define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */ #define NS_MAXCDNAME 255 /* maximum compressed domain name */ #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else # define SPRINTF(x) ((size_t)sprintf x) #endif /* * Inline versions of get/put short/long. Pointer is advanced. */ #define uchar_t unsigned char #define NS_GET16(s, cp) do { \ register uchar_t *t_cp = (uchar_t *)(cp); \ (s) = ((uint16_t)t_cp[0] << 8) \ | ((uint16_t)t_cp[1]) \ ; \ (cp) += NS_INT16SZ; \ } while (0) #define NS_GET32(l, cp) do { \ register uchar_t *t_cp = (uchar_t *)(cp); \ (l) = ((uint32_t)t_cp[0] << 24) \ | ((uint32_t)t_cp[1] << 16) \ | ((uint32_t)t_cp[2] << 8) \ | ((uint32_t)t_cp[3]) \ ; \ (cp) += NS_INT32SZ; \ } while (0) #define GETSHORT NS_GET16 #define GETLONG NS_GET32 #define QUESTION 0; #define RESPONSE 1; /* end of spp_dns defs */ /* your data structure info goes here */ typedef struct _DnsHeadData { int value; /* field in dns data struct */ int type; /* expected value for this field */ } DnsHeadData; typedef struct _DnsRecord { u_short type[24]; u_short class[24]; u_int32_t ttl[24]; u_short dlen[24]; u_short error; /* if there is an error digesting the data, set this and clean up */ } DnsRecord; void DNSTemplateInit(char *, OptTreeNode *, int); void ParseDNS(char *, OptTreeNode *); int DnsDetectorFunction(Packet *, struct _OptTreeNode *, OptFpList *); void SetupDNSTemplate(); void dumpPacket(Packet *); DnsRecord GatherInnerData(Packet *); int skipName(); int skipToData(); void dnsErrorHand(int et, Packet *p); void packetClean(u_char *read_ptr, u_char *endOfData, DNS_HEADER *dnsheader, Packet *p); /* new stuff */ int special(int); int printable(int); int encode_bitsring(const char **, const char *,char **, char **, const char *); int labellen(const u_char *); int decode_bitstring(const char **, char *, const char *); int dn_expand(const u_char *, const u_char *, const u_char *, char *, int); int ns_name_uncompress(const u_char *, const u_char *, const u_char *, char *, size_t); int ns_name_unpack(const u_char *, const u_char *, const u_char *, u_char *, size_t); int ns_name_ntop(const u_char *, char *, size_t); #endif /* __SP_DNS_HEAD_H__ */