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

1.1、## 过滤器详解

#### 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

第二、 高级过滤

2.1、## 条件过滤

# 逻辑操作符

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

2.2、## 协议分析

### 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

2.3、## 网络故障排查

### 连接问题诊断

1. **TCP连接建立**: 查找SYN, SYN-ACK, ACK三次握手

2. **连接重置**: 过滤`tcp.flags.reset == 1`

3. **连接超时**: 查找重传`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**: 流量图表

第三、 安全分析

3.1、### 恶意流量检测

# 可疑端口连接

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"

3.2、### 常见攻击模式

# 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

3.3.、### 数据泄露检测

# 明文密码传输

tcp contains "password=" or tcp contains "passwd="

# 敏感信息

tcp contains "credit" or tcp contains "ssn" or tcp contains "social"

# 文件上传/下载

http.request.method == "PUT" or http.request.method == "POST"

3.4、### 性能优化

### 提高捕获性能

1. **使用捕获过滤器**: 减少不需要的数据包

2. **增加缓冲区大小**: Capture → Options → Buffer size

3. **写入多个文件**: 避免单个文件过大

4. **关闭名称解析**: View → Name Resolution

### 分析大文件技巧

1. **使用显示过滤器**: 只显示相关数据包

2. **时间范围过滤**: 分段分析

3. **导出特定数据**: File → Export Objects

4. **使用tshark**: 命令行工具处理大文件

3.5、### 导出与统计

### 导出对象

- **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)

4.1、### 基本用法

# 捕获网络流量

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

4.2、### 高级用法

# 输出为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\""

4.3、### 批处理脚本示例

#!/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

第五、 实用技巧总结

5.1、### 快速分析检查清单

1. **概览**: Statistics → Summary 查看基本信息

2. **协议分布**: Statistics → Protocol Hierarchy

3. **主要通信方**: Statistics → Conversations

4. **异常检查**: 查找错误、重传、异常状态码

5. **时间分析**: I/O Graph 查看流量模式

6. **内容检查**: Follow Stream 查看具体通信内容

5.2、### 常见问题解决

- **中文乱码**: Edit → Preferences → Protocols → HTTP → 设置字符编码

- **DNS解析慢**: View → Name Resolution → 关闭网络名解析

- **内存不足**: 使用显示过滤器减少显示的数据包数量

- **时间不准**: View → Time Display Format 调整时间显示

5.3、### 颜色规则自定义

- **View → Coloring Rules**: 自定义数据包颜色

- 常用颜色规则:

  - 红色:TCP错误 `tcp.analysis.flags`

  - 黄色:HTTP错误 `http.response.code >= 400`

  - 绿色:DNS `dns`

  - 蓝色:HTTP `http`

案例

HTTP分析过滤器

http contains "github"
http.host contains "github"
http.request.uri contains "github"

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值