2016-04-03 02:04: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
|
2019-08-02 02:41:37 +03:00
|
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-04-03 02:04:32 +03:00
|
|
|
# Copyright (c) 2014 Mozilla Corporation
|
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2020-06-24 18:41:08 +03:00
|
|
|
from mozdef_util.query_models import\
|
|
|
|
PhraseMatch,\
|
|
|
|
SearchQuery,\
|
|
|
|
TermMatch,\
|
|
|
|
WildcardMatch
|
2016-08-03 23:40:10 +03:00
|
|
|
|
2016-04-03 02:04:32 +03:00
|
|
|
|
|
|
|
class ldapGroupModify(AlertTask):
|
|
|
|
def main(self):
|
2016-08-03 23:40:10 +03:00
|
|
|
search_query = SearchQuery(minutes=15)
|
|
|
|
|
|
|
|
search_query.add_must([
|
2016-08-19 22:50:16 +03:00
|
|
|
TermMatch('category', 'ldapChange'),
|
2017-01-12 01:03:29 +03:00
|
|
|
TermMatch('details.changetype', 'modify'),
|
2016-10-18 21:43:41 +03:00
|
|
|
PhraseMatch("summary", "groups")
|
2016-08-03 23:40:10 +03:00
|
|
|
])
|
2016-04-03 02:04:32 +03:00
|
|
|
|
2020-04-23 23:07:36 +03:00
|
|
|
# ignore test accounts and attempts to create accounts that already exist.
|
|
|
|
search_query.add_must_not([
|
|
|
|
WildcardMatch('details.actor', '*bind*'),
|
2020-06-24 18:41:08 +03:00
|
|
|
WildcardMatch('details.changepairs', 'delete:*member*')
|
2020-04-23 23:07:36 +03:00
|
|
|
])
|
|
|
|
|
2016-08-03 23:40:10 +03:00
|
|
|
self.filtersManual(search_query)
|
2020-06-24 18:41:08 +03:00
|
|
|
self.searchEventsAggregated('details.email', samplesLimit=50)
|
|
|
|
self.walkAggregations(threshold=1, config={})
|
2016-04-03 02:04:32 +03:00
|
|
|
|
|
|
|
# Set alert properties
|
2020-06-24 18:41:08 +03:00
|
|
|
def onAggregation(self, agg):
|
|
|
|
email = agg['value']
|
|
|
|
events = agg['events']
|
|
|
|
|
2016-04-03 02:04:32 +03:00
|
|
|
category = 'ldap'
|
|
|
|
tags = ['ldap']
|
|
|
|
severity = 'INFO'
|
2020-06-24 18:41:08 +03:00
|
|
|
|
|
|
|
if email is None:
|
|
|
|
summary = 'LDAP group change detected'
|
|
|
|
else:
|
|
|
|
summary = 'LDAP group change initiated by {0}'.format(email)
|
2016-04-03 02:04:32 +03:00
|
|
|
|
|
|
|
# Create the alert object based on these properties
|
2020-06-24 18:41:08 +03:00
|
|
|
return self.createAlertDict(summary, category, tags, events, severity)
|