Skip to content

Commit 7d3bac3

Browse files
authored
Merge pull request #929 from atomicturtle/geoip-v26
Modify rule token different_geoip rule to different_srcgeoip
2 parents d39ed86 + ed3efbc commit 7d3bac3

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

src/analysisd/analysisd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ int main_analysisd(int argc, char **argv)
235235
geoipdb = GeoIP_open(Config.geoipdb_file, GEOIP_INDEX_CACHE);
236236
if (geoipdb == NULL)
237237
{
238-
merror("%s: Unable to open GeoIP database from: %s (disabling GeoIP).", ARGV0, Config.geoipdb_file);
238+
merror("%s: ERROR: Unable to open GeoIP database from: %s (disabling GeoIP).", ARGV0, Config.geoipdb_file);
239239
}
240240
}
241241
#endif

src/analysisd/decoders/geoip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ char *GetGeoInfobyIP(char *ip_addr)
4747
return(NULL);
4848
}
4949

50-
if(geoiprecord->country_code == NULL || geoiprecord->country_code == NULL)
50+
if(geoiprecord->country_code == NULL)
5151
{
5252
GeoIPRecord_delete(geoiprecord);
5353
return(NULL);

src/analysisd/eventinfo.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ Eventinfo *Search_LastSids(Eventinfo *my_lf, RuleInfo *rule)
135135
}
136136
}
137137

138+
/* GEOIP version of check for repetitions from same src_ip */
139+
if (rule->context_opts & DIFFERENT_SRCGEOIP) {
140+
if ((!lf->srcgeoip) || (!my_lf->srcgeoip)) {
141+
continue;
142+
}
143+
144+
if (strcmp(lf->srcgeoip, my_lf->srcgeoip) == 0) {
145+
continue;
146+
}
147+
}
148+
138149
/* Check if the number of matches worked */
139150
if (rule->__frequency <= 10) {
140151
rule->last_events[rule->__frequency]
@@ -404,6 +415,8 @@ Eventinfo *Search_LastEvents(Eventinfo *my_lf, RuleInfo *rule)
404415
}
405416

406417

418+
419+
407420
/* Check if the number of matches worked */
408421
if (rule->__frequency < rule->frequency) {
409422
if (rule->__frequency <= 10) {

src/analysisd/rules.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int Rules_OP_ReadRules(const char *rulefile)
112112

113113
const char *xml_different_url = "different_url";
114114
const char *xml_different_srcip = "different_srcip";
115-
const char *xml_different_geoip = "different_geoip";
115+
const char *xml_different_srcgeoip = "different_srcgeoip";
116116

117117
const char *xml_notsame_source_ip = "not_same_source_ip";
118118
const char *xml_notsame_user = "not_same_user";
@@ -825,8 +825,8 @@ int Rules_OP_ReadRules(const char *rulefile)
825825
if(!(config_ruleinfo->alert_opts & SAME_EXTRAINFO))
826826
config_ruleinfo->alert_opts |= SAME_EXTRAINFO;
827827
} else if(strcmp(rule_opt[k]->element,
828-
xml_different_geoip) == 0) {
829-
config_ruleinfo->context_opts|= DIFFERENT_GEOIP;
828+
xml_different_srcgeoip) == 0) {
829+
config_ruleinfo->context_opts|= DIFFERENT_SRCGEOIP;
830830

831831
if(!(config_ruleinfo->alert_opts & SAME_EXTRAINFO))
832832
config_ruleinfo->alert_opts |= SAME_EXTRAINFO;
@@ -1228,6 +1228,10 @@ int Rules_OP_ReadRules(const char *rulefile)
12281228

12291229
/* Mark rules that match this id */
12301230
OS_MarkID(NULL, config_ruleinfo);
1231+
1232+
/* Set function pointer */
1233+
config_ruleinfo->event_search = (void *(*)(void *, void *))
1234+
Search_LastEvents;
12311235
}
12321236

12331237
/* Mark the rules that match if_matched_group */

src/analysisd/rules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define SAME_LOCATION 0x008 /* 8 */
2626
#define DIFFERENT_URL 0x010 /* */
2727
#define DIFFERENT_SRCIP 0x200
28-
#define DIFFERENT_GEOIP 0x400
28+
#define DIFFERENT_SRCGEOIP 0x400
2929
#define SAME_SRCPORT 0x020
3030
#define SAME_DSTPORT 0x040
3131
#define SAME_DODIFF 0x100

src/headers/rules_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define SAME_LOCATION 0x008 /* 8 */
2222
#define DIFFERENT_URL 0x010
2323
#define DIFFERENT_SRCIP 0x200
24-
#define DIFFERENT_GEOIP 0x400
24+
#define DIFFERENT_SRCGEOIP 0x400
2525
#define SAME_SRCPORT 0x020
2626
#define SAME_DSTPORT 0x040
2727
#define SAME_DODIFF 0x100

0 commit comments

Comments
 (0)