2015-11-24 18:43:33 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
# Copyright (c) 2015 Mozilla Corporation
|
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2018-10-17 01:33:58 +03:00
|
|
|
from mozdef_util.query_models import SearchQuery, TermMatch
|
2016-08-03 23:40:10 +03:00
|
|
|
|
2015-11-24 18:43:33 +03:00
|
|
|
|
|
|
|
class AlertGeomodel(AlertTask):
|
2016-06-22 22:09:58 +03:00
|
|
|
# The minimum event severity we will create an alert for
|
|
|
|
MINSEVERITY = 2
|
|
|
|
|
2015-11-24 18:43:33 +03:00
|
|
|
def main(self):
|
2017-12-06 00:41:43 +03:00
|
|
|
self.parse_config('geomodel.conf', ['exclusions', 'url'])
|
2017-12-05 20:27:24 +03:00
|
|
|
|
2016-08-03 23:40:10 +03:00
|
|
|
search_query = SearchQuery(minutes=30)
|
|
|
|
|
|
|
|
search_query.add_must([
|
2018-03-03 00:29:30 +03:00
|
|
|
TermMatch('category', 'geomodelnotice')
|
2016-08-03 23:40:10 +03:00
|
|
|
])
|
2015-11-24 18:43:33 +03:00
|
|
|
|
2017-12-05 20:27:24 +03:00
|
|
|
# Allow the ability to ignore certain users
|
|
|
|
for exclusion in self.config.exclusions.split(','):
|
|
|
|
search_query.add_must_not(TermMatch('summary', exclusion))
|
|
|
|
|
2016-08-03 23:40:10 +03:00
|
|
|
self.filtersManual(search_query)
|
2015-11-24 18:43:33 +03:00
|
|
|
self.searchEventsSimple()
|
|
|
|
self.walkEvents()
|
|
|
|
|
|
|
|
# Set alert properties
|
|
|
|
def onEvent(self, event):
|
|
|
|
category = 'geomodel'
|
|
|
|
tags = ['geomodel']
|
2017-04-20 18:17:58 +03:00
|
|
|
severity = 'NOTICE'
|
2016-06-22 22:09:58 +03:00
|
|
|
|
|
|
|
ev = event['_source']
|
|
|
|
|
|
|
|
# If the event severity is below what we want, just ignore
|
|
|
|
# the event.
|
|
|
|
if 'details' not in ev or 'severity' not in ev['details']:
|
|
|
|
return None
|
|
|
|
if ev['details']['severity'] < self.MINSEVERITY:
|
|
|
|
return None
|
2015-11-24 18:43:33 +03:00
|
|
|
|
2017-04-20 18:17:58 +03:00
|
|
|
# By default we assign a MozDef severity of NOTICE, but up this if the
|
|
|
|
# geomodel alert is sev 3
|
|
|
|
if ev['details']['severity'] == 3:
|
|
|
|
severity = 'WARNING'
|
|
|
|
|
2016-06-22 22:09:58 +03:00
|
|
|
summary = ev['summary']
|
2017-12-06 00:41:43 +03:00
|
|
|
alert_dict = self.createAlertDict(summary, category, tags, [event], severity, self.config.url)
|
2017-10-05 20:12:26 +03:00
|
|
|
|
2017-12-04 22:36:41 +03:00
|
|
|
if 'category' in ev['details'] and ev['details']['category'].lower() == 'newcountry':
|
|
|
|
alert_dict['details'] = {
|
2018-05-11 20:31:12 +03:00
|
|
|
'previous_locality_details': ev['details']['prev_locality_details'],
|
2017-12-04 22:36:41 +03:00
|
|
|
'locality_details': ev['details']['locality_details'],
|
|
|
|
'category': ev['details']['category'],
|
|
|
|
'principal': ev['details']['principal'],
|
|
|
|
'source_ip': ev['details']['source_ipv4']
|
|
|
|
}
|
2017-10-05 20:12:26 +03:00
|
|
|
|
|
|
|
return alert_dict
|