Ejemplo n.º 1
0
    def pkt_callback(self, pkt):
        try:
            data = pkt.get_payload()

            if self.snitch.dns.add_response(IP(data)):
                pkt.accept()
                return

            self.latest_packet_id += 1
            conn = Connection(self.snitch.procmon, self.snitch.dns,
                              self.latest_packet_id, data)
            if conn.proto is None:
                logging.debug("Could not detect protocol for packet.")
                return

            elif conn.app.pid is None and conn.proto != 'icmp':
                logging.debug("Could not detect process for connection.")
                return

            # Get verdict, if verdict cannot be found prompt user in thread
            verd = self.snitch.rules.get_verdict(conn)
            if verd is None:
                handler = PacketHandler(conn, pkt, self.snitch.rules)
                self.handlers[conn.id] = handler
                self.snitch.dbus_service.prompt(conn.id, conn.hostname,
                                                conn.dst_port, conn.dst_addr,
                                                conn.proto, conn.app.pid or 0,
                                                conn.app.path or '',
                                                conn.app.cmdline or '')

            elif RuleVerdict(verd) == RuleVerdict.DROP:
                drop_packet(pkt, conn)

            elif RuleVerdict(verd) == RuleVerdict.ACCEPT:
                pkt.accept()

            else:
                raise RuntimeError("Unhandled state")

        except Exception as e:
            logging.exception("Exception on packet callback:")
            logging.exception(e)
Ejemplo n.º 2
0
 def set_conn_result(self, connection_id, save_option, verdict,
                     apply_to_all):
     msg = self.app.dbus_handler.interface.call(
         'connection_set_result', connection_id,
         RuleSaveOption(save_option).value,
         RuleVerdict(verdict).value, apply_to_all)
     reply = QtDBus.QDBusReply(msg)
     if not reply.isValid():
         logging.info('Could not apply result to connection "%s"',
                      connection_id)
         logging.error(msg.arguments()[0])