53 - Pentesting DNS

支持 HackTricks

即时可用的漏洞评估与渗透测试设置。从任何地方运行完整的渗透测试,提供 20 多种工具和功能,从侦察到报告。我们不替代渗透测试人员 - 我们开发自定义工具、检测和利用模块,以便让他们有更多时间深入挖掘、获取 shell 并享受乐趣。

基本信息

域名系统 (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

如果您能够找到解析到内部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 Recursion DDoS

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

dig google.com A @<IP>

不可用

可用

即时可用的漏洞评估和渗透测试设置。从任何地方运行完整的渗透测试,提供20多个工具和功能,从侦察到报告。我们不替代渗透测试人员 - 我们开发自定义工具、检测和利用模块,以便让他们有更多时间深入挖掘、获取shell并享受乐趣。

邮件发送至不存在的账户

通过检查因发送至目标域内无效地址而触发的未送达通知(NDN),通常会泄露有价值的内部网络细节。

提供的未送达报告包括以下信息:

  • 生成服务器被识别为 server.example.com

  • 返回了 user@example.com 的失败通知,错误代码为 #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

user@example.com
#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 user@example.com; Mon,
25 May 2015 14:52:13 -0700 (PDT)
X-Envelope-From: sender@anotherdomain.org
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

收集区域的统计数据。

参考文献

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并享受乐趣。

支持HackTricks

Last updated