-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add responder functionality to TheHive4Py #108
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eed8689
Add customFields to Alert
zpriddy b4764a3
Merge pull request #1 from TheHive-Project/master
zpriddy 66b45be
Add functions for responders from thehive4py
zpriddy 33cb822
Fix Errors
zpriddy 6166c00
Fix Errors
zpriddy c0b384c
Merge remote-tracking branch 'origin/run_analyzer' into run_analyzer
zpriddy 9ddc8b6
Update api.py
zpriddy bf68377
Update api.py
zpriddy 9b6f635
Update api.py
zpriddy 6aa1847
Merge branch 'master' into run_analyzer
zpriddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -115,7 +115,7 @@ def update_case(self, case, fields=[]): | |
# Choose which attributes to send | ||
update_keys = [ | ||
'title', 'description', 'severity', 'startDate', 'owner', 'flag', 'tlp', 'tags', 'status', 'resolutionStatus', | ||
'impactStatus', 'summary', 'endDate', 'metrics', 'customFields' | ||
'impactStatus', 'summary', 'endDate', 'metrics', 'customFields', 'artifacts' | ||
] | ||
data = {k: v for k, v in case.__dict__.items() if (len(fields) > 0 and k in fields) or (len(fields) == 0 and k in update_keys)} | ||
try: | ||
|
@@ -415,7 +415,7 @@ def update_alert(self, alert_id, alert, fields=[]): | |
req = self.url + "/api/alert/{}".format(alert_id) | ||
|
||
# update only the alert attributes that are not read-only | ||
update_keys = ['tlp', 'severity', 'tags', 'caseTemplate', 'title', 'description'] | ||
update_keys = ['tlp', 'severity', 'tags', 'caseTemplate', 'title', 'description', 'customFields', 'artifacts'] | ||
|
||
data = {k: v for k, v in alert.__dict__.items() if | ||
(len(fields) > 0 and k in fields) or (len(fields) == 0 and k in update_keys)} | ||
|
@@ -489,6 +489,88 @@ def run_analyzer(self, cortex_id, artifact_id, analyzer_id): | |
except requests.exceptions.RequestException as e: | ||
raise TheHiveException("Analyzer run error: {}".format(e)) | ||
|
||
def run_responder(self, object_id, object_type, responder_name=None, responder_id=None): | ||
|
||
""" | ||
Run a responder by name or id. Must have either name or ID provided. | ||
:param object_id: identifier of the object to run the responder on | ||
:param object_type: type of the object the responder is running on | ||
:param responder_name: Name of the responder to run (optional) | ||
:param responder_id: identifier of the Cortex responder (optional) | ||
:rtype: json | ||
""" | ||
if not responder_id and not responder_name: | ||
raise TheHiveException("Responder run error: No responder ID or Name provided") | ||
|
||
data = { | ||
"objectType": object_type, | ||
"objectId": object_id | ||
} | ||
|
||
if responder_name: | ||
if not self.verify_responder_name(responder_name): | ||
resp_id = self.search_responder_by_name(responder_name) | ||
if resp_id: | ||
data['responderId'] = resp_id | ||
else: | ||
data['responderName'] = responder_name | ||
else: | ||
data['responderId'] = responder_id | ||
|
||
req = self.url + "/api/connector/cortex/action" | ||
|
||
try: | ||
return requests.post(req, headers={'Content-Type': 'application/json'}, json=data, proxies=self.proxies, | ||
auth=self.auth, verify=self.cert) | ||
except requests.exceptions.RequestException as e: | ||
raise TheHiveException("Responder run error: {}".format(e)) | ||
|
||
def verify_responder_name(self, responder_name): | ||
""" | ||
Verify the responder name. | ||
:param responder_name: Cortex responder name | ||
:return: bool | ||
""" | ||
data = { | ||
"query": { | ||
"name": responder_name | ||
} | ||
} | ||
|
||
req = self.url + "/api/connector/cortex/responder/_search" | ||
try: | ||
responder_list = requests.post(req, headers={'Content-Type': 'application/json'}, json=data, | ||
proxies=self.proxies, | ||
auth=self.auth, verify=self.cert).json() | ||
if len(responder_list) == 1: | ||
return True | ||
return False | ||
except requests.exceptions.RequestException as e: | ||
raise TheHiveException("Responder verify error: {}".format(e)) | ||
|
||
def search_responder_by_name(self, responder_name): | ||
""" | ||
Find a responder by short name (without version) | ||
:param responder_name: Cortex responder name | ||
:return: str | ||
""" | ||
data = { | ||
"query": { | ||
"_string": responder_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
} | ||
|
||
req = self.url + "/api/connector/cortex/responder/_search" | ||
try: | ||
responder_list = requests.post(req, headers={'Content-Type': 'application/json'}, json=data, | ||
proxies=self.proxies, | ||
auth=self.auth, verify=self.cert).json() | ||
if len(responder_list) == 1: | ||
return responder_list[0].get('id') | ||
return None | ||
except requests.exceptions.RequestException as e: | ||
raise TheHiveException("Responder verify error: {}".format(e)) | ||
|
||
def find_tasks(self, **attributes): | ||
""" | ||
:return: list of Tasks | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of all this
if
statement?