mcpField
P
performing-dns-tunneling-detection

performing-dns-tunneling-detection

github.com/mukul975安全35.2k59 次安装8 周前更新
代码仓库

关于 performing-dns-tunneling-detection

面向安全运维和事件响应人员的 DNS 隧道检测技能,通过分析 DNS 查询名称的熵和统计特征来识别可疑流量,并提供 Python 与数据包示例。

主要功能

  1. 01计算查询名称的 Shannon 熵
  2. 02检测异常长的查询名称
  3. 03统计 TXT 请求和子域名数量
  4. 04检查标签中的字符分布
  5. 05使用 Scapy 分析 PCAP 文件

适用场景

  1. 01排查事件响应中的可疑 DNS 流量
  2. 02在授权的测试环境中验证检测控制

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill performing-dns-tunneling-detection

安装后在 Claude Code 中输入/performing-dns-tunneling-detection确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

执行 DNS 隧道检测

何时使用

  • 在执行涉及 DNS 隧道检测的安全评估时
  • 在针对相关安全事件遵循事件响应流程时
  • 在执行计划内的安全测试或审计活动时
  • 在通过动手测试验证安全控制措施时

前置条件

  • 熟悉安全运营概念和工具
  • 拥有可安全执行的测试或实验环境访问权限
  • 已安装所需依赖项的 Python 3.8+
  • 对任何测试活动拥有适当授权

操作说明

使用熵分析和对查询名称特征的统计方法,分析 DNS 流量中是否存在 DNS 隧道指标。

import math
from collections import Counter

def shannon_entropy(data):
    if not data:
        return 0
    counter = Counter(data)
    length = len(data)
    return -sum((c/length) * math.log2(c/length) for c in counter.values())

# Legitimate domain: low entropy (~3.0-3.5)
print(shannon_entropy("www.google.com"))
# DNS tunnel: high entropy (~4.0-5.0)
print(shannon_entropy("aGVsbG8gd29ybGQ.tunnel.example.com"))

关键检测指标:

  1. 查询名称中的 Shannon 熵较高(子域标签大于 3.5)
  2. 查询名称异常长(大于 50 个字符)
  3. 针对单个域名的 TXT 记录请求量高
  4. 每个父域名的唯一子域名数量高
  5. 标签中的字符分布非标准

示例

from scapy.all import rdpcap, DNS, DNSQR
packets = rdpcap("dns_traffic.pcap")
for pkt in packets:
    if pkt.haslayer(DNSQR):
        query = pkt[DNSQR].qname.decode()
        entropy = shannon_entropy(query)
        if entropy > 4.0:
            print(f"Suspicious: {query} (entropy={entropy:.2f})")

评论

支持 Markdown