网络安全-wireshark工具
网络安全-wireshark工具
作者:Hanami 介绍:Wireshark 过滤规则速查手册
一、基础语法
Wireshark 过滤分为两类:
- 协议过滤:基于协议和属性值(如
tcp.port==80、http.request.method=="GET"
) - 内容过滤:基于字符串匹配(如
http contains "Server"
)或偏移匹配(如tcp[20:3] == 47:45:54
)
二、核心过滤规则
IP/MAC 地址过滤
# IP 地址过滤
ip.addr == 8.8.8.8 # 指定IP地址
ip.src == 8.8.8.8 # 源IP
ip.dst == 8.8.8.8 # 目标IP
ip.addr == 10.0.0.0/16 # 网段过滤
# MAC 地址过滤(将ip改为eth)
eth.addr == xx:xx:xx:xx:xx:xx
端口过滤
# TCP/UDP 端口过滤
tcp.port == 9090 # 指定端口
tcp.dstport == 9090 # 目标端口
tcp.srcport == 9090 # 源端口
tcp.port >=1 and tcp.port <= 80 # 端口范围
udp.port == 53 # UDP端口
长度过滤
tcp.len >= 7 # TCP数据长度
ip.len == 88 # IP包长度(除固定头部)
udp.length == 26 # UDP包长度(含8字节头部)
frame.len == 999 # 整个数据包长度
HTTP 专项过滤
# 基础过滤
http.host == xxx.com # 主机名
http.request.method == POST # 请求方法
http.response.code == 302 # 响应状态码
http.request.uri == "/api" # 请求路径
# 内容过滤
http.cookie contains xxx # Cookie内容
http.server contains "nginx" # 服务器类型
http.content_type == "text/html" # 内容类型
http.content_encoding == "gzip" # 编码方式
http.content_length == 279 # 内容长度
DNS 专项过滤
# 基础DNS过滤
dns # 所有DNS流量
dns.qry.name == "google.com" # 查询特定域名
dns.qry.type == 1 # A记录查询 (IPv4地址)
dns.qry.type == 28 # AAAA记录查询 (IPv6地址)
dns.qry.type == 15 # MX记录查询 (邮件服务器)
dns.qry.type == 5 # CNAME记录查询 (别名)
# DNS响应分析
dns.flags.response == 1 # DNS响应包
dns.flags.response == 0 # DNS查询包
dns.flags.rcode == 0 # 成功响应 (NOERROR)
dns.flags.rcode == 3 # 域名不存在 (NXDOMAIN)
dns.flags.rcode == 2 # 服务器失败 (SERVFAIL)
# DNS服务器分析
ip.dst == 8.8.8.8 and dns # 发往Google DNS的查询
ip.src == 1.1.1.1 and dns # 来自Cloudflare DNS的响应
ip.dst == 223.5.5.5 and dns # 发往阿里DNS的查询 (可能的泄露)
# DNS加密流量检测
tcp.port == 853 # DNS over TLS (DoT)
tcp.port == 443 and http.host contains "dns" # DNS over HTTPS (DoH)
http.request.uri contains "/dns-query" # DoH查询路径
ssl.handshake.extensions_server_name contains "dns" # DoT/DoH握手
# DNS异常检测
dns.qry.name contains ".." # 可疑的域名格式
dns.qry.name matches ".*\.tk$" # 特定TLD域名 (如.tk免费域名)
dns and frame.len > 512 # 超长DNS包 (可能的DNS隧道)
dns.count.queries > 1 # 多查询DNS包
# DNS缓存投毒检测
dns.flags.response == 1 and dns.count.answers > 10 # 异常多答案
dns.a != 0.0.0.0 and ip.src != dns.a # 响应IP与源IP不符
# DNS泄露分析
(ip.dst == 192.168.0.0/16 or ip.dst == 10.0.0.0/8) and dns # 内网DNS查询
not (ip.dst == 1.1.1.1 or ip.dst == 8.8.8.8 or ip.dst == 9.9.9.9) and dns # 非公共DNS
时间和统计过滤
# 时间范围过滤
frame.time >= "2024-12-19 10:00:00" and frame.time <= "2024-12-19 11:00:00"
frame.time_relative >= 10 # 抓包开始后10秒内的流量
# 流量统计
frame.len > 1000 # 大包过滤 (>1KB)
tcp.analysis.retransmission # TCP重传包
tcp.analysis.duplicate_ack # 重复ACK包
组合过滤示例
# DNS泄露检测组合
dns and not (ip.dst == 1.1.1.1 or ip.dst == 8.8.8.8 or ip.dst == 9.9.9.9 or ip.dst == 149.112.112.112)
# 加密流量分析
(tcp.port == 853 or (tcp.port == 443 and http.host contains "dns")) and ssl
# 可疑DNS活动
dns and (dns.qry.name contains "tunnel" or dns.qry.name matches ".*\.tk$" or frame.len > 512)
# 网络故障诊断
(icmp.type == 3) or (dns.flags.rcode != 0) or tcp.analysis.retransmission
三、常用协议
tcp、udp、arp、icmp、http、https、ssl、dns、smtp、ftp、ssh、telnet
四、实用技巧
基础操作技巧
- 组合过滤:使用
and、or、not
连接条件 - 正则匹配:
matches
操作符支持正则表达式 - 快速定位:右键数据包选择"Follow TCP Stream"查看完整会话
- 导出过滤:File → Export → 导出特定过滤结果
DNS分析实践
# DNS泄露检测流程
1. 使用过滤器: dns and not (ip.dst == 1.1.1.1 or ip.dst == 8.8.8.8)
2. 查看是否有发往ISP DNS服务器的查询
3. 分析Statistics → Conversations → IPv4 查看DNS服务器分布
# 加密DNS验证
1. 过滤DoH流量: http.request.uri contains "/dns-query"
2. 过滤DoT流量: tcp.port == 853
3. 检查是否存在端口53的明文DNS流量
# DNS性能分析
1. 统计DNS响应时间: Statistics → Service Response Time → DNS
2. 查看DNS错误: dns.flags.rcode != 0
3. 分析DNS查询分布: Statistics → DNS
常见分析场景
- 网络故障排查:结合ICMP和DNS错误码分析连接问题
- 安全审计:检测DNS隧道、缓存投毒和异常查询
- 隐私保护验证:确认DNS加密配置是否生效
- 性能优化:分析DNS响应时间和服务器选择
// 以上为Wireshark核心过滤规则,特别适用于DNS安全分析和网络诊断。