1 /* @(#) $Id: ./src/analysisd/rules.h, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
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
18 #define MAX_LAST_EVENTS 11
21 #include "active-response.h"
25 /* Event context - stored on a uint8 */
26 #define SAME_USER 0x001 /* 1 */
27 #define SAME_SRCIP 0x002 /* 2 */
28 #define SAME_ID 0x004 /* 4 */
29 #define SAME_LOCATION 0x008 /* 8 */
30 #define DIFFERENT_URL 0x010 /* */
31 #define SAME_SRCPORT 0x020
32 #define SAME_DSTPORT 0x040
33 #define SAME_DODIFF 0x100
34 #define NOT_SAME_USER 0xffe /* 0xfff - 0x001 */
35 #define NOT_SAME_SRCIP 0xffd /* 0xfff - 0x002 */
36 #define NOT_SAME_ID 0xffb /* 0xfff - 0x004 */
37 #define NOT_SAME_AGENT 0xff7 /* 0xfff - 0x008 */
39 /* Alert options - store on a uint8 */
41 #define DO_MAILALERT 0x002
42 #define DO_LOGALERT 0x004
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
52 #define RULE_SRCPORT 4
54 #define RULE_DSTPORT 16
58 #define RULE_HOSTNAME 256
59 #define RULE_PROGRAM_NAME 512
60 #define RULE_STATUS 1024
61 #define RULE_ACTION 2048
64 #define RULEINFODETAIL_TEXT 0
65 #define RULEINFODETAIL_LINK 1
66 #define RULEINFODETAIL_CVE 2
67 #define RULEINFODETAIL_OSVDB 3
68 #define RULEINFODETAIL_BUGTRACK 4
70 #define MAX_RULEINFODETAIL 32
72 typedef struct _RuleInfoDetail
76 struct _RuleInfoDetail *next;
79 typedef struct _RuleInfo
81 int sigid; /* id attribute -- required*/
82 int level; /* level attribute --required */
87 u_int8_t context; /* Not an user option */
89 int firedtimes; /* Not an user option */
90 int time_ignored; /* Not an user option */
94 int group_prev_matched_sz;
100 /* Not an option in the rule */
101 u_int16_t alert_opts;
103 /* Context options */
104 u_int16_t context_opts;
110 u_int16_t decoded_as;
112 /* List of previously matched events */
113 OSList *sid_prev_matched;
115 /* Pointer to a list (points to sid_prev_matched of if_matched_sid */
118 /* List of previously matched events in this group.
119 * Every rule that has if_matched_group will have this
120 * list. Every rule that matches this group, it going to
121 * have a pointer to it (group_search).
123 OSList **group_prev_matched;
125 /* Pointer to group_prev_matched */
126 OSList *group_search;
128 /* Function pointer to the event_search. */
129 void *(*event_search)(void *lf, void *rule);
136 /* Policy-based rules */
149 OSMatch *program_name;
153 char *comment; /* description in the xml */
156 RuleInfoDetail *info_details;
163 OSRegex *if_matched_regex;
164 OSMatch *if_matched_group;
167 void *(*compiled_rule)(void *lf);
168 active_response **ar;
173 typedef struct _RuleNode
176 struct _RuleNode *next;
177 struct _RuleNode *child;
181 RuleInfo *currently_rule; /* */
183 RuleInfoDetail *zeroinfodetails(int type, char *data);
184 int get_info_attributes(char **attributes, char **values);
186 /* RuleInfo functions */
187 RuleInfo *zerorulemember(int id,
197 /** Rule_list Functions **/
199 /* create the rule list */
200 void OS_CreateRuleList();
202 /* Add rule information to the list */
203 int OS_AddRule(RuleInfo *read_rule);
205 /* Add rule information as a child */
206 int OS_AddChild(RuleInfo *read_rule);
208 /* Add an overwrite rule */
209 int OS_AddRuleInfo(RuleNode *r_node, RuleInfo *newrule, int sid);
211 /* Mark groups (if_matched_group) */
212 int OS_MarkGroup(RuleNode *r_node, RuleInfo *orig_rule);
214 /* Mark IDs (if_matched_sid) */
215 int OS_MarkID(RuleNode *r_node, RuleInfo *orig_rule);
219 RuleNode *OS_GetFirstRule();
222 /** Defition of the internal rule IDS **
223 ** These SIGIDs cannot be used **
226 #define STATS_MODULE 11
227 #define FTS_MODULE 12
228 #define SYSCHECK_MODULE 13
229 #define HOSTINFO_MODULE 15
232 #define ROOTCHECK_MOD "rootcheck"
233 #define HOSTINFO_NEW "hostinfo_new"
234 #define HOSTINFO_MOD "hostinfo_modified"
235 #define SYSCHECK_MOD "syscheck_integrity_changed"
236 #define SYSCHECK_MOD2 "syscheck_integrity_changed_2nd"
237 #define SYSCHECK_MOD3 "syscheck_integrity_changed_3rd"
238 #define SYSCHECK_NEW "syscheck_new_entry"
239 #define SYSCHECK_DEL "syscheck_deleted"
242 #endif /* _OS_RULES */