2018-08-08 17:00:10 +02:00
|
|
|
import json
|
2018-12-11 15:29:09 +01:00
|
|
|
import sys
|
2018-08-08 17:00:10 +02:00
|
|
|
|
|
|
|
try:
|
2023-04-02 10:11:24 +02:00
|
|
|
original_path = sys.path
|
|
|
|
sys.path = original_path[1:]
|
2018-08-08 17:00:10 +02:00
|
|
|
import dns.resolver
|
2023-04-02 10:11:24 +02:00
|
|
|
sys.path = original_path
|
2018-08-08 17:00:10 +02:00
|
|
|
resolver = dns.resolver.Resolver()
|
|
|
|
resolver.timeout = 0.2
|
|
|
|
resolver.lifetime = 0.2
|
2018-09-08 02:53:15 +02:00
|
|
|
except ImportError:
|
2018-08-08 17:00:10 +02:00
|
|
|
print("dnspython3 is missing, use 'pip install dnspython3' to install it.")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
misperrors = {'error': 'Error'}
|
|
|
|
mispattributes = {'input': ['domain', 'domain|ip', 'hostname', 'hostname|port'], 'output': ['text']}
|
|
|
|
moduleinfo = {'version': '0.1', 'author': 'Christian Studer',
|
|
|
|
'description': 'Checks Spamhaus DBL for a domain name.',
|
|
|
|
'module-type': ['expansion', 'hover']}
|
|
|
|
moduleconfig = []
|
|
|
|
|
|
|
|
dbl = 'dbl.spamhaus.org'
|
|
|
|
dbl_mapping = {'127.0.1.2': 'spam domain',
|
|
|
|
'127.0.1.4': 'phish domain',
|
|
|
|
'127.0.1.5': 'malware domain',
|
|
|
|
'127.0.1.6': 'botnet C&C domain',
|
|
|
|
'127.0.1.102': 'abused legit spam',
|
|
|
|
'127.0.1.103': 'abused spammed redirector domain',
|
|
|
|
'127.0.1.104': 'abused legit phish',
|
|
|
|
'127.0.1.105': 'abused legit malware',
|
|
|
|
'127.0.1.106': 'abused legit botnet C&C',
|
|
|
|
'127.0.1.255': 'IP queries prohibited!'}
|
|
|
|
|
2018-12-11 15:29:09 +01:00
|
|
|
|
2018-08-08 17:00:10 +02:00
|
|
|
def fetch_requested_value(request):
|
|
|
|
for attribute_type in mispattributes['input']:
|
|
|
|
if request.get(attribute_type):
|
|
|
|
return request[attribute_type].split('|')[0]
|
|
|
|
return None
|
|
|
|
|
2018-12-11 15:29:09 +01:00
|
|
|
|
2018-08-08 17:00:10 +02:00
|
|
|
def handler(q=False):
|
|
|
|
if q is False:
|
|
|
|
return False
|
|
|
|
request = json.loads(q)
|
|
|
|
requested_value = fetch_requested_value(request)
|
|
|
|
if requested_value is None:
|
|
|
|
misperrors['error'] = "Unsupported attributes type"
|
|
|
|
return misperrors
|
|
|
|
query = "{}.{}".format(requested_value, dbl)
|
|
|
|
try:
|
2023-07-01 14:46:28 +02:00
|
|
|
query_result = resolver.resolve(query, 'A')[0]
|
2018-08-08 17:00:10 +02:00
|
|
|
result = "{} - {}".format(requested_value, dbl_mapping[str(query_result)])
|
2019-10-08 15:48:26 +02:00
|
|
|
except dns.resolver.NXDOMAIN as e:
|
|
|
|
result = e.msg
|
|
|
|
except Exception:
|
|
|
|
return {'error': 'Not able to reach dbl.spamhaus.org or something went wrong'}
|
2018-08-08 17:00:10 +02:00
|
|
|
return {'results': [{'types': mispattributes.get('output'), 'values': result}]}
|
|
|
|
|
2018-12-11 15:29:09 +01:00
|
|
|
|
2018-08-08 17:00:10 +02:00
|
|
|
def introspection():
|
|
|
|
return mispattributes
|
|
|
|
|
2018-12-11 15:29:09 +01:00
|
|
|
|
2018-08-08 17:00:10 +02:00
|
|
|
def version():
|
|
|
|
moduleinfo['config'] = moduleconfig
|
|
|
|
return moduleinfo
|