oremanj/python-netfilterqueue

Send additional packets to socket fromfd

b-schuetz opened this issue · 1 comments

Hello,
thank you for your great work on this project.

Is it possible to send additional packets over the socket, which was returned from "socket.fromfd" ?
I try to inject additional packets, whenever one packet should be send. My current code looks somethings like this:

Best Regards
Bertram

` def setup_and_run_out_queue(self):

    cmd_out = "iptables -w -I OUTPUT -d XXX -p udp  -j NFQUEUE --queue-num " +str(out_q_num)
    os.system(cmd_out)
    print cmd_out

    self.out_nfqueue = NetfilterQueue()
    self.out_nfqueue.bind(out_q_num, self.out_queue_callback)
    self.out_sock = socket.fromfd(self.out_nfqueue.get_fd(), socket.AF_INET, socket.SOCK_DGRAM)
    print(self.out_sock )
    try:
        self.out_nfqueue.run_socket(self.out_sock)
    except KeyboardInterrupt:
        self.graceful_exit()

def out_queue_callback(self, pkt):
    pkt_ip = dpkt.ip.IP(pkt.get_payload())
    dst_ip = socket.inet_ntop(socket.AF_INET, pkt_ip.dst)
    pkt_udp = pkt_ip.data  # remove IP Layer to get UDP
    udp_payload = pkt_udp.data
    print("OUT", dst_ip, ":", pkt_udp.dport)
    self.out_sock.sendto("Test", (dst_ip, pkt_udp.dport))
    pkt.accept()`

I guess I've never seen any documentation that says whether the socket can be used like that. I doubt it. It seems like your usage would work, if it was possible. So if you're not seeing any packets, then I guess it doesn't work. Sorry can't provide more info.