Peculiar DNS Traffic
DNS traffic analysis can be challenging due to its high volume, but identifying abnormalities is crucial for detecting malicious activity.
DNS Queries
DNS queries allow clients to resolve domain names to IP addresses and vice versa.
DNS Forward Queries
In a forward lookup, the client resolves a domain name to an IP address, following these steps:
Query Initiation: Client queries domain, e.g.,
academy.hackthebox.com.Local Cache Check: Checks local DNS cache; if unresolved, continues.
Recursive Query: Sends query to the configured DNS server.
Root Servers: DNS resolver queries root servers if necessary.
TLD Servers: Root server directs to TLD servers (e.g.,
.com).Authoritative Servers: TLD server points to domain's authoritative server.
Domain’s Authoritative Servers: The resolver obtains the IP address.
Response: The IP address is sent back to the client.
DNS Reverse Lookups/Queries
Reverse lookups are used to find a domain name from an IP address:
Query Initiation: Client sends a DNS reverse query with the IP.
Reverse Lookup Zones: DNS resolver checks if it is authoritative.
PTR Record Query: Resolver searches for a PTR record.
Response: The FQDN is returned if a matching PTR is found.
DNS Record Types
A
Maps a domain name to an IPv4 address
AAAA
Maps a domain name to an IPv6 address
CNAME
Creates an alias for a domain
MX
Specifies mail server for the domain
NS
Authoritative name servers for the domain
PTR
Used in reverse queries to map IP to a domain
TXT
Specifies text associated with the domain
SOA
Administrative information about the zone
Detecting DNS Enumeration Attempts
A high volume of DNS queries from a single host may suggest DNS enumeration. Using Wireshark, filter DNS traffic as follows:
dnsIf queries include ANY, this could indicate DNS enumeration, or even subdomain enumeration.
Finding DNS Tunneling
DNS tunneling can involve a significant number of TXT records from one host. Attackers may exfiltrate data by appending it to the TXT field of DNS queries.
Example of DNS Tunneling Indicators
Examine DNS traffic for unusual or unexpected text in the TXT field. Encoded or encrypted data may appear, often as base64:
Extracting Base64 Encoded Data:
echo 'VTBaU1EyVXhaSFprVjNocldETnNkbVJXT1cxaU0wb3pXVmhLYTFneU1XeFlNMUp2WVZoT1ptTklTbXhrU0ZJMVdETkNjMXBYUm5wYQpXREJMQ2c9PQo=' | base64 -dHandling Multi-Level Encoding:
echo 'encoded_string' | base64 -d | base64 -d | base64 -dSome attackers may encode data multiple times or encrypt it, making detection harder.
Reasons for DNS Tunneling
Data Exfiltration: Used to covertly export data from a network.
Command and Control: Enables compromised systems to communicate with attacker-controlled servers, often used in botnets.
Firewall Bypassing: DNS tunnels can bypass firewalls or proxies focused on HTTP/HTTPS.
Domain Generation Algorithms (DGAs): Advanced malware uses DGAs to generate dynamic domain names, complicating detection.
The Interplanetary File System and DNS Tunneling
Advanced threat actors may use IPFS to store and retrieve malicious files, making DNS/HTTP traffic to URIs like the following noteworthy:
IPFS Example URI:
https://cloudflare-ipfs.com/ipfs/QmS6eyoGjENZTMxM7UdqBk6Z3U3TZPAVeJXdgp9VK4o1Sz
IPFS operates on a peer-to-peer basis, complicating detection. Regular monitoring of DNS and HTTP/HTTPS traffic is essential to mitigate these attacks.
Last updated