Skip to content

Commit 3cf76c2

Browse files
weslambertnadouani
authored andcommitted
Add Spamhaus DBL analyzer (#585)
* intial Spamhaus DBL analyzer * add fqdn
1 parent b22f1e4 commit 3cf76c2

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "SpamhausDBL",
3+
"version": "1.0",
4+
"author": "Wes Lambert",
5+
"url": "https://github.com/TheHive-Project/Cortex-Analyzers",
6+
"license": "AGPL-V3",
7+
"description": "Perform domain lookup to Spamhaus DBL",
8+
"dataTypeList": ["domain", "fqdn"],
9+
"baseConfig": "SpamhausDBL",
10+
"config": {
11+
"service": "DBLLookup"
12+
},
13+
"command": "SpamhausDBL/spamhausdbl.py",
14+
"configurationItems": []
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dnyspython
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env python3
2+
# encoding: utf-8
3+
4+
from cortexutils.analyzer import Analyzer
5+
import dns.resolver
6+
7+
class SpamhausDBLAnalyzer(Analyzer):
8+
def __init__(self):
9+
Analyzer.__init__(self)
10+
self.observable = self.get_param('data', None, 'Data missing!')
11+
12+
def summary(self, raw):
13+
taxonomies = []
14+
level = 'info'
15+
namespace = 'SpamhausDBL'
16+
17+
# Set predicate for return_code
18+
predicate = 'return_code'
19+
taxonomies.append(self.build_taxonomy(level, namespace, predicate, raw['return_code']))
20+
21+
# Set predicate for classification
22+
predicate = 'classification'
23+
taxonomies.append(self.build_taxonomy(level, namespace, predicate, raw['classification']))
24+
25+
return {"taxonomies": taxonomies}
26+
27+
def run(self):
28+
try:
29+
lookup = dns.resolver.query(self.observable + '.dbl.spamhaus.org')
30+
return_code = str(lookup[0])
31+
# Check return code for result info
32+
# Reference here: https://www.spamhaus.org/faq/section/Spamhaus%20DBL#291
33+
34+
# spam domain
35+
if return_code == "127.0.1.2" :
36+
classification = "Spam"
37+
38+
# phish domain
39+
if return_code == "127.0.1.4" :
40+
classification = "Phishing"
41+
42+
# malware domain
43+
if return_code == "127.0.1.5" :
44+
classification = "Malware"
45+
46+
# botnet C&C domain
47+
if return_code == "127.0.1.6" :
48+
classification = "Botnet C&C"
49+
50+
# abused legit spam
51+
if return_code == "127.0.1.102" :
52+
classification = "Abused legit spam"
53+
54+
# abused spammed redirector domain
55+
if return_code == "127.0.1.103" :
56+
classification = "Abused spammed redirector"
57+
58+
# abused legit phish
59+
if return_code == "127.0.1.104" :
60+
classification = "Abused legit phish"
61+
62+
# abused legit malware
63+
if return_code == "127.0.1.105" :
64+
classification = "Abused legit malware"
65+
66+
# abused legit botnet C&C
67+
if return_code == "127.0.1.106" :
68+
classification = "Abused legit Botnet C&C"
69+
70+
# IP queries prohibited
71+
if return_code == "127.0.1.255" :
72+
classification = "IP queries prohibited"
73+
74+
# Typing error in DNSBL name
75+
if return_code == "127.255.255.252" :
76+
classification = "Typing error in DNSBL name"
77+
78+
# Anon query through public resolver
79+
if return_code == "127.255.255.254" :
80+
classification = "Anon query through public resolver"
81+
82+
# Excessive number of queries
83+
if return_code == "127.255.255.255" :
84+
classification = "Excessive number of queries"
85+
86+
self.report({ 'return_code': return_code, 'classification': classification })
87+
88+
except dns.resolver.NXDOMAIN:
89+
self.report({ 'return_code': 'NXDOMAIN', 'classification': 'Clean' })
90+
except dns.resolver.NoAnswer:
91+
self.report({ 'return_code': 'NoAnswer', 'classification': 'NoAnswer' })
92+
except dns.resolver.Timeout:
93+
self.report({ 'return_code': 'Timeout', 'classification': 'Timeout' })
94+
except:
95+
self.error('Something unexpected happened!')
96+
97+
if __name__ == '__main__':
98+
SpamhausDBLAnalyzer().run()
99+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="panel panel-info">
2+
<div class="panel-heading">
3+
Spamhaus DBL Lookup Results
4+
</div>
5+
<div class="panel-body">
6+
<table class="table table-hover">
7+
<tr>
8+
<th>Return Code</th>
9+
<th>Classification</th>
10+
</tr>
11+
<td>{{content.return_code | ellipsis:40}}</td>
12+
<td>{{content.classification}}</a></td>
13+
</tr>
14+
</table>
15+
</div>
16+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<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]">
2+
{{t.namespace}}:{{t.predicate}}="{{t.value}}"
3+
</span>

0 commit comments

Comments
 (0)