A-A+

渗透测试之子域名探测指南

2018年12月11日 文章转载 暂无评论 阅读 5,590 views 次
原文链接:https://blog.appsecco.com/a-penetration-testers-guide-to-sub-domain-enumeration-7d842d5570f6

前言

作为一名渗透测试人员,或者说一个漏洞赏金猎人,一般情况下,当您进行安全测试时,您将获得一个或一组域名。您必须进行广泛的信息搜集,以找到有用的信息,如服务器,Web应用程序,属于目标组织的域等,从而增加您找到漏洞的机会。

我们撰写了一篇关于技术博文(https://blog.appsecco.com/open-source-intelligence-gathering-101-d2861d4429e3) ,这些技术通常用于信息搜集阶段。

子域名探测是信息搜集阶段的重要组成部分,这篇博文以简洁明了的方式介绍了各种子域名探测技术。

这篇博文的后续内容将用gitbook的形式发布,内容将涉及我们对这些技术的深入介绍。我们在2017年Bugcrowd LevelUp会议上发表的"Esoteric子域名探测技术"(https://github.com/appsecco/bugcrowd-levelup-subdomain-enumeration) 演讲中介绍了一些技巧。

除了本博文中的内容之外,我们还发布了一本gitbook,其中涵盖了更多技术:gitbook - 子域名探测的艺术(https://appsecco.com/books/subdomain-enumeration/)

什么是子域名探测?

子域名探测是查找一个或多个域的子域名的过程。这是信息搜集阶段的重要组成部分。

为什么要进行子域名探测?

  • 子域名探测可以帮我们发现渗透测试中更多的服务,这将增加发现漏洞的可能性
  • 查找一些用户上较少,被人遗忘的子域名,其上运行的应用程序可能会使我们发现关键漏洞
  • 通常,同一组织的不同域名/应用程序中存在相同的漏洞

著名的Yahoo! Voices hack就是因为其在yahoo.com子域名上部署了易受攻击的应用程序

子域名探测技术

1.Google和Bing等搜索引擎支持各种高级搜索运算符来优化搜索查询:

  • 我们可以在Google搜索中使用 site:运算符来查找一个域的所有子域名。谷歌还额外支持减号运算符site:*.wikimedia.org -www -store -jobs -uk以排除我们不感兴趣的子域名

Bing搜索引擎也支持一些高级搜索运算符。与Google一样,Bing也支持site:运算符,可以帮助您检查除Google搜索之外的其他结果。

2.有许多第三方服务提供大量的DNS数据,可以用其检索给定域名的子域名

  • VirusTotal会运行DNS复制功能,通过存储用户访问URL时执行的DNS解析来构建数据库。要检索子域名的信息,您只需将域名放在搜索栏中即可

  • DNSdumpster是另一个有趣的工具,可以找到给定域名的大量潜在子域名

Sublist3r(https://github.com/aboul3la/Sublist3r) 是一个非常热门的工具,它可以用来探测各种子域名。Sublist3r使用许多搜索引擎(如Google,Yahoo,Bing,Baidu和Ask)进行子域名探测。Sublist3r还使用Netcraft,Virustotal,ThreatCrowd,DNSdumpster和ReverseDNS进行子域名探测。

3.证书透明(CT)是证书颁发机构(CA)必须将其发布的每个SSL/TLS证书发布到公共日志的项目。SSL/TLS证书通常包含域名,子域名和电子邮件地址。这使他们成为攻击者的宝库。我在关于证书透明的知识上写了一系列技术文章,我已经深入介绍了这个技术,你可以在这里(https://blog.appsecco.com/certificate-transparency-the-bright-side-and-the-dark-side-8aa47d9a6616) 阅读这个系列。

查找为域颁发的证书的最简单方法是使用收集CT日志的搜索引擎,下面列出了一些比较受欢迎的链接:

https://crt.sh/
https://censys.io/
https://developers.facebook.com/tools/ct/
https://google.com/transparencyreport/https/ct/

除了Web界面之外,crt.sh还可以使用postgres界面访问CT日志数据。这使得运行一些高级查询变得简单而灵活。如果您安装了PostgreSQL客户端软件,则可以按如下方式登录:

$ psql -h crt.sh -p 5432 -U guest certwatch

我们编写了一些脚本来简化使用CT日志搜索引擎查找子域名的过程。这些脚本可以在我们的github repo中找到https://github.com/appsecco/the-art-of-subdomain-enumeration

使用CT进行子域名探测的缺点是CT日志中找到的域名可能不存在,因此无法解析为IP地址。您可以将massdns(https://github.com/blechschmidt/massdns) 等工具与CT日志结合使用,以快速识别可解析的域名。

# ct.py - extracts domain names from CT Logs(shipped with massdns)
# massdns - will find resolvable domains & adds them to a file 
./ct.py icann.org | ./bin/massdns -r resolvers.txt -t A -q -a -o -w icann_resolvable_domains.txt -

4.基于字典的子域名枚举是另一种发现子域名的方式。DNSRecon(https://github.com/darkoperator/dnsrecon) 是一个功能强大的DNS枚举工具,它的功能之一是使用预定义的列表进行基于字典的子域名探测。

$ python dnsrecon.py -n ns1.insecuredns.com -d insecuredns.com -D subdomains-top1mil-5000.txt -t brt

5.置换扫描是另一个有趣的技术来识别子域名。在该技术中,我们使用已知域/子域名的排列组合来识别新的子域名。

$ python altdns.py -i icann.domains -o data_output -w icann.words -r -s results_output.txt

6.查找自治系统(AS)号码(https://www.iana.org/assignments/as-numbers) 将帮助我们识别属于组织的网络块,而该组块又可能具有有效域。

  • 找到的ASN号码可用于查找域的网络块。有Nmap脚本可以实现这一目的-nmap.org/nsedoc/scripts/targets-asn.html
    $ nmap --script targets-asn --script-args targets-asn.asn=17012 > netblocks.txt

7.域传送是一种DNS事务,DNS服务器将其全部或部分域文件的副本传递给另一个DNS服务器。如果未安全地配置域传输送,则任何人都可以对指定名称的服务器启动域传送并获取域文件的副本。根据设计,域文件包含有关域和保存在域中的大量主机信息。

$ dig +multi AXFR @ns1.insecuredns.com insecuredns.com

8.由于DNSSEC处理不存在域名的方式,您可以"遍历"DNSSEC域并枚举该域中的所有域名。您可以从这里(https://info.menandmice.com/blog/bid/73645/Take-your-DNSSEC-with-a-grain-of-salt) 了解有关此技术的更多信息。

  • 对于使用NSEC记录的DNSSEC域,可以使用ldns-walk(https://www.nlnetlabs.nl/projects/ldns/about/) 等工具进行探测
    $ ldns-walk @ns1.insecuredns.com insecuredns.com

  • 一些DNSSEC域使用NSEC3做记录,该记录使用散列域名来防止攻击者收集纯文本域名。攻击者可以收集所有子域名hash值并将hash值离线破解。
  • 像nsec3walker(https://dnscurve.org/nsec3walker.html) ,nsec3map(https://github.com/anonion0/nsec3map) 这样的工具帮助我们自动收集NSEC3 hash并破解hash。安装nsec3walker后,可以使用以下命令枚举受NSEC3保护的域名的子域名
    # Collect NSEC3 hashes of a domain
    $ ./collect icann.org > icann.org.collect
    # Undo the hashing, expose the sub-domain information.
    $ ./unhash < icann.org.collect > icann.org.unhash
    # Listing only the sub-domain part from the unhashed data
    $ cat icann.org.unhash | grep "icann" | awk '{print $2;}'
    del.icann.org.
    access.icann.org.
    charts.icann.org.
    communications.icann.org.
    fellowship.icann.org.
    files.icann.org.
    forms.icann.org.
    mail.icann.org.
    maintenance.icann.org.
    new.icann.org.
    public.icann.org.
    research.icann.org.

9.有些项目收集了全互联网范围内的扫描数据,并将其提供给研究人员和安全社区。该项目发布的数据集是子域名信息的宝库。虽然在这个庞大的数据集中找到子域名就像大海捞针,但却值得我们去一试。

  • Forward DNS(https://scans.io/study/sonar.fdns_v2) 数据集作为Project Sonar的一部分发布。数据格式是通过gzip压缩的JSON文件。我们可以解析数据集以查找给定域名的子域名。数据集很大(压缩后:20+GB,压缩前:300+GB)
    # Command to parse & extract sub-domains for a given domain
    $ curl -silent https://scans.io/data/rapid7/sonar.fdns_v2/20170417-fdns.json.gz | pigz -dc | grep ".icann.org" | jq

子域名探测技术 - 比较

我们针对icann.org运行了一些讨论过的子域名探测技术并对结果进行了比较。下面的条形图显示了不同探测技术为icann.org找到的可解析的子域名数量。

子域名探测 - 参考

我们为子域名探测技术的工具和源创建了一个简单的参考列表。这个列表是使用Github gist创建的:https://gist.github.com/yamakira/2a36d3ae077558ac446e4a89143c69ab

子域名探测 - 参考

搜索引擎

谷歌(https://google.com/)
Bing(https://bing.com/)

DNS信息搜集

VirusTotal(https://www.virustotal.com/)
ViewDNS(https://viewdns.info/)
DNSdumpster(https://dnsdumpster.com/)
Threatcrowd(https://www.threatcrowd.org/)

证书透明日志

https://crt.sh/
https://censys.io/
https://developers.facebook.com/tools/ct/
https://google.com/transparencyreport/https/ct/

工具

Sublister(https://github.com/aboul3la/Sublist3r)
Altdns(https://github.com/infosec-au/altdns)
massdns(https://github.com/blechschmidt/massdns)
enumall(https://github.com/jhaddix/domain)
DNSRecon(https://github.com/darkoperator/dnsrecon)
Domain analyzer(https://github.com/eldraco/domain_analyzer)
XRay(https://github.com/evilsocket/xray)
Aquatone(https://github.com/michenriksen/aquatone)
ldns-walk(https://www.nlnetlabs.nl/projects/ldns/)
NSEC3 walker(https://dnscurve.org/nsec3walker.html)

数据来源

Project Sonar(https://sonar.labs.rapid7.com/)
Certificate Transparency logs(https://www.certificate-transparency.org/known-logs)

参考

https://github.com/appsecco/bugcrowd-levelup-subdomain-enumeration
https://blog.appsecco.com/open-source-intelligence-gathering-101-d2861d4429e3
https://www.databreaches.net/hackers-post-450k-credentials-apparently-pilfered-from-yahoo/
http://info.menandmice.com/blog/bid/73645/Take-your-DNSSEC-with-a-grain-of-salt
https://www.peerlyst.com/posts/bsideslv-2017-breaking-ground-with-underflow-bsides-las-vegas

 

原文链接:https://xz.aliyun.com/t/3478

标签:

给我留言