53 - Pentesting DNS

Reading time: 8 minutes

tip

Jifunze na fanya mazoezi ya AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Jifunze na fanya mazoezi ya GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

Taarifa za Msingi

Mfumo wa Majina ya Kikoa (DNS) unatumika kama directory ya mtandao, ukiruhusu watumiaji kufikia tovuti kupitia majina ya kikoa ambayo ni rahisi kukumbuka kama google.com au facebook.com, badala ya anwani za Internet Protocol (IP) za nambari. Kwa kutafsiri majina ya kikoa kuwa anwani za IP, DNS inahakikisha kwamba vivinjari vya wavuti vinaweza kupakia rasilimali za mtandao haraka, na kurahisisha jinsi tunavyosafiri katika ulimwengu wa mtandao.

Bandari ya Kawaida: 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)

Different DNS Servers

  • DNS Root Servers: Hizi ziko juu ya hierarchi ya DNS, zikisimamia maeneo ya juu na kuingilia tu ikiwa seva za chini hazijajibu. Shirika la Mtandao la Majina na Nambari (ICANN) linaangalia uendeshaji wao, ikiwa na idadi ya kimataifa ya 13.
  • Authoritative Nameservers: Seva hizi zina neno la mwisho kwa maswali katika maeneo yao yaliyotengwa, zikitoa majibu ya uhakika. Ikiwa hawawezi kutoa jibu, swali linaelekezwa kwa seva za mzizi.
  • Non-authoritative Nameservers: Zikiwa hazina umiliki juu ya maeneo ya DNS, seva hizi zinakusanya taarifa za eneo kupitia maswali kwa seva nyingine.
  • Caching DNS Server: Aina hii ya seva inakumbuka majibu ya maswali ya awali kwa muda fulani ili kuharakisha nyakati za majibu kwa maombi ya baadaye, huku muda wa cache ukiongozwa na seva yenye mamlaka.
  • Forwarding Server: Ikihudumu katika jukumu rahisi, seva za kupeleka zinapeleka maswali kwa seva nyingine.
  • Resolver: Imejumuishwa ndani ya kompyuta au route, resolvers hufanya utatuzi wa majina ndani ya eneo na hazichukuliwi kuwa na mamlaka.

Enumeration

Hakuna mabango katika DNS lakini unaweza kupata swali la kichawi kwa version.bind. CHAOS TXT ambalo litafanya kazi kwenye seva nyingi za BIND.
Unaweza kufanya swali hili kwa kutumia dig:

bash
dig version.bind CHAOS TXT @DNS

Zaidi ya hayo, chombo fpdns kinaweza pia kubaini alama ya seva.

Pia inawezekana kupata bendera pia kwa kutumia skripti ya nmap:

--script dns-nsid

Kila rekodi

Rekodi ANY itaomba seva ya DNS irudishe kila kitu kilichopo ambacho inaweza kufichua.

bash
dig any victim.com @<DNS_IP>

Transferi ya Eneo

Utaratibu huu unafupishwa kama Asynchronous Full Transfer Zone (AXFR).

bash
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

Maelezo zaidi

bash
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)

Utaftaji

bash
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>

Kutumia nslookup

bash
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...

Moduli muhimu ya metasploit

bash
auxiliary/gather/enum_dns #Perform enumeration actions

Mifumo ya nmap inayofaa

bash
#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 - Reverse BF

bash
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

Ikiwa unaweza kupata subdomains zinazoelekeza kwenye anwani za IP za ndani, unapaswa kujaribu kufanya reverse dns BF kwa NSs za domain inayouliza kwa anuwai hiyo ya IP.

Chombo kingine cha kufanya hivyo: https://github.com/amine7536/reverse-scan

Unaweza kuuliza anuwai za IP za nyuma kwa https://bgp.he.net/net/205.166.76.0/24#_dns (chombo hiki pia ni muhimu na BGP).

DNS - Subdomains BF

bash
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

Seva za Active Directory

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.<CLIENT_DOMAIN>
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

Brute force kutumia maombi ya "AAAA" kukusanya IPv6 za subdomains.

bash
dnsdict6 -s -t <domain>

Bruteforce reverse DNS kwa kutumia anwani za IPv6

bash
dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns.ripe.net

DNS Recursion DDoS

Ikiwa DNS recursion imewezeshwa, mshambuliaji anaweza kudanganya chanzo kwenye pakiti ya UDP ili kufanya DNS itume jibu kwa seva ya mwathirika. Mshambuliaji anaweza kutumia aina za rekodi ANY au DNSSEC kwani huwa na majibu makubwa.
Njia ya kuangalia ikiwa DNS inasaidia recursion ni kuuliza jina la kikoa na kuangalia ikiwa bendera "ra" (recursion available) iko kwenye jibu:

bash
dig google.com A @<IP>

Sio kupatikana:

Inapatikana:

Barua kwa akaunti isiyokuwepo

Kutuma barua pepe kwa anwani isiyokuwepo kwa kutumia kikoa cha mwathirika kunaweza kusababisha mwathirika kutuma ujumbe wa arifa ya kutofika (NDN) ambao vichwa vyake vinaweza kuwa na taarifa za kuvutia kama vile majina ya seva za ndani na anwani za IP.

Baada ya Utekelezaji

  • Wakati wa kuangalia usanidi wa seva ya Bind, angalia usanidi wa param allow-transfer kwani inaonyesha nani anaweza kufanya uhamishaji wa eneo na allow-recursion na allow-query kwani zinaonyesha nani anaweza kutuma maombi ya kurudi na maombi kwake.
  • Ifuatayo ni majina ya faili zinazohusiana na DNS ambazo zinaweza kuwa za kuvutia kutafuta ndani ya mashine:
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/*

Marejeo

Amri za Kiotomatiki za 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'

tip

Jifunze na fanya mazoezi ya AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Jifunze na fanya mazoezi ya GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks