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