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
đïž 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 :
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
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