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