53 - Pentesting DNS

即时可用的漏洞评估和渗透测试设置。从任何地方运行完整的渗透测试,拥有 20 多种工具和功能,从侦察到报告。我们不取代渗透测试人员 - 我们开发定制工具、检测和利用模块,让他们有更多时间深入挖掘、弹出 shell 并享受乐趣。
基本信息
域名系统(DNS) 充当互联网的目录,允许用户通过易记的域名(如 google.com 或 facebook.com)访问网站,而不是数字的互联网协议(IP)地址。通过将域名翻译为 IP 地址,DNS 确保 Web 浏览器可以快速加载互联网资源,简化我们在线世界中的导航。
默认端口: 53
PORT STATE SERVICE REASON
53/tcp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)
5353/udp open zeroconf udp-response
53/udp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)
不同的DNS服务器
DNS根服务器:这些位于DNS层次结构的顶部,管理顶级域,并仅在较低级别服务器不响应时介入。互联网名称分配和编号机构(ICANN)监督它们的运作,全球共有13个。
权威域名服务器:这些服务器对其指定区域的查询拥有最终决定权,提供明确的答案。如果它们无法提供响应,查询将升级到根服务器。
非权威域名服务器:这些服务器没有对DNS区域的所有权,它们通过查询其他服务器收集域信息。
缓存DNS服务器:这种类型的服务器会记住先前查询的答案一段时间,以加快未来请求的响应时间,缓存持续时间由权威服务器决定。
转发服务器:扮演简单角色的转发服务器只是将查询转发到另一个服务器。
解析器:集成在计算机或路由器中,解析器在本地执行名称解析,不被视为权威。
枚举
横幅抓取
DNS中没有横幅,但您可以获取version.bind. CHAOS TXT
的魔术查询,这将适用于大多数BIND域名服务器。
您可以使用dig
执行此查询:
dig version.bind CHAOS TXT @DNS
此外,工具fpdns
也可以对服务器进行指纹识别。
还可以使用nmap脚本获取横幅:
--script dns-nsid
任意记录
ANY 记录将要求 DNS 服务器返回其愿意披露的所有可用条目。
dig any victim.com @<DNS_IP>
区域传送
该过程简称为异步完整传送区域
(AXFR
)。
dig axfr @<DNS_IP> #Try zone transfer without domain
dig axfr @<DNS_IP> <DOMAIN> #Try zone transfer guessing the domain
fierce --domain <DOMAIN> --dns-servers <DNS_IP> #Will try toperform a zone transfer against every authoritative name server and if this doesn'twork, will launch a dictionary attack
更多信息
dig ANY @<DNS_IP> <DOMAIN> #Any information
dig A @<DNS_IP> <DOMAIN> #Regular DNS request
dig AAAA @<DNS_IP> <DOMAIN> #IPv6 DNS request
dig TXT @<DNS_IP> <DOMAIN> #Information
dig MX @<DNS_IP> <DOMAIN> #Emails related
dig NS @<DNS_IP> <DOMAIN> #DNS that resolves that name
dig -x 192.168.0.2 @<DNS_IP> #Reverse lookup
dig -x 2a00:1450:400c:c06::93 @<DNS_IP> #reverse IPv6 lookup
#Use [-p PORT] or -6 (to use ivp6 address of dns)
自动化
for sub in $(cat <WORDLIST>);do dig $sub.<DOMAIN> @<DNS_IP> | grep -v ';\|SOA' | sed -r '/^\s*$/d' | grep $sub | tee -a subdomains.txt;done
dnsenum --dnsserver <DNS_IP> --enum -p 0 -s 0 -o subdomains.txt -f <WORDLIST> <DOMAIN>
使用 nslookup
nslookup
> SERVER <IP_DNS> #Select dns server
> 127.0.0.1 #Reverse lookup of 127.0.0.1, maybe...
> <IP_MACHINE> #Reverse lookup of a machine, maybe...
有用的metasploit模块
auxiliary/gather/enum_dns #Perform enumeration actions
有用的 nmap 脚本
#Perform enumeration actions
nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" <IP>
DNS - 反向 BF
dnsrecon -r 127.0.0.0/24 -n <IP_DNS> #DNS reverse of all of the addresses
dnsrecon -r 127.0.1.0/24 -n <IP_DNS> #DNS reverse of all of the addresses
dnsrecon -r <IP_DNS>/24 -n <IP_DNS> #DNS reverse of all of the addresses
dnsrecon -d active.htb -a -n <IP_DNS> #Zone transfer
另一个工具可以实现这一点:https://github.com/amine7536/reverse-scan
您可以查询反向IP范围到https://bgp.he.net/net/205.166.76.0/24#_dns(此工具在BGP方面也很有帮助)。
DNS - 子域名BF
dnsenum --dnsserver <IP_DNS> --enum -p 0 -s 0 -o subdomains.txt -f subdomains-1000.txt <DOMAIN>
dnsrecon -D subdomains-1000.txt -d <DOMAIN> -n <IP_DNS>
dnscan -d <domain> -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan
Active Directory 服务器
dig -t _gc._tcp.lab.domain.com
dig -t _ldap._tcp.lab.domain.com
dig -t _kerberos._tcp.lab.domain.com
dig -t _kpasswd._tcp.lab.domain.com
nslookup -type=srv _kerberos._tcp.<CLIENT_DOMAIN>
nslookup -type=srv _kerberos._tcp.domain.com
nmap --script dns-srv-enum --script-args "dns-srv-enum.domain='domain.com'"
DNSSec
DNSSec
#Query paypal subdomains to ns3.isc-sns.info
nmap -sSU -p53 --script dns-nsec-enum --script-args dns-nsec-enum.domains=paypal.com ns3.isc-sns.info
IPv6
使用“AAAA”请求进行暴力破解,以收集子域的IPv6地址。
dnsdict6 -s -t <domain>
使用 IPv6 地址进行反向 DNS 暴力破解
Reverse DNS 暴力破解是一种常见的渗透测试技术,用于查找与给定 IPv6 地址相关联的域名。
dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns.ripe.net
DNS递归DDoS
如果启用了DNS递归,攻击者可以伪造UDP数据包中的源,以便使DNS将响应发送到受害者服务器。攻击者可以滥用ANY或DNSSEC记录类型,因为它们通常具有更大的响应。 检查DNS是否支持递归的方法是查询一个域名,并检查响应中是否包含标志"ra"(递归可用):
dig google.com A @<IP>
不可用:

