# 53 - Pentesting DNS {{#include ../banners/hacktricks-training.md}} ## **बुनियादी जानकारी** **डोमेन नाम प्रणाली (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` का उपयोग करके कर सकते हैं: ```bash dig version.bind CHAOS TXT @DNS ``` इसके अलावा, उपकरण [`fpdns`](https://github.com/kirei/fpdns) सर्वर की फिंगरप्रिंटिंग भी कर सकता है। यह **nmap** स्क्रिप्ट के साथ बैनर भी प्राप्त करना संभव है: ``` --script dns-nsid ``` ### **कोई रिकॉर्ड** रिकॉर्ड **ANY** DNS सर्वर से **सभी उपलब्ध** **एंट्रीज़** **वापस** करने के लिए कहेगा जो **यह प्रकट करने के लिए तैयार है**। ```bash dig any victim.com @ ``` ### **ज़ोन ट्रांसफर** यह प्रक्रिया को संक्षिप्त रूप में `Asynchronous Full Transfer Zone` (`AXFR`) कहा जाता है। ```bash dig axfr @ #Try zone transfer without domain dig axfr @ #Try zone transfer guessing the domain fierce --domain --dns-servers #Will try toperform a zone transfer against every authoritative name server and if this doesn'twork, will launch a dictionary attack ``` ### अधिक जानकारी ```bash dig ANY @ #Any information dig A @ #Regular DNS request dig AAAA @ #IPv6 DNS request dig TXT @ #Information dig MX @ #Emails related dig NS @ #DNS that resolves that name dig -x 192.168.0.2 @ #Reverse lookup dig -x 2a00:1450:400c:c06::93 @ #reverse IPv6 lookup #Use [-p PORT] or -6 (to use ivp6 address of dns) ``` #### स्वचालन ```bash for sub in $(cat );do dig $sub. @ | grep -v ';\|SOA' | sed -r '/^\s*$/d' | grep $sub | tee -a subdomains.txt;done dnsenum --dnsserver --enum -p 0 -s 0 -o subdomains.txt -f ``` #### nslookup का उपयोग करना ```bash nslookup > SERVER #Select dns server > 127.0.0.1 #Reverse lookup of 127.0.0.1, maybe... > #Reverse lookup of a machine, maybe... ``` ### उपयोगी मेटास्प्लॉट मॉड्यूल ```bash auxiliary/gather/enum_dns #Perform enumeration actions ``` ### उपयोगी nmap स्क्रिप्ट्स ```bash #Perform enumeration actions nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" ``` ### DNS - रिवर्स BF ```bash dnsrecon -r 127.0.0.0/24 -n #DNS reverse of all of the addresses dnsrecon -r 127.0.1.0/24 -n #DNS reverse of all of the addresses dnsrecon -r /24 -n #DNS reverse of all of the addresses dnsrecon -d active.htb -a -n #Zone transfer ``` > [!NOTE] > यदि आप आंतरिक IP-पते को हल करने वाले उपडोमेन खोजने में सक्षम हैं, तो आपको उस IP रेंज के लिए डोमेन के NSs पर एक रिवर्स DNS BF करने का प्रयास करना चाहिए। इसे करने के लिए एक और उपकरण: [https://github.com/amine7536/reverse-scan](https://github.com/amine7536/reverse-scan) आप रिवर्स IP रेंज के लिए पूछताछ कर सकते हैं [https://bgp.he.net/net/205.166.76.0/24#\_dns](https://bgp.he.net/net/205.166.76.0/24#_dns) (यह उपकरण BGP के साथ भी सहायक है)। ### DNS - उपडोमेन BF ```bash dnsenum --dnsserver --enum -p 0 -s 0 -o subdomains.txt -f subdomains-1000.txt dnsrecon -D subdomains-1000.txt -d -n dnscan -d -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan ``` ### सक्रिय निर्देशिका सर्वर ```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. 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 "AAAA" अनुरोधों का उपयोग करके सबडोमेन के IPv6 को इकट्ठा करने के लिए ब्रूट फोर्स। ```bash dnsdict6 -s -t ``` IPv6 पतों का उपयोग करके रिवर्स DNS पर ब्रूटफोर्स ```bash 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" ध्वज** (_पुनरावृत्ति उपलब्ध_) प्रतिक्रिया में है: ```bash dig google.com A @ ``` **उपलब्ध नहीं**: ![](<../images/image (123).png>) **उपलब्ध**: ![](<../images/image (146).png>) ### अस्तित्वहीन खाते के लिए मेल **पीड़ित के डोमेन का उपयोग करके एक अस्तित्वहीन पते पर ईमेल भेजना** पीड़ित को एक गैर-डिलीवरी सूचना (NDN) संदेश भेजने के लिए प्रेरित कर सकता है, जिसके **हेडर** में **आंतरिक सर्वरों के नाम और IP पते** जैसी दिलचस्प जानकारी हो सकती है। ## पोस्ट-एक्सप्लॉइटेशन - एक बाइंड सर्वर की कॉन्फ़िगरेशन की जांच करते समय **`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/](https://www.myrasecurity.com/en/knowledge-hub/dns/) - पुस्तक: **नेटवर्क सुरक्षा मूल्यांकन 3रा संस्करण** ## 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' ``` {{#include ../banners/hacktricks-training.md}}