Skip to content
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

[IntezerCommunity] Added support for hash (sha256) type #1029

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analyzers/IntezerCommunity/IntezerCommunity.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://github.com/TheHive-Project/Cortex-Analyzers",
"license": "AGPL-v3",
"description": "Analyze a possible malicious file with Intezer Analyzer",
"dataTypeList": ["file"],
"dataTypeList": ["file", "hash"],
"baseConfig": "IntezerCommunity",
"command": "IntezerCommunity/intezer_community.py",
"configurationItems": [
Expand Down
25 changes: 23 additions & 2 deletions analyzers/IntezerCommunity/intezer_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ class IntezerCommunityAnalyzer(Analyzer):
"""

def run(self):

base_url = 'https://analyze.intezer.com/api/v2-0'
try:

if self.data_type == 'file':
api_key = self.get_param('config.key', None, 'Missing Intezer API key')
filepath = self.get_param('file', None, 'File is missing')
filename = self.get_param('filename', os.path.basename(filepath))

base_url = 'https://analyze.intezer.com/api/v2-0'
# this should be done just once in a day, but we cannot do that with Cortex Analyzers
response = requests.post(base_url + '/get-access-token', json={'api_key': api_key})
response.raise_for_status()
Expand All @@ -43,7 +42,29 @@ def run(self):

report = response.json()
self.report(report)
elif self.data_type == 'hash':
file_hash = self.get_param('data', None, 'Sha256 is missing')
api_key = self.get_param('config.key', None, 'Missing Intezer API key')

# this should be done just once in a day, but we cannot do that with Cortex Analyzers
response = requests.post(base_url + '/get-access-token', json={'api_key': api_key})
response.raise_for_status()
session = requests.session()
session.headers['Authorization'] = session.headers['Authorization'] = 'Bearer %s' % response.json()[
'result']

response = session.post(base_url + '/analyze-by-hash', json={'hash': file_hash})
if response.status_code != 201:
self.error('Error sending hash to Intezer Analyzer\n{}'.format(response.text))

while response.status_code != 200:
time.sleep(3)
result_url = response.json()['result_url']
response = session.get(base_url + result_url)
response.raise_for_status()

report = response.json()
self.report(report)
else:
self.notSupported()

Expand Down