Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DNS name resolution capability to ctfr #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 70 additions & 46 deletions ctfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,95 @@
# -*- 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 json
import requests
import dns.resolver

## # CONTEXT VARIABLES # ##
version = 1.1

## # 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.")
parser.add_argument('-r', '--resolve', action='store_true', help="Perform DNS Name Resolution.")

return parser.parse_args()

def banner():
global version
from pyfiglet import figlet_format
b = figlet_format(" CTFR") + \
''' Version {v} - Hey don't miss AXFR!
global version
from pyfiglet import figlet_format
b = figlet_format(" CTFR") + \
''' Version {v} - Hey don't miss AXFR!
Made by Sheila A. Berta (UnaPibaGeek)
'''.format(v=version)
print(b)
'''.format(v=version)
print(b)

def save_subdomains(subdomain,output_file):
with open(output_file,"a") as f:
f.write(subdomain + '\n')
f.close()
with open(output_file,"a") as f:
f.write(subdomain + '\n')
f.close()

def main():
banner()
args = parse_args()

subdomains = []
target = args.domain
output = args.output

req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=target))

if req.status_code != 200:
print("[X] Error! Invalid domain or information not available!")
exit(1)

json_data = json.loads('[{}]'.format(req.text.replace('}{', '},{')))

for (key,value) in enumerate(json_data):
subdomains.append(value['name_value'])


print("\n[!] ---- TARGET: {d} ---- [!] \n".format(d=target))

subdomains = sorted(set(subdomains))

for subdomain in subdomains:
print("[-] {s}".format(s=subdomain))
if output is not None:
save_subdomains(subdomain,output)

print("\n\n[!] Done. Have a nice day! ;).")

banner()
args = parse_args()

subdomains = []
target = args.domain
output = args.output
resolve = args.resolve

req = requests.get("https://crt.sh/?q=%.{d}&output=json".format(d=target))

if req.status_code != 200:
print("[-] Error! Invalid domain or information not available!")
exit(1)

json_data = json.loads('[{}]'.format(req.text.replace('}{', '},{')))

for (key,value) in enumerate(json_data):
subdomains.append(value['name_value'])


print("\n[!] ---- TARGET: {d} ---- [!] \n".format(d=target))

subdomains = sorted(set(subdomains))

# Perform DNS resolution
if resolve is not False:
resolver = dns.resolver.Resolver()
for subdomain in subdomains:
try:
response = resolver.query(subdomain,"A")
ips = []
for ip in response:
ips.append(str(ip))
except KeyboardInterrupt:
print("[*] Caught Keyboard Interrupt! Exiting...\n")
exit(1)
except:
ips = ''

ips = ','.join(ips)
print("{s}:{i}".format(s=subdomain,i=ips))
# Continue without DNS resolution
else:
for subdomain in subdomains:
print("{s}".format(s=subdomain))

# Save domains to output file
if output is not None:
save_subdomains(subdomain,output)

print("\n\n[!] Done. Have a nice day! ;).")

main()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests
pyfiglet
pyfiglet
dnspython