|
| 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 | + |
0 commit comments