2018-05-02 01:08:49 +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
|
|
|
|
#
|
|
|
|
# This code alerts on every successfully opened session on any of the host from a given list
|
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
|
|
|
from query_models import SearchQuery, TermMatch, QueryStringMatch, PhraseMatch
|
|
|
|
|
|
|
|
|
2018-05-02 22:54:18 +03:00
|
|
|
class WriteAudit(AlertTask):
|
2018-05-02 01:08:49 +03:00
|
|
|
def main(self):
|
|
|
|
self.parse_config('write_audit.conf', ['skipprocess'])
|
2018-05-10 02:00:10 +03:00
|
|
|
search_query = SearchQuery(minutes=15)
|
2018-05-02 01:08:49 +03:00
|
|
|
|
|
|
|
search_query.add_must([
|
|
|
|
TermMatch('category', 'write'),
|
|
|
|
TermMatch('details.auditkey', 'audit'),
|
|
|
|
])
|
|
|
|
|
|
|
|
for processname in self.config.skipprocess.split():
|
|
|
|
search_query.add_must_not(PhraseMatch('details.processname', processname))
|
|
|
|
|
|
|
|
self.filtersManual(search_query)
|
|
|
|
self.searchEventsAggregated('details.originaluser', samplesLimit=10)
|
|
|
|
self.walkAggregations(threshold=2)
|
|
|
|
|
|
|
|
def onAggregation(self, aggreg):
|
|
|
|
category = 'write'
|
|
|
|
severity = 'WARNING'
|
|
|
|
tags = ['audit']
|
|
|
|
|
2018-05-02 01:14:10 +03:00
|
|
|
summary = ('{0} Filesystem write(s) to an auditd path by {1}'.format(aggreg['count'], aggreg['value'], ))
|
|
|
|
hostnames = self.mostCommon(aggreg['allevents'],'_source.hostname')
|
2018-05-02 01:08:49 +03:00
|
|
|
#did they modify more than one host?
|
|
|
|
#or just modify an existing configuration more than once?
|
|
|
|
if len(hostnames) > 1:
|
|
|
|
for i in hostnames[:5]:
|
|
|
|
summary += ' on {0} ({1} hosts)'.format(i[0], i[1])
|
|
|
|
|
|
|
|
return self.createAlertDict(summary, category, tags, aggreg['events'], severity)
|