-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
rules.c
3268 lines (2734 loc) · 141 KB
/
rules.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2015, Wazuh Inc.
* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/
#include "rules.h"
#include "config.h"
#include "eventinfo.h"
#include "compiled_rules/compiled_rules.h"
#include "analysisd.h"
#ifdef WAZUH_UNIT_TESTING
// Remove STATIC qualifier from tests
#define STATIC
#define INLINE
#else
#define STATIC static
#define INLINE inline
#endif
/* Global definition */
int default_timeframe;
/* Used for statistics */
unsigned int hourly_alerts;
/* Do diff mutex */
static pthread_mutex_t do_diff_mutex = PTHREAD_MUTEX_INITIALIZER;
/* Hourly alerts mutex */
static pthread_mutex_t hourly_alert_mutex = PTHREAD_MUTEX_INITIALIZER;
w_queue_t * writer_queue_log_fts;
EventList *os_analysisd_last_events;
/* Change path for test rule */
#ifdef TESTRULE
#undef RULEPATH
#define RULEPATH "ruleset/rules/"
#endif
/* Prototypes */
STATIC int getattributes(char **attributes, char **values, int *id, int *level,
int *maxsize, int *timeframe, int *frequency,
int *accuracy, int *noalert, int *ignore_time,
int *overwrite, OSList* log_msg);
STATIC int doesRuleExist(int sid, RuleNode *r_node);
STATIC void Rule_AddAR(RuleInfo *config_rule);
STATIC char *loadmemory(char *at, const char *str, OSList* log_msg);
STATIC void printRuleinfo(const RuleInfo *rule, int node);
/**
* @brief Free the rules_tmp_params_t structure members
* @param rule_tmp_params Struct to free
*/
STATIC INLINE void w_free_rules_tmp_params(rules_tmp_params_t * rule_tmp_params);
/**
* @brief Check if a option has attribute negate
* @param node xml node which contains the rule
* @param rule_id rule identifier
* @param log_msg List to save log messages.
* @return true if it must be negated, otherwise false
*/
bool w_check_attr_negate(xml_node *node, int rule_id, OSList* log_msg);
/**
* @brief Check if field name is valid
* @param node xml node which contains the rule
* @param field field to validate
* @param rule_id rule identifier
* @param log_msg List to save log messages
* @return true on success, otherwise false
*/
bool w_check_attr_field_name(xml_node * node, FieldInfo ** field, int rule_id, OSList* log_msg);
/**
* @brief Get regex type attribute of a node
* @param node node to find regex type value
* @param default_type default type be returned in case of invalid or missing type
* @param rule_id rule identifier
* @param log_msg List to save log messages.
* @return regex type
*/
w_exp_type_t w_check_attr_type(xml_node * node, w_exp_type_t default_type, int rule_id, OSList* log_msg);
/* Will initialize the rules list */
void Rules_OP_CreateRules() {
/* Initialize the rule list */
OS_CreateRuleList();
}
int Rules_OP_ReadRules(const char *rulefile, RuleNode **r_node, ListNode **l_node,
EventList **last_event_list, OSStore **decoder_list, OSList* log_msg)
{
OS_XML xml;
XML_NODE node = NULL;
XML_NODE rule = NULL;
int retval = -1;
/* XML variables */
/* These are the available options for the rule configuration */
const char *xml_group = "group";
const char *xml_rule = "rule";
const char *xml_regex = "regex";
const char *xml_match = "match";
const char *xml_decoded = "decoded_as";
const char *xml_category = "category";
const char *xml_cve = "cve";
const char *xml_info = "info";
const char *xml_day_time = "time";
const char *xml_week_day = "weekday";
const char *xml_comment = "description";
const char *xml_ignore = "ignore";
const char *xml_check_if_ignored = "check_if_ignored";
const char *xml_srcip = "srcip";
const char *xml_srcgeoip = "srcgeoip";
const char *xml_srcport = "srcport";
const char *xml_dstip = "dstip";
const char *xml_dstgeoip = "dstgeoip";
const char *xml_dstport = "dstport";
const char *xml_user = "user";
const char *xml_url = "url";
const char *xml_id = "id";
const char *xml_data = "data";
const char *xml_extra_data = "extra_data";
const char *xml_hostname = "hostname";
const char *xml_program_name = "program_name";
const char *xml_status = "status";
const char *xml_protocol = "protocol";
const char *xml_system_name = "system_name";
const char *xml_action = "action";
const char *xml_compiled = "compiled_rule";
const char *xml_field = "field";
const char *xml_location = "location";
const char *xml_list = "list";
const char *xml_list_lookup = "lookup";
const char *xml_list_field = "field";
const char *xml_list_cvalue = "check_value";
const char *xml_match_key = "match_key";
const char *xml_not_match_key = "not_match_key";
const char *xml_match_key_value = "match_key_value";
const char *xml_address_key = "address_match_key";
const char *xml_not_address_key = "not_address_match_key";
const char *xml_address_key_value = "address_match_key_value";
const char *xml_if_sid = "if_sid";
const char *xml_if_group = "if_group";
const char *xml_if_level = "if_level";
const char *xml_fts = "if_fts";
const char *xml_if_matched_regex = "if_matched_regex";
const char *xml_if_matched_group = "if_matched_group";
const char *xml_if_matched_sid = "if_matched_sid";
const char *xml_same_source_ip = "same_source_ip";
const char *xml_same_srcip = "same_srcip";
const char *xml_same_src_port = "same_src_port";
const char *xml_same_srcport = "same_srcport";
const char *xml_same_dst_port = "same_dst_port";
const char *xml_same_dstport = "same_dstport";
const char *xml_same_srcuser = "same_srcuser";
const char *xml_same_user = "same_user";
const char *xml_same_location = "same_location";
const char *xml_same_id = "same_id";
const char *xml_dodiff = "check_diff";
const char *xml_same_field = "same_field";
const char *xml_same_dstip = "same_dstip";
const char *xml_same_agent = "same_agent";
const char *xml_same_url = "same_url";
const char *xml_same_srcgeoip = "same_srcgeoip";
const char *xml_same_protocol = "same_protocol";
const char *xml_same_action = "same_action";
const char *xml_same_data = "same_data";
const char *xml_same_extra_data = "same_extra_data";
const char *xml_same_status = "same_status";
const char *xml_same_systemname = "same_system_name";
const char *xml_same_dstgeoip = "same_dstgeoip";
const char *xml_different_url = "different_url";
const char *xml_different_srcip = "different_srcip";
const char *xml_different_srcgeoip = "different_srcgeoip";
const char *xml_different_dstip = "different_dstip";
const char *xml_different_src_port = "different_src_port";
const char *xml_different_srcport = "different_srcport";
const char *xml_different_dst_port = "different_dst_port";
const char *xml_different_dstport = "different_dstport";
const char *xml_different_location = "different_location";
const char *xml_different_protocol = "different_protocol";
const char *xml_different_action = "different_action";
const char *xml_different_srcuser = "different_srcuser";
const char *xml_different_user = "different_user";
const char *xml_different_id = "different_id";
const char *xml_different_data = "different_data";
const char *xml_different_extra_data = "different_extra_data";
const char *xml_different_status = "different_status";
const char *xml_different_systemname = "different_system_name";
const char *xml_different_dstgeoip = "different_dstgeoip";
const char *xml_different_field = "different_field";
const char *xml_notsame_source_ip = "not_same_source_ip";
const char *xml_notsame_user = "not_same_user";
const char *xml_notsame_agent = "not_same_agent";
const char *xml_notsame_id = "not_same_id";
const char *xml_notsame_field = "not_same_field";
const char *xml_global_frequency = "global_frequency";
const char *xml_options = "options";
const char *xml_mitre = "mitre";
const char *xml_mitre_id = "id";
const char *xml_mitre_tactic_id = "tacticID";
const char *xml_mitre_technique_id = "techniqueID";
rules_tmp_params_t rule_tmp_params = {0};
RuleInfo * config_ruleinfo = NULL;
char * rulepath = NULL;
size_t i;
default_timeframe = 360;
/* If no directory in the rulefile, add the default */
if ((strchr(rulefile, '/')) == NULL) {
/* Build the rule file name + path */
i = strlen(RULEPATH) + strlen(rulefile) + 2;
rulepath = (char *)calloc(i, sizeof(char));
if (!rulepath) {
merror_exit(MEM_ERROR, errno, strerror(errno));
}
snprintf(rulepath, i, "%s/%s", RULEPATH, rulefile);
} else {
os_strdup(rulefile, rulepath);
mdebug1("%s is the rulefile", rulefile);
mdebug1("Not modifing the rule path");
}
i = 0;
/* Read the XML */
switch(OS_ReadXML(rulepath, &xml)) {
case -2:
smwarn(log_msg, FOPEN_ERROR, rulepath, errno, strerror(errno));
retval = 0;
goto cleanup;
case -1:
smerror(log_msg, XML_ERROR, rulepath, xml.err, xml.err_line);
goto cleanup;
case 0:
default:
break;
}
mdebug2("Read xml for rule.");
/* Apply any variable found */
if (OS_ApplyVariables(&xml) != 0) {
smerror(log_msg, XML_ERROR_VAR, rulepath, xml.err);
goto cleanup;
}
mdebug2("XML Variables applied.");
/* Check if the file is empty */
if(FileSize(rulepath) == 0){
retval = 0;
goto cleanup;
}
/* Get the root elements */
node = OS_GetElementsbyNode(&xml, NULL);
if (!node) {
smerror(log_msg, CONFIG_ERROR, rulepath);
goto cleanup;
}
/* Zero the rule memory -- not used anymore */
free(rulepath);
rulepath = NULL;
/* Get default time frame */
default_timeframe = getDefine_Int("analysisd",
"default_timeframe",
60, 3600);
/* Check if there is any invalid global option */
while (node[i]) {
if (node[i]->element) {
if (strcasecmp(node[i]->element, xml_group) != 0) {
smerror(log_msg, "rules_op: Invalid root element \"%s\".Only \"group\" is allowed", node[i]->element);
goto cleanup;
}
if ((!node[i]->attributes) || (!node[i]->values)
|| (!node[i]->values[0]) || (!node[i]->attributes[0])
|| (strcasecmp(node[i]->attributes[0], "name") != 0)
|| (node[i]->attributes[1])) {
smerror(log_msg, "rules_op: Invalid root element '%s'."
"Only the group name is allowed", node[i]->element);
goto cleanup;
}
} else {
smerror(log_msg, XML_READ_ERROR);
goto cleanup;
}
i++;
}
/* Get the rules */
i = 0;
while (node[i]) {
int j = 0;
/* Get all rules for a global group */
rule = OS_GetElementsbyNode(&xml, node[i]);
if (rule == NULL) {
smerror(log_msg, "Group '%s' without any rule.", node[i]->element);
goto cleanup;
}
while (rule[j]) {
config_ruleinfo = NULL;
/* Check if the rule element is correct */
if (!rule[j]->element) {
smerror(log_msg, INVALID_RULE_ELEMENT);
goto cleanup;
}
if (strcasecmp(rule[j]->element, xml_rule) != 0) {
smerror(log_msg, "Invalid configuration. '%s' is not a valid element.", rule[j]->element);
goto cleanup;
}
/* Check for the attributes of the rule */
if ((!rule[j]->attributes) || (!rule[j]->values)) {
smerror(log_msg, "Invalid rule '%d'. You must specify an ID and a level at least.", j);
goto cleanup;
}
/* Attribute block */
{
int id = -1, level = -1, maxsize = 0, timeframe = 0;
int frequency = 0, accuracy = 1, noalert = 0, ignore_time = 0;
int overwrite = 0;
/* Get default timeframe */
timeframe = default_timeframe;
if (getattributes(rule[j]->attributes, rule[j]->values,
&id, &level, &maxsize, &timeframe,
&frequency, &accuracy, &noalert,
&ignore_time, &overwrite, log_msg) < 0) {
smerror(log_msg, "Invalid attribute for rule.");
goto cleanup;
}
if ((id == -1) || (level == -1)) {
smerror(log_msg, "No rule id or level specified for rule '%d'.", j);
goto cleanup;
}
if (doesRuleExist(id, *r_node)) {
// If rule exists but 'overwrite' was not set to 'yes', then the rule is skipped.
if (overwrite != 1) {
smwarn(log_msg, ANALYSISD_DUPLICATED_SIG_ID, id);
j++;
continue;
}
} else if (overwrite == 1) {
// As the rule does not exists, it will be handled as if the 'overwrite' parameter were set to 'no'
smwarn(log_msg, ANALYSISD_OVERWRITE_MISSING_RULE, id);
overwrite = 0;
}
/* Allocate memory and initialize structure */
config_ruleinfo = zerorulemember(id, level, maxsize, frequency,
timeframe, noalert, ignore_time,
overwrite, last_event_list);
/* If rule is 0, set it to level 99 to have high priority.
* Set it to 0 again later.
*/
if (config_ruleinfo->level == 0) {
config_ruleinfo->level = 99;
}
/* Each level now is going to be multiplied by 100.
* If the accuracy is set to 0 we don't multiply,
* so it will be at the end of the list. We will
* divide by 100 later.
*/
if (accuracy) {
config_ruleinfo->level *= 100;
}
if (config_ruleinfo->maxsize > 0) {
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
}
} /* end attributes/memory allocation block */
/* Here we can assign the group name to the rule.
* The level is correct so the rule is probably going to
* be fine
*/
os_strdup(node[i]->values[0], config_ruleinfo->group);
os_strdup(rulefile,config_ruleinfo->file);
/* Rule elements block */
{
bool do_skip_rule = false;
int ifield = 0;
int info_type = 0;
int count_info_detail = 0;
int mitre_size = 0;
int mitre_size_deprecated = 0;
bool mitre_deprecated = false;
bool mitre_new_format = false;
RuleInfoDetail *last_info_detail = NULL;
bool negate_regex = false;
bool negate_match = false;
bool negate_data = false;
bool negate_extra_data = false;
bool negate_hostname = false;
bool negate_id = false;
bool negate_location = false;
bool negate_program_name = false;
bool negate_protocol = false;
bool negate_user = false;
bool negate_url = false;
bool negate_status = false;
bool negate_srcport = false;
bool negate_dstport = false;
bool negate_system_name = false;
bool negate_srcgeoip = false;
bool negate_dstgeoip = false;
bool negate_action = false;
/* Default regex types */
w_exp_type_t match_type = EXP_TYPE_OSMATCH;
w_exp_type_t regex_type = EXP_TYPE_OSREGEX;
w_exp_type_t extra_data_type = EXP_TYPE_OSMATCH;
w_exp_type_t hostname_type = EXP_TYPE_OSMATCH;
w_exp_type_t location_type = EXP_TYPE_OSMATCH;;
w_exp_type_t program_name_type = EXP_TYPE_OSMATCH;
w_exp_type_t protocol_type = EXP_TYPE_OSMATCH;;
w_exp_type_t user_type = EXP_TYPE_OSMATCH;;
w_exp_type_t url_type = EXP_TYPE_OSMATCH;;
w_exp_type_t srcport_type = EXP_TYPE_OSMATCH;;
w_exp_type_t dstport_type = EXP_TYPE_OSMATCH;
w_exp_type_t status_type = EXP_TYPE_OSMATCH;
w_exp_type_t system_name_type = EXP_TYPE_OSMATCH;
w_exp_type_t data_type = EXP_TYPE_OSMATCH;
w_exp_type_t srcgeoip_type = EXP_TYPE_OSMATCH;
w_exp_type_t dstgeoip_type = EXP_TYPE_OSMATCH;
w_exp_type_t id_type = EXP_TYPE_OSMATCH;
w_exp_type_t action_type = EXP_TYPE_STRING;
memset(&rule_tmp_params, 0, sizeof(rules_tmp_params_t));
rule_tmp_params.rule_arr_opt = OS_GetElementsbyNode(&xml, rule[j]);
if (rule_tmp_params.rule_arr_opt == NULL) {
smerror(log_msg, "Rule '%d' without any option. It may lead to false positives and some "
"other problems for the system. Exiting.", config_ruleinfo->sigid);
goto cleanup;
}
for (int k = 0; rule_tmp_params.rule_arr_opt[k]; k++) {
if ((!rule_tmp_params.rule_arr_opt[k]->element) || (!rule_tmp_params.rule_arr_opt[k]->content)) {
break;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_regex) == 0) {
rule_tmp_params.regex = loadmemory(rule_tmp_params.regex, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_regex = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
regex_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSREGEX, config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_match) == 0) {
rule_tmp_params.match = loadmemory(rule_tmp_params.match, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_match = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
match_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH, config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_decoded) == 0) {
config_ruleinfo->decoded_as = getDecoderfromlist(rule_tmp_params.rule_arr_opt[k]->content, decoder_list);
if (config_ruleinfo->decoded_as == 0) {
smerror(log_msg, "Invalid decoder name: '%s'.", rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_cve) == 0) {
if (config_ruleinfo->info_details == NULL) {
config_ruleinfo->info_details = zeroinfodetails(RULEINFODETAIL_CVE, rule_tmp_params.rule_arr_opt[k]->content);
} else {
for (last_info_detail = config_ruleinfo->info_details;
last_info_detail->next != NULL;
last_info_detail = last_info_detail->next) {
count_info_detail++;
}
/* Silently Drop info messages if their are more then MAX_RULEINFODETAIL */
if (count_info_detail <= MAX_RULEINFODETAIL) {
last_info_detail->next = zeroinfodetails(RULEINFODETAIL_CVE,
rule_tmp_params.rule_arr_opt[k]->content);
}
}
/* keep old methods for now */
config_ruleinfo->cve = loadmemory(config_ruleinfo->cve, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_info) == 0) {
info_type = get_info_attributes(rule_tmp_params.rule_arr_opt[k]->attributes, rule_tmp_params.rule_arr_opt[k]->values, log_msg);
mdebug1("info_type = %d", info_type);
if (config_ruleinfo->info_details == NULL) {
config_ruleinfo->info_details = zeroinfodetails(info_type, rule_tmp_params.rule_arr_opt[k]->content);
} else {
for (last_info_detail = config_ruleinfo->info_details;
last_info_detail->next != NULL;
last_info_detail = last_info_detail->next) {
count_info_detail++;
}
/* Silently Drop info messages if their are more then MAX_RULEINFODETAIL */
if (count_info_detail <= MAX_RULEINFODETAIL) {
last_info_detail->next = zeroinfodetails(info_type, rule_tmp_params.rule_arr_opt[k]->content);
}
}
/* keep old methods for now */
config_ruleinfo->info = loadmemory(config_ruleinfo->info, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_day_time) == 0) {
config_ruleinfo->day_time = OS_IsValidTime(rule_tmp_params.rule_arr_opt[k]->content);
if (!config_ruleinfo->day_time) {
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_week_day) == 0) {
config_ruleinfo->week_day = OS_IsValidDay(rule_tmp_params.rule_arr_opt[k]->content);
if (!config_ruleinfo->week_day) {
smerror(log_msg, INVALID_DAY, rule_tmp_params.rule_arr_opt[k]->content);
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_group) == 0) {
config_ruleinfo->group = loadmemory(config_ruleinfo->group, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_comment) == 0) {
char * newline = strchr(rule_tmp_params.rule_arr_opt[k]->content, '\n');
if (newline) {
*newline = ' ';
}
config_ruleinfo->comment = loadmemory(config_ruleinfo->comment, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_srcip) == 0) {
if (!w_expression_add_osip(&config_ruleinfo->srcip, rule_tmp_params.rule_arr_opt[k]->content)) {
smerror(log_msg, INVALID_IP, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
if (!config_ruleinfo->srcip) {
smerror(log_msg, INVALID_IP, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
config_ruleinfo->srcip->negate = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k],
config_ruleinfo->sigid,
log_msg);
if (!(config_ruleinfo->alert_opts & DO_PACKETINFO)) {
config_ruleinfo->alert_opts |= DO_PACKETINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_dstip) == 0) {
if (!w_expression_add_osip(&config_ruleinfo->dstip, rule_tmp_params.rule_arr_opt[k]->content)) {
smerror(log_msg, INVALID_IP, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
if (!config_ruleinfo->dstip) {
smerror(log_msg, INVALID_IP, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
config_ruleinfo->dstip->negate = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k],
config_ruleinfo->sigid,
log_msg);
if (!(config_ruleinfo->alert_opts & DO_PACKETINFO)) {
config_ruleinfo->alert_opts |= DO_PACKETINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_user) == 0) {
rule_tmp_params.user = loadmemory(rule_tmp_params.user, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_user = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
user_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH, config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_srcgeoip) == 0) {
rule_tmp_params.srcgeoip = loadmemory(rule_tmp_params.srcgeoip, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_srcgeoip = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
srcgeoip_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_dstgeoip) == 0) {
rule_tmp_params.dstgeoip = loadmemory(rule_tmp_params.dstgeoip, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_dstgeoip = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
dstgeoip_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_id) == 0) {
rule_tmp_params.id = loadmemory(rule_tmp_params.id, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_id = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
id_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH, config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_srcport) == 0) {
rule_tmp_params.srcport = loadmemory(rule_tmp_params.srcport, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_srcport = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
srcport_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_PACKETINFO)) {
config_ruleinfo->alert_opts |= DO_PACKETINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_dstport) == 0) {
rule_tmp_params.dstport = loadmemory(rule_tmp_params.dstport, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_dstport = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
dstport_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_PACKETINFO)) {
config_ruleinfo->alert_opts |= DO_PACKETINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_status) == 0) {
rule_tmp_params.status = loadmemory(rule_tmp_params.status, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_status = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
status_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_hostname) == 0) {
rule_tmp_params.hostname = loadmemory(rule_tmp_params.hostname, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_hostname = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
hostname_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_data) == 0) {
rule_tmp_params.data = loadmemory(rule_tmp_params.data, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_data = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
data_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH, config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_extra_data) == 0) {
rule_tmp_params.extra_data = loadmemory(rule_tmp_params.extra_data, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_extra_data = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
extra_data_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_program_name) == 0) {
rule_tmp_params.program_name = loadmemory(rule_tmp_params.program_name, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_program_name = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
program_name_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_action) == 0) {
rule_tmp_params.action = loadmemory(rule_tmp_params.action, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_action = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
action_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_STRING, config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_system_name) == 0){
rule_tmp_params.system_name = loadmemory(rule_tmp_params.system_name, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_system_name = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
system_name_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_protocol) == 0){
rule_tmp_params.protocol = loadmemory(rule_tmp_params.protocol, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_protocol = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
protocol_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_location) == 0) {
rule_tmp_params.location = loadmemory(rule_tmp_params.location, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_location = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
location_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH,
config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_field) == 0) {
if (Config.decoder_order_size <= ifield) {
smerror(log_msg, "Rule %d has exceeded the maximum number of allowed fields",
config_ruleinfo->sigid);
goto cleanup;
}
if (!w_check_attr_field_name(rule_tmp_params.rule_arr_opt[k],
&config_ruleinfo->fields[ifield],
config_ruleinfo->sigid, log_msg)) {
goto cleanup;
}
w_exp_type_t type;
type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSREGEX, config_ruleinfo->sigid, log_msg);
bool negate = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
w_calloc_expression_t(&config_ruleinfo->fields[ifield]->regex, type);
config_ruleinfo->fields[ifield]->regex->negate = negate;
if (!w_expression_compile(config_ruleinfo->fields[ifield]->regex, rule_tmp_params.rule_arr_opt[k]->content, 0)) {
smerror(log_msg, RL_REGEX_SYNTAX, config_ruleinfo->fields[ifield]->name, config_ruleinfo->sigid);
goto cleanup;
}
ifield++;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_list) == 0) {
mdebug1("-> %s == %s", rule_tmp_params.rule_arr_opt[k]->element, xml_list);
if (rule_tmp_params.rule_arr_opt[k]->attributes && rule_tmp_params.rule_arr_opt[k]->values && rule_tmp_params.rule_arr_opt[k]->content) {
int list_att_num = 0;
int rule_type = 0;
char *rule_dfield = NULL;
OSMatch *matcher = NULL;
int lookup_type = LR_STRING_MATCH;
while (rule_tmp_params.rule_arr_opt[k]->attributes[list_att_num]) {
if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->attributes[list_att_num], xml_list_lookup) == 0) {
if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_match_key) == 0) {
lookup_type = LR_STRING_MATCH;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_not_match_key) == 0) {
lookup_type = LR_STRING_NOT_MATCH;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_match_key_value) == 0) {
lookup_type = LR_STRING_MATCH_VALUE;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_address_key) == 0) {
lookup_type = LR_ADDRESS_MATCH;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_not_address_key) == 0) {
lookup_type = LR_ADDRESS_NOT_MATCH;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_address_key_value) == 0) {
lookup_type = LR_ADDRESS_MATCH_VALUE;
} else {
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
smerror(log_msg, "List match lookup=\"%s\" is not valid.",
rule_tmp_params.rule_arr_opt[k]->values[list_att_num]);
goto cleanup;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->attributes[list_att_num], xml_list_field) == 0) {
if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_srcip) == 0) {
rule_type = RULE_SRCIP;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_srcport) == 0) {
rule_type = RULE_SRCPORT;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_dstip) == 0) {
rule_type = RULE_DSTIP;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_dstport) == 0) {
rule_type = RULE_DSTPORT;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_user) == 0) {
rule_type = RULE_USER;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_url) == 0) {
rule_type = RULE_URL;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_id) == 0) {
rule_type = RULE_ID;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_hostname) == 0) {
rule_type = RULE_HOSTNAME;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_program_name) == 0) {
rule_type = RULE_PROGRAM_NAME;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_status) == 0) {
rule_type = RULE_STATUS;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_action) == 0) {
rule_type = RULE_ACTION;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_protocol) == 0) {
rule_type = RULE_PROTOCOL;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_system_name) == 0) {
rule_type = RULE_SYSTEMNAME;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_data) == 0) {
rule_type = RULE_DATA;
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], xml_extra_data) == 0) {
rule_type = RULE_EXTRA_DATA;
} else {
rule_type = RULE_DYNAMIC;
// Trim whitespaces
rule_dfield = rule_tmp_params.rule_arr_opt[k]->values[list_att_num];
rule_dfield = &rule_dfield[strspn(rule_dfield, " ")];
rule_dfield[strcspn(rule_dfield, " ")] = '\0';
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->attributes[list_att_num], xml_list_cvalue) == 0) {
os_calloc(1, sizeof(OSMatch), matcher);
if (!OSMatch_Compile(rule_tmp_params.rule_arr_opt[k]->values[list_att_num], matcher, 0)) {
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
smerror(log_msg, REGEX_COMPILE, rule_tmp_params.rule_arr_opt[k]->values[list_att_num],
matcher->error);
goto cleanup;
}
} else {
smerror(log_msg, "List field=\"%s\" is not valid",
rule_tmp_params.rule_arr_opt[k]->values[list_att_num]);
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
list_att_num++;
}
if (rule_type == 0) {
smerror(log_msg, "List requires the field=\"\" attribute");
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
/* Wow it's all ready - this seems too complex to get to this point */
ListRule * list_head
= OS_AddListRule(config_ruleinfo->lists,
lookup_type,
rule_type,
rule_dfield,
rule_tmp_params.rule_arr_opt[k]->content,
matcher,
l_node);
if (list_head == NULL) {
smwarn(log_msg, ANALYSISD_LIST_NOT_LOADED,
rule_tmp_params.rule_arr_opt[k]->content,
config_ruleinfo->sigid);
if (matcher != NULL) {
OSMatch_FreePattern(matcher);
}
os_free(matcher);
do_skip_rule = true;
break;
}
config_ruleinfo->lists = list_head;
} else {
smerror(log_msg, "List must have a correctly formatted field attribute");
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
/* xml_list eval is done */
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_url) == 0) {
rule_tmp_params.url = loadmemory(rule_tmp_params.url, rule_tmp_params.rule_arr_opt[k]->content, log_msg);
negate_url = w_check_attr_negate(rule_tmp_params.rule_arr_opt[k], config_ruleinfo->sigid, log_msg);
url_type = w_check_attr_type(rule_tmp_params.rule_arr_opt[k], EXP_TYPE_OSMATCH, config_ruleinfo->sigid, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_compiled) == 0) {
int it_id = 0;
while (compiled_rules_name[it_id]) {
if (strcmp(compiled_rules_name[it_id], rule_tmp_params.rule_arr_opt[k]->content) == 0) {
break;
}
it_id++;
}
/* Checking if the name is valid */
if (!compiled_rules_name[it_id]) {
smerror(log_msg, "Compiled rule not found: '%s'", rule_tmp_params.rule_arr_opt[k]->content);
smerror(log_msg, INVALID_CONFIG, rule_tmp_params.rule_arr_opt[k]->element, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
config_ruleinfo->compiled_rule = (void *(*)(void *)) compiled_rules_list[it_id];
if (!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) {
config_ruleinfo->alert_opts |= DO_EXTRAINFO;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_category) == 0) {
if (strcmp(rule_tmp_params.rule_arr_opt[k]->content, "firewall") == 0) {
config_ruleinfo->category = FIREWALL;
} else if (strcmp(rule_tmp_params.rule_arr_opt[k]->content, "ids") == 0) {
config_ruleinfo->category = IDS;
} else if (strcmp(rule_tmp_params.rule_arr_opt[k]->content, "syslog") == 0) {
config_ruleinfo->category = SYSLOG;
} else if (strcmp(rule_tmp_params.rule_arr_opt[k]->content, "web-log") == 0) {
config_ruleinfo->category = WEBLOG;
} else if (strcmp(rule_tmp_params.rule_arr_opt[k]->content, "squid") == 0) {
config_ruleinfo->category = SQUID;
} else if (strcmp(rule_tmp_params.rule_arr_opt[k]->content, "windows") == 0) {
config_ruleinfo->category = DECODER_WINDOWS;
} else if (strcmp(rule_tmp_params.rule_arr_opt[k]->content, "ossec") == 0) {
config_ruleinfo->category = OSSEC_RL;
} else {
merror(INVALID_CAT, rule_tmp_params.rule_arr_opt[k]->content);
goto cleanup;
}
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_if_sid) == 0) {
config_ruleinfo->if_sid =
loadmemory(config_ruleinfo->if_sid,
rule_tmp_params.rule_arr_opt[k]->content,
log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_if_level) == 0) {
if (!OS_StrIsNum(rule_tmp_params.rule_arr_opt[k]->content)) {
smwarn(log_msg, ANALYSISD_INV_IF_LEVEL,
rule_tmp_params.rule_arr_opt[k]->content,
config_ruleinfo->sigid);
do_skip_rule = true;
break;
}
config_ruleinfo->if_level =
loadmemory(config_ruleinfo->if_level,
rule_tmp_params.rule_arr_opt[k]->content,
log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_if_group) == 0) {
config_ruleinfo->if_group =
loadmemory(config_ruleinfo->if_group,
rule_tmp_params.rule_arr_opt[k]->content,
log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_if_matched_regex) == 0) {
config_ruleinfo->context = 1;
rule_tmp_params.if_matched_regex =
loadmemory(rule_tmp_params.if_matched_regex,
rule_tmp_params.rule_arr_opt[k]->content, log_msg);
} else if (strcasecmp(rule_tmp_params.rule_arr_opt[k]->element, xml_if_matched_group) == 0) {
config_ruleinfo->context = 1;
rule_tmp_params.if_matched_group =
loadmemory(rule_tmp_params.if_matched_group,
rule_tmp_params.rule_arr_opt[k]->content,
log_msg);