【问题标题】:How to Derive the TSVal and TSecr TCP option fields using python?如何使用 python 导出 TSVal 和 TSecr TCP 选项字段?
【发布时间】:2015-01-07 04:46:10
【问题描述】:

我正在尝试为 python 网络项目开发一个小型概念验证,但我遇到了一个障碍。谁能解释我如何从 python 中的操作系统导出 TSVal 和 TSecr 值? 我正在使用 Scapy 来查看是否可以作为客户端连接到一个简单的 python 服务器程序。下面的陈述是我有点卡住的地方。

TCP(flags='S', options=[('Timestamp', (TSval, TSecr))])

因此,如果有人可以推荐一种算法或 python 库来计算 TSval 和 TSecr,将不胜感激!

提前致谢!

【问题讨论】:

  • 你是如何设置时间戳选项的?我有这些值,但无法将它们设置为 TCP 中的选项。你可以找到我的详细问题here

标签: python networking tcp scapy


【解决方案1】:

我认为这两个值都应该自己计算并分配给数据包。

scapy 有可能会自动分配这些值。你可以试试。但如果没有,就得按照RFC自己计算了。

TSV 是Timestamp Value 字段。它与序列号结合使用以唯一标识段(因为序列号可能会换行)。

TSER 是 Timestamp Echo Reply 字段。这用于 ACK 消息。它保存收到的最后一个 TSV 值的副本。可用于往返时间估计(RTT = 当前时间 - TSER)。

这些字段在 RFC 1323(高性能 TCP 扩展)中有正式描述:

TCP 时间戳选项 (TSopt):

 Kind: 8

 Length: 10 bytes

  +-------+-------+---------------------+---------------------+
  |Kind=8 |  10   |   TS Value (TSval)  |TS Echo Reply (TSecr)|
  +-------+-------+---------------------+---------------------+
      1       1              4                     4

 The Timestamps option carries two four-byte timestamp fields.
 The Timestamp Value field (TSval) contains the current value of
 the timestamp clock of the TCP sending the option.

 The Timestamp Echo Reply field (TSecr) is only valid if the ACK
 bit is set in the TCP header; if it is valid, it echos a times-
 tamp value that was sent by the remote TCP in the TSval field
 of a Timestamps option.  When TSecr is not valid, its value
 must be zero.  The TSecr value will generally be from the most
 recent Timestamp option that was received; however, there are
 exceptions that are explained below.

【讨论】:

  • 感谢 m170897017,但我希望在发送数据包之前从操作系统获取值以将其分配为 TSVal 和 TSecr 变量。
  • @nicRodz OS 中的 TSVal 和 TSecr 是什么?
  • 到目前为止,我知道 TSVal 是由操作系统派生的某种时间戳,用于维护 TCP 连接的顺序。此值用于防止序列号换行 (RFC1323)。 TSecr 源自某种算法,用于确定接收者发送回复之前的时间延迟(我认为)
  • @nicRodz 现在我明白你在说什么了。检查我的更新。
  • 感谢 m170897017,这是我在标准中也遇到的极好的信息。我现在正在寻找一种算法来帮助从头开始计算这些值。不幸的是,默认情况下 Scapy 不会计算或输入这些值。
猜你喜欢
  • 1970-01-01
  • 2019-11-22
  • 2016-02-14
  • 1970-01-01
  • 2016-04-04
  • 1970-01-01
  • 2011-02-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多