5

我正在尝试捕获数据包并重新组织数据包以获取原始 HTTP 请求。

我正在通过 IPQUEUE(通过 iptables 规则)捕获数据包,我发现数据包没有按顺序捕获。

我已经知道在 TCP 协议中,数据包必须重新排序,所以我试图通过序列号重新排序数据包。

根据 Wikipedia,TCP 的序列号是 32 位数字。那么,如果序列号达到 MAX 32bits 数会怎样?

因为SYN包的序号是随机数,我觉得这个限制可以很快达到。

如果有人对此表示赞赏,或者有一些有用的链接,请给我一个答案。

4

3 回答 3

3

来自RFC-1185

  Avoiding reuse of sequence numbers within the same connection is
  simple in principle: enforce a segment lifetime shorter than the
  time it takes to cycle the sequence space, whose size is
  effectively 2**31.

  If the maximum effective bandwidth at which TCP
  is able to transmit over a particular path is B bytes per second,
  then the following constraint must be satisfied for error-free 
  operation:
      2**31 / B  > MSL (secs)  

因此,简单地说,TCP 会处理它。除了这个条件,TCP 还具有时间戳的概念来处理序列号环绕条件。来自相同的上述 RFC

  Timestamps carried from sender to receiver in TCP Echo options can
  also be used to prevent data corruption caused by sequence number
  wrap-around, as this section describes.

具体来说,TCP 使用 PAWS 机制来处理 TCP 环绕案例。您可以在RFC-1323中找到有关 PAWS 的更多信息

于 2013-01-28T06:17:57.637 回答
1

简单来说,32 位无符号数将环绕:

...
0xFFFFFFFE
0xFFFFFFFF
0x00000000
0x00000001
...
于 2013-01-28T05:13:20.350 回答
0

RFC793 第 3.3 节:

必须记住,实际的序列号空间是有限的,尽管非常大。这个空间的范围从 0 到 2* 32 - 1。由于空间是有限的,所有处理序列号的算术必须以 2 * 32 为模执行。这种无符号算术保留了序列号的关系,因为它们再次从 2**32 - 1 循环到 0。计算机模算术有一些微妙之处,因此在编程这些值的比较时应该非常小心。

对序列号进行的任何算术都是模 2^32

于 2013-01-28T05:08:31.137 回答