Skip to content

Commit

Permalink
ipwhois removed
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhiteh4t committed Oct 19, 2023
1 parent ab0c7bf commit c69c355
Show file tree
Hide file tree
Showing 3 changed files with 1,455 additions and 32 deletions.
11 changes: 8 additions & 3 deletions finalrecon.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ def banner():
print(f'{G}[+] {C}Target : {W}{target}')
ext = tldextract.extract(target)
domain = ext.registered_domain
hostname = '.'.join(part for part in ext if part)
domain_suffix = ext.suffix

if ext.subdomain:
hostname = f'{ext.subdomain}.{ext.domain}.{ext.suffix}'
else:
hostname = domain

try:
ipaddress.ip_address(hostname)
Expand Down Expand Up @@ -189,7 +194,7 @@ def banner():

headers(target, out_settings, data)
cert(hostname, sslp, out_settings, data)
whois_lookup(ip, out_settings, data)
whois_lookup(domain, domain_suffix, path_to_script, out_settings, data)
dnsrec(domain, out_settings, data)
if not type_ip:
subdomains(domain, tout, out_settings, data, conf_path)
Expand All @@ -211,7 +216,7 @@ def banner():
if whois:
from modules.whois import whois_lookup
log_writer('Starting whois enum...')
whois_lookup(ip, out_settings, data)
whois_lookup(domain, domain_suffix, path_to_script, out_settings, data)

if crawl:
from modules.crawler import crawler
Expand Down
70 changes: 41 additions & 29 deletions modules/whois.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import ipwhois
import asyncio
from json import load
from modules.export import export
from modules.write_log import log_writer

Expand All @@ -11,40 +12,51 @@
Y = '\033[33m' # yellow


def whois_lookup(ip_addr, output, data):
async def get_whois(domain, server):
whois_result = {}
reader, writer = await asyncio.open_connection(server, 43)
writer.write((domain + '\r\n').encode())

raw_resp = b''
while True:
chunk = await reader.read(4096)
if not chunk:
break
raw_resp += chunk

writer.close()
await writer.wait_closed()
raw_result = raw_resp.decode()

if 'No match for' in raw_result:
whois_result = None

res_parts = raw_result.split('>>>', 1)
whois_result['whois'] = res_parts[0]
return whois_result


def whois_lookup(domain, tld, script_path, output, data):
result = {}
db_path = f'{script_path}/whois_servers.json'
with open(db_path, 'r') as db_file:
db_json = load(db_file)
print(f'\n{Y}[!] Whois Lookup : {W}\n')

try:
lookup = ipwhois.IPWhois(ip_addr)
results = lookup.lookup_whois()

for key, val in results.items():
if val is not None:
if isinstance(val, list):
for item in val:
for key, value in item.items():
if value is not None:
if not isinstance(value, list):
temp_val = value.replace(',', ' ').replace('\r', ' ').replace('\n', ' ')
print(f'{G}[+] {C}{key}: {W}{temp_val}')
if output != 'None':
result.update({str(key): str(temp_val)})
else:
temp_val = ', '.join(value)
print(f'{G}[+] {C}{key}: {W}{temp_val}')
if output != 'None':
result.update({str(key): str(temp_val)})
else:
temp_val = val.replace(',', ' ').replace('\r', ' ').replace('\n', ' ')
print(f'{G}[+] {C}{key}: {W}{temp_val}')
if output != 'None':
result.update({str(key): str(temp_val)})
whois_sv = db_json[tld]
whois_info = asyncio.run(get_whois(domain, whois_sv))
print(whois_info['whois'])
result.update(whois_info)
except KeyError:
print(f'{R}[-] Error : {C}This domain suffix is not supported.{W}')
result.update({'Error': 'This domain suffix is not supported.'})
log_writer('[whois] Exception = This domain suffix is not supported.')
except Exception as exc:
print(f'{R}[-] Error : {C}{exc}{W}')

if output != 'None':
result.update({'Error': str(exc)})
result.update({'Error': str(exc)})
log_writer(f'[whois] Exception = {exc}')

result.update({'exported': False})

if output != 'None':
Expand Down
Loading

0 comments on commit c69c355

Please sign in to comment.