Skip to content

Commit

Permalink
#531 Close Zerofox Alert
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed Sep 11, 2019
1 parent a9de814 commit b50de48
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
29 changes: 29 additions & 0 deletions responders/ZEROFOX_Close_alert/ZEROFOX_Close_alert.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "ZEROFOX_Close_alert",
"version": "1.0",
"author": "TheHive-Project",
"url": "https://github.com/TheHive-Project/Cortex-Analyzers",
"license": "AGPL-V3",
"description": "Close alert in Zerofox",
"dataTypeList": ["thehive:case"],
"command": "ZEROFOX_Close_alert/ZEROFOX_Close_alert.py",
"baseConfig": "ZEROFOX_Close_alert",
"configurationItems": [
{
"name": "url",
"description": "URL for Zerofox API",
"type": "string",
"multi": false,
"required": true,
"defaultValue": "https://api.zerofox.com/1.0"
},
{
"name": "api",
"description": "Key API for Zerofox",
"type": "string",
"multi": false,
"required": true,
"defaultValue": ""
}
]
}
60 changes: 60 additions & 0 deletions responders/ZEROFOX_Close_alert/ZEROFOX_Close_alert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
# encoding: utf-8


from cortexutils.responder import Responder
import re
import requests


class CloseAlert(Responder):
def __init__(self):
Responder.__init__(self)
self.data = self.get_param('data', None, 'Data is missing')
self.url = self.get_param('config.url', None, 'url is missing')
self.api = self.get_param('config.api', None, 'api key is missing')

# Action for Zerofox Alert : see "POST /alerts/{alert_id}/{action}/" on https://api.zerofox.com/1.0/docs/
self.zfEntity = "alerts"
self.zfAction = "close"


def operations(self, raw):
return [self.build_operation('AddTagToCase', tag='TheHive:Responders=Zerofox Alert Closed')]

def ZerofoxAlert(self, tags):
"""
:param tags: list
:return: bool
"""
zfalert="src:ZEROFOX"
if tags:
for tag in tags:
zf_id = re.match("^ZF:Id=(\d+)", tag)
if zf_id and zfalert in tags:
return zf_id.group(1)
return 0


def run(self):
Responder.run(self)
tags = self.get_param('data.tags', None)
action_request = "{}/{}/{}/{}/".format(self.url, self.zfEntity, self.ZerofoxAlert(tags), self.zfAction)


# Manage mail addresses
if self.data_type == 'thehive:case':
if self.ZerofoxAlert(tags):
try:
response = requests.post(action_request, headers={'Authorization':
'Token {}'.format(self.api)})
if response.status_code == 200:
self.report({'message': 'Alert {} has been closed'.format(self.ZerofoxAlert(tags))})
elif response.status_code == 400:
self.error('HTTP 400 : Request body schema error')
except Exception as ex:
self.error(ex)

if __name__ == '__main__':
CloseAlert().run()
1 change: 1 addition & 0 deletions responders/ZEROFOX_Close_alert/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit b50de48

Please sign in to comment.