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 Spamhaus DBL analyzer #585

Merged
merged 2 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions analyzers/SpamhausDBL/SpamhausDBL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "SpamhausDBL",
"version": "1.0",
"author": "Wes Lambert",
"url": "https://github.com/TheHive-Project/Cortex-Analyzers",
"license": "AGPL-V3",
"description": "Perform domain lookup to Spamhaus DBL",
"dataTypeList": ["domain"],
"baseConfig": "SpamhausDBL",
"config": {
"service": "DBLLookup"
},
"command": "SpamhausDBL/spamhausdbl.py",
"configurationItems": []
}
1 change: 1 addition & 0 deletions analyzers/SpamhausDBL/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dnyspython
99 changes: 99 additions & 0 deletions analyzers/SpamhausDBL/spamhausdbl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
# encoding: utf-8

from cortexutils.analyzer import Analyzer
import dns.resolver

class SpamhausDBLAnalyzer(Analyzer):
def __init__(self):
Analyzer.__init__(self)
self.observable = self.get_param('data', None, 'Data missing!')

def summary(self, raw):
taxonomies = []
level = 'info'
namespace = 'SpamhausDBL'

# Set predicate for return_code
predicate = 'return_code'
taxonomies.append(self.build_taxonomy(level, namespace, predicate, raw['return_code']))

# Set predicate for classification
predicate = 'classification'
taxonomies.append(self.build_taxonomy(level, namespace, predicate, raw['classification']))

return {"taxonomies": taxonomies}

def run(self):
try:
lookup = dns.resolver.query(self.observable + '.dbl.spamhaus.org')
return_code = str(lookup[0])
# Check return code for result info
# Reference here: https://www.spamhaus.org/faq/section/Spamhaus%20DBL#291

# spam domain
if return_code == "127.0.1.2" :
classification = "Spam"

# phish domain
if return_code == "127.0.1.4" :
classification = "Phishing"

# malware domain
if return_code == "127.0.1.5" :
classification = "Malware"

# botnet C&C domain
if return_code == "127.0.1.6" :
classification = "Botnet C&C"

# abused legit spam
if return_code == "127.0.1.102" :
classification = "Abused legit spam"

# abused spammed redirector domain
if return_code == "127.0.1.103" :
classification = "Abused spammed redirector"

# abused legit phish
if return_code == "127.0.1.104" :
classification = "Abused legit phish"

# abused legit malware
if return_code == "127.0.1.105" :
classification = "Abused legit malware"

# abused legit botnet C&C
if return_code == "127.0.1.106" :
classification = "Abused legit Botnet C&C"

# IP queries prohibited
if return_code == "127.0.1.255" :
classification = "IP queries prohibited"

# Typing error in DNSBL name
if return_code == "127.255.255.252" :
classification = "Typing error in DNSBL name"

# Anon query through public resolver
if return_code == "127.255.255.254" :
classification = "Anon query through public resolver"

# Excessive number of queries
if return_code == "127.255.255.255" :
classification = "Excessive number of queries"

self.report({ 'return_code': return_code, 'classification': classification })

except dns.resolver.NXDOMAIN:
self.report({ 'return_code': 'NXDOMAIN', 'classification': 'Clean' })
except dns.resolver.NoAnswer:
self.report({ 'return_code': 'NoAnswer', 'classification': 'NoAnswer' })
except dns.resolver.Timeout:
self.report({ 'return_code': 'Timeout', 'classification': 'Timeout' })
except:
self.error('Something unexpected happened!')

if __name__ == '__main__':
SpamhausDBLAnalyzer().run()

16 changes: 16 additions & 0 deletions thehive-templates/SpamhausDBL_1_0/long.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="panel panel-info">
<div class="panel-heading">
Spamhaus DBL Lookup Results
</div>
<div class="panel-body">
<table class="table table-hover">
<tr>
<th>Return Code</th>
<th>Classification</th>
</tr>
<td>{{content.return_code | ellipsis:40}}</td>
<td>{{content.classification}}</a></td>
</tr>
</table>
</div>
</div>
3 changes: 3 additions & 0 deletions thehive-templates/SpamhausDBL_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>