WireShark分析实战手册
没什么含量,只是份wireshark分析的实战手册,我一直备查用,送给你。
主要内容包括:
- 基础操作 - 启动、捕获、导航快捷键
- 过滤器详解 - 显示过滤器和捕获过滤器的详细语法
- 协议分析 - TCP、HTTP、DNS、TLS等协议的专门分析技巧
- 网络故障排查 - 连接问题、性能问题、丢包分析
- 安全分析 - 恶意流量检测、攻击模式识别、数据泄露检测
- 性能优化 - 提高捕获和分析效率的技巧
- 导出与统计 - 数据导出和统计报告生成
- 命令行工具 - tshark的使用方法和批处理脚本
基础操作
导航快捷键
- 查找:
Ctrl+F
- 查找下一个:
Ctrl+N
- 前往数据包:
Ctrl+G
- 标记数据包:
Ctrl+M
- 放大:
Ctrl++
- 缩小:
Ctrl+-
IP地址过滤
特定源IP
ip.src == 192.168.1.100
特定目标IP
ip.dst == 192.168.1.1
IP范围
ip.addr == 192.168.1.0/24
排除特定IP
!(ip.addr == 192.168.1.1)
端口过滤
特定端口
tcp.port == 80
端口范围
tcp.port >= 1000 and tcp.port <= 2000
常用端口
tcp.port == 22 # SSH
tcp.port == 25 # SMTP
tcp.port == 53 # DNS
tcp.port == 80 # HTTP
tcp.port == 443 # HTTPS
tcp.port == 3389 # RDP
过滤器详解
HTTP专用过滤器
HTTP方法
http.request.method == "GET"
http.request.method == "POST"
HTTP状态码
http.response.code == 200
http.response.code == 404
http.response.code == 500
HTTP主机
http.host == "www.example.com"
HTTP用户代理
http.user_agent contains "Chrome"
HTTP内容类型
http.content_type contains "json"
HTTP请求URI
http.request.uri contains "/api/"
HTTP响应时间
http.time > 1.0
高级过滤技巧
逻辑操作符
http and tcp.port == 80
http or https
not dns
括号分组
(tcp.port == 80 or tcp.port == 443) and ip.src == 192.168.1.100
字符串匹配
tcp contains "password"
http contains "admin"
正则表达式
http.host matches ".*\.com$"
时间过滤
frame.time >= "2024-01-01 00:00:00"
捕获过滤器 (Capture Filters)
基于Berkeley Packet Filter(BPF)语法:
捕获特定主机
host 192.168.1.1
捕获特定端口
port 80
组合条件
host 192.168.1.1 and port 80
not port 22
协议分析
TCP分析
- TCP流跟踪: 右键数据包 → Follow → TCP Stream
- TCP重传:
tcp.analysis.retransmission
- TCP重复ACK:
tcp.analysis.duplicate_ack
- TCP窗口满:
tcp.analysis.zero_window
- TCP重置:
tcp.flags.reset == 1
HTTP分析
查看完整HTTP对话
http.request or http.response
HTTP错误
http.response.code >= 400
大文件传输
http.content_length > 1000000
慢速响应
http.time > 2.0
DNS分析
DNS查询
dns.flags.response == 0
DNS响应
dns.flags.response == 1
DNS错误
dns.flags.rcode != 0
特定域名查询
dns.qry.name contains "example.com"
TLS/SSL分析
TLS握手
tls.handshake
TLS证书
tls.handshake.certificate
TLS警报
tls.alert
特定TLS版本
tls.record.version == 0x0303 # TLS 1.2
网络故障排查
连接问题诊断
- TCP连接建立: 查找SYN, SYN-ACK, ACK三次握手
- 连接重置: 过滤
tcp.flags.reset == 1
- 连接超时: 查找重传
tcp.analysis.retransmission
性能问题分析
慢速查询
dns.time > 0.1
HTTP响应时间
http.time > 1.0
TCP窗口问题
tcp.analysis.zero_window
tcp.analysis.window_update
丢包分析
TCP重传
tcp.analysis.retransmission
乱序数据包
tcp.analysis.out_of_order
重复ACK
tcp.analysis.duplicate_ack
常用统计信息
- Statistics → Protocol Hierarchy: 协议分布
- Statistics → Conversations: 会话统计
- Statistics → Endpoints: 端点统计
- Statistics → I/O Graph: 流量图表
安全分析
恶意流量检测
可疑端口连接
tcp.port == 1337 or tcp.port == 31337
大量连接尝试
tcp.flags.syn == 1 and tcp.flags.ack == 0
DNS隧道检测
dns.qry.name.len > 50
异常用户代理
http.user_agent contains "bot" or http.user_agent contains "crawler"
常见攻击模式
SQL注入尝试
http.request.uri contains "union" or http.request.uri contains "select"
XSS尝试
http.request.uri contains "<script>
" or http.request.uri contains "javascript:"
目录遍历
http.request.uri contains "../"
扫描行为
tcp.flags.syn == 1 and tcp.flags.ack == 0
性能优化
提高捕获性能
- 使用捕获过滤器: 减少不需要的数据包
- 增加缓冲区大小: Capture → Options → Buffer size
- 写入多个文件: 避免单个文件过大
- 关闭名称解析: View → Name Resolution
分析大文件技巧
- 使用显示过滤器: 只显示相关数据包
- 时间范围过滤: 分段分析
- 导出特定数据: File → Export Objects
- 使用tshark: 命令行工具处理大文件
导出与统计
导出对象
- File → Export Objects → HTTP: 导出HTTP对象
- File → Export Objects → DICOM: 导出DICOM文件
- File → Export Objects → SMB: 导出SMB文件
流跟踪导出
- Follow Stream: 右键数据包选择跟踪流
- Save As: 保存完整对话内容
统计报告
生成统计报告
Statistics → Summary # 捕获摘要
Statistics → Protocol Hierarchy # 协议层次
Statistics → Conversations # 对话统计
Statistics → Endpoints # 端点统计
Statistics → Packet Lengths # 数据包长度分布
命令行工具(tshark)
基本用法
捕获网络流量
tshark -i eth0
读取pcap文件
tshark -r capture.pcap
应用显示过滤器
tshark -r capture.pcap -Y "http"
指定输出字段
tshark -r capture.pcap -T fields -e ip.src -e ip.dst -e http.host
高级用法
输出为JSON格式
tshark -r capture.pcap -T json
导出HTTP对象
tshark -r capture.pcap --export-objects http,/tmp/objects/
统计信息
tshark -r capture.pcap -z conv,tcp
tshark -r capture.pcap -z endpoints,ip
协议层次统计
tshark -r capture.pcap -z io,phs
时间窗口分析
tshark -r capture.pcap -Y "frame.time >= "2024-01-01 00:00:00""
批处理脚本示例
!/bin/bash
分析HTTP流量脚本
echo "=== HTTP主机统计 ==="
tshark -r $1 -Y "http.request" -T fields -e http.host | sort | uniq -c | sort -nr
echo "=== HTTP状态码统计 ==="
tshark -r $1 -Y "http.response" -T fields -e http.response.code | sort | uniq -c | sort -nr
echo "=== 用户代理统计 ==="
tshark -r $1 -Y "http.request" -T fields -e http.user_agent | sort | uniq -c | sort -nr
实用技巧总结
快速分析检查清单
- 概览: Statistics → Summary 查看基本信息
- 协议分布: Statistics → Protocol Hierarchy
- 主要通信方: Statistics → Conversations
- 异常检查: 查找错误、重传、异常状态码
- 时间分析: I/O Graph 查看流量模式
- 内容检查: Follow Stream 查看具体通信内容
常见问题解决
- 中文乱码: Edit → Preferences → Protocols → HTTP → 设置字符编码
- DNS解析慢: View → Name Resolution → 关闭网络名解析
- 内存不足: 使用显示过滤器减少显示的数据包数量
- 时间不准: View → Time Display Format 调整时间显示
颜色规则自定义
- View → Coloring Rules: 自定义数据包颜色
- 常用颜色规则:
- 红色:TCP错误tcp.analysis.flags
- 黄色:HTTP错误http.response.code >= 400
- 绿色:DNSdns
- 蓝色:HTTPhttp
这份手册涵盖了Wireshark的主要使用技巧,从基础操作到高级分析,希望能帮助您更高效地进行网络分析。建议收藏备用,并在实际使用中不断实践和完善。
举个例子:有个pcap分析题。某单位被攻击了,请分析以下网络安全事件的流量包,并解答以下问题,黑客利用的Github开源项目的名字是?提交答案格式:flag{项目名称}(如有字母请全部使用小写)
答:HTTP分析过滤器
http contains "github"
http.host contains "github"
http.request.uri contains "github"