DNS (Domain Name System)

🧠 Qu'est-ce que le DNS ?

Le Domain Name System (DNS) est un systĂšme distribuĂ© dont le rĂŽle est de traduire les noms de domaines en adresses IP. Il permet ainsi Ă  un utilisateur de taper www.hackthebox.com dans son navigateur au lieu d’une adresse IP comme 10.129.14.5. DNS est souvent comparĂ© Ă  un annuaire tĂ©lĂ©phonique de l’internet.

Il n’existe pas de base de donnĂ©es centrale. À la place, des milliers de serveurs DNS interconnectĂ©s maintiennent collectivement l’ensemble des informations de rĂ©solution.


đŸ—ïž Types de serveurs DNS

Type de serveur
Description

đŸ›ïž DNS Root Server

Serveurs racine pour les TLDs (.com, .org, etc.). Il en existe 13 dans le monde, coordonnĂ©s par l’ICANN.

📘 Authoritative Name Server

Répond avec autorité pour un domaine spécifique.

📗 Non-Authoritative Server

Sert des réponses en cache ou obtenues via d'autres serveurs.

đŸ—‚ïž Caching Server

Conserve temporairement les réponses DNS pour améliorer la vitesse.

🚀 Forwarding Server

Transmet les requĂȘtes Ă  un autre serveur DNS.

đŸ’» Resolver

Souvent local (machine ou box), effectue la résolution initiale.


🔐 SĂ©curitĂ© & ConfidentialitĂ©

Traditionnellement, DNS est non chiffrĂ©, ce qui permet Ă  des acteurs malveillants ou Ă  des FAI d’intercepter les requĂȘtes. Des protocoles comme DNS over TLS (DoT), DNS over HTTPS (DoH) ou encore DNSCrypt permettent dĂ©sormais de chiffrer les Ă©changes.


📄 Types d’enregistrements DNS

Voici les enregistrements les plus courants et leur rĂŽle :

Enregistrement
Description

A

Associe un domaine Ă  une adresse IPv4.

AAAA

Associe un domaine Ă  une adresse IPv6.

MX

Indique les serveurs de messagerie.

NS

Spécifie les nameservers du domaine.

TXT

Contient des données diverses : vérification Google, SPF, DMARC


CNAME

Alias vers un autre domaine (Canonical Name).

PTR

RĂ©solution inverse d’une IP vers un nom.

SOA

Donne des infos sur la zone DNS (admin, serial, etc.).


đŸ§© HiĂ©rarchie DNS

Exemple hiérarchique pour WS01.dev.inlanefreight.com :

scssCopierModifier. (racine)
├── com (TLD)
│   └── inlanefreight (Second-level)
│       ├── dev (Sous-domaine)
│       │   └── WS01 (Hîte)

⚙ Configuration DNS (BIND9)

BIND9 est une des implémentations les plus utilisées sous Linux. Elle repose sur trois fichiers principaux :

  • named.conf (configuration gĂ©nĂ©rale)

  • Zone files (rĂ©solution directe)

  • Reverse files (rĂ©solution inverse)

đŸ—ƒïž Exemple : named.conf.local

bashCopierModifierzone "domain.com" {
    type master;
    file "/etc/bind/db.domain.com";
    allow-update { key rndc-key; };
};

📁 Exemple : fichier de zone directe

bashCopierModifier$ORIGIN domain.com.
@ IN SOA dns1.domain.com. hostmaster.domain.com. (
    2024060101 ; serial
    3600       ; refresh
    1800       ; retry
    604800     ; expire
    86400 )    ; minimum TTL

IN NS ns1.domain.com.
IN MX 10 mail.domain.com.
www IN A 10.10.10.10

🔁 Exemple : fichier de zone inverse

bashCopierModifier$ORIGIN 10.10.10.in-addr.arpa.
@ IN SOA dns1.domain.com. hostmaster.domain.com. (
    2024060101 ; serial
    3600       ; refresh
    1800       ; retry
    604800     ; expire
    86400 )    ; minimum TTL

10 IN PTR www.domain.com.

⚠ ParamĂštres sensibles & erreurs courantes

Option
Risque potentiel

allow-query { any; };

Le serveur peut rĂ©pondre Ă  tout le monde, mĂȘme sur Internet.

allow-transfer { any; };

Permet des transferts de zone non autorisés (AXFR).

allow-recursion { any; };

Peut ĂȘtre utilisĂ© pour des attaques de type DNS Amplification.

