diff --git a/ctfr.py b/ctfr.py index 36a2ea1..70fea2f 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()