title: other-Wireshark_网络抓包
categories: Others
tags: [抓包, Wireshark]
date: 2020-10-26 16:57:58
comments: false
mathjax: true
toc: true
other-Wireshark_网络抓包
前篇
- 下载地址: 网络封包分析工具 Wireshark 3.3.0 + x64 中文多语免费版 - http://www.dayanzai.me/wireshark.html
- wireshark 实用过滤表达式(针对ip、协议、端口、长度和内容) - https://blog.csdn.net/aflyeaglenku/article/details/50884296
- Wireshark使用技巧及数据包分析方法 - https://zhuanlan.zhihu.com/p/31512066
筛选条件
- wireshark过滤规则及使用方法 - https://blog.csdn.net/wojiaopanpan/article/details/69944970
过滤 IP
如来源IP或者目标IP等于某个IP, 例如
- ip.src == 192.168.1.107 || ip.dst == 192.168.1.107`
- ip.addr == 192.168.1.107 : 等价于 ip.src == 192.168.1.107 || ip.dst == 192.168.1.107
过滤 端口
- tcp.port == 80 : 等价于 tcp.srcport == 80 || tcp.dstport == 80
- tcp.port == 80 || udp.port == 80
- tcp.dstport == 80 : 只显tcp协议的目标端口80
- tcp.srcport == 80 : 只显tcp协议的来源端口80
过滤 协议
- tcp
- udp
- arp
- icmp
- http
- smtp
- ftp
- dns
- msnms
- ip
- ssl
- oicq
- bootp
- 排除arp包,如 !arp 或者 not arp
过滤 包长度
- udp.length == 26 这个长度是指udp本身固定长度8加上udp下面那块数据包之和
- tcp.len >= 7 指的是ip数据包(tcp下面那块数据),不包括tcp本身
- ip.len == 94 除了以太网头固定长度14,其它都算是ip.len,即从ip本身到最后
- frame.len == 119 整个数据包长度,从eth开始到最后
过滤 MAC
太以网头过滤
- eth.dst == A0:00:00:04:C5:84 // 过滤目标mac
- eth.src eq A0:00:00:04:C5:84 // 过滤来源mac
- eth.dst==A0:00:00:04:C5:84
- eth.dst==A0-00-00-04-C5-84
- eth.addr eq A0:00:00:04:C5:84 // 过滤来源MAC和目标MAC都等于A0:00:00:04:C5:84的
过滤 http 模式
- http.request.method == “GET”
- http.request.method == “POST”
- http.request.uri == “/img/logo-edu.gif”
- http contains “GET”
- http contains “HTTP/1.”
// GET包
-
http.request.method == “GET” && http contains "Host: "
-
http.request.method == “GET” && http contains "User-Agent: "
// POST包
- http.request.method == “POST” && http contains "Host: "
- http.request.method == “POST” && http contains "User-Agent: "
// 响应包
- http contains “HTTP/1.1 200 OK” && http contains "Content-Type: "
- http contains “HTTP/1.0 200 OK” && http contains "Content-Type: "
过滤 TCP参数
- tcp.flags 显示包含TCP标志的封包。
- tcp.flags.syn == 0x02 显示包含TCP SYN标志的封包。
- tcp.window_size == 0 && tcp.flags.reset != 1
过滤 包内容
- tcp[20]表示从20开始,取1个字符
- tcp[20:]表示从20开始,取1个字符以上
注: 些两虚线中的内容在我的wireshark(linux)上测试未通过。
tcp[20:8]表示从20开始,取8个字符
tcp[offset,n]
udp[8:3]81:60:03 // 偏移8个bytes,再取3个数,是否与后面的数据相等?
udp[8:1]==32 如果我猜的没有错的话,应该是udp[offset:截取个数]=nValue
eth.addr[0:3]00:06:5B
例子:
判断upd下面那块数据包前三个是否等于0x20 0x21 0x22
我们都知道udp固定长度为8
udp[8:3]20:21:22
判断tcp那块数据包前三个是否等于0x20 0x21 0x22
tcp一般情况下,长度为20,但也有不是20的时候
tcp[8:3]20:21:22
如果想得到最准确的,应该先知道tcp长度
matches(匹配)和contains(包含某字符串)语法
ip.src192.168.1.107 and udp[8:5] matches “\x02\x12\x21\x00\x22″ ------???--------
ip.src192.168.1.107 and udp contains 02:12:21:00:22
ip.src192.168.1.107 and tcp contains “GET”
udp contains 7c:7c:7d:7d 匹配payload中含有0x7c7c7d7d的UDP数据包,不一定是从第一字节匹配。
http 抓包 - json
-
请求数据
const url = "http://192.168.1.233:57305/hotupdate" request.post(url, { json: { Plat: 1042, Os: 2, Appid: 3, Uid: "123123", Version: "0.301.3.4", Deviceid: "wolegequ", } }, (error, res, body) => { if (error) { console.error(error) return } console.log(`--- statusCode: ${ res.statusCode}`) console.log(`--- post rsp:`, body) })
请求包
-
比如输入表达式:
ip.dst == 192.168.1.233 && tcp.port == 57305
可以捕捉到请求 目标 ip 为 192.168.1.233 的数据
返回包
-
比如输入表达式:
ip.src == 192.168.1.233 && tcp.port == 57305
可以捕捉到 源 ip 为 192.168.1.233 的返回数据
http 抓包 - stream
这个演示基于游戏内的协议. 上行的数据的 buff 结构: [buff 总大小]+[pb buff], pb buff 由 head + body 组成
请求包
-
选中请求接口 -> 右键 Data -> 导出分组字节流, 导出到文件 loginData.bin. 这就是客户单端上行的 二进制 数据
-
解析 loginData.bin 文件. (golang 演示)
func Test_login_data(t *testing.T) { path := "C:/Users/wolegequ/Desktop/loginData.bin" bts, err := ioutil.ReadFile(path) if err != nil { panic(err) } log.Printf("--- total len: %d\n", len(bts)) pld := &csprotos.PayloadData{ } err = proto.Unmarshal(bts[2:], pld) // 去掉头部 两个字节 (buff 总长度值) if err != nil { panic(err) } log.Printf("--- body len: %d\n", len(pld.CSBody)) req := &csprotos.LoginReq{ } err = proto.Unmarshal(pld.CSBody, req) if err != nil { panic(err) } log.Printf("--- req: %v\n", req) } /* 结果: 2020/10/26 20:10:11 --- total len: 81 2020/10/26 20:10:11 --- body len: 57 2020/10/26 20:10:11 --- req: PlatID:1042 ChanID:1 ... */
tcp 抓包 - stream
与 [http 抓包 - stream](#http 抓包 - stream) 几乎一致
请求包
-
选中请求接口 -> 右键 Data -> 导出分组字节流, 导出到文件 heart.bin. 这就是客户单端上行的 二进制 数据
-
解析 heart.bin 文件. (golang 演示)
func Test_login_data(t *testing.T) { path := "C:/Users/wolegequ/Desktop/heart.bin" bts, err := ioutil.ReadFile(path) if err != nil { panic(err) } log.Printf("--- total len: %d\n", len(bts)) pld := &csprotos.PayloadData{ } err = proto.Unmarshal(bts[2:], pld) // 去掉头部 两个字节 (buff 总长度值) if err != nil { panic(err) } log.Printf("--- pld: %+v\n", pld) /* 结果: 2020/10/26 20:43:11 --- total len: 34 2020/10/26 20:43:11 --- pld: CSHead:{CMDID:303 ReqID:26 ...} CSBody:"" ExtA:12516300 ExtC:1320706011723882496 */ }