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