2022-07-18 23:59:14 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-04-20 16:19:55 +00:00
|
|
|
from datetime import datetime
|
2023-09-14 21:07:15 +00:00
|
|
|
from nxc.helpers.logger import write_log
|
2018-01-23 00:45:56 +00:00
|
|
|
|
|
|
|
|
2023-09-17 20:20:40 +00:00
|
|
|
class NXCModule:
|
2023-03-31 17:49:25 +00:00
|
|
|
"""
|
|
|
|
Uses WMI to dump DNS from an AD DNS Server.
|
|
|
|
Module by @fang0654
|
|
|
|
"""
|
2023-05-02 15:17:59 +00:00
|
|
|
|
2023-04-04 13:39:54 +00:00
|
|
|
name = "enum_dns"
|
|
|
|
description = "Uses WMI to dump DNS from an AD DNS Server"
|
2023-09-01 13:49:57 +00:00
|
|
|
supported_protocols = ["smb", "wmi"]
|
2023-04-04 13:39:54 +00:00
|
|
|
opsec_safe = True
|
|
|
|
multiple_hosts = True
|
|
|
|
|
2023-03-31 17:49:25 +00:00
|
|
|
def __init__(self, context=None, module_options=None):
|
|
|
|
self.context = context
|
|
|
|
self.module_options = module_options
|
|
|
|
self.domains = None
|
2018-01-23 00:45:56 +00:00
|
|
|
|
|
|
|
def options(self, context, module_options):
|
2023-03-31 17:49:25 +00:00
|
|
|
"""
|
|
|
|
DOMAIN Domain to enumerate DNS for. Defaults to all zones.
|
|
|
|
"""
|
2018-01-23 00:45:56 +00:00
|
|
|
self.domains = None
|
2023-05-02 15:17:59 +00:00
|
|
|
if module_options and "DOMAIN" in module_options:
|
|
|
|
self.domains = module_options["DOMAIN"]
|
2018-01-23 00:45:56 +00:00
|
|
|
|
|
|
|
def on_admin_login(self, context, connection):
|
|
|
|
if not self.domains:
|
|
|
|
domains = []
|
2023-05-08 18:39:36 +00:00
|
|
|
output = connection.wmi("Select Name FROM MicrosoftDNS_Zone", "root\\microsoftdns")
|
2018-01-23 00:45:56 +00:00
|
|
|
|
|
|
|
if output:
|
|
|
|
for result in output:
|
2023-05-02 15:17:59 +00:00
|
|
|
domains.append(result["Name"]["value"])
|
2018-01-23 00:45:56 +00:00
|
|
|
|
2023-05-02 15:17:59 +00:00
|
|
|
context.log.success("Domains retrieved: {}".format(domains))
|
2018-01-23 00:45:56 +00:00
|
|
|
else:
|
|
|
|
domains = [self.domains]
|
|
|
|
data = ""
|
|
|
|
for domain in domains:
|
2023-05-02 15:17:59 +00:00
|
|
|
output = connection.wmi(
|
|
|
|
f"Select TextRepresentation FROM MicrosoftDNS_ResourceRecord WHERE DomainName = {domain}",
|
|
|
|
"root\\microsoftdns",
|
|
|
|
)
|
|
|
|
|
2018-01-23 00:45:56 +00:00
|
|
|
if output:
|
|
|
|
domain_data = {}
|
2023-03-31 17:49:25 +00:00
|
|
|
context.log.highlight(f"Results for {domain}")
|
|
|
|
data += f"Results for {domain}\n"
|
2018-01-23 00:45:56 +00:00
|
|
|
for entry in output:
|
2023-05-02 15:17:59 +00:00
|
|
|
text = entry["TextRepresentation"]["value"]
|
|
|
|
rname = text.split(" ")[0]
|
|
|
|
rtype = text.split(" ")[2]
|
|
|
|
rvalue = " ".join(text.split(" ")[3:])
|
2018-01-23 00:45:56 +00:00
|
|
|
if domain_data.get(rtype, False):
|
2023-03-31 17:49:25 +00:00
|
|
|
domain_data[rtype].append(f"{rname}: {rvalue}")
|
2018-01-23 00:45:56 +00:00
|
|
|
else:
|
2023-03-31 17:49:25 +00:00
|
|
|
domain_data[rtype] = [f"{rname}: {rvalue}"]
|
2018-01-23 00:45:56 +00:00
|
|
|
|
2019-11-10 23:12:35 +00:00
|
|
|
for k, v in sorted(domain_data.items()):
|
2023-03-31 17:49:25 +00:00
|
|
|
context.log.highlight(f"Record Type: {k}")
|
|
|
|
data += f"Record Type: {k}\n"
|
2018-01-23 00:45:56 +00:00
|
|
|
for d in sorted(v):
|
2023-05-02 15:17:59 +00:00
|
|
|
context.log.highlight("\t" + d)
|
2018-01-23 00:45:56 +00:00
|
|
|
data += "\t" + d + "\n"
|
|
|
|
|
2023-08-30 03:43:02 +00:00
|
|
|
log_name = "DNS-Enum-{}-{}.log".format(connection.host, datetime.now().strftime("%Y-%m-%d_%H%M%S"))
|
2018-01-23 00:45:56 +00:00
|
|
|
write_log(data, log_name)
|
2023-09-14 21:07:15 +00:00
|
|
|
context.log.display(f"Saved raw output to ~/.nxc/logs/{log_name}")
|