53 - Pentesting DNS

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

즉시 사용 가능한 취약점 평가 및 침투 테스트 설정. 20개 이상의 도구 및 기능을 사용하여 어디서나 전체 침투 테스트를 실행하세요. 우리는 침투 테스터를 대체하지 않습니다 - 우리는 그들이 더 깊이 파고들고, 쉘을 터뜨리고, 재미를 느낄 수 있도록 맞춤형 도구, 탐지 및 악용 모듈을 개발합니다.

기본 정보

**도메인 네임 시스템(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

내부 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 Recursion DDoS

만약 DNS 재귀가 활성화되어 있다면, 공격자는 UDP 패킷의 원본스푸핑하여 DNS가 피해 서버로 응답을 보내도록 만들 수 있다. 공격자는 ANY 또는 DNSSEC 레코드 유형을 악용할 수 있는데, 이들은 더 큰 응답을 가지기 때문이다. DNS가 재귀를 지원하는지 확인하는 방법은 도메인 이름을 쿼리하고 응답에 "ra" 플래그 (재귀 사용 가능)가 있는지 확인하는 것이다:

dig google.com A @<IP>

사용 불가능:

사용 가능:

취약점 평가 및 침투 테스트를 위한 즉시 사용 가능한 설정. 20개 이상의 도구 및 기능을 사용하여 어디서나 전체 침투 테스트를 실행하세요. Recon부터 보고서 작성까지. 우리는 침투 테스터를 대체하지 않습니다 - 그들이 더 깊이 파고들고, 쉘을 터뜨리고, 재미를 느낄 수 있도록 맞춤형 도구, 탐지 및 악용 모듈을 개발합니다.

존재하지 않는 계정으로 메일 전송

대상 도메인 내의 잘못된 주소로 전송된 이메일로 인해 발생한 비배달 알림(NDN)을 조사함으로써, 종종 귀중한 내부 네트워크 세부정보가 공개됩니다.

제공된 비배달 보고서에는 다음과 같은 정보가 포함됩니다:

  • 생성 서버가 server.example.com으로 확인되었습니다.

  • user@example.com에 대한 실패 알림이 오류 코드 #550 5.1.1 RESOLVER.ADR.RecipNotFound; not found와 함께 반환되었습니다.

  • 내부 IP 주소와 호스트 이름이 원본 메시지 헤더에 공개되었습니다.

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

존의 통계 데이터를 수집합니다.

참고문헌

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개 이상의 도구와 기능을 사용하여 어디서나 전체 침투 테스트를 실행하세요. 우리는 침투 테스터를 대체하지 않습니다 - 그들이 더 깊이 파고들고, 쉘을 터뜨리고, 재미를 느낄 수 있도록 맞춤형 도구, 탐지 및 악용 모듈을 개발합니다.

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE) GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE)

HackTricks 지원하기

Last updated