Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove need for external API for whois lookups #3155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 13 additions & 25 deletions external-import/ransomwarelive/src/lib/ransom_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests
import tldextract
import validators
import whois
from pycti import OpenCTIConnectorHelper
from stix2 import (
TLP_WHITE,
Expand Down Expand Up @@ -174,38 +175,25 @@ def ip_fetcher(self, domain):

# Fetches the whois information of a domain
def fetch_country_domain(self, domain):
url = f"https://who-dat.as93.net/{domain}"
headers = {"user-agent": "OpenCTI"}
try:
response = requests.get(url, headers=headers, timeout=(20000, 20000))
if response.status_code == 200:
response_json = response.json()
if response_json.get("whoisparser") == "domain is not found":
self.helper.log_info(f"Domain {domain} is not found")
return None

else:
return None
w = whois.whois(domain)
except Exception as e:
self.helper.log_error(f"Error fetching WHOIS for domain {domain}")
self.helper.log_error(str(e))
return None

try:
description = f"Domain:{domain} \n"
if (
response_json.get("domain") is not None
and response_json.get("administrative") is not None
):
if response_json.get("administrative").get("country") is not None:
description += f" is registered in {response_json.get('administrative').get('country')} \n"
if response_json.get("registrar") is not None:
description += (
f"registered with {response_json.get('registrar').get('name')} \n"
)
if response_json.get("domain").get("created_date") is not None:
description += f" creation_date {response_json.get('domain').get('created_date')} \n"
if response_json.get("domain").get("expiration_date") is not None:
description += f" expiration_date {response_json.get('domain').get('expiration_date')} \n"
# Using whois data from w instead of response_json
if w is not None:
if w.get("country") is not None:
description += f" is registered in {w.get('country')} \n"
if w.get("registrar") is not None:
description += f"registered with {w.get('registrar')} \n"
if w.get("creation_date") is not None:
description += f" creation_date {w.get('creation_date')} \n"
if w.get("expiration_date") is not None:
description += f" expiration_date {w.get('expiration_date')} \n"

except Exception as e:
self.helper.log_error(f"Error fetching whois for domain {domain}")
Expand Down
1 change: 1 addition & 0 deletions internal-enrichment/hygiene/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tldextract==5.1.3
pycti==6.4.5
python-whois
git+http://github.com/MISP/PyMISPWarningLists.git@main#egg=pymispwarninglists