1、snort 免费的软件这是一个免费的软件,你可以在GUN通用公共许可协议系统下进行重新配置或修改,通过免费软件开发发行版本2或你自己买的有使用权的任意一个都可以。这个项目是分散式的,比较有用,本软件不提供任何保证,甚至不会包括可售性和适用于任何特定目的的保证。可以看得相关GUN通用公共许可协议的更多详细资料。你应该接受一个复制的GUN通用公共许可协议在项目以外。#include log.hextern OptTreeNode *otn_tmp; /* global ptr to current rule data */char *data_dump_buffer; /* printout bu
2、ffer for PrintNetData */int dump_ready; /* flag to indicate status of printout buffer */int dump_size; /* size of printout buffer */static unsigned char ezero6; /* crap for ARP */* * Function: OpenLogFile() * * Purpose: Create the log directory and file to put the packet log into. * This function su
3、cks, Ive got to find a better way to do this * this stuff. * * Arguments: None. * * Returns: 0 on success, exits on error */int OpenLogFile(int mode, Packet * p) char log_pathSTD_BUF+1; /* path to log file */ char log_fileSTD_BUF+1; /* name of log file */ char proto5; /* logged packet protocol */ /*
4、 zero out our buffers */ bzero(char *) log_path, STD_BUF+1); bzero(char *) log_file, STD_BUF+1); bzero(char *) proto, 5); if(mode = GENERIC_LOG) snprintf(log_file, STD_BUF, %s%s/log, chrootdir = NULL ? : chrootdir, pv.log_dir); if(log_ptr = fopen(log_file, a) = NULL) FatalError(ERROR: OpenLogFile()
5、= fopen(%s) log file: %sn, log_file, strerror(errno); return 0; if(mode = DUMP) snprintf(log_file, STD_BUF, %s%s/PACKET_FRAG, chrootdir = NULL ? : chrootdir, pv.log_dir); if(log_ptr = fopen(log_file, a) = NULL) FatalError(ERROR: OpenLogFile() = fopen(%s) log file: %sn, log_file, strerror(errno); ret
6、urn 0; if(mode = BOGUS) snprintf(log_file, STD_BUF, %s%s/PACKET_BOGUS, chrootdir = NULL ? : chrootdir, pv.log_dir); if(log_ptr = fopen(log_file, a) = NULL) FatalError(ERROR: OpenLogFile() = fopen(%s) log file: %sn, log_file, strerror(errno); return 0; if(mode = NON_IP) snprintf(log_file, STD_BUF, %s
7、%s/PACKET_NONIP, chrootdir = NULL ? : chrootdir, pv.log_dir); if(log_ptr = fopen(log_file, a) = NULL) FatalError(ERROR: OpenLogFile() = fopen(%s) log file: %sn, log_file, strerror(errno); return 0; if(mode = ARP) snprintf(log_file, STD_BUF, %s%s/ARP, chrootdir = NULL ? : chrootdir, pv.log_dir); if(l
8、og_ptr = fopen(log_file, a) = NULL) FatalError(ERROR: OpenLogFile() = fopen(%s) log file: %sn, log_file, strerror(errno); return 0; if(otn_tmp != NULL) if(otn_tmp-logto != NULL) snprintf(log_file, STD_BUF, %s%s/%s, chrootdir = NULL ? : chrootdir, pv.log_dir, otn_tmp-logto); if(log_ptr = fopen(log_fi
9、le, a) = NULL) FatalError(ERROR: OpenLogFile() = fopen(%s) log file: %sn, log_file, strerror(errno); return 0; /* figure out which way this packet is headed in relation to the homenet */ if(p-iph-ip_dst.s_addr & mask) = pv.homenet) if(p-iph-ip_src.s_addr & mask) != pv.homenet) snprintf(log_path, STD
10、_BUF, %s%s/%s, chrootdir = NULL ? : chrootdir, pv.log_dir, inet_ntoa(p-iph-ip_src); else if(p-sp = p-dp) snprintf(log_path, STD_BUF, %s%s/%s, chrootdir = NULL ? : chrootdir, pv.log_dir, inet_ntoa(p-iph-ip_src); else snprintf(log_path, STD_BUF, %s%s/%s, chrootdir = NULL ? : chrootdir, pv.log_dir, ine
11、t_ntoa(p-iph-ip_dst); else if(p-iph-ip_src.s_addr & mask) = pv.homenet) snprintf(log_path, STD_BUF, %s%s/%s, chrootdir = NULL ? : chrootdir, pv.log_dir, inet_ntoa(p-iph-ip_dst); else if(p-sp = p-dp) snprintf(log_path, STD_BUF, %s%s/%s, chrootdir = NULL ? : chrootdir, pv.log_dir, inet_ntoa(p-iph-ip_s
12、rc); else snprintf(log_path, STD_BUF, %s%s/%s, chrootdir = NULL ? : chrootdir, pv.log_dir, inet_ntoa(p-iph-ip_dst); #ifdef DEBUG ErrorMessage(Creating directory: %sn, log_path);#endif /* build the log directory */ if(mkdir(log_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) if(errno != EEXIST) FatalErr
13、or(ERROR: OpenLogFile() = mkdir(%s) log directory: %sn, log_path, strerror(errno); #ifdef DEBUG printf(Directory Created!n);#endif /* build the log filename */ if(p-iph-ip_proto = IPPROTO_TCP | p-iph-ip_proto = IPPROTO_UDP) if(p-frag_flag) #ifdef WIN32 snprintf(log_file, STD_BUF, %s/IP_FRAG.ids, log
14、_path);#else snprintf(log_file, STD_BUF, %s/IP_FRAG, log_path);#endif else if(p-sp = p-dp) #ifdef WIN32 snprintf(log_file, STD_BUF, %s/%s_%d-%d.ids, log_path,#else snprintf(log_file, STD_BUF, %s/%s:%d-%d, log_path,#endif protocol_namesp-iph-ip_proto, p-sp, p-dp); else #ifdef WIN32 snprintf(log_file,
15、 STD_BUF, %s/%s_%d-%d.ids, log_path,#else snprintf(log_file, STD_BUF, %s/%s:%d-%d, log_path,#endif protocol_namesp-iph-ip_proto, p-dp, p-sp); else if(p-frag_flag) #ifdef WIN32 snprintf(log_file, STD_BUF, %s/IP_FRAG.ids, log_path);#else snprintf(log_file, STD_BUF, %s/IP_FRAG, log_path);#endif else if
16、(p-iph-ip_proto = IPPROTO_ICMP) #ifdef WIN32 snprintf(log_file, STD_BUF, %s/%s_%s.ids, log_path, ICMP, IcmpFileName(p);#else snprintf(log_file, STD_BUF, %s/%s_%s, log_path, ICMP, IcmpFileName(p);#endif else #ifdef WIN32 snprintf(log_file, STD_BUF, %s/PROTO%d.ids, log_path, p-iph-ip_proto);#else snpr
17、intf(log_file, STD_BUF, %s/PROTO%d, log_path, p-iph-ip_proto);#endif #ifdef DEBUG printf(Opening file: %sn, log_file);#endif /* finally open the log file */ if(log_ptr = fopen(log_file, a) = NULL) FatalError(ERROR: OpenLogFile() = fopen(%s) log file: %sn, log_file, strerror(errno); #ifdef DEBUG prin
18、tf(File opened.n);#endif return 0;/* * Function: PrintNetData(FILE *, u_char *,int) * * Purpose: Do a side by side dump of a buffer, hex dump of buffer bytes on * the left, decoded ASCII on the right. * * Arguments: fp = ptr to stream to print to * start = pointer to buffer data * len = length of da
19、ta buffer * * Returns: void function */void PrintNetData(FILE * fp, u_char * start, const int len) char *end; /* ptr to buffer end */ int i; /* counter */ int j; /* counter */ int dbuf_size; /* data buffer size */ int done; /* flag */ char *data; /* index pointer */ char *frame_ptr; /* we use 66 byt
20、e frames for a printed line */ char *d_ptr; /* data pointer into the frame */ char *c_ptr; /* char pointer into the frame */ char conv = 0123456789ABCDEF; /* xlation lookup table */ /* initialization */ done = 0; if(start = NULL) printf(Got NULL ptr in PrintNetData()n); return; /* zero, print a and
21、get out */ if(!len) fputc(n, fp); return; /* * if weve already prepared this particular data buffer, just print it * out again to save time */ if(dump_ready) fwrite(data_dump_buffer, dump_size, 1, fp); fflush(fp); return; end = start + (len - 1); /* set the end of buffer ptr */ if(len pv.mtus0) if(p
22、v.verbose_flag) printf(Got bogus buffer length (%d) for PrintNetData, defaulting to 16 bytes!n, len); if(pv.verbose_bytedump_flag = 1) dbuf_size = (FRAME_SIZE + 8) + (FRAME_SIZE + 8) + 1; else dbuf_size = FRAME_SIZE + FRAME_SIZE + 1; /* dbuf_size = 66 + 67; */ end = start + 15; else if(pv.verbose_by
23、tedump_flag = 1) /* figure out how big the printout data buffer has to be */ dbuf_size = (len / 16) * (FRAME_SIZE + 8) + (FRAME_SIZE + 8) + 1; else /* figure out how big the printout data buffer has to be */ dbuf_size = (len / 16) * FRAME_SIZE) + FRAME_SIZE + 1; /* dbuf_size = (len / 16) * 66) + 67;
24、 */ /* generate the buffer */ data_dump_buffer = (char *) malloc(dbuf_size); /* make sure it got allocated properly */ if(data_dump_buffer = NULL) ErrorMessage(Failed allocating %X bytes! (Length: %X)n, dbuf_size, len); perror(PrintNetData(); CleanExit(SIGQUIT); /* clean it out */ memset(data_dump_b
25、uffer, 0x20, dbuf_size); /* set the byte buffer pointer to step thru the data buffer */ data = start; /* set the frame pointer to the start of the printout buffer */ frame_ptr = data_dump_buffer; /* initialize counters and frame index pointers */ i = 0; j = 0; /* loop thru the whole buffer */ while(
26、!done) if(pv.verbose_bytedump_flag = 1) d_ptr = frame_ptr + 8; c_ptr = (frame_ptr + 8 + C_OFFSET); sprintf(frame_ptr, 0x%04X: , j); j += 16; else d_ptr = frame_ptr; c_ptr = (frame_ptr + C_OFFSET); /* process 16 bytes per frame */ for(i = 0; i 4); d_ptr+; /* look up the second nybble */ *d_ptr = conv
27、(*data & 0xFF) & 0x0F); d_ptr+; /* put a space in between */ *d_ptr = 0x20; d_ptr+; /* print out the char equivalent */ if(*data 0x1F & *data 0x7F) *c_ptr = (*data & 0xFF); else *c_ptr = 0x2E; c_ptr+; /* increment the pointer or finish up */ if(data end) data+; else /* finish up the buffer printout
28、and set the ready flags */ done = 1; dump_ready = 1; *c_ptr = n; c_ptr+; *c_ptr = n; c_ptr+; *c_ptr = 0; dump_size = (int) (c_ptr - data_dump_buffer); fwrite(data_dump_buffer, dump_size, 1, fp); return; *c_ptr = n; if(pv.verbose_bytedump_flag = 1) frame_ptr += (FRAME_SIZE + 8); else frame_ptr += FRAME_SIZE; /* * Function: PrintCharData(FILE *, char *,int) * * Purpose: Dump th
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1