2012-08-27 47 views
0

我想匹配數據包與他們觸發的ICMP超時數據包。因此,我將每個數據包的28個字節長的字符串(有效負載的IP頭+ 8B)與全部(28個字節長)的ICMP有效負載進行比較。匹配數據包和ICMP數據包在TCP重複的情況下

我有問題,當我重複發送的TCP數據包:

>>> p1 
<IP version=4L ihl=5L tos=0x0 len=60 id=0 flags=DF frag=0L ttl=1 proto=tcp chksum=0x7093 src=XXX dst=YYY options=[] |<TCP sport=10743 dport=37901 seq=2939035442L ack=2703569003L dataofs=10L reserved=0L flags=SA window=14480 chksum=0x9529 urgptr=0 options=[('MSS', 1460), ('SAckOK', ''), ('Timestamp', (215365485, 52950)), ('NOP', None), ('WScale', 4)] |>> 
>>> p2 
<IP version=4L ihl=5L tos=0x0 len=60 id=0 flags=DF frag=0L ttl=1 proto=tcp chksum=0x7093 src=XXX dst=YYY options=[] |<TCP sport=10743 dport=37901 seq=2939035442L ack=2703569003L dataofs=10L reserved=0L flags=SA window=14480 chksum=0x9426 urgptr=0 options=[('MSS', 1460), ('SAckOK', ''), ('Timestamp', (215365744, 52950)), ('NOP', None), ('WScale', 4)] |>> 

...其前28個字節是相同的,但在TCP報頭的其餘部分不同:

'E\x00\x00<\x00\[email protected]\x00\x01\x06p\x93\x8a`t\x86\xb2.X\x14)\xf7\x94\r\xaf.\x1f2' 
'E\x00\x00<\x00\[email protected]\x00\x01\x06p\x93\x8a`t\x86\xb2.X\x14)\xf7\x94\r\xaf.\x1f2' 

ICMP數據包我有這樣相同的有效載荷:

>>> i1[ICMP] 
<ICMP type=time-exceeded code=ttl-zero-during-transit chksum=0x689a unused=0 |<IPerror version=4L ihl=5L tos=0x0 len=60 id=0 flags=DF frag=0L ttl=1 proto=tcp chksum=0x7093 src=XXX dst=YYY options=[] |<TCPerror sport=10743 dport=37901 seq=2939035442L |>>> 

>>> i2[ICMP] 
<ICMP type=time-exceeded code=ttl-zero-during-transit chksum=0x689a unused=0 |<IPerror version=4L ihl=5L tos=0x0 len=60 id=0 flags=DF frag=0L ttl=1 proto=tcp chksum=0x7093 src=XXX dst=YYY options=[] |<TCPerror sport=10743 dport=37901 seq=2939035442L |>>> 

相應的字符串是:

'E\x00\x00<\x00\[email protected]\x00\x01\x06p\x93\x8a`t\x86\xb2.X\x14)\xf7\x94\r\xaf.\x1f2' 
'E\x00\x00<\x00\[email protected]\x00\x01\x06p\x93\x8a`t\x86\xb2.X\x14)\xf7\x94\r\xaf.\x1f2' 

眼下在這種特殊情況下,我聲稱a1比賽i1因爲i1i2之間,它是i1說的a1發送後,很快就到了,而i2到達晚得多。

這夠了嗎?我還有什麼遺漏?

回答

1

TCP數據包的標頭大小並不總是20個字節。如果有選項設置,標題可能會更大。您可以使用Internet標題長度字段查找標題大小並將所需的有效負載量添加到該數字。

Scapy: how do I get the full IP packet header?

+0

是的,但在任何情況下,我只有前8個字節所需要的,所以...... 這個問題是我的,順便說一下! –