53 - Pentesting DNS
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.
κΈ°λ³Έ μ 보
**λλ©μΈ λ€μ μμ€ν (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λ₯Ό μ¬μ©νμ¬ μνν μ μμ΅λλ€:
dig version.bind CHAOS TXT @DNS
λν, λꡬ fpdnsλ μλ²μ μ§λ¬Έμ μλ³ν μ μμ΅λλ€.
nmap μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νμ¬ λ°°λλ₯Ό κ°μ Έμ€λ κ²λ κ°λ₯ν©λλ€:
--script dns-nsid
Any record
λ μ½λ ANYλ DNS μλ²μ μμ μ΄ κ³΅κ°ν μμ¬κ° μλ λͺ¨λ μ¬μ© κ°λ₯ν νλͺ©μ λ°ννλλ‘ μμ²ν©λλ€.
dig any victim.com @<DNS_IP>
μ‘΄ μ μ‘
μ΄ μ μ°¨λ λΉλκΈ° μ 체 μ μ‘ μ‘΄(AXFR)μΌλ‘ μ½μΉλ©λλ€.
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
μΆκ° μ 보
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)
μλν
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 μ¬μ©νκΈ°
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...
μ μ©ν λ©νμ€νλ‘μ λͺ¨λ
auxiliary/gather/enum_dns #Perform enumeration actions
μ μ©ν nmap μ€ν¬λ¦½νΈ
#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
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
μ IP λ²μλ₯Ό 쿼리ν μ μμ΅λλ€: https://bgp.he.net/net/205.166.76.0/24#_dns (μ΄ λꡬλ BGPμλ μ μ©ν©λλ€).
DNS - μλΈλλ©μΈ BF
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
μ‘ν°λΈ λλ ν 리 μλ²
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
#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λ₯Ό μμ§νλ λ¬΄μ°¨λ³ λμ 곡격.
dnsdict6 -s -t <domain>
IPv6 μ£Όμλ₯Ό μ¬μ©ν μ DNS λΈλ£¨νΈν¬μ€
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β (μ¬κ· μ¬μ© κ°λ₯)κ° μλ΅μ μλμ§ νμΈνλ κ²μ
λλ€:
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/
- 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'
Tip
AWS ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:HackTricks Training GCP Red Team Expert (GRTE)
Azure ν΄νΉ λ°°μ°κΈ° λ° μ°μ΅νκΈ°:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.


