This commit is contained in:
Brandon Myers 2020-07-06 12:57:02 -05:00 коммит произвёл GitHub
Родитель 2788729e2c
Коммит b9fc856c04
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 33 добавлений и 33 удалений

Просмотреть файл

@ -251,15 +251,15 @@ class AlertTask(Task):
def tagBotNotify(self, alert): def tagBotNotify(self, alert):
""" """
Tag alert to be excluded based on severity Tag alert to be excluded based on severity
If 'ircchannel' is set in an alert, we automatically notify mozdefbot If 'channel' is set in an alert, we automatically set notify_mozdefbot to True
""" """
alert["notify_mozdefbot"] = True alert["notify_mozdefbot"] = True
if alert["severity"] == "NOTICE" or alert["severity"] == "INFO": if alert["severity"] == "NOTICE" or alert["severity"] == "INFO":
alert["notify_mozdefbot"] = False alert["notify_mozdefbot"] = False
# If an alert sets specific ircchannel, then we should probably always notify in mozdefbot # If an alert sets specific channel, then we should probably always notify in mozdefbot
if ( if (
"ircchannel" in alert and alert["ircchannel"] != "" and alert["ircchannel"] is not None "channel" in alert and alert["channel"] != "" and alert["channel"] is not None
): ):
alert["notify_mozdefbot"] = True alert["notify_mozdefbot"] = True
return alert return alert
@ -426,7 +426,7 @@ class AlertTask(Task):
events, events,
severity="NOTICE", severity="NOTICE",
url=None, url=None,
ircchannel=None, channel=None,
): ):
""" """
Create an alert dict Create an alert dict
@ -446,7 +446,7 @@ class AlertTask(Task):
"category": category, "category": category,
"tags": tags, "tags": tags,
"events": [], "events": [],
"ircchannel": ircchannel, "channel": channel,
"status": DEFAULT_STATUS, "status": DEFAULT_STATUS,
"classname": classname "classname": classname
} }

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"hostfilter": "(host1|host2.*).*", "hostfilter": "(host1|host2.*).*",
"ircchannel": "#somechannel", "channel": "#somechannel",
"exclusions": [ "exclusions": [
{"summary":"someuser", "details.sourceipaddress": "4.5.6.7"}, {"summary":"someuser", "details.sourceipaddress": "4.5.6.7"},
{"summary":"anotheruser", "details.sourceipaddress": "8.9.10.11"} {"summary":"anotheruser", "details.sourceipaddress": "8.9.10.11"}

Просмотреть файл

@ -16,8 +16,8 @@ class AlertAuthSignRelengSSH(AlertTask):
self.config = self.parse_json_alert_config('ssh_access_signreleng.json') self.config = self.parse_json_alert_config('ssh_access_signreleng.json')
if self.config['ircchannel'] == '': if self.config['channel'] == '':
self.config['ircchannel'] = None self.config['channel'] = None
search_query.add_must([ search_query.add_must([
TermMatch('tags', 'releng'), TermMatch('tags', 'releng'),
@ -62,4 +62,4 @@ class AlertAuthSignRelengSSH(AlertTask):
targetuser = found_usernames[0] targetuser = found_usernames[0]
summary = 'SSH login from {0} on {1} as user {2}'.format(sourceipaddress, targethost, targetuser) summary = 'SSH login from {0} on {1} as user {2}'.format(sourceipaddress, targethost, targetuser)
return self.createAlertDict(summary, category, tags, [event], severity, ircchannel=self.config['ircchannel']) return self.createAlertDict(summary, category, tags, [event], severity, channel=self.config['channel'])

Просмотреть файл

@ -315,10 +315,10 @@ class alertConsumer(ConsumerMixin):
# process valid message # process valid message
# see where we send this alert # see where we send this alert
ircchannel = options.alertircchannel channel = options.alertchannel
if 'ircchannel' in body_dict: if 'channel' in body_dict:
if body_dict['ircchannel'] in options.join.split(","): if body_dict['channel'] in options.join.split(","):
ircchannel = body_dict['ircchannel'] channel = body_dict['channel']
# see if we need to delay a bit before sending the alert, to avoid # see if we need to delay a bit before sending the alert, to avoid
# flooding the channel # flooding the channel
@ -333,7 +333,7 @@ class alertConsumer(ConsumerMixin):
sys.stdout.write('alert is more than 450 bytes, truncating\n') sys.stdout.write('alert is more than 450 bytes, truncating\n')
body_dict['summary'] = body_dict['summary'][:450] + ' truncated...' body_dict['summary'] = body_dict['summary'][:450] + ' truncated...'
self.ircBot.client.msg(ircchannel, formatAlert(body_dict)) self.ircBot.client.msg(channel, formatAlert(body_dict))
message.ack() message.ack()
except ValueError as e: except ValueError as e:
@ -395,8 +395,8 @@ def initConfig():
channels.append(channel) channels.append(channel)
options.join = ','.join(channels) options.join = ','.join(channels)
options.alertircchannel = getConfig( options.alertchannel = getConfig(
'alertircchannel', 'alertchannel',
'', '',
options.configfile) options.configfile)
@ -446,8 +446,8 @@ def initConfig():
# mqack=True sets persistant delivery, False sets transient delivery # mqack=True sets persistant delivery, False sets transient delivery
options.mqack = getConfig('mqack', True, options.configfile) options.mqack = getConfig('mqack', True, options.configfile)
if options.alertircchannel == '': if options.alertchannel == '':
options.alertircchannel = options.join.split(",")[0] options.alertchannel = options.join.split(",")[0]
if __name__ == "__main__": if __name__ == "__main__":

Просмотреть файл

@ -73,9 +73,9 @@ class AlertConsumer(ConsumerMixin):
# process valid message # process valid message
# see where we send this alert # see where we send this alert
channel = options.default_alert_channel channel = options.default_alert_channel
if 'ircchannel' in body_dict: if 'channel' in body_dict:
if body_dict['ircchannel'] in options.channels: if body_dict['channel'] in options.channels:
channel = body_dict['ircchannel'] channel = body_dict['channel']
# see if we need to delay a bit before sending the alert, to avoid # see if we need to delay a bit before sending the alert, to avoid
# flooding the channel # flooding the channel

Просмотреть файл

@ -47,7 +47,7 @@ def _ssh_sensitive_host_alert():
"documentid": "X8-tOG4B-YuPuGRRXQta", "documentid": "X8-tOG4B-YuPuGRRXQta",
} }
], ],
"ircchannel": None, "channel": None,
"url": "website.com", "url": "website.com",
"notify_mozdefbot": True, "notify_mozdefbot": True,
"details": {"sites": []}, "details": {"sites": []},
@ -116,7 +116,7 @@ def _duo_bypass_code_gen_alert():
"documentid": "wPPKOG4B-YuPuGRRc2s7", "documentid": "wPPKOG4B-YuPuGRRc2s7",
} }
], ],
"ircchannel": None, "channel": None,
"url": "website.com", "url": "website.com",
"notify_mozdefbot": False, "notify_mozdefbot": False,
"details": {"sites": []}, "details": {"sites": []},
@ -191,7 +191,7 @@ def _duo_bypass_code_used_alert():
"documentid": "8iMaT3vSO0ddbCe7eaNQ", "documentid": "8iMaT3vSO0ddbCe7eaNQ",
} }
], ],
"ircchannel": None, "channel": None,
"url": "website.com", "url": "website.com",
"notify_mozdefbot": False, "notify_mozdefbot": False,
"details": {"sites": []}, "details": {"sites": []},
@ -269,7 +269,7 @@ def _ssh_access_releng_alert():
"documentid": "hsudfg92123ASDf234rm", "documentid": "hsudfg92123ASDf234rm",
} }
], ],
"ircchannel": "infosec-releng-alerts", "channel": "infosec-releng-alerts",
"notify_mozdefbot": True, "notify_mozdefbot": True,
"details": { "details": {
"sourceipv4address": "4.3.2.1", "sourceipv4address": "4.3.2.1",

Просмотреть файл

@ -166,7 +166,7 @@ class AlertTestSuite(UnitTestSuite):
assert '_index' in document assert '_index' in document
alert_body = document['_source'] alert_body = document['_source']
assert alert_body['notify_mozdefbot'] is test_case.expected_alert['notify_mozdefbot'], 'Alert from rabbitmq has bad notify_mozdefbot field' assert alert_body['notify_mozdefbot'] is test_case.expected_alert['notify_mozdefbot'], 'Alert from rabbitmq has bad notify_mozdefbot field'
assert alert_body['ircchannel'] == test_case.expected_alert['ircchannel'], 'Alert from rabbitmq has bad ircchannel field' assert alert_body['channel'] == test_case.expected_alert['channel'], 'Alert from rabbitmq has bad channel field'
assert alert_body['summary'] == found_alert['_source']['summary'], 'Alert from rabbitmq has bad summary field' assert alert_body['summary'] == found_alert['_source']['summary'], 'Alert from rabbitmq has bad summary field'
assert alert_body['utctimestamp'] == found_alert['_source']['utctimestamp'], 'Alert from rabbitmq has bad utctimestamp field' assert alert_body['utctimestamp'] == found_alert['_source']['utctimestamp'], 'Alert from rabbitmq has bad utctimestamp field'
assert alert_body['category'] == found_alert['_source']['category'], 'Alert from rabbitmq has bad category field' assert alert_body['category'] == found_alert['_source']['category'], 'Alert from rabbitmq has bad category field'
@ -209,17 +209,17 @@ class AlertTestSuite(UnitTestSuite):
# Verify there is a utctimestamp field # Verify there is a utctimestamp field
assert 'utctimestamp' in found_alert['_source'], 'Alert does not have utctimestamp specified' assert 'utctimestamp' in found_alert['_source'], 'Alert does not have utctimestamp specified'
if 'ircchannel' not in test_case.expected_alert: if 'channel' not in test_case.expected_alert:
test_case.expected_alert['ircchannel'] = None test_case.expected_alert['channel'] = None
# Verify notify_mozdefbot is set correctly based on severity # Verify notify_mozdefbot is set correctly based on severity
expected_notify_mozdefbot = True expected_notify_mozdefbot = True
if (test_case.expected_alert['severity'] == 'NOTICE' or test_case.expected_alert['severity'] == 'INFO') and test_case.expected_alert['ircchannel'] is None: if (test_case.expected_alert['severity'] == 'NOTICE' or test_case.expected_alert['severity'] == 'INFO') and test_case.expected_alert['channel'] is None:
expected_notify_mozdefbot = False expected_notify_mozdefbot = False
test_case.expected_alert['notify_mozdefbot'] = expected_notify_mozdefbot test_case.expected_alert['notify_mozdefbot'] = expected_notify_mozdefbot
# Verify ircchannel is set correctly # Verify channel is set correctly
assert found_alert['_source']['ircchannel'] == test_case.expected_alert['ircchannel'], 'Alert ircchannel field is bad' assert found_alert['_source']['channel'] == test_case.expected_alert['channel'], 'Alert channel field is bad'
# Verify classname is set correctly # Verify classname is set correctly
assert found_alert['_source']['classname'] == self.alert_classname, 'Alert classname field is bad' assert found_alert['_source']['classname'] == self.alert_classname, 'Alert classname field is bad'

Просмотреть файл

@ -28,7 +28,7 @@ class TestAlertSSHAccessSignReleng(AlertTestSuite):
"severity": "NOTICE", "severity": "NOTICE",
"summary": "SSH login from 1.2.3.4 on host1 as user ttesterson", "summary": "SSH login from 1.2.3.4 on host1 as user ttesterson",
"tags": ['ssh'], "tags": ['ssh'],
'ircchannel': '#somechannel', 'channel': '#somechannel',
} }
test_cases = [] test_cases = []

Просмотреть файл

@ -407,7 +407,7 @@ TEST_ALERT = {
"documentid": "Jd7Ro3EBh9xp2NOItEXH", "documentid": "Jd7Ro3EBh9xp2NOItEXH",
}, },
], ],
"ircchannel": None, "channel": None,
"status": "manual", "status": "manual",
"classname": "AlertGeoModel", "classname": "AlertGeoModel",
"details": { "details": {