-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput_module.py
84 lines (71 loc) · 3.07 KB
/
output_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# output_module.py
import os
import json
from urllib.parse import urlparse
import whois_module
def format_url(url):
parts = url.split(".")
formatted_url = "[.]".join(parts)
return formatted_url
def get_threat_types(vt_result):
threat_types = set()
scans = vt_result.get("scans", {})
for scanner, result in scans.items():
result_str = result.get("result", "").lower()
if "phishing site" in result_str:
threat_types.add("Phishing")
elif "malicious site" in result_str:
threat_types.add("Malicious")
elif "malware" in result_str:
threat_types.add("Malware")
elif "suspicious" in result_str:
threat_types.add("Suspicious")
return ", ".join(sorted(threat_types))
def save_results(results):
# Get the number of existing output files
output_files = [f for f in os.listdir("outputs") if f.startswith("output")]
output_number = len(output_files) + 1
# Create the output file name
output_filename = f"output{output_number}.txt"
output_path = os.path.join("outputs", output_filename)
# Write the results to the output file
with open(output_path, "w") as f:
vt_result = results["VirusTotal"]
urlscan_result = results["URLScan.io"]
# Get the data from VirusTotal and URLScan.io
scanned_url = vt_result.get("url")
scan_date = vt_result.get("scan_date")
vt_permalink = vt_result.get("permalink")
urlscan_reporturl = urlscan_result.get("task", {}).get("reportURL")
ips = urlscan_result.get("lists", {}).get("ips", [])
countries = urlscan_result.get("lists", {}).get("countries", [])
screenshot_url = urlscan_result.get("task", {}).get("screenshotURL")
# Get the domain from the scanned URL
parsed_url = urlparse(scanned_url)
domain = parsed_url.netloc
# Get the threat types from VirusTotal results
threat_types = get_threat_types(vt_result)
# Get WHOIS information
whois_info = whois_module.get_whois_info(domain)
if isinstance(whois_info, dict):
registrar = whois_info.get("registrar", "N/A")
creation_date = whois_info.get("creation_date", "N/A")
expiration_date = whois_info.get("expiration_date", "N/A")
else:
registrar = "N/A"
creation_date = "N/A"
expiration_date = "N/A"
# Format the output
f.write(f"NEW URL DISCOVERED ON {scan_date}\n")
f.write(f"URL: {format_url(scanned_url)}\n")
f.write(f"Domain: {format_url(domain)}\n")
f.write(f"Registrar: {registrar}\n")
f.write(f"Created at: {creation_date}\n")
f.write(f"Expires at: {expiration_date}\n")
f.write(f"Type: {threat_types}\n")
f.write("IPs: " + ", ".join(ips) + "\n")
f.write("Countries: " + ", ".join(countries) + "\n")
f.write(f"Scanned at: {scan_date}\n")
f.write(f"Screenshot: {screenshot_url}\n")
f.write(f"VirusTotal Report: {vt_permalink}\n")
f.write(f"URLScan report: {urlscan_reporturl}\n")