53 - Pentesting DNS

htARTE (HackTricks AWS Red Team 전문가)로부터 AWS 해킹을 제로부터 전문가까지 배우세요

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에는 배너가 없지만 대부분의 BIND 네임서버에서 작동하는 version.bind. CHAOS TXT의 매직 쿼리를 가져올 수 있습니다. dig를 사용하여 이 쿼리를 수행할 수 있습니다:

dig version.bind CHAOS TXT @DNS

또한, 도구 fpdns를 사용하여 서버의 fingerprint를 식별할 수 있습니다.

또한 nmap 스크립트를 사용하여 배너를 가져올 수도 있습니다:

--script dns-nsid

모든 레코드

레코드 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...

유용한 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

내부 IP 주소로 해석되는 하위 도메인을 찾을 수 있다면, 해당 IP 범위를 요청하는 도메인의 NS에 대해 역 DNS BF를 수행해 보아야 합니다.

이를 수행하기 위한 또 다른 도구: https://github.com/amine7536/reverse-scan

https://bgp.he.net/net/205.166.76.0/24#_dns에서 역 IP 범위를 쿼리할 수 있습니다 (이 도구는 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

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>

사용 불가능:

사용 가능:

취약점 평가 및 침투 테스트를 위한 즉시 사용 가능한 설정. 20가지 이상의 도구 및 기능을 사용하여 어디서든 전체 펜테스트를 실행하고, 정찰부터 보고서 작성까지 가능합니다. 우리는 펜테스터를 대체하지 않습니다 - 사용자들이 더 심층적으로 파고들고, 쉘을 열고, 즐길 수 있도록 맞춤형 도구, 탐지 및 공격 모듈을 개발합니다.

존재하지 않는 계정으로 메일 보내기

대상 도메인 내의 잘못된 주소로 전송된 이메일에 의해 트리거된 비배달 알림 (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

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

참고 자료

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 해킹을 배우세요 htARTE (HackTricks AWS Red Team Expert)!

HackTricks를 지원하는 다른 방법:

Last updated