jmhIcoding/flowcontainer

源IP源端口错乱问题

Opened this issue · 6 comments

提取特征工程过程中我想通过flowcontainer提取一条会话流数据包之间的时间间隔,发现利用time.delta只能提取相邻数据包的间隔,无法提取会话流中数据包时间间隔。于是,利用ip_timestamps进行实现。在实现过程中,我发现了一个问题,在对一个pcap的第一个流的五元组信息提取过程中,src_ip和src_port与nfstream提取出的信息不一致,通过查看相应pcap文件,发现flowcontainer提取的src_ip与src_port和dst_ip与dst_port反过来了,请问是什么原因?

请提供你的PCAP,以及nfstream日志

看不到图片,也看不到PCAP。

说一下我的发现:

flow.py line 113 ~ 121:

if self.src is not None:
    if {self.src, self.dst} != {ip_a, ip_b} and {self.sport, self.dport} != {port_a, port_b}:
        print("Packet {} incompatible with flow {}" .format(packet, self))
# Set endpoints where smallest dport is destination
elif port_a > port_b:
    self.src  , self.dst   = ip_a  , ip_b
    self.sport, self.dport = port_a, port_b
else:
    self.src  , self.dst   = ip_b  , ip_a
    self.sport, self.dport = port_b, port_a

当访问一些端口号较大的服务时,例如访问UPnP的37215端口,第一个packet进入时,会进入elif分支,由于src_port=32067, dst_port=37215,因此这部分会被反转。
这里的判断,如果是TCP flow的话,第一个包的条件应该根据SYN标志,可能会更好一点?

Let me share my findings:
File flow.py, line 113 ~ 121

When accessing services with large port numbers, for example, accessing UPnP on port 37215. When the first packet of the flow arrives, it goes into the elif branch. As src_port=32067 and dst_port=37215, the source and destination address get reversed.

Perhaps it would be better to identifying the first packet of a TCP flow base on the SYN flag.

已修改,将按照第一次出现的packet的源端口和目的端口分配端口号