other-Wireshark_网络抓包


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, 例如

  1. ip.src == 192.168.1.107 || ip.dst == 192.168.1.107`
  2. ip.addr == 192.168.1.107 : 等价于 ip.src == 192.168.1.107 || ip.dst == 192.168.1.107

过滤 端口

  1. tcp.port == 80 : 等价于 tcp.srcport == 80 || tcp.dstport == 80
  2. tcp.port == 80 || udp.port == 80
  3. tcp.dstport == 80 : 只显tcp协议的目标端口80
  4. tcp.srcport == 80 : 只显tcp协议的来源端口80

过滤 协议

  1. tcp
  2. udp
  3. arp
  4. icmp
  5. http
  6. smtp
  7. ftp
  8. dns
  9. msnms
  10. ip
  11. ssl
  12. oicq
  13. bootp
  14. 排除arp包,如 !arp 或者 not arp

过滤 包长度

  1. udp.length == 26 这个长度是指udp本身固定长度8加上udp下面那块数据包之和
  2. tcp.len >= 7 指的是ip数据包(tcp下面那块数据),不包括tcp本身
  3. ip.len == 94 除了以太网头固定长度14,其它都算是ip.len,即从ip本身到最后
  4. frame.len == 119 整个数据包长度,从eth开始到最后

过滤 MAC

太以网头过滤

  1. eth.dst == A0:00:00:04:C5:84 // 过滤目标mac
  2. eth.src eq A0:00:00:04:C5:84 // 过滤来源mac
  3. eth.dst==A0:00:00:04:C5:84
  4. eth.dst==A0-00-00-04-C5-84
  5. eth.addr eq A0:00:00:04:C5:84 // 过滤来源MAC和目标MAC都等于A0:00:00:04:C5:84的

过滤 http 模式

  1. http.request.method == “GET”
  2. http.request.method == “POST”
  3. http.request.uri == “/img/logo-edu.gif”
  4. http contains “GET”
  5. http contains “HTTP/1.”

// GET包

  1. http.request.method == “GET” && http contains "Host: "

  2. http.request.method == “GET” && http contains "User-Agent: "

// POST包

  1. http.request.method == “POST” && http contains "Host: "
  2. http.request.method == “POST” && http contains "User-Agent: "

// 响应包

  1. http contains “HTTP/1.1 200 OK” && http contains "Content-Type: "
  2. http contains “HTTP/1.0 200 OK” && http contains "Content-Type: "

过滤 TCP参数

  1. tcp.flags 显示包含TCP标志的封包。
  2. tcp.flags.syn == 0x02 显示包含TCP SYN标志的封包。
  3. tcp.window_size == 0 && tcp.flags.reset != 1

过滤 包内容

  1. tcp[20]表示从20开始,取1个字符
  2. 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.src
192.168.1.107 and udp[8:5] matches “\x02\x12\x21\x00\x22″ ------???--------
ip.src
192.168.1.107 and udp contains 02:12:21:00:22
ip.src
192.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 组成

请求包

  1. 选中请求接口 -> 右键 Data -> 导出分组字节流, 导出到文件 loginData.bin. 这就是客户单端上行的 二进制 数据

  2. 解析 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) 几乎一致

请求包

  1. 选中请求接口 -> 右键 Data -> 导出分组字节流, 导出到文件 heart.bin. 这就是客户单端上行的 二进制 数据

  2. 解析 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
    */
    }
    

猜你喜欢

转载自blog.csdn.net/yangxuan0261/article/details/109305315
今日推荐