程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

scapy:UDP碎片整理时间戳记问题

发布于2020-02-25 19:58     阅读(565)     评论(0)     点赞(4)     收藏(3)


我使用以下脚本(python + scapy)创建包含碎片化UDP数据包的pcap文件的碎片整理版本。

# Read pcap file
in=rdpcap("in.pcap")
# Defragment ...
out = defragment(in)
# Write defragmented pcap file
wrpcap ("out.pcap", out) 

我的问题是,将经过碎片整理的数据包的pcap时间戳设置为碎片整理的日期,而不是捕获的日期。未分段的数据包仍然具有其原始捕获时间戳。

我查看了inet.py,defragment()和defrag(),但我不太熟练。我想帮助您理解并破解它,以保持最后一次的日期碎片,然后将其放入经过碎片整理的数据包中...

有人可以帮我这个忙吗?
例如,在哪里可以找到输入数据包中的捕获日期,以及应该在哪里将其放在经过碎片整理的数据包中...

当然,任何其他达到相同目标的解决方案都是可以接受的(我承认...我很着急:( ...)


解决方案


这是inet.py的补丁程序,它将第一个片段的捕获日期添加到已碎片整理的数据包中。

可能有更清洁的解决方案,例如修改Packet.copy()方法和其他一些解决方案,但是,它很合适...

*** inet.py     2011-03-29 14:01:19.000000000 +0000
--- inet.py.orig        2011-03-29 07:59:02.000000000 +0000
***************
*** 846,856 ****
          lastp = lst[-1]
          if p.frag > 0 or lastp.flags & 1 != 0: # first or last fragment missing
              missfrag += lst
-             print "missing framgent!"
              continue
!         # Keep 1st fragment capture time (as it is lost in subsequent copies during defragmentation)
!         ptime = p.time
!         p = p.copy() # copy() method do not copy time member (?)
          if Padding in p:
              del(p[Padding].underlayer.payload)
          ip = p[IP]
--- 846,853 ----
          lastp = lst[-1]
          if p.frag > 0 or lastp.flags & 1 != 0: # first or last fragment missing
              missfrag += lst
              continue
!         p = p.copy()
          if Padding in p:
              del(p[Padding].underlayer.payload)
          ip = p[IP]
***************
*** 878,892 ****
              del(ip.len)
              p = p/txt
              p._defrag_pos = max(x._defrag_pos for x in lst)
-             # Put back time in packet
-             p.time= ptime
              defrag.append(p)
      defrag2=[]
      for p in defrag:
          q = p.__class__(str(p))
          q._defrag_pos = p._defrag_pos
-         # Put back time in packet
-         q.time = p.time
          defrag2.append(q)
      final += defrag2
      final += missfrag
--- 875,885 ----


所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/233631/9ed5892742c9201cd658/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

4 0
收藏该文
已收藏

评论内容:(最多支持255个字符)