可用:


即时提供漏洞评估和渗透测试设置。从侦察到报告,使用20多种工具和功能运行完整的渗透测试。我们不取代渗透测试人员 - 我们开发定制工具、检测和利用模块,为他们节省时间深入挖掘、弹出shell并享受乐趣。
发送到不存在账户的邮件
通过检查由发送到目标域中无效地址的电子邮件触发的非投递通知(NDN),通常会披露有价值的内部网络详细信息。
提供的非投递报告包括以下信息:
生成服务器被识别为
server.example.com
。返回了针对
[email protected]
的错误代码#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found
的失败通知。原始消息头中披露了内部IP地址和主机名。
The original message headers were modified for anonymity and now present randomized data:
Generating server: server.example.com
[email protected]
#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##
Original message headers:
Received: from MAILSERVER01.domain.example.com (192.168.1.1) by
mailserver02.domain.example.com (192.168.2.2) with Microsoft SMTP Server (TLS)
id 14.3.174.1; Mon, 25 May 2015 14:52:22 -0700
Received: from filter.example.com (203.0.113.1) by
MAILSERVER01.domain.example.com (192.168.1.1) with Microsoft SMTP Server (TLS)
id 14.3.174.1; Mon, 25 May 2015 14:51:22 -0700
X-ASG-Debug-ID: 1432576343-0614671716190e0d0001-zOQ9WJ
Received: from gateway.domainhost.com (gateway.domainhost.com [198.51.100.37]) by
filter.example.com with ESMTP id xVNPkwaqGgdyH5Ag for [email protected]; Mon,
25 May 2015 14:52:13 -0700 (PDT)
X-Envelope-From: [email protected]
X-Apparent-Source-IP: 198.51.100.37
配置文件
host.conf
/etc/resolv.conf
/etc/bind/named.conf
/etc/bind/named.conf.local
/etc/bind/named.conf.options
/etc/bind/named.conf.log
/etc/bind/*
在配置Bind服务器时的危险设置:
选项
描述
allow-query
定义允许向DNS服务器发送请求的主机。
allow-recursion
定义允许向DNS服务器发送递归请求的主机。
allow-transfer
定义允许从DNS服务器接收区域传输的主机。
zone-statistics
收集区域的统计数据。
参考资料
书籍:Network Security Assessment 3rd edition
HackTricks自动命令
Protocol_Name: DNS #Protocol Abbreviation if there is one.
Port_Number: 53 #Comma separated if there is more than one.
Protocol_Description: Domain Name Service #Protocol Abbreviation Spelled out
Entry_1:
Name: Notes
Description: Notes for DNS
Note: |
#These are the commands I run every time I see an open DNS port
dnsrecon -r 127.0.0.0/24 -n {IP} -d {Domain_Name}
dnsrecon -r 127.0.1.0/24 -n {IP} -d {Domain_Name}
dnsrecon -r {Network}{CIDR} -n {IP} -d {Domain_Name}
dig axfr @{IP}
dig axfr {Domain_Name} @{IP}
nslookup
SERVER {IP}
127.0.0.1
{IP}
Domain_Name
exit
https://book.hacktricks.xyz/pentesting/pentesting-dns
Entry_2:
Name: Banner Grab
Description: Grab DNS Banner
Command: dig version.bind CHAOS TXT @DNS
Entry_3:
Name: Nmap Vuln Scan
Description: Scan for Vulnerabilities with Nmap
Command: nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" {IP}
Entry_4:
Name: Zone Transfer
Description: Three attempts at forcing a zone transfer
Command: dig axfr @{IP} && dix axfr @{IP} {Domain_Name} && fierce --dns-servers {IP} --domain {Domain_Name}
Entry_5:
Name: Active Directory
Description: Eunuerate a DC via DNS
Command: dig -t _gc._{Domain_Name} && dig -t _ldap._{Domain_Name} && dig -t _kerberos._{Domain_Name} && dig -t _kpasswd._{Domain_Name} && nmap --script dns-srv-enum --script-args "dns-srv-enum.domain={Domain_Name}"
Entry_6:
Name: consolesless mfs enumeration
Description: DNS enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/dns/dns_amp; set RHOSTS {IP}; set RPORT 53; run; exit' && msfconsole -q -x 'use auxiliary/gather/enum_dns; set RHOSTS {IP}; set RPORT 53; run; exit'

立即提供的漏洞评估和渗透测试设置。从任何地方运行完整的渗透测试,使用20多种工具和功能,从侦察到报告。我们不取代渗透测试人员 - 我们开发定制工具、检测和利用模块,为他们节省时间深入挖掘、弹出shell并享受乐趣。
最后更新于