使用 Wireshark 選擇需要抓包的網絡方式,並設置過濾器條件,當有數據通信后即可抓到對應的數據包,這里將分析其每一幀數據包的結構。
以HTTP協議為例,一幀數據包一般包括以下幾個部分:
- Frame:物理層的數據幀情況。
- Ethernet II :數據鏈路層以太網幀頭部信息。
- Internet Protocol Version 4:以太網協議層。
- Transmission Control Protocol:傳輸控制協議。
- HyperText Transfer Protocol:超文本傳輸協議。
對於各種協議而言,前三層基本一樣,第四層開始就可以出現TCP, UDP 協議,第五層就有HTTP 應用層協議等。
第一層:Frame:(物理層)
1 // 第8056幀,有507個字節在線,共4056位,實際在接口0上捕獲到507個字節 2 Frame 8056: 507 bytes on wire (4056 bits), 507 bytes captured (4056 bits) on interface 0 3 // 接口ID:0 4 Interface id: 0 (\Device\NPF_{7920DB7B-B8DB-417F-8C85-72E6DCCD61C5}) 5 // 封裝類型 6 Encapsulation type: Ethernet (1) 7 // 到達時間 8 Arrival Time: Aug 8, 2019 15:45:00.750794000 中國標准時間 9 // 包偏移量 10 [Time shift for this packet: 0.000000000 seconds] 11 // 新紀元時間 12 Epoch Time: 1565250300.750794000 seconds 13 // 兩幀之間的時間間隔 14 [Time delta from previous captured frame: 0.000326000 seconds] 15 // 捕獲到顯示的時間間隔 16 [Time delta from previous displayed frame: 0.126423000 seconds] 17 // 此幀與第一幀的時間間隔 18 [Time since reference or first frame: 197.144051000 seconds] 19 // 幀號 20 Frame Number: 8056 21 // 幀長度 22 Frame Length: 507 bytes (4056 bits) 23 // 捕獲的幀長度 24 Capture Length: 507 bytes (4056 bits) 25 // 幀是否標記 26 [Frame is marked: False] 27 // 幀是否忽略 28 [Frame is ignored: False] 29 // 幀內封裝的協議層次結構 30 [Protocols in frame: eth:ethertype:ip:tcp:http] 31 // 着色標記的協議 32 [Coloring Rule Name: HTTP] 33 // 着色規則顯示的字符串 34 [Coloring Rule String: http || tcp.port == 80 || http2]
第二層:Ethernet II (數據鏈路層以太網幀頭部信息)
1 // 源MAC地址:TexasIns_ce:a9:4b (68:c9:0b:ce:a9:4b) 2 // 目標MAC地址:AplexTec_0d:4e (40:d8:55:16:ad:4e) 3 Ethernet II, Src: AsustekC_4d:bc:f2 (70:8b:cd:4d:bc:f2), Dst: Hangzhou_91:be:b8 (d4:61:fe:91:be:b8) 4 // 目標MAC地址 5 Destination: Hangzhou_91:be:b8 (d4:61:fe:91:be:b8) 6 // 源MAC地址 7 Source: AsustekC_4d:bc:f2 (70:8b:cd:4d:bc:f2) 8 // IP類型 9 Type: IPv4 (0x0800)
第三層:Internet Protocol Version 4(以太網協議層)
1 // IPv4 協議,源IP:192.168.1.50, 目的IP:111.202.102.36 2 Internet Protocol Version 4, Src: 192.168.1.50, Dst: 111.202.102.36 3 // 版本4 4 0100 .... = Version: 4 5 // 頭長度20字節 6 .... 0101 = Header Length: 20 bytes (5) 7 // 差分服務字段 8 Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) 9 // 總長度 10 Total Length: 493 11 // 鑒別 12 Identification: 0x90c2 (37058) 13 // 標志 14 Flags: 0x4000, Don't fragment 15 // 生存期 16 Time to live: 64 17 // 協議名稱 18 Protocol: TCP (6) 19 // 頭部校驗和 20 Header checksum: 0x0000 [validation disabled] 21 // 頭部校驗和檢測狀態 22 [Header checksum status: Unverified] 23 // 源IP 24 Source: 192.168.1.50 25 // 目標IP 26 Destination: 111.202.102.36
第四層:Transmission Control Protocol(傳輸控制協議)
1 // 傳輸控制協議,源端口:4434,目標端口:80,序號1,確認號:1,長度:453 2 Transmission Control Protocol, Src Port: 4434, Dst Port: 80, Seq: 1, Ack: 1, Len: 453 3 // 源端口:4434 4 Source Port: 4434 5 // 目標端口:80 6 Destination Port: 80 7 // 流索引 8 [Stream index: 105] 9 // TCP段長度 10 [TCP Segment Len: 453] 11 // 序號 12 Sequence number: 1 (relative sequence number) 13 // 下一個序號 14 [Next sequence number: 454 (relative sequence number)] 15 // 確認號 16 Acknowledgment number: 1 (relative ack number) 17 // 頭部長度 18 0101 .... = Header Length: 20 bytes (5) 19 // 標記 20 Flags: 0x018 (PSH, ACK) 21 // 窗口大小 22 Window size value: 32768 23 // 計算窗口大小 24 [Calculated window size: 262144] 25 // 窗口大小乘積因子 26 [Window size scaling factor: 8] 27 // 校驗和 28 Checksum: 0x99a8 [unverified] 29 // 校驗和監測狀態 30 [Checksum Status: Unverified] 31 // 緊急指針 32 Urgent pointer: 0 33 [SEQ/ACK analysis] 34 [Timestamps] 35 // TCP負載 36 TCP payload (453 bytes)
第五層:HyperText Transfer Protocol(超文本傳輸協議)
1 // 超文本傳輸協議(HTML) 2 Hypertext Transfer Protocol 3 // POST請求 4 POST /q HTTP/1.1\r\n 5 // 緩存控制 6 Cache-Control: no-cache\r\n 7 // 連接類型 8 Connection: Keep-Alive\r\n 9 // 編輯注解 10 Pragma: no-cache\r\n 11 // 用戶代理 12 User-Agent: SESC\r\n 13 // 內容長度 14 Content-Length: 719\r\n 15 [Content length: 719] 16 // 主機 17 Host: get.sogou.com\r\n 18 \r\n 19 // 完整請求地址 20 [Full request URI: http://get.sogou.com/q] 21 [HTTP request 47/57] 22 // 前一請求所在幀 23 [Prev request in frame: 5904] 24 // 響應幀 25 [Response in frame: 5910] 26 // 下一請求幀 27 [Next request in frame: 5912] 28 // 文件數據 29 File Data: 719 bytes 30 // 數據 31 Data (719 bytes)
HTTP協議的內容根據請求情況會有所不同,需要具體情況具體分析。