domainaware / checkdmarc

A parser for SPF and DMARC DNS records
https://domainaware.github.io/checkdmarc
Apache License 2.0
244 stars 76 forks source link

Error when SPF is 10+ lookups #112

Closed EmailKarma closed 8 months ago

EmailKarma commented 9 months ago

Just updated to v 4.8.5 and this bug was found when an SPF record was greater than 10 look ups.

Traceback (most recent call last):
  File "C:\Python311\Lib\site-packages\checkdmarc.py", line 2749, in check_spf
    parsed_spf = parse_spf_record(spf_results["record"],
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\checkdmarc.py", line 1911, in parse_spf_record
    raise SPFTooManyDNSLookups(
checkdmarc.SPFTooManyDNSLookups: Parsing the SPF record requires 15/10 maximum DNS lookups - https://tools.ietf.org/html/rfc7208#section-4.6.4

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Python311\Scripts\checkdmarc.exe\__main__.py", line 7, in <module>
  File "C:\Python311\Lib\site-packages\checkdmarc.py", line 2990, in _main
    results = check_domains(domains, skip_tls=args.skip_tls,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\checkdmarc.py", line 2529, in check_domains
    domain_results["spf"] = check_spf(
                            ^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\checkdmarc.py", line 2763, in check_spf
    spf_results["error"] = error.args[0].args[0]
                           ^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'args'
MikJagger commented 9 months ago

The same issue seems to encounter when an SPF records doesn't exist. Switched back to version 4.8.4 which is working fine.

python checkdmarc.py domain xx.xx --debug --skip-tls -p 2023-11-15 02:44:12,688 - DEBUG: Debug output enabled 2023-11-15 02:44:12,688 - DEBUG: Checking: xx.xx 2023-11-15 02:44:12,790 - DEBUG: Getting NS records on xx.xx 2023-11-15 02:44:12,817 - DEBUG: Checking for MX records on xx.xx 2023-11-15 02:44:12,873 - DEBUG: Checking for a SPF record on xx.xx Traceback (most recent call last): File "checkdmarc/checkdmarc.py", line 1663, in query_spf_record answers = _query_dns(domain, "TXT", nameservers=nameservers, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "checkdmarc/checkdmarc.py", line 649, in _query_dns resolver.resolve(domain, record_type, lifetime=timeout))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dns/resolver.py", line 1333, in resolve (answer, done) = resolution.query_result(response, None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/dns/resolver.py", line 836, in query_result raise NoAnswer(response=answer.response) dns.resolver.NoAnswer: The DNS response does not contain an answer to the question: xx.xx. IN TXT

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "checkdmarc/checkdmarc.py", line 2743, in check_spf spf_query = query_spf_record( ^^^^^^^^^^^^^^^^^ File "checkdmarc/checkdmarc.py", line 1680, in query_spf_record raise SPFRecordNotFound( SPFRecordNotFound: ('xx.xx does not have a SPF TXT record', 'xx.xx')

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "checkdmarc/checkdmarc.py", line 3020, in _main() File "checkdmarc/checkdmarc.py", line 2990, in _main results = check_domains(domains, skip_tls=args.skip_tls, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "checkdmarc/checkdmarc.py", line 2529, in check_domains domain_results["spf"] = check_spf( ^^^^^^^^^^ File "checkdmarc/checkdmarc.py", line 2763, in check_spf spf_results["error"] = error.args[0].args[0] ^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'args'

seanthegeek commented 8 months ago

This should be fixed in the newly released version 5.0.0. Can you confirm?

EmailKarma commented 8 months ago

Updated today - seems to be good now.