-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheres_johnny.py
executable file
·85 lines (69 loc) · 2.49 KB
/
heres_johnny.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
#!/usr/bin/env python3
import os
import itertools
import time
import subprocess
import argparse
class Johnny:
def __init__(self):
self.host = ""
self.ports = ""
def get_args(self):
args = argparse.ArgumentParser()
args.add_argument("host", help="Target to Knock")
args.add_argument("ports", help="Ports to knock, separated by space. "
"\nexample: heres_johnny.py 10.10.10.10 \"80 443 445\"")
parsed = args.parse_args()
self.host = parsed.host
self.ports = parsed.ports
def get_port_list(self):
p1, p2, p3 = self.ports.split(" ")
port_list = [p1, p2, p3]
return port_list
def knock(self, tuple_of_three_ports):
p1, p2, p3 = tuple_of_three_ports
ports = [p1, p2, p3]
print("\n*************************************************")
print("Here's Johnny!!")
print("Port order: " + str(p1) + " " + str(p2) + " " + str(p3))
time.sleep(1)
i:int = 0
while i < 2:
for p in ports:
port = str(p)
command = "\nnmap -T2 -sT -Pn --host-timeout 100 --max-retries 0 -p " + port + " " + self.host
print("\nExecuting: " + command)
subprocess.run([command], stdout=subprocess.PIPE, shell=True)
time.sleep(.5)
time.sleep(1)
print("\nChecking for open SSH...")
sshcheck = "nmap -T2 -sT -n " + self.host + " -Pn --open -p 22"
proc = subprocess.run([sshcheck], stdout=subprocess.PIPE, shell=True)
out = proc.stdout
out = out.decode()
out = str(out)
if "open" in out:
print("\n!!! PORT 22 OPEN !!!")
print(self.host + " now has SSH open")
exit(0)
else:
print("\nSSH is not open on " + self.host)
print("\n*************************************************")
time.sleep(2)
i += 1
def all_combinations(self, port_list):
'''
Generate all possible combinations of ports
'''
order = itertools.permutations(port_list)
permutations = [o for o in order]
return permutations
def main():
os.system("clear")
john = Johnny()
john.get_args()
port_list = john.get_port_list()
combos = john.all_combinations(port_list)
[john.knock(c) for c in combos]
if __name__ == '__main__':
main()