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
## 网络故障排查
### 连接问题诊断
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**: 流量图表
## 安全分析
### 恶意流量检测
# 可疑端口连接
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
### 数据泄露检测
# 明文密码传输
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"
## 性能优化
### 提高捕获性能
1. **使用捕获过滤器**: 减少不需要的数据包
2. **增加缓冲区大小**: Capture → Options → Buffer size
3. **写入多个文件**: 避免单个文件过大
4. **关闭名称解析**: View → Name Resolution
### 分析大文件技巧
1. **使用显示过滤器**: 只显示相关数据包
2. **时间范围过滤**: 分段分析
3. **导出特定数据**: File → Export Objects
4. **使用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
## 实用技巧总结
### 快速分析检查清单
1. **概览**: Statistics → Summary 查看基本信息
2. **协议分布**: Statistics → Protocol Hierarchy
3. **主要通信方**: Statistics → Conversations
4. **异常检查**: 查找错误、重传、异常状态码
5. **时间分析**: I/O Graph 查看流量模式
6. **内容检查**: 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`
- 绿色:DNS `dns`
- 蓝色:HTTP `http`
这份手册涵盖了Wireshark的主要使用技巧,从基础操作到高级分析,希望能帮助您更高效地进行网络分析。建议收藏备用,并在实际使用中不断实践和完善。
举个例子:有个pcap分析题。某单位被攻击了,请分析以下网络安全事件的流量包,并解答以下问题,黑客利用的Github开源项目的名字是?提交答案格式:flag{项目名称}(如有字母请全部使用小写)
答:
HTTP分析过滤器
http contains "github"
http.host contains "github"
http.request.uri contains "github"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495


上次更新: 2025/07/09, 17:19:47