zone-statistics yes;

Peut révéler des métadonnées sensibles.


🧭 Techniques d’énumĂ©ration DNS

Voici quelques exemples d’énumĂ©ration possibles :

  • 🔍 Obtenir les nameservers : dig ns domain.com @<IP>

  • 🔁 Transfert de zone (AXFR) : dig axfr domain.com @<IP>

  • đŸ•”ïž Brute force des sous-domaines : boucle Bash ou dnsenum

  • 📩 Voir tous les enregistrements publics : dig any domain.com @<IP>

  • 💬 Voir la version du serveur DNS : dig CH TXT version.bind @<IP>


📚 Ressources utiles


Interact with the target DNS using its IP address and enumerate the FQDN of it for the "inlanefreight.htb" domain.

Nous interagissons comme demandé :

$ dig any inlanefreight.htb @10.xx.xx.xx

;; ANSWER SECTION:
inlanefreight.htb.	604800	IN	TXT	"v=spf1 include:mailgun.org include:_spf.google.com include:spf.protection.outlook.com include:_spf.atlassian.net ip4:10.xx.xx.xx ip4:10.xx.xx.xx ip4:10.xx.xx.xx ~all"
inlanefreight.htb.	604800	IN	TXT	"atlassian-domain-verification=t1rKCy68JFszSdCKVpw64A1QksWdXuYFUeSXKU"
inlanefreight.htb.	604800	IN	TXT	"MS=ms97310371"
inlanefreight.htb.	604800	IN	SOA	inlanefreight.htb. root.inlanefreight.htb. 2 604800 86400 2419200 604800
inlanefreight.htb.	604800	IN	NS	ns.inlanefreight.htb.

;; ADDITIONAL SECTION:
ns.inlanefreight.htb.	604800	IN	A	127.0.0.1

Nous obtenons ainsi le FQDN souhaité : ns.inlanefreight.htb.


Identify if its possible to perform a zone transfer and submit the TXT record as the answer. (Format: HTB{...})

Nous dressons dans un premier temps les zones de transfers de inlanefreight.htb :

$ dig axfr inlanefreight.htb @10.129.116.154

; <<>> DiG 9.18.28-1~deb12u2-Debian <<>> axfr inlanefreight.htb @10.xx.xx.xx
inlanefreight.htb.	604800	IN	SOA	inlanefreight.htb. root.inlanefreight.htb. 2 604800 86400 2419200 604800
inlanefreight.htb.	604800	IN	TXT	"MS=ms97310371"
inlanefreight.htb.	604800	IN	TXT	"atlassian-domain-verification=t1rKCy68JFszSdCKVpw64A1QksWdXuYFUeSXKU"
inlanefreight.htb.	604800	IN	TXT	"v=spf1 include:mailgun.org include:_spf.google.com include:spf.protection.outlook.com include:_spf.atlassian.net ip4:10.xx.xx.xx ip4:10.xx.xx.xx ip4:10.xx.xx.xx ~all"
inlanefreight.htb.	604800	IN	NS	ns.inlanefreight.htb.
app.inlanefreight.htb.	604800	IN	A	10.xx.xx.xx
dev.inlanefreight.htb.	604800	IN	A	10.xx.xx.xx
internal.inlanefreight.htb. 604800 IN	A	10.xx.xx.xx
mail1.inlanefreight.htb. 604800	IN	A	10.xx.xx.xx
ns.inlanefreight.htb.	604800	IN	A	127.0.0.1
inlanefreight.htb.	604800	IN	SOA	inlanefreight.htb. root.inlanefreight.htb. 2 604800 86400 2419200 604800

Certains sous-domaines nous sont alors remontés :

  • app.inlanefreight.htb

  • dev.inlanefreight.htb

  • internal.inlanefreight.htb

  • mail1.inlanefreight.htb

  • ns.inlanefreight.htb

Nous utilisons alors dig pour checker les zones de transfert sur chacun des sous-domaines jusqu'a tomber sur ce résultat :

$ dig axfr internal.inlanefreight.htb @10.xx.xx.xx

