Skip to content

Commit

Permalink
Merge pull request #162 from filippolauria/master
Browse files Browse the repository at this point in the history
rewritten make_csv() function.
  • Loading branch information
L1ghtn1ng authored Feb 7, 2021
2 parents f840481 + 772757b commit 819ebc1
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions dnsrecon.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ def brute_tlds(res, domain, verbose=False, thread_num=None):
domain_main = domain.split(".")[0]

# Let the user know how long it could take
print_status("The operation could take up to: {0}".format(
time.strftime('%H:%M:%S', time.gmtime((len(itld) + len(gtld) + len(grtld) + len(stld) + len(cctld)) / 3))))
all_tlds_len = len(itld) + len(gtld) + len(grtld) + len(stld) + len(cctld)
duration = time.strftime('%H:%M:%S', time.gmtime(all_tlds_len / 3))
print_status(f"The operation could take up to: {duration}")

total_tlds = list(set(itld + gtld + grtld + stld))

Expand All @@ -305,12 +306,13 @@ def brute_tlds(res, domain, verbose=False, thread_num=None):

except Exception as e:
print_error(e)

found_tlds = []
for rcd_found in brtdata:
for rcd in rcd_found:
if re.search(r"^A", rcd[0]):
print_good({"type": rcd[0], "name": rcd[1], "address": rcd[2]})
found_tlds.append([{"type": rcd[0], "name": rcd[1], "address": rcd[2]}])
for type_, name_, addr_ in rcd_found:
if type_ in ['A', 'AAAA']:
print_good(f"\t {type_} {name_} {addr_}")
found_tlds.append([{"type": type_, "name": name_, "address": addr_}])
print_good(f"{len(found_tlds)} Records Found")
return found_tlds

Expand Down Expand Up @@ -675,49 +677,50 @@ def create_db(db):

def make_csv(data):
csv_data = "Type,Name,Address,Target,Port,String\n"
for n in data:
for record in data:
# make sure that we are working with a dictionary.
if isinstance(n, dict):
print(n)
if n['type'] in ['PTR', 'A', 'AAAA']:
csv_data += n["type"] + "," + n["name"] + "," + n["address"] + "\n"
if not isinstance(record, dict):
continue

elif re.search(r"NS$", n["type"]):
csv_data += n["type"] + "," + n["target"] + "," + n["address"] + "\n"
type_ = record['type'].upper()
csv_data += type_ + ","

elif re.search(r"SOA", n["type"]):
csv_data += n["type"] + "," + n["mname"] + "," + n["address"] + "\n"
if type_ in ['PTR', 'A', 'AAAA', 'NS', 'SOA', 'MX']:

elif re.search(r"MX", n["type"]):
csv_data += n["type"] + "," + n["exchange"] + "," + n["address"] + "\n"
if type_ in ['PTR', 'A', 'AAAA']:
csv_data += record["name"]
elif type_ == 'NS':
csv_data += record["target"]
elif type_ == 'SOA':
csv_data += record["mname"]
elif type_ == 'MX':
csv_data += record["exchange"]

elif re.search(r"SPF", n["type"]):
if "zone_server" in n:
csv_data += n["type"] + ",,,,,\'" + n["strings"] + "\'\n"
else:
csv_data += n["type"] + ",,,,,\'" + n["strings"] + "\'\n"
csv_data += "," + record['address'] + ("," * 3) + "\n"

elif re.search(r"TXT", n["type"]):
if "zone_server" in n:
csv_data += n["type"] + ",,,,,\'" + n["strings"] + "\'\n"
else:
csv_data += n["type"] + "," + n["name"] + ",,,,\'" + n["strings"] + "\'\n"
elif type_ in ['TXT', 'SPF']:
if 'zone_server' not in record:
csv_data += record['name']

elif re.search(r"SRV", n["type"]):
csv_data += n["type"] + "," + n["name"] + "," + n["address"] + "," + n["target"] + "," + n["port"] + "\n"
csv_data += ("," * 4) + "'{}'\n".format(record['strings'])

elif re.search(r"CNAME", n["type"]):
if "target" not in n.keys():
n["target"] = ""
csv_data += n["type"] + "," + n["name"] + ",," + n["target"] + ",\n"
elif type_ == 'SRV':
items = [record["name"], record["address"],
record["target"], record["port"]]
csv_data += ",".join(items) + ",\n"

else:
# Handle not common records
t = n["type"]
del n["type"]
record_data = "".join(["%s =%s," % (key, value) for key, value in n.items()])
records = [t, record_data]
csv_data + records[0] + ",,,,," + records[1] + "\n"
elif type_ == 'CNAME':
csv_data += record['name'] + ("," * 2)
if 'target' in record:
csv_data += record['target']

csv_data += ("," * 2) + "\n"

else:
# Handle not common records
del record["type"]
s = "; ".join([f"{k}={v}" for k, v in record.items()])
csv_data += ("," * 4) + f"'{s}'\n"

return csv_data

Expand Down

0 comments on commit 819ebc1

Please sign in to comment.