-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9de814
commit b50de48
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|