Guest User

60 Second Hunt

a guest
Oct 13th, 2024
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import subprocess
  4. import re
  5. import os
  6. import dns.resolver
  7. import ipaddress
  8. from ipwhois import IPWhois
  9. from reportlab.lib.pagesizes import letter
  10. from reportlab.pdfgen import canvas
  11. from datetime import datetime
  12. from concurrent.futures import ThreadPoolExecutor, as_completed
  13.  
  14. def main():
  15. # Define the nameserver you want to query
  16. NAMESERVER = "ns3.my-ndns.com"
  17.  
  18. # Fetch domains associated with the nameserver using curl
  19. url = f"https:/dns.coffee/api/nameservers/{NAMESERVER}"
  20. output_file = "coffee.txt"
  21. print(f"Fetching domains associated with nameserver: {NAMESERVER}")
  22.  
  23. # Execute the curl command
  24. curl_command = ["curl", url, "-o", output_file]
  25. try:
  26. subprocess.run(curl_command, check=True)
  27. except subprocess.CalledProcessError as e:
  28. print(f"Error fetching data from {url}: {e}")
  29. return
  30.  
  31. # Read the content of coffee.txt
  32. with open(output_file, 'r') as f:
  33. content = f.read()
  34.  
  35. # Extract domain names from the JSON response using regular expressions
  36. domains = re.findall(r'"name":\s*"([^"]+)"', content)
  37.  
  38. # Remove duplicates and empty lines
  39. domains = list(set(domain.strip() for domain in domains if domain.strip()))
  40.  
  41. # Exclude known domains if you have a list
  42. known_domains = set()
  43. if os.path.exists('known.txt'):
  44. with open('known.txt', 'r') as f:
  45. known_domains = set(line.strip() for line in f if line.strip())
  46. domains = [domain for domain in domains if domain not in known_domains]
  47.  
  48. print("Processing domains...")
  49.  
  50. # Prepare dictionary to store information
  51. ip_info = {}
  52.  
  53. # Use ThreadPoolExecutor for concurrency
  54. max_workers = 10 # Adjust based on your system's capabilities
  55. with ThreadPoolExecutor(max_workers=max_workers) as executor:
  56. # Submit tasks to the executor
  57. future_to_domain = {executor.submit(process_domain, domain): domain for domain in domains}
  58.  
  59. for future in as_completed(future_to_domain):
  60. domain = future_to_domain[future]
  61. try:
  62. info = future.result()
  63. ip_info[domain] = info
  64. except Exception as e:
  65. print(f"Error processing domain {domain}: {e}")
  66. ip_info[domain] = {'ip': 'Error', 'as_owner': 'Error'}
  67.  
  68. # Save IP information to a file
  69. ip_output_filename = "Domain_IP_AS_Info.txt"
  70. with open(ip_output_filename, 'w') as f:
  71. for domain, info in ip_info.items():
  72. ip = info.get('ip', 'N/A')
  73. as_owner = info.get('as_owner', 'N/A')
  74. f.write(f"{domain}: IP: {ip}, AS: {as_owner}\n")
  75.  
  76. print(f"Domain IP and AS information saved in {ip_output_filename}")
  77.  
  78. # Generate intelligence report PDF for specific AS Owners
  79. print("Generating intelligence report for specified domains...")
  80. generate_pdf_report(ip_info)
  81. print("Intelligence report generated as 'Intel_Report.pdf'")
  82.  
  83. def process_domain(domain):
  84. try:
  85. # Use a specific DNS resolver
  86. resolver = dns.resolver.Resolver()
  87. resolver.nameservers = ['1.1.1.1'] # Cloudflare's DNS resolver
  88.  
  89. answers = resolver.resolve(domain, 'A')
  90. ip_address = answers[0].to_text()
  91.  
  92. # Validate the IP address
  93. try:
  94. ip_address_obj = ipaddress.ip_address(ip_address)
  95. except ValueError:
  96. print(f"{domain} resolves to an invalid IP address {ip_address}.")
  97. return {'ip': 'Invalid IP', 'as_owner': 'N/A'}
  98.  
  99. # Check if the IP is public
  100. if not ip_address_obj.is_global:
  101. print(f"{domain} resolves to a non-public IP address {ip_address}. Skipping RDAP lookup.")
  102. return {'ip': ip_address, 'as_owner': 'Reserved or Private IP'}
  103.  
  104. # Get AS information without connecting to the domain
  105. obj = IPWhois(ip_address)
  106. results = obj.lookup_rdap(depth=1)
  107. asn_description = results.get('asn_description', 'Unknown')
  108. print(f"{domain} resolves to IP {ip_address}, AS: {asn_description}")
  109. return {'ip': ip_address, 'as_owner': asn_description}
  110. except dns.resolver.NoAnswer:
  111. print(f"No DNS answer for domain {domain}.")
  112. return {'ip': 'No Answer', 'as_owner': 'N/A'}
  113. except dns.resolver.NXDOMAIN:
  114. print(f"Domain {domain} does not exist.")
  115. return {'ip': 'NXDOMAIN', 'as_owner': 'N/A'}
  116. except dns.exception.Timeout:
  117. print(f"DNS query for domain {domain} timed out.")
  118. return {'ip': 'Timeout', 'as_owner': 'N/A'}
  119. except Exception as e:
  120. print(f"Error processing domain {domain}: {e}")
  121. return {'ip': 'Error', 'as_owner': 'Error'}
  122.  
  123. def generate_pdf_report(ip_info):
  124. pdf_filename = "Intel_Report.pdf"
  125. c = canvas.Canvas(pdf_filename, pagesize=letter)
  126. width, height = letter
  127. c.setFont("Helvetica", 12)
  128. y = height - 50 # Start from top of the page
  129.  
  130. # Report Title
  131. c.setFont("Helvetica-Bold", 16)
  132. c.drawString(50, y, "Intelligence Report")
  133. y -= 30
  134. c.setFont("Helvetica", 12)
  135. c.drawString(50, y, f"Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
  136. y -= 40
  137.  
  138. # Adjusted keywords to include variations
  139. keywords = ['digitalocean', 'virtuo']
  140.  
  141. # Filter ip_info to include domains with AS Owners containing the keywords
  142. filtered_ip_info = {}
  143. for domain, info in ip_info.items():
  144. as_owner_clean = info.get('as_owner', '').replace(' ', '').lower()
  145. if any(keyword.replace(' ', '') in as_owner_clean for keyword in keywords):
  146. filtered_ip_info[domain] = info
  147.  
  148. if not filtered_ip_info:
  149. c.drawString(50, y, "No domains found with specified AS Owners.")
  150. else:
  151. for domain, info in filtered_ip_info.items():
  152. if y < 100:
  153. c.showPage()
  154. y = height - 50
  155. ip = info.get('ip', 'N/A')
  156. as_owner = info.get('as_owner', 'N/A')
  157. c.setFont("Helvetica-Bold", 14)
  158. c.drawString(50, y, f"Domain: {domain}")
  159. y -= 20
  160. c.setFont("Helvetica", 12)
  161. c.drawString(70, y, f"IP Address: {ip}")
  162. y -= 15
  163. c.drawString(70, y, f"AS Owner: {as_owner}")
  164. y -= 30 # Space before next domain
  165.  
  166. c.save()
  167.  
  168. if __name__ == "__main__":
  169. main()
  170.  
Tags: TLP_R3D
Advertisement
Add Comment
Please, Sign In to add comment