8.9 KiB
Raw Blame History

53 - Pentesting DNS

{{#include ../banners/hacktricks-training.md}}

基本信息

域名系统 (DNS) 作为互联网的目录,使用户能够通过 易于记忆的域名 访问网站,如 google.com 或 facebook.com而不是数字互联网协议 (IP) 地址。通过将域名转换为 IP 地址DNS 确保网页浏览器能够快速加载互联网资源,简化了我们在在线世界中的导航方式。

默认端口: 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 record

记录 ANY 将请求 DNS 服务器 返回 所有可用的 条目,这些 条目它愿意披露 的。

dig any victim.com @<DNS_IP>

区域传输

此过程缩写为 Asynchronous Full Transfer Zone (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 - 反向暴力破解

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

Note

如果您能够找到解析到内部IP地址的子域名您应该尝试对该IP范围的域名的NS进行反向DNS暴力破解。

另一个工具可以做到这一点: https://github.com/amine7536/reverse-scan

您可以查询反向IP范围到 https://bgp.he.net/net/205.166.76.0/24#_dns这个工具在BGP方面也很有帮助

DNS - 子域名暴力破解

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

活动目录服务器

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

#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

dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns.ripe.net

DNS 递归 DDoS

如果 DNS 递归已启用,攻击者可以 伪造 UDP 数据包中的 ,以使 DNS 将响应发送到受害者服务器。攻击者可以滥用 ANYDNSSEC 记录类型,因为它们通常具有更大的响应。
检查 DNS 是否支持 递归 的方法是查询一个域名并 检查 响应中是否包含 标志 "ra" (递归可用)

dig google.com A @<IP>

不可用

可用

发送到不存在的账户

向不存在的地址发送电子邮件使用受害者的域可能会触发受害者发送一条未送达通知NDN消息头部可能包含有趣的信息,例如内部服务器的名称和IP地址

后期利用

  • 检查Bind服务器的配置时检查参数**allow-transfer的配置,因为它指示谁可以执行区域传输,以及allow-recursionallow-query**,因为它们指示谁可以向其发送递归请求和请求。
  • 以下是可能在机器内部搜索的与DNS相关的文件名称
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/*

参考

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.wiki/en/todo/pentesting-dns.html

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'

{{#include ../banners/hacktricks-training.md}}