Wireshark数据包分析教程

Wireshark数据包分析教程

本教程将基于Wireshark工具捕获的数据包,逐步讲解网络数据帧中的各项信息,帮助你了解每个字段的含义及其作用。我们将从最基础的帧(Frame)信息开始,逐层解释包括以太网、IP、TCP、HTTP和JSON数据结构。

1. 捕获的帧信息

在Wireshark中,每一个数据包称为一个"帧"(Frame)。每个帧的基本信息包括帧号、帧长度、捕获接口等。我们来看一个实际捕获的数据包的结构:

Frame 307: 881 bytes on wire (7048 bits), 881 bytes captured (7048 bits) on interface en0, id 0
    Section number: 1
    Interface id: 0 (en0)
    Interface name: en0
    Interface description: Wi-Fi
    Encapsulation type: Ethernet (1)
    Arrival Time: Oct 10, 2024 14:55:11.336319000 CST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1728543311.336319000 seconds
    [Time delta from previous captured frame: 0.001562000 seconds]
    [Time delta from previous displayed frame: 0.001562000 seconds]
    [Time since reference or first frame: 5.208361000 seconds]
    Frame Number: 307
    Frame Length: 881 bytes (7048 bits)
    Capture Length: 881 bytes (7048 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ip:tcp:http:json]
    [Coloring Rule Name: HTTP]
    [Coloring Rule String: http || tcp.port == 80 || http2]
1.1. 基本信息
  • Frame 307:数据包的序号是307。
  • 881 bytes on wire (7048 bits):该帧在网络中传输的实际大小是881字节,合7048比特。
  • 881 bytes captured:Wireshark捕获的帧长度也是881字节。
  • on interface en0 :该帧通过接口en0(Wi-Fi接口)捕获。
  • Encapsulation type:该帧的封装类型是以太网(Ethernet),编号为1。
1.2. 时间信息
  • Arrival Time:数据包到达时间是2024年10月10日14:55:11.336 CST。
  • Epoch Time:Unix时间戳,表示自1970年1月1日以来的秒数。
  • Time delta:显示该帧与上一帧之间的时间间隔。
  • Time since reference or first frame:自捕获的第一个帧以来的时间。
1.3. 帧长信息
  • Frame Length:该帧的实际大小是881字节。
  • Capture Length:捕获的字节数也是881字节。
1.4. 协议信息
  • Protocols in frame:该帧中包含的协议层依次为以太网(eth)、以太网类型(ethertype)、IP(ip)、TCP(tcp)、HTTP(http)、JSON(json)。

2. 以太网层信息 (Ethernet II)

以太网是数据链路层协议,用于在局域网中传输数据。以下是该数据包的以太网层信息:

Ethernet II, Src: VMware_a5:21:6f (00:0c:29:a5:21:6f), Dst: Apple_17:27:a4 (a4:83:e7:17:27:a4)
    Destination: Apple_17:27:a4 (a4:83:e7:17:27:a4)
        Address: Apple_17:27:a4 (a4:83:e7:17:27:a4)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: VMware_a5:21:6f (00:0c:29:a5:21:6f)
        Address: VMware_a5:21:6f (00:0c:29:a5:21:6f)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
2.1. 源地址和目的地址
  • Src :源MAC地址是VMware_a5:21:6f,表示数据包来自一台VMware虚拟机。
  • Dst :目的MAC地址是Apple_17:27:a4,可能是一台Apple设备。
2.2. 地址类型
  • LG bit:表示地址是全球唯一的出厂地址(未经过本地修改)。
  • IG bit:表示这是一个单播地址。
2.3. 协议类型
  • Type :协议类型为IPv4(0x0800),表示该帧封装的是IPv4协议数据。

3. IP层信息 (Internet Protocol Version 4)

IP层负责将数据包从源传送到目的IP地址。以下是该数据包的IP层信息:

Internet Protocol Version 4, Src: 192.168.2.20, Dst: 10.2.4.59
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
    Total Length: 867
    Identification: 0xdbb1 (56241)
    010. .... = Flags: 0x2, Don't fragment
    Time to Live: 62
    Protocol: TCP (6)
    Header Checksum: 0x8cea [validation disabled]
    Source Address: 192.168.2.20
    Destination Address: 10.2.4.59