internal.inlanefreight.htb. 604800 IN	SOA	inlanefreight.htb. root.inlanefreight.htb. 2 604800 86400 2419200 604800
internal.inlanefreight.htb. 604800 IN	TXT	"MS=ms97310371"
internal.inlanefreight.htb. 604800 IN	TXT	"HTB{DN5_z0N3_7r4N5F3r_iskdufhcnlu34}"
internal.inlanefreight.htb. 604800 IN	TXT	"atlassian-domain-verification=t1rKCy68JFszSdCKVpw64A1QksWdXuYFUeSXKU"
internal.inlanefreight.htb. 604800 IN	TXT	"v=spf1 include:mailgun.org include:_spf.google.com include:spf.protection.outlook.com include:_spf.atlassian.net ip4:10.xx.xx.xx ip4:10.xx.xx.xx ip4:10.xx.xx.xx ~all"
internal.inlanefreight.htb. 604800 IN	NS	ns.inlanefreight.htb.
dc1.internal.inlanefreight.htb.	604800 IN A	10.xx.xx.xx
dc2.internal.inlanefreight.htb.	604800 IN A	10.xx.xx.xx
mail1.internal.inlanefreight.htb. 604800 IN A	10.xx.xx.xx
ns.internal.inlanefreight.htb. 604800 IN A	127.0.0.1
vpn.internal.inlanefreight.htb.	604800 IN A	10.xx.xx.xx
ws1.internal.inlanefreight.htb.	604800 IN A	10.xx.xx.xx4
ws2.internal.inlanefreight.htb.	604800 IN A	10.xx.xx.xx
wsus.internal.inlanefreight.htb. 604800	IN A	10.xx.xx.xx
internal.inlanefreight.htb. 604800 IN	SOA	inlanefreight.htb. root.inlanefreight.htb. 2 604800 86400 2419200 604800

Nous pouvons relevé la ligne suivante :

internal.inlanefreight.htb. 604800 IN	TXT	"HTB{DN5_z0N3_7r4N5F3r_iskdufhcnlu34}"

Cette ligne nous permet d'obtenir le flag :

HTB{DN5_z0N3_7r4N5F3r_iskdufhcnlu34}

What is the IPv4 address of the hostname DC1?

Grùce à la commande effectuée précédemment, nous savons que l'IP associée au DC1 est 10.129.34.16.


What is the FQDN of the host where the last octet ends with "x.x.x.203"?

Afin de résoudre cette question, j'effectue donc dans un premier temps une recherche des sous-domaines liés à inlanefreight.htb :

$ dnsenum --dnsserver 10.xx.xx.xx --enum -p 0 -s 0 -o subdomains.txt -f /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-110000.txt inlanefreight.htb 
dnsenum VERSION:1.2.6
-----   inlanefreight.htb   -----

Name Servers:
______________
ns.inlanefreight.htb.                    604800   IN    A         127.0.0.1


Trying Zone Transfers and getting Bind Versions:
_________________________________________________

unresolvable name: ns.inlanefreight.htb at /usr/bin/dnsenum line 900 thread 1.

Trying Zone Transfer for inlanefreight.htb on ns.inlanefreight.htb ... 
AXFR record query failed: no nameservers


Brute forcing with /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-110000.txt:
__________________________________________________________________________________________________

ns.inlanefreight.htb.                    604800   IN    A         127.0.0.1
mail1.inlanefreight.htb.                 604800   IN    A        10.xx.xx.xx
app.inlanefreight.htb.                   604800   IN    A        10.xx.xx.xx
ns.dev.inlanefreight.htb.                604800   IN    A         127.0.0.1

Nous observons alors la présence du sous-domaine dev.inlanefreight.htb.

Maintenant, nous effectuons une recherche des sous-domaines liés à ce dernier, ceci à l'aide de la liste :

$ dnsenum --dnsserver 10.xx.xx.xx --enum -p 0 -s 0 -o subdomains.txt -f /usr/share/wordlists/seclists/Discovery/DNS/fierce-hostlist.txt dev.inlanefreight.htb 
dnsenum VERSION:1.2.6

Name Servers:
______________

ns.inlanefreight.htb.                    604800   IN    A         127.0.0.1


Brute forcing with /usr/share/wordlists/seclists/Discovery/DNS/fierce-hostlist.txt:
____________________________________________________________________________________
dev1.dev.inlanefreight.htb.              604800   IN    A         10.xx.xx.xx
ns.dev.inlanefreight.htb.                604800   IN    A         127.0.0.1
win2k.dev.inlanefreight.htb.             604800   IN    A         10.xx.xx.203

Cette énumération nous permet alors de relever ceci :

win2k.dev.inlanefreight.htb.             604800   IN    A         10.xx.xx.203

Le FQDN lié à l'IP terminant par 203 est donc win2k.dev.inlanefreight.htb.


Mis Ă  jour