攻击者常利用内网对 DNS(端口 53)放行的策略,使用 DNS 隧道工具(如 dnscat2、iodine) 将敏感数据 Base32/Base64 编码后拼接在子域名中,通过递归解析外传给攻击者受控的权威服务器。
一、DNS 隧道典型请求与特征提取
text
# 典型 DNS 隧道 Exfiltration 数据包
aXJ1bHRlZDMxNGxvc3Quc2VjcmV0ZGF0YS5leGFtcGxlLmNvbQ==.attacker.compython
import math
def calculate_shannon_entropy(domain_label: str) -> float:
"""计算子域名字符香农熵:恶意隧道通常具有高熵特征"""
prob = [float(domain_label.count(c)) / len(domain_label) for c in dict.fromkeys(domain_label)]
entropy = -sum([p * math.log(p) / math.log(2.0) for p in prob])
return entropy # 若大于 3.8 则判定为可疑编码载荷