6. Attacking DNS

nmap -p53 -Pn -sV -sC 10.10.110.213

AXFR Zone Transfer

dig AXFR @ns1.inlanefreight.htb inlanefreight.htb

where @ns1.inlanefreight.htb is a DNS server associated with the domain. [[2. DNS pt2electricboogaloo and vhosts#ZONE TRANSFERS]]

Tools like fierce can be used to enumerate all DNS servers of the root domain and scan for a DNS zone transfer

fierce --domain zonetransfer.me

6a. Domain takeovers and Subdomain enumeration

Domain takeovers

6b. subdomain enumeration

before attempting a subdomain takeover, enumerate with subfinder https://github.com/projectdiscovery/subfinder

./subfinder -d inlanefreight.com -v   

tool scrapes subds from open sources like DNSdumpster https://dnsdumpster.com/

other tools like Sublist3r can also be used to bruteforce subdomains with a pregenerated wordlist

another tool is subbrute https://github.com/TheRook/subbrute  This tool allows us to use self-defined resolvers and perform pure DNS brute-forcing attacks during internal penetration tests on hosts that do not have Internet access.

git clone https://github.com/TheRook/subbrute.git >> /dev/null 2>&1
cd subbrute
echo "ns1.inlanefreight.com" > ./resolvers.txt
./subbrute inlanefreight.com -s ./names.txt -r ./resolvers.txt

Warning: Fewer than 16 resolvers per process, consider adding more nameservers to resolvers.txt.
inlanefreight.com
ns2.inlanefreight.com
www.inlanefreight.com
ms1.inlanefreight.com
support.inlanefreight.com

<SNIP>

sometimes internal configs are poorly secured which we can exploit to upload our tools from a usb stick. another scenario is reaching internal hosts through pivoting

we can also enumerate cname records for those subdomains:

host support.inlanefreight.com

support.inlanefreight.com is an alias for inlanefreight.s3.amazonaws.com
The support subdomain has an alias record pointing to an AWS S3 bucket. However, the URL https://support.inlanefreight.com shows a NoSuchBucket error indicating that the subdomain is potentially vulnerable to a subdomain takeover. Now, we can take over the subdomain by creating an AWS S3 bucket with the same subdomain name

6c. dns spoofing

also referred to as DNS Cache Poisoning

local dns cache poisoning

stejwes@htb[/htb]# cat /etc/ettercap/etter.dns

inlanefreight.com      A   192.168.225.110
*.inlanefreight.com    A   192.168.225.110

after successful dns spoofing, if a victim user coming from 192.168.152.129 visits inlanefreight.com on a web browser they will be redirected to a fake page hosted on your attacking machine 192.168.225.110

pings to that domain will also resolve to 225.110


scenario:

Find all available DNS records for the "inlanefreight.htb" domain on the target name server and submit the flag found as a DNS record as the answer.
┌──(root㉿kali)-[~/cpts/attacking-common/dns/subbrute]
└─# echo "ns1.inlanefreight.htb" > ./resolvers.txt

┌──(root㉿kali)-[~/cpts/attacking-common/dns/subbrute]
└─# cat resolvers.txt
ns1.inlanefreight.htb

┌──(root㉿kali)-[~/cpts/attacking-common/dns/subbrute]
└─# python3 subbrute.py inlanefreight.htb -s ./names.txt -r ./resolvers.txt

Warning: Fewer than 16 resolvers per process, consider adding more nameservers to resolvers.txt.
inlanefreight.htb
hr.inlanefreight.htb
helpdesk.inlanefreight.htb
ns.inlanefreight.htb
control.inlanefreight.htb
malowicki.inlanefreight.htb
maloy.inlanefreight.htb

┌──(root㉿kali)-[~/cpts/attacking-common/dns/subbrute]
└─# dig axfr @inlanefreight.htb hr.inlanefreight.htb

; <<>> DiG 9.19.25-185-g392e7199df2-1-Debian <<>> axfr @inlanefreight.htb hr.inlanefreight.htb
; (1 server found)
;; global options: +cmd
hr.inlanefreight.htb.   604800  IN      SOA     inlanefreight.htb. root.inlanefreight.htb. 2 604800 86400 2419200 604800
hr.inlanefreight.htb.   604800  IN      TXT     "HTB{LUIHNFAS2871SJK1259991}"
hr.inlanefreight.htb.   604800  IN      NS      ns.inlanefreight.htb.
ns.hr.inlanefreight.htb. 604800 IN      A       127.0.0.1
hr.inlanefreight.htb.   604800  IN      SOA     inlanefreight.htb. root.inlanefreight.htb. 2 604800 86400 2419200 604800
;; Query time: 43 msec
;; SERVER: 10.129.59.207#53(inlanefreight.htb) (TCP)
;; WHEN: Thu Aug 22 14:50:44 EDT 2024
;; XFR size: 5 records (messages 1, bytes 230)


recent vulnerabilities We can find thousands of subdomains and domains on the web - often pointing to deactivated third party services providers or cloud providers. Companies often cancel services from 3rd party service providers but forget to delete the DNS records accompanied with those dns records - primarily because there's no cost associated with DNS entries.

One of the biggest dangers of a subdomain takeover is that a phishing campaign can be launched that is considered part of the official domain of the target company.