From c664ab4cb24c05bb5a8bf9782ec86fc6ee2310fe Mon Sep 17 00:00:00 2001 From: Corvus DDoSKrom <60022643+Corvus-DDoSKrom@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:17:33 -0300 Subject: [PATCH 1/2] btain the IP addresses corresponding to each subdomain --- ctfr.py | 93 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/ctfr.py b/ctfr.py index 36a2ea1..7330b61 100644 --- a/ctfr.py +++ b/ctfr.py @@ -2,13 +2,14 @@ # -*- coding: utf-8 -*- """ ------------------------------------------------------------------------------ - CTFR - 04.03.18.02.10.00 - Sheila A. Berta (UnaPibaGeek) + CTFR - 04.03.18.02.10.00 - Sheila A. Berta (UnaPibaGeek) ------------------------------------------------------------------------------ """ ## # LIBRARIES # ## import re import requests +import socket # Import the library to resolve IP addresses ## # CONTEXT VARIABLES # ## version = 1.2 @@ -16,15 +17,15 @@ ## # MAIN FUNCTIONS # ## def parse_args(): - import argparse - parser = argparse.ArgumentParser() - parser.add_argument('-d', '--domain', type=str, required=True, help="Target domain.") - parser.add_argument('-o', '--output', type=str, help="Output file.") - return parser.parse_args() + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('-d', '--domain', type=str, required=True, help="Target domain.") + parser.add_argument('-o', '--output', type=str, help="Output file.") + return parser.parse_args() def banner(): - global version - b = ''' + global version + b = ''' ____ _____ _____ ____ / ___|_ _| ___| _ \ | | | | | |_ | |_) | @@ -33,46 +34,64 @@ def banner(): Version {v} - Hey don't miss AXFR! Made by Sheila A. Berta (UnaPibaGeek) - '''.format(v=version) - print(b) - + '''.format(v=version) + print(b) + def clear_url(target): - return re.sub('.*www\.','',target,1).split('/')[0].strip() + return re.sub('.*www\.','',target,1).split('/')[0].strip() + +def save_subdomains(subdomain, ip, output_file): + with open(output_file,"a") as f: + f.write(f"{subdomain} - {ip}\n") + f.close() -def save_subdomains(subdomain,output_file): - with open(output_file,"a") as f: - f.write(subdomain + '\n') - f.close() +def resolve_ip(subdomain): + try: + ip = socket.gethostbyname(subdomain) + return ip + except socket.error: + return "N/A" def main(): - banner() - args = parse_args() + banner() + args = parse_args() - subdomains = [] - target = clear_url(args.domain) - output = args.output + subdomains = [] + target = clear_url(args.domain) + output = args.output - req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=target)) + try: + req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=target)) - if req.status_code != 200: - print("[X] Information not available!") - exit(1) + req.raise_for_status() # Throw an exception if the request was not successful - for (key,value) in enumerate(req.json()): - subdomains.append(value['name_value']) + json_data = req.json() - - print("\n[!] ---- TARGET: {d} ---- [!] \n".format(d=target)) + for (key, value) in enumerate(json_data): + subdomain = value['name_value'] + ip = resolve_ip(subdomain) + subdomains.append((subdomain, ip)) - subdomains = sorted(set(subdomains)) + print("\n[!] ---- TARGET: {d} ---- [!] \n".format(d=target)) - for subdomain in subdomains: - print("[-] {s}".format(s=subdomain)) - if output is not None: - save_subdomains(subdomain,output) + subdomains = sorted(set(subdomains)) - print("\n\n[!] Done. Have a nice day! ;).") + for subdomain, ip in subdomains: + print("[-] {s} - {ip}".format(s=subdomain, ip=ip)) + if output is not None: + save_subdomains(subdomain, ip, output) + print("\n\n[!] Done. Have a nice day! ;).") -main() - + except requests.exceptions.HTTPError as e: + print(f"[X] HTTP error occurred: {e}") + except requests.exceptions.RequestException as e: + print(f"[X] Request error occurred: {e}") + except requests.exceptions.JSONDecodeError as e: + print(f"[X] JSON decoding error occurred: {e}") + print("[X] Unable to parse JSON response. Please check the response manually.") + print("[X] Response content:") + print(req.text) + +if __name__ == "__main__": + main() From 90c4b3af6209592af5213060f28887d496175e94 Mon Sep 17 00:00:00 2001 From: Corvus DDoSKrom <60022643+Corvus-DDoSKrom@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:18:54 -0300 Subject: [PATCH 2/2] Obtain the IP addresses corresponding to each subdomain --- ctfr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctfr.py b/ctfr.py index 7330b61..70fea2f 100644 --- a/ctfr.py +++ b/ctfr.py @@ -9,7 +9,7 @@ ## # LIBRARIES # ## import re import requests -import socket # Import the library to resolve IP addresses +import socket # Import the library to resolve IP addresses. ## # CONTEXT VARIABLES # ## version = 1.2 @@ -63,7 +63,7 @@ def main(): try: req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=target)) - req.raise_for_status() # Throw an exception if the request was not successful + req.raise_for_status() # Throw an exception if the request was not successful. json_data = req.json()