Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit fea6ad7
Author: funilrys <contact@funilrys.com>
Date:   Sat Dec 3 10:21:10 2022 +0100

    fixup! Introduction of the changeip SPECIAL rule.

commit 6a96637
Author: funilrys <contact@funilrys.com>
Date:   Thu Dec 1 21:34:25 2022 +0100

    Introduction of the changeip SPECIAL rule.

    This patch fixes #311.

    Also:
      * Introduction of checker/availability/extras/dns.py

    From now on any changeip platform domains that were disabled for
    abuse will be switch to the `INACTIVE` status.
    To do that, this patch looks at the SOA record of the domain and
    look for `abuse.changeip.com` in the response.

    Contributors:
      * @smed79
  • Loading branch information
funilrys committed Dec 3, 2022
1 parent b953fd3 commit 2f2923d
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 20 deletions.
7 changes: 6 additions & 1 deletion PyFunceble/checker/availability/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import PyFunceble.factory
import PyFunceble.storage
from PyFunceble.checker.availability.extras.base import ExtraRuleHandlerBase
from PyFunceble.checker.availability.extras.dns import DNSRulesHandler
from PyFunceble.checker.availability.extras.rules import ExtraRulesHandler
from PyFunceble.checker.availability.extras.subject_switch import (
SubjectSwitchRulesHandler,
Expand Down Expand Up @@ -169,7 +170,11 @@ def __init__(
self.ip_syntax_checker = IPSyntaxChecker()
self.url_syntax_checker = URLSyntaxChecker()
# WARNING: Put the aggressive one first!
self.extra_rules_handlers = [SubjectSwitchRulesHandler(), ExtraRulesHandler()]
self.extra_rules_handlers = [
SubjectSwitchRulesHandler(),
DNSRulesHandler(),
ExtraRulesHandler(),
]
self.db_session = db_session

self.params = AvailabilityCheckerParams()
Expand Down
21 changes: 20 additions & 1 deletion PyFunceble/checker/availability/extras/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@
"""

import functools
from typing import Callable, Optional
from typing import Callable, List, Optional

import requests

import PyFunceble.factory
from PyFunceble.checker.availability.status import AvailabilityCheckerStatus
from PyFunceble.query.dns.query_tool import DNSQueryTool


class ExtraRuleHandlerBase:
Expand All @@ -71,6 +72,7 @@ class ExtraRuleHandlerBase:

_status: Optional[AvailabilityCheckerStatus] = None
req: Optional[requests.Response] = None
dns_query_tool: Optional[DNSQueryTool] = None
req_url: Optional[str] = None

def __init__(self, status: Optional[AvailabilityCheckerStatus] = None) -> None:
Expand All @@ -79,6 +81,7 @@ def __init__(self, status: Optional[AvailabilityCheckerStatus] = None) -> None:

# Be sure that all settings are loaded proprely!!
PyFunceble.factory.Requester.guess_all_settings()
self.dns_query_tool = DNSQueryTool()

def ensure_status_is_given(
func: Callable[..., "ExtraRuleHandlerBase"]
Expand Down Expand Up @@ -212,6 +215,22 @@ def do_request(self, *, allow_redirects: bool = True) -> requests.Response:

return self

def do_dns_lookup(self, *, subject: str, query_type: str) -> List[str]:
"""
Do a DNS lookup and return its response.
:param subject:
The subject to query.
:param query_type:
The query type.
"""

return (
self.dns_query_tool.set_query_record_type(query_type)
.set_subject(subject)
.query()
)

def start(self) -> "ExtraRuleHandlerBase":
"""
Starts the gathering process.
Expand Down
164 changes: 164 additions & 0 deletions PyFunceble/checker/availability/extras/dns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
"""
The tool to check the availability or syntax of domain, IP or URL.
::
██████╗ ██╗ ██╗███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗██████╗ ██╗ ███████╗
██╔══██╗╚██╗ ██╔╝██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝██╔══██╗██║ ██╔════╝
██████╔╝ ╚████╔╝ █████╗ ██║ ██║██╔██╗ ██║██║ █████╗ ██████╔╝██║ █████╗
██╔═══╝ ╚██╔╝ ██╔══╝ ██║ ██║██║╚██╗██║██║ ██╔══╝ ██╔══██╗██║ ██╔══╝
██║ ██║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝
Provides the extra rules handler based on some DNS records.
Author:
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
Special thanks:
https://pyfunceble.github.io/#/special-thanks
Contributors:
https://pyfunceble.github.io/#/contributors
Project link:
https://github.com/funilrys/PyFunceble
Project documentation:
https://pyfunceble.readthedocs.io/en/dev/
Project homepage:
https://pyfunceble.github.io/
License:
::
Copyright 2017, 2018, 2019, 2020, 2022 Nissar Chababy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from typing import Optional

import PyFunceble.facility
from PyFunceble.checker.availability.extras.base import ExtraRuleHandlerBase
from PyFunceble.checker.availability.status import AvailabilityCheckerStatus
from PyFunceble.helpers.regex import RegexHelper


class DNSRulesHandler(ExtraRuleHandlerBase):
"""
Provides our very own sets of DNS based rules.
:param status:
The previously gathered status.
:type status:
:class:`~PyFunceble.checker.availability.status.AvailabilityCheckerStatus`
"""

rulesets: dict = {}

def __init__(self, status: Optional[AvailabilityCheckerStatus] = None) -> None:
self.rulesets = {
r"\.(25u\.com|2waky\.com|3-a\.net|4dq\.com|4pu\.com|acmetoy\.com|"
r"almostmy\.com|americanunfinished\.com|as19557\.net|"
r"authorizeddns\.net|authorizeddns\.org|authorizeddns\.us|"
r"b0tnet\.com|bigmoney\.biz|changeip\.biz|changeip\.co|"
r"changeip\.net|changeip\.org|changeip\.us|cleansite\.biz|"
r"cleansite\.info|cleansite\.us|ddns\.info|ddns\.mobi|ddns\.ms|"
r"ddns\.us|dhcp\.biz|dns-dns\.com|dns-report\.com|dns-stuff\.com|"
r"dns04\.com|dns05\.com|dns1\.us|dns2\.us|dnset\.com|"
r"dnsfailover\.net|dnsrd\.com|dsmtp\.biz|dsmtp\.com|dubya\.biz|"
r"dubya\.info|dubya\.net|dubya\.us|dumb1\.com|dynamic-dns\.net|"
r"dynamicdns\.biz|dynssl\.com|edns\.biz|esmtp\.biz|ezua\.com|"
r"faqserv\.com|fartit\.com|freeddns\.com|freetcp\.com|freewww\.biz|"
r"freewww\.info|ftp1\.biz|ftpserver\.biz|gettrials\.com|"
r"got-game\.org|gr8domain\.biz|gr8name\.biz|homingbeacon\.net|"
r"https443\.net|https443\.org|ikwb\.com|instanthq\.com|iownyour\.biz|"
r"iownyour\.org|isasecret\.com|itemdb\.com|itsaol\.com|jetos\.com|"
r"jkub\.com|jungleheart\.com|justdied\.com|lflink\.com|lflinkup\.com|"
r"lflinkup\.net|lflinkup\.org|longmusic\.com|mefound\.com|"
r"misecure\.com|moneyhome\.biz|mrbasic\.com|mrbonus\.com|mrface\.com|"
r"mrslove\.com|my03\.com|mydad\.info|myddns\.com|myftp\.info|"
r"mylftv\.com|mymom\.info|mynetav\.com|mynetav\.net|mynetav\.org|"
r"mynumber\.org|mypicture\.info|mypop3\.net|mypop3\.org|"
r"mysecondarydns\.com|mywww\.biz|myz\.info|ninth\.biz|ns01\.biz|"
r"ns01\.info|ns01\.us|ns02\.biz|ns02\.info|ns02\.us|ns1\.name|"
r"ns2\.name|ns3\.name|ocry\.com|onedumb\.com|onmypc\.biz|"
r"onmypc\.info|onmypc\.net|onmypc\.org|onmypc\.us|"
r"organiccrap\.com|otzo\.com|ourhobby\.com|port25\.biz|"
r"proxydns\.com|qhigh\.com|qpoe\.com|rebatesrule\.net|"
r"sendsmtp\.com|serveuser\.com|serveusers\.com|sexidude\.com|"
r"sexxxy\.biz|sixth\.biz|squirly\.info|ssl443\.org|ssmailer\.com|"
r"toh\.info|toshibanetcam\.com|toythieves\.com|trickip\.net|"
r"trickip\.org|vizvaz\.com|wikaba\.com|www1\.biz|"
r"wwwhost\.biz|wwwhost\.us|x24hr\.com|xxuz\.com|xxxy\.biz|"
r"xxxy\.info|ygto\.com|youdontcare\.com|yourtrap\.com|"
r"zyns\.com|zzux\.com)(\.|)$": [
(self._switch_down_if_match, ("SOA", ["abuse.changeip.com."]))
]
}

super().__init__(status)

def _switch_down_if_match(
self, query_type: str, matches: list
) -> "DNSRulesHandler":
"""
Tries to switch the status :code:`INACTIVE` if the query matched.
"""

result = (
self.dns_query_tool.set_query_record_type(query_type)
.set_subject(self.status.netloc)
.query()
)

for record in result:
for match in matches:
if match in record:
self.switch_to_down()
break

@ExtraRuleHandlerBase.ensure_status_is_given
@ExtraRuleHandlerBase.setup_status_before
@ExtraRuleHandlerBase.setup_status_after
def start(self) -> "SubjectSwitchRulesHandler":
"""
Process the check and handling of the current subject.
"""

PyFunceble.facility.Logger.info(
"Started to check %r against our subject switcher rules.",
self.status.idna_subject,
)

for regex, rulesets in self.rulesets.items():
if self.status.status_after_extra_rules:
break

if not RegexHelper(regex).match(self.status.netloc, return_match=False):
break

for ruler, params in rulesets:
if self.status.status_after_extra_rules:
break

ruler(*params)

PyFunceble.facility.Logger.info(
"Finished to check %r against our subject switcher rules.",
self.status.idna_subject,
)
Loading

0 comments on commit 2f2923d

Please sign in to comment.