Skip to content
Skillpedia
Analysis & spreadsheets35k · #5661

detecting-dns-exfiltration-with-dns-query-analysis

Helps your agent detect data theft via DNS. It analyzes DNS query patterns to identify suspicious traffic used to hide data.

What it does

This tool analyzes DNS traffic to find attempts at data theft. It looks for unusual patterns in how data is sent through DNS queries and responses, which might indicate the use of malicious tools.

When to use it

  • ✓When investigating a potential data leak over the network.
  • ✓When monitoring network security for suspicious activities.
  • ✓When trying to understand how attack tools use DNS.

Example of what to ask your AI

“Look for anomalous activity in DNS traffic that might indicate data exfiltration.”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-dns-exfiltration-with-dns-query-analysis/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-dns-exfiltration-with-dns-query-analysis/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

The tool examines characteristics of DNS queries, such as subdomain length, the number of queries to the same domain, and the types of DNS records used. It compares these characteristics against normal patterns to identify anomalies.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill detecting-dns-exfiltration-with-dns-query-analysis

Or download just the file:

curl -L https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/main/skills/detecting-dns-exfiltration-with-dns-query-analysis/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Detecting DNS Exfiltration with DNS Query Analysis

Overview

DNS exfiltration exploits the Domain Name System as a covert channel to extract data from compromised networks. Attackers encode stolen data into DNS query names (subdomains) or DNS response records (TXT, CNAME, NULL), bypassing traditional security controls that typically allow DNS traffic unrestricted. Tools like iodine, dnscat2, and dns2tcp enable full TCP tunneling over DNS. Detection requires analyzing DNS query patterns for anomalies including excessive query length, high entropy subdomain strings, abnormal query volumes to single domains, and oversized TXT record responses. This skill covers building a comprehensive DNS exfiltration detection capability using passive DNS analysis, statistical methods, and machine learning approaches.

When to Use

  • When investigating security incidents that require detecting dns exfiltration with dns query analysis
  • When building detection rules or threat hunting queries for this domain
  • When SOC analysts need structured procedures for this analysis type
  • When validating security monitoring coverage for related attack techniques

Prerequisites

  • Access to DNS query logs (passive DNS capture, DNS server logs, or PCAP)
  • Zeek, Suricata, or tcpdump for DNS traffic capture
  • Python 3.8+ with scipy, numpy, pandas, and scikit-learn
  • SIEM platform for alert correlation
  • Baseline of normal DNS traffic patterns for the environment

Core Concepts

DNS Tunneling Mechanics

DNS exfiltration encodes data in different parts of DNS messages:

Outbound (Query-based exfiltration):

Encoded data as subdomain labels:
dGhlIHNlY3JldCBkYXRh.exfil.attacker.com
[base64-encoded data].[tunnel domain]

Query types used: A, AAAA, CNAME, MX, TXT, NULL

Inbound (Response-based command channel):

TXT records carry encoded commands/data in responses
CNAME records chain encoded data through multiple labels
NULL records carry arbitrary binary data

Detection Indicators

Indicator Normal DNS DNS Tunneling
Subdomain length 5-20 chars 40-253 chars
Label count 2-4 labels 5-10+ labels
Shannon entropy 2.5-3.5 bits 4.0-5.5 bits
Query volume (per domain) Variable 100s-1000s/min
TXT response size < 100 bytes 200-4000+ bytes
Unique subdomains Low Very high
Query type distribution Mostly A/AAAA Heavy TXT, NULL, CNAME

Common Tunneling Tools

Tool Protocol Encoding Detection Difficulty
iodine IP-over-DNS Base32/Base64/Raw Medium
dnscat2 TCP-over-DNS Hex encoding Medium
dns2tcp TCP-over-DNS Base64 Medium
DNSExfiltrator Custom Base64 Low
Cobalt Strike DNS C2 over DNS Custom encoding High

Workflow

Step 1: Capture DNS Traffic

Using Zeek:

# Live capture
zeek -i eth0 -C base/protocols/dns

# Offline PCAP analysis
zeek -r traffic.pcap base/protocols/dns

# Output: dns.log with query, qtype, answers, TTL

Using tcpdump:

# Capture all DNS traffic
tcpdump -i eth0 -w dns_capture.pcap port 53

# Capture with size filter (large DNS packets)
tcpdump -i eth0 -w large_dns.pcap 'port 53 and greater 512'

Using Suricata:

# In suricata.yaml, enable DNS logging
outputs:
  - eve-log:
      types:
        - dns:
            query: yes
            answer: yes
            formats: [detailed]

Step 2: Analyze Query Characteristics

Python script for DNS exfiltration detection:

#!/usr/bin/env python3
"""DNS Exfiltration Detector - Analyzes DNS logs for tunneling indicators."""

import json
import math
import re
import sys
from collections import defaultdict
from datetime import datetime, timedelta

import pandas as pd


def calculate_entropy(domain: str) -> float:
    """Calculate Shannon entropy of a string."""
    if not domain:
        return 0.0
    freq = defaultdict(int)
    for char in domain:
        freq[char] += 1
    length = len(domain)
    entropy = -sum(
        (count / length) * math.log2(count / length)
        for count in freq.values()
    )
    return entropy


def extract_subdomain(query: str) -> str:
    """Extract subdomain portion from FQDN."""
    parts = query.rstrip('.').split('.')
    if len(parts) > 2:
        return '.'.join(parts[:-2])
    return ''


def get_base_domain(query: str) -> str:

…
FAQ

What is DNS data exfiltration?

It's a technique where attackers hide stolen data within DNS queries or responses to send it out of the network, bypassing firewalls.

What tools use this technique?

Common tools include iodine, dnscat2, and dns2tcp, which create tunnels to transfer data over DNS.

What are 'TXT/CNAME/NULL records'?

These are types of DNS records that can be used to carry data. Attacks might abuse these records to send or receive information.

Details

Original description by the author

Detect data exfiltration via DNS tunneling (tools like iodine, dnscat2, dns2tcp) by analyzing query entropy, subdomain length, query volume to single domains, TXT/CNAME/NULL record abuse, and oversized response payloads using passive DNS monitoring and statistical/ML methods. Use when hunting for covert DNS-based data exfiltration or building a passive DNS anomaly detection capability.

repo: mukul975/Anthropic-Cybersecurity-Skills

Popularity

GitHub stars
35k
Ranking position
#5661
License
Apache-2.0
Updated
8/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills