2017-06-15 22:56:47 +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:
|
|
|
|
# Jonathan Claudius jclaudius@mozilla.com
|
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2016-08-19 23:40:51 +03:00
|
|
|
from query_models import SearchQuery, TermMatch, QueryStringMatch
|
2016-08-03 23:40:10 +03:00
|
|
|
|
2017-06-15 22:56:47 +03:00
|
|
|
|
|
|
|
class AlertConfluenceShellUsage(AlertTask):
|
|
|
|
def main(self):
|
|
|
|
# look for events in last X mins
|
2016-08-03 23:40:10 +03:00
|
|
|
search_query = SearchQuery(minutes=5)
|
|
|
|
|
|
|
|
search_query.add_must([
|
2016-08-19 22:50:16 +03:00
|
|
|
TermMatch('_type', 'auditd'),
|
|
|
|
TermMatch('details.user', 'confluence'),
|
2017-01-12 01:17:07 +03:00
|
|
|
QueryStringMatch('hostname: /.*(mana|confluence).*/'),
|
2016-08-03 23:40:10 +03:00
|
|
|
])
|
|
|
|
|
2016-08-19 22:50:16 +03:00
|
|
|
search_query.add_must_not(TermMatch('details.originaluser', 'root'))
|
2016-08-03 23:40:10 +03:00
|
|
|
|
|
|
|
self.filtersManual(search_query)
|
|
|
|
|
|
|
|
# Search aggregations on field 'sourceipaddress', keep X samples of
|
|
|
|
# events at most
|
2017-01-12 01:17:07 +03:00
|
|
|
self.searchEventsAggregated('hostname', samplesLimit=10)
|
2017-06-15 22:56:47 +03:00
|
|
|
# alert when >= X matching events in an aggregation
|
|
|
|
# in this case, always
|
|
|
|
self.walkAggregations(threshold=1)
|
|
|
|
|
|
|
|
# Set alert properties
|
|
|
|
def onAggregation(self, aggreg):
|
|
|
|
# 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 = 'intrusion'
|
|
|
|
tags = ['confluence', 'mana']
|
|
|
|
severity = 'CRITICAL'
|
|
|
|
|
2016-10-18 21:43:41 +03:00
|
|
|
summary = 'Confluence user is running shell commands on {0}'.format(aggreg['value'])
|
2017-06-15 22:56:47 +03:00
|
|
|
|
|
|
|
# Create the alert object based on these properties
|
|
|
|
return self.createAlertDict(summary, category, tags, aggreg['events'], severity)
|