NetFilterQueue

问题描述

我正在与Polymorph合作。 尝试中断某些过程时出现问题。

我通常对Ctrl + C进行KeyboardInterrupt,但是当我这样做时:

Exception ignored in: 'netfilterqueue.global_callback'
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/polymorph/interceptor.py",line 75,in linux_modify
    packet.accept()
KeyboardInterrupt

,过程仍然继续。

我去检查interceptor.py,这是函数

def linux_modify(self,packet):
        """This is the callback method that will be called when a packet
        is intercepted. It is responsible of executing the preconditions,executions and postconditions of the `Template`.

        Parameters
        ----------
        packet : :obj:`Packet`
            Netfilterqueue packet object. The packet that is intercepted.

        """
        # Initialization of the Packet with the new raw bytes
        self.packet.raw = packet.get_payload()
        # Executing the preconditions,executions and postconditions
        for functions in self._functions:
            for condition in functions:
                pkt = condition(self.packet)
                # If the condition returns None,it is not held and the
                # packet must be forwarded
                if not pkt:
                    if self.packet:
                        packet.set_payload(self.packet.raw)
                    packet.accept()
                    return
                # If the precondition returns the packet,we assign it to the
                # actual packet
                self.packet = pkt
        # If all the conditions are met,we assign the payload of the modified
        # packet to the nfqueue packet and forward it
        packet.set_payload(self.packet.raw)
        packet.accept()

由…呼叫:

def intercept(self):
       """This method intercepts the packets and send them to a callback
       function."""
       # For Windows Platforms
       if platform.system() == "Windows":
           import pydivert
           w = pydivert.Windivert()
           w.open()
           print("[*] Waiting for packets...\n\n(Press Ctrl-C to exit)\n")
           try:
               while True:
                   self.windows_modify(w.recv(),w,pydivert)
           except KeyboardInterrupt:
               w.close()
       # For Linux platforms
       elif platform.system() == "Linux":
           from netfilterqueue import NetfilterQueue
           nfqueue = NetfilterQueue()
           # The iptables rule queue number by default is 1
           nfqueue.bind(1,self.linux_modify)
           try:
               self.set_iptables_rules()
               print("[*] Waiting for packets...\n\n(Press Ctrl-C to exit)\n")
               nfqueue.run()
           except KeyboardInterrupt:
               self.clean_iptables()
       else:
           print("Sorry. Platform not supported!\n")

15秒后(我认为NFQueue必须为空),我无法使用KeyboardInterrupt正常工作。

有什么主意吗?谢谢大家!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)