天天看點

UDP/TCP資料包分析

本文旨在分析使用抓包工具抓取到的資料包。

(一)抓包工具

tcpdump:linux下的抓包利器

wireshark:帶GUI的抓包工具,其前身是大名鼎鼎的Ethereal

(二)抓包

這裡隻簡述tcpdump的一般用法,詳細資料可參考tcpdump使用手冊。

wireshark帶有GUI,操作比較簡單,暫不贅述。

tcpdump -i eth1 tcp -Xnlps0 port 16815 src host 192.168.0.0 and dst net 192.168.0.1

tcpdump -i eth1 -Xnlps0 dst net 172.23.9.155 and port 37861

tcpdump -i eth1 -Xnlps0 dst net 172.23.9.155 and port 37861 -w yourfile

PS:可以使用wireshark分析tcpdump抓取的資料包

tcpdump -w output.cap -s0

wireshark可以在圖形界面下分析應用層按照TCP/IP四層結構顯顯示資料包,

第一行是資料鍊路層的資訊,

第二行是網絡層資訊(IP協定),

第三行是傳輸層資訊(TCP協定),

第四行是應用層資訊(HTTP協定),

可以展開每一行用來觀察具體的内容

(三)TCP/UDP資料包結構

1. 單獨的TCP/UDP封包結構

UDP頭:8byte

TCP頭:24byte

UDP/TCP資料包分析

2.帶幀頭(14byte),IP頭(20byte)的UDP資料包結構

UDP/TCP資料包分析

PS:後面的資料分析都是帶IP頭的資料包。

(四)UDP資料包分析

0x0000:  4500 0054 9a08 4000 4011 b88d ac17 8639  [email protected]@......9

0x0010:  ac17 099b e317 93e5 0040 e854 0000 0065  [email protected]

0x0020:  012d d668 0000 0000 0000 0000 0000 0038  .-.h...........8

0x0030:  3030 3030 3030 3030 3030 3030 3030 3030  0000000000000000

0x0040:  0000 0001 0000 0000 0000 0000 0000 0000  ................

0x0050:  0000 0000 

4500        [4: ipv4], [5: header length, *4 ==> 20], [00: Type of Service(TOS)]

0054        [total length: 0x54(84), ip header(20) + udp header(8) + packlen(56) -> 84]

9a08        id

4000        3bits(ip flags), 40 -> do not flag, 5bits: fragment offset

4011        [ttl: 40], [protocol: 0x11(17) ==> udp]

b88d        checksum

ac17 8639   source ip: 172.23.134.57

ac17 099b   dest ip: 172.23.9.155

e317        sourc port: 58135 (ntohs(0xe317)) [exchange]

93e5        dest port: 37861

0040        length: 64

e854        checksum

0000 0065...  data

(五)TCP資料包分析

0x0000:  4500 0073 cdc5 4000 4006 6285 ca6e 4099  [email protected]@.b..n@.

0x0010:  7474 8abe 1f40 070a 6d88 acdd 23d7 a448  [email protected]#..H

0x0020:  5018 16d0 0aa0 0000 0100 8000 0000 0047  P..............G

0x0030:  3004 8000 0016 8117 04d7 cd00 000b 0006  0...............

0x0040:  4500 1a4d 6bd0 180a 909a bc08 883d edea  E..Mk........=..

0x0050:  091f                                     ..

4500        [4: ipv4] [5: ip header length, 4*5 -> 20] [00 TOS]

0073        [total length: 0x73(115), ip header(20) + tcp header(20) + packlen(75) -> 115]

cdc5        id(ignore it)

4000        3bits(ip flags), 40 -> do not flag, 5bits: fragment offset

4006        [40 ttl] [06 protocol, 0x06 -> tcp]

6285        checksum

ca6e 4099   source ip: 202.110.64.153

7474 8abe   dest ip: 116.116.138.190

1f40        sourc port: 8000 (ntohs(0x401f)) [exchange]

070a        dest port: 1802

6d88 acdd   32 bits sequence number(ignore)

23d7 a448   32 bits ack(ignore)

5018        [5: tcp header length 5 * 4 -> 20] [018: 0000 00/01 1000: reserved 6bit -> ACK+PUSH] (URG|ACK|PSH|RST|SYN|FIN)

16d0        16bit window size: 5840

0aa0        16bit tcp checksum(ignore)

0000        16bit urgent pointer

繼續閱讀