# Wireshark 使用手册与过滤器完全指南 ## 1. Wireshark 基础介绍 ### 1.1 什么是 Wireshark Wireshark 是世界上最流行的网络协议分析工具,用于捕获和交互式浏览网络流量。 ### 1.2 两种过滤器类型 - **Capture Filter(捕获过滤器)**:在捕获前过滤,减少捕获的数据量 - **Display Filter(显示过滤器)**:在捕获后过滤,用于分析已捕获的数据 ### 1.3 界面布局 ``` +------------------------------------------+ | 菜单栏 | 工具栏 | Display Filter 输入框 | +------------------------------------------+ | Packet List(数据包列表) | +------------------------------------------+ | Packet Details(数据包详细信息) | +------------------------------------------+ | Packet Bytes(数据包字节流) | +------------------------------------------+ ``` --- ## 2. Display Filter(显示过滤器)详解 ### 2.1 基本语法 #### 2.1.1 比较运算符 ``` == (eq) 等于 != (ne) 不等于 > (gt) 大于 < (lt) 小于 >= (ge) 大于等于 <= (le) 小于等于 ``` #### 2.1.2 逻辑运算符 ``` and (&&) 逻辑与 or (||) 逻辑或 not (!) 逻辑非 xor (^^) 逻辑异或 ``` #### 2.1.3 搜索运算符 ``` contains 包含 matches 正则表达式匹配 in 在范围内 ``` ### 2.2 基础过滤器 #### 2.2.1 按协议过滤 ```bash # 显示特定协议 http tcp udp dns icmp arp tls ssh ftp smtp # 排除特定协议 !http not tcp ``` #### 2.2.2 按 IP 地址过滤 ```bash # 源 IP 地址 ip.src == 192.168.1.1 ip.src == 10.0.0.0/8 # 目标 IP 地址 ip.dst == 192.168.1.100 # 源或目标 IP ip.addr == 192.168.1.1 # IP 地址段 ip.addr == 192.168.1.0/24 # 多个 IP 地址 ip.addr == 192.168.1.1 or ip.addr == 192.168.1.2 # 排除 IP !(ip.addr == 192.168.1.1) ``` #### 2.2.3 按端口过滤 ```bash # TCP 端口 tcp.port == 80 tcp.srcport == 443 tcp.dstport == 8080 # UDP 端口 udp.port == 53 udp.srcport == 67 # 端口范围 tcp.port >= 1000 and tcp.port <= 2000 # 多个端口 tcp.port == 80 or tcp.port == 443 or tcp.port == 8080 ``` #### 2.2.4 按 MAC 地址过滤 ```bash # 源 MAC 地址 eth.src == 00:11:22:33:44:55 # 目标 MAC 地址 eth.dst == AA:BB:CC:DD:EE:FF # 任意 MAC 地址 eth.addr == 00:11:22:33:44:55 ``` ### 2.3 HTTP 过滤器(重点) #### 2.3.1 HTTP 请求方法 ```bash # GET 请求 http.request.method == "GET" # POST 请求 http.request.method == "POST" # 其他方法 http.request.method == "PUT" http.request.method == "DELETE" http.request.method == "HEAD" http.request.method == "OPTIONS" ``` #### 2.3.2 HTTP 状态码 ```bash # 所有响应 http.response # 特定状态码 http.response.code == 200 http.response.code == 404 http.response.code == 500 # 状态码范围 http.response.code >= 400 http.response.code >= 400 and http.response.code < 500 # 4xx 错误 http.response.code >= 500 # 5xx 错误 ``` #### 2.3.3 HTTP 主机和 URI ```bash # 主机名 http.host == "www.example.com" http.host contains "google" # 完整 URI http.request.uri == "/api/v1/users" http.request.uri contains "/admin" http.request.uri matches "\\.(php|asp|jsp)$" # 请求的完整 URL http.request.full_uri contains "password" ``` #### 2.3.4 HTTP 头部 ```bash # User-Agent http.user_agent contains "Mozilla" http.user_agent contains "curl" http.user_agent contains "python" # Cookie http.cookie contains "session" http.cookie contains "PHPSESSID" # Referer http.referer contains "google.com" # Authorization http.authorization # Content-Type http.content_type contains "application/json" http.content_type == "text/html" ``` #### 2.3.5 HTTP 内容过滤 ```bash # 请求/响应包含特定字符串 http contains "password" http contains "admin" http contains "flag{" # 请求体包含 http.request.body contains "username" # 响应体包含 http.response.body contains "error" ``` ### 2.4 TCP 过滤器(重点) #### 2.4.1 TCP 标志位 ```bash # SYN 包(连接建立) tcp.flags.syn == 1 # SYN-ACK 包 tcp.flags.syn == 1 and tcp.flags.ack == 1 # ACK 包 tcp.flags.ack == 1 # FIN 包(连接终止) tcp.flags.fin == 1 # RST 包(连接重置) tcp.flags.reset == 1 # PSH 包(立即推送数据) tcp.flags.push == 1 # URG 包(紧急数据) tcp.flags.urg == 1 # 只有 SYN 标志(三次握手第一步) tcp.flags == 0x002 ``` #### 2.4.2 TCP 连接分析 ```bash # TCP 三次握手 tcp.flags.syn == 1 and tcp.flags.ack == 0 # 第一步 tcp.flags.syn == 1 and tcp.flags.ack == 1 # 第二步 tcp.flags.syn == 0 and tcp.flags.ack == 1 # 第三步 # TCP 重传 tcp.analysis.retransmission # TCP 乱序 tcp.analysis.out_of_order # TCP 快速重传 tcp.analysis.fast_retransmission # TCP 重复 ACK tcp.analysis.duplicate_ack # TCP 窗口满 tcp.analysis.window_full # TCP 零窗口 tcp.analysis.zero_window ``` #### 2.4.3 TCP 流追踪 ```bash # 追踪特定 TCP 流 tcp.stream eq 0 tcp.stream eq 5 # 结合其他条件 tcp.stream eq 10 and http ``` #### 2.4.4 TCP 序列号和窗口 ```bash # 序列号 tcp.seq == 1000 # 确认号 tcp.ack == 2000 # 窗口大小 tcp.window_size > 0 tcp.window_size == 0 # 零窗口 ``` ### 2.5 DNS 过滤器 ```bash # DNS 查询 dns.flags.response == 0 # DNS 响应 dns.flags.response == 1 # 查询特定域名 dns.qry.name == "www.example.com" dns.qry.name contains "google" # DNS 查询类型 dns.qry.type == 1 # A 记录 dns.qry.type == 28 # AAAA 记录 dns.qry.type == 5 # CNAME dns.qry.type == 15 # MX 记录 dns.qry.type == 16 # TXT 记录 # DNS 响应码 dns.flags.rcode == 0 # 无错误 dns.flags.rcode == 3 # NXDOMAIN(域名不存在) ``` ### 2.6 TLS/SSL 过滤器 ```bash # TLS 握手 ssl.handshake.type == 1 # Client Hello ssl.handshake.type == 2 # Server Hello # TLS 版本 ssl.handshake.version == 0x0303 # TLS 1.2 ssl.handshake.version == 0x0304 # TLS 1.3 # 服务器名称指示(SNI) tls.handshake.extensions_server_name contains "example.com" # TLS 应用数据 ssl.app_data # TLS 证书 ssl.handshake.certificate ``` ### 2.7 FTP 过滤器 ```bash # FTP 命令 ftp.request.command == "USER" ftp.request.command == "PASS" ftp.request.command == "LIST" ftp.request.command == "RETR" ftp.request.command == "STOR" # FTP 响应 ftp.response.code == 230 # 登录成功 ftp.response.code == 530 # 登录失败 # FTP 数据传输 ftp-data ``` ### 2.8 ICMP 过滤器 ```bash # ICMP 类型 icmp.type == 8 # Echo Request (ping) icmp.type == 0 # Echo Reply icmp.type == 3 # Destination Unreachable icmp.type == 11 # Time Exceeded # Ping 请求和响应 icmp.type == 8 or icmp.type == 0 ``` ### 2.9 ARP 过滤器 ```bash # ARP 请求 arp.opcode == 1 # ARP 响应 arp.opcode == 2 # 查找特定 IP 的 ARP arp.src.proto_ipv4 == 192.168.1.1 arp.dst.proto_ipv4 == 192.168.1.1 ``` ### 2.10 数据包长度过滤 ```bash # 按长度过滤 frame.len > 1000 frame.len < 100 frame.len >= 64 and frame.len <= 128 # IP 层长度 ip.len > 500 # TCP 载荷长度 tcp.len > 0 # 有数据的 TCP 包 tcp.len == 0 # 无数据的 TCP 包(如握手包) ``` ### 2.11 时间过滤 ```bash # 时间间隔 frame.time_delta > 1 # 与上一个包间隔超过 1 秒 # 相对时间 frame.time_relative > 10 # 相对于第一个包超过 10 秒 ``` ### 2.12 字符串搜索(重点) ```bash # 包含特定字符串(任何层) frame contains "password" frame contains "flag{" frame contains "admin" # 特定协议包含字符串 http contains "login" tcp contains "secret" udp contains "key" # 大小写不敏感(使用 matches) http.request.uri matches "(?i)admin" # 正则表达式 http.host matches ".*\\.example\\.com" http.request.uri matches "/api/v[0-9]+/" ``` ### 2.13 组合过滤器(高级) ```bash # HTTP POST 请求到特定主机 http.request.method == "POST" and http.host == "api.example.com" # 来自特定 IP 的 HTTP 流量 http and ip.src == 192.168.1.100 # 非标准端口的 HTTP http and tcp.port != 80 and tcp.port != 443 # 大数据包 ip.len > 1000 and tcp # 可疑的 DNS 查询 dns and frame contains "exe" # 失败的 HTTP 请求 http.response.code >= 400 # TLS 握手失败 ssl.alert_message # 扫描行为检测 tcp.flags.syn == 1 and tcp.flags.ack == 0 and tcp.window_size <= 1024 # SQL 注入尝试 http.request.uri contains "select" or http.request.uri contains "union" # XSS 尝试 http contains "