Imported Upstream version 2.7
[ossec-hids.git] / src / analysisd / decoders / plugins / symantecws_decoder.c
1 /* @(#) $Id: ./src/analysisd/decoders/plugins/symantecws_decoder.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights reserved.
6  *
7  * This program is a free software; you can redistribute it
8  * and/or modify it under the terms of the GNU General Public
9  * License (version 2) as published by the FSF - Free Software
10  * Foundation.
11  *
12  * License details at the LICENSE file included with OSSEC or
13  * online at: http://www.ossec.net/en/licensing.html
14  */
15
16 #include "shared.h"
17 #include "eventinfo.h"
18
19
20 /* Symantec Web Security decoder init */
21 void *SymantecWS_Decoder_Init()
22 {
23     debug1("%s: Initializing SymantecWS decoder..", ARGV0);
24
25     /* There is nothing to do over here */
26     return(NULL);
27 }
28
29
30 /* Symantec Web Security decoder
31  * Will extract the action, srcip, id, url and username.
32  *
33  * Examples (also online at
34  * http://www.ossec.net/wiki/index.php/Symantec_WebSecurity ).
35  * 20070717,73613,1=5,11=10.1.1.3,10=userc,3=1,2=1
36  * 20070717,73614,1=5,11=1.2.3.4,1106=News,60=http://news.bbc.co.uk/,10=userX,1000=212.58.240.42,2=27
37  */
38 void *SymantecWS_Decoder_Exec(Eventinfo *lf)
39 {
40     int count = 0;
41     char buf_str[OS_SIZE_1024 +1];
42     char *tmp_str = NULL;
43
44     /* Initializing buffer */
45     buf_str[0] = '\0';
46     buf_str[OS_SIZE_1024] = '\0';
47
48
49     /* Removing date and time */
50     if(!(tmp_str = strchr(lf->log, ',')))
51     {
52         return(NULL);
53     }
54     if(!(tmp_str = strchr(tmp_str, ',')))
55     {
56         return(NULL);
57     }
58     tmp_str++;
59
60
61     /* Getting all the values */
62     while(tmp_str != NULL)
63     {
64         /* Checking if we have the username */
65         if(strncmp(tmp_str, "10=", 3) == 0)
66         {
67             count = 0;
68             tmp_str+=3;
69             while(*tmp_str != '\0' && count < 128 && *tmp_str != ',')
70             {
71                 buf_str[count] = *tmp_str;
72                 count++; tmp_str++;
73             }
74             buf_str[count] = '\0';
75
76             if(!lf->dstuser)
77             {
78                 os_strdup(buf_str, lf->dstuser);
79             }
80         }
81
82         /* Checking the ip address */
83         else if(strncmp(tmp_str, "11=", 3) == 0)
84         {
85             count = 0;
86             tmp_str+=3;
87             while(*tmp_str != '\0' && count < 128 && *tmp_str != ',')
88             {
89                 buf_str[count] = *tmp_str;
90                 count++; tmp_str++;
91             }
92             buf_str[count] = '\0';
93
94             /* Avoiding memory leaks -- only adding the first one */
95             if(!lf->srcip)
96             {
97                 os_strdup(buf_str, lf->srcip);
98             }
99         }
100
101         /* Getting the URL */
102         else if(strncmp(tmp_str, "60=", 3) == 0)
103         {
104             count = 0;
105             tmp_str+=3;
106             while(*tmp_str != '\0' && count < OS_SIZE_1024 && *tmp_str != ',')
107             {
108                 buf_str[count] = *tmp_str;
109                 count++; tmp_str++;
110             }
111             buf_str[count] = '\0';
112
113             /* Avoiding memory leaks -- only adding the first one */
114             if(!lf->url)
115             {
116                 os_strdup(buf_str, lf->url);
117             }
118         }
119
120         /* Getting ID */
121         else if((strncmp(tmp_str, "3=", 2) == 0) ||
122                 (strncmp(tmp_str, "2=", 2) == 0))
123         {
124             count = 0;
125             while(*tmp_str != '\0' && count < 9)
126             {
127                 buf_str[count] = *tmp_str;
128                 count++; tmp_str++;
129             }
130             buf_str[count] = '\0';
131
132             /* Avoiding memory leaks -- only adding the first one */
133             if(!lf->id)
134             {
135                 os_strdup(buf_str, lf->id);
136             }
137         }
138
139         /* Getting next entry */
140         tmp_str = strchr(tmp_str, ',');
141         if(tmp_str)
142         {
143             tmp_str++;
144         }
145     }
146
147     return(NULL);
148 }
149
150 /* END Decoder */