DNStwist errors
tested with www.test.com
intelowl_celery_worker_default | Traceback (most recent call last):
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/urllib/request.py", line 1348, in do_open
intelowl_celery_worker_default | h.request(req.get_method(), req.selector, req.data, headers,
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1294, in request
intelowl_celery_worker_default | self._send_request(method, url, body, headers, encode_chunked)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1340, in _send_request
intelowl_celery_worker_default | self.endheaders(body, encode_chunked=encode_chunked)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1289, in endheaders
intelowl_celery_worker_default | self._send_output(message_body, encode_chunked=encode_chunked)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1048, in _send_output
intelowl_celery_worker_default | self.send(msg)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 986, in send
intelowl_celery_worker_default | self.connect()
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1466, in connect
intelowl_celery_worker_default | self.sock = self._context.wrap_socket(self.sock,
intelowl_celery_worker_default | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/ssl.py", line 517, in wrap_socket
intelowl_celery_worker_default | return self.sslsocket_class._create(
intelowl_celery_worker_default | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/ssl.py", line 1108, in _create
intelowl_celery_worker_default | self.do_handshake()
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/ssl.py", line 1383, in do_handshake
intelowl_celery_worker_default | self._sslobj.do_handshake()
intelowl_celery_worker_default | ssl.SSLEOFError: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)
Hi @mlodic,
I've analyzed the ssl.SSLEOFError in the DNStwist analyzer. This issue is likely caused by Python 3.11's stricter SSL handshake handling when dnstwist attempts to connect to misconfigured or malicious typo-squatting domains that drop connections abruptly.
Proposed Fix:
I plan to wrap the dnstwist.run() call in api_app/analyzers_manager/observable_analyzers/dnstwist.py with a try...except block to catch ssl.SSLEOFError (and potentially other SSL-related exceptions). This will prevent the Celery worker from crashing and allow for more graceful error handling.
Does this approach for handling the SSL handshake failures sound correct to you? If so, I can proceed with the implementation.
while testing another domain (www.randomnamenonexistent.com) I found a different error:
intelowl_celery_worker_default | Traceback (most recent call last):
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/urllib/request.py", line 1348, in do_open
intelowl_celery_worker_default | h.request(req.get_method(), req.selector, req.data, headers,
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1294, in request
intelowl_celery_worker_default | self._send_request(method, url, body, headers, encode_chunked)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1340, in _send_request
intelowl_celery_worker_default | self.endheaders(body, encode_chunked=encode_chunked)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1289, in endheaders
intelowl_celery_worker_default | self._send_output(message_body, encode_chunked=encode_chunked)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 1048, in _send_output
intelowl_celery_worker_default | self.send(msg)
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 986, in send
intelowl_celery_worker_default | self.connect()
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/http/client.py", line 952, in connect
intelowl_celery_worker_default | self.sock = self._create_connection(
intelowl_celery_worker_default | ^^^^^^^^^^^^^^^^^^^^^^^^
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/socket.py", line 827, in create_connection
intelowl_celery_worker_default | for res in getaddrinfo(host, port, 0, SOCK_STREAM):
intelowl_celery_worker_default | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
intelowl_celery_worker_default | File "/usr/local/lib/python3.11/socket.py", line 962, in getaddrinfo
intelowl_celery_worker_default | for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
intelowl_celery_worker_default | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
intelowl_celery_worker_default | socket.gaierror: [Errno -2] Name or service not known
This would need to be wrapped in a way that a more delicate error is shown to the user. The analysis should not fail in my opinion cause the tool worked as intended but it should show the error in a more graceful way. If you want to work on this I can assign you @NikhilRaikwar
report = dnstwist.run(**params)
Hi @mlodic, please go ahead and assign it to me!
I've noted the socket.gaierror as well. It seems that dnstwist.run() lets certain network/SSL exceptions bubble up, especially when encountering non-existent domains or abruptly dropped connections.
I'll implement a fix to catch these exceptions (ssl.SSLEOFError, socket.gaierror, etc.) within the analyzer. Instead of letting the entire analysis job fail, I will ensure it returns a successful status with a report that gracefully describes the error encountered. This way, the user gets the feedback without the Celery worker crashing.
Hi @mlodic, I've created the PR https://github.com/intelowlproject/IntelOwl/pull/3290 to address your feedback:
- Error Handling: Now gracefully catches both
ssl.SSLEOFErrorandsocket.gaierror(DNS resolution errors). - Unit Tests: Added automated test cases for both SSL and DNS error scenarios to ensure stability (all tests pass).
- Verification: Updated the description with screenshots of the JSON results, Celery logs, and unit test outputs.
Ready for another look!
We cannot silence the errors, it would make believe that this works fine while it is not. Clearly here the problem is the domain provided as input. We need to add a message that explicitly says that to the user instead of getting them just the generic connection error which doesn't mean anything. The user must understand in this way that the problem is the input and not the analyzer. Also self.report.errors must be used like we do in other similar analyzers and a log entry must be added
Proposed solution
Changes in test_dnstwist.py
from unittest.mock import (patch, MagicMock)
def test_run_with_ssl_error(self):
import ssl
from api_app.analyzers_manager.models import AnalyzerConfig
from api_app.choices import Classification
config = AnalyzerConfig.objects.filter(name="DNStwist").first()
analyzer = self._setup_analyzer(config, Classification.DOMAIN, "example.com")
analyzer.report = MagicMock()
analyzer.report.errors = []
with patch("dnstwist.run", side_effect=ssl.SSLEOFError("EOF occurred in violation of protocol")):
analyzer.run()
self.assertTrue(any("Network/SSL error" in e for e in analyzer.report.errors))
self.assertTrue(any("example.com" in e for e in analyzer.report.errors))
def test_run_with_dns_error(self):
import socket
from api_app.analyzers_manager.models import AnalyzerConfig
from api_app.choices import Classification
config = AnalyzerConfig.objects.filter(name="DNStwist").first()
analyzer = self._setup_analyzer(config, Classification.DOMAIN, "example.com")
analyzer.report = MagicMock()
analyzer.report.errors = []
with patch("dnstwist.run", side_effect=socket.gaierror(-2, "Name or service not known")):
analyzer.run()
self.assertTrue(any("Network/SSL error" in e for e in analyzer.report.errors))
self.assertTrue(any("example.com" in e for e in analyzer.report.errors))
dnstwist.py
try:
report = dnstwist.run(**params)
except (OSError, ssl.SSLError) as e:
error_msg = (
f"Network/SSL error: The provided domain '{self.observable_name}' may be invalid or misconfigured. Details: {str(e)}"
)
logger.error(error_msg)
self.report.errors.append(error_msg)
return []
tested the changes locally, @mlodic PTAL and lmk if this is alright.
"Network/SSL error" is not necessary, it will be explained in the real error message
Alright