Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion api_app/analyzers_manager/observable_analyzers/dnstwist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See the file 'LICENSE' for copying permission.

import logging
import ssl
from ipaddress import AddressValueError, IPv4Address
from urllib.parse import urlparse

Expand Down Expand Up @@ -55,6 +56,11 @@ def run(self):
if self.user_agent:
params["useragent"] = self.user_agent

report = dnstwist.run(**params)
try:
report = dnstwist.run(**params)
except (OSError, ssl.SSLError) as e:
return {"error": f"Network/SSL error: {str(e)}"}
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected errors should still make the analyzer fail so please remove this.

Here we want to manage the errors that are not caused by the tool itself but are based on the input data based on the current observations that we reported in the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the catch-all Exception block in the latest commit.

return {"error": f"Unexpected error: {str(e)}"}

return report
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,43 @@ def get_extra_config(cls) -> dict:
"user_agent": "IntelOwl-Test",
"nameservers": "8.8.8.8,8.8.4.4",
}

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")

with patch("dnstwist.run", side_effect=ssl.SSLEOFError("EOF occurred in violation of protocol")):
report = analyzer.run()
self.assertIn("error", report)
self.assertTrue(report["error"].startswith("Network/SSL error"))

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")

with patch("dnstwist.run", side_effect=socket.gaierror(-2, "Name or service not known")):
report = analyzer.run()
self.assertIn("error", report)
self.assertTrue(report["error"].startswith("Network/SSL error"))

def test_run_with_unexpected_error(self):
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")

with patch("dnstwist.run", side_effect=Exception("Something went wrong")):
report = analyzer.run()
self.assertIn("error", report)
self.assertTrue(report["error"].startswith("Unexpected error"))
Loading