重组TCP流的一些问题

发布于 2024-12-04 14:29:21 字数 241 浏览 0 评论 0原文

我正在实现一个IPS系统,在观察wireshark重新组装TCP流的过程时我有点困惑。

例如,服务器向客户端传输HTML页面。页面分为4部分,并由TCP数据包封装。然后服务器将另外 4 个 TCP 数据包推送到客户端以获取 JavaScript 文本。

我的问题是,我知道我可以通过测量它们的 Seq 和 Len 来确定它们的序列,但是我如何确定 HTML 文本的结尾?我如何知道 HTML 包含 4 个 TCP 数据包而不是 5 个?

I'm implementing an IPS system, and I'm a little confused when observing the procesure of TCP stream reassembling by wireshark.

For example, the server transfer a HTML page to the client. The page is divided into 4 parts and encapsulated by TCP packet. Then the server push another 4 TCP packets to the client for a JavaScript text.

My question is, I know I can determine their sequences by measuring their Seq and Len, but how can I determine the end of the HTML text? How can I know the HTML contains 4 TCP packets but not 5?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哑剧 2024-12-11 14:29:21

RFC 2616 第 4.4 节 规定消息长度可以是有多种方式给出:

  • 通过 Content-Length 标头(如果已定义)。 (这可能就是您所看到的情况,并且相对简单。如果您知道正文开始的位置(seq+数据包内的偏移量)和消息长度,则只需添加即可获得结束位置。 )
  • 通过分块编码。 RFC 有详细信息,但它对每个块有类似的编码以及注释最终块的方法。
  • multipart/byteranges(除非客户要求,否则您不会看到它,而且 HTML 文档可能不会)。
  • 或者直到 TCP 连接关闭。 (特别是,直到 FIN 数据包从服务器发送到客户端,这仅发生在完全关闭时;否则您会看到 RST。)

RFC 2616 section 4.4 states that the message length could be given in several ways:

  • By the Content-Length header if one is defined. (This is probably the case you're seeing, and it's relatively simple. If you know the position (seq+offset within packet) of the start of body and the message length, you can just add to get the position of the end.)
  • By chunked encoding. The RFC has the details, but it has a similar encoding for each chunk and a way of noting the final chunk.
  • multipart/byteranges (which you won't see unless the client asked for it, and it probably won't for an HTML document).
  • Or until the TCP connection is closed. (In particular, until a FIN packet is sent from the server to the client, which only happens on a clean close; you'd see an RST otherwise.)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文