3.1. 版本和头部长度
  • Version:IP协议版本为4(IPv4)。
  • Header Length:IP头部长度为20字节。
3.2. 服务类型
  • Differentiated Services Field:服务类型字段用于QoS(服务质量)管理,但这里的值为0,表示默认服务。
3.3. 标志
  • Flags:该包设置了"Don't fragment"标志,表示不要对该数据包进行分片。
3.4. TTL和协议
  • Time to Live (TTL):数据包的生存时间为62跳。
  • Protocol:该数据包的传输协议是TCP(协议编号6)。
3.5. 源地址和目的地址
  • Source Address :源IP地址为192.168.2.20
  • Destination Address :目的IP地址为10.2.4.59

4. TCP层信息 (Transmission Control Protocol)

TCP是传输层协议,负责数据包的可靠传输。以下是TCP层的信息:

Transmission Control Protocol, Src Port: 8333, Dst Port: 63678, Seq: 1, Ack: 908, Len: 815
    Source Port: 8333
    Destination Port: 63678
    [TCP Flags: ·······AP···]
    Window: 241
    [Calculated window size: 30848]
    Checksum: 0xc375 [unverified]
    Urgent Pointer: 0
4.1. 源端口和目的端口
  • Source Port:源端口为8333,可能是服务器端口。
  • Destination Port:目的端口为63678,通常是客户端的临时端口。
4.2. 序列号和确认号
  • Seq (Sequence Number):序列号为1,表示这是该TCP连接中传输的第一个字节。
  • Ack (Acknowledgment Number):确认号为908,表示已经成功接收到的字节数。
4.3. TCP标志
  • TCP Flags:这里设置了PSH(Push)和ACK(Acknowledgment)标志,表示立即发送数据并确认接收到的数据。
4.4. 窗口大小
  • Window:当前接收窗口大小为241字节。

5. 应用层信息 (HTTP 和 JSON)

该帧包含一个HTTP响应和JSON数据:

Hypertext Transfer Protocol
    HTTP/1.1 200 OK\r\n
    Server: nginx/1.21.5\r\n
    Content-Type: application/json; charset=utf-8\r\n
JavaScript Object Notation: application/json
   

 Member: code = 200
    Member: message = success
    Member: data
        Array
            Object
                Member: id = 11000
                Member: name = 数据库
5.1. HTTP响应
  • HTTP/1.1 200 OK:这是HTTP协议的响应行,表示请求成功。
  • Content-Type :响应内容类型是application/json,表明响应体是JSON数据。
5.2. JSON数据
  • Member: code = 200 :JSON对象中的code字段表示请求状态为200(成功)。
  • Member: message = successmessage字段显示成功信息。
  • Member: datadata字段包含一个数组,其中的对象有idname字段,如id=11000name=数据库

总结

通过逐层解析网络数据包,Wireshark可以帮助我们了解网络通信的详细内容,包括传输的协议、地址信息、时间戳以及具体的应用数据(如HTTP和JSON)。这种分析方法能够有效地诊断网络问题,检测异常流量,并优化网络性能。

Wireshark是一款功能强大的网络分析工具,熟练使用它可以为网络管理与安全带来极大便利。

相关推荐
Cshaosun几秒前
Web开发动画与性能优化
前端·javascript·网络·性能优化
API199701081106 分钟前
VVIC商品详情接口技术解析与实战代码示例
开发语言·python·json·php
ZachOn1y1 小时前
计算机网络:物理层 —— 数据的传输方式
网络·计算机网络·数据传输·物理层·考研必备
xcx0031 小时前
什么是快充协议、支持多协议的USB Type-C受电端取电芯片
网络
沫风港1 小时前
内网笔记大全
服务器·网络·windows·笔记·php
一起努力学习吧!2 小时前
【华为】ACL访问控制列表
网络·华为
谢尔登2 小时前
【浏览器】HTTP 状态码
网络·网络协议·http
ac-er88882 小时前
PHP静态化和伪静态如何实现的
开发语言·php
tekin3 小时前
php获取远程https内容时提示 PHP Warning: copy(): Unable to find the wrapper “https“ 解决方法
开发语言·macos·https·php