mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
229 lines
9.8 KiB
Markdown
229 lines
9.8 KiB
Markdown
# 53 - Pentesting DNS
|
|
|
|
{{#include ../banners/hacktricks-training.md}}
|
|
|
|
|
|
## **기본 정보**
|
|
|
|
**도메인 네임 시스템(DNS)**은 인터넷의 디렉토리 역할을 하며, 사용자가 google.com이나 facebook.com과 같은 **기억하기 쉬운 도메인 이름**을 통해 웹사이트에 접근할 수 있도록 합니다. 도메인 이름을 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`를 사용하여 수행할 수 있습니다:
|
|
```bash
|
|
dig version.bind CHAOS TXT @DNS
|
|
```
|
|
또한, 도구 [`fpdns`](https://github.com/kirei/fpdns)는 서버의 지문을 식별할 수 있습니다.
|
|
|
|
**nmap** 스크립트를 사용하여 배너를 가져오는 것도 가능합니다:
|
|
```
|
|
--script dns-nsid
|
|
```
|
|
### **Any record**
|
|
|
|
레코드 **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...
|
|
```
|
|
### 유용한 메타스플로잇 모듈
|
|
```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
|
|
```
|
|
> [!NOTE]
|
|
> 내부 IP 주소로 해결되는 서브도메인을 찾을 수 있다면, 해당 IP 범위에 대해 도메인의 NS에 역 DNS BF를 수행해 보아야 합니다.
|
|
|
|
또 다른 도구: [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
|
|
```
|
|
### 액티브 디렉토리 서버
|
|
```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
|
|
```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>
|
|
```
|
|
IPv6 주소를 사용한 역 DNS 브루트포스
|
|
```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>
|
|
```
|
|
**사용 불가**:
|
|
|
|
.png>)
|
|
|
|
**사용 가능**:
|
|
|
|
.png>)
|
|
|
|
|
|
### 존재하지 않는 계정으로 메일 보내기
|
|
|
|
**피해자의 도메인을 사용하여 존재하지 않는 주소로 이메일을 보내는 것**은 피해자가 **헤더**에 **내부 서버의 이름과 IP 주소**와 같은 흥미로운 정보를 포함할 수 있는 비배달 알림(NDN) 메시지를 전송하도록 유도할 수 있습니다.
|
|
|
|
## 사후 활용
|
|
|
|
- Bind 서버의 구성을 확인할 때 **`allow-transfer`** 매개변수의 구성을 확인하십시오. 이는 누가 존 전송을 수행할 수 있는지를 나타내며, **`allow-recursion`** 및 **`allow-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/*
|
|
```
|
|
## References
|
|
|
|
- [https://www.myrasecurity.com/en/knowledge-hub/dns/](https://www.myrasecurity.com/en/knowledge-hub/dns/)
|
|
- Book: **Network Security Assessment 3rd edition**
|
|
|
|
## HackTricks Automatic Commands
|
|
```
|
|
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}}
|