Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ def _quad9_dns_query(self, observable) -> bool:
dns_response = dns.message.from_wire(quad9_response.content)
resolutions: list[str] = []
for answer in dns_response.answer:
resolutions.extend([resolution.address for resolution in answer])
for record in answer:
if hasattr(record, "address"):
resolutions.append(record.address)
elif hasattr(record, "target"):
resolutions.append(str(record.target))

return bool(resolutions)
return bool(resolutions), resolutions

def _google_dns_query(self, observable) -> bool:
"""Perform a DNS query with Google service, return True if Google answer the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ def run(self):
else:
quad9_response.raise_for_status()

json_response = quad9_response.json()
try:
json_response = quad9_response.json()
except Exception:
json_response = {}
resolutions: list[str] = []
for answer in json_response.get("Answer", []):
if "data" in answer:
resolutions.append(answer["data"])
data = answer.get("data") # safe access
if data is not None: # skip None values
resolutions.append(data)

return dns_resolver_response(observable, resolutions)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl
# See the file 'LICENSE' for copying permission.
from unittest.mock import patch

import pytest

from api_app.analyzers_manager.observable_analyzers.dns import Quad9DNSResolver


@pytest.mark.django_db
@patch("httpx.Client.get")
def test_quad9_dns_resolver_handles_non_utf8(mock_get):
class MockResponse:
content = b"\xd5\x00\x01"

@staticmethod
def raise_for_status():
pass

@staticmethod
def json():
return {"Answer": [{"data": "1.1.1.1"}]}

mock_get.return_value = MockResponse()

analyzer = Quad9DNSResolver(
observable_name="test.com", observable_classification="domain", config={}
)

result = analyzer.run()
assert "1.1.1.1" in result["resolutions"]
Loading