简体   繁体   English

如何在Python中重组TCP数据包?

[英]How to reassemble TCP packets in Python?

How to reassemble TCP packets in Python? 如何在Python中重组TCP数据包? Is there any existing tools for this? 有没有现成的工具?

Thanks! 谢谢! :-) :-)

To do perform TCP reassembly you'll need to use something like pynids http://jon.oberheide.org/pynids/ . 要执行TCP重组,您需要使用像pynids http://jon.oberheide.org/pynids/这样的东西。

You can also build your own using pylibpcap, dpkt or scapy. 您也可以使用pylibpcap,dpkt或scapy构建自己的。

TCP reassembly is very tricky with a LOT of edge cases. 有很多边缘情况,TCP重组非常棘手。 I wouldn't recommend doing it yourself if you need a robust solution. 如果你需要一个强大的解决方案,我不建议你自己做。

Yes... the TCP protocol guarantees that the application layer will only see packets assembled and in order. 是的... TCP协议保证应用程序层只能查看已按顺序组装的数据包。 Now if you are talking about building some low level interface parsing the IP packet itself, you can take a stab at it with RAW sockets which should give you access to IP header information. 现在,如果您正在讨论构建一些解析IP数据包本身的低级接口,您可以使用RAW套接字进行攻击,这样可以访问IP头信息。 Here's an example: 这是一个例子:

import socket

# the public network interface
HOST = socket.gethostbyname(socket.gethostname())

# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))

# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

# receive all packages
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)

# receive a package
print s.recvfrom(65565)

# disabled promiscuous mode
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)

lifted shamelessly from the python socket module documentation: http://docs.python.org/library/socket.html 从python套接字模块文档中无耻地解除: http//docs.python.org/library/socket.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM