hacktricks/network-services-pentesting/pentesting-dns.md

306 lines
15 KiB
Markdown
Raw Normal View History

2022-10-02 19:15:35 +00:00
# 53 - Pentesting DNS
2022-04-28 16:01:33 +00:00
{% hint style="success" %}
Leer & oefen AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Leer & oefen GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Support HackTricks</summary>
2024-01-03 10:42:55 +00:00
* Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
* **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}
2022-04-28 16:01:33 +00:00
<figure><img src="/.gitbook/assets/image (14) (1).png" alt=""><figcaption></figcaption></figure>
**Onmiddellik beskikbare opstelling vir kwesbaarheidsassessering & penetrasietoetsing**. Voer 'n volledige pentest van enige plek af uit met 20+ gereedskap & funksies wat van rekognisie tot verslagdoening strek. Ons vervang nie pentesters nie - ons ontwikkel pasgemaakte gereedskap, opsporing & eksploitasiemodules om hulle weer 'n bietjie tyd te gee om dieper te delf, shells te pop en pret te hê.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
2024-02-11 02:07:06 +00:00
## **Basiese Inligting**
Die **Domeinnaamstelsel (DNS)** dien as die internet se gids, wat gebruikers in staat stel om toegang tot webwerwe te verkry deur middel van **maklik onthoubare domeinnames** soos google.com of facebook.com, in plaas van die numeriese Internetprotokol (IP) adresse. Deur domeinnames in IP adresse te vertaal, verseker die DNS dat webblaaiers vinnig internetbronne kan laai, wat die manier vereenvoudig waarop ons in die aanlyn wêreld navigeer.
**Standaard poort:** 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)
```
### Verskillende DNS Bedieners
* **DNS Wortel Bedieners**: Hierdie is aan die top van die DNS hiërargie, wat die topvlak domeine bestuur en slegs ingryp as laer vlak bedieners nie reageer nie. Die Internet Korporasie vir Toegewyde Name en Nommers (**ICANN**) toesig oor hul werking, met 'n globale telling van 13.
* **Autoritatiewe Naamservers**: Hierdie bedieners het die finale sê vir navrae in hul aangewese sones, wat definitiewe antwoorde bied. As hulle nie 'n antwoord kan verskaf nie, word die navraag na die wortelbedieners opgestoot.
* **Nie-autoritatiewe Naamservers**: Gebrek aan eienaarskap oor DNS sones, versamel hierdie bedieners domein inligting deur navrae aan ander bedieners.
* **Kas DNS Bediener**: Hierdie tipe bediener onthou vorige navraag antwoorde vir 'n bepaalde tyd om reaksietye vir toekomstige versoeke te versnel, met die kasduur wat deur die autoritatiewe bediener bepaal word.
* **Voorwaartse Bediener**: Wat 'n eenvoudige rol dien, stuur voorwaartse bedieners eenvoudig navrae na 'n ander bediener.
* **Resolver**: Geïntegreer binne rekenaars of routers, voer resolvers naamresolusie plaaslik uit en word nie as autoritatief beskou nie.
2024-02-06 03:10:38 +00:00
## Enumerasie
2024-02-06 03:10:38 +00:00
### **Banner Grabbing**
2024-02-06 03:10:38 +00:00
Daar is nie bane in DNS nie, maar jy kan die magiese navraag vir `version.bind. CHAOS TXT` gryp wat op die meeste BIND naamservers sal werk.\
Jy kan hierdie navraag uitvoer met `dig`:
```bash
dig version.bind CHAOS TXT @DNS
```
Boonop kan die hulpmiddel [`fpdns`](https://github.com/kirei/fpdns) ook die bediener vingerafdruk.
Dit is ook moontlik om die banner te gryp met 'n **nmap** skrip:
```
--script dns-nsid
```
2024-02-11 02:07:06 +00:00
### **Enige rekord**
Die rekord **ANY** sal die DNS-bediener vra om **terug te gee** al die beskikbare **ingevoerde** wat **hy bereid is om bekend te maak**.
2022-10-02 19:15:35 +00:00
```bash
dig any victim.com @<DNS_IP>
```
### **Zone Oordrag**
2022-10-02 19:15:35 +00:00
Hierdie prosedure word afgekort as `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
2021-06-20 12:09:34 +00:00
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
```
2024-02-11 02:07:06 +00:00
### Meer inligting
```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)
```
2024-02-11 02:07:06 +00:00
#### Outomatisering
2023-08-15 08:09:34 +00:00
```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
2023-08-15 08:09:34 +00:00
dnsenum --dnsserver <DNS_IP> --enum -p 0 -s 0 -o subdomains.txt -f <WORDLIST> <DOMAIN>
```
#### Gebruik van 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...
```
### Nuttige metasploit modules
```bash
auxiliary/gather/enum_dns #Perform enumeration actions
```
### Nuttige nmap skripte
```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>
```
2024-02-11 02:07:06 +00:00
### DNS - Omgekeerde 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
```
2021-04-02 19:21:43 +00:00
{% hint style="info" %}
As jy in staat is om subdomeine te vind wat na interne IP-adresse oplos, moet jy probeer om 'n omgekeerde dns BF na die NS's van die domein te doen wat vir daardie IP-reeks vra.
2021-04-02 19:21:43 +00:00
{% endhint %}
Another tool to do so: [https://github.com/amine7536/reverse-scan](https://github.com/amine7536/reverse-scan)
You can query reverse IP ranges to [https://bgp.he.net/net/205.166.76.0/24#\_dns](https://bgp.he.net/net/205.166.76.0/24#\_dns) (this tool is also helpful with BGP).
2024-02-11 02:07:06 +00:00
### DNS - Subdomeine BF
```bash
2022-10-02 19:15:35 +00:00
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
```
### Aktiewe Gidsservers
2023-11-03 01:17:04 +00:00
```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
2023-11-03 01:17:04 +00:00
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'"
```
2022-10-02 19:15:35 +00:00
### DNSSec
```bash
2024-02-11 02:07:06 +00:00
#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
```
2022-10-02 19:15:35 +00:00
### IPv6
Brute force met "AAAA" versoeke om die IPv6 van die subdomeine te versamel.
```bash
dnsdict6 -s -t <domain>
```
Bruteforce omgekeerde DNS met behulp van IPv6 adresse
```bash
dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48 #Will use the dns pri.authdns.ripe.net
```
2024-02-11 02:07:06 +00:00
### DNS Rekursie DDoS
As **DNS-rekursie geaktiveer is**, kan 'n aanvaller **spoof** die **oorsprong** op die UDP-pakket om die **DNS die antwoord na die slagofferbediener** te laat stuur. 'n Aanvaller kan **ANY** of **DNSSEC** rekordtipes misbruik aangesien hulle groter antwoorde het.\
Die manier om te **kontroleer** of 'n DNS **rekursie** ondersteun, is om 'n domeinnaam te vra en te **kontroleer** of die **vlag "ra"** (_rekursie beskikbaar_) in die antwoord is:
```bash
dig google.com A @<IP>
```
2024-02-11 02:07:06 +00:00
**Nie beskikbaar**:
![](<../.gitbook/assets/image (123).png>)
2024-02-11 02:07:06 +00:00
**Beskikbaar**:
![](<../.gitbook/assets/image (146).png>)
<figure><img src="/.gitbook/assets/image (14) (1).png" alt=""><figcaption></figcaption></figure>
**Onmiddellik beskikbare opstelling vir kwesbaarheidsevaluering & penetrasietoetsing**. Voer 'n volledige pentest vanaf enige plek uit met 20+ gereedskap & funksies wat van rekognisie tot verslagdoening strek. Ons vervang nie pentesters nie - ons ontwikkel pasgemaakte gereedskap, opsporing & uitbuitingsmodules om hulle weer 'n bietjie tyd te gee om dieper te delf, shells te pop en pret te hê.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
### Pos aan nie-bestaande rekening
Deur die ondersoek van 'n nie-afleweringskennisgewing (NDN) wat veroorsaak is deur 'n e-pos wat na 'n ongeldige adres binne 'n teikendom gestuur is, word waardevolle interne netwerkbesonderhede dikwels bekend gemaak.
Die verskafde nie-afleweringsverslag sluit inligting in soos:
* Die genererende bediener is geïdentifiseer as `server.example.com`.
* 'n Foutkennisgewing vir `user@example.com` met die foutkode `#550 5.1.1 RESOLVER.ADR.RecipNotFound; nie gevind nie` is teruggestuur.
* Interne IP-adresse en gasheername is in die oorspronklike boodskapkoppe bekend gemaak.
2024-02-06 03:10:38 +00:00
```markdown
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:
2024-02-06 03:10:38 +00:00
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
```
## Konfigurasie lêers
```
host.conf
2022-10-02 19:15:35 +00:00
/etc/resolv.conf
/etc/bind/named.conf
/etc/bind/named.conf.local
/etc/bind/named.conf.options
/etc/bind/named.conf.log
/etc/bind/*
```
Dangerous settings when configuring a Bind server:
| **Option** | **Description** |
2022-10-02 19:15:35 +00:00
| ----------------- | ------------------------------------------------------------------------------ |
| `allow-query` | Definieer watter hosts toegelaat is om versoeke na die DNS-bediener te stuur. |
| `allow-recursion` | Definieer watter hosts toegelaat is om rekursiewe versoeke na die DNS-bediener te stuur. |
| `allow-transfer` | Definieer watter hosts toegelaat is om sone oordragte van die DNS-bediener te ontvang. |
| `zone-statistics` | Versamel statistiese data van sones. |
2022-10-02 19:15:35 +00:00
## References
2024-02-06 03:10:38 +00:00
* [https://www.myrasecurity.com/en/knowledge-hub/dns/](https://www.myrasecurity.com/en/knowledge-hub/dns/)
* Book: **Network Security Assessment 3rd edition**
2021-08-12 12:57:59 +00:00
## HackTricks Automatic Commands
```
2021-08-12 12:57:59 +00:00
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
2021-08-15 17:42:53 +00:00
Entry_1:
2024-02-11 02:07:06 +00:00
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
2021-08-15 17:42:53 +00:00
Entry_2:
2024-02-11 02:07:06 +00:00
Name: Banner Grab
Description: Grab DNS Banner
Command: dig version.bind CHAOS TXT @DNS
2021-08-15 17:42:53 +00:00
Entry_3:
2024-02-11 02:07:06 +00:00
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}
2021-08-15 17:42:53 +00:00
Entry_4:
2024-02-11 02:07:06 +00:00
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}
2021-08-15 17:42:53 +00:00
Entry_5:
2024-02-11 02:07:06 +00:00
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:
2024-02-11 02:07:06 +00:00
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'
2021-08-12 12:57:59 +00:00
```
<figure><img src="/.gitbook/assets/image (14) (1).png" alt=""><figcaption></figcaption></figure>
**Onmiddellik beskikbare opstelling vir kwesbaarheidsevaluering & penetrasietoetsing**. Voer 'n volledige pentest vanaf enige plek uit met 20+ gereedskap en funksies wat van rekognisie tot verslagdoening gaan. Ons vervang nie pentesters nie - ons ontwikkel pasgemaakte gereedskap, opsporing- & eksplorasie-modules om hulle weer 'n bietjie tyd te gee om dieper te delf, shells te pop en pret te hê.
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
{% hint style="success" %}
Leer & oefen AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Leer & oefen GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Ondersteun HackTricks</summary>
2024-01-03 10:42:55 +00:00
* Kyk na die [**subskripsieplanne**](https://github.com/sponsors/carlospolop)!
* **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Deel hacking truuks deur PR's in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}