修改Scapy脚本中的字节

2024-06-16 14:11:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个pcap文件,其中有这样的数据包: 乙醚()/IP()/TCP()/Raw(this one for example

我想在pcap文件中随机选择10个数据包,在原始层修改3个字节,在整个10个数据包中位于同一位置,然后保存pcap。 我做了一些测试,但什么都没有实现,我认为这不是正确的方法:

pkt = rdpcap('file.pcap')

for i in pkt:
  if i.haslayer(TCP) and i.haslayer(Raw):
    list_pkt.append(i)

rdm_list = random.sample(list_pkt,10)

for i in rdm_list:
  org = i[Raw].load
  new = org[:15] + '\xdd\xdd\xdd' + org[18:]
  i[Raw].load = new

有什么帮助吗?在


Tags: 文件inorgnewforrawloadpcap