- 论坛徽章:
- 1
|
本帖最后由 winway1988 于 2012-05-12 10:53 编辑
回复 7# chaogle
正常去分析数据包,要拿首部结构体去套,来分析字段值。
如果是想基于tcpdump或其他捕包软件的输出来分析信息,我一般这么做
tcpdump保存pcap文件,用wireshark打开(我用的是win下的),wireshark可以导出txt、xml等格式文件,这些文件包含数据包的信息
如- <?xml version="1.0"?>
- <psml version="0" creator="wireshark/1.4.1">
- <structure>
- <section>No.</section>
- <section>Time</section>
- <section>Source</section>
- <section>Destination</section>
- <section>Protocol</section>
- <section>Info</section>
- </structure>
- <packet>
- <section>5</section>
- <section>0.922489</section>
- <section>101.44.1.35</section>
- <section>192.168.1.103</section>
- <section>TCP</section>
- <section>http > quasar-server [FIN, ACK] Seq=1 Ack=1 Win=69 Len=0</section>
- </packet>
复制代码- No. Time Source Destination Protocol Info
- 17 1.065012 192.168.1.103 101.44.1.35 HTTP GET /forum.php?mod=ajax&action=forumchecknew&fid=24&time=1336789898&inajax=yes HTTP/1.1
- Frame 17: 170 bytes on wire (1360 bits), 170 bytes captured (1360 bits)
- Arrival Time: May 12, 2012 10:44:40.839803000 中国标准时间
- Epoch Time: 1336790680.839803000 seconds
- [Time delta from previous captured frame: 0.000080000 seconds]
- [Time delta from previous displayed frame: 0.000080000 seconds]
- [Time since reference or first frame: 1.065012000 seconds]
- Frame Number: 17
- Frame Length: 170 bytes (1360 bits)
- Capture Length: 170 bytes (1360 bits)
- [Frame is marked: False]
- [Frame is ignored: False]
- [Protocols in frame: eth:ip:tcp:http]
- Ethernet II, Src: IntelCor_51:0c:9e (00:26:c7:51:0c:9e), Dst: Tp-LinkT_5c:11:04 (e0:05:c5:5c:11:04)
- Destination: Tp-LinkT_5c:11:04 (e0:05:c5:5c:11:04)
- Address: Tp-LinkT_5c:11:04 (e0:05:c5:5c:11:04)
- .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
- .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
- Source: IntelCor_51:0c:9e (00:26:c7:51:0c:9e)
- Address: IntelCor_51:0c:9e (00:26:c7:51:0c:9e)
- .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
- .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
- Type: IP (0x0800)
- Internet Protocol, Src: 192.168.1.103 (192.168.1.103), Dst: 101.44.1.35 (101.44.1.35)
- Version: 4
- Header length: 20 bytes
- Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
- 0000 00.. = Differentiated Services Codepoint: Default (0x00)
- .... ..0. = ECN-Capable Transport (ECT): 0
- .... ...0 = ECN-CE: 0
- Total Length: 156
- Identification: 0x192d (6445)
- Flags: 0x02 (Don't Fragment)
- 0... .... = Reserved bit: Not set
- .1.. .... = Don't fragment: Set
- ..0. .... = More fragments: Not set
- Fragment offset: 0
- Time to live: 64
- Protocol: TCP (6)
- Header checksum: 0xf8d0 [correct]
- [Good: True]
- [Bad: False]
- Source: 192.168.1.103 (192.168.1.103)
- Destination: 101.44.1.35 (101.44.1.35)
- Transmission Control Protocol, Src Port: int-rcv-cntrl (3603), Dst Port: http (80), Seq: 1441, Ack: 1, Len: 116
- Source port: int-rcv-cntrl (3603)
- Destination port: http (80)
- [Stream index: 1]
- Sequence number: 1441 (relative sequence number)
- [Next sequence number: 1557 (relative sequence number)]
- Acknowledgement number: 1 (relative ack number)
- Header length: 20 bytes
- Flags: 0x18 (PSH, ACK)
- 000. .... .... = Reserved: Not set
- ...0 .... .... = Nonce: Not set
- .... 0... .... = Congestion Window Reduced (CWR): Not set
- .... .0.. .... = ECN-Echo: Not set
- .... ..0. .... = Urgent: Not set
- .... ...1 .... = Acknowledgement: Set
- .... .... 1... = Push: Set
- .... .... .0.. = Reset: Not set
- .... .... ..0. = Syn: Not set
- .... .... ...0 = Fin: Not set
- Window size: 8192
- Checksum: 0xd5ff [validation disabled]
- [Good Checksum: False]
- [Bad Checksum: False]
- [SEQ/ACK analysis]
- [Number of bytes in flight: 1556]
- TCP segment data (116 bytes)
- [Reassembled TCP Segments (1556 bytes): #16(1440), #17(116), #18(116)]
- [Frame: 16, payload: 0-1439 (1440 bytes)]
- [Frame: 17, payload: 1440-1555 (116 bytes)]
- [Frame: 18, payload: 1440-1555 (116 bytes)]
- [Segment overlap: True]
- [Reassembled TCP length: 1556]
- Hypertext Transfer Protocol
- GET /forum.php?mod=ajax&action=forumchecknew&fid=24&time=1336789898&inajax=yes HTTP/1.1\r\n
- [Expert Info (Chat/Sequence): GET /forum.php?mod=ajax&action=forumchecknew&fid=24&time=1336789898&inajax=yes HTTP/1.1\r\n]
- [Message: GET /forum.php?mod=ajax&action=forumchecknew&fid=24&time=1336789898&inajax=yes HTTP/1.1\r\n]
- [Severity level: Chat]
- [Group: Sequence]
- Request Method: GET
- Request URI: /forum.php?mod=ajax&action=forumchecknew&fid=24&time=1336789898&inajax=yes
- Request Version: HTTP/1.1
- User-Agent: Opera/9.80 (Windows NT 5.1; U; zh-cn) Presto/2.10.229 Version/11.64\r\n
- Host: bbs.chinaunix.net\r\n
- Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\n
- Accept-Language: zh-CN,zh;q=0.9,en;q=0.8\r\n
- Accept-Encoding: gzip, deflate\r\n
- Referer: http://bbs.chinaunix.net/forum-24-1.html\r\n
- [truncated] Cookie: ndfU_2132_saltkey=0xs5msd7; ndfU_2132_lastvisit=1336782408; ndfU_2132_auth=64451xbWFQkoyofLMH%2BvnfnBqxa9iDYxL5ssC%2FqOWie8WC3nOEh6zmFxiXUyOkoAkaBEysFAmGa6KwpAyJOIst%2BdM20VQA; ndfU_2132_ulastactivity=bba7kG0LKSGfIjzBG4
- Connection: Keep-Alive\r\n
- X-Requested-With: XMLHttpRequest\r\n
- \r\n
复制代码 这样就可以集中精力用awk、sed来从文本中提取信息了 |
|