2017-05-27 00:05:15 +03:00
|
|
|
# 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) 2017 Mozilla Corporation
|
2017-06-15 22:56:47 +03:00
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2016-08-19 23:40:51 +03:00
|
|
|
from query_models import SearchQuery, TermMatch, ExistsMatch, PhraseMatch
|
2016-08-03 23:40:10 +03:00
|
|
|
|
2017-06-15 22:56:47 +03:00
|
|
|
|
|
|
|
class AlertDuoAuthFail(AlertTask):
|
|
|
|
def main(self):
|
2017-05-27 00:05:15 +03:00
|
|
|
self.parse_config('duo_authfail.conf', ['url'])
|
2017-03-31 23:28:18 +03:00
|
|
|
search_query = SearchQuery(minutes=15)
|
2016-08-03 23:40:10 +03:00
|
|
|
|
|
|
|
search_query.add_must([
|
2016-08-19 22:50:16 +03:00
|
|
|
TermMatch('category', 'event'),
|
2017-03-30 22:50:08 +03:00
|
|
|
ExistsMatch('details.sourceipaddress'),
|
2016-08-19 22:53:16 +03:00
|
|
|
ExistsMatch('details.username'),
|
2018-03-03 00:29:30 +03:00
|
|
|
PhraseMatch('details.result', 'FRAUD')
|
2016-08-03 23:40:10 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
self.filtersManual(search_query)
|
2017-06-15 22:56:47 +03:00
|
|
|
self.searchEventsSimple()
|
|
|
|
self.walkEvents()
|
|
|
|
|
|
|
|
# Set alert properties
|
|
|
|
def onEvent(self, event):
|
2017-03-21 01:06:13 +03:00
|
|
|
category = 'duosecurity'
|
2017-03-31 01:00:49 +03:00
|
|
|
tags = ['duosecurity', 'duosecuritypagerduty']
|
2017-06-15 22:56:47 +03:00
|
|
|
severity = 'WARNING'
|
2017-05-27 00:05:15 +03:00
|
|
|
url = self.config.url
|
2017-06-15 22:56:47 +03:00
|
|
|
|
|
|
|
sourceipaddress = 'unknown'
|
|
|
|
user = 'unknown'
|
|
|
|
x = event['_source']
|
|
|
|
if 'details' in x:
|
2017-03-30 22:50:08 +03:00
|
|
|
if 'sourceipaddress' in x['details']:
|
|
|
|
sourceipaddress = x['details']['sourceipaddress']
|
2017-06-15 22:56:47 +03:00
|
|
|
if 'username' in x['details']:
|
|
|
|
user = x['details']['username']
|
|
|
|
|
|
|
|
summary = 'Duo Authentication Failure: user {1} rejected and marked a Duo Authentication attempt from {0} as fraud'.format(sourceipaddress, user)
|
|
|
|
|
|
|
|
# Create the alert object based on these properties
|
2017-03-30 22:50:08 +03:00
|
|
|
return self.createAlertDict(summary, category, tags, [event], severity, url)
|