使用scapy修改接收到的数据包src / dst

问题描述 投票:0回答:1

我正在尝试嗅探我的wifi以获取接收到的数据包。当我收到ftp数据包时,我反转源和目标(Mac地址,IP地址和端口),然后再次将它们发送回去。

但是,当我检查wireshark时,我发现发送的修改后的数据包有一个错误“ [格式错误的数据包] [以太网帧检查序列不正确]”,尽管我在将数据包发回之前删除了校验和。下面是我定义的修改接收到的数据包src / dst的功能:

def modify_packet(pkt):
    source_mac_address = pkt[Ether].src
    destination_mac_address = pkt[Ether].dst
    destination_address = pkt[IP].dst
    source_address = pkt[IP].src
    destination_port = pkt[TCP].dport
    source_port = pkt[TCP].sport


    pkt[Ether].dst = source_mac_address
    pkt[Ether].src = destination_mac_address
    pkt[IP].dst = source_address
    pkt[IP].src = destination_address
    pkt[TCP].dport = source_port
    pkt[TCP].sport =  destination_port

    del pkt[IP].chksum
    del pkt[TCP].chksum

    send(pkt)
return
python scapy
1个回答
0
投票

Scapy尚未实现以太网校验和,因为它们不可预测:如wireshark's doc上所述

大多数以太网接口要么不向Fashshark或其他应用程序提供FCS,要么没有通过其驱动程序进行配置;因此,尽管在某些平台上具有某些接口,将在传入数据包中提供FCS,但通常只会为Wireshark分配绿色字段。

但是,如果您知道一个数据包具有校验和,则它很可能作为您正在处理的Scapy数据包末尾的Padding层存在。如果是这种情况,您可能可以删除它而不会出现很多问题。

您可以尝试类似的东西

if Padding in pkt:
    pkt[Padding].underlayer.remove_payload()

删除它。

另一注:在处理第2层数据包(在本例中为以太网帧)时,需要使用sendp()而不是send()

© www.soinside.com 2019 - 2024. All rights reserved.