Massdns 高性能 DNS 存根解析器,用于批量查找和侦察

高性能 DNS 存根解析器

MassDNS 是一款简单的高性能 DNS 存根解析器,专门针对那些希望解析数百万甚至数十亿个域名的用户。无需特殊配置,MassDNS 便能够使用公开可用的解析器每秒解析超过 350,000 个名称。

贡献者

汇编

将 git 存储库和克隆cd到项目根文件夹中。然后运行make以从源代码构建。如果您不是在 Linux 上,请运行make nolinux。在 Windows 上,Cygwingcc-coregitmake是必需的。

用法

Usage: ./bin/massdns [options] [domainlist]
  -b  --bindto           Bind to IP address and port. (Default: 0.0.0.0:0)
      --busy-poll        Use busy-wait polling instead of epoll.
  -c  --resolve-count    Number of resolves for a name before giving up. (Default: 50)
      --drop-group       Group to drop privileges to when running as root. (Default: nogroup)
      --drop-user        User to drop privileges to when running as root. (Default: nobody)
      --extended-input   Input names are followed by a space-separated list of resolvers.
                         These are used before falling back to the resolvers file.
      --filter           Only output packets with the specified response code.
      --flush            Flush the output file whenever a response was received.
  -h  --help             Show this help.
      --ignore           Do not output packets with the specified response code.
  -i  --interval         Interval in milliseconds to wait between multiple resolves of the same
                         domain. (Default: 500)
  -l  --error-log        Error log file path. (Default: /dev/stderr)
      --norecurse        Use non-recursive queries. Useful for DNS cache snooping.
  -o  --output           Flags for output formatting.
      --predictable      Use resolvers incrementally. Useful for resolver tests.
      --processes        Number of processes to be used for resolving. (Default: 1)
  -q  --quiet            Quiet mode.
      --rand-src-ipv6    Use a random IPv6 address from the specified subnet for each query.
      --rcvbuf           Size of the receive buffer in bytes.
      --retry            Unacceptable DNS response codes.
                         (Default: All codes but NOERROR or NXDOMAIN)
  -r  --resolvers        Text file containing DNS resolvers.
      --root             Do not drop privileges when running as root. Not recommended.
  -s  --hashmap-size     Number of concurrent lookups. (Default: 10000)
      --sndbuf           Size of the send buffer in bytes.
      --status-format    Format for real-time status updates, json or ansi (Default: ansi)
      --sticky           Do not switch the resolver when retrying.
      --socket-count     Socket count per process. (Default: 1)
  -t  --type             Record type to be resolved. (Default: A)
      --verify-ip        Verify IP addresses of incoming replies.
  -w  --outfile          Write to the specified output file instead of standard output.

Output flags:
  L - domain list output
  S - simple text output
  F - full text output
  B - binary output
  J - ndjson output

Advanced flags for the domain list output mode:
  0 - Include NOERROR replies without answers.

Advanced flags for the simple output mode:
  d - Include records from the additional section.
  i - Indent any reply record.
  l - Separate replies using a line feed.
  m - Only output reply records that match the question name.
  n - Include records from the answer section.
  q - Print the question.
  r - Print the question with resolver IP address, Unix timestamp and return code prepended.
  s - Separate packet sections using a line feed.
  t - Include TTL and record class within the output.
  u - Include records from the authority section.

Advanced flags for the ndjson output mode:
  e - Write a record for each terminal query failure.

有关命令行界面的详细描述,请使用 查阅手册页man ./doc/massdns.1

例子

resolvers.txt使用内的解析器解析 domains.txt 中域的所有 AAAA 记录lists,并将结果存储在 results.txt 中:

$ ./bin/massdns -r lists/resolvers.txt -t AAAA domains.txt > results.txt

这相当于:

$ ./bin/massdns -r lists/resolvers.txt -t AAAA -w results.txt domains.txt

示例输出

默认情况下,MassDNS 将以文本格式输出响应数据包,类似于以下内容:

;; Server: 77.41.229.2:53
;; Size: 93
;; Unix time: 1513458347
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51298
;; flags: qr rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0

;; QUESTION SECTION:
example.com. IN A

;; ANSWER SECTION:
example.com. 45929 IN A 93.184.216.34

;; AUTHORITY SECTION:
example.com. 24852 IN NS b.iana-servers.net.
example.com. 24852 IN NS a.iana-servers.net.

包含解析器 IP 地址是为了让您在检测到某些解析器产生不良结果时更轻松地过滤输出。

解析

该存储库包含由subbrute 项目resolvers.txt提供的解析器筛选子集的文件。请注意,使用 MassDNS 可能会对使用的解析器造成很大负载,并导致向您的 ISP 发送滥用投诉。另请注意,提供的解析器不保证是值得信赖的。解析器列表目前已过时,大部分解析器功能失调。

