2015-01-23 03:39:32 +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) 2014 Mozilla Corporation
|
|
|
|
#
|
|
|
|
# Contributors:
|
|
|
|
# kang@mozilla.com
|
|
|
|
#
|
|
|
|
# This script alerts when openvpn's duo security failed to contact the duo server and let the user in.
|
|
|
|
# This is a very serious warning that must be acted upon as it means MFA failed and only one factor was validated (in
|
|
|
|
# this case a VPN certificate)
|
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2016-08-19 22:13:53 +03:00
|
|
|
from query_models import SearchQuery, PhraseMatch
|
2016-07-29 23:09:13 +03:00
|
|
|
|
2015-01-23 03:39:32 +03:00
|
|
|
|
|
|
|
class AlertDuoFailOpen(AlertTask):
|
|
|
|
def main(self):
|
2016-07-29 23:09:13 +03:00
|
|
|
search_query = SearchQuery(minutes=15)
|
|
|
|
|
2016-08-19 22:13:53 +03:00
|
|
|
search_query.add_must(PhraseMatch('summary', 'Failsafe Duo login'))
|
2016-07-29 23:09:13 +03:00
|
|
|
|
|
|
|
self.filtersManual(search_query)
|
2015-01-23 03:39:32 +03:00
|
|
|
|
2016-08-03 23:40:10 +03:00
|
|
|
# Search aggregations on field 'sourceipaddress', keep X samples of
|
|
|
|
# events at most
|
2015-05-27 23:23:42 +03:00
|
|
|
self.searchEventsAggregated('details.hostname', samplesLimit=10)
|
2015-01-23 03:39:32 +03:00
|
|
|
# alert when >= X matching events in an aggregation
|
|
|
|
# in this case, always
|
|
|
|
self.walkAggregations(threshold=1)
|
|
|
|
|
|
|
|
# Set alert properties
|
2015-05-27 23:23:42 +03:00
|
|
|
def onAggregation(self, aggreg):
|
2015-01-23 03:39:32 +03:00
|
|
|
# aggreg['count']: number of items in the aggregation, ex: number of failed login attempts
|
|
|
|
# aggreg['value']: value of the aggregation field, ex: toto@example.com
|
|
|
|
# aggreg['events']: list of events in the aggregation
|
|
|
|
category = 'bypass'
|
|
|
|
tags = ['openvpn', 'duosecurity']
|
|
|
|
severity = 'WARNING'
|
|
|
|
|
2016-10-18 21:43:41 +03:00
|
|
|
summary = 'DuoSecurity contact failed, fail open triggered on {0}'.format(aggreg['value'])
|
2015-01-23 03:39:32 +03:00
|
|
|
|
|
|
|
# Create the alert object based on these properties
|
|
|
|
return self.createAlertDict(summary, category, tags, aggreg['events'], severity)
|