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

add threatcrowd analyzer #244

Merged
merged 8 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 19 additions & 0 deletions analyzers/Threatcrowd/Threatcrowd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Threatcrowd",
"author": "Rémi ALLAIN, Cyberprotect",
"license": "AGPL-V3",
"url": "https://github.com/Cyberprotect/Cortex-Analyzers",
"version": "1.0",
"description": "Search for information on threatcrowd.org",
"dataTypeList": [
"email",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default e-mail data type is mail.

"ip",
"domain"
],
"command": "Threatcrowd/threatcrowd_analyzer.py",
"baseConfig": "Threatcrowd",
"config": {
"check_tlp": false,
"service": "get"
}
}
2 changes: 2 additions & 0 deletions analyzers/Threatcrowd/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cortexutils
requests
46 changes: 46 additions & 0 deletions analyzers/Threatcrowd/threatcrowd_analyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
# encoding: utf-8

import requests
from cortexutils.analyzer import Analyzer

class Threatcrowd(Analyzer):

URI = "https://www.threatcrowd.org/searchApi/v2"

def summary(self, raw):
taxonomies = []

level = "info"
value = "None"

if 'votes' in raw:
r = raw.get('votes')
value = r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r is None if ThreatCrowd doesn't know an email. That should be catched somehow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the level would be unspecified that way)

if r == 1:
level = "safe"
elif r == 0:
level = "suspicious"
elif r == -1:
level = "malicious"

taxonomies.append(self.build_taxonomy(level, "Threatcrowd", "votes", value))

result = {"taxonomies": taxonomies}
return result

def run(self):
Analyzer.run(self)

if (self.data_type == 'domain' or self.data_type == 'ip' or self.data_type == 'email'):
try:
response = requests.get("{}/{}/report/".format(self.URI, self.data_type), {self.data_type: self.get_data()})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above: default e-mail datatype is mail.

Something like self.data_type if self.data_type != 'mail' else 'email' would be possible. Requests to threat crowd contains then email as a datatype.

self.report(response.json())
except Exception as e:
self.unexpectedError(e)
else:
self.notSupported()


if __name__ == '__main__':
Threatcrowd().run()
69 changes: 69 additions & 0 deletions thehive-templates/Threatcrowd_1_0/long.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<div class="panel panel-info" ng-if="success">
<div class="panel-heading">
Threatcrowd analysis for
<strong>{{artifact.data}}</strong>
</div>
<div class="panel-body">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should catch an empty result, because currently there would be an empty table.

<h4 class="dl-horizontal">
Votes : <strong>{{content.votes}}</strong>
<br/>
<a href="{{content.permalink}}">View report on threatcrowd.org</a>
</h4>
<table class="table table-bordered">
<tr>
<th>References</th>
</tr>
<tr ng-repeat="ref in ::content.references">
<td>{{ref}}</td>
</tr>
</table>
<table class="table table-bordered">
<tr>
<th>Domains</th>
</tr>
<tr ng-repeat="dom in ::content.domains">
<td>{{dom}}</td>
</tr>
</table>
<table class="table table-bordered">
<tr>
<th>Subdomains</th>
</tr>
<tr ng-repeat="dom in ::content.subdomains">
<td>{{dom}}</td>
</tr>
</table>
<table class="table table-bordered">
<tr>
<th>Emails</th>
</tr>
<tr ng-repeat="email in ::content.emails">
<td>{{email}}</td>
</tr>
</table>
<table class="table table-bordered">
<tr>
<th colspan="3">Resolutions</th>
</tr>
<tr>
<th>Last resolved</th>
<th>Domain</th>
<th>Ip</th>
</tr>
<tr ng-repeat="res in ::content.resolutions">
<td>{{res.last_resolved}}</td>
<td>{{res.domain}}</td>
<td>{{res.ip_address}}</td>
</tr>
</table>
</div>
</div>

<div class="panel panel-danger" ng-if="!success">
<div class="panel-heading">
<strong>{{(artifact.data || artifact.attachment.name) | fang}}</strong>
</div>
<div class="panel-body">
{{content.errorMessage}}
</div>
</div>
3 changes: 3 additions & 0 deletions thehive-templates/Threatcrowd_1_0/short.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="label" ng-repeat="t in content.taxonomies" ng-class="{'info': 'label-info', 'safe': 'label-success', 'suspicious': 'label-warning', 'malicious':'label-danger'}[t.level]">
{{t.namespace}}:{{t.predicate}}={{t.value}}
</span>