mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-23 13:13:41 +00:00
327 lines
15 KiB
Markdown
327 lines
15 KiB
Markdown
# 53 - 渗透测试 DNS
|
||
|
||
<details>
|
||
|
||
<summary><strong>从零开始学习 AWS 黑客技术,成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE(HackTricks AWS 红队专家)</strong></a><strong>!</strong></summary>
|
||
|
||
支持 HackTricks 的其他方式:
|
||
|
||
* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版的 HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
||
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
|
||
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family),我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
|
||
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/carlospolopm)** 上关注我**。
|
||
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。
|
||
|
||
</details>
|
||
|
||
<figure><img src="/.gitbook/assets/image (2).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
**即时提供的漏洞评估和渗透测试设置**。使用 20 多种工具和功能从侦察到报告运行完整的渗透测试。我们不取代渗透测试人员 - 我们开发定制工具、检测和利用模块,让他们有更多时间深入挖掘、弹出 shell 并享受乐趣。
|
||
|
||
{% embed url="https://pentest-tools.com/" %}
|
||
|
||
## **基本信息**
|
||
|
||
**域名系统(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`执行此查询:
|
||
```bash
|
||
dig version.bind CHAOS TXT @DNS
|
||
```
|
||
此外,工具[`fpdns`](https://github.com/kirei/fpdns)也可以对服务器进行指纹识别。
|
||
|
||
还可以使用**nmap**脚本获取横幅信息:
|
||
```
|
||
--script dns-nsid
|
||
```
|
||
### **任何记录**
|
||
|
||
**ANY** 记录将要求 DNS 服务器返回其愿意披露的所有可用条目。
|
||
```bash
|
||
dig any victim.com @<DNS_IP>
|
||
```
|
||
### **区域传送**
|
||
|
||
该过程简称为`异步完整传送区域`(`AXFR`)。
|
||
```bash
|
||
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
|
||
```
|
||
### 更多信息
|
||
```bash
|
||
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)
|
||
```
|
||
#### 自动化
|
||
```bash
|
||
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
|
||
```bash
|
||
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模块
|
||
```bash
|
||
auxiliary/gather/enum_dns #Perform enumeration actions
|
||
```
|
||
### 有用的 nmap 脚本
|
||
```bash
|
||
#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
|
||
```bash
|
||
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
|
||
```
|
||
{% hint style="info" %}
|
||
如果您能找到解析为内部IP地址的子域名,您应该尝试对该IP范围进行反向DNS BF,向该域的NSs请求。
|
||
{% endhint %}
|
||
|
||
另一个执行此操作的工具:[https://github.com/amine7536/reverse-scan](https://github.com/amine7536/reverse-scan)
|
||
|
||
您可以查询反向IP范围至[https://bgp.he.net/net/205.166.76.0/24#\_dns](https://bgp.he.net/net/205.166.76.0/24#\_dns)(此工具在BGP方面也很有帮助)。
|
||
|
||
### DNS - 子域名BF
|
||
```bash
|
||
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 服务器
|
||
```bash
|
||
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
|
||
```bash
|
||
#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地址。
|
||
```bash
|
||
dnsdict6 -s -t <domain>
|
||
```
|
||
## Bruteforce reverse DNS in using IPv6 addresses
|
||
|
||
### Introduction
|
||
|
||
In IPv6, reverse DNS lookup is performed by reversing the IP address nibble by nibble and appending the DNS zone. This process can be automated using tools like `dnsrevenum6` to bruteforce reverse DNS entries for IPv6 addresses.
|
||
|
||
### Steps to bruteforce reverse DNS in IPv6
|
||
|
||
1. **Generate IPv6 addresses**: Use a tool like `ipv6gen` to generate a list of IPv6 addresses to bruteforce reverse DNS entries.
|
||
|
||
2. **Perform reverse DNS lookup**: Use `dnsrevenum6` tool to perform reverse DNS lookup for each generated IPv6 address.
|
||
|
||
3. **Automate the process**: Write a script to automate the generation of IPv6 addresses and reverse DNS lookup using `dnsrevenum6`.
|
||
|
||
4. **Analyzing results**: Analyze the results to identify any misconfigurations or potential security issues in the reverse DNS entries.
|
||
|
||
### Conclusion
|
||
|
||
Bruteforcing reverse DNS entries for IPv6 addresses can help identify misconfigured DNS entries or potential security vulnerabilities in the network. It is essential for pentesters to perform thorough testing of reverse DNS configurations to ensure the security of the network.
|
||
```bash
|
||
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"**(_递归可用_):
|
||
```bash
|
||
dig google.com A @<IP>
|
||
```
|
||
**不可用**:
|
||
|
||
![](<../.gitbook/assets/image (275).png>)
|
||
|
||
**可用**:
|
||
|
||
![](<../.gitbook/assets/image (276).png>)
|
||
|
||
<figure><img src="/.gitbook/assets/image (2).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
**即时提供漏洞评估和渗透测试设置**。从任何地方运行完整的渗透测试,拥有20多种工具和功能,从侦察到报告。我们不取代渗透测试人员 - 我们开发定制工具、检测和利用模块,为他们节省时间深入挖掘、弹出shell并享受乐趣。
|
||
|
||
{% embed url="https://pentest-tools.com/" %}
|
||
|
||
### 发送到不存在账户的邮件
|
||
|
||
通过检查发送到目标域中无效地址的电子邮件引发的非投递通知(NDN),通常会披露有价值的内部网络详细信息。
|
||
|
||
提供的非投递报告包括以下信息:
|
||
|
||
- 生成服务器被识别为 `server.example.com`。
|
||
- 返回了针对 `user@example.com` 的错误代码 `#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found` 的失败通知。
|
||
- 在原始消息头中披露了内部IP地址和主机名。
|
||
```markdown
|
||
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` | 收集区域的统计数据。 |
|
||
|
||
## 参考资料
|
||
* [https://www.myrasecurity.com/en/knowledge-hub/dns/](https://www.myrasecurity.com/en/knowledge-hub/dns/)
|
||
* 书籍:**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'
|
||
```
|
||
<figure><img src="/.gitbook/assets/image (2).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
**立即提供漏洞评估和渗透测试设置**。从侦察到报告,使用20多种工具和功能运行完整的渗透测试。我们不取代渗透测试人员 - 我们开发定制工具、检测和利用模块,为他们节省时间深入挖掘、弹出shell并享受乐趣。
|
||
|
||
{% embed url="https://pentest-tools.com/" %}
|
||
|
||
<details>
|
||
|
||
<summary><strong>从零开始学习AWS黑客技术,成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE(HackTricks AWS红队专家)</strong></a><strong>!</strong></summary>
|
||
|
||
支持HackTricks的其他方式:
|
||
|
||
* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
||
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
|
||
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们的独家[NFTs](https://opensea.io/collection/the-peass-family)收藏品
|
||
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/carlospolopm)**。**
|
||
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
|
||
|
||
</details>
|