00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039
00040 #include "event.h"
00041 #include "decode.h"
00042 #include "plugbase.h"
00043 #include "spo_plugbase.h"
00044 #include "debug.h"
00045 #include "parser.h"
00046 #include "util.h"
00047 #include "log.h"
00048 #include "mstring.h"
00049
00050 #include "snort.h"
00051
00052 #ifdef HAVE_STRINGS_H
00053 #include <strings.h>
00054 #endif
00055
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058
00059
00060 typedef struct _SpoAlertFullData
00061 {
00062 FILE *file;
00063 } SpoAlertFullData;
00064
00065 void AlertFullInit(u_char *);
00066 SpoAlertFullData *ParseAlertFullArgs(char *);
00067 void AlertFull(Packet *, char *, void *, Event *);
00068 void AlertFullCleanExit(int, void *);
00069 void AlertFullRestart(int, void *);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 void AlertFullSetup(void)
00085 {
00086
00087
00088 RegisterOutputPlugin("alert_full", NT_OUTPUT_ALERT, AlertFullInit);
00089
00090 DEBUG_WRAP(DebugMessage(DEBUG_INIT,"Output plugin: AlertFull is setup...\n"););
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 void AlertFullInit(u_char *args)
00106 {
00107 SpoAlertFullData *data;
00108 DEBUG_WRAP(DebugMessage(DEBUG_INIT, "Output: AlertFull Initialized\n"););
00109
00110 pv.alert_plugin_active = 1;
00111
00112
00113 data = ParseAlertFullArgs(args);
00114 DEBUG_WRAP(DebugMessage(DEBUG_INIT,"Linking AlertFull functions to call lists...\n"););
00115
00116
00117 AddFuncToOutputList(AlertFull, NT_OUTPUT_ALERT, data);
00118 AddFuncToCleanExitList(AlertFullCleanExit, data);
00119 AddFuncToRestartList(AlertFullRestart, data);
00120 }
00121
00122 void AlertFull(Packet *p, char *msg, void *arg, Event *event)
00123 {
00124 char timestamp[TIMEBUF_SIZE];
00125 SpoAlertFullData *data = (SpoAlertFullData *)arg;
00126
00127 if(msg != NULL)
00128 {
00129 fwrite("[**] ", 5, 1, data->file);
00130
00131 if(event != NULL)
00132 {
00133 fprintf(data->file, "[%lu:%lu:%lu] ",
00134 (unsigned long) event->sig_generator,
00135 (unsigned long) event->sig_id,
00136 (unsigned long) event->sig_rev);
00137 }
00138
00139 if(pv.alert_interface_flag)
00140 {
00141 fprintf(data->file, " <%s> ", PRINT_INTERFACE(pv.interface));
00142 fwrite(msg, strlen(msg), 1, data->file);
00143 fwrite(" [**]\n", 6, 1, data->file);
00144 }
00145 else
00146 {
00147 fwrite(msg, strlen(msg), 1, data->file);
00148 fwrite(" [**]\n", 6, 1, data->file);
00149 }
00150 }
00151 else
00152 {
00153 fwrite("[**] Snort Alert! [**]\n", 23, 1, data->file);
00154 }
00155
00156 if(p && p->iph)
00157 {
00158 PrintPriorityData(data->file, 1);
00159 }
00160
00161 DEBUG_WRAP(DebugMessage(DEBUG_LOG, "Logging Alert data!\n"););
00162
00163 bzero((char *) timestamp, TIMEBUF_SIZE);
00164 ts_print(p == NULL ? NULL : (struct timeval *) & p->pkth->ts, timestamp);
00165
00166
00167 fwrite(timestamp, strlen(timestamp), 1, data->file);
00168 if(p && p->iph)
00169 {
00170
00171
00172 if(pv.show2hdr_flag)
00173 {
00174 Print2ndHeader(data->file, p);
00175 }
00176
00177 PrintIPHeader(data->file, p);
00178
00179
00180 if(!p->frag_flag)
00181 {
00182 switch(p->iph->ip_proto)
00183 {
00184 case IPPROTO_TCP:
00185 PrintTCPHeader(data->file, p);
00186 break;
00187
00188 case IPPROTO_UDP:
00189 PrintUDPHeader(data->file, p);
00190 break;
00191
00192 case IPPROTO_ICMP:
00193 PrintICMPHeader(data->file, p);
00194 break;
00195
00196 default:
00197 break;
00198 }
00199
00200 PrintXrefs(data->file, 1);
00201 }
00202
00203 fputc('\n', data->file);
00204 }
00205 else
00206 {
00207 fputs("\n\n", data->file);
00208 }
00209
00210 fflush(data->file);
00211 return;
00212
00213
00214
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 SpoAlertFullData *ParseAlertFullArgs(char *args)
00232 {
00233 char **toks;
00234 int num_toks;
00235 char *filename;
00236 SpoAlertFullData *data;
00237
00238 data = (SpoAlertFullData *)SnortAlloc(sizeof(SpoAlertFullData));
00239 if(args == NULL)
00240 {
00241 data->file = OpenAlertFile(NULL);
00242 return data;
00243 }
00244 DEBUG_WRAP(DebugMessage(DEBUG_LOG,"ParseAlertFullArgs: %s\n", args););
00245
00246 toks = mSplit(args, " ", 2, &num_toks, 0);
00247 if(strcasecmp("stdout", toks[0]) == 0)
00248 data->file = stdout;
00249 else
00250 {
00251 filename = ProcessFileOption(toks[0]);
00252 data->file = OpenAlertFile(filename);
00253 free(filename);
00254 }
00255 mSplitFree(&toks, num_toks);
00256 return data;
00257 }
00258
00259 void AlertFullCleanExit(int signal, void *arg)
00260 {
00261 SpoAlertFullData *data = (SpoAlertFullData *)arg;
00262
00263 DEBUG_WRAP(DebugMessage(DEBUG_LOG,"AlertFullCleanExit\n"););
00264 fclose(data->file);
00265
00266 free(data);
00267 }
00268
00269 void AlertFullRestart(int signal, void *arg)
00270 {
00271 SpoAlertFullData *data = (SpoAlertFullData *)arg;
00272
00273 DEBUG_WRAP(DebugMessage(DEBUG_LOG,"AlertFullRestart\n"););
00274 fclose(data->file);
00275
00276 free(data);
00277 }
00278