53 - Pentesting DNS
Reading time: 12 minutes
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をサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
基本情報
ドメインネームシステム (DNS) はインターネットのディレクトリとして機能し、ユーザーがgoogle.comやfacebook.comのような覚えやすいドメイン名を通じてウェブサイトにアクセスできるようにします。これにより、数値のインターネットプロトコル (IP) アドレスの代わりに、ドメイン名を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>
ゾーン転送
この手順は Asynchronous Full Transfer Zone
(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...
有用なMetasploitモジュール
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ブルートフォースを実行してみるべきです。
別のツール: https://github.com/amine7536/reverse-scan
リバースIP範囲をクエリできます: https://bgp.he.net/net/205.166.76.0/24#_dns(このツールはBGPにも役立ちます)。
DNS - サブドメインブルートフォース
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サーバー
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>
利用不可:
利用可能:
存在しないアカウントへのメール
被害者のドメインを使用して存在しないアドレスにメールを送信することで、被害者が配信不能通知 (NDN) メッセージを送信する可能性があり、そのヘッダーには内部サーバーの名前やIPアドレスなどの興味深い情報が含まれている可能性があります。
ポストエクスプロイト
- 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/*
参考文献
- 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.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をサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。