# 53 - Pentesting DNS
{% hint style="success" %}
Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** π¬ [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** π¦ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
#### ν΄μ»€μ κ΄μ μμ μΉ μ±, λ€νΈμν¬ λ° ν΄λΌμ°λλ₯Ό μ΄ν΄λ³΄μΈμ
**μ€μ λΉμ¦λμ€μ μν₯μ λ―ΈμΉλ μ€μν μ·¨μ½μ μ μ°Ύμλ³΄κ³ λ³΄κ³ νμΈμ.** 곡격 νλ©΄μ 맀ννκ³ κΆν μμΉμ νμ©νλ 보μ λ¬Έμ λ₯Ό μ°Ύμλ΄λ©°, νμ μ¦κ±°λ₯Ό μμ§νκΈ° μν΄ μλνλ μ΅μ€νλ‘μμ μ¬μ©νλ 20κ° μ΄μμ λ§μΆ€ν λꡬλ₯Ό μ¬μ©νμΈμ. μ¬λ¬λΆμ λ
Έλ ₯μ μ€λλ ₯ μλ λ³΄κ³ μλ‘ λ°κΎΈμΈμ.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
## **κΈ°λ³Έ μ 보**
**λλ©μΈ λ€μ μμ€ν
(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 @
```
### **μ‘΄ μ μ‘**
μ΄ μ μ°¨λ `λΉλκΈ° μ 체 μ μ‘ μ‘΄`(`AXFR`)μΌλ‘ μ½μΉλ©λλ€.
```bash
dig axfr @ #Try zone transfer without domain
dig axfr @ #Try zone transfer guessing the domain
fierce --domain --dns-servers #Will try toperform a zone transfer against every authoritative name server and if this doesn'twork, will launch a dictionary attack
```
### λ λ§μ μ 보
```bash
dig ANY @ #Any information
dig A @ #Regular DNS request
dig AAAA @ #IPv6 DNS request
dig TXT @ #Information
dig MX @ #Emails related
dig NS @ #DNS that resolves that name
dig -x 192.168.0.2 @ #Reverse lookup
dig -x 2a00:1450:400c:c06::93 @ #reverse IPv6 lookup
#Use [-p PORT] or -6 (to use ivp6 address of dns)
```
#### μλν
```bash
for sub in $(cat );do dig $sub. @ | grep -v ';\|SOA' | sed -r '/^\s*$/d' | grep $sub | tee -a subdomains.txt;done
dnsenum --dnsserver --enum -p 0 -s 0 -o subdomains.txt -f
```
#### nslookup μ¬μ©νκΈ°
```bash
nslookup
> SERVER #Select dns server
> 127.0.0.1 #Reverse lookup of 127.0.0.1, maybe...
> #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"
```
### DNS - 리λ²μ€ BF
```bash
dnsrecon -r 127.0.0.0/24 -n #DNS reverse of all of the addresses
dnsrecon -r 127.0.1.0/24 -n #DNS reverse of all of the addresses
dnsrecon -r /24 -n #DNS reverse of all of the addresses
dnsrecon -d active.htb -a -n #Zone transfer
```
{% hint style="info" %}
λ΄λΆ IP μ£Όμλ‘ ν΄κ²°λλ μλΈλλ©μΈμ μ°Ύμ μ μλ€λ©΄, ν΄λΉ IP λ²μμ λν΄ λλ©μΈμ NSμ μ DNS BFλ₯Ό μνν΄ λ³΄μμΌ ν©λλ€.
{% 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 --enum -p 0 -s 0 -o subdomains.txt -f subdomains-1000.txt
dnsrecon -D subdomains-1000.txt -d -n
dnscan -d -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.
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
μλΈλλ©μΈμ IPv6λ₯Ό μμ§νκΈ° μν΄ "AAAA" μμ²μ μ¬μ©ν λ¬΄μ°¨λ³ λμ
곡격.
```bash
dnsdict6 -s -t
```
IPv6 μ£Όμλ₯Ό μ¬μ©ν μ DNS λΈλ£¨νΈν¬μ€
```bash
dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns.ripe.net
```
### DNS Recursion DDoS
λ§μ½ **DNS μ¬κ·κ° νμ±νλμ΄ μλ€λ©΄**, 곡격μλ UDP ν¨ν·μ **μλ³Έ**μ **μ€νΈν**νμ¬ **DNSκ° νΌν΄ μλ²λ‘ μλ΅μ 보λ΄λλ‘** λ§λ€ μ μλ€. 곡격μλ **ANY** λλ **DNSSEC** λ μ½λ μ νμ μ
μ©ν μ μλλ°, μ΄λ€μ λ ν° μλ΅μ κ°μ§κΈ° λλ¬Έμ΄λ€.\
DNSκ° **μ¬κ·**λ₯Ό μ§μνλμ§ **νμΈ**νλ λ°©λ²μ λλ©μΈ μ΄λ¦μ 쿼리νκ³ **μλ΅μ "ra" νλκ·Έ** (_μ¬κ· μ¬μ© κ°λ₯_)κ° μλμ§ **νμΈ**νλ κ²μ΄λ€:
```bash
dig google.com A @
```
**μ¬μ© λΆκ°λ₯**:
![](<../.gitbook/assets/image (123).png>)
**μ¬μ© κ°λ₯**:
![](<../.gitbook/assets/image (146).png>)
#### ν΄μ»€μ κ΄μ μμ μΉ μ±, λ€νΈμν¬ λ° ν΄λΌμ°λ 보기
**μ€μ λΉμ¦λμ€μ μν₯μ λ―ΈμΉλ μ€μν, μ
μ© κ°λ₯ν μ·¨μ½μ μ μ°Ύμλ³΄κ³ λ³΄κ³ νμΈμ.** 곡격 νλ©΄μ 맀ννκ³ κΆν μμΉμ νμ©νλ 보μ λ¬Έμ λ₯Ό μ°Ύμλ΄λ©°, νμ μ¦κ±°λ₯Ό μμ§νκΈ° μν΄ μλνλ μ΅μ€νλ‘μμ μ¬μ©νμ¬ κ·νμ λ
Έλ ₯μ μ€λλ ₯ μλ λ³΄κ³ μλ‘ μ ννλ 20κ° μ΄μμ λ§μΆ€ν λꡬλ₯Ό μ¬μ©νμΈμ.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
### μ‘΄μ¬νμ§ μλ κ³μ μΌλ‘ λ©μΌ 보λ΄κΈ°
λμ λλ©μΈ λ΄μ μλͺ»λ μ£Όμλ‘ μ μ‘λ μ΄λ©μΌλ‘ μΈν΄ λ°μν λ°°λ¬ μ€ν¨ μλ¦Ό(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'
```
#### ν΄μ»€μ κ΄μ μμ μΉ μ±, λ€νΈμν¬ λ° ν΄λΌμ°λλ₯Ό μ΄ν΄λ³΄μΈμ
**μ€μ λΉμ¦λμ€μ μν₯μ λ―ΈμΉλ μ€μν μ·¨μ½μ μ μ°Ύμλ³΄κ³ λ³΄κ³ νμΈμ.** 20κ° μ΄μμ λ§μΆ€ν λꡬλ₯Ό μ¬μ©νμ¬ κ³΅κ²© νλ©΄μ 맀ννκ³ , κΆν μμΉμ νμ©νλ 보μ λ¬Έμ λ₯Ό μ°Ύμλ΄λ©°, μλνλ μ΅μ€νλ‘μμ μ¬μ©νμ¬ νμ μ¦κ±°λ₯Ό μμ§νμ¬ κ·νμ λ
Έλ ₯μ μ€λλ ₯ μλ λ³΄κ³ μλ‘ μ ννμΈμ.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
{% hint style="success" %}
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
HackTricks μ§μνκΈ°
* [**ꡬλ
κ³ν**](https://github.com/sponsors/carlospolop) νμΈνκΈ°!
* **π¬ [**Discord κ·Έλ£Ή**](https://discord.gg/hRep4RUj7f) λλ [**ν
λ κ·Έλ¨ κ·Έλ£Ή**](https://t.me/peass)μ μ°Έμ¬νκ±°λ **Twitter** π¦ [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**λ₯Ό νλ‘μ°νμΈμ.**
* **[**HackTricks**](https://github.com/carlospolop/hacktricks) λ° [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νμ 곡μ νμΈμ.**
{% endhint %}