MassDNS 的自定义、无 malloc 的 DNS 实现目前仅支持最常见的记录。欢迎您通过协作来帮助改变这种情况。

PTR 记录

MassDNS 包含一个 Python 脚本,允许您通过将各自的查询打印到标准输出来解析所有 IPv4 PTR 记录。

$ ./scripts/ptr.py | ./bin/massdns -r lists/resolvers.txt -t PTR -w ptr.txt

请注意,其中in-addr.arpa的标签是反转的。为了解析域名1.2.3.4,MassDNS 需要4.3.2.1.in-addr.arpa输入查询名称。因此,Python 脚本不会按升序解析记录,这是一个优点,因为可以避免 IPv4 子网的名称服务器突然出现大峰值。

通过暴力破解子域名进行侦察

负责任地执行侦察扫描并调整-s参数以免压垮权威名称服务器。

与subbrute类似,MassDNS 允许你使用附带的脚本对子域名进行暴力破解subbrute.py

$ ./scripts/subbrute.py example.com lists/names.txt | ./bin/massdns -r lists/resolvers.txt -t A -o S -w results.txt

作为一种额外的侦察方法,该脚本通过从crt.shct.py中抓取数据来从证书透明度日志中提取子域:

$ ./scripts/ct.py example.com | ./bin/massdns -r lists/resolvers.txt -t A -o S -w results.txt

从subbrute 项目复制的文件names.txt和包含常用子域名的名称。还可以考虑使用Jason Haddix 的子域名汇编(包含超过 1,000,000 个名称)或Assetnote 单词表(包含超过 9,000,000 万个名称)。names_small.txt

MassDNS 还在文件夹中包含一个recon.py包装器脚本(测试状态)scripts,该脚本直接针对权威名称服务器执行子域名枚举,因此不需要第三方解析器。并发性由 MassDNS 自动确定,每秒支持数十万次查询,同时提供可靠的结果。在廉价的专用服务器上,Assetnode 单词表可以在不到一分钟的时间内枚举完成。当前的限制是区域委派仅处理到委派点。例如,如果example.org枚举并sub.example.org委派给另一个名称服务器,则如果包含在单词列表中,abc.sub.example.org则此脚本将找不到。但是,脚本将报告此事实,就像在这种情况下一样。abc.sub?.sub.example.org

$ ./scripts/recon.py -d google.com -l lists/best-dns-wordlist.txt > google.txt

截图

截屏

安全

MassDNS 不需要 root 权限,因此在以 root 身份运行时,默认情况下会将权限放弃给名为“nobody”的用户。如果用户“nobody”不存在,MassDNS 将拒绝执行。在这种情况下,建议以另一个非特权用户身份运行 MassDNS。可以使用--root不推荐的参数来规避权限放弃。另请注意,除了 master 之外的其他分支根本不应在生产中使用。

实际考虑

性能调优

MassDNS 是一个简单的单线程应用程序,专为网络成为瓶颈的情况而设计。它旨在在具有高上传和下载带宽的服务器上运行。在内部,MassDNS 使用哈希图来控制查找的并发性。-s因此,设置大小参数允许您控制查找率。如果您遇到性能问题,请尝试调整-s参数以获得更好的成功率。

逃避速率限制

如果 IPv6 解析器的速率限制是个问题,你可以使用--rand-src-ipv6 <your_ipv6_prefix>。然后,MassDNS 将使用原始套接字发送和接收 DNS 数据包,并为每个查询从指定的前缀中随机挑选一个源 IPv6 地址。这要求 MassDNS 以CAP_NET_RAW特权运行。使用此方法时,你应该拥有iptablesnftables丢弃 MassDNS 收到的 DNS 流量,以使Port unreachable操作系统不会生成任何 ICMP 响应,例如使用ip6tables -p udp --sport 53 -I INPUT -j DROP。请注意,此规则仅是示例,将丢弃所有 DNS 流量,包括其他应用程序的流量。你可能希望调整规则以更细粒度地适合你的用例。

结果真实性

如果结果的真实性至关重要,则不应依赖包含的解析器列表。相反,应设置本地未绑定解析器并向 MassDNS 提供其 IP 地址。如果您使用 MassDNS 作为侦察工具,您可能希望先使用默认解析器列表运行它,然后使用受信任的解析器列表对找到的名称重新运行它,以消除误报。

如果您要枚举单个名称的子域,例如example.com,您可能希望简单地忽略第三方解析器。在这种情况下,您可以直接探测权威名称服务器,如下所示:

$ ./bin/massdns -r <(./scripts/auth-addrs.sh example.com) --norecurse -o Je example-com-subdomains.txt > results.txt

国内下载链接

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享