2015-02-26 21:42:51 +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/.
|
2017-05-27 00:05:15 +03:00
|
|
|
# Copyright (c) 2017 Mozilla Corporation
|
2015-02-26 21:42:51 +03:00
|
|
|
|
|
|
|
from lib.alerttask import AlertTask
|
2018-12-14 20:34:42 +03:00
|
|
|
from mozdef_util.query_models import SearchQuery, TermMatch, PhraseMatch
|
2016-08-03 23:40:10 +03:00
|
|
|
|
2015-02-26 21:42:51 +03:00
|
|
|
|
|
|
|
class AlertSSHManyConns(AlertTask):
|
|
|
|
def main(self):
|
2017-08-25 20:17:53 +03:00
|
|
|
self.parse_config('ssh_bruteforce_bro.conf', ['url'])
|
2017-05-27 00:05:15 +03:00
|
|
|
|
2016-08-03 23:40:10 +03:00
|
|
|
search_query = SearchQuery(minutes=15)
|
|
|
|
|
|
|
|
search_query.add_must([
|
2017-10-21 01:31:18 +03:00
|
|
|
TermMatch('category', 'bro'),
|
|
|
|
TermMatch('source', 'notice'),
|
2018-03-03 00:29:30 +03:00
|
|
|
PhraseMatch('details.note', 'SSH::Password_Guessing')
|
2016-08-03 23:40:10 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
self.filtersManual(search_query)
|
2015-02-26 21:42:51 +03:00
|
|
|
|
|
|
|
# Search events
|
|
|
|
self.searchEventsSimple()
|
|
|
|
self.walkEvents()
|
|
|
|
|
|
|
|
# Set alert properties
|
|
|
|
def onEvent(self, event):
|
|
|
|
category = 'bruteforce'
|
|
|
|
tags = ['http']
|
|
|
|
severity = 'NOTICE'
|
|
|
|
hostname = event['_source']['hostname']
|
2017-05-27 00:05:15 +03:00
|
|
|
url = self.config.url
|
2015-02-26 21:42:51 +03:00
|
|
|
|
|
|
|
# the summary of the alert is the same as the event
|
|
|
|
summary = '{0} {1}'.format(hostname, event['_source']['summary'])
|
|
|
|
|
|
|
|
# Create the alert object based on these properties
|
2015-03-26 02:52:19 +03:00
|
|
|
return self.createAlertDict(summary, category, tags, [event], severity=severity, url=url)
|