DNS Tunneling

Data Exfil Theory

Domain Name System (DNS) is a protocol used to translate human-readable domain names into IP addresses, which are necessary for routing internet traffic. Because DNS traffic is typically allowed through firewalls, attackers can abuse it to tunnel data in and out of restricted networks. When a client requests the IP address for a domain like www.example.com, it typically contacts a recursive resolver. The resolver queries, typically via UDP port 53, a hierarchy of DNS servers in this order:

  1. Root name server: Directs the resolver to the appropriate Top-Level Domain (TLD) name server based on the domain suffix (e.g., .com).

  2. Top Level Domain (TLD) name server: Refers the resolver to the authoritative name server for the specific domain.

  3. Authoritative name server: Holds the actual DNS records and returns the requested IP address via an A record.

In our scenario:

  • FELINEAUTHORITY is positoned in the WAN alongside our Kali host and acts as the authoritative name server for the feline.corp zone.

  • MULTISERVER03, CONFLUENCE01, and Kali can route to it, but PGDATABASE01 and HRSHARES cannot.

  • PGDATABASE01 uses MULTISERVER03 as its DNS resolver.

When PGDATABASE01 sends a DNS query for exfiltrated-data.feline.corp, it forwards the request to MULTISERVER03, which then forwards it to FELINEAUTHORITY since it’s authoritative for the zone. The dnsmasq service running on FELINEAUTHORITY responds to the query with NXDOMAIN (request failed) since it is not configured to respond for this specific URL (it does not have an A record for it).

In the above scenario, an arbitrary DNS query from an internal host with no other outbound connectivity (PGDATABASE01) has found its way to an external server we control (FELINEAUTHORITY). This makes DNS a potential covert channel for exfiltration. Data can be split into chunks, converted to a safe format like hexadecimal or Base64, and sent via the subdomain part of DNS queries (e.g.,chunk1 on chunk1.feline.corp). The authoritative server logs these and reconstructs the data.

Data Infil Theory

Conversely, arbitrary data can be infiltrated using DNS TXT records, a DNS record type designed to carry arbitrary string data. Configuring dnsmasq to serve TXT records allows a remote client to query for them using tools like nslookup, receiving back the configured string values. This can be expanded to deliver encoded files or commands into isolated networks.

This bidirectional data exchange capability via DNS underpins techniques like DNS tunneling, where tools (e.g., dnscat2) encode traffic into DNS queries and responses to bypass typical network restrictions.

dnscat2

dnscat2 is a tool for creating a covert command-and-control (C2) channel using DNS queries and responses. It can exfiltrate data by embedding it in DNS subdomain queries and receive data through DNS record types like TXT, CNAME, and MX.

A typical setup involves running a dnscat2 server on an authoritative DNS server for a chosen domain, and a dnscat2 client on a compromised host configured to query that domain. This forms a tunnel through standard DNS traffic, often overlooked by firewalls.

Last updated

Was this helpful?