现在的位置: 首页 > 综合 > 正文

UDP/TCP数据包分析

2012年12月22日 ⁄ 综合 ⁄ 共 2421字 ⁄ 字号 评论关闭

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

(一)抓包工具

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

2.带帧头(14byte),IP头(20byte)的UDP数据包结构

PS:后面的数据分析都是带IP头的数据包。

(四)UDP数据包分析

0x0000:  4500 0054 9a08 4000 4011 b88d ac17 8639 
E..T..@.@......9

0x0010:  ac17 099b e317 93e5 0040 e854 0000 0065 
.........@.T...e

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 
E..s..@.@.b..n
@.
0x0010:  7474 8abe 1f40 070a 6d88 acdd 23d7 a448 
tt...@..m...#..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

 

抱歉!评论已关闭.