发布于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黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!