dd03e638c139f4e3e47b3db4f3326c4fba6cce03
[ossec-hids.git] / src / headers / rules_op.h
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 /* Common API for dealing with directory trees */
16           
17
18 #ifndef _OS_RULESOP_H
19 #define _OS_RULESOP_H
20
21 #include "shared.h"
22
23
24 /* Event context  - stored on a uint8 */
25 #define SAME_USER       0x001 /* 1   */
26 #define SAME_SRCIP      0x002 /* 2   */
27 #define SAME_ID         0x004 /* 4   */
28 #define SAME_LOCATION   0x008 /* 8   */
29 #define DIFFERENT_URL   0x010 /* */
30 #define SAME_SRCPORT    0x020
31 #define SAME_DSTPORT    0x040
32 #define SAME_DODIFF     0x100
33 #define NOT_SAME_USER   0xffe /* 0xfff - 0x001  */
34 #define NOT_SAME_SRCIP  0xffd /* 0xfff - 0x002  */
35 #define NOT_SAME_ID     0xffb /* 0xfff - 0x004  */
36 #define NOT_SAME_AGENT  0xff7 /* 0xfff - 0x008 */
37
38
39 /* Alert options  - store on a uint8 */
40 #define DO_FTS          0x001
41 #define DO_MAILALERT    0x002
42 #define DO_LOGALERT     0x004
43 #define NO_AR           0x008
44 #define NO_ALERT        0x010
45 #define DO_OVERWRITE    0x020
46 #define DO_PACKETINFO   0x040
47 #define DO_EXTRAINFO    0x100
48 #define SAME_EXTRAINFO  0x200
49
50
51 /** Types of events (from decoders) **/
52 #define UNKNOWN     0   /* Unkown */
53 #define SYSLOG      1   /* syslog messages */
54 #define IDS         2   /* IDS alerts */
55 #define FIREWALL    3   /* Firewall events */
56 #define WEBLOG      7   /* Apache logs */
57 #define SQUID       8   /* Squid logs */
58 #define WINDOWS     9   /* Windows logs */
59 #define HOST_INFO   10  /* Host information logs (from nmap or similar) */
60 #define OSSEC_RL    11  /* Ossec rules */
61
62
63 /* FTS allowed values */
64 #define FTS_NAME        001000
65 #define FTS_USER        002000
66 #define FTS_DSTUSER     004000
67 #define FTS_SRCIP       000100
68 #define FTS_DSTIP       000200
69 #define FTS_LOCATION    000400
70 #define FTS_ID          000010
71 #define FTS_DATA        000020
72 #define FTS_SYSTEMNAME  000040
73
74
75
76
77 typedef struct _RuleInfo
78 {
79     int sigid;  /* id attribute -- required*/
80     int level;  /* level attribute --required */
81     int maxsize;
82     int frequency;
83     int timeframe;
84
85     u_int8_t context; /* Not an user option */
86
87     int firedtimes;  /* Not an user option */
88     int time_ignored; /* Not an user option */
89     int ignore_time;
90     int ignore;
91     int ckignore;
92     int group_prev_matched_sz;
93
94     int __frequency;
95     char **last_events;
96     
97
98     /* Not an option in the rule */
99     u_int16_t alert_opts;
100
101     /* Context options */
102     u_int16_t context_opts;
103
104     /* category */
105     u_int8_t category;
106    
107     /* Decoded as */
108     u_int16_t decoded_as;
109
110     /* List of previously matched events */
111     OSList *sid_prev_matched;
112
113     /* Pointer to a list (points to sid_prev_matched of if_matched_sid */
114     OSList *sid_search;
115
116     /* List of previously matched events in this group.
117      * Every rule that has if_matched_group will have this
118      * list. Every rule that matches this group, it going to
119      * have a pointer to it (group_search).
120      */
121     OSList **group_prev_matched;
122
123     /* Pointer to group_prev_matched */
124     OSList *group_search;
125
126     /* Function pointer to the event_search. */
127     void *(*event_search)(void *lf, void *rule);
128     
129
130     char *group;
131     OSMatch *match;
132     OSRegex *regex;
133
134     /* Policy-based rules */
135     char *day_time;
136     char *week_day;
137
138     os_ip **srcip;
139     os_ip **dstip;
140     OSMatch *srcport;
141     OSMatch *dstport;
142     OSMatch *user;
143     OSMatch *url;
144     OSMatch *id;
145     OSMatch *status;
146     OSMatch *hostname;
147     OSMatch *program_name;
148     OSMatch *extra_data;
149     char *action;
150     
151     char *comment; /* description in the xml */
152     char *info;
153     char *cve;
154     
155     char *if_sid;
156     char *if_level;
157     char *if_group;
158
159     OSRegex *if_matched_regex;
160     OSMatch *if_matched_group;
161     int if_matched_sid;
162     
163     void **ar;
164
165 }RuleInfo;
166
167
168 /** Prototypes **/
169 int OS_ReadXMLRules(char *rulefile, 
170                     void *(*ruleact_function)(RuleInfo *rule, void *data),
171                     void *data);
172
173
174 #endif
175
176
177 /* EOF */