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

Create new 'error' category #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions pydnsbl/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import aiodns

from .providers import Provider, BASE_PROVIDERS, BASE_DOMAIN_PROVIDERS
from .providers import Provider, BASE_PROVIDERS, BASE_DOMAIN_PROVIDERS, DNSBL_CATEGORY_ERROR

if sys.platform == 'win32' and sys.version_info >= (3, 8):
# fixes https://github.com/dmippolitov/pydnsbl/issues/12
Expand Down Expand Up @@ -58,10 +58,12 @@ def process_results(self):
if not result.response:
continue
# set blacklisted to True if ip is detected with at least one dnsbl
self.blacklisted = True
provider_categories = provider.process_response(result.response)
self.categories = self.categories.union(provider_categories)
self.detected_by[provider.host] = list(provider_categories)
# If the response is an error, do not consider it as blacklisted (refer to https://www.spamhaus.org/faqs/domain-blocklist/#291:~:text=The%20following%20special%20codes%20indicate%20an%20error)
if provider_categories != {DNSBL_CATEGORY_ERROR}:
self.blacklisted = True
self.categories = self.categories.union(provider_categories)
self.detected_by[provider.host] = list(provider_categories)

def __repr__(self):
blacklisted = '[BLACKLISTED]' if self.blacklisted else ''
Expand Down
13 changes: 11 additions & 2 deletions pydnsbl/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DNSBL_CATEGORY_CNC = 'cnc'
DNSBL_CATEGORY_ABUSED = 'abused'
DNSBL_CATEGORY_LEGIT = 'legit'
DNSBL_CATEGORY_ERROR = 'error'

class Provider(object):

Expand Down Expand Up @@ -57,6 +58,8 @@ def process_response(self, response):
categories.add(DNSBL_CATEGORY_SPAM)
elif result.host in ['127.0.0.4', '127.0.0.5', '127.0.0.6', '127.0.0.7']:
categories.add(DNSBL_CATEGORY_EXPLOITS)
elif result.host in ['127.255.255.252', '127.255.255.254', '127.255.255.255']:
categories.add(DNSBL_CATEGORY_ERROR)
else:
categories.add(DNSBL_CATEGORY_UNKNOWN)
return categories
Expand All @@ -71,7 +74,10 @@ def process_response(self, response):
'blackholes.five-ten-sg.com',
'blacklist.woody.ch',
'bogons.cymru.com',
'cbl.abuseat.org',
# The provider zen.spamhaus.org is already being used. abuseat.org redirects to spamhaus.org
# Additionally, abuseat.org has the same behaviour as zen.spamhaus.org
# and we manage the new DNSBL_CATEGORY_ERROR in the zen.spamhaus.org Provider class
# 'cbl.abuseat.org',
'combined.abuse.ch',
'combined.rbl.msrbl.net',
'db.wpbl.info',
Expand Down Expand Up @@ -122,7 +128,10 @@ class DblSpamhaus(Provider):
'127.0.1.103': {DNSBL_CATEGORY_ABUSED, DNSBL_CATEGORY_SPAM},
'127.0.1.104': {DNSBL_CATEGORY_ABUSED, DNSBL_CATEGORY_LEGIT, DNSBL_CATEGORY_PHISH},
'127.0.1.105': {DNSBL_CATEGORY_ABUSED, DNSBL_CATEGORY_LEGIT, DNSBL_CATEGORY_MALWARE},
'127.0.1.106': {DNSBL_CATEGORY_ABUSED, DNSBL_CATEGORY_LEGIT, DNSBL_CATEGORY_CNC}
'127.0.1.106': {DNSBL_CATEGORY_ABUSED, DNSBL_CATEGORY_LEGIT, DNSBL_CATEGORY_CNC},
'127.255.255.252': {DNSBL_CATEGORY_ERROR},
'127.255.255.254': {DNSBL_CATEGORY_ERROR},
'127.255.255.255': {DNSBL_CATEGORY_ERROR},
}

def __init__(self, host='dbl.spamhaus.org'):
Expand Down