0

Could anyone help me, please?

I wrote the same code:

from netfilterqueue import NetfilterQueue

def print_and_accept(pkt):    
    print(pkt)
    pkt.accept()

nfqueue = NetfilterQueue()
nfqueue.bind(1, print_and_accept)
try:
    nfqueue.run()
except KeyboardInterrupt:
    print('')

nfqueue.unbind()

Before push the run button I wrote

 iptables -I FORWARD -j NFQUEUE --queue-num 0 

I tried to write INPUT and OUTPUT instead FORWARD; and change --queue-num 1,2,3...

When I write python3 net_cut.py nothing happens and then pushing CTRL + C I get a message:

^CTraceback (most recent call last):
  File "PycharmProjects/net_cut/net_cut.py", line 12, in <module>
    nfqueue.run()
KeyboardInterrupt
The Fabio
  • 5,369
  • 1
  • 25
  • 55

1 Answers1

0

change --queue-num 0 to 1, if that does not work heres a complete example:

sudo iptables -A OUTPUT -p icmp -j NFQUEUE --queue-num 1

on the system you run the iptables, do a ping -c 1 8.8.8, the code will rewrite the target to 192.168.1.100 - obviously change that ip to some machine in your network and run a tcpdumo icmp on the arriving interface

from scapy.all import *
from netfilterqueue import NetfilterQueue

def modify(packet):
    print("running")
    #pkt = IP(packet.get_payload())
    pkt = IP(packet.get_payload())
    if pkt.haslayer(ICMP):
        print("found icmp")
        pkt.dst = '192.168.1.100'
        print(pkt.dst)

        del pkt[IP].chksum
        #del pkt[TCP].chksum
        packet.set_payload(bytes(pkt))
    #packet.accept()

    packet.drop()
    send(pkt)

nfqueue = NetfilterQueue()
nfqueue.bind(1, modify)
try:
    print("[*] waiting for data")
    nfqueue.run()
except KeyboardInterrupt:
    pass
James Baker
  • 107
  • 2
  • 11