-
Notifications
You must be signed in to change notification settings - Fork 2
/
knockit.py
70 lines (58 loc) · 2.98 KB
/
knockit.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
#!/usr/bin/python3
import socket
import itertools
import sys
import time
import argparse
print("\n******************************************************")
print("* *")
print("* _ __ _ _____ _ *")
print("* | |/ / | | |_ _|| | *")
print("* | ' / _ __ ___ ___ | | __ | | | |_ *")
print("* | < | '_ \ / _ \ / __|| |/ / | | | __| *")
print("* | . \ | | | || (_) || (__ | < _| |_ | |_ *")
print("* |_|\_\|_| |_| \___/ \___||_|\_\|_____| \__| *")
print("* *")
print("* *")
print("* KnockIt v1.0 *")
print("* Coded by thebish0p *")
print("* https://github.com/thebish0p/ *")
print("******************************************************\n\n")
class Knockit(object):
def __init__(self, args: list):
self._parse_args(args)
def _parse_args(self, args: list):
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--delay', type=int, default=200,
help='Delay between each knock. Default is 200 ms.')
parser.add_argument('-b', '--bruteforce', help='Try all possible combinations.', action='store_true')
parser.add_argument('host', help='Hostname or IP address of the host.')
parser.add_argument('ports', type=int, help='Port(s) to knock on', nargs='+')
args = parser.parse_args(args)
self.delay = args.delay / 1000
self.ports = args.ports
self.bruteforce = args.bruteforce
self.host= args.host
def knockit(self):
self.ports = list(map(int, self.ports))
if (self.bruteforce):
print("[+] Knockit started attacking with all the possible combinations\n")
print("******************************************************")
for port_list in itertools.permutations(self.ports):
print("[+] Knocking with sequence: %s" % (port_list,))
for port in port_list:
print("[+] Knocking on port %s:%s" % (self.host,port))
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.delay)
sock.connect_ex((self.host, port))
sock.close()
print("******************************************************")
else:
for port in self.ports:
print("[+] Knocking on port %s:%s" % (self.host,port))
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.delay)
sock.connect_ex((self.host, port))
sock.close()
if __name__ == '__main__':
Knockit(sys.argv[1:]).knockit()