1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/* Copyright (C) 2000-2006 Boris Wesslowski */
/* $Id: win_xp.c,v 1.7 2006/03/08 19:36:03 bw Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "main.h"
#include "utils.h"
extern struct options opt;
unsigned char win_xp(char *input, int linenum)
{
char *sinputs=input, *sinpute;
int retval, year, day, month, hour, minute, second;
struct tm *t;
/* Read file header */
if(*input=='#' || !isdigit((int)*input))
return PARSE_NO_HIT;
init_line();
xstrncpy(opt.line->hostname, "-", SHORTLEN);
xstrncpy(opt.line->chainlabel, "-", SHORTLEN);
xstrncpy(opt.line->interface, "-", SHORTLEN);
/* Read time */
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
retval = sscanf(sinputs, "%4d-%2d-%2d", &year, &month, &day);
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
retval = sscanf(sinputs, "%2d:%2d:%2d", &hour, &minute, &second);
t = xmalloc(sizeof(struct tm));
t->tm_year = year-1900;
t->tm_mon = month-1;
t->tm_mday = day;
t->tm_hour = hour;
t->tm_min = minute;
t->tm_sec = second;
t->tm_isdst = -1;
opt.line->time = mktime(t);
/* Read action */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (*sinputs == '-'){
xstrncpy(opt.line->branchname, "-", SHORTLEN);
} else {
xstrncpy(opt.line->branchname, sinputs, SHORTLEN);
}
/* Read protocol */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if(strncmp(sinputs, "TCP", 3) == 0) opt.line->protocol = 6;
else if(strncmp(sinputs, "UDP", 3) == 0) opt.line->protocol = 17;
else if(strncmp(sinputs, "ICMP", 4) == 0) opt.line->protocol = 1;
else {
if(opt.verbose)
fprintf(stderr, "win_xp parse error while reading proto in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read src ip */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (*sinputs != '-'){
if(convert_ip(sinputs, &opt.line->shost) == IN_ADDR_ERROR) return PARSE_NO_HIT;
} else {
if(opt.verbose)
fprintf(stderr, "win_xp parse error while reading shost in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read dst ip */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (*sinputs != '-'){
if(convert_ip(sinputs, &opt.line->dhost) == IN_ADDR_ERROR) return PARSE_NO_HIT;
} else {
if(opt.verbose)
fprintf(stderr, "win_xp parse error while reading dhost in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read src port */
sinpute=sinpute+1;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (isdigit((int)*sinputs)){
opt.line->sport=atoi(sinputs);
} else if (*sinputs == '-' && (opt.line->protocol == 6 || opt.line->protocol == 17)) {
if(opt.verbose)
fprintf(stderr, "win_xp parse error while reading sport in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read dst port */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (isdigit((int)*sinputs)){
opt.line->dport=atoi(sinputs);
} else if (*sinputs == '-' && (opt.line->protocol == 6 || opt.line->protocol == 17)) {
if(opt.verbose)
fprintf(stderr, "win_xp parse error while reading dport in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
/* Read size */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (isdigit((int)*sinputs)){
opt.line->datalen=atoi(sinputs);
} else {
opt.line->datalen=0;
}
/* Read tcp flags */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
while (*sinputs != '\0') {
switch (*sinputs) {
case '-':
opt.line->flags = 0;
break;
case 'S':
opt.line->flags = opt.line->flags | TCP_SYN;
break;
case 'A':
opt.line->flags = opt.line->flags | TCP_ACK;
break;
case 'F':
opt.line->flags = opt.line->flags | TCP_FIN;
break;
case 'P':
opt.line->flags = opt.line->flags | TCP_PSH;
break;
default:
if(opt.verbose)
fprintf(stderr, "win_xp parse error in line %d, ignoring.\n", linenum);
return PARSE_WRONG_FORMAT;
}
sinputs++;
}
/* Read tcpsyn tcpack and tcpwin, not used */
sinpute++;
sinpute = strchr(sinpute, ' ');
sinpute++;
sinpute = strchr(sinpute, ' ');
sinpute++;
sinpute = strchr(sinpute, ' ');
/* Read icmp type */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (isdigit((int)*sinputs)){
opt.line->sport=atoi(sinputs);
}
/* Read icmp code */
sinpute++;
sinputs=sinpute;
sinpute = strchr(sinputs, ' ');
if (sinpute != NULL)
*sinpute = '\0';
if (isdigit((int)*sinputs)){
opt.line->dport=atoi(sinputs);
}
/* Ignore info at end of line */
opt.line->count = 1;
return PARSE_OK;